-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
text.cljs
72 lines (70 loc) · 2.27 KB
/
text.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
(ns portal.ui.viewer.text
(:require [clojure.string :as str]
[portal.colors :as c]
[portal.ui.inspector :as ins]
[portal.ui.lazy :as l]
[portal.ui.state :as state]
[portal.ui.styled :as s]
[portal.ui.theme :as theme]
[reagent.core :as r]))
(defn inspect-text [value]
(let [theme (theme/use-theme)
state (state/use-state)
context (ins/use-context)
location (state/get-location context)
opts (ins/use-options)
background (ins/get-background)
search-text @(r/cursor state [:search-text location])]
[s/div
{:style
{:overflow :auto
:background background
:padding (:padding theme)
:box-sizing :border-box
:cursor :text
:border-radius (:border-radius theme)
:border [1 :solid (::c/border theme)]
:max-height (when-not (:expanded? opts) "24rem")}}
[s/table
[s/tbody
[l/lazy-seq
(->>
(str/split value #"\n")
(map-indexed
(fn [line line-content]
[(inc line) line-content]))
(filter
(fn [[_ line-content]]
(if search-text
(some
#(str/includes? line-content %)
(str/split search-text #"\s+"))
true)))
(map
(fn [[line line-content]]
[s/tr
{:key line}
[s/td
{:style
{:color (::c/number theme)
:background background
:font-size (:font-size theme)
:user-select :none
:text-align :right
:vertical-align :top
:padding-right (* 2 (:padding theme))}}
[s/span line]]
[s/td
{:style
{:color (::c/text theme)
:background background
:text-align :left
:font-size (:font-size theme)}}
[:pre {:style {:margin 0 :white-space :pre-wrap}}
[ins/highlight-words line-content]]]])))
{:default-take 100 :step 100}]]]]))
(def viewer
{:predicate string?
:component inspect-text
:name :portal.viewer/text
:doc "View string as a text file."})