Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
dash_ace_persistent
Advanced tools
Dash Ace is a Plotly Dash component of Ace editor that wraps up a react ace editor
It supports the following four modes: Python, SQL, Text, Norm and several themes: github, monokai, tomorrow, twilight, textmate. If you want other languages and themes, you can fork the repo and modify the code. Dynamic loading of modes and themes are not supported yet.
pip install dash-ace
The following is a simple example using this component.
import dash
import dash_ace
import dash_html_components as html
import flask
from flask import jsonify
from flask_cors import CORS
server = flask.Flask(__name__)
CORS(server)
app = dash.Dash(__name__,
server=server,
routes_pathname_prefix='/dash/'
)
app.layout = html.Div([
dash_ace.DashAceEditor(
id='input',
value='def test(a: int) -> str : \n'
' return f"value is {a}"',
theme='github',
mode='python',
tabSize=2,
enableBasicAutocompletion=True,
enableLiveAutocompletion=True,
autocompleter='/autocompleter?prefix=',
placeholder='Python code ...'
)
])
@server.route('/autocompleter', methods=['GET'])
def autocompleter():
return jsonify([{"name": "Completed", "value": "Completed", "score": 100, "meta": "test"}])
if __name__ == '__main__':
app.run_server(debug=True)
Prop | Default | Type | Description |
---|---|---|---|
id | 'ace-editor' | str | Unique Id to be used for the editor |
placeholder | 'Type code here ...' | str | Placeholder text to be displayed when editor is empty |
mode | 'python' | str | Language for parsing and code highlighting |
syntaxKeywords | {} | dict | Custom language keywords, see format |
syntaxFolds | None | str | Custom language folding character to fold code |
theme | 'github' | str | theme to use |
value | '' | str or List[str] | values you want to populate in the code |
className | None | str | custom className |
fontSize | 14 | int | pixel value for font-size |
showGutter | True | bool | show gutter |
showPrintMargin | True | bool | show print margin |
highlightActiveLine | True | bool | highlight active line |
focus | False | bool | whether to focus |
cursorStart | 1 | int | the location of the cursor |
wrapEnabled | False | bool | Wrapping lines |
readOnly | False | bool | make the editor read only |
orientation | 'below' | str | diff view orientation, 'below' or 'beside' |
minLines | None | int | Minimum number of lines to be displayed |
maxLines | None | int | Maximum number of lines to be displayed |
enableBasicAutocompletion | False | bool | Enable basic autocompletion |
enableLiveAutocompletion | False | bool | Enable live autocompletion |
autocompleter | None | str | Custom auto completer from a language server |
prefixLine | False | bool | Custom auto completer takes the current line as the prefix (False to take the current word) |
triggerWords | None | list | The list of possible words before the cursor can trigger the custom auto completer (default to any words) |
enableSnippets | False | bool | Enable snippets |
tabSize | 4 | int | tabSize |
debounceChangePeriod | None | int | A debounce delay period for the onChange event |
editorProps | None | dict | properties to apply directly to the Ace editor instance |
setOptions | None | dict | options to apply directly to the Ace editor instance |
commands | None | list | new commands to add to the editor |
annotations | None | list | annotations to show in the editor i.e. [{ row: 0, column: 2, type: 'error', text: 'Some error.'}] , displayed in the gutter |
markers | None | list | markers to show in the editor, i.e. [{ startRow: 0, startCol: 2, endRow: 1, endCol: 20, className: 'error-marker', type: 'background' }] . Make sure to define the class (eg. ".error-marker") and set position: absolute for it. |
style | None | dict | camelCased properties Get started with: |
Dash ace editor has a simple mechanism to create a custom mode that extends from python language. The syntax highlighting allows
custom keywords to be defined in syntaxKeywords
. Additional folding characters can be defined in syntaxFolds
.
The following is a custom syntax configuration for Norm.
syntaxKeywords = {
"variable.language": "this|that|super|self|sub|",
"support.function": "enumerate|range|pow|sum|abs|max|min|argmax|argmin|len|mean|std|median|all|any|",
"support.type": "String|Integer|Bool|Float|Image|UUID|Time|DateTime|Type|",
"storage.modifier": "parameter|atomic|primary|optional|id|time|asc|desc|",
"constant.language": "true|false|none|na|",
"keyword.operator": "and|or|not|except|unless|imply|in|",
"keyword.control": "as|from|to|import|export|return|for|exist|with|"
}
syntaxFolds = '\\:='
The syntax rules can be created and tested on Mode Creator.
A language server can provide a better intellisense service to recommend the most relevant keywords, types and variables.
autocompleter='/autocompleter?prefix='
configures the editor to consult the API given a prefix. The returned list of recommended words
has the schema of name: str, value: str, score: int, meta: str
. The popup menu in UI shows value
and meta
and order the
recommended words by the score
. The one with the highest score
lists at the top.
Ace editor autocompletion by default takes the word at the cursor as the prefix. Setting prefixLine=True
allows the custom auto completer
to receive the entire line before the cursor as the prefix. Note that ace editor does not invoke live auto completion for anything
other than words. Press Ctrl+Space
to show the recommended completions if you would like to access members like test.
or to declare types like test:
.
Hitting the language server for every key press can overload the server. Setting triggerWords
to explicitly invoke custom auto completion
is highly recommended. Note that symbols need to be escaped, e.g., \\.
, because these words will be used to compose a regex directly.
See javascript regex for more details.
The following is a complete example:
dash_ace.DashAceEditor(
id='input',
value='test(a: Integer) -> String := \n'
' return f"value is {a}"',
theme='github',
mode='norm',
syntaxKeywords=syntaxKeywords,
syntaxFolds=syntaxFolds,
tabSize=2,
enableBasicAutocompletion=True,
enableLiveAutocompletion=True,
autocompleter='/autocompleter?prefix=',
prefixLine=True,
triggerWords=[':', '\\.', '::'], # consult the completer for types, members and inheritances
placeholder='Norm code ...'
),
If the value is provided as an array of two strings, editor splits into two views to show the difference between two pieces of codes.
dash_ace.DashAceEditor(
id='input',
value=['test(a: Integer) -> String := \n return f"value is {a}"',
'test(a: Integer) -> String := return f"valus is not {a}"']
theme='github',
mode='norm',
syntaxKeywords=syntaxKeywords,
syntaxFolds=syntaxFolds,
tabSize=2,
orientation='below',
enableBasicAutocompletion=True,
enableLiveAutocompletion=True,
autocompleter='/autocompleter?prefix=',
prefixLine=True,
triggerWords=[':', '\\.', '::'], # consult the completer for types, members and inheritances
placeholder='Norm code ...'
),
The property orientation
sets the comparisons horizontal or vertical.
See CONTRIBUTING.md
Follow these instructions to develop dash ace
If you have selected install_dependencies during the prompt, you can skip this part.
Install npm packages
$ npm install
Create a virtual env and activate.
$ virtualenv venv
$ . venv/bin/activate
Note: venv\Scripts\activate for windows
Install python packages required to build components.
$ pip install -r requirements.txt
Install the python packages for testing (optional)
$ pip install -r tests/requirements.txt
src/lib/components/DashAceEditor.react.js
.src/demo
and you will import your example component code into your demo app.$ npm run build
$ npm start
usage.py
sample dash app:
$ python usage.py
tests/test_usage.py
, it will load usage.py
and you can then automate interactions with selenium.$ pytest tests
.dash_ace
).
MANIFEST.in
so that they get properly included when you're ready to publish your component._css_dist
dict in dash_ace/__init__.py
so dash will serve them automatically when the component suite is requested.FAQs
Dash Ace Editor Component with persistence
The npm package dash_ace_persistent receives a total of 0 weekly downloads. As such, dash_ace_persistent popularity was classified as not popular.
We found that dash_ace_persistent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.