A pointer finds what it points at by name; following takes a tool as a tool

A step of a pointer's path is matched first by what the element is called —
its id, aria-label or a field's name — then by its classes. The pool, the
inspector and the timeline say which pane they are, so a path names the
inspector rather than the second section.pane.

Taking a facet back catches up on that facet alone, not on everything a
mate last said: their frame has moved on since if they are playing. A
mate's tool and selection are taken through the app's own functions, so a
tool change finishes your open pen polygon as it would if you made it.
On your own, an event no longer builds the shared view twice to find out
nobody is listening, and a pointer that has arrived is redrawn four times
a second rather than every frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Olive Vaughn 2026-10-11 13:51:09 -04:00
parent 0919bdcbb5
commit fce76dfaa6
6 changed files with 112 additions and 57 deletions

View file

@ -665,16 +665,17 @@
(declare finishing-polygon) (declare finishing-polygon)
(rf/reg-event-db (defn with-tool
::set-tool "`db` on `tool`. Leaving the pen commits what it was drawing, as Esc does: an
;; Leaving the pen commits what it was drawing, as Esc does: an unfinished unfinished polygon is not a thing the document can hold."
;; polygon is not a thing the document can hold. [db tool]
(fn [db [_ tool]] (if (contains? tools tool)
(if (contains? tools tool) (-> (if (= tool (get-in db [:ui :tool])) db (finishing-polygon db))
(-> (if (= tool (get-in db [:ui :tool])) db (finishing-polygon db)) (update :ui merge {:tool tool :draft []})
(update :ui merge {:tool tool :draft []}) (update :ui dissoc :hover))
(update :ui dissoc :hover)) db))
db)))
(rf/reg-event-db ::set-tool (fn [db [_ tool]] (with-tool db tool)))
(rf/reg-event-db (rf/reg-event-db
::cancel-polygon ::cancel-polygon

View file

@ -21,6 +21,7 @@
own clock, and a play goes out once with its frame rather than streamed." own clock, and a play goes out once with its frame rather than streamed."
(:require [arthur.events.collab :as collab] (:require [arthur.events.collab :as collab]
[arthur.events.playback :as pb] [arthur.events.playback :as pb]
[arthur.events.ui :as ui]
[arthur.follow.page :as page] [arthur.follow.page :as page]
[arthur.follow.party :as party] [arthur.follow.party :as party]
[arthur.ui.menu :as menu] [arthur.ui.menu :as menu]
@ -52,14 +53,23 @@
[:scroll "panel scroll" nil] [:scroll "panel scroll" nil]
[:pointers "pointers" nil]]) [:pointers "pointers" nil]])
(defn- facet-paths [k] (some (fn [[fk _ ps]] (when (= fk k) ps)) facets))
(def ^:private takes
"Values taken the way the app takes them, not written over, because writing
would skip what it does on the way: a new tool commits the pen's unfinished
polygon, and a selection carries the multi-selection along with it."
{[:ui :tool] ui/with-tool
[:ui :selection] ui/selected})
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------
;; what we keep ;; what we keep
;; ;;
;; `[:presence :party]` and `[:presence :joinable]` are what we tell the room; ;; `[:presence :party]` and `[:presence :joinable]` are what we tell the room;
;; `collab` says them again when the socket comes back, which is the rejoin. ;; `collab` says them again when the socket comes back, which is the rejoin.
;; `:follow` is ours alone: the facets let go of, a move we could not take yet ;; `:follow` is ours alone: the facets let go of, a move we could not take yet
;; (`:parked`), and the last move a mate made, to catch up to on taking a facet ;; (`:parked`), and `:last`, everything mates have said of where they are, to
;; back. ;; catch up to on taking a facet back.
(def ^:private stored {:joinable "arthur/followable" :off "arthur/follow-off"}) (def ^:private stored {:joinable "arthur/followable" :off "arthur/follow-off"})
@ -119,19 +129,26 @@
;; taken only on the tab it was made on. ;; taken only on the tab it was made on.
(fn [{:keys [db]} [_ cid v]] (fn [{:keys [db]} [_ cid v]]
(let [open (get v [:ui :open]) (let [open (get v [:ui :open])
last (second (get-in db [:follow :last]))
place? (and (contains? v [:ui :open]) (not (contains? (off db) :place))) place? (and (contains? v [:ui :open]) (not (contains? (off db) :place)))
taken (select-keys v (remove #{[:ui :open]} (paths db)))] taken (select-keys v (remove #{[:ui :open]} (paths db)))]
(cond (cond
(not (party/mirrors? (:peers db) (me db) cid)) {} (not (party/mirrors? (:peers db) (me db) cid)) {}
(and place? (not (pb/openable? db open))) (and place? (not (pb/openable? db open)))
{:db (update db :follow assoc :parked [cid v] :last [cid v])} {:db (update db :follow assoc :parked [cid v] :last [cid (merge last v)])}
:else :else
(let [switch? (and place? (not= open (get-in db [:ui :open]))) (let [switch? (and place? (not= open (get-in db [:ui :open])))
db (cond-> (update db :follow assoc :parked nil :last [cid v]) db (cond-> (update db :follow assoc :parked nil :last [cid (merge last v)])
switch? (pb/open open)) switch? (pb/open open))
;; In facet order, so `:selections` lands after the `:selection`
;; it belongs to.
db (cond-> db db (cond-> db
(= (get v ::tab) (get-in db [:ui :open])) (= (get v ::tab) (get-in db [:ui :open]))
(as-> db (reduce-kv #(assoc-in %1 (at %1 %2) %3) db taken))) (as-> db (reduce (fn [db p]
(if (contains? taken p)
((takes p #(assoc-in %1 (at %1 p) %2)) db (taken p))
db))
db (paths db))))
n (pb/frames db) n (pb/frames db)
f (-> (get-in db [:playback :frame] 0) (max 0) (min (dec n))) f (-> (get-in db [:playback :frame] 0) (max 0) (min (dec n)))
db (assoc-in db [:playback :frame] f)] db (assoc-in db [:playback :frame] f)]
@ -157,19 +174,22 @@
(rf/->interceptor (rf/->interceptor
:id ::steer :id ::steer
:after (fn [ctx] :after (fn [ctx]
(let [event (first (get-in ctx [:coeffects :event])) (let [after (get-in ctx [:effects :db])]
before (get-in ctx [:coeffects :db]) ;; On your own, which is nearly always, an event costs this and
after (get-in ctx [:effects :db]) ;; nothing more.
[_ v :as parked] (get-in after [:follow :parked])] (if-not (and after (together? after))
(cond-> ctx ctx
(and parked (pb/openable? after (get v [:ui :open]))) (let [event (first (get-in ctx [:coeffects :event]))
(update-in [:effects :fx] (fnil conj []) [:dispatch (into [::moved] parked)]) before (get-in ctx [:coeffects :db])
[_ v :as parked] (get-in after [:follow :parked])]
(cond-> ctx
(and parked (pb/openable? after (get v [:ui :open])))
(update-in [:effects :fx] (fnil conj []) [:dispatch (into [::moved] parked)])
(not (or (nil? after) (#{::pb/tick ::moved} event) (not (or (#{::pb/tick ::moved} event)
(= (view before (paths after)) (view after)) (not= (get-in before [:project :id]) (get-in after [:project :id]))
(not= (get-in before [:project :id]) (get-in after [:project :id])) (= (view before (paths after)) (view after))))
(not (together? after)))) (update-in [:effects :fx] (fnil conj []) [::nav! (view-msg after)]))))))))
(update-in [:effects :fx] (fnil conj []) [::nav! (view-msg after)]))))))
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------
;; the room ;; the room
@ -243,15 +263,18 @@
(rf/reg-event-fx (rf/reg-event-fx
::toggle ::toggle
;; Taking a facet back catches up to where the party last was. ;; Taking a facet back catches up on that facet — and only that one: the rest
;; of what they last said is as old as it is, and their frame, say, has moved
;; on since if they are playing.
(fn [{:keys [db]} [_ k]] (fn [{:keys [db]} [_ k]]
(let [was (off db) (let [was (off db)
now (if (contains? was k) (disj was k) (conj was k)) now (if (contains? was k) (disj was k) (conj was k))
db (assoc-in db [:follow :off] now)] db (assoc-in db [:follow :off] now)
[cid v] (get-in db [:follow :last])]
(cond-> {:db db ::remember [:off (.join (to-array (map name now)) ",")]} (cond-> {:db db ::remember [:off (.join (to-array (map name now)) ",")]}
(= :pointers k) (assoc ::forget :all) (= :pointers k) (assoc ::forget :all)
(and (contains? was k) (get-in db [:follow :last])) (and (contains? was k) cid (facet-paths k))
(assoc :dispatch (into [::moved] (get-in db [:follow :last]))))))) (assoc :dispatch [::moved cid (select-keys v (conj (facet-paths k) ::tab))])))))
(rf/reg-sub ::joinable? (fn [db _] (get-in db [:presence :joinable] true))) (rf/reg-sub ::joinable? (fn [db _] (get-in db [:presence :joinable] true)))
(rf/reg-sub ::together? (fn [db _] (together? db))) (rf/reg-sub ::together? (fn [db _] (together? db)))

View file

@ -27,6 +27,14 @@
(defn- classes [^js el] (.getAttribute el "class")) (defn- classes [^js el] (.getAttribute el "class"))
(defn- kind [^js el] [(.-localName el) (.. el -classList (item 0))]) (defn- kind [^js el] [(.-localName el) (.. el -classList (item 0))])
(defn- label
"What `el` is called, if anything says: an id, an aria-label, a field's name.
Written for people and screen readers, so it says WHICH thing it is — the
inspector, not the second `section.pane` — and it does not change when the
layout does."
[^js el]
(some (fn [a] (some->> (.getAttribute el a) not-empty (str a "="))) ["id" "aria-label" "name"]))
(defn- nth-like (defn- nth-like
"Which of `el`'s siblings that `same?` says are like it, it is." "Which of `el`'s siblings that `same?` says are like it, it is."
[^js el same?] [^js el same?]
@ -34,22 +42,22 @@
(filter same? (array-seq (.. el -parentElement -children)))))) (filter same? (array-seq (.. el -parentElement -children))))))
(defn- step (defn- step
"`el` as one step of a path: its tag and classes, which of its siblings with "`el` as one step of a path, three ways from surest to least: by what it is
those it is, and which of those with its tag and FIRST class. The pool and the called, among its siblings called that; by its tag and classes; and by its tag
inspector are both a `section.pane`, so the first class alone takes one for and FIRST class, because the rest come and go with state — `on`, `selected` —
the other whenever a pane is shut on one page and not the other; but the rest and a row lit on one page is still the same row on the other."
come and go with state — `on`, `selected` — and a row lit on one page is still
the same row on the other, so that is what a step falls back to."
[^js el] [^js el]
(let [tag (.-localName el) cls (classes el) k (kind el)] (let [tag (.-localName el) cls (classes el) k (kind el) l (label el)]
[tag cls [tag cls
(nth-like el #(and (= tag (.-localName %)) (= cls (classes %)))) (nth-like el #(and (= tag (.-localName %)) (= cls (classes %))))
(nth-like el #(= k (kind %)))])) (nth-like el #(= k (kind %)))
l (when l (nth-like el #(= l (label %))))]))
(defn- child [^js parent [tag cls n m]] (defn- child [^js parent [tag cls n m l i]]
(let [kids (array-seq (.-children parent)) (let [kids (array-seq (.-children parent))
k [tag (not-empty (first (some-> cls (.split " "))))]] k [tag (not-empty (first (some-> cls (.split " "))))]]
(or (nth (filter #(and (= tag (.-localName %)) (= cls (classes %))) kids) n nil) (or (when l (nth (filter #(= l (label %)) kids) i nil))
(nth (filter #(and (= tag (.-localName %)) (= cls (classes %))) kids) n nil)
(nth (filter #(= k (kind %)) kids) m nil)))) (nth (filter #(= k (kind %)) kids) m nil))))
(defn- lineage (defn- lineage
@ -94,7 +102,7 @@
;; drawing them ;; drawing them
(defonce ^:private shown (atom {})) ; cid → {:msg :found :clip :xy :el} (defonce ^:private shown (atom {})) ; cid → {:msg :found :clip :xy :el}
(defonce ^:private raf (atom nil)) (defonce ^:private ticking (atom nil)) ; [:frame id] or [:idle id]
(defn- layer [] (defn- layer []
(or (.getElementById js/document "follow-layer") (or (.getElementById js/document "follow-layer")
@ -141,18 +149,36 @@
cx (max l (min r x)) cy (max t (min b y))] cx (max l (min r x)) cy (max t (min b y))]
{:xy [cx cy] :lost? (< d (count path)) :away? (not= [x y] [cx cy])})) {:xy [cx cy] :lost? (< d (count path)) :away? (not= [x y] [cx cy])}))
(declare frame!)
(defn- tick!
"Draw again: next frame while a pointer is on its way, and four times a
second once they have all arrived — only to notice a layout that moved
under one, a pane opened or a list scrolled, which no message announces."
[moving?]
(reset! ticking (cond (empty? @shown) nil
moving? [:frame (js/requestAnimationFrame frame!)]
:else [:idle (js/setTimeout frame! 250)])))
(defn- frame! [_] (defn- frame! [_]
(doseq [[cid {:keys [found xy ^js el] :as s}] @shown] (tick!
(let [s (cond-> s (not (.-isConnected ^js (peek found))) resolved) (reduce
{[tx ty] :xy :keys [lost? away?]} (target s) (fn [moving? [cid {:keys [found xy ^js el] :as s}]]
;; Halfway there each frame: messages come every 40ms, frames every (let [s (cond-> s (not (.-isConnected ^js (peek found))) resolved)
;; 16, and a pointer that jumps between them looks like it stutters. {[tx ty] :xy :keys [lost? away?]} (target s)
[x y] (if xy [(+ (xy 0) (* 0.5 (- tx (xy 0)))) (+ (xy 1) (* 0.5 (- ty (xy 1))))] [tx ty])] ;; Halfway there each frame: messages come every 40ms, frames every
(set! (.. el -style -transform) (str "translate(" x "px," y "px)")) ;; 16, and a pointer that jumps between them looks like it stutters.
(.toggle (.-classList el) "lost" lost?) ;; Within half a pixel, there.
(.toggle (.-classList el) "away" away?) [x y] (if (and xy (< 0.5 (js/Math.hypot (- tx (xy 0)) (- ty (xy 1)))))
(swap! shown assoc cid (assoc s :xy [x y])))) [(+ (xy 0) (* 0.5 (- tx (xy 0)))) (+ (xy 1) (* 0.5 (- ty (xy 1))))]
(reset! raf (when (seq @shown) (js/requestAnimationFrame frame!)))) [tx ty])]
(when (not= xy [x y])
(set! (.. el -style -transform) (str "translate(" x "px," y "px)")))
(.toggle (.-classList el) "lost" lost?)
(.toggle (.-classList el) "away" away?)
(swap! shown assoc cid (assoc s :xy [x y]))
(or moving? (not= [x y] [tx ty]))))
false @shown)))
(defn gone! [cid] (defn gone! [cid]
(some-> (get-in @shown [cid :el]) .remove) (some-> (get-in @shown [cid :el]) .remove)
@ -174,7 +200,10 @@
#js [#js {:transform "scale(.3)" :opacity 1} #js {:transform "scale(1.6)" :opacity 0}] #js [#js {:transform "scale(.3)" :opacity 1} #js {:transform "scale(1.6)" :opacity 0}]
450)) 450))
(swap! shown assoc cid (-> (resolved m) (assoc :msg m :el el :xy (:xy was)))) (swap! shown assoc cid (-> (resolved m) (assoc :msg m :el el :xy (:xy was))))
(when-not @raf (reset! raf (js/requestAnimationFrame frame!)))))) (let [[how id] @ticking]
(when-not (= :frame how)
(some-> id js/clearTimeout)
(tick! true))))))
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------
;; scroll ;; scroll

View file

@ -937,7 +937,7 @@
;; the open symbol; the open symbol itself is at no path at all. ;; the open symbol; the open symbol itself is at no path at all.
path (if placed (or (nth selection 3 nil) [(second node)]) []) path (if placed (or (nth selection 3 nil) [(second node)]) [])
a-face? (and face (face? clip face) (not layer?))] a-face? (and face (face? clip face) (not layer?))]
[:section.pane.params [:section.pane.params {:aria-label "inspector"}
[:div.pane-head "inspector"] [:div.pane-head "inspector"]
[:div.inspect [:div.inspect
(cond (cond

View file

@ -698,7 +698,8 @@
tallies (counts ctx) tallies (counts ctx)
files? (fn [^js e] (some #{"Files"} (array-seq (.. e -dataTransfer -types))))] files? (fn [^js e] (some #{"Files"} (array-seq (.. e -dataTransfer -types))))]
[:section.pane.pool [:section.pane.pool
{:class (when (pos? @depth) "dropping") {:aria-label "media pool"
:class (when (pos? @depth) "dropping")
;; Only a FILE lights the pane up: a row dragged out of the pool is on ;; Only a FILE lights the pane up: a row dragged out of the pool is on
;; its way somewhere else. ;; its way somewhere else.
:on-drag-enter (fn [^js e] (when (files? e) (.preventDefault e) (swap! depth inc))) :on-drag-enter (fn [^js e] (when (files? e) (.preventDefault e) (swap! depth inc)))

View file

@ -1667,7 +1667,8 @@
(when (not= [clip-id open] @key-context) (when (not= [clip-id open] @key-context)
(reset! key-context [clip-id open]) (reset! key-selection []) (reset! key-preview nil) (reset! key-anchor nil) (reset! row-anchor nil)) (reset! key-context [clip-id open]) (reset! key-selection []) (reset! key-preview nil) (reset! key-anchor nil) (reset! row-anchor nil))
[:section.pane.time [:section.pane.time
{:tab-index -1 {:aria-label "timeline"
:tab-index -1
:on-key-down (fn [e] :on-key-down (fn [e]
(when (and (= (.-target e) (.-currentTarget e)) (when (and (= (.-target e) (.-currentTarget e))
(#{"Delete" "Backspace"} (.-key e))) (#{"Delete" "Backspace"} (.-key e)))