import { tracked } from "@glimmer/tracking"; import Component, { Input } from "@ember/component"; import { array, concat, fn } from "@ember/helper"; import { on } from "@ember/modifier"; import { action, computed } from "@ember/object"; import { LinkTo } from "@ember/routing"; import { next } from "@ember/runloop"; import { service } from "@ember/service"; import { gt, lte } from "truth-helpers"; import AceEditor from "discourse/components/ace-editor"; import icon from "discourse/helpers/d-icon"; import htmlSafe from "discourse/helpers/html-safe"; import { fmt } from "discourse/lib/computed"; import discourseComputed from "discourse/lib/decorators"; import { isDocumentRTL } from "discourse/lib/text-direction"; import { i18n } from "discourse-i18n"; const JS_DEFAULT_VALUE = `import { apiInitializer } from "discourse/lib/api"; export default apiInitializer((api) => { // Your code here }); `; const ADVANCED_TARGETS = ["desktop", "mobile"]; const ADVANCED_FIELDS = [ "embedded_scss", "embedded_header", "color_definitions", "body_tag", ]; export default class AdminThemeEditor extends Component { @service router; @tracked showAdvanced; @tracked onlyOverridden; @tracked currentTargetName; warning = null; @fmt("fieldName", "currentTargetName", "%@|%@") editorId; get visibleTargets() { return this.theme.targets.filter((target) => { if (target.edited) { return true; } if (!this.showAdvanced && ADVANCED_TARGETS.includes(target.name)) { return false; } if (!this.onlyOverridden) { return true; } }); } get visibleFields() { let fields = this.theme.fields[this.currentTargetName]; if (this.onlyOverridden) { fields = fields.filter((field) => field.edited); } if (!this.showAdvanced) { fields = fields.filter( (field) => field.edited || !ADVANCED_FIELDS.includes(field.name) ); } return fields; } get currentField() { return this.theme.fields[this.currentTargetName].find( (field) => field.name === this.fieldName ); } @discourseComputed("currentTargetName", "fieldName") activeSectionMode(targetName, fieldName) { if (fieldName === "color_definitions") { return "scss"; } if (fieldName === "js") { return "javascript"; } return fieldName && fieldName.includes("scss") ? "scss" : "html"; } @discourseComputed("currentTargetName", "fieldName") placeholder(targetName, fieldName) { if (fieldName && fieldName === "color_definitions") { const example = ":root {\n" + " --mytheme-tertiary-or-highlight: #{dark-light-choose($tertiary, $highlight)};\n" + "}"; return i18n("admin.customize.theme.color_definitions.placeholder", { example: isDocumentRTL() ? `
{{this.error}}
{{/if}}
{{#if this.warning}}
{{htmlSafe this.warning}}
{{/if}}