diff --git a/app/assets/javascripts/admin/addon/components/ace-editor.js b/app/assets/javascripts/admin/addon/components/ace-editor.js index 58bd1f5295..06afc360e6 100644 --- a/app/assets/javascripts/admin/addon/components/ace-editor.js +++ b/app/assets/javascripts/admin/addon/components/ace-editor.js @@ -1,9 +1,12 @@ import Component from "@ember/component"; import getURL from "discourse-common/lib/get-url"; import loadScript from "discourse/lib/load-script"; +import I18n from "I18n"; import { observes } from "discourse-common/utils/decorators"; import { on } from "@ember/object/evented"; +const COLOR_VARS_REGEX = /\$(primary|secondary|tertiary|quaternary|header_background|header_primary|highlight|danger|success|love)(\s|;|-(low|medium|high))/g; + export default Component.extend({ mode: "css", classNames: ["ace-wrapper"], @@ -117,12 +120,18 @@ export default Component.extend({ bindKey: { mac: "cmd-s", win: "ctrl-s" }, }); } + + editor.on("blur", () => { + this.warnSCSSDeprecations(); + }); + editor.$blockScrolling = Infinity; editor.renderer.setScrollMargin(10, 10); this.element.setAttribute("data-editor", editor); this._editor = editor; this.changeDisabledState(); + this.warnSCSSDeprecations(); $(window) .off("ace:resize") @@ -140,6 +149,38 @@ export default Component.extend({ }); }, + warnSCSSDeprecations() { + if ( + this.mode !== "scss" || + this.editorId.startsWith("color_definitions") || + !this._editor + ) { + return; + } + + let warnings = this.content + .split("\n") + .map((line, row) => { + if (line.match(COLOR_VARS_REGEX)) { + return { + row, + column: 0, + text: I18n.t("admin.customize.theme.scss_warning_inline"), + type: "warning", + }; + } + }) + .filter(Boolean); + + this._editor.getSession().setAnnotations(warnings); + + this.setWarning( + warnings.length + ? I18n.t("admin.customize.theme.scss_color_variables_warning") + : false + ); + }, + actions: { focus() { if (this._editor) { diff --git a/app/assets/javascripts/admin/addon/components/admin-theme-editor.js b/app/assets/javascripts/admin/addon/components/admin-theme-editor.js index 9d2b0b70c9..36d861779a 100644 --- a/app/assets/javascripts/admin/addon/components/admin-theme-editor.js +++ b/app/assets/javascripts/admin/addon/components/admin-theme-editor.js @@ -6,6 +6,8 @@ import { isDocumentRTL } from "discourse/lib/text-direction"; import { next } from "@ember/runloop"; export default Component.extend({ + warning: null, + @discourseComputed("theme.targets", "onlyOverridden", "showAdvanced") visibleTargets(targets, onlyOverridden, showAdvanced) { return targets.filter((target) => { @@ -124,5 +126,9 @@ export default Component.extend({ save() { this.attrs.save(); }, + + setWarning(message) { + this.set("warning", message); + }, }, }); diff --git a/app/assets/javascripts/admin/addon/templates/components/admin-theme-editor.hbs b/app/assets/javascripts/admin/addon/templates/components/admin-theme-editor.hbs index 5efbb71db1..a309f9aba5 100644 --- a/app/assets/javascripts/admin/addon/templates/components/admin-theme-editor.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/admin-theme-editor.hbs @@ -87,4 +87,17 @@
{{error}}
{{/if}}
-{{ace-editor content=activeSection editorId=editorId mode=activeSectionMode autofocus="true" placeholder=placeholder htmlPlaceholder=true save=(action "save")}}
+{{#if warning}}
+ {{html-safe warning}}
+{{/if}}
+
+{{ace-editor
+ content=activeSection
+ editorId=editorId
+ mode=activeSectionMode
+ autofocus="true"
+ placeholder=placeholder
+ htmlPlaceholder=true
+ save=(action "save")
+ setWarning=(action "setWarning")
+}}
diff --git a/app/assets/stylesheets/common/admin/customize.scss b/app/assets/stylesheets/common/admin/customize.scss
index 8fe711b91c..47a5e43d7c 100644
--- a/app/assets/stylesheets/common/admin/customize.scss
+++ b/app/assets/stylesheets/common/admin/customize.scss
@@ -49,14 +49,19 @@
}
}
- .field-error {
+ .field-error,
+ .field-warning {
margin-top: 10px;
margin-bottom: 10px;
- background-color: var(--quaternary-low);
- padding: 5px;
+ background-color: var(--danger-low-mid);
+ padding: 10px;
white-space: pre-wrap;
}
+ .field-warning {
+ background-color: var(--highlight-low);
+ }
+
.admin-container {
padding-left: 10px;
padding-right: 10px;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index ec8c4ef243..3ee96c7bfb 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4358,6 +4358,8 @@ en:
yaml:
text: "YAML"
title: "Define theme settings in YAML format"
+ scss_color_variables_warning: "Using core SCSS color variables in themes is deprecated. Please use CSS custom properties instead. See this guide for more details."
+ scss_warning_inline: "Using core SCSS color variables in themes is deprecated."
colors:
select_base:
title: "Select base color palette"