Commit adbc2603 authored by Joachim Schunk's avatar Joachim Schunk

update reagent-dependency for "dom-node"

parent c44e1a04
(ns lernmeister.components.common
(:require [reagent.core :as reagent]
[reagent.dom :as rdom]
[cljsjs.katex]
[lernmeister.components.ui :as ui]
[lernmeister.components.static-content.images :refer [the-scream]]))
......@@ -40,7 +41,7 @@
[:span.red-text "✘ "]))
(defn binary-input [{:keys [default-bits result on-change-fn bitcount]
:or {bitcount 8}}]
:or {bitcount 8}}]
(let [bits (reagent/atom
(or default-bits
(vec (repeat (or bitcount 8) false))))
......@@ -50,44 +51,42 @@
(fn [this [_ {:as old-args}]]
(let [new-bitcount (:bitcount (reagent/props this))
old-bitcount (:bitcount old-args)]
(when (not= new-bitcount old-bitcount)
(reset! bits (mapv
#(if (< % (count @bits))
(get @bits %)
false)
(range bitcount))))))
:reagent-render
(fn [{:keys [default-bits result on-change-fn bitcount]}]
[:div.row {:style {:margin "auto auto auto auto" :display :inline-block}}
[:div.col.s12.center
[:p.flow-text.center
(when result
(if-not (pos? (:points result))
[wrong-tick]
[correct-tick]))]]
(when-not result
[:div.col.s12
[:div.row
[:div.columns {:key (hash bitcount)}
(doall (for [i (range bitcount #_(count @bits))]
[:div.column {:key (str id "-cb-" i)
:style {:display :inline-block}}
(if (get @bits i)
"1"
"0")[:br]
[ui/checkbox
{:id (str id "-cb-" i)
:type "checkbox"
:checked? (get @bits i)
:on-change #(do
(swap! bits update i not)
(on-change-fn @bits))}]]))]
[:p.is-pulled-left
[:acronym {:title "most significant bit"} "MSB"]]
[:p.is-pulled-right
[:acronym {:title "least significant bit"} "LSB"]
]]])])
})))
(when (not= new-bitcount old-bitcount)
(reset! bits (mapv
#(if (< % (count @bits))
(get @bits %)
false)
(range bitcount))))))
:reagent-render
(fn [{:keys [default-bits result on-change-fn bitcount]}]
[:div.row {:style {:margin "auto auto auto auto" :display :inline-block}}
[:div.col.s12.center
[:p.flow-text.center
(when result
(if-not (pos? (:points result))
[wrong-tick]
[correct-tick]))]]
(when-not result
[:div.col.s12
[:div.row
[:div.columns {:key (hash bitcount)}
(doall (for [i (range bitcount #_(count @bits))]
[:div.column {:key (str id "-cb-" i)
:style {:display :inline-block}}
(if (get @bits i)
"1"
"0") [:br]
[ui/checkbox
{:id (str id "-cb-" i)
:type "checkbox"
:checked? (get @bits i)
:on-change #(do
(swap! bits update i not)
(on-change-fn @bits))}]]))]
[:p.is-pulled-left
[:acronym {:title "most significant bit"} "MSB"]]
[:p.is-pulled-right
[:acronym {:title "least significant bit"} "LSB"]]]])])})))
(defn error-div [error]
(fn [error]
......@@ -107,7 +106,7 @@
(str code)])
(defn katex-render-in-element [element]
(let [node (reagent/dom-node element)]
(let [node (rdom/dom-node element)]
(when-let [latexstring (first (reagent/children element))]
(try
(js/katex.render latexstring node)
......@@ -133,7 +132,6 @@
[:br]
(str error)]])
(defn styles [style-urls]
[:<>
(for [su style-urls]
......
......@@ -3,9 +3,9 @@
[lernmeister.components.exercise-types.calculation.check
:refer [prefix-mapping prefix-set unit-set not-empty-or-minus]]
[reagent.core :as reagent]
[reagent.dom :as rdom]
[lernmeister.components.helper :refer [vec-remove]]))
(defn parse-unit [string]
(when (string? string)
(when-let [matched-string (re-matches #"^[a-zA-z]*" string)]
......@@ -34,7 +34,6 @@
(defn append-to-string-vec [arg append-string]
(update arg :string-vec conj append-string))
(defn add-number [arg]
(let [number (:number arg)]
(when (not-empty-or-minus number)
......@@ -82,7 +81,6 @@
(str "\\dfrac{" num-str-mod "}{" denominator-str "}"))))
""))
(defn add-units [arg]
(if (every-pred :with-units)
(append-to-string-vec arg (build-units-latex-string (:units arg)))
......@@ -110,7 +108,7 @@
(defn latex-span [latex-string]
(letfn [(katex-render [element]
(let [node (reagent/dom-node element)
(let [node (rdom/dom-node element)
latexstring (first (reagent/children element))]
(when-not (= nil latexstring)
(try
......@@ -125,8 +123,6 @@
:component-did-update
#(katex-render %)})))
(defn input-text-inline [answer & {:keys [value width label class disabled on-change]}]
(fn [answer & {:keys [value width label class disabled on-change]}]
[:div.input-field.inline
......@@ -137,4 +133,3 @@
:disabled disabled
:on-change #(on-change answer (-> % .-target .-value))}]
[:label.active label]]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment