Compare commits

..

No commits in common. "2eb5944a78f6153a75488e9d5a3e31f884f9f181" and "0919bdcbb5d731a9aee719a0c9625bd5844be2a3" have entirely different histories.

8 changed files with 59 additions and 178 deletions

View file

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

View file

@ -21,7 +21,6 @@
own clock, and a play goes out once with its frame rather than streamed."
(:require [arthur.events.collab :as collab]
[arthur.events.playback :as pb]
[arthur.events.ui :as ui]
[arthur.follow.page :as page]
[arthur.follow.party :as party]
[arthur.ui.menu :as menu]
@ -53,23 +52,14 @@
[:scroll "panel scroll" 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
;;
;; `[:presence :party]` and `[:presence :joinable]` are what we tell the room;
;; `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
;; (`:parked`), and `:last`, everything mates have said of where they are, to
;; catch up to on taking a facet back.
;; (`:parked`), and the last move a mate made, to catch up to on taking a facet
;; back.
(def ^:private stored {:joinable "arthur/followable" :off "arthur/follow-off"})
@ -129,26 +119,19 @@
;; taken only on the tab it was made on.
(fn [{:keys [db]} [_ cid v]]
(let [open (get v [:ui :open])
last (second (get-in db [:follow :last]))
place? (and (contains? v [:ui :open]) (not (contains? (off db) :place)))
taken (select-keys v (remove #{[:ui :open]} (paths db)))]
(cond
(not (party/mirrors? (:peers db) (me db) cid)) {}
(and place? (not (pb/openable? db open)))
{:db (update db :follow assoc :parked [cid v] :last [cid (merge last v)])}
{:db (update db :follow assoc :parked [cid v] :last [cid v])}
:else
(let [switch? (and place? (not= open (get-in db [:ui :open])))
db (cond-> (update db :follow assoc :parked nil :last [cid (merge last v)])
db (cond-> (update db :follow assoc :parked nil :last [cid v])
switch? (pb/open open))
;; In facet order, so `:selections` lands after the `:selection`
;; it belongs to.
db (cond-> db
(= (get v ::tab) (get-in db [:ui :open]))
(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))))
(as-> db (reduce-kv #(assoc-in %1 (at %1 %2) %3) db taken)))
n (pb/frames db)
f (-> (get-in db [:playback :frame] 0) (max 0) (min (dec n)))
db (assoc-in db [:playback :frame] f)]
@ -174,22 +157,19 @@
(rf/->interceptor
:id ::steer
:after (fn [ctx]
(let [after (get-in ctx [:effects :db])]
;; On your own, which is nearly always, an event costs this and
;; nothing more.
(if-not (and after (together? after))
ctx
(let [event (first (get-in ctx [:coeffects :event]))
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)])
(let [event (first (get-in ctx [:coeffects :event]))
before (get-in ctx [:coeffects :db])
after (get-in ctx [:effects :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 (#{::pb/tick ::moved} event)
(not= (get-in before [:project :id]) (get-in after [:project :id]))
(= (view before (paths after)) (view after))))
(update-in [:effects :fx] (fnil conj []) [::nav! (view-msg after)]))))))))
(not (or (nil? after) (#{::pb/tick ::moved} event)
(= (view before (paths after)) (view after))
(not= (get-in before [:project :id]) (get-in after [:project :id]))
(not (together? after))))
(update-in [:effects :fx] (fnil conj []) [::nav! (view-msg after)]))))))
;; ---------------------------------------------------------------------------
;; the room
@ -263,18 +243,15 @@
(rf/reg-event-fx
::toggle
;; 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.
;; Taking a facet back catches up to where the party last was.
(fn [{:keys [db]} [_ k]]
(let [was (off db)
now (if (contains? was k) (disj was k) (conj was k))
db (assoc-in db [:follow :off] now)
[cid v] (get-in db [:follow :last])]
db (assoc-in db [:follow :off] now)]
(cond-> {:db db ::remember [:off (.join (to-array (map name now)) ",")]}
(= :pointers k) (assoc ::forget :all)
(and (contains? was k) cid (facet-paths k))
(assoc :dispatch [::moved cid (select-keys v (conj (facet-paths k) ::tab))])))))
(and (contains? was k) (get-in db [:follow :last]))
(assoc :dispatch (into [::moved] (get-in db [:follow :last])))))))
(rf/reg-sub ::joinable? (fn [db _] (get-in db [:presence :joinable] true)))
(rf/reg-sub ::together? (fn [db _] (together? db)))

View file

@ -27,14 +27,6 @@
(defn- classes [^js el] (.getAttribute el "class"))
(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
"Which of `el`'s siblings that `same?` says are like it, it is."
[^js el same?]
@ -42,22 +34,22 @@
(filter same? (array-seq (.. el -parentElement -children))))))
(defn- step
"`el` as one step of a path, three ways from surest to least: by what it is
called, among its siblings called that; by its tag and classes; and by its tag
and FIRST class, because the rest come and go with state — `on`, `selected` —
and a row lit on one page is still the same row on the other."
"`el` as one step of a path: its tag and classes, which of its siblings with
those it is, and which of those with its tag and FIRST class. The pool and the
inspector are both a `section.pane`, so the first class alone takes one for
the other whenever a pane is shut on one page and not the other; but the rest
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]
(let [tag (.-localName el) cls (classes el) k (kind el) l (label el)]
(let [tag (.-localName el) cls (classes el) k (kind el)]
[tag cls
(nth-like el #(and (= tag (.-localName %)) (= cls (classes %))))
(nth-like el #(= k (kind %)))
l (when l (nth-like el #(= l (label %))))]))
(nth-like el #(= k (kind %)))]))
(defn- child [^js parent [tag cls n m l i]]
(defn- child [^js parent [tag cls n m]]
(let [kids (array-seq (.-children parent))
k [tag (not-empty (first (some-> cls (.split " "))))]]
(or (when l (nth (filter #(= l (label %)) kids) i nil))
(nth (filter #(and (= tag (.-localName %)) (= cls (classes %))) kids) n nil)
(or (nth (filter #(and (= tag (.-localName %)) (= cls (classes %))) kids) n nil)
(nth (filter #(= k (kind %)) kids) m nil))))
(defn- lineage
@ -102,7 +94,7 @@
;; drawing them
(defonce ^:private shown (atom {})) ; cid → {:msg :found :clip :xy :el}
(defonce ^:private ticking (atom nil)) ; [:frame id] or [:idle id]
(defonce ^:private raf (atom nil))
(defn- layer []
(or (.getElementById js/document "follow-layer")
@ -149,36 +141,18 @@
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])}))
(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! [_]
(tick!
(reduce
(fn [moving? [cid {:keys [found xy ^js el] :as s}]]
(let [s (cond-> s (not (.-isConnected ^js (peek found))) resolved)
{[tx ty] :xy :keys [lost? away?]} (target s)
;; Halfway there each frame: messages come every 40ms, frames every
;; 16, and a pointer that jumps between them looks like it stutters.
;; Within half a pixel, there.
[x y] (if (and xy (< 0.5 (js/Math.hypot (- tx (xy 0)) (- ty (xy 1)))))
[(+ (xy 0) (* 0.5 (- tx (xy 0)))) (+ (xy 1) (* 0.5 (- ty (xy 1))))]
[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)))
(doseq [[cid {:keys [found xy ^js el] :as s}] @shown]
(let [s (cond-> s (not (.-isConnected ^js (peek found))) resolved)
{[tx ty] :xy :keys [lost? away?]} (target s)
;; Halfway there each frame: messages come every 40ms, frames every
;; 16, and a pointer that jumps between them looks like it stutters.
[x y] (if xy [(+ (xy 0) (* 0.5 (- tx (xy 0)))) (+ (xy 1) (* 0.5 (- ty (xy 1))))] [tx ty])]
(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]))))
(reset! raf (when (seq @shown) (js/requestAnimationFrame frame!))))
(defn gone! [cid]
(some-> (get-in @shown [cid :el]) .remove)
@ -200,10 +174,7 @@
#js [#js {:transform "scale(.3)" :opacity 1} #js {:transform "scale(1.6)" :opacity 0}]
450))
(swap! shown assoc cid (-> (resolved m) (assoc :msg m :el el :xy (:xy was))))
(let [[how id] @ticking]
(when-not (= :frame how)
(some-> id js/clearTimeout)
(tick! true))))))
(when-not @raf (reset! raf (js/requestAnimationFrame frame!))))))
;; ---------------------------------------------------------------------------
;; scroll

View file

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

View file

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

View file

@ -79,20 +79,6 @@
(+ at (/ (or (clip/frames clip (node/source n)) 0) rate))
(clip/frames clip sid)))
(defn- shows
"Where on the ruler `n` has something to show, as `[from to)`, given `->open`
from its own frames to the ruler's; nil where it places nothing or shows
something across all of its span.
A SPAN IS NOT CONTENT. Lengthening a placement past the end of the symbol it
plays leaves the bar longer and the picture empty — `node/placed-frame` runs
out — so the row has to say where the symbol does. A held or looping
placement always has a frame to show, so only a playing one answers."
[clip n ->open]
(when-let [t (and (node/source n) (node/source-time n))]
(mapv (comp ->open (time->parent t))
[0 (or (clip/frames clip (node/source n)) 0)])))
(defn- node-label
"What to call a node in the label column.
@ -208,7 +194,6 @@
:expandable? true
:expanded? open?
:span cspan
:shows (shows clip child cself)
:key-items (key-items child sid cself)
:keys (into [] (comp (mapcat keyed-frames)
(map cself)
@ -257,7 +242,6 @@
(node-label clip (:id child) child))
:source (node/source child)
:span (mapv ->open (node/placed-span child))
:shows (shows clip child (comp ->open (local->parent child)))
:key-items (key-items child sid (comp ->open (local->parent child)))
:keys (into []
(comp (mapcat keyed-frames)
@ -322,7 +306,6 @@
:expandable? true
:expanded? open?
:span span
:shows (shows clip n self)
:key-items (key-items n sid self)
:keys (into [] (comp (mapcat keyed-frames)
(map self)
@ -345,7 +328,6 @@
(some-> (node/source child) name))
:source (node/source child)
:span (mapv source-self (node/placed-span child))
:shows (shows clip child (comp source-self (local->parent child)))
;; The clip's own keys, on the
;; block, so a collapsed lane
;; still says where it changes.
@ -1064,24 +1046,12 @@
(reset! gesture nil) (when @preview (reset! preview nil)))
:on-pointer-cancel (fn [e] (.stopPropagation e) (reset! gesture nil) (reset! preview nil))}])))
(defn- runout
"The stretches of a bar drawn from `in` to `out` where what it places has
nothing to show — see `shows` — as Flash draws empty frames: unfilled, inside
the outline of a clip that still lasts there."
[in out shows]
(when-let [[from to] shows]
(for [[a b] [[in (min out from)] [(max in to) out]]
:when (< a b)]
^{:key a}
[:span.tl-runout {:style {:left (str (* 100 (/ (- a in) (- out in))) "%")
:width (str (* 100 (/ (- b a) (- out in))) "%")}}])))
(defn- track-cell
"`sliding` is the gesture in flight: `{:row :path :kind :from :df}`, where
`:from` is the frame the press was on and `:df` how many frames the pointer has
moved since. What it looks like mid-drag is `[:ui :sliding]`, which the clip
every row and the stage are drawn from already has in it."
[{:keys [path span shows keys key-items gaps dense? kind node-kind select slides cels lane? of unmapped? owner]}
[{:keys [path span keys key-items gaps dense? kind node-kind select slides cels lane? of unmapped? owner]}
frames sliding hint {:keys [clip store open selection selections target-path key-selection key-preview key-anchor key-state key-elements choose-row!]}]
(let [selected-set (set selections)
active-row (:row @sliding)
@ -1343,7 +1313,6 @@
:on-pointer-down
(when (and select (not unmapped?))
#(begin! % (or slides path) :slide select nil nil))}
(runout in out shows)
(when (and select (not unmapped?))
[:span.tl-edge.in {:title "Drag start"
:on-pointer-down #(begin! % path :in select nil nil)}])
@ -1351,7 +1320,7 @@
[:span.tl-edge.out {:title "Drag endpoint · Shift-drag ripples later clips"
:on-pointer-down #(begin! % path :out select nil nil)}])]))
(doall
(for [[i {:keys [id label source span shows select ghost?]}]
(for [[i {:keys [id label source span select ghost?]}]
(map-indexed vector
(cond-> (vec cels)
(= select (:target-lane @sliding))
@ -1408,7 +1377,6 @@
{:selection select :label label
:in (js/Math.floor in)
:duration (- out in)}))}
(runout in out shows)
[:span.tl-cel-label label]
(when select
(if joined?
@ -1699,8 +1667,7 @@
(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))
[:section.pane.time
{:aria-label "timeline"
:tab-index -1
{:tab-index -1
:on-key-down (fn [e]
(when (and (= (.-target e) (.-currentTarget e))
(#{"Delete" "Backspace"} (.-key e)))

View file

@ -225,28 +225,6 @@
(is (= [[2 3]] (mapv :span (:cels lane)))
"a lane placed at twice the speed draws its frames 4–6 on ruler frames 2–3")))
(deftest a-bar-says-where-what-it-plays-runs-out
(let [placed {:id :short :kind :instance :z "a" :span [0 10]
:time {:at 6 :rate 1}
:source {:symbol :short}
:playback {:in 0 :speed 1 :end :stop}}
doc (-> (clip/blank)
(assoc-in [:symbols :main :frames] 24)
(assoc-in [:symbols :main :nodes] {:short placed})
(assoc-in [:symbols :short] {:id :short :frames 4 :nodes {}}))
row #(first (timeline/rows % :main #{}))]
(is (= [6 16] (:span (row doc))))
(is (= [6 10] (:shows (row doc)))
"four frames of symbol, stretched to ten, show from 6 to 10 only")
(is (nil? (:shows (row (assoc-in doc [:symbols :main :nodes :short :playback :speed] 0))))
"a held placement shows its frame across the whole span")
(let [lane (-> (assoc-in doc [:symbols :main :display] :lane)
(assoc-in [:symbols :main :nodes :short :playback :speed] 2)
(timeline/rows :main #{})
first)]
(is (= [[6 8]] (mapv :shows (:cels lane)))
"a clip in a lane says it too, at its own speed"))))
(deftest an-ordinary-symbol-keeps-a-row-per-node
(let [doc (update-in (fixture/document) [:symbols :main] dissoc :display)
rows (timeline/rows doc :main #{})]

View file

@ -1372,16 +1372,6 @@ button.followable svg { width: 12px; height: 12px; display: block; }
text-overflow: ellipsis;
pointer-events: none;
}
/* Frames of a clip past the end of what it plays: still the clip's — the outline
and the handles go on — but empty, as Flash leaves an empty frame unfilled. */
.tl-runout {
position: absolute;
top: 0;
bottom: 0;
background: repeating-linear-gradient(135deg, var(--pane) 0 3px, var(--sunk) 3px 6px);
pointer-events: none;
}
.tl-cel-label { position: relative; }
.tl-span.ghost {
background: transparent;
border: 1px dashed var(--sel);