Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/osborneMs/morphir-elm into …
Browse files Browse the repository at this point in the history
…feature/sdk-functions-localdate
  • Loading branch information
osborneMs committed Jun 9, 2023
2 parents c031517 + a4c5133 commit de3a5c5
Show file tree
Hide file tree
Showing 40 changed files with 11,316 additions and 432 deletions.
2 changes: 2 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ Morphir.*.js
web/main.js
web/index.js
web/insight.js
web/valueEditor.js
web/editor-custom-element.js
web/try-morphir.html
5 changes: 4 additions & 1 deletion cli/src/Morphir/Web/DevelopApp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,11 @@ update msg model =
, Cmd.none
)

ServerGetIRResponse distribution ->
ServerGetIRResponse (Library packageName dependencies packageDef) ->
let

distribution =
(Library packageName (dependencies |> Dict.insert SDK.packageName SDK.packageSpec) packageDef)
irLoaded : IRState
irLoaded =
IRLoaded distribution
Expand Down
221 changes: 221 additions & 0 deletions cli/src/Morphir/Web/Editor.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
port module Morphir.Web.Editor exposing (..)

import Browser
import Element
import Html exposing (Html)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
import Morphir.IR as IR exposing (IR)
import Morphir.IR.Distribution exposing (Distribution)
import Morphir.IR.Distribution.Codec exposing (decodeVersionedDistribution)
import Morphir.IR.FQName as FQName exposing (FQName)
import Morphir.IR.Type as Type exposing (Type)
import Morphir.IR.Type.DataCodec as DataCodec exposing (decodeData)
import Morphir.IR.Value exposing (RawValue, Value(..))
import Morphir.Visual.Theme as Theme exposing (Theme)
import Morphir.Visual.ValueEditor as ValueEditor



--MODEL


type alias Model =
Result String ModelState


type alias ModelState =
{ ir : IR
, theme : Theme
, valueType : Type ()
, editorState : ValueEditor.EditorState
, encoder : RawValue -> Result String Encode.Value
}



--MAIN


main : Program Decode.Value Model Msg
main =
Browser.element
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}



--INIT


init : Decode.Value -> ( Model, Cmd Msg )
init flags =
case flags |> Decode.decodeValue decodeFlag of
Ok flag ->
let
tpe : Type ()
tpe =
Type.Reference () flag.entryPoint []

ir : IR
ir =
IR.fromDistribution flag.distribution

initEditorState : ValueEditor.EditorState
initEditorState =
ValueEditor.initEditorState ir tpe flag.initialValue

encoderResult : Result String (RawValue -> Result String Encode.Value)
encoderResult =
DataCodec.encodeData ir tpe

model : Model
model =
encoderResult
|> Result.map
(\encoder ->
{ ir = ir
, theme = Theme.fromConfig Nothing
, valueType = tpe
, editorState = initEditorState
, encoder = encoder
}
)
in
( model
, Cmd.none
)

Err error ->
( Err (Decode.errorToString error), reportError (Decode.errorToString error) )



--FLAGS


type alias Flags =
{ distribution : Distribution
, entryPoint : FQName
, initialValue : Maybe RawValue
}



--MESSAGE


type Msg
= UpdatedEditor ValueEditor.EditorState



--PORTS


port valueUpdated : Decode.Value -> Cmd msg


port reportError : String -> Cmd msg



--SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions _ =
Sub.none



--UPDATE


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case model of
Ok m ->
case msg of
UpdatedEditor editorState ->
case editorState.errorState of
Just error ->
( model, reportError error )

Nothing ->
let
jsonResult : Result String Encode.Value
jsonResult =
editorState.lastValidValue
|> Maybe.map m.encoder
|> Maybe.withDefault (Ok Encode.null)
in
case jsonResult of
Ok json ->
( Result.map (\mod -> { mod | editorState = editorState }) model
, valueUpdated json
)

Err error ->
( model, reportError error )

Err error ->
( model, Cmd.none )



--VIEW


view : Model -> Html Msg
view model =
case model of
Ok { theme, ir, editorState, valueType } ->
Element.layout [] (ValueEditor.view theme ir valueType UpdatedEditor editorState)

Err error ->
Html.text error


decodeFlag : Decode.Decoder Flags
decodeFlag =
let
decodeResultToFailure : Result String (Decoder a) -> Decoder a
decodeResultToFailure result =
case result of
Ok decoder ->
decoder

