DEV: Apply prettier, remove es6 extension

DEV: Apply prettier, remove es6 extension

diff --git a/javascripts/discourse/controllers/discourse-placeholder-builder.js b/javascripts/discourse/controllers/discourse-placeholder-builder.js
new file mode 100644
index 0000000..697f172
--- /dev/null
+++ b/javascripts/discourse/controllers/discourse-placeholder-builder.js
@@ -0,0 +1,47 @@
+import Controller from "@ember/controller";
+import ModalFunctionality from "discourse/mixins/modal-functionality";
+import EmberObject, { action } from "@ember/object";
+import { isBlank } from "@ember/utils";
+
+export default Controller.extend(ModalFunctionality, {
+  form: null,
+
+  onShow() {
+    this.set(
+      "form",
+      EmberObject.create({
+        key: null,
+        description: null,
+        values: [],
+      })
+    );
+  },
+
+  onClose() {},
+
+  @action
+  insertPlaceholder() {
+    if (isBlank(this.form.key)) {
+      bootbox.alert(I18n.t(themePrefix("builder.errors.no_key")));
+      return;
+    }
+
+    let output = `[wrap=placeholder key="${this.form.key}"`;
+
+    if (this.form.description) {
+      output = `${output} description="${this.form.description}"`;
+    }
+
+    if (this.form.values.length) {
+      if (this.form.values.length === 1) {
+        output = `${output} default="${this.form.values.firstObject}"`;
+      } else {
+        output = `${output} defaults="${this.form.values.join(",")}"`;
+      }
+    }
+
+    this.model.toolbarEvent.addText(`${output}][/wrap]`);
+
+    this.send("closeModal");
+  },
+});
diff --git a/javascripts/discourse/controllers/discourse-placeholder-builder.js.es6 b/javascripts/discourse/controllers/discourse-placeholder-builder.js.es6
deleted file mode 100644
index 610edb1..0000000
--- a/javascripts/discourse/controllers/discourse-placeholder-builder.js.es6
+++ /dev/null
@@ -1,47 +0,0 @@
-import Controller from "@ember/controller";
-import ModalFunctionality from "discourse/mixins/modal-functionality";
-import EmberObject, { action } from "@ember/object";
-import { isBlank } from "@ember/utils";
-
-export default Controller.extend(ModalFunctionality, {
-  form: null,
-
-  onShow() {
-    this.set(
-      "form",
-      EmberObject.create({
-        key: null,
-        description: null,
-        values: []
-      })
-    );
-  },
-
-  onClose() {},
-
-  @action
-  insertPlaceholder() {
-    if (isBlank(this.form.key)) {
-      bootbox.alert(I18n.t(themePrefix("builder.errors.no_key")));
-      return;
-    }
-
-    let output = `[wrap=placeholder key="${this.form.key}"`;
-
-    if (this.form.description) {
-      output = `${output} description="${this.form.description}"`;
-    }
-
-    if (this.form.values.length) {
-      if (this.form.values.length === 1) {
-        output = `${output} default="${this.form.values.firstObject}"`;
-      } else {
-        output = `${output} defaults="${this.form.values.join(",")}"`;
-      }
-    }
-
-    this.model.toolbarEvent.addText(`${output}][/wrap]`);
-
-    this.send("closeModal");
-  }
-});
diff --git a/javascripts/discourse/initializers/setup.js b/javascripts/discourse/initializers/setup.js
new file mode 100644
index 0000000..a84e1fc
--- /dev/null
+++ b/javascripts/discourse/initializers/setup.js
@@ -0,0 +1,263 @@
+import showModal from "discourse/lib/show-modal";
+import { withPluginApi } from "discourse/lib/plugin-api";
+import { later, debounce } from "@ember/runloop";
+import cookie, { removeCookie } from "discourse/lib/cookie";
+
+const VALID_TAGS =
+  "h1, h2, h3, h4, h5, h6, p, code, blockquote, .md-table, li p";
+const DELIMITER = "=";
+
+function buildInput(key, placeholder) {
+  const input = document.createElement("input");
+  input.classList.add("discourse-placeholder-value");
+  input.dataset.key = key;
+  input.dataset.delimiter = placeholder.delimiter;
+
+  if (placeholder.description) {
+    input.setAttribute("placeholder", placeholder.description);
+  }
+
+  if (placeholder.default) {
+    input.value = placeholder.default;
+  }
+
+  return input;
+}
+
+function addSelectOption(select, options = {}) {
+  const option = document.createElement("option");
+  option.classList.add("discourse-placeholder-option");
+  option.value = options.value;
+  option.text = options.description || options.value;
+
+  if (options.selected) {
+    option.setAttribute("selected", true);
+  }
+
+  select.appendChild(option);
+}
+
+function buildSelect(key, placeholder) {
+  const select = document.createElement("select");
+  select.classList.add("discourse-placeholder-select");
+  select.dataset.key = key;
+  select.dataset.delimiter = placeholder.delimiter;
+
+  if (placeholder.description) {
+    addSelectOption(select, {
+      value: "none",
+      description: placeholder.description,
+    });
+  }
+
+  placeholder.defaults.forEach((value) =>
+    addSelectOption(select, {
+      value,
+      selected: placeholder.default === value,
+    })
+  );
+
+  return select;
+}
+
+export default {
+  name: "discourse-placeholder-theme-component",
+
+  initialize() {
+    withPluginApi("0.8.7", (api) => {
+      api.decorateCooked(
+        ($cooked, postWidget) => {
+          if (!postWidget) return;
+
+          const postIdentifier = `d-placeholder-${postWidget.widget.attrs.topicId}-${postWidget.widget.attrs.id}-`;
+          const mappings = [];
+          const placeholders = {};
+
+          function processChange(inputEvent) {
+            const value = inputEvent.target.value;
+            const key = inputEvent.target.dataset.key;
+            const placeholder = placeholders[inputEvent.target.dataset.key];
+            const placeholderIdentifier = `${postIdentifier}${key}`;
+
+            if (value) {
+              if (value !== placeholder.default) {
+                cookie(placeholderIdentifier, value);
+              }
+            } else {
+              removeCookie(placeholderIdentifier);
+            }
+
+            let newValue;
+            if (value && value.length && value !== "none") {
+              newValue = value;
+            } else {
+              newValue = `${placeholder.delimiter}${key}${placeholder.delimiter}`;
+            }
+
+            $cooked.find(VALID_TAGS).each((index, elem) => {
+              const mapping = mappings[index];
+
+              if (!mapping) return;
+
+              let diff = 0;
+              let replaced = false;
+              let newInnnerHTML = elem.innerHTML;
+
+              mapping.forEach((m) => {
+                if (
+                  m.pattern !==
+                  `${placeholder.delimiter}${key}${placeholder.delimiter}`
+                ) {
+                  m.position = m.position + diff;
+                  return;
+                }
+
+                replaced = true;
+
+                const previousLength = m.length;
+                const prefix = newInnnerHTML.slice(0, m.position + diff);
+                const suffix = newInnnerHTML.slice(
+                  m.position + diff + m.length,
+                  newInnnerHTML.length
+                );
+                newInnnerHTML = `${prefix}${newValue}${suffix}`;
+
+                m.length = newValue.length;
+                m.position = m.position + diff;
+                diff = diff + newValue.length - previousLength;
+              });
+
+              if (replaced) elem.innerHTML = newInnnerHTML;
+            });
+          }
+
+          function processPlaceholders() {
+            mappings.length = 0;
+
+            const keys = Object.keys(placeholders);
+            const pattern = keys
+              .map((key) => {
+                const placeholder = placeholders[key];
+                return `(${placeholder.delimiter}${key}${placeholder.delimiter})`;
+              })
+              .join("|");
+            const regex = new RegExp(pattern, "g");
+
+            $cooked.find(VALID_TAGS).each((index, elem) => {
+              let match;
+
+              mappings[index] = mappings[index] || [];
+
+              while ((match = regex.exec(elem.innerHTML)) != null) {

[... diff too long, it was truncated ...]

GitHub sha: 6c43321b2860b31a2685823653c8d91f2bc8a880

This commit appears in #6 which was approved by jjaffeux. It was merged by davidtaylorhq.