util.cljs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. (ns frontend.handler.property.util
  2. "Utility fns for properties that are for both file and db graphs.
  3. Some fns like lookup and get-property were written to easily be backwards
  4. compatible with file graphs"
  5. (:require [frontend.db.conn :as conn]
  6. [frontend.state :as state]
  7. [logseq.db.common.property-util :as db-property-util]))
  8. (defn lookup
  9. "Get the property value by a built-in property's db-ident from block. For file and db graphs"
  10. [block key]
  11. (let [repo (state/get-current-repo)]
  12. (db-property-util/lookup repo block key)))
  13. (defn get-block-property-value
  14. "Get the value of a built-in block's property by its db-ident"
  15. [block db-ident]
  16. (let [repo (state/get-current-repo)
  17. db (conn/get-db repo)]
  18. (db-property-util/get-block-property-value repo db block db-ident)))
  19. (defn get-pid
  20. "Get a built-in property's id (db-ident or name) given its db-ident. For file and db graphs"
  21. [db-ident]
  22. (let [repo (state/get-current-repo)]
  23. (db-property-util/get-pid repo db-ident)))
  24. (defn block->shape [block]
  25. (get-block-property-value block :logseq.property.tldraw/shape))
  26. (defn page-block->tldr-page [block]
  27. (get-block-property-value block :logseq.property.tldraw/page))
  28. (defn shape-block?
  29. [block]
  30. (let [repo (state/get-current-repo)
  31. db (conn/get-db repo)]
  32. (db-property-util/shape-block? repo db block)))