Skip to content

Commit

Permalink
Bunch of fixes to think about in a bit
Browse files Browse the repository at this point in the history
Null references
Override style on paste
Save to slot repl function.
Fix bug with pasting colors
  • Loading branch information
prabhanshuguptagit committed Jul 1, 2024
1 parent b82b443 commit 2c84d9e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
16 changes: 13 additions & 3 deletions src/bean/functions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(remove #(every? nil? %) matrix))

(defn minimum-matrix [matrix]
(if (not (first (first matrix)))
(if (zero? (count (first matrix)))
[[nil]]
matrix))

Expand Down Expand Up @@ -124,7 +124,13 @@

new-selection
(->> (util/map-on-matrix
#(get first-match (:representation (util/get-cell (:grid sheet) %)))
#(let [value (:representation (util/get-cell (:grid sheet) %))]
(if (empty? value)
;; Hack for null references cells (to make it work like a left join)
;; return a null cell
;; but this breaks the renderer etc so we'll fix this later
[79 15]
(get first-match value)))
(:selection from-frame))
remove-nil-columns
remove-nil-rows)]
Expand All @@ -147,7 +153,11 @@
(and (contains? (:skips frame-result) %)
(contains? (:skips label-cells) %))) %))
remove-nil-columns
remove-nil-rows)]
remove-nil-rows
;; Hack for null references cells
;; these come from top left labels
(util/map-on-matrix
#(if-not % [79 15] %)))]
{:matrix (address-matrix->cells-matrix sheet (minimum-matrix new-selection))
:frame (merge frame-result {:selection new-selection})})
(errors/label-not-found
Expand Down
4 changes: 2 additions & 2 deletions src/bean/grid.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
(let [existing-cell (util/get-cell (:grid sheet*) address)
new-cell (-> existing-cell
(assoc :content (:content attrs))
(assoc :style (merge (:style existing-cell) (:style attrs))))
(assoc :style (:style attrs)))
new-sheet (eval-cell address sheet* new-cell true)]
(if (:merge-until attrs)
(merge-cells new-sheet
Expand Down Expand Up @@ -387,7 +387,7 @@
(defn clear-area [sheet {:keys [start end]}]
(->> (util/addresses-matrix start end)
(mapcat identity)
(map #(do [% {:content ""}]))
(map #(do [% {:content "" :style {}}]))
(into {})
(update-cells-bulk sheet start)))

Expand Down
3 changes: 2 additions & 1 deletion src/bean/ui/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ average:{x.sum() / x.count()}"))
(assoc :grid-dimensions {:num-rows num-rows
:num-cols num-cols
:row-heights (vec (repeat num-rows (:cell-h styles/sizes)))
:col-widths (vec (repeat num-cols (:cell-w styles/sizes)))}))
:col-widths (vec (repeat num-cols (:cell-w styles/sizes)))})
(assoc :frames {}))
:ui {:help-display false
:grid {:editing-cell nil
:selection nil
Expand Down
17 changes: 9 additions & 8 deletions src/bean/ui/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
[bean.ui.util :as util]
[day8.re-frame.undo :as undo :refer [undoable]]
[re-frame.core :as rf]
[reagent.core :as rc]))
[reagent.core :as rc]
[bean.area :as area]))

(rf/reg-event-db
::initialize-db
Expand Down Expand Up @@ -51,6 +52,13 @@
(fn clear-area [db [_ area]]
(update-in db [:sheet] #(grid/clear-area % area))))

(rf/reg-event-fx
::save-to-slot
;; for repl usage only
(fn set-demo [{:keys [db]} [_ frame-name]]
{:db (assoc-in db [:ui :current-demo-name] frame-name)
:fx [[:dispatch [::export-demos]]]}))

(rf/reg-event-fx
::export-demos
(fn [{:keys [db]} [_]]
Expand Down Expand Up @@ -254,12 +262,6 @@
(fn [db [_]]
(assoc-in db [:ui :grid :selection] nil)))

(rf/reg-event-fx
::select-frame
(fn select-frame [{:keys [db]} [_ frame-name]]
(let [{:keys [start]} (get-in db [:sheet :frames frame-name])]
(when start {:fx [[:dispatch [::edit-cell start]]]}))))

(rf/reg-event-fx
::make-frame
(undoable)
Expand All @@ -285,7 +287,6 @@

(rf/reg-event-db
::highlight-matrix
(undoable)
(fn highlight-matrix [db [_ content]]
(assoc-in db [:ui :grid :highlighted-cells]
(set (mapcat identity (get-in
Expand Down
2 changes: 1 addition & 1 deletion src/bean/ui/paste.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
[(when (get-in cell [:style :bold])
"font-weight: bold")
(when-let [bg (get-in cell [:style :background])]
(str "background: " (util/color-int->hex bg)))])}
(str "background: " (.toString bg 16)))])}
(when mc {:colspan (str (inc (- mc c)))})
(when mr {:rowspan (str (inc (- mr r)))}))
(:representation cell)])))
Expand Down

0 comments on commit 2c84d9e

Please sign in to comment.