-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/osborneMs/morphir-elm into …
…feature/sdk-functions-localdate
- Loading branch information
Showing
40 changed files
with
11,316 additions
and
432 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
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,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 |
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,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" | ||
] | ||
} |
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,2 @@ | ||
node_modules/ | ||
dist |
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,13 @@ | ||
.vscode/** | ||
.vscode-test/** | ||
out/** | ||
node_modules/** | ||
src/** | ||
.gitignore | ||
.yarnrc | ||
webpack.config.js | ||
vsc-extension-quickstart.md | ||
**/tsconfig.json | ||
**/.eslintrc.json | ||
**/*.map | ||
**/*.ts |
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,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!** |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,6 @@ | ||
import '../../cli/web/editor-custom-element.js' | ||
|
||
const customEdit = document.querySelector('#value-editor'); | ||
const valueEditor = document.createElement("value-editor"); | ||
|
||
customEdit?.appendChild(valueEditor) |
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,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" | ||
] | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.