@charmland/gem 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +13 -0
- package/README.md +24 -2
- package/assets/fonts/Hypography-Italic.woff2 +0 -0
- package/assets/fonts/Hypography-Regular.woff2 +0 -0
- package/assets/fonts/PPFraktionMono-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionMonoItalic-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSans-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSansItalic-Variable.ttf +0 -0
- package/bin/gem-elm.js +3 -0
- package/dist/browser/boot.d.ts +10 -0
- package/dist/browser/boot.js +14 -0
- package/dist/browser/color-scheme.d.ts +9 -0
- package/dist/browser/color-scheme.js +76 -0
- package/dist/browser/ports.d.ts +37 -0
- package/dist/browser/ports.js +90 -0
- package/dist/browser/router.d.ts +5 -0
- package/dist/browser/router.js +35 -0
- package/dist/browser/runtime.d.ts +12 -0
- package/dist/browser/runtime.js +22 -0
- package/dist/browser/tabs.d.ts +9 -0
- package/dist/browser/tabs.js +69 -0
- package/dist/default/theme.css +4664 -0
- package/dist/default/theme.js +13815 -0
- package/dist/node/build.d.ts +16 -0
- package/dist/node/build.js +48 -0
- package/dist/node/cli.d.ts +2 -0
- package/dist/node/cli.js +21 -0
- package/elm.json +28 -0
- package/package.json +86 -4
- package/src/app/Gem/App.elm +1268 -0
- package/src/app/Gem/CharmSticker.elm +35 -0
- package/src/app/Gem/Components.elm +292 -0
- package/src/app/Gem/Main.elm +17 -0
- package/src/app/Gem/Ports.elm +32 -0
- package/src/app/Gem/Shell.elm +957 -0
- package/src/browser/theme.d.ts +1 -0
- package/src/core/Gem/Node.elm +219 -0
- package/src/core/Gem/Page.elm +560 -0
- package/src/core/Gem/Render.elm +510 -0
- package/src/core/Gem/Slots.elm +11 -0
- package/src/styles/docs.scss +1083 -0
- package/src/styles/fonts.scss +51 -0
- package/src/styles/gem.scss +362 -0
- package/src/styles/theme.scss +8 -0
- package/src/styles/ui/burger.scss +272 -0
- package/src/styles/ui/button.scss +350 -0
- package/src/styles/ui/charmtone.scss +70 -0
- package/src/styles/ui/controls-extra.scss +316 -0
- package/src/styles/ui/controls.scss +110 -0
- package/src/styles/ui/display.scss +359 -0
- package/src/styles/ui/dropdown.scss +341 -0
- package/src/styles/ui/form.scss +314 -0
- package/src/styles/ui/menu.scss +200 -0
- package/src/styles/ui/meter.scss +124 -0
- package/src/styles/ui/modal.scss +545 -0
- package/src/styles/ui/oauth.scss +50 -0
- package/src/styles/ui/page-nav.scss +63 -0
- package/src/styles/ui/reset.scss +111 -0
- package/src/styles/ui/scrollbar.scss +39 -0
- package/src/styles/ui/search.scss +164 -0
- package/src/styles/ui/sidebar.scss +229 -0
- package/src/styles/ui/squircle.scss +60 -0
- package/src/styles/ui/table.scss +97 -0
- package/src/styles/ui/theme.scss +132 -0
- package/src/styles/ui/toast.scss +587 -0
- package/src/styles/ui/toc.scss +128 -0
- package/src/styles/ui/typography.scss +21 -0
- package/src/styles/ui/ui.scss +33 -0
- package/src/ui/Ui/Badge.elm +51 -0
- package/src/ui/Ui/Banner.elm +97 -0
- package/src/ui/Ui/Burger.elm +259 -0
- package/src/ui/Ui/Button.elm +261 -0
- package/src/ui/Ui/Card.elm +32 -0
- package/src/ui/Ui/Cards.elm +15 -0
- package/src/ui/Ui/ChoiceGroup.elm +62 -0
- package/src/ui/Ui/CopyButton.elm +139 -0
- package/src/ui/Ui/Divider.elm +16 -0
- package/src/ui/Ui/Dropdown.elm +600 -0
- package/src/ui/Ui/Empty.elm +41 -0
- package/src/ui/Ui/ErrorBubble.elm +34 -0
- package/src/ui/Ui/Field.elm +45 -0
- package/src/ui/Ui/FormStatus.elm +32 -0
- package/src/ui/Ui/Icon.elm +381 -0
- package/src/ui/Ui/InlineForm.elm +51 -0
- package/src/ui/Ui/Input.elm +113 -0
- package/src/ui/Ui/KeyValue.elm +25 -0
- package/src/ui/Ui/ListRow.elm +67 -0
- package/src/ui/Ui/Loader.elm +32 -0
- package/src/ui/Ui/Logo/Charm.elm +21 -0
- package/src/ui/Ui/Logo/CharmMark.elm +32 -0
- package/src/ui/Ui/Logo/CharmSticker.elm +35 -0
- package/src/ui/Ui/Logo/Discord.elm +26 -0
- package/src/ui/Ui/Logo/GitHub.elm +21 -0
- package/src/ui/Ui/Logo/Google.elm +21 -0
- package/src/ui/Ui/Logo/Hexy.elm +29 -0
- package/src/ui/Ui/Logo/Hyper.elm +42 -0
- package/src/ui/Ui/Logo/Integration.elm +117 -0
- package/src/ui/Ui/Logo/Prism.elm +35 -0
- package/src/ui/Ui/Logos.elm +115 -0
- package/src/ui/Ui/Menu.elm +348 -0
- package/src/ui/Ui/Meter.elm +132 -0
- package/src/ui/Ui/Modal.elm +247 -0
- package/src/ui/Ui/Motion.elm +32 -0
- package/src/ui/Ui/NumberBox.elm +86 -0
- package/src/ui/Ui/OAuthButton.elm +39 -0
- package/src/ui/Ui/PageNav.elm +65 -0
- package/src/ui/Ui/Pager.elm +49 -0
- package/src/ui/Ui/Search.elm +396 -0
- package/src/ui/Ui/SearchBox.elm +78 -0
- package/src/ui/Ui/Section.elm +21 -0
- package/src/ui/Ui/Sidebar.elm +239 -0
- package/src/ui/Ui/Stat.elm +29 -0
- package/src/ui/Ui/Switch.elm +34 -0
- package/src/ui/Ui/Table.elm +89 -0
- package/src/ui/Ui/Tabs.elm +280 -0
- package/src/ui/Ui/ToC.elm +120 -0
- package/src/ui/Ui/Toast.elm +1145 -0
- package/src/ui/Ui/Toolbar.elm +31 -0
- package/src/ui/Ui/TwoStepConfirm.elm +159 -0
- package/src/ui/Ui/Typography.elm +33 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
module Gem.Render exposing
|
|
2
|
+
( Code
|
|
3
|
+
, CodeView
|
|
4
|
+
, blocks
|
|
5
|
+
, blocksWithHref
|
|
6
|
+
, codeHead
|
|
7
|
+
, codeLines
|
|
8
|
+
, defaultCodeView
|
|
9
|
+
, inlines
|
|
10
|
+
, inlinesWithHref
|
|
11
|
+
, linesToText
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
{-| Nodes to Html.
|
|
15
|
+
|
|
16
|
+
The class names are the ones the kit's own docs site styles (`md-p`,
|
|
17
|
+
`code-block`, `code-inline`, `table-wrap`), so the default stylesheet is the
|
|
18
|
+
library's stylesheet and not a parallel one.
|
|
19
|
+
|
|
20
|
+
Components go through `Slots` so a theme decides what a tag means.
|
|
21
|
+
|
|
22
|
+
-}
|
|
23
|
+
|
|
24
|
+
import Gem.Slots exposing (Slots)
|
|
25
|
+
import Dict exposing (Dict)
|
|
26
|
+
import Gem.Node exposing (Block(..), Inline(..), Token)
|
|
27
|
+
import Html exposing (Html)
|
|
28
|
+
import Html.Attributes as A
|
|
29
|
+
import String
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
{-| A code block as the theme receives it. `text` is what the copy button
|
|
33
|
+
puts on the clipboard; `lines` is what it draws.
|
|
34
|
+
-}
|
|
35
|
+
type alias Code =
|
|
36
|
+
{ lang : Maybe String
|
|
37
|
+
, title : Maybe String
|
|
38
|
+
, text : String
|
|
39
|
+
, lines : List (List Token)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
{-| How a theme draws a code block. Supplying this is how a theme adds a copy
|
|
44
|
+
button, a line-number gutter, or a title bar: the node tree stays neutral.
|
|
45
|
+
-}
|
|
46
|
+
type alias CodeView msg =
|
|
47
|
+
Code -> Html msg
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
{-| Render a list of blocks with links and images left as authored.
|
|
51
|
+
-}
|
|
52
|
+
blocks : Slots msg -> CodeView msg -> List Block -> List (Html msg)
|
|
53
|
+
blocks slots codeView list =
|
|
54
|
+
blocksWithHref identity slots codeView list
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
{-| Render a list of blocks, rewriting internal link/image URLs and the
|
|
58
|
+
`href`/`src`/`poster` component props with `rewrite` before they reach a
|
|
59
|
+
`Slots` renderer. The default shell passes `Gem.Page.href` so a non-root base
|
|
60
|
+
prefixes every generated URL; a custom renderer that wants base support calls
|
|
61
|
+
this with the same function.
|
|
62
|
+
-}
|
|
63
|
+
blocksWithHref : (String -> String) -> Slots msg -> CodeView msg -> List Block -> List (Html msg)
|
|
64
|
+
blocksWithHref rewrite slots codeView list =
|
|
65
|
+
List.map (block rewrite slots codeView) list
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
{-| Render a list of inlines with links and images left as authored.
|
|
69
|
+
-}
|
|
70
|
+
inlines : Slots msg -> List Inline -> List (Html msg)
|
|
71
|
+
inlines slots list =
|
|
72
|
+
inlinesWithHref identity slots list
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
{-| Render a list of inlines, rewriting internal URLs with `rewrite`.
|
|
76
|
+
-}
|
|
77
|
+
inlinesWithHref : (String -> String) -> Slots msg -> List Inline -> List (Html msg)
|
|
78
|
+
inlinesWithHref rewrite slots list =
|
|
79
|
+
List.map (inline rewrite slots) list
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
block : (String -> String) -> Slots msg -> CodeView msg -> Block -> Html msg
|
|
83
|
+
block rewrite slots codeView node =
|
|
84
|
+
case node of
|
|
85
|
+
Heading depth id children ->
|
|
86
|
+
heading depth id (inlinesWithHref rewrite slots children)
|
|
87
|
+
|
|
88
|
+
Paragraph children ->
|
|
89
|
+
Html.p [ A.class "md-p" ] (inlinesWithHref rewrite slots children)
|
|
90
|
+
|
|
91
|
+
CodeBlock code ->
|
|
92
|
+
codeView
|
|
93
|
+
{ lang = code.lang
|
|
94
|
+
, title = code.title
|
|
95
|
+
, text = linesToText code.lines
|
|
96
|
+
, lines = code.lines
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ListBlock list ->
|
|
100
|
+
listBlock rewrite slots codeView list
|
|
101
|
+
|
|
102
|
+
Quote children ->
|
|
103
|
+
Html.blockquote [ A.class "md-quote" ] (blocksWithHref rewrite slots codeView children)
|
|
104
|
+
|
|
105
|
+
Table table ->
|
|
106
|
+
tableView rewrite slots table
|
|
107
|
+
|
|
108
|
+
Rule ->
|
|
109
|
+
Html.hr [] []
|
|
110
|
+
|
|
111
|
+
Raw text ->
|
|
112
|
+
Html.p [ A.class "gem-raw" ] [ Html.text text ]
|
|
113
|
+
|
|
114
|
+
BlockComponent "code-group" _ children ->
|
|
115
|
+
codeGroupView codeView (codeBlocks children)
|
|
116
|
+
|
|
117
|
+
BlockComponent "ui-cards" props children ->
|
|
118
|
+
case cardGroups children of
|
|
119
|
+
Just groups ->
|
|
120
|
+
cardsGroupView rewrite slots codeView groups
|
|
121
|
+
|
|
122
|
+
Nothing ->
|
|
123
|
+
slots.component "ui-cards" (rewriteProps rewrite props) (blocksWithHref rewrite slots codeView children)
|
|
124
|
+
|
|
125
|
+
BlockComponent tag props children ->
|
|
126
|
+
slots.component tag (rewriteProps rewrite props) (blocksWithHref rewrite slots codeView children)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
{-| The code panels inside a `<code-group>`: every direct child that is a
|
|
130
|
+
fenced code block, in source order.
|
|
131
|
+
-}
|
|
132
|
+
codeBlocks : List Block -> List Code
|
|
133
|
+
codeBlocks children =
|
|
134
|
+
List.filterMap
|
|
135
|
+
(\node ->
|
|
136
|
+
case node of
|
|
137
|
+
CodeBlock code ->
|
|
138
|
+
Just
|
|
139
|
+
{ lang = code.lang
|
|
140
|
+
, title = code.title
|
|
141
|
+
, text = linesToText code.lines
|
|
142
|
+
, lines = code.lines
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
_ ->
|
|
146
|
+
Nothing
|
|
147
|
+
)
|
|
148
|
+
children
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
{-| A `<code-group>`: one underline tab per fenced panel, the first panel
|
|
152
|
+
visible. The switching itself is the theme boot's tab behavior — the
|
|
153
|
+
markup stays structural.
|
|
154
|
+
-}
|
|
155
|
+
codeGroupView : CodeView msg -> List Code -> Html msg
|
|
156
|
+
codeGroupView codeView codes =
|
|
157
|
+
Html.div
|
|
158
|
+
[ A.class "code-group", A.attribute "data-tabs" "" ]
|
|
159
|
+
([ Html.nav
|
|
160
|
+
[ A.class "tabs underline", A.attribute "data-tabs-nav" "" ]
|
|
161
|
+
(List.indexedMap
|
|
162
|
+
(\index code ->
|
|
163
|
+
Html.button
|
|
164
|
+
[ A.type_ "button"
|
|
165
|
+
, A.classList [ ( "active", index == 0 ) ]
|
|
166
|
+
]
|
|
167
|
+
[ Html.text (Maybe.withDefault (Maybe.withDefault "text" code.lang) code.title) ]
|
|
168
|
+
)
|
|
169
|
+
codes
|
|
170
|
+
)
|
|
171
|
+
]
|
|
172
|
+
++ List.indexedMap
|
|
173
|
+
(\index code ->
|
|
174
|
+
Html.div
|
|
175
|
+
([ A.class "code-panel", A.attribute "data-panel" "" ]
|
|
176
|
+
++ (if index > 0 then
|
|
177
|
+
[ A.attribute "hidden" "" ]
|
|
178
|
+
|
|
179
|
+
else
|
|
180
|
+
[]
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
[ codeView { code | title = Nothing } ]
|
|
184
|
+
)
|
|
185
|
+
codes
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
{-| The groups inside a `<ui-cards>`: every labeled `<ui-cards-group>`
|
|
190
|
+
child, ignoring whitespace between them. `Nothing` when the band holds
|
|
191
|
+
no groups, so it renders as a plain grid.
|
|
192
|
+
-}
|
|
193
|
+
cardGroups : List Block -> Maybe (List { label : String, cards : List Block })
|
|
194
|
+
cardGroups children =
|
|
195
|
+
let
|
|
196
|
+
groupOf node =
|
|
197
|
+
case node of
|
|
198
|
+
BlockComponent "ui-cards-group" props inner ->
|
|
199
|
+
Just { label = Maybe.withDefault "" (Dict.get "label" props), cards = inner }
|
|
200
|
+
|
|
201
|
+
_ ->
|
|
202
|
+
Nothing
|
|
203
|
+
|
|
204
|
+
groups =
|
|
205
|
+
List.filterMap groupOf children
|
|
206
|
+
in
|
|
207
|
+
if List.isEmpty groups then
|
|
208
|
+
Nothing
|
|
209
|
+
|
|
210
|
+
else
|
|
211
|
+
Just groups
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
{-| A grouped `<ui-cards>`: one underline tab per set, the first set
|
|
215
|
+
visible. The switching is the theme boot's tab behavior.
|
|
216
|
+
-}
|
|
217
|
+
cardsGroupView :
|
|
218
|
+
(String -> String)
|
|
219
|
+
-> Slots msg
|
|
220
|
+
-> CodeView msg
|
|
221
|
+
-> List { label : String, cards : List Block }
|
|
222
|
+
-> Html msg
|
|
223
|
+
cardsGroupView rewrite slots codeView groups =
|
|
224
|
+
Html.div
|
|
225
|
+
[ A.class "cards-root", A.attribute "data-tabs" "" ]
|
|
226
|
+
([ Html.nav
|
|
227
|
+
[ A.class "tabs underline", A.attribute "data-tabs-nav" "" ]
|
|
228
|
+
(List.indexedMap
|
|
229
|
+
(\index group ->
|
|
230
|
+
Html.button
|
|
231
|
+
[ A.type_ "button"
|
|
232
|
+
, A.classList [ ( "active", index == 0 ) ]
|
|
233
|
+
]
|
|
234
|
+
[ Html.text group.label ]
|
|
235
|
+
)
|
|
236
|
+
groups
|
|
237
|
+
)
|
|
238
|
+
]
|
|
239
|
+
++ List.indexedMap
|
|
240
|
+
(\index group ->
|
|
241
|
+
Html.div
|
|
242
|
+
([ A.class "cards-group"
|
|
243
|
+
, A.attribute "data-panel" ""
|
|
244
|
+
, A.attribute "data-label" group.label
|
|
245
|
+
]
|
|
246
|
+
++ (if index > 0 then
|
|
247
|
+
[ A.attribute "hidden" "" ]
|
|
248
|
+
|
|
249
|
+
else
|
|
250
|
+
[]
|
|
251
|
+
)
|
|
252
|
+
)
|
|
253
|
+
[ Html.div [ A.class "cards" ] (blocksWithHref rewrite slots codeView group.cards) ]
|
|
254
|
+
)
|
|
255
|
+
groups
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
inline : (String -> String) -> Slots msg -> Inline -> Html msg
|
|
260
|
+
inline rewrite slots node =
|
|
261
|
+
case node of
|
|
262
|
+
Text text ->
|
|
263
|
+
Html.text text
|
|
264
|
+
|
|
265
|
+
InlineCode text ->
|
|
266
|
+
Html.code [ A.class "code-inline" ] [ Html.text text ]
|
|
267
|
+
|
|
268
|
+
Strong children ->
|
|
269
|
+
Html.strong [] (inlinesWithHref rewrite slots children)
|
|
270
|
+
|
|
271
|
+
Em children ->
|
|
272
|
+
Html.em [] (inlinesWithHref rewrite slots children)
|
|
273
|
+
|
|
274
|
+
Del children ->
|
|
275
|
+
Html.del [] (inlinesWithHref rewrite slots children)
|
|
276
|
+
|
|
277
|
+
Link link children ->
|
|
278
|
+
Html.a
|
|
279
|
+
(A.class "md-link"
|
|
280
|
+
:: A.href (rewrite link.href)
|
|
281
|
+
:: A.title (Maybe.withDefault "" link.title)
|
|
282
|
+
:: (if link.external then
|
|
283
|
+
[ A.target "_blank", A.rel "noreferrer" ]
|
|
284
|
+
|
|
285
|
+
else
|
|
286
|
+
[]
|
|
287
|
+
)
|
|
288
|
+
)
|
|
289
|
+
(inlinesWithHref rewrite slots children)
|
|
290
|
+
|
|
291
|
+
Image image ->
|
|
292
|
+
Html.img
|
|
293
|
+
[ A.class "md-image"
|
|
294
|
+
, A.src (rewrite image.src)
|
|
295
|
+
, A.alt image.alt
|
|
296
|
+
, A.title (Maybe.withDefault "" image.title)
|
|
297
|
+
]
|
|
298
|
+
[]
|
|
299
|
+
|
|
300
|
+
LineBreak ->
|
|
301
|
+
Html.br [] []
|
|
302
|
+
|
|
303
|
+
InlineComponent tag props children ->
|
|
304
|
+
slots.component tag (rewriteProps rewrite props) (inlinesWithHref rewrite slots children)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
heading : Int -> String -> List (Html msg) -> Html msg
|
|
308
|
+
heading depth id children =
|
|
309
|
+
let
|
|
310
|
+
attrs =
|
|
311
|
+
[ A.id id, A.class ("md-h" ++ String.fromInt (clamp 1 6 depth)) ]
|
|
312
|
+
in
|
|
313
|
+
case depth of
|
|
314
|
+
1 ->
|
|
315
|
+
Html.h1 attrs children
|
|
316
|
+
|
|
317
|
+
2 ->
|
|
318
|
+
Html.h2 attrs children
|
|
319
|
+
|
|
320
|
+
3 ->
|
|
321
|
+
Html.h3 attrs children
|
|
322
|
+
|
|
323
|
+
4 ->
|
|
324
|
+
Html.h4 attrs children
|
|
325
|
+
|
|
326
|
+
5 ->
|
|
327
|
+
Html.h5 attrs children
|
|
328
|
+
|
|
329
|
+
_ ->
|
|
330
|
+
Html.h6 attrs children
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
{-| The plain code block: language label, no copy button. A theme that wants
|
|
334
|
+
copying supplies its own `CodeView`.
|
|
335
|
+
-}
|
|
336
|
+
defaultCodeView : CodeView msg
|
|
337
|
+
defaultCodeView code =
|
|
338
|
+
Html.div [ A.class "code-frame" ]
|
|
339
|
+
[ codeHead defaultLanguage code.lang code.title []
|
|
340
|
+
, Html.div [ A.class "code-block" ]
|
|
341
|
+
[ Html.pre [] [ Html.code [] (codeLines code.lines) ] ]
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
{-| The fallback has no messages to spend on a `Ui.Button`, so the language
|
|
346
|
+
is the same compact secondary button markup, inert.
|
|
347
|
+
-}
|
|
348
|
+
defaultLanguage : String -> Html msg
|
|
349
|
+
defaultLanguage name =
|
|
350
|
+
Html.button
|
|
351
|
+
[ A.class "secondary compact code-lang"
|
|
352
|
+
, A.type_ "button"
|
|
353
|
+
, A.attribute "tabindex" "-1"
|
|
354
|
+
, A.attribute "aria-hidden" "true"
|
|
355
|
+
]
|
|
356
|
+
[ Html.text name ]
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
{-| The code frame's head. A titled fence gets the full band: the file name,
|
|
360
|
+
the language as a qualifier, and the theme's controls at the right. An
|
|
361
|
+
untitled one gets no band at all — the controls float over the frame's top
|
|
362
|
+
corner and the language stays a quiet button beside them, so a plain fence
|
|
363
|
+
does not pay for an empty strip.
|
|
364
|
+
-}
|
|
365
|
+
codeHead : (String -> Html msg) -> Maybe String -> Maybe String -> List (Html msg) -> Html msg
|
|
366
|
+
codeHead language lang title actions =
|
|
367
|
+
case title of
|
|
368
|
+
Just label ->
|
|
369
|
+
Html.div [ A.class "code-head" ]
|
|
370
|
+
[ Html.div [ A.class "code-id" ]
|
|
371
|
+
[ Html.span [ A.class "code-title" ] [ Html.text label ]
|
|
372
|
+
, case lang of
|
|
373
|
+
Just name ->
|
|
374
|
+
language name
|
|
375
|
+
|
|
376
|
+
Nothing ->
|
|
377
|
+
Html.text ""
|
|
378
|
+
]
|
|
379
|
+
, Html.div [ A.class "code-actions" ] actions
|
|
380
|
+
]
|
|
381
|
+
|
|
382
|
+
Nothing ->
|
|
383
|
+
if lang == Nothing && List.isEmpty actions then
|
|
384
|
+
Html.text ""
|
|
385
|
+
|
|
386
|
+
else
|
|
387
|
+
Html.div [ A.class "code-float" ]
|
|
388
|
+
([ case lang of
|
|
389
|
+
Just name ->
|
|
390
|
+
language name
|
|
391
|
+
|
|
392
|
+
Nothing ->
|
|
393
|
+
Html.text ""
|
|
394
|
+
]
|
|
395
|
+
++ (if List.isEmpty actions then
|
|
396
|
+
[]
|
|
397
|
+
|
|
398
|
+
else
|
|
399
|
+
[ Html.div [ A.class "code-actions" ] actions ]
|
|
400
|
+
)
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
{-| Render the highlighted lines, one block-level span per line.
|
|
405
|
+
-}
|
|
406
|
+
codeLines : List (List Token) -> List (Html msg)
|
|
407
|
+
codeLines lines =
|
|
408
|
+
List.indexedMap
|
|
409
|
+
(\index line -> codeLine index (List.map token line))
|
|
410
|
+
lines
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
{-| The block's source, as the copy button hands it to the clipboard.
|
|
414
|
+
-}
|
|
415
|
+
linesToText : List (List Token) -> String
|
|
416
|
+
linesToText lines =
|
|
417
|
+
lines
|
|
418
|
+
|> List.map (\line -> line |> List.map .text |> String.concat)
|
|
419
|
+
|> String.join "\n"
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
codeLine : Int -> List (Html msg) -> Html msg
|
|
423
|
+
codeLine index rendered =
|
|
424
|
+
Html.span [ A.class "gem-code-line", A.attribute "data-line" (String.fromInt (index + 1)) ]
|
|
425
|
+
(if List.isEmpty rendered then
|
|
426
|
+
[ Html.text " " ]
|
|
427
|
+
|
|
428
|
+
else
|
|
429
|
+
rendered
|
|
430
|
+
)
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
token : Token -> Html msg
|
|
434
|
+
token value =
|
|
435
|
+
Html.span
|
|
436
|
+
((case value.color of
|
|
437
|
+
Just color ->
|
|
438
|
+
[ A.style "color" color ]
|
|
439
|
+
|
|
440
|
+
Nothing ->
|
|
441
|
+
[]
|
|
442
|
+
)
|
|
443
|
+
++ (if value.italic then
|
|
444
|
+
[ A.style "font-style" "italic" ]
|
|
445
|
+
|
|
446
|
+
else
|
|
447
|
+
[]
|
|
448
|
+
)
|
|
449
|
+
++ (if value.bold then
|
|
450
|
+
[ A.style "font-weight" "620" ]
|
|
451
|
+
|
|
452
|
+
else
|
|
453
|
+
[]
|
|
454
|
+
)
|
|
455
|
+
)
|
|
456
|
+
[ Html.text value.text ]
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
listBlock : (String -> String) -> Slots msg -> CodeView msg -> { ordered : Bool, start : Int, items : List (List Block) } -> Html msg
|
|
460
|
+
listBlock rewrite slots codeView list =
|
|
461
|
+
let
|
|
462
|
+
children =
|
|
463
|
+
List.map (\item -> Html.li [] (blocksWithHref rewrite slots codeView item)) list.items
|
|
464
|
+
in
|
|
465
|
+
if list.ordered then
|
|
466
|
+
Html.ol
|
|
467
|
+
(A.class "md-ol"
|
|
468
|
+
:: (if list.start /= 1 then
|
|
469
|
+
[ A.start list.start ]
|
|
470
|
+
|
|
471
|
+
else
|
|
472
|
+
[]
|
|
473
|
+
)
|
|
474
|
+
)
|
|
475
|
+
children
|
|
476
|
+
|
|
477
|
+
else
|
|
478
|
+
Html.ul [ A.class "md-ul" ] children
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
tableView : (String -> String) -> Slots msg -> { head : List (List Inline), rows : List (List (List Inline)) } -> Html msg
|
|
482
|
+
tableView rewrite slots table =
|
|
483
|
+
Html.div [ A.class "table-wrap" ]
|
|
484
|
+
[ Html.table []
|
|
485
|
+
[ Html.thead []
|
|
486
|
+
[ Html.tr [] (List.map (\cell -> Html.th [] (inlinesWithHref rewrite slots cell)) table.head) ]
|
|
487
|
+
, Html.tbody []
|
|
488
|
+
(List.map
|
|
489
|
+
(\row -> Html.tr [] (List.map (\cell -> Html.td [] (inlinesWithHref rewrite slots cell)) row))
|
|
490
|
+
table.rows
|
|
491
|
+
)
|
|
492
|
+
]
|
|
493
|
+
]
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
{-| Rewrite the URL props a component carries (`href`, `src`, `poster`) before
|
|
497
|
+
the `Slots` renderer sees them, so `ui-card` and custom elements receive the
|
|
498
|
+
base-prefixed value without changing the `Slots` record shape.
|
|
499
|
+
-}
|
|
500
|
+
rewriteProps : (String -> String) -> Dict String String -> Dict String String
|
|
501
|
+
rewriteProps rewrite props =
|
|
502
|
+
Dict.map
|
|
503
|
+
(\key value ->
|
|
504
|
+
if key == "href" || key == "src" || key == "poster" then
|
|
505
|
+
rewrite value
|
|
506
|
+
|
|
507
|
+
else
|
|
508
|
+
value
|
|
509
|
+
)
|
|
510
|
+
props
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Gem.Slots exposing (Slots)
|
|
2
|
+
|
|
3
|
+
import Dict exposing (Dict)
|
|
4
|
+
import Html exposing (Html)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
{-| A component renderer: tag, props, children.
|
|
8
|
+
-}
|
|
9
|
+
type alias Slots msg =
|
|
10
|
+
{ component : String -> Dict String String -> List (Html msg) -> Html msg
|
|
11
|
+
}
|