Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Feature: Ace Editor Integration #667

Open
wants to merge 2 commits into
base: releaseCandidate
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added ace editor to page
  • Loading branch information
sqone2 committed Nov 29, 2024
commit 95442bd06bfe4249b131ea77f97e046f785c2a3a
5 changes: 5 additions & 0 deletions addon/data-export.html
Original file line number Diff line number Diff line change
@@ -11,11 +11,16 @@
</head>

<body>

<div id="root"></div>
<script src="react.js"></script>
<script src="react-dom.js"></script>
<script src="button.js"></script>
<script type="module" src="data-export.js"></script>

<script src="lib/ace-editor/ace.js"></script>
<script src="lib/ace-editor/ext-language_tools.js"></script>

</body>

</html>
67 changes: 67 additions & 0 deletions addon/data-export.js
Original file line number Diff line number Diff line change
@@ -1433,6 +1433,7 @@ class App extends React.Component {
),
),
),
h("div", {id:"ace-editor", style: {height: "300px"}},),
h("textarea", {id: "query", ref: "query", style: {maxHeight: (model.winInnerHeight - 200) + "px"}}),
h("div", {className: "autocomplete-box" + (model.expandAutocomplete ? " expanded" : "")},
h("div", {className: "autocomplete-header"},
@@ -1503,6 +1504,71 @@ class App extends React.Component {
}
}

function initAceEditor() {
// trigger extension
ace.require("ace/ext/language_tools");
const editor = ace.edit("ace-editor");
editor.session.setMode("ace/mode/sql");
editor.setTheme("ace/theme/cobalt");
// enable autocompletion and snippets
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
fontFamily: "Consolas",
fontSize: "20px"
});

const soqlKeywords = [
"SELECT",
"FROM",
"WHERE",
"AND",
"OR",
"NOT",
"IN",
"NOT IN",
"LIKE",
"LIMIT",
"OFFSET",
"ORDER BY",
"ASC",
"DESC",
"GROUP BY",
"HAVING",
"COUNT()",
"SUM()",
"AVG()",
"MIN()",
"MAX()",
"WITH",
"TYPEOF",
"TO LABEL",
"ALL ROWS",
"FOR UPDATE",
"DISTANCE",
"GEOLOCATION"
];


const staticWordCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var wordList = soqlKeywords
callback(null, wordList.map(function(word) {
return {
caption: word,
value: word,
meta: "keyword"
};
}));

}
}

editor.completers = [staticWordCompleter]
editor.setValue('SELECT Id\nFROM Account\nLIMIT 200');
}

{

let args = new URLSearchParams(location.search);
@@ -1518,6 +1584,7 @@ class App extends React.Component {
let model = new Model({sfHost, args});
model.reactCallback = cb => {
ReactDOM.render(h(App, {model}), root, cb);
initAceEditor();
};
ReactDOM.render(h(App, {model}), root);

Loading