Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add WYSIWYG editor

dominik-zeglen2a3c6be1269c
diff --git a/package-lock.json b/package-lock.json
index 0ca6377c88..1bfae68732 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6602,6 +6602,11 @@
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
"dev": true
},
+ "medium-editor": {
+ "version": "5.23.3",
+ "resolved": "https://registry.npmjs.org/medium-editor/-/medium-editor-5.23.3.tgz",
+ "integrity": "sha512-he9/TdjX8f8MGdXGfCs8AllrYnqXJJvjNkDKmPg3aPW/uoIrlRqtkFthrwvmd+u4QyzEiadhCCM0EwTiRdUCJw=="
+ },
"mem": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz",
diff --git a/package.json b/package.json
index 92251e1e4e..0926fbf995 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,7 @@
"jquery": "^3.1.1",
"jquery.cookie": "^1.4.1",
"materialize-css": "^0.100.2",
+ "medium-editor": "^5.23.3",
"mobx": "^3.0.2",
"mobx-react": "^4.1.0",
"popper.js": "^1.12.5",
diff --git a/saleor/static/dashboard/js/components/misc.js b/saleor/static/dashboard/js/components/misc.js
index 35880e463f..4853272739 100644
--- a/saleor/static/dashboard/js/components/misc.js
+++ b/saleor/static/dashboard/js/components/misc.js
@@ -1,4 +1,5 @@
import SVGInjector from 'svg-injector-2';
+import MediumEditor from 'medium-editor';
import { initSelects } from './selects';
import { onScroll } from './utils';
@@ -59,6 +60,9 @@ $('#product-is-published').on('click', (e) => {
}
});
+// WYSIWYG editor
+const editor = new MediumEditor('#id_description');
+
// Styleguide sticky right menu
onScroll(() => $('.styleguide__menu').toggleClass('fixed', $(window).scrollTop() > 100));
diff --git a/saleor/static/dashboard/scss/components/_form.scss b/saleor/static/dashboard/scss/components/_form.scss
index a4bf33111e..97c1137a59 100644
--- a/saleor/static/dashboard/scss/components/_form.scss
+++ b/saleor/static/dashboard/scss/components/_form.scss
@@ -232,6 +232,16 @@
}
}
+.medium-editor-element {
+ padding-bottom: 1rem;
+ border-bottom: 1px $grey-color solid;
+ outline: none;
+ &:focus, &:active {
+ border-bottom-color: $secondary-color;
+ box-shadow: 2px 0 0 $secondary-color;
+ }
+}
+
.main form, .modal form {
@include form;
}
diff --git a/saleor/static/dashboard/scss/dashboard.scss b/saleor/static/dashboard/scss/dashboard.scss
index 4955751366..6436b42d58 100644
--- a/saleor/static/dashboard/scss/dashboard.scss
+++ b/saleor/static/dashboard/scss/dashboard.scss
@@ -3,6 +3,7 @@
@import "~materialize-css/sass/materialize";
@import "~dropzone/dist/dropzone";
@import "~select2/src/scss/core";
+@import "~medium-editor/src/sass/medium-editor";
@import "components/global";
@import "components/breadcrumbs";
diff --git a/saleor/static/dashboard/scss/variables.scss b/saleor/static/dashboard/scss/variables.scss
index cf1f75831d..b95df06e65 100644
--- a/saleor/static/dashboard/scss/variables.scss
+++ b/saleor/static/dashboard/scss/variables.scss
@@ -52,3 +52,12 @@ $timeline-circle-radius: 6px !default;
$timeline-event-margin: 1rem !default;
$timeline-date-width: 20rem;
$timeline-status-width: 12rem;
+
+/*** Medium Editor ***/
+$medium-editor-bgcolor: $off-black;
+$medium-editor-button-size: 40px;
+$medium-editor-button-active-text-color: #fff;
+$medium-editor-hover-color: $link-color;
+$medium-editor-link-color: #fff;
+$medium-editor-border-radius: 2px;
+$medium-editor-placeholder-color: $placeholder-text-color;
diff --git a/templates/product/details.html b/templates/product/details.html
index 8ceeaf7b1a..5fb2a6b007 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -166,7 +166,7 @@
<div class="product__info__description">
<h3>{% trans "Description" context "Product details title" %}</h3>
<hr>
- {{ product.description|markdown }}
+ {{ product.description|safe }}
</div>
<hr>
<table>