Lazy load code-editor.js

This commit is contained in:
Tienson Qin
2020-10-09 00:41:53 +08:00
parent af7a08e544
commit 4a5a07c3ad
8 changed files with 65 additions and 36 deletions

View File

@@ -1,6 +1,5 @@
(ns frontend.extensions.code
(:require [rum.core :as rum]
[frontend.loader :as loader]
[frontend.config :as config]
[frontend.util :as util]
[frontend.mixins :as mixins]
@@ -44,22 +43,6 @@
(def from-text-area (gobj/get cm "fromTextArea"))
(defn highlight!
[state]
(let [[id attr] (:rum/args state)]
(when (:data-lang attr)
(when-let [element (js/document.getElementById id)]
(js/hljs.highlightBlock element)))))
(rum/defcs highlight < rum/reactive
{:did-mount (fn [state]
(highlight! state)
state)}
[state id attr code]
[:pre.code.pre-wrap-white-space
[:code (assoc attr :id id)
code]])
(defn render!
[state]
(let [[config id attr] (:rum/args state)
@@ -123,9 +106,3 @@
(get attr :data-lang "javascript")]
[:textarea (merge {:id id
:default-value code} attr)]])
(defn html-export
[attr code]
[:pre.pre-wrap-white-space
[:code attr
code]])