Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add AceWidget
Pacu2988d4e13ff35
diff --git a/saleor/static/dashboard/js/components/ace_widget.js b/saleor/static/dashboard/js/components/ace_widget.jsnew file mode 100644index 0000000000..1a3f9bf517--- /dev/null+++ b/saleor/static/dashboard/js/components/ace_widget.js@@ -0,0 +1,34 @@+import $ from 'jquery';+import ace from 'brace';++require('brace/mode/javascript');+require('brace/mode/html');+require('brace/theme/monokai');++function setEditor(editor, langMode) {+ editor.setTheme('ace/theme/monokai');+ editor.session.setUseWrapMode(true);+ editor.session.setMode(`ace/mode/${langMode}`);+ editor.setShowPrintMargin(false);+ editor.setHighlightActiveLine(true);+}++function setAceWidget(name) {+ const $textarea = $(`textarea[name='${name}']`);+ const aceEditor = ace.edit(name);+ const $editor = $(`#${name}`);+ const langMode = $editor.data('mode');+ aceEditor.$blockScrolling = Infinity;+ setEditor(aceEditor, langMode);+ aceEditor.session.setValue($textarea.val());+ aceEditor.session.on('change', () => {+ $textarea.text(aceEditor.getSession().getValue());+ });+}++$(document).ready(() => {+ const aceWidgets = $('.ace-editor');+ aceWidgets.each((index, element) => {+ setAceWidget(element.id);+ });+});diff --git a/templates/dashboard/includes/_ace.html b/templates/dashboard/includes/_ace.htmlnew file mode 100644index 0000000000..6fe9e8adad--- /dev/null+++ b/templates/dashboard/includes/_ace.html@@ -0,0 +1,10 @@+{% load staticfiles %}++<div id="{{ widget.name }}" class="ace-editor" data-mode="{{ widget.mode }}"></div>+<div class="textarea-hide">+ <textarea name="{{ widget.name }}" {% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value }}"{% endif %}{% endif %}{% endfor %}>+ {% if widget.value %}+ {{ widget.value }}+ {% endif %}+ </textarea>+</div>