Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into resizable-feedback-pane
- Loading branch information
Showing
36 changed files
with
9,466 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module BlocklyEditor.State where | ||
|
||
import Prelude | ||
import BlocklyEditor.Types (Action(..), State, _errorMessage, _marloweCode) | ||
import Control.Monad.Except (ExceptT(..), except, runExceptT) | ||
import Data.Bifunctor (lmap) | ||
import Data.Either (note, Either(..)) | ||
import Data.Lens (assign) | ||
import Data.Maybe (Maybe(..)) | ||
import Debug.Trace (spy) | ||
import Effect.Aff.Class (class MonadAff) | ||
import Halogen (HalogenM, query) | ||
import Halogen as H | ||
import Halogen.Blockly as Blockly | ||
import MainFrame.Types (ChildSlots, _blocklySlot) | ||
import Marlowe.Parser as Parser | ||
import Text.Extra as Text | ||
import Text.Pretty (pretty) | ||
|
||
handleAction :: | ||
forall m. | ||
MonadAff m => | ||
Action -> | ||
HalogenM State Action ChildSlots Void m Unit | ||
handleAction (HandleBlocklyMessage Blockly.CodeChange) = do | ||
eContract <- | ||
runExceptT do | ||
code <- ExceptT <<< map (note "Blockly Workspace is empty") $ query _blocklySlot unit $ H.request Blockly.GetCode | ||
except <<< lmap (unexpected <<< show) $ Parser.parseContract (Text.stripParens code) | ||
case eContract of | ||
Left e -> do | ||
assign _errorMessage $ Just e | ||
assign _marloweCode Nothing | ||
Right contract -> do | ||
assign _errorMessage Nothing | ||
assign _marloweCode $ Just $ show $ pretty contract | ||
where | ||
unexpected s = "An unexpected error has occurred, please raise a support issue at https://github.com/input-output-hk/plutus/issues/new: " <> s | ||
|
||
handleAction (InitBlocklyProject code) = do | ||
assign _marloweCode $ Just code | ||
void $ query _blocklySlot unit $ H.tell (Blockly.SetCode code) | ||
|
||
handleAction SendToSimulator = pure unit | ||
|
||
handleAction ViewAsMarlowe = pure unit | ||
|
||
handleAction Save = pure unit | ||
|
||
editorGetValue :: forall state action msg m. HalogenM state action ChildSlots msg m (Maybe String) | ||
editorGetValue = query _blocklySlot unit $ H.request Blockly.GetCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module BlocklyEditor.Types where | ||
|
||
import Prelude | ||
import Analytics (class IsEvent, defaultEvent) | ||
import Data.Lens (Lens') | ||
import Data.Lens.Record (prop) | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Symbol (SProxy(..)) | ||
import Halogen.Blockly as Blockly | ||
|
||
data Action | ||
= HandleBlocklyMessage Blockly.Message | ||
| InitBlocklyProject String | ||
| SendToSimulator | ||
| ViewAsMarlowe | ||
| Save | ||
|
||
instance blocklyActionIsEvent :: IsEvent Action where | ||
toEvent (HandleBlocklyMessage _) = Just $ (defaultEvent "HandleBlocklyMessage") { category = Just "Blockly" } | ||
toEvent (InitBlocklyProject _) = Just $ (defaultEvent "InitBlocklyProject") { category = Just "Blockly" } | ||
toEvent SendToSimulator = Just $ (defaultEvent "SendToSimulator") { category = Just "Blockly" } | ||
toEvent ViewAsMarlowe = Just $ (defaultEvent "ViewAsMarlowe") { category = Just "Blockly" } | ||
toEvent Save = Just $ (defaultEvent "Save") { category = Just "Blockly" } | ||
|
||
type State | ||
= { errorMessage :: Maybe String | ||
, marloweCode :: Maybe String | ||
} | ||
|
||
_errorMessage :: Lens' State (Maybe String) | ||
_errorMessage = prop (SProxy :: SProxy "errorMessage") | ||
|
||
_marloweCode :: Lens' State (Maybe String) | ||
_marloweCode = prop (SProxy :: SProxy "marloweCode") | ||
|
||
initialState :: State | ||
initialState = | ||
{ errorMessage: Nothing | ||
, marloweCode: Nothing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module BlocklyEditor.View where | ||
|
||
import Prelude hiding (div) | ||
import BlocklyEditor.Types (Action(..), State, _marloweCode) | ||
import Data.Lens ((^.)) | ||
import Data.Maybe (Maybe(..), isJust) | ||
import Effect.Aff.Class (class MonadAff) | ||
import Halogen (ComponentHTML) | ||
import Halogen.Blockly as Blockly | ||
import Halogen.Classes (disabled, group) | ||
import Halogen.HTML (HTML, button, div, slot, text, div_) | ||
import Halogen.HTML.Events (onClick) | ||
import Halogen.HTML.Properties (classes, enabled) | ||
import MainFrame.Types (ChildSlots, _blocklySlot) | ||
import Marlowe.Blockly as MB | ||
|
||
render :: | ||
forall m. | ||
MonadAff m => | ||
State -> | ||
ComponentHTML Action ChildSlots m | ||
render state = | ||
div_ | ||
[ slot _blocklySlot unit (Blockly.blockly MB.rootBlockName MB.blockDefinitions) unit (Just <<< HandleBlocklyMessage) | ||
, MB.toolbox | ||
, MB.workspaceBlocks | ||
] | ||
|
||
otherActions :: | ||
forall p. | ||
State -> HTML p Action | ||
otherActions state = | ||
div [ classes [ group ] ] | ||
[ button | ||
[ onClick $ const $ Just ViewAsMarlowe | ||
, enabled hasCode | ||
, classes [ disabled hasCode ] | ||
] | ||
[ text "View as Marlowe" ] | ||
, button | ||
[ onClick $ const $ Just SendToSimulator | ||
, enabled hasCode | ||
, classes [ disabled hasCode ] | ||
] | ||
[ text "Send To Simulator" ] | ||
] | ||
where | ||
hasCode = isJust $ state ^. _marloweCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.