enhance(rtc): update schema :sibling? to :pos

pull/11102/head
rcmerci 2024-03-01 16:53:37 +08:00
parent 90576661f3
commit d3c1e08516
3 changed files with 13 additions and 7 deletions

View File

@ -21,6 +21,12 @@
(into #{} (map first) general-attrs-schema-coll))
(def block-type-schema [:enum "property" "class" "whiteboard" "hidden" "closed value"])
(def block-pos-schema
":sibling: sibling of target-block(:target-uuid)
:child: child of target-block(:target-uuid)
:no-order: this block doesn't have :block/left attr"
[:enum :sibling :child :no-order])
(def to-ws-op-schema
[:multi {:dispatch first :decode/string #(update % 0 keyword)}
@ -29,7 +35,7 @@
[:map
[:block-uuid :uuid]
[:target-uuid :uuid]
[:sibling? :boolean]]]]
[:pos block-pos-schema]]]]
[:remove
[:cat :keyword
[:map
@ -40,7 +46,7 @@
[:map
[:block-uuid :uuid]
[:target-uuid {:optional true} :uuid]
[:sibling? {:optional true} :boolean]
[:pos {:optional true} block-pos-schema]
[:content {:optional true} :string]
[:updated-at {:optional true} :int]
[:created-at {:optional true} :int]

View File

@ -562,8 +562,8 @@
[_ & {:keys [parent-uuid left-uuid block-uuid *remote-ops *depend-on-block-uuid-set]}]
(when parent-uuid
(let [target-uuid (or left-uuid parent-uuid)
sibling? (not= left-uuid parent-uuid)]
(swap! *remote-ops conj [:move {:block-uuid block-uuid :target-uuid target-uuid :sibling? sibling?}])
pos (if (not= left-uuid parent-uuid) :sibling :child)]
(swap! *remote-ops conj [:move {:block-uuid block-uuid :target-uuid target-uuid :pos pos}])
(swap! *depend-on-block-uuid-set conj target-uuid))))
(defmethod local-block-ops->remote-ops-aux :update-op
@ -592,7 +592,7 @@
(seq add*) (assoc :add add*)
(seq retract) (assoc :retract retract))))
target-uuid (or left-uuid parent-uuid)
sibling? (not= left-uuid parent-uuid)]
pos (if (not= left-uuid parent-uuid) :sibling :child)]
(swap! *remote-ops conj
[:update
(cond-> {:block-uuid block-uuid}
@ -611,7 +611,7 @@
(and (contains? attr-map :link)
(:block/uuid (:block/link block)))
(assoc :link (:block/uuid (:block/link block)))
target-uuid (assoc :target-uuid target-uuid :sibling? sibling?))])))
target-uuid (assoc :target-uuid target-uuid :pos pos))])))
(defmethod local-block-ops->remote-ops-aux :update-page-op
[_ & {:keys [conn block-uuid *remote-ops]}]

View File

@ -32,7 +32,7 @@
(let [r (rtc-const/to-ws-ops-decoder
(rtc-core/sort-remote-ops
(rtc-core/gen-block-uuid->remote-ops repo conn)))]
(is (rtc-const/to-ws-ops-validator r))
(is (rtc-const/to-ws-ops-validator r) r)
r))]
(testing "create a new page"
(page-handler/create! page1-name {:redirect? false :create-first-block? false :uuid page1-uuid})