Err error ->
Decode.fail error
in
Decode.map2
(\distribution fqn ->
let
tpe =
Type.Reference () fqn []
in
Decode.field "initialValue"
(Decode.maybe
(decodeData (IR.fromDistribution distribution) tpe
|> decodeResultToFailure
)
)
|> Decode.map (Flags distribution fqn)
)
(Decode.field "distribution" decodeVersionedDistribution)
(Decode.field "entryPoint" Decode.string
|> Decode.andThen
(\str ->
case FQName.fromStringStrict str ":" of
Ok fQName ->
Decode.succeed fQName

Err error ->
Decode.fail error
)
)
|> Decode.andThen identity
2 changes: 1 addition & 1 deletion lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fsReadFile("./morphir-ir.json")
function toDistribution(text: string): Distribution.Distribution {
let data = JSON.parse(text);

if (data["formatVersion"] != 2) {
if (data["formatVersion"] != 3) {
throw "Unsupported morphir-ir.json format";
}

Expand Down
24 changes: 24 additions & 0 deletions morphir-decoration-extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
2 changes: 2 additions & 0 deletions morphir-decoration-extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist
13 changes: 13 additions & 0 deletions morphir-decoration-extension/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.vscode/**
.vscode-test/**
out/**
node_modules/**
src/**
.gitignore
.yarnrc
webpack.config.js
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
41 changes: 41 additions & 0 deletions morphir-decoration-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Morphir Decorations Editor

The Morphir Decorations Editor is a Visual Studio Code (VSCode) extension that enhances the editing experience for developers working with Morphir. It provides a tree view that reads the Intermediate Representation (IR) of your Morphir project and displays decorations for various modules, types, and values. This extension allows you to edit decorations while working with Morphir.

## Features

- **Tree View**: The Morphir Decorations Editor extension provides a tree view in the VSCode sidebar that represents the structure of your Morphir project based on its IR. It displays modules, types, and values in a hierarchical manner, allowing you to navigate and explore the different elements.

- **Edit Existing Decorations**: With the Morphir Decorations Editor, you can easily edit the existing decorations associated with modules, types, and values in your Morphir project. The extension provides a user-friendly interface to modify and customize the decorations based on your requirements.

- **Decorations Per Selection**: When you select a specific module, type, or value in the tree view, the Morphir Decorations Editor displays the associated decorations for that selection. This feature enables you to quickly identify and modify the decorations applied to individual elements of your Morphir project.

## Usage

1. Install the Morphir Decorations Editor extension from the VSCode Marketplace.

2. Open your Morphir project in VSCode.

3. In the VSCode sidebar, locate the Icon for the Morphir Decoration Editor

4. Once Icon is cliicked, locate the tree view of the various modules, types and values in the IR, in the exploerer view.

5. Explore the tree view to navigate through the modules, types, and values of your Morphir project.

6. To edit the existing decorations, select the desired module, type, or value in the tree view. The existing decorations will be displayed, and you can modify them as needed.

7. Changes are saved in edit, so the edit will be applied to the respective elements in your Morphir project.

## Benefits

The Morphir Decorations Editor extension offers several benefits to developers working with Morphir:

- **Enhanced Editing Experience**: By providing a tree view of your Morphir project's IR, the extension simplifies navigation and exploration of the project's modules, types, and values. This makes it easier to locate and work with specific elements of your Morphir codebase.

- **Efficient Decoration Management**: With the ability to edit existing decorations, the extension streamlines the process of customizing the visual representation of your Morphir code. Developers can easily attach and modify decorations, improving code readability and comprehension.

## Feedback and Contributions

We welcome your feedback, bug reports, and contributions to the Morphir Decorations Editor extension. If you have any questions or suggestions, please feel free to open an issue in the [GitHub repository](https://github.com/finos/morphir-elm/tree/main/morphir-decoration-extension). We appreciate your support in improving the extension and making it even more useful for the Morphir community.

**Enjoy!**
4 changes: 4 additions & 0 deletions morphir-decoration-extension/media/dark-decoration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions morphir-decoration-extension/media/dark-refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions morphir-decoration-extension/media/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import '../../cli/web/editor-custom-element.js'

const customEdit = document.querySelector('#value-editor');
const valueEditor = document.createElement("value-editor");

customEdit?.appendChild(valueEditor)
22 changes: 22 additions & 0 deletions morphir-decoration-extension/media/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"jsx": "preserve",
"checkJs": true,
"strict": true,
"strictFunctionTypes": true,
"lib": [
"dom"
]
},
"exclude": [
"node_modules",
"**/node_modules/*"
],
"typeAcquisition": {
"include": [
"@types/vscode-webview"
]
}
}
3 changes: 3 additions & 0 deletions morphir-decoration-extension/media/light-decoration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions morphir-decoration-extension/media/light-refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions morphir-decoration-extension/media/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit de3a5c5

Please sign in to comment.