-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
web.cljs
114 lines (95 loc) · 2.58 KB
/
web.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(ns portal.web
(:require [clojure.set :as set]
[portal.runtime :as rt]
[portal.runtime.web.client :as c]
[portal.runtime.web.launcher :as l]
[portal.shortcuts :as shortcuts]
[portal.spec :as s]))
(def ^:export send! l/send!)
(defn ^:export submit
"Tap target function."
[value]
(rt/update-value value)
nil)
(defn ^:export ^{:deprecated "0.9"} tap
"Add portal as a tap> target."
[]
(add-tap #'submit)
nil)
(def ^:private long->short
{:portal.colors/theme :theme
:portal.launcher/app :app
:portal.launcher/host :host
:portal.launcher/port :port
:portal.launcher/window-title :window-title})
(defn- rename [options]
(set/rename-keys options long->short))
(defn set-defaults!
"Set default options for `open`.
Parameters passed directly to either will override defaults."
{:added "0.20.0"
:see-also ["open"]}
[options]
(swap! rt/default-options merge (rename options)))
(defn ^:export open
"Open a new inspector window."
([] (open nil))
([options]
(s/assert-options options)
(l/open (rename options))))
(defn inspect
"Open a new portal window to inspect a particular value.
- value: a value to inspect.
- options: see `portal.web/open` for options."
{:command true
:added "0.50.0"
:see-also ["open"]}
([value]
(open {:value value}))
([value options]
(open (assoc options :value value))))
(defn ^:export close
"Close all current inspector windows."
[]
(l/close)
nil)
(defn ^:export clear
"Clear all values."
[]
(l/clear)
nil)
(defn register!
"Register a var with portal. For now, the var should be a 1 arity fn.
Example: `(register! #'identity)`
The function name and doc string will show up in the command palette."
{:added "0.20.0"}
[var]
(rt/register! var)
nil)
(defn eval-str
"Evaluate ClojureScript source given as a string in the UI runtime."
{:added "0.19.0"}
([code]
(eval-str :all code nil))
([_portal code opts]
(let [result (l/eval-str (assoc opts :code code))]
(cond-> result (not (:verbose opts)) :value))))
(defn sessions
"Get all current portal sessions."
{:added "0.27.0"}
[]
(c/sessions))
(defonce ^:private init? (atom false))
(defn- init []
(when-not @init?
(reset! init? true)
(l/init @rt/default-options)
(shortcuts/add!
::init
(fn [log]
(when (shortcuts/match?
{::shortcuts/osx #{"meta" "shift" "o"}
::shortcuts/default #{"control" "shift" "o"}}
log)
(open))))))
(js/setTimeout init 0)