-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from cesarParra/editor
Playground Editor
- Loading branch information
Showing
33 changed files
with
38,798 additions
and
22 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
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
37 changes: 37 additions & 0 deletions
37
expression-src/main/editor/controllers/PlaygroundController.cls
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,37 @@ | ||
public with sharing class PlaygroundController { | ||
@AuraEnabled(Cacheable=true) | ||
public static List<String> getFunctions() { | ||
Set<String> builtInFunctionNames = ExpressionFunction.FUNCTIONS.keySet(); | ||
Set<String> customFunctionNames = Expression_Function__mdt.getAll().keySet(); | ||
Set<String> functionNames = new Set<String>(); | ||
functionNames.addAll(builtInFunctionNames); | ||
functionNames.addAll(customFunctionNames); | ||
return new List<String>( | ||
functionNames | ||
); | ||
} | ||
|
||
@AuraEnabled | ||
public static Result validate(String expr, Id recordId) { | ||
Result toReturn = new Result(); | ||
try { | ||
if (recordId != null) { | ||
toReturn.result = Evaluator.run(expr, recordId); | ||
} else { | ||
toReturn.result = Evaluator.run(expr); | ||
} | ||
} catch (Exception e) { | ||
toReturn.error = e.getMessage(); | ||
} | ||
|
||
return toReturn; | ||
} | ||
|
||
public class Result { | ||
@AuraEnabled | ||
public String error; | ||
|
||
@AuraEnabled | ||
public Object result; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
expression-src/main/editor/controllers/PlaygroundController.cls-meta.xml
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>58.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
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,8 @@ | ||
.lgc-bg { | ||
background-color: rgb(242 242 242); | ||
} | ||
.top-right { | ||
position: absolute; | ||
top: 20px; | ||
right: 20px; | ||
} |
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,29 @@ | ||
<template> | ||
<div class="slds-p-around_medium slds-m-bottom_small lgc-bg"> | ||
<lightning-input type="text" | ||
value={recordId} | ||
onchange={handleInputChange} | ||
label="Record Id (Optional Context)"></lightning-input> | ||
</div> | ||
<div class="slds-grid slds-gutters"> | ||
<div class="slds-col slds-size_6-of-12 slds-is-relative"> | ||
<iframe src={iframeUrl} | ||
scrolling="no" style="width: 100%; height: 500px; overflow: hidden; border: none" | ||
onload={iframeLoaded} | ||
></iframe> | ||
<div class="top-right"> | ||
<lightning-button | ||
icon-name="utility:play" | ||
variant="brand" label="Validate" onclick={getExpression}> | ||
</lightning-button> | ||
</div> | ||
</div> | ||
<div class="slds-col slds-size_6-of-12"> | ||
<lightning-card title="Result" icon-name="custom:custom14"> | ||
<div class="slds-p-horizontal_small"> | ||
<pre class={resultColor}>{result.payload}</pre> | ||
</div> | ||
</lightning-card> | ||
</div> | ||
</div> | ||
</template> |
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,47 @@ | ||
import { LightningElement } from 'lwc'; | ||
import monaco from '@salesforce/resourceUrl/monaco'; | ||
import getFunctions from '@salesforce/apex/PlaygroundController.getFunctions'; | ||
import validate from '@salesforce/apex/PlaygroundController.validate'; | ||
|
||
export default class Monaco extends LightningElement { | ||
recordId; | ||
iframeUrl = `${monaco}/main.html`; | ||
result = {}; | ||
|
||
async iframeLoaded() { | ||
console.log('iframe loaded'); | ||
const functionKeywords = await getFunctions(); | ||
this.iframeWindow.postMessage({ | ||
name: 'initialize', | ||
keywords: functionKeywords | ||
}); | ||
} | ||
|
||
async getExpression() { | ||
const expr = this.iframeWindow.editor.getValue(); | ||
const result = await validate({expr: expr, recordId: this.recordId}); | ||
if (result.error) { | ||
this.result = { | ||
type: "error", | ||
payload: result.error | ||
} | ||
} else { | ||
this.result = { | ||
type: "success", | ||
payload: JSON.stringify(result.result, null, 2) | ||
} | ||
} | ||
} | ||
|
||
handleInputChange(event) { | ||
this.recordId = event.detail.value; | ||
} | ||
|
||
get iframeWindow() { | ||
return this.template.querySelector('iframe').contentWindow; | ||
} | ||
|
||
get resultColor() { | ||
return this.result.type === 'error' ? 'slds-text-color_error' : 'slds-text-color_default'; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
expression-src/main/editor/lwc/playground/playground.js-meta.xml
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>58.0</apiVersion> | ||
<description>Playground</description> | ||
<isExposed>true</isExposed> | ||
<masterLabel>Playground</masterLabel> | ||
<targets> | ||
<target>lightning__Tab</target> | ||
</targets> | ||
</LightningComponentBundle> |
6 changes: 6 additions & 0 deletions
6
expression-src/main/editor/staticresources/monaco.resource-meta.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<StaticResource xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<cacheControl>Public</cacheControl> | ||
<contentType>application/zip</contentType> | ||
<description>monaco2</description> | ||
</StaticResource> |
74 changes: 74 additions & 0 deletions
74
expression-src/main/editor/staticresources/monaco/main.html
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,74 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | ||
<link | ||
rel="stylesheet" | ||
data-name="vs/editor/editor.main" | ||
href="min/vs/editor/editor.main.css" | ||
/> | ||
</head> | ||
<body style="margin: 0;"> | ||
<div id="container" style="width: 800px; height: 500px;"></div> | ||
|
||
<script> | ||
var require = {paths: {vs: 'min/vs'}}; | ||
</script> | ||
<script src="min/vs/loader.js"></script> | ||
<script src="min/vs/editor/editor.main.nls.js"></script> | ||
<script src="min/vs/editor/editor.main.js"></script> | ||
|
||
<script> | ||
window.addEventListener("message", onMessage, false); | ||
|
||
function onMessage(event) { | ||
console.log(JSON.stringify(event.data)); | ||
if (event.data.name === 'initialize') { | ||
initialize(event.data.keywords); | ||
} | ||
} | ||
|
||
function initialize(functionKeywords) { | ||
monaco.languages.register({id: 'expression'}); | ||
let keywords = functionKeywords; | ||
monaco.languages.setMonarchTokensProvider('expression', { | ||
keywords, | ||
tokenizer: { | ||
root: [ | ||
// identifiers and keywords | ||
[/[a-zA-Z_$][\w$]*/, { | ||
cases: { | ||
'@keywords': 'keyword', | ||
} | ||
}], | ||
[/".*?"/, 'string'], | ||
[/[{}()\[\]]/, '@brackets'], | ||
], | ||
}, | ||
ignoreCase: true | ||
}); | ||
monaco.languages.registerCompletionItemProvider('expression', { | ||
provideCompletionItems(model, position, context, token) { | ||
const suggestions = [ | ||
...keywords.map( | ||
k => { | ||
return { | ||
label: k, | ||
kind: monaco.languages.CompletionItemKind.Keyword, | ||
insertText: k, | ||
} | ||
} | ||
) | ||
]; | ||
return {suggestions: suggestions}; | ||
} | ||
}); | ||
|
||
window.editor = monaco.editor.create(document.getElementById('container'), { | ||
value: [''].join('\n'), | ||
language: 'expression', | ||
}); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Binary file added
BIN
+71.9 KB
...rc/main/editor/staticresources/monaco/min/vs/base/browser/ui/codicons/codicon/codicon.ttf
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
...sion-src/main/editor/staticresources/monaco/min/vs/base/common/worker/simpleWorker.nls.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.