mirror of
https://github.com/logseq/logseq.git
synced 2026-05-03 10:26:35 +00:00
wip add more tests
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
(ns frontend.handler.whiteboard
|
||||
(:require [frontend.state :as state]
|
||||
[clojure.string :as string]
|
||||
[frontend.db :as db]
|
||||
[frontend.db.model :as model]
|
||||
[goog.object :as gobj]))
|
||||
[clojure.string :as string]))
|
||||
|
||||
;; FIXME: embed /draw should be supported too
|
||||
(defn whiteboard-mode?
|
||||
@@ -29,49 +26,4 @@
|
||||
[{:id (.-id fs)
|
||||
:logseqLink page-or-block-id}])))))))
|
||||
|
||||
(defn- get-page-block [page-name]
|
||||
(db/pull '[*] (:db/id (model/get-page page-name))))
|
||||
|
||||
(defn- block->shape [block]
|
||||
(let [properties (:block/properties block)]
|
||||
(merge properties
|
||||
;; Use the block's id as the shape's id.
|
||||
{:id (str (:block/uuid block))})))
|
||||
|
||||
(defn- shape->block [blocks-by-uuid shape]
|
||||
(let [properties shape
|
||||
block (get blocks-by-uuid (:id shape))]
|
||||
(merge block
|
||||
{:properties properties})))
|
||||
|
||||
(defn get-whiteboard-cjs [page-name]
|
||||
(let [page-block (get-page-block page-name)
|
||||
blocks (model/get-page-blocks-no-cache page-name)]
|
||||
[page-block blocks]))
|
||||
|
||||
(defn whiteboard-cjs->tldr [page-block blocks]
|
||||
(let [shapes (map block->shape blocks)
|
||||
page-name (:block/name page-block)
|
||||
page-properties (:block/properties page-block)]
|
||||
(clj->js {:currentPageId page-name
|
||||
:pages [(merge page-properties
|
||||
{:id "page"
|
||||
:name "page"
|
||||
:shapes shapes})]})))
|
||||
|
||||
(defn page-name->tldr [page-name]
|
||||
(let [[page-block blocks] (get-whiteboard-cjs page-name)]
|
||||
(whiteboard-cjs->tldr page-block blocks)))
|
||||
|
||||
(defn transact-tldr! [page-name tldr]
|
||||
(let [[page-block blocks] (get-whiteboard-cjs page-name)
|
||||
{:keys [pages]} (js->clj tldr)
|
||||
page (first pages) ;; should only contain one page
|
||||
shapes (:shapes page)
|
||||
blocks-by-uuid (reduce (fn [acc shape]
|
||||
(assoc (:id shape) shape acc))
|
||||
blocks {})
|
||||
blocks (map #(shape->block blocks-by-uuid %) shapes)]
|
||||
[page-block blocks]))
|
||||
|
||||
;; (set! (. js/window -foo) (page-name->tldr "edn-test"))
|
||||
|
||||
Reference in New Issue
Block a user