1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- (ns microtables-frontend.subs
- (:require
- [re-frame.core :as re-frame]
- [microtables-frontend.utils :as utils]))
- (re-frame/reg-sub
- ::controls-state
- (fn [db]
- (println "reporting state of controls")
- (:controls db)))
- (defn highlight-cells
- "Modify all cells in data (set :view to :highlighted) that are within the given range."
- [data selection]
- (let [c1 (get-in selection [:start :col])
- r1 (get-in selection [:start :row])
- c2 (get-in selection [:end :col])
- r2 (get-in selection [:end :row])
- cells (utils/range->list c1 r1 c2 r2)]
- (loop [new-data data
- remaining cells]
- (if (empty? remaining)
- new-data
- (let [cur (first remaining)
- highlighted (assoc-in new-data [(:col cur) (:row cur) :view] :highlighted)]
- (recur highlighted (rest remaining)))))))
- ;TODO: insert other display mode data? ("value": formula (cursor), "display" (default): evaluated, "highlighted": in a selection (just a class?))
- (re-frame/reg-sub
- ::table-data
- (fn [db]
- (println "returning table data")
- (let [data (:table-data db)
- cursor (get-in db [:position :cursor])
- selection (get-in db [:position :selection])
- highlighted (if selection
- (highlight-cells data selection)
- data)]
- (if cursor
- (assoc-in highlighted [(:col cursor) (:row cursor) :view] :value)
- highlighted))))
|