(defn
input-node-set-value
[node rendered-value dom-value component {:keys [on-write]}]
(if-not
(and
(identical? node ($ js/document :activeElement))
(has-selection-api? ($ node :type))
(string? rendered-value)
(string? dom-value))
(do
($! component :cljsDOMValue rendered-value)
($! node :value rendered-value)
(when (fn? on-write) (on-write rendered-value)))
(let
[node-value ($ node :value)]
(if
(not= node-value dom-value)
(batch/do-after-render
(fn* [] (input-component-set-value component)))
(let
[existing-offset-from-end
(- (count node-value) ($ node :selectionStart))
new-cursor-offset
(- (count rendered-value) existing-offset-from-end)]
($! component :cljsDOMValue rendered-value)
($! node :value rendered-value)
(when (fn? on-write) (on-write rendered-value))
($! node :selectionStart new-cursor-offset)
($! node :selectionEnd new-cursor-offset))))))