mirror of https://github.com/logseq/logseq
fix: use page-handler/<create! if possible
parent
7600a53929
commit
baefeaad5b
|
@ -183,8 +183,9 @@
|
|||
(reset! (:editor/create-page? @state/state) false))))
|
||||
|
||||
(defn rebuild-block-refs
|
||||
[repo conn db date-formatter block new-properties & {:keys [skip-content-parsing?]}]
|
||||
(let [property-key-refs (keys new-properties)
|
||||
[repo conn date-formatter block new-properties & {:keys [skip-content-parsing?]}]
|
||||
(let [db @conn
|
||||
property-key-refs (keys new-properties)
|
||||
property-value-refs (->> (vals new-properties)
|
||||
(mapcat (fn [v]
|
||||
(cond
|
||||
|
@ -192,7 +193,7 @@
|
|||
v
|
||||
|
||||
(uuid? v)
|
||||
(when-let [entity (d/entity conn [:block/uuid v])]
|
||||
(when-let [entity (d/entity db [:block/uuid v])]
|
||||
(let [from-property? (get-in entity [:block/metadata :created-from-property])]
|
||||
(if (and from-property? (not (contains? (:block/type entity) "closed value")))
|
||||
;; don't reference hidden block property values except closed values
|
||||
|
@ -216,9 +217,9 @@
|
|||
(concat property-refs content-refs)))
|
||||
|
||||
(defn- rebuild-refs
|
||||
[repo conn db date-formatter txs-state block m]
|
||||
[repo conn date-formatter txs-state block m]
|
||||
(when (sqlite-util/db-based-graph? repo)
|
||||
(let [refs (->> (rebuild-block-refs repo conn db date-formatter block (:block/properties block)
|
||||
(let [refs (->> (rebuild-block-refs repo conn date-formatter block (:block/properties block)
|
||||
:skip-content-parsing? true)
|
||||
(concat (:block/refs m))
|
||||
(concat (:block/tags m)))]
|
||||
|
@ -344,7 +345,7 @@
|
|||
(swap! txs-state conj
|
||||
(dissoc m :db/other-tx)))
|
||||
|
||||
(rebuild-refs repo conn db date-formatter txs-state block-entity m)
|
||||
(rebuild-refs repo conn date-formatter txs-state block-entity m)
|
||||
|
||||
this))
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
(-get-left [this conn])
|
||||
(-get-right [this conn])
|
||||
(-get-down [this conn])
|
||||
(-save [this db conn repo date-formatter])
|
||||
(-save [this txs-state conn repo date-formatter])
|
||||
(-del [this db children? conn])
|
||||
(-get-children [this conn]))
|
||||
|
||||
|
|
|
@ -498,16 +498,17 @@
|
|||
create-whiteboard? (= :whiteboard (:source-create item))
|
||||
create-page? (= :page (:source-create item))
|
||||
class (when create-class? (get-class-from-input @!input))]
|
||||
(cond
|
||||
create-class? (page-handler/create! class
|
||||
{:redirect? false
|
||||
:create-first-block? false
|
||||
:class? true})
|
||||
create-whiteboard? (whiteboard-handler/create-new-whiteboard-and-redirect! @!input)
|
||||
create-page? (page-handler/create! @!input {:redirect? true}))
|
||||
(if create-class?
|
||||
(state/pub-event! [:class/configure (db/entity [:block/name (util/page-name-sanity-lc class)])])
|
||||
(state/close-modal!))))
|
||||
(p/do!
|
||||
(cond
|
||||
create-class? (page-handler/<create! class
|
||||
{:redirect? false
|
||||
:create-first-block? false
|
||||
:class? true})
|
||||
create-whiteboard? (whiteboard-handler/create-new-whiteboard-and-redirect! @!input)
|
||||
create-page? (page-handler/<create! @!input {:redirect? true}))
|
||||
(if create-class?
|
||||
(state/pub-event! [:class/configure (db/entity [:block/name (util/page-name-sanity-lc class)])])
|
||||
(state/close-modal!)))))
|
||||
|
||||
(defn- get-filter-user-input
|
||||
[input]
|
||||
|
|
|
@ -109,11 +109,11 @@
|
|||
(common-util/safe-subs value (+ (count q) 4 pos)))]
|
||||
(state/set-edit-content! (.-id input) value')
|
||||
(state/clear-editor-action!)
|
||||
(let [page-name (util/page-name-sanity-lc chosen-item)
|
||||
page (db/entity [:block/name page-name])
|
||||
_ (when-not page (page-handler/create! chosen-item {:redirect? false
|
||||
:create-first-block? false}))
|
||||
current-block (state/get-edit-block)]
|
||||
(p/let [page-name (util/page-name-sanity-lc chosen-item)
|
||||
page (db/entity [:block/name page-name])
|
||||
_ (when-not page (page-handler/<create! chosen-item {:redirect? false
|
||||
:create-first-block? false}))
|
||||
current-block (state/get-edit-block)]
|
||||
(editor-handler/api-insert-new-block! chosen-item
|
||||
{:block-uuid (:block/uuid current-block)
|
||||
:sibling? true
|
||||
|
|
|
@ -32,15 +32,15 @@
|
|||
[frontend.components.property.util :as components-pu]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn- create-class-if-not-exists!
|
||||
(defn- <create-class-if-not-exists!
|
||||
[value]
|
||||
(when (string? value)
|
||||
(let [page-name (string/trim value)]
|
||||
(when-not (string/blank? page-name)
|
||||
(page-handler/create! page-name {:redirect? false
|
||||
:create-first-block? false
|
||||
:class? true})
|
||||
(pu/get-page-uuid page-name)))))
|
||||
(p/let [_ (page-handler/<create! page-name {:redirect? false
|
||||
:create-first-block? false
|
||||
:class? true})]
|
||||
(pu/get-page-uuid page-name))))))
|
||||
|
||||
(rum/defc class-select
|
||||
[*property-schema schema-classes {:keys [multiple-choices? save-property-fn]
|
||||
|
@ -86,16 +86,19 @@
|
|||
nil))}}
|
||||
multiple-choices?
|
||||
(assoc :on-apply (fn [choices]
|
||||
(let [choices' (map (fn [value] (or (create-class-if-not-exists! value) value)) choices)]
|
||||
(swap! *property-schema assoc :classes (set choices'))
|
||||
(save-property-fn)
|
||||
(p/let [choices' (p/all (map (fn [value]
|
||||
(p/let [result (<create-class-if-not-exists! value)]
|
||||
(or result value))) choices))
|
||||
_ (swap! *property-schema assoc :classes (set choices'))
|
||||
_ (save-property-fn)]
|
||||
(toggle-fn))))
|
||||
|
||||
(not multiple-choices?)
|
||||
(assoc :on-chosen (fn [value]
|
||||
(let [value' (or (create-class-if-not-exists! value) value)]
|
||||
(swap! *property-schema assoc :classes #{value'})
|
||||
(save-property-fn)
|
||||
(p/let [result (<create-class-if-not-exists! value)
|
||||
value' (or result value)
|
||||
_ (swap! *property-schema assoc :classes #{value'})
|
||||
_ (save-property-fn)]
|
||||
(toggle-fn)))))]
|
||||
|
||||
(select/select opts)))
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
[lambdaisland.glogi :as log]
|
||||
[rum.core :as rum]
|
||||
[frontend.handler.route :as route-handler]
|
||||
[frontend.handler.property.util :as pu]))
|
||||
[frontend.handler.property.util :as pu]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn- select-type?
|
||||
[property type]
|
||||
|
@ -96,15 +97,16 @@
|
|||
(fn [{:keys [toggle-fn]}]
|
||||
(ui/datepicker value' {:on-change (fn [_e date]
|
||||
(let [journal (date/js-date->journal-title date)]
|
||||
(when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
|
||||
(page-handler/create! journal {:redirect? false
|
||||
:create-first-block? false}))
|
||||
(when (fn? on-change)
|
||||
(on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
|
||||
(exit-edit-property)
|
||||
(toggle-fn)
|
||||
(when-let [toggle (:toggle-fn opts)]
|
||||
(toggle))))}))
|
||||
(p/do!
|
||||
(when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
|
||||
(page-handler/<create! journal {:redirect? false
|
||||
:create-first-block? false}))
|
||||
(when (fn? on-change)
|
||||
(on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
|
||||
(exit-edit-property)
|
||||
(toggle-fn)
|
||||
(when-let [toggle (:toggle-fn opts)]
|
||||
(toggle)))))}))
|
||||
{:modal-class (util/hiccup->class
|
||||
"origin-top-right.absolute.left-0.rounded-md.shadow-lg.mt-2")})))
|
||||
|
||||
|
@ -122,7 +124,7 @@
|
|||
(:block/uuid page))
|
||||
(exit-edit-property)))}))))
|
||||
|
||||
(defn- create-page-if-not-exists!
|
||||
(defn- <create-page-if-not-exists!
|
||||
[property classes page]
|
||||
(let [page* (string/trim page)
|
||||
[_ page inline-class] (or (seq (map string/trim (re-find #"(.*)#(.*)$" page*)))
|
||||
|
@ -135,15 +137,15 @@
|
|||
(or (pu/get-page-uuid inline-class)
|
||||
(do (log/error :msg "Given inline class does not exist" :inline-class inline-class)
|
||||
nil)))]
|
||||
(page-handler/create! page {:redirect? false
|
||||
:create-first-block? false
|
||||
:tags (if inline-class-uuid
|
||||
[inline-class-uuid]
|
||||
(p/let [_ (page-handler/<create! page {:redirect? false
|
||||
:create-first-block? false
|
||||
:tags (if inline-class-uuid
|
||||
[inline-class-uuid]
|
||||
;; Only 1st class b/c page normally has
|
||||
;; one of and not all these classes
|
||||
(take 1 classes))
|
||||
:class? class?})))
|
||||
[page id]))
|
||||
(take 1 classes))
|
||||
:class? class?})]
|
||||
[page id])))))
|
||||
|
||||
(defn- select-aux
|
||||
[block property {:keys [items selected-choices multiple-choices?] :as opts}]
|
||||
|
@ -241,17 +243,16 @@
|
|||
:input-opts input-opts})
|
||||
multiple-choices?
|
||||
(assoc :on-apply (fn [choices]
|
||||
(let [pages (->> choices
|
||||
(map #(create-page-if-not-exists! property string-classes %))
|
||||
(map first))
|
||||
values (set (map #(pu/get-page-uuid repo %) pages))]
|
||||
(p/let [result (p/all (map #(<create-page-if-not-exists! property string-classes %) choices))
|
||||
pages (map first result)
|
||||
values (set (map #(pu/get-page-uuid repo %) pages))]
|
||||
(when on-chosen (on-chosen values)))))
|
||||
(not multiple-choices?)
|
||||
(assoc :on-chosen (fn [chosen]
|
||||
(let [page* (string/trim (if (string? chosen) chosen (:value chosen)))]
|
||||
(when-not (string/blank? page*)
|
||||
(let [[page id] (create-page-if-not-exists! property string-classes page*)
|
||||
id' (or id (pu/get-page-uuid repo page))]
|
||||
(p/let [[page id] (<create-page-if-not-exists! property string-classes page*)
|
||||
id' (or id (pu/get-page-uuid repo page))]
|
||||
(when on-chosen (on-chosen id'))))))))]
|
||||
(select-aux block property opts')))
|
||||
|
||||
|
@ -306,6 +307,7 @@
|
|||
(when (= js/document.activeElement (gdom/getElement editor-id))
|
||||
(exit-edit-property false)))))
|
||||
|
||||
;; FIXME:
|
||||
(defn create-new-block!
|
||||
[block property value]
|
||||
(let [last-block-id (db-property-handler/create-property-text-block! block property value
|
||||
|
@ -315,14 +317,15 @@
|
|||
(exit-edit-property)
|
||||
(editor-handler/edit-block! (db/entity [:block/uuid last-block-id]) :max last-block-id)))
|
||||
|
||||
;; FIXME:
|
||||
(defn create-new-block-from-template!
|
||||
"`template`: tag block"
|
||||
[block property template]
|
||||
(let [repo (state/get-current-repo)
|
||||
{:keys [page blocks]} (db-property-handler/property-create-new-block-from-template block property template)]
|
||||
(db/transact! repo (if page (cons page blocks) blocks) {:outliner-op :insert-blocks})
|
||||
(add-property! block (:block/original-name property) (:block/uuid (last blocks)))
|
||||
(last blocks)))
|
||||
(p/let [_ (db/transact! repo (if page (cons page blocks) blocks) {:outliner-op :insert-blocks})
|
||||
_ (add-property! block (:block/original-name property) (:block/uuid (last blocks)))]
|
||||
(last blocks))))
|
||||
|
||||
(defn- new-text-editor-opts
|
||||
[repo block property value editor-id]
|
||||
|
|
|
@ -161,56 +161,59 @@
|
|||
file-path)]
|
||||
(if-not page
|
||||
(let [label (:filename pdf-current)]
|
||||
(page-handler/create! page-name {:redirect? false :create-first-block? false
|
||||
:split-namespace? false
|
||||
:format format
|
||||
;; FIXME: file and file-path properties for db version
|
||||
:properties {:file (case format
|
||||
:markdown
|
||||
(util/format "[%s](%s)" label url)
|
||||
(p/do!
|
||||
(page-handler/<create! page-name {:redirect? false :create-first-block? false
|
||||
:split-namespace? false
|
||||
:format format
|
||||
;; FIXME: file and file-path properties for db version
|
||||
:properties {:file (case format
|
||||
:markdown
|
||||
(util/format "[%s](%s)" label url)
|
||||
|
||||
:org
|
||||
(util/format "[[%s][%s]]" url label)
|
||||
:org
|
||||
(util/format "[[%s][%s]]" url label)
|
||||
|
||||
url)
|
||||
:file-path url}})
|
||||
(db-model/get-page page-name))
|
||||
url)
|
||||
:file-path url}})
|
||||
(db-model/get-page page-name)))
|
||||
|
||||
;; try to update file path
|
||||
(property-handler/add-page-property! page-name :file-path url))
|
||||
page)))
|
||||
;; try to update file path
|
||||
(do
|
||||
(property-handler/add-page-property! page-name :file-path url)
|
||||
page)))))
|
||||
|
||||
(defn ensure-ref-block!
|
||||
([pdf hl] (ensure-ref-block! pdf hl nil))
|
||||
([pdf-current {:keys [id content page properties]} insert-opts]
|
||||
(when-let [ref-page (and pdf-current (ensure-ref-page! pdf-current))]
|
||||
(let [ref-block (db-model/query-block-by-uuid id)]
|
||||
(if-not (nil? (:block/content ref-block))
|
||||
(do
|
||||
(println "[existed ref block]" ref-block)
|
||||
ref-block)
|
||||
(let [text (:text content)
|
||||
wrap-props #(if-let [stamp (:image content)]
|
||||
(assoc %
|
||||
(pu/get-pid :hl-type) :area
|
||||
(pu/get-pid :hl-stamp) stamp)
|
||||
%)
|
||||
props (cond->
|
||||
{(pu/get-pid :ls-type) :annotation
|
||||
(pu/get-pid :hl-page) page
|
||||
(pu/get-pid :hl-color) (:color properties)}
|
||||
(not (config/db-based-graph? (state/get-current-repo)))
|
||||
(p/let [ref-page (when pdf-current (ensure-ref-page! pdf-current))]
|
||||
(when ref-page
|
||||
(let [ref-block (db-model/query-block-by-uuid id)]
|
||||
(if-not (nil? (:block/content ref-block))
|
||||
(do
|
||||
(println "[existed ref block]" ref-block)
|
||||
ref-block)
|
||||
(let [text (:text content)
|
||||
wrap-props #(if-let [stamp (:image content)]
|
||||
(assoc %
|
||||
(pu/get-pid :hl-type) :area
|
||||
(pu/get-pid :hl-stamp) stamp)
|
||||
%)
|
||||
props (cond->
|
||||
{(pu/get-pid :ls-type) :annotation
|
||||
(pu/get-pid :hl-page) page
|
||||
(pu/get-pid :hl-color) (:color properties)}
|
||||
(not (config/db-based-graph? (state/get-current-repo)))
|
||||
;; force custom uuid
|
||||
(assoc (pu/get-pid :id) (str id)))
|
||||
properties (->>
|
||||
(wrap-props props)
|
||||
(property-handler/replace-key-with-id (state/get-current-repo)))]
|
||||
(when (string? text)
|
||||
(editor-handler/api-insert-new-block!
|
||||
text (merge {:page (:block/name ref-page)
|
||||
:custom-uuid id
|
||||
:properties properties}
|
||||
insert-opts)))))))))
|
||||
(assoc (pu/get-pid :id) (str id)))
|
||||
properties (->>
|
||||
(wrap-props props)
|
||||
(property-handler/replace-key-with-id (state/get-current-repo)))]
|
||||
(when (string? text)
|
||||
(editor-handler/api-insert-new-block!
|
||||
text (merge {:page (:block/name ref-page)
|
||||
:custom-uuid id
|
||||
:properties properties}
|
||||
insert-opts))))))))))
|
||||
|
||||
(defn del-ref-block!
|
||||
[{:keys [id]}]
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
(go
|
||||
(let [{:keys [page-name properties abstract-note]} (extractor/extract item)]
|
||||
(when-not (str/blank? page-name)
|
||||
;; FIXME:
|
||||
(if (db/page-exists? (str/lower-case page-name))
|
||||
(if (setting/setting :overwrite-mode?)
|
||||
(page-handler/delete!
|
||||
|
|
|
@ -35,14 +35,31 @@
|
|||
:as options}]
|
||||
(let [repo (state/get-current-repo)
|
||||
conn (db/get-db repo false)
|
||||
config (state/get-config repo)]
|
||||
(p/let [_ (worker-page/create! repo conn config title options)]
|
||||
(let [[_ page-name] (worker-page/get-title-and-pagename title)]
|
||||
(when redirect?
|
||||
(route-handler/redirect-to-page! page-name))
|
||||
(when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
|
||||
(block-handler/edit-block! first-block :max nil))
|
||||
page-name)))))
|
||||
config (state/get-config repo)
|
||||
_ (worker-page/create! repo conn config title options)
|
||||
[_ page-name] (worker-page/get-title-and-pagename title)]
|
||||
(when redirect?
|
||||
(route-handler/redirect-to-page! page-name))
|
||||
(when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
|
||||
(block-handler/edit-block! first-block :max nil))
|
||||
page-name)))
|
||||
|
||||
(defn <create!
|
||||
([title]
|
||||
(<create! title {}))
|
||||
([title {:keys [redirect?]
|
||||
:or {redirect? true}
|
||||
:as options}]
|
||||
(p/let [repo (state/get-current-repo)
|
||||
conn (db/get-db repo false)
|
||||
config (state/get-config repo)
|
||||
_ (worker-page/create! repo conn config title options)
|
||||
[_ page-name] (worker-page/get-title-and-pagename title)]
|
||||
(when redirect?
|
||||
(route-handler/redirect-to-page! page-name))
|
||||
(when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
|
||||
(block-handler/edit-block! first-block :max nil))
|
||||
page-name)))
|
||||
|
||||
;; favorite fns
|
||||
;; ============
|
||||
|
|
|
@ -69,9 +69,9 @@
|
|||
|
||||
(defn- rebuild-block-refs
|
||||
[repo block new-properties & opts]
|
||||
(let [db (db/get-db repo)
|
||||
(let [conn (db/get-db repo false)
|
||||
date-formatter (state/get-date-formatter)]
|
||||
(outliner-core/rebuild-block-refs repo db date-formatter block new-properties opts)))
|
||||
(outliner-core/rebuild-block-refs repo conn date-formatter block new-properties opts)))
|
||||
|
||||
(defn convert-property-input-string
|
||||
[schema-type v-str]
|
||||
|
|
|
@ -95,9 +95,10 @@
|
|||
parsed-blocks (->>
|
||||
(block/extract-blocks parsed-blocks "" :markdown {:page-name page-name})
|
||||
(mapv editor/wrap-parse-block))]
|
||||
(when (not (db/page-exists? page-name))
|
||||
(page-handler/create! page-name {:redirect? false}))
|
||||
(let [page-block (db/entity [:block/name (util/page-name-sanity-lc page-name)])
|
||||
(p/do!
|
||||
(when (not (db/page-exists? page-name))
|
||||
(page-handler/<create! page-name {:redirect? false}))
|
||||
(let [page-block (db/entity [:block/name (util/page-name-sanity-lc page-name)])
|
||||
children (:block/_parent page-block)
|
||||
blocks (db/sort-by-left children page-block)
|
||||
last-block (last blocks)
|
||||
|
@ -111,7 +112,7 @@
|
|||
parsed-blocks
|
||||
{:target-block target-block
|
||||
:sibling? sibling?})
|
||||
(finished-ok-handler [page-name])))))
|
||||
(finished-ok-handler [page-name]))))))
|
||||
|
||||
(defn create-page-with-exported-tree!
|
||||
"Create page from the per page object generated in `export-repo-as-edn-v2!`
|
||||
|
@ -127,39 +128,40 @@
|
|||
has-children? (seq children)
|
||||
page-format (or (some-> tree (:children) (first) (:format)) :markdown)
|
||||
whiteboard? (= type "whiteboard")]
|
||||
(try (page-handler/create! title {:redirect? false
|
||||
:format page-format
|
||||
:uuid uuid
|
||||
:create-first-block? false
|
||||
:properties properties
|
||||
:whiteboard? whiteboard?})
|
||||
(catch :default e
|
||||
(js/console.error e)
|
||||
(prn {:tree tree})
|
||||
(notification/show! (str "Error happens when creating page " title ":\n"
|
||||
e
|
||||
"\nSkipped and continue the remaining import.") :error)))
|
||||
(when has-children?
|
||||
(let [page-name (util/page-name-sanity-lc title)
|
||||
page-block (db/entity [:block/name page-name])]
|
||||
(p/do!
|
||||
(try (page-handler/<create! title {:redirect? false
|
||||
:format page-format
|
||||
:uuid uuid
|
||||
:create-first-block? false
|
||||
:properties properties
|
||||
:whiteboard? whiteboard?})
|
||||
(catch :default e
|
||||
(js/console.error e)
|
||||
(prn {:tree tree})
|
||||
(notification/show! (str "Error happens when creating page " title ":\n"
|
||||
e
|
||||
"\nSkipped and continue the remaining import.") :error)))
|
||||
(when has-children?
|
||||
(let [page-name (util/page-name-sanity-lc title)
|
||||
page-block (db/entity [:block/name page-name])]
|
||||
;; Missing support for per block format (or deprecated?)
|
||||
(try (if whiteboard?
|
||||
(try (if whiteboard?
|
||||
;; only works for file graph :block/properties
|
||||
(let [blocks (->> children
|
||||
(map (partial medley/map-keys (fn [k] (keyword "block" k))))
|
||||
(map gp-whiteboard/migrate-shape-block)
|
||||
(map #(merge % (gp-whiteboard/with-whiteboard-block-props % page-name))))]
|
||||
(db/transact! blocks))
|
||||
(editor/insert-block-tree children page-format
|
||||
{:target-block page-block
|
||||
:sibling? false
|
||||
:keep-uuid? true}))
|
||||
(catch :default e
|
||||
(js/console.error e)
|
||||
(prn {:tree tree})
|
||||
(notification/show! (str "Error happens when creating block content of page " title "\n"
|
||||
e
|
||||
"\nSkipped and continue the remaining import.") :error))))))
|
||||
(let [blocks (->> children
|
||||
(map (partial medley/map-keys (fn [k] (keyword "block" k))))
|
||||
(map gp-whiteboard/migrate-shape-block)
|
||||
(map #(merge % (gp-whiteboard/with-whiteboard-block-props % page-name))))]
|
||||
(db/transact! blocks))
|
||||
(editor/insert-block-tree children page-format
|
||||
{:target-block page-block
|
||||
:sibling? false
|
||||
:keep-uuid? true}))
|
||||
(catch :default e
|
||||
(js/console.error e)
|
||||
(prn {:tree tree})
|
||||
(notification/show! (str "Error happens when creating block content of page " title "\n"
|
||||
e
|
||||
"\nSkipped and continue the remaining import.") :error)))))))
|
||||
title)
|
||||
|
||||
(defn- pre-transact-uuids!
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
[frontend.handler.property :as property-handler]
|
||||
[frontend.handler.ui :as ui-handler]
|
||||
[frontend.handler.web.nfs :as web-nfs]
|
||||
[frontend.worker.handler.page :as worker-page]
|
||||
[frontend.worker.handler.page.rename :as worker-page-rename]
|
||||
[frontend.mobile.util :as mobile-util]
|
||||
[frontend.state :as state]
|
||||
|
@ -39,9 +40,11 @@
|
|||
[frontend.context.i18n :refer [t]]))
|
||||
|
||||
(def create! page-common-handler/create!)
|
||||
(def <create! page-common-handler/<create!)
|
||||
(def delete! page-common-handler/delete!)
|
||||
(def unfavorite-page! page-common-handler/unfavorite-page!)
|
||||
(def favorite-page! page-common-handler/favorite-page!)
|
||||
(def get-title-and-pagename worker-page/get-title-and-pagename)
|
||||
|
||||
;; FIXME: add whiteboard
|
||||
(defn- get-directory
|
||||
|
@ -232,30 +235,30 @@
|
|||
(subs q 1)
|
||||
q))
|
||||
last-pattern (str "#" (when wrapped? page-ref/left-brackets) last-pattern)]
|
||||
(when db-based?
|
||||
(let [tag (string/trim chosen)
|
||||
edit-block (state/get-edit-block)]
|
||||
(when (and (not (string/blank? tag)) (:block/uuid edit-block))
|
||||
(let [tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])]
|
||||
(when-not tag-entity
|
||||
(create! tag {:redirect? false
|
||||
:create-first-block? false
|
||||
:class? class?}))
|
||||
(when class?
|
||||
(let [repo (state/get-current-repo)
|
||||
tag-entity (or tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)]))
|
||||
tx-data [[:db/add [:block/uuid (:block/uuid edit-block)] :block/tags (:db/id tag-entity)]
|
||||
[:db/add [:block/uuid (:block/uuid edit-block)] :block/refs (:db/id tag-entity)]]]
|
||||
(db/transact! repo tx-data {:outliner-op :save-block})))))))
|
||||
(p/do!
|
||||
(when db-based?
|
||||
(let [tag (string/trim chosen)
|
||||
edit-block (state/get-edit-block)]
|
||||
(when (and (not (string/blank? tag)) (:block/uuid edit-block))
|
||||
(p/let [tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])
|
||||
_ (when-not tag-entity
|
||||
(<create! tag {:redirect? false
|
||||
:create-first-block? false
|
||||
:class? class?}))]
|
||||
(when class?
|
||||
(let [repo (state/get-current-repo)
|
||||
tag-entity (or tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)]))
|
||||
tx-data [[:db/add [:block/uuid (:block/uuid edit-block)] :block/tags (:db/id tag-entity)]
|
||||
[:db/add [:block/uuid (:block/uuid edit-block)] :block/refs (:db/id tag-entity)]]]
|
||||
(db/transact! repo tx-data {:outliner-op :save-block})))))))
|
||||
(editor-handler/insert-command! id
|
||||
(str "#" wrapped-tag)
|
||||
format
|
||||
{:last-pattern last-pattern
|
||||
:end-pattern (when wrapped? page-ref/right-brackets)
|
||||
:command :page-ref})
|
||||
|
||||
(editor-handler/insert-command! id
|
||||
(str "#" wrapped-tag)
|
||||
format
|
||||
{:last-pattern last-pattern
|
||||
:end-pattern (when wrapped? page-ref/right-brackets)
|
||||
:command :page-ref})
|
||||
|
||||
(when input (.focus input))))
|
||||
(when input (.focus input)))))
|
||||
(fn [chosen e]
|
||||
(util/stop e)
|
||||
(state/clear-editor-action!)
|
||||
|
@ -285,7 +288,7 @@
|
|||
template (state/get-default-journal-template)
|
||||
create-f (fn []
|
||||
(p/do!
|
||||
(create! title {:redirect? false
|
||||
(<create! title {:redirect? false
|
||||
:split-namespace? false
|
||||
:create-first-block? (not template)
|
||||
:journal? true
|
||||
|
|
|
@ -195,6 +195,7 @@
|
|||
:updated-at (util/time-ms),
|
||||
:created-at (util/time-ms)}]))
|
||||
|
||||
;; FIXME:
|
||||
(defn create-new-whiteboard-page!
|
||||
([]
|
||||
(create-new-whiteboard-page! nil))
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
[frontend.handler.page :as page-handler]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
[frontend.util.text :as text-util]))
|
||||
[frontend.util.text :as text-util]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn- is-tweet-link
|
||||
[url]
|
||||
|
@ -85,11 +86,11 @@
|
|||
(editor-handler/insert content)
|
||||
(editor-handler/insert (str "\n" content)))
|
||||
|
||||
(do
|
||||
(p/do!
|
||||
(editor-handler/escape-editing)
|
||||
(when (not= page (state/get-current-page))
|
||||
(page-handler/create! page {:redirect? redirect-page?}))
|
||||
;; Or else this will clear the newly inserted content
|
||||
(page-handler/<create! page {:redirect? redirect-page?}))
|
||||
;; Or else this will clear the newly inserted content
|
||||
(js/setTimeout #(editor-handler/api-insert-new-block! content {:page page
|
||||
:edit-block? true
|
||||
:replace-empty-target? true})
|
||||
|
|
|
@ -555,22 +555,24 @@
|
|||
|
||||
(def ^:export create_page
|
||||
(fn [name ^js properties ^js opts]
|
||||
(some-> (if-let [page (db-model/get-page name)]
|
||||
page
|
||||
(let [properties (bean/->clj properties)
|
||||
{:keys [redirect createFirstBlock format journal]} (bean/->clj opts)
|
||||
name (page-handler/create!
|
||||
name
|
||||
{:redirect? (if (boolean? redirect) redirect true)
|
||||
:journal? journal
|
||||
:create-first-block? (if (boolean? createFirstBlock) createFirstBlock true)
|
||||
:format format
|
||||
:properties properties})]
|
||||
(db-model/get-page name)))
|
||||
(:db/id)
|
||||
(db-utils/pull)
|
||||
(sdk-utils/normalize-keyword-for-json)
|
||||
(bean/->js))))
|
||||
(let [properties (bean/->clj properties)
|
||||
{:keys [redirect createFirstBlock format journal]} (bean/->clj opts)]
|
||||
(p/let [page (db-model/get-page name)
|
||||
new-page (when-not page
|
||||
(p/let [_ (page-handler/<create!
|
||||
name
|
||||
{:redirect? (if (boolean? redirect) redirect true)
|
||||
:journal? journal
|
||||
:create-first-block? (if (boolean? createFirstBlock) createFirstBlock true)
|
||||
:format format
|
||||
:properties properties})
|
||||
name (second (page-handler/get-title-and-pagename))]
|
||||
(db-model/get-page name)))]
|
||||
(some-> (or page new-page)
|
||||
:db/id
|
||||
(db-utils/pull)
|
||||
(sdk-utils/normalize-keyword-for-json)
|
||||
(bean/->js))))))
|
||||
|
||||
(def ^:export delete_page
|
||||
(fn [name]
|
||||
|
@ -605,45 +607,45 @@
|
|||
(fn [block-uuid-or-page-name content ^js opts]
|
||||
(when (string/blank? block-uuid-or-page-name)
|
||||
(throw (js/Error. "Page title or block UUID shouldn't be empty.")))
|
||||
(let [{:keys [before sibling focus customUUID properties]} (bean/->clj opts)
|
||||
[page-name block-uuid] (if (util/uuid-string? block-uuid-or-page-name)
|
||||
[nil (uuid block-uuid-or-page-name)]
|
||||
[block-uuid-or-page-name nil])
|
||||
page-name (when page-name (util/page-name-sanity-lc page-name))
|
||||
_ (when (and page-name (not (db/entity [:block/name page-name])))
|
||||
(page-handler/create! block-uuid-or-page-name {:create-first-block? false}))
|
||||
custom-uuid (or customUUID (:id properties))
|
||||
custom-uuid (when custom-uuid (sdk-utils/uuid-or-throw-error custom-uuid))
|
||||
edit-block? (if (nil? focus) true focus)
|
||||
_ (when (and custom-uuid (db-model/query-block-by-uuid custom-uuid))
|
||||
(throw (js/Error.
|
||||
(util/format "Custom block UUID already exists (%s)." custom-uuid))))
|
||||
block-uuid' (if (and (not sibling) before block-uuid)
|
||||
(let [block (db/entity [:block/uuid block-uuid])
|
||||
first-child (db-model/get-by-parent-&-left (db/get-db)
|
||||
(:db/id block)
|
||||
(:db/id block))]
|
||||
(if first-child
|
||||
(:block/uuid first-child)
|
||||
block-uuid))
|
||||
block-uuid)
|
||||
insert-at-first-child? (not= block-uuid' block-uuid)
|
||||
[sibling? before?] (if insert-at-first-child?
|
||||
[true true]
|
||||
[sibling before])
|
||||
before? (if (and (false? sibling?) before? (not insert-at-first-child?))
|
||||
false
|
||||
before?)
|
||||
new-block (editor-handler/api-insert-new-block!
|
||||
content
|
||||
{:block-uuid block-uuid'
|
||||
:sibling? sibling?
|
||||
:before? before?
|
||||
:edit-block? edit-block?
|
||||
:page page-name
|
||||
:custom-uuid custom-uuid
|
||||
:properties (merge properties
|
||||
(when custom-uuid {:id custom-uuid}))})]
|
||||
(p/let [{:keys [before sibling focus customUUID properties]} (bean/->clj opts)
|
||||
[page-name block-uuid] (if (util/uuid-string? block-uuid-or-page-name)
|
||||
[nil (uuid block-uuid-or-page-name)]
|
||||
[block-uuid-or-page-name nil])
|
||||
page-name (when page-name (util/page-name-sanity-lc page-name))
|
||||
_ (when (and page-name (not (db/entity [:block/name page-name])))
|
||||
(page-handler/<create! block-uuid-or-page-name {:create-first-block? false}))
|
||||
custom-uuid (or customUUID (:id properties))
|
||||
custom-uuid (when custom-uuid (sdk-utils/uuid-or-throw-error custom-uuid))
|
||||
edit-block? (if (nil? focus) true focus)
|
||||
_ (when (and custom-uuid (db-model/query-block-by-uuid custom-uuid))
|
||||
(throw (js/Error.
|
||||
(util/format "Custom block UUID already exists (%s)." custom-uuid))))
|
||||
block-uuid' (if (and (not sibling) before block-uuid)
|
||||
(let [block (db/entity [:block/uuid block-uuid])
|
||||
first-child (db-model/get-by-parent-&-left (db/get-db)
|
||||
(:db/id block)
|
||||
(:db/id block))]
|
||||
(if first-child
|
||||
(:block/uuid first-child)
|
||||
block-uuid))
|
||||
block-uuid)
|
||||
insert-at-first-child? (not= block-uuid' block-uuid)
|
||||
[sibling? before?] (if insert-at-first-child?
|
||||
[true true]
|
||||
[sibling before])
|
||||
before? (if (and (false? sibling?) before? (not insert-at-first-child?))
|
||||
false
|
||||
before?)
|
||||
new-block (editor-handler/api-insert-new-block!
|
||||
content
|
||||
{:block-uuid block-uuid'
|
||||
:sibling? sibling?
|
||||
:before? before?
|
||||
:edit-block? edit-block?
|
||||
:page page-name
|
||||
:custom-uuid custom-uuid
|
||||
:properties (merge properties
|
||||
(when custom-uuid {:id custom-uuid}))})]
|
||||
(bean/->js (sdk-utils/normalize-keyword-for-json new-block)))))
|
||||
|
||||
(def ^:export insert_batch_block
|
||||
|
@ -818,12 +820,12 @@
|
|||
|
||||
(defn ^:export prepend_block_in_page
|
||||
[uuid-or-page-name content ^js opts]
|
||||
(let [page? (not (util/uuid-string? uuid-or-page-name))
|
||||
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
|
||||
_ (and page-not-exist? (page-handler/create! uuid-or-page-name
|
||||
{:redirect? false
|
||||
:create-first-block? true
|
||||
:format (state/get-preferred-format)}))]
|
||||
(p/let [page? (not (util/uuid-string? uuid-or-page-name))
|
||||
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
|
||||
_ (and page-not-exist? (page-handler/<create! uuid-or-page-name
|
||||
{:redirect? false
|
||||
:create-first-block? true
|
||||
:format (state/get-preferred-format)}))]
|
||||
(when-let [block (db-model/get-page uuid-or-page-name)]
|
||||
(let [block' (if page? (second-child-of-block block) (first-child-of-block block))
|
||||
sibling? (and page? (not (nil? block')))
|
||||
|
@ -834,12 +836,12 @@
|
|||
|
||||
(defn ^:export append_block_in_page
|
||||
[uuid-or-page-name content ^js opts]
|
||||
(let [page? (not (util/uuid-string? uuid-or-page-name))
|
||||
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
|
||||
_ (and page-not-exist? (page-handler/create! uuid-or-page-name
|
||||
{:redirect? false
|
||||
:create-first-block? true
|
||||
:format (state/get-preferred-format)}))]
|
||||
(p/let [page? (not (util/uuid-string? uuid-or-page-name))
|
||||
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
|
||||
_ (and page-not-exist? (page-handler/<create! uuid-or-page-name
|
||||
{:redirect? false
|
||||
:create-first-block? true
|
||||
:format (state/get-preferred-format)}))]
|
||||
(when-let [block (db-model/get-page uuid-or-page-name)]
|
||||
(let [block' (last-child-of-block block)
|
||||
sibling? (not (nil? block'))
|
||||
|
|
Loading…
Reference in New Issue