mirror of https://github.com/logseq/logseq
Expand fix
parent
95ac09330c
commit
306128d2d7
|
@ -35,45 +35,49 @@
|
||||||
nodes))
|
nodes))
|
||||||
|
|
||||||
(defn collapse-non-heading!
|
(defn collapse-non-heading!
|
||||||
[all-headings id]
|
[id]
|
||||||
(when-let [node (gdom/getElement id)]
|
(when-let [node (gdom/getElement id)]
|
||||||
(let [children (next (array-seq (d/children node)))]
|
(let [children (next (array-seq (d/children node)))]
|
||||||
(doseq [node children]
|
(doseq [node children]
|
||||||
(d/hide! node)))))
|
(d/hide! node)))))
|
||||||
|
|
||||||
(defn expand-non-heading!
|
(defn expand-non-heading!
|
||||||
[all-headings id]
|
[id]
|
||||||
(when-let [node (gdom/getElement id)]
|
(when-let [node (gdom/getElement id)]
|
||||||
(let [children (next (array-seq (d/children node)))]
|
(let [children (next (array-seq (d/children node)))]
|
||||||
(doseq [node children]
|
(doseq [node children]
|
||||||
(d/show! node)))))
|
(d/show! node)))))
|
||||||
|
|
||||||
|
(defn conj-heading!
|
||||||
|
[heading-id]
|
||||||
|
(let [id (uuid (string/replace heading-id "ls-heading-parent-" ""))]
|
||||||
|
(swap! state/collapsed-headings conj id)))
|
||||||
|
(defn disj-heading!
|
||||||
|
[heading-id]
|
||||||
|
(let [id (uuid (string/replace heading-id "ls-heading-parent-" ""))]
|
||||||
|
(swap! state/collapsed-headings disj id)))
|
||||||
|
|
||||||
(defn collapse!
|
(defn collapse!
|
||||||
[headings-id heading-id]
|
[headings-id heading-id]
|
||||||
(let [all-headings (get-headings headings-id)]
|
(let [all-headings (get-headings headings-id)]
|
||||||
(collapse-non-heading! all-headings heading-id)
|
(collapse-non-heading! heading-id)
|
||||||
(when-let [node (gdom/getElement heading-id)]
|
(when-let [node (gdom/getElement heading-id)]
|
||||||
(let [children (get-heading-children all-headings node)]
|
(let [children (get-heading-children all-headings node)]
|
||||||
(doseq [node children]
|
(doseq [node children]
|
||||||
(let [id (uuid (string/replace (gobj/get node "id") "ls-heading-parent-" ""))]
|
(conj-heading! (gobj/get node "id"))
|
||||||
(prn {:id id})
|
|
||||||
(swap! state/collapsed-headings conj id))
|
|
||||||
(d/hide! node))))
|
(d/hide! node))))
|
||||||
(let [id (uuid (string/replace heading-id "ls-heading-parent-" ""))]
|
(conj-heading! heading-id)))
|
||||||
(swap! state/collapsed-headings conj id))))
|
|
||||||
|
|
||||||
(defn expand!
|
(defn expand!
|
||||||
[headings-id heading-id]
|
[headings-id heading-id]
|
||||||
(let [all-headings (get-headings headings-id)]
|
(let [all-headings (get-headings headings-id)]
|
||||||
(expand-non-heading! all-headings heading-id)
|
(expand-non-heading! heading-id)
|
||||||
(when-let [node (gdom/getElement heading-id)]
|
(when-let [node (gdom/getElement heading-id)]
|
||||||
(let [children (get-heading-children all-headings node)]
|
(let [children (get-heading-children all-headings node)]
|
||||||
(doseq [node children]
|
(doseq [node children]
|
||||||
(let [id (uuid (string/replace (gobj/get node "id") "ls-heading-parent-" ""))]
|
(disj-heading! (gobj/get node "id"))
|
||||||
(swap! state/collapsed-headings disj id))
|
|
||||||
(d/show! node))))
|
(d/show! node))))
|
||||||
(let [id (uuid (string/replace heading-id "ls-heading-parent-" ""))]
|
(disj-heading! heading-id)))
|
||||||
(swap! state/collapsed-headings disj id))))
|
|
||||||
|
|
||||||
(defn get-control-node
|
(defn get-control-node
|
||||||
[heading]
|
[heading]
|
||||||
|
@ -86,27 +90,21 @@
|
||||||
[id]
|
[id]
|
||||||
(let [all-headings (get-headings id)
|
(let [all-headings (get-headings id)
|
||||||
headings (next all-headings)]
|
headings (next all-headings)]
|
||||||
|
(when (seq headings)
|
||||||
(let [toggle-state @state/toggle-state]
|
(let [toggle-state @state/toggle-state]
|
||||||
(doseq [heading headings]
|
(doseq [heading headings]
|
||||||
(prn "control node: " (get-control-node heading))
|
|
||||||
(when-let [element (get-control-node heading)]
|
(when-let [element (get-control-node heading)]
|
||||||
(if toggle-state
|
(if toggle-state
|
||||||
;; expand
|
;; expand
|
||||||
(do
|
(do
|
||||||
(d/remove-class! element "caret-right")
|
(d/remove-class! element "caret-right")
|
||||||
|
(d/add-class! element "caret-down")
|
||||||
(expand! id (gobj/get heading "id")))
|
(expand! id (gobj/get heading "id")))
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(d/remove-class! element "caret-down")
|
(d/remove-class! element "caret-down")
|
||||||
(d/add-class! element "caret-right")
|
(d/add-class! element "caret-right")
|
||||||
(collapse! id (gobj/get heading "id"))))))
|
(collapse! id (gobj/get heading "id"))))))
|
||||||
(swap! state/toggle-state not)
|
|
||||||
(when toggle-state
|
(when toggle-state
|
||||||
(reset! state/collapsed-headings #{})))))
|
(reset! state/collapsed-headings #{}))
|
||||||
|
(swap! state/toggle-state not)))))
|
||||||
(comment
|
|
||||||
(def all-headings (get-headings "dGVzdC5vcmc="))
|
|
||||||
(def id "Ideas")
|
|
||||||
(collapse! all-headings id)
|
|
||||||
(expand! all-headings id)
|
|
||||||
)
|
|
||||||
|
|
|
@ -249,7 +249,7 @@
|
||||||
collapsed? (contains? collapsed-headings uuid)
|
collapsed? (contains? collapsed-headings uuid)
|
||||||
class "control block no-underline text-gray-700 hover:bg-gray-100 transition ease-in-out duration-150"
|
class "control block no-underline text-gray-700 hover:bg-gray-100 transition ease-in-out duration-150"
|
||||||
class (cond
|
class (cond
|
||||||
(and @control-show? collapsed?)
|
collapsed?
|
||||||
(str class " caret-right")
|
(str class " caret-right")
|
||||||
|
|
||||||
(and @control-show? (not collapsed?))
|
(and @control-show? (not collapsed?))
|
||||||
|
|
Loading…
Reference in New Issue