@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.
Files changed (121) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +13 -0
  3. package/README.md +24 -2
  4. package/assets/fonts/Hypography-Italic.woff2 +0 -0
  5. package/assets/fonts/Hypography-Regular.woff2 +0 -0
  6. package/assets/fonts/PPFraktionMono-Variable.ttf +0 -0
  7. package/assets/fonts/PPFraktionMonoItalic-Variable.ttf +0 -0
  8. package/assets/fonts/PPFraktionSans-Variable.ttf +0 -0
  9. package/assets/fonts/PPFraktionSansItalic-Variable.ttf +0 -0
  10. package/bin/gem-elm.js +3 -0
  11. package/dist/browser/boot.d.ts +10 -0
  12. package/dist/browser/boot.js +14 -0
  13. package/dist/browser/color-scheme.d.ts +9 -0
  14. package/dist/browser/color-scheme.js +76 -0
  15. package/dist/browser/ports.d.ts +37 -0
  16. package/dist/browser/ports.js +90 -0
  17. package/dist/browser/router.d.ts +5 -0
  18. package/dist/browser/router.js +35 -0
  19. package/dist/browser/runtime.d.ts +12 -0
  20. package/dist/browser/runtime.js +22 -0
  21. package/dist/browser/tabs.d.ts +9 -0
  22. package/dist/browser/tabs.js +69 -0
  23. package/dist/default/theme.css +4664 -0
  24. package/dist/default/theme.js +13815 -0
  25. package/dist/node/build.d.ts +16 -0
  26. package/dist/node/build.js +48 -0
  27. package/dist/node/cli.d.ts +2 -0
  28. package/dist/node/cli.js +21 -0
  29. package/elm.json +28 -0
  30. package/package.json +86 -4
  31. package/src/app/Gem/App.elm +1268 -0
  32. package/src/app/Gem/CharmSticker.elm +35 -0
  33. package/src/app/Gem/Components.elm +292 -0
  34. package/src/app/Gem/Main.elm +17 -0
  35. package/src/app/Gem/Ports.elm +32 -0
  36. package/src/app/Gem/Shell.elm +957 -0
  37. package/src/browser/theme.d.ts +1 -0
  38. package/src/core/Gem/Node.elm +219 -0
  39. package/src/core/Gem/Page.elm +560 -0
  40. package/src/core/Gem/Render.elm +510 -0
  41. package/src/core/Gem/Slots.elm +11 -0
  42. package/src/styles/docs.scss +1083 -0
  43. package/src/styles/fonts.scss +51 -0
  44. package/src/styles/gem.scss +362 -0
  45. package/src/styles/theme.scss +8 -0
  46. package/src/styles/ui/burger.scss +272 -0
  47. package/src/styles/ui/button.scss +350 -0
  48. package/src/styles/ui/charmtone.scss +70 -0
  49. package/src/styles/ui/controls-extra.scss +316 -0
  50. package/src/styles/ui/controls.scss +110 -0
  51. package/src/styles/ui/display.scss +359 -0
  52. package/src/styles/ui/dropdown.scss +341 -0
  53. package/src/styles/ui/form.scss +314 -0
  54. package/src/styles/ui/menu.scss +200 -0
  55. package/src/styles/ui/meter.scss +124 -0
  56. package/src/styles/ui/modal.scss +545 -0
  57. package/src/styles/ui/oauth.scss +50 -0
  58. package/src/styles/ui/page-nav.scss +63 -0
  59. package/src/styles/ui/reset.scss +111 -0
  60. package/src/styles/ui/scrollbar.scss +39 -0
  61. package/src/styles/ui/search.scss +164 -0
  62. package/src/styles/ui/sidebar.scss +229 -0
  63. package/src/styles/ui/squircle.scss +60 -0
  64. package/src/styles/ui/table.scss +97 -0
  65. package/src/styles/ui/theme.scss +132 -0
  66. package/src/styles/ui/toast.scss +587 -0
  67. package/src/styles/ui/toc.scss +128 -0
  68. package/src/styles/ui/typography.scss +21 -0
  69. package/src/styles/ui/ui.scss +33 -0
  70. package/src/ui/Ui/Badge.elm +51 -0
  71. package/src/ui/Ui/Banner.elm +97 -0
  72. package/src/ui/Ui/Burger.elm +259 -0
  73. package/src/ui/Ui/Button.elm +261 -0
  74. package/src/ui/Ui/Card.elm +32 -0
  75. package/src/ui/Ui/Cards.elm +15 -0
  76. package/src/ui/Ui/ChoiceGroup.elm +62 -0
  77. package/src/ui/Ui/CopyButton.elm +139 -0
  78. package/src/ui/Ui/Divider.elm +16 -0
  79. package/src/ui/Ui/Dropdown.elm +600 -0
  80. package/src/ui/Ui/Empty.elm +41 -0
  81. package/src/ui/Ui/ErrorBubble.elm +34 -0
  82. package/src/ui/Ui/Field.elm +45 -0
  83. package/src/ui/Ui/FormStatus.elm +32 -0
  84. package/src/ui/Ui/Icon.elm +381 -0
  85. package/src/ui/Ui/InlineForm.elm +51 -0
  86. package/src/ui/Ui/Input.elm +113 -0
  87. package/src/ui/Ui/KeyValue.elm +25 -0
  88. package/src/ui/Ui/ListRow.elm +67 -0
  89. package/src/ui/Ui/Loader.elm +32 -0
  90. package/src/ui/Ui/Logo/Charm.elm +21 -0
  91. package/src/ui/Ui/Logo/CharmMark.elm +32 -0
  92. package/src/ui/Ui/Logo/CharmSticker.elm +35 -0
  93. package/src/ui/Ui/Logo/Discord.elm +26 -0
  94. package/src/ui/Ui/Logo/GitHub.elm +21 -0
  95. package/src/ui/Ui/Logo/Google.elm +21 -0
  96. package/src/ui/Ui/Logo/Hexy.elm +29 -0
  97. package/src/ui/Ui/Logo/Hyper.elm +42 -0
  98. package/src/ui/Ui/Logo/Integration.elm +117 -0
  99. package/src/ui/Ui/Logo/Prism.elm +35 -0
  100. package/src/ui/Ui/Logos.elm +115 -0
  101. package/src/ui/Ui/Menu.elm +348 -0
  102. package/src/ui/Ui/Meter.elm +132 -0
  103. package/src/ui/Ui/Modal.elm +247 -0
  104. package/src/ui/Ui/Motion.elm +32 -0
  105. package/src/ui/Ui/NumberBox.elm +86 -0
  106. package/src/ui/Ui/OAuthButton.elm +39 -0
  107. package/src/ui/Ui/PageNav.elm +65 -0
  108. package/src/ui/Ui/Pager.elm +49 -0
  109. package/src/ui/Ui/Search.elm +396 -0
  110. package/src/ui/Ui/SearchBox.elm +78 -0
  111. package/src/ui/Ui/Section.elm +21 -0
  112. package/src/ui/Ui/Sidebar.elm +239 -0
  113. package/src/ui/Ui/Stat.elm +29 -0
  114. package/src/ui/Ui/Switch.elm +34 -0
  115. package/src/ui/Ui/Table.elm +89 -0
  116. package/src/ui/Ui/Tabs.elm +280 -0
  117. package/src/ui/Ui/ToC.elm +120 -0
  118. package/src/ui/Ui/Toast.elm +1145 -0
  119. package/src/ui/Ui/Toolbar.elm +31 -0
  120. package/src/ui/Ui/TwoStepConfirm.elm +159 -0
  121. package/src/ui/Ui/Typography.elm +33 -0
@@ -0,0 +1,957 @@
1
+ module Gem.Shell exposing (Config, view)
2
+
3
+ {-| The default theme, built the way the kit's own docs site is: the shell, the
4
+ header with the search trigger, the sidebar rail, the content column and the
5
+ ToC rail, all from the library's components. Search is a command-palette
6
+ dialog: the header keeps only a trigger, and the field, results and keyboard
7
+ legend live in the modal.
8
+
9
+ Overriding a piece means copying this module; the pieces themselves are
10
+ `Ui.*`, so a theme inherits the house look by default.
11
+
12
+ -}
13
+
14
+ import Gem.CharmSticker
15
+ import Gem.Slots exposing (Slots)
16
+ import Gem.Page as Page exposing (NavItem(..), Page, Site)
17
+ import Gem.Render as Render
18
+ import Html exposing (Html)
19
+ import Html.Attributes as A
20
+ import Html.Events
21
+ import Svg
22
+ import Svg.Attributes as S
23
+ import Ui.Burger
24
+ import Ui.Button
25
+ import Ui.CopyButton
26
+ import Ui.Dropdown
27
+ import Ui.Icon
28
+ import Ui.Modal
29
+ import Ui.PageNav
30
+ import Ui.Search
31
+ import Ui.Sidebar
32
+ import Ui.Tabs
33
+ import Ui.ToC
34
+ import Ui.Toolbar
35
+ import Url exposing (Url)
36
+
37
+
38
+ {-| What the shell needs from the app.
39
+ -}
40
+ type alias Config msg =
41
+ { site : Site
42
+ , page : Maybe Page
43
+ , url : Url
44
+ , query : String
45
+ , results : List (Ui.Search.Item String)
46
+ , collapsed : List String
47
+ , search : Ui.Search.Model
48
+ , searchOpen : Bool
49
+ , onSearchOpen : msg
50
+ , onSearchClose : msg
51
+ , burger : Ui.Burger.Model
52
+ , slots : Slots msg
53
+ , codeView : Render.CodeView msg
54
+ , onQuery : String -> msg
55
+ , onClear : msg
56
+ , onSearchMsg : Ui.Search.Msg String -> msg
57
+ , onToggleGroup : String -> msg
58
+ , onBurgerMsg : Ui.Burger.Msg -> msg
59
+ , doc : Page.Doc
60
+ , nav : List NavItem
61
+ , docs : List Page.Doc
62
+ , docsTabs : Ui.Tabs.Model String
63
+ , menuDocsTabs : Ui.Tabs.Model String
64
+ , onDocsTabs : Ui.Tabs.Msg String -> msg
65
+ , onMenuDocsTabs : Ui.Tabs.Msg String -> msg
66
+ , themeTabs : Ui.Tabs.Model String
67
+ , menuTabs : Ui.Tabs.Model String
68
+ , onThemeTabs : Ui.Tabs.Msg String -> msg
69
+ , onMenuTabs : Ui.Tabs.Msg String -> msg
70
+ , aiOpen : Bool
71
+ , aiFlip : Bool
72
+ , onAiToggle : msg
73
+ , onAiPick : String -> msg
74
+ , onCopyPage : msg
75
+ , pageCopied : Bool
76
+ , copyButton : Ui.CopyButton.Model
77
+ , onCopyButton : Ui.CopyButton.Msg -> msg
78
+ , activeSection : Maybe String
79
+ , headerHidden : Bool
80
+ , tocOpen : Bool
81
+ , onTocToggle : msg
82
+ }
83
+
84
+
85
+ view : Config msg -> Html msg
86
+ view config =
87
+ Html.div [ A.class "shell" ]
88
+ [ Html.node "style" [] [ Html.text (tokenStyles config.site.colors) ]
89
+ , header config
90
+ , Html.div [ A.class "docs" ]
91
+ [ sidebar config
92
+ , Html.main_ [ A.class "docs-main" ]
93
+ [ pageView config ]
94
+ ]
95
+ , footerView config
96
+ , drawer config
97
+ , searchModal config
98
+ ]
99
+
100
+
101
+ {-| The search dialog: the field, its results, and the keyboard legend.
102
+ `Ui.Search` owns the combobox mechanics; the modal gives them the room a
103
+ header field never had. The empty query is a jump list of the collection's
104
+ pages, so the dialog is useful before the first keystroke.
105
+ -}
106
+ searchModal : Config msg -> Html msg
107
+ searchModal config =
108
+ if not config.searchOpen then
109
+ Html.text ""
110
+
111
+ else
112
+ Ui.Modal.view
113
+ { dismissible = Just config.onSearchClose
114
+ , maxWidth = Just 42
115
+ , attributes = [ A.class "search-modal" ]
116
+ , content =
117
+ [ Html.div [ A.class "search-modal-row" ]
118
+ [ Ui.Search.view
119
+ { query = config.query
120
+ , placeholder = "Search pages and headings…"
121
+ , onInput = config.onQuery
122
+ , onClear = config.onClear
123
+ , items = config.results
124
+ , toMsg = config.onSearchMsg
125
+ , emptyText = "No matches"
126
+ , persistent = True
127
+ , attributes = [ A.class "search-modal-field" ]
128
+ }
129
+ config.search
130
+ , Html.button
131
+ [ A.class "search-close"
132
+ , A.type_ "button"
133
+ , A.attribute "aria-label" "Close search"
134
+ , Html.Events.onClick config.onSearchClose
135
+ ]
136
+ [ Ui.Icon.view Ui.Icon.Close ]
137
+ ]
138
+ , Html.div [ A.class "search-hints" ]
139
+ [ searchHint [ "↑", "↓" ] "navigate"
140
+ , searchHint [ "↵" ] "open"
141
+ , searchHint [ "esc" ] "close"
142
+ ]
143
+ ]
144
+ }
145
+
146
+
147
+ searchHint : List String -> String -> Html msg
148
+ searchHint keys label =
149
+ Html.span [ A.class "search-hint" ]
150
+ (List.map (\key -> Html.kbd [ A.class "code-inline" ] [ Html.text key ]) keys
151
+ ++ [ Html.span [] [ Html.text label ] ]
152
+ )
153
+
154
+
155
+ {-| Token colors arrive as slots (`--gem-tk-3`) so the same markup works in
156
+ every theme. They are emitted once, here, instead of on every span.
157
+ -}
158
+ tokenStyles : List Page.Color -> String
159
+ tokenStyles colors =
160
+ if List.isEmpty colors then
161
+ ""
162
+
163
+ else
164
+ let
165
+ define pick =
166
+ colors
167
+ |> List.map (\color -> color.name ++ ":" ++ pick color ++ ";")
168
+ |> String.concat
169
+
170
+ light =
171
+ "{" ++ define (\color -> Maybe.withDefault "inherit" color.light) ++ "}"
172
+
173
+ dark =
174
+ "{" ++ define (\color -> Maybe.withDefault "inherit" color.dark) ++ "}"
175
+ in
176
+ -- Char (no attribute) is the house default and it is a dark theme, so
177
+ -- the dark set is what `:root` gets.
178
+ ":root" ++ dark ++ ":root[data-theme=\"dark\"]" ++ dark ++ ":root[data-theme=\"light\"]" ++ light
179
+
180
+
181
+ header : Config msg -> Html msg
182
+ header config =
183
+ let
184
+ chrome =
185
+ config.site.chrome.header
186
+ in
187
+ Html.div
188
+ [ A.classList
189
+ [ ( "docs-header", True )
190
+ , ( "is-hidden", config.headerHidden )
191
+ ]
192
+ ]
193
+ ([ if chrome.logo then
194
+ Html.a [ A.class "docs-header-title", A.href (Page.href config.site config.doc.root) ]
195
+ [ logoView config.site.meta.logo config ]
196
+
197
+ else
198
+ Html.text ""
199
+ ]
200
+ ++ [ Html.div [ A.class "docs-header-end" ]
201
+ (List.map (headerAction config) chrome.actions
202
+ ++ [ if chrome.search then
203
+ searchToggle config
204
+
205
+ else
206
+ Html.text ""
207
+ , if chrome.docs then
208
+ docsTabsView config
209
+
210
+ else
211
+ Html.text ""
212
+ , if chrome.theme then
213
+ Html.map config.onThemeTabs
214
+ (Ui.Tabs.view
215
+ { choices = themeChoices config.site.themeSystem
216
+ , size = Ui.Tabs.Compact
217
+ , attributes = []
218
+ }
219
+ config.themeTabs
220
+ )
221
+
222
+ else
223
+ Html.text ""
224
+ ]
225
+ )
226
+ ]
227
+ )
228
+
229
+
230
+ {-| The header keeps a magnifier, not a field: the search itself lives in
231
+ the modal, which has room for results, snippets and a keyboard legend.
232
+ -}
233
+ searchToggle : Config msg -> Html msg
234
+ searchToggle config =
235
+ Html.button
236
+ [ A.class "ghost compact docs-search-toggle"
237
+ , A.type_ "button"
238
+ , A.title "Search (Ctrl/Cmd K)"
239
+ , A.attribute "aria-label" "Search"
240
+ , Html.Events.onClick config.onSearchOpen
241
+ ]
242
+ [ Ui.Icon.view Ui.Icon.Search ]
243
+
244
+
245
+ headerAction : Config msg -> { label : String, href : String } -> Html msg
246
+ headerAction config action =
247
+ Ui.Button.viewLink
248
+ { label = action.label
249
+ , variant = Ui.Button.Secondary
250
+ , size = Ui.Button.Compact
251
+ , wide = False
252
+ , disabled = False
253
+ , icon = Nothing
254
+ , attributes = [ A.class "docs-header-action" ]
255
+ }
256
+ (Page.href config.site action.href)
257
+
258
+
259
+ {-| A site brand: its configured logo image when it has one, otherwise the
260
+ text label. The image is the same node in the bar, the drawer and the
261
+ footer; each context sizes it.
262
+ -}
263
+ logoView : String -> Config msg -> Html msg
264
+ logoView label config =
265
+ case config.site.meta.logoImage of
266
+ Just src ->
267
+ Html.node "img" [ A.class "site-logo", A.src (Page.href config.site src), A.alt label ] []
268
+
269
+ Nothing ->
270
+ Html.text label
271
+
272
+
273
+ -- FOOTER
274
+
275
+
276
+ {-| The site footer: an accent hairline, a brand block with the wordmark and
277
+ chips, the configured link columns, and a bar with the footer text. Fully
278
+ driven by the site's chrome.
279
+ -}
280
+ footerView : Config msg -> Html msg
281
+ footerView config =
282
+ let
283
+ footer =
284
+ config.site.chrome.footer
285
+
286
+ column view_ =
287
+ Html.div [ A.class "site-footer-col" ]
288
+ [ Html.span [ A.class "site-footer-heading" ] [ Html.text view_.heading ]
289
+ , Html.ul []
290
+ (List.map
291
+ (\link ->
292
+ Html.li [] [ Html.a [ A.href (Page.href config.site link.href) ] [ Html.text link.label ] ]
293
+ )
294
+ view_.links
295
+ )
296
+ ]
297
+
298
+ brand =
299
+ Html.div [ A.class "site-footer-brand" ]
300
+ [ Html.a
301
+ [ A.class "site-footer-brandmark"
302
+ , A.href "https://charm.land"
303
+ , A.attribute "aria-label" "Charm"
304
+ ]
305
+ [ Gem.CharmSticker.view ]
306
+ , if String.isEmpty footer.blurb then
307
+ Html.text ""
308
+
309
+ else
310
+ Html.p [ A.class "site-footer-blurb" ] [ Html.text footer.blurb ]
311
+ , if List.isEmpty footer.chips then
312
+ Html.text ""
313
+
314
+ else
315
+ Html.div [ A.class "site-footer-chips" ]
316
+ (List.map
317
+ (\chip -> Html.span [ A.class "footer-chip" ] [ Html.text chip ])
318
+ footer.chips
319
+ )
320
+ ]
321
+ in
322
+ if not footer.enabled then
323
+ Html.text ""
324
+
325
+ else
326
+ Html.footer [ A.class "site-footer" ]
327
+ [ Html.div [ A.class "site-footer-inner" ]
328
+ (brand :: List.map column footer.columns)
329
+ , Html.div [ A.class "site-footer-bar" ]
330
+ [ Html.span [] [ Html.text (Maybe.withDefault "" config.site.meta.footer) ]
331
+ , Html.a [ A.class "site-footer-top", A.href "#" ] [ Html.text "Top" ]
332
+ ]
333
+ ]
334
+
335
+
336
+ {-| The collections switcher, in the header. One tab per documentation set;
337
+ the active tab is the set the current page belongs to. A single-collection
338
+ site renders nothing.
339
+ -}
340
+ docsTabsView : Config msg -> Html msg
341
+ docsTabsView config =
342
+ if List.length config.docs < 2 then
343
+ Html.text ""
344
+
345
+ else
346
+ Html.map config.onDocsTabs
347
+ (Ui.Tabs.view
348
+ { choices = docsChoices config
349
+ , size = Ui.Tabs.Compact
350
+ , attributes = [ A.class "docs-tabs" ]
351
+ }
352
+ config.docsTabs
353
+ )
354
+
355
+
356
+ {-| The drawer's copy of the collection switcher. It carries its own id, so
357
+ the thumb is measured against the copy that is actually on screen: the
358
+ header's is `display: none` on a phone.
359
+ -}
360
+ menuDocsTabsView : Config msg -> Html msg
361
+ menuDocsTabsView config =
362
+ if List.length config.docs < 2 then
363
+ Html.text ""
364
+
365
+ else
366
+ Html.map config.onMenuDocsTabs
367
+ (Ui.Tabs.view
368
+ { choices = docsChoices config
369
+ , size = Ui.Tabs.Compact
370
+ , attributes = [ A.class "docs-tabs" ]
371
+ }
372
+ config.menuDocsTabs
373
+ )
374
+
375
+
376
+ docsChoices : Config msg -> List (Ui.Tabs.Choice String)
377
+ docsChoices config =
378
+ List.map
379
+ (\doc -> { label = doc.label, icon = Nothing, value = doc.id })
380
+ config.docs
381
+
382
+
383
+ sidebar : Config msg -> Html msg
384
+ sidebar config =
385
+ sidebarView config [ A.class "docs-sidebar" ]
386
+
387
+
388
+ sidebarView : Config msg -> List (Html.Attribute msg) -> Html msg
389
+ sidebarView config attributes =
390
+ Ui.Sidebar.view
391
+ { sections = sections config
392
+ , narrow = False
393
+ , footer = Nothing
394
+ , collapsed = config.collapsed
395
+ , onToggleGroup = Just config.onToggleGroup
396
+ , attributes = attributes
397
+ }
398
+
399
+
400
+ sections : Config msg -> List (Ui.Sidebar.Section msg)
401
+ sections config =
402
+ let
403
+ rootItems =
404
+ List.filterMap (pageItem config) config.nav
405
+
406
+ groups =
407
+ List.filterMap (categorySection config) config.nav
408
+ in
409
+ (if List.isEmpty rootItems then
410
+ []
411
+
412
+ else
413
+ [ Ui.Sidebar.Unlabeled rootItems ]
414
+ )
415
+ ++ groups
416
+
417
+
418
+ {-| A category is a group of its own pages, then its child categories, so a
419
+ nested directory reads as a nested section in the rail. The collapse key is
420
+ the directory path, which stays unique at any depth.
421
+ -}
422
+ categorySection : Config msg -> NavItem -> Maybe (Ui.Sidebar.Section msg)
423
+ categorySection config item =
424
+ case item of
425
+ PageItem _ ->
426
+ Nothing
427
+
428
+ Category category ->
429
+ Just
430
+ (Ui.Sidebar.Group
431
+ { key = category.id, label = category.label }
432
+ (List.filterMap (pageItem config) category.items)
433
+ (List.filterMap (categorySection config) category.items)
434
+ )
435
+
436
+
437
+ pageItem : Config msg -> NavItem -> Maybe (Ui.Sidebar.Item msg)
438
+ pageItem config item =
439
+ case item of
440
+ PageItem page ->
441
+ Just (navItem config page.title page.route)
442
+
443
+ Category _ ->
444
+ Nothing
445
+
446
+
447
+ navItem : Config msg -> String -> String -> Ui.Sidebar.Item msg
448
+ navItem config label route =
449
+ { label = label
450
+ , icon = Nothing
451
+ , target = Ui.Sidebar.Href (Page.href config.site route)
452
+ , active = isActive config route
453
+ }
454
+
455
+
456
+ pageView : Config msg -> Html msg
457
+ pageView config =
458
+ case config.page of
459
+ Nothing ->
460
+ Html.div [ A.class "docs-content" ]
461
+ [ Html.div [ A.class "docs-page" ]
462
+ [ Ui.Toolbar.view { title = "Not found", actions = [], attributes = [] }
463
+ , Html.p [ A.class "md-p" ]
464
+ [ Html.text "There is no page at this address. "
465
+ , Html.a [ A.class "md-link", A.href (Page.href config.site config.doc.root) ] [ Html.text "Back to the introduction" ]
466
+ , Html.text "."
467
+ ]
468
+ ]
469
+ ]
470
+
471
+ Just page ->
472
+ Html.div [ A.class "docs-with-toc" ]
473
+ [ tocView config page
474
+ , Html.div [ A.class "docs-content" ]
475
+ [ Html.div [ A.class "docs-page" ]
476
+ ([ Ui.Toolbar.view
477
+ { title = page.title
478
+ , actions = []
479
+ , attributes = []
480
+ }
481
+ ]
482
+ ++ lede page
483
+ ++ [ pageActions config ]
484
+ ++ [ Html.div [ A.class "md" ]
485
+ (Render.blocksWithHref (Page.href config.site) config.slots config.codeView page.blocks)
486
+ ]
487
+ ++ [ pageTail config page ]
488
+ ++ [ pager config page ]
489
+ )
490
+ ]
491
+ ]
492
+
493
+
494
+ pageActions : Config msg -> Html msg
495
+ pageActions config =
496
+ let
497
+ actions =
498
+ toolbarActions config
499
+ in
500
+ if List.isEmpty actions then
501
+ Html.text ""
502
+
503
+ else
504
+ Html.div [ A.class "page-actions" ] actions
505
+
506
+
507
+ lede : Page -> List (Html msg)
508
+ lede page =
509
+ if String.isEmpty page.summary then
510
+ []
511
+
512
+ else
513
+ [ Html.p [ A.class "docs-lede page-desc" ] [ Html.text page.summary ] ]
514
+
515
+
516
+ {-| The page's tail, which is often nothing: the EOF band when
517
+ `[footer] eof` is on, then the source link when `[site] edit_url` is set.
518
+ -}
519
+ pageTail : Config msg -> Page -> Html msg
520
+ pageTail config page =
521
+ if config.site.chrome.footer.eof || config.site.meta.editUrl /= Nothing then
522
+ Html.div [ A.class "docs-tail" ]
523
+ [ eofBand config page, editLink config page ]
524
+
525
+ else
526
+ Html.text ""
527
+
528
+
529
+ {-| The way back to the source: `[site] edit_url` is the repository's edit
530
+ prefix, and the page's own path is appended, so one key covers every page.
531
+ Off unless a site sets it.
532
+ -}
533
+ editLink : Config msg -> Page -> Html msg
534
+ editLink config page =
535
+ case config.site.meta.editUrl of
536
+ Just base ->
537
+ let
538
+ prefix =
539
+ if String.endsWith "/" base then
540
+ base
541
+
542
+ else
543
+ base ++ "/"
544
+ in
545
+ Html.a
546
+ [ A.class "docs-edit"
547
+ , A.href (prefix ++ page.source)
548
+ , A.target "_blank"
549
+ , A.rel "noopener noreferrer"
550
+ ]
551
+ [ Ui.Icon.view Ui.Icon.ExternalLink
552
+ , Html.text "Edit this page on GitHub"
553
+ ]
554
+
555
+ Nothing ->
556
+ Html.text ""
557
+
558
+
559
+ {-| The end of the page, opt-in through `[footer] eof`: the EOF mark and the
560
+ command that prints this page in a terminal. The command
561
+ copies through the same button model as the code blocks, so the flash
562
+ follows the text that was copied rather than the page.
563
+ -}
564
+ eofBand : Config msg -> Page -> Html msg
565
+ eofBand config page =
566
+ if not config.site.chrome.footer.eof then
567
+ Html.text ""
568
+
569
+ else
570
+ let
571
+ command =
572
+ "glow -p " ++ pageMarkdownUrl config page
573
+ in
574
+ Html.div [ A.class "docs-eof" ]
575
+ [ Html.p [ A.class "docs-eof-term" ]
576
+ [ Html.span [ A.class "docs-eof-say" ]
577
+ [ Html.text "Read this post in your terminal with "
578
+ , Html.a
579
+ [ A.class "docs-eof-tool"
580
+ , A.href "https://github.com/charmbracelet/glow"
581
+ , A.target "_blank"
582
+ , A.rel "noreferrer noopener"
583
+ ]
584
+ [ Html.text "glow" ]
585
+ , Html.text ":"
586
+ ]
587
+ , Html.code [ A.class "docs-eof-cmd" ] [ Html.text command ]
588
+ , Html.map config.onCopyButton
589
+ (Ui.CopyButton.view
590
+ { text = command
591
+ , label = "Copy command"
592
+ , attributes = [ A.class "docs-eof-copy" ]
593
+ }
594
+ config.copyButton
595
+ )
596
+ ]
597
+ , Html.span [ A.class "docs-eof-mark" ] [ Html.text "EOF" ]
598
+ ]
599
+
600
+
601
+ {-| The page's markdown URL: absolute when the site declares an origin
602
+ (origin only — any path, query or fragment in `site.url` is ignored, matching
603
+ the build), and relative so it still works in dev and under a base when it
604
+ doesn't.
605
+ -}
606
+ pageMarkdownUrl : Config msg -> Page -> String
607
+ pageMarkdownUrl config page =
608
+ let
609
+ markdown =
610
+ Page.markdownHref config.site page
611
+
612
+ raw =
613
+ String.trim config.site.meta.url
614
+
615
+ candidate =
616
+ if String.contains "://" raw then
617
+ raw
618
+
619
+ else
620
+ "https://" ++ raw
621
+ in
622
+ if String.isEmpty raw then
623
+ markdown
624
+
625
+ else
626
+ case Url.fromString candidate of
627
+ Just parsed ->
628
+ Url.toString { parsed | path = "", query = Nothing, fragment = Nothing } ++ markdown
629
+
630
+ Nothing ->
631
+ markdown
632
+
633
+
634
+ tocView : Config msg -> Page -> Html msg
635
+ tocView config page =
636
+ if List.isEmpty page.toc then
637
+ Html.text ""
638
+
639
+ else
640
+ Html.aside [ A.class "docs-toc" ]
641
+ [ Html.div [ A.class "docs-toc-sticky" ]
642
+ [ Ui.ToC.view
643
+ { title = "On this page"
644
+ , items = tocTree page.toc
645
+ , active = config.activeSection
646
+ , disclosure = Just { open = config.tocOpen, onToggle = config.onTocToggle }
647
+ , attributes = []
648
+ }
649
+ ]
650
+ ]
651
+
652
+
653
+ tocTree : List Page.Heading -> List Ui.ToC.Item
654
+ tocTree headings =
655
+ buildToc 2 headings |> Tuple.first
656
+
657
+
658
+ buildToc : Int -> List Page.Heading -> ( List Ui.ToC.Item, List Page.Heading )
659
+ buildToc level headings =
660
+ case headings of
661
+ [] ->
662
+ ( [], [] )
663
+
664
+ first :: rest ->
665
+ if first.depth < level then
666
+ ( [], headings )
667
+
668
+ else
669
+ let
670
+ ( children, afterChildren ) =
671
+ buildToc (first.depth + 1) rest
672
+
673
+ ( siblings, remaining ) =
674
+ buildToc level afterChildren
675
+ in
676
+ ( Ui.ToC.Item
677
+ { label = first.text
678
+ , href = "#" ++ first.id
679
+ , children = children
680
+ }
681
+ :: siblings
682
+ , remaining
683
+ )
684
+
685
+
686
+ {-| The page toolbar's actions, each behind its `[toolbar]` flag.
687
+ -}
688
+ toolbarActions : Config msg -> List (Html msg)
689
+ toolbarActions config =
690
+ let
691
+ toolbar =
692
+ config.site.chrome.toolbar
693
+ in
694
+ (if toolbar.copy then
695
+ [ copyPageButton config ]
696
+
697
+ else
698
+ []
699
+ )
700
+ ++ (if toolbar.openIn then
701
+ [ aiDropdown config ]
702
+
703
+ else
704
+ []
705
+ )
706
+
707
+
708
+ {-| The compact copy action: an outlined (Secondary) button, so its hit
709
+ area reads at rest, beside the chatbot menu's matching outline.
710
+ -}
711
+ copyPageButton : Config msg -> Html msg
712
+ copyPageButton config =
713
+ Ui.Button.view
714
+ { label =
715
+ if config.pageCopied then
716
+ "Copied"
717
+
718
+ else
719
+ "Copy page"
720
+ , variant = Ui.Button.Secondary
721
+ , size = Ui.Button.Compact
722
+ , wide = False
723
+ , disabled = False
724
+ , busy = Nothing
725
+ , icon =
726
+ Just
727
+ (if config.pageCopied then
728
+ Ui.Icon.view Ui.Icon.Check
729
+
730
+ else
731
+ Ui.Icon.view Ui.Icon.Copy
732
+ )
733
+ , onClick = config.onCopyPage
734
+ , attributes =
735
+ [ A.class "page-copy"
736
+ , A.classList [ ( "done", config.pageCopied ) ]
737
+ ]
738
+ }
739
+
740
+
741
+ aiDropdown : Config msg -> Html msg
742
+ aiDropdown config =
743
+ Ui.Dropdown.view
744
+ { options =
745
+ List.map
746
+ (\bot -> Ui.Dropdown.option bot.label bot.id)
747
+ chatbots
748
+ , selected = ""
749
+ , trigger = "Open in"
750
+ , open = config.aiOpen
751
+ , flip = config.aiFlip
752
+ , id = "ai-dropdown"
753
+ , onToggle = config.onAiToggle
754
+ , onSelect = config.onAiPick
755
+ , search = Nothing
756
+ , action = Nothing
757
+ , compact = True
758
+ , triggerIcon = Just (Ui.Icon.view Ui.Icon.Chevron)
759
+ , attributes = [ A.class "ai-dropdown" ]
760
+ }
761
+
762
+
763
+ chatbots : List { id : String, label : String }
764
+ chatbots =
765
+ [ { id = "chatgpt", label = "Open in ChatGPT" }
766
+ , { id = "claude", label = "Open in Claude" }
767
+ , { id = "perplexity", label = "Open in Perplexity" }
768
+ , { id = "copilot", label = "Open in Copilot" }
769
+ , { id = "you", label = "Open in You.com" }
770
+ , { id = "phind", label = "Open in Phind" }
771
+ ]
772
+
773
+
774
+ {-| The theme tabs: light and dark at the ends, and the system preference
775
+ between them when the site enables it. `themeIcon "system"` falls through to
776
+ the half-filled circle.
777
+ -}
778
+ themeChoices : Bool -> List (Ui.Tabs.Choice String)
779
+ themeChoices system =
780
+ [ { label = "", icon = Just (themeIcon "light"), value = "light" } ]
781
+ ++ (if system then
782
+ [ { label = "", icon = Just (themeIcon "system"), value = "system" } ]
783
+
784
+ else
785
+ []
786
+ )
787
+ ++ [ { label = "", icon = Just (themeIcon "dark"), value = "dark" } ]
788
+
789
+
790
+ themeIcon : String -> Html msg
791
+ themeIcon kind =
792
+ Svg.svg
793
+ [ S.viewBox "0 0 24 24", S.class "theme-icon", S.fill "none" ]
794
+ (case kind of
795
+ "light" ->
796
+ [ Svg.circle
797
+ [ S.cx "12", S.cy "12", S.r "4.5", S.stroke "currentColor", S.strokeWidth "2" ]
798
+ []
799
+ , Svg.path
800
+ [ S.d "M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1"
801
+ , S.stroke "currentColor"
802
+ , S.strokeWidth "2"
803
+ , S.strokeLinecap "round"
804
+ ]
805
+ []
806
+ ]
807
+
808
+ "dark" ->
809
+ [ Svg.path
810
+ [ S.d "M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z", S.fill "currentColor" ]
811
+ []
812
+ ]
813
+
814
+ _ ->
815
+ [ Svg.circle
816
+ [ S.cx "12", S.cy "12", S.r "9", S.stroke "currentColor", S.strokeWidth "2" ]
817
+ []
818
+ , Svg.path [ S.d "M12 3a9 9 0 0 1 0 18Z", S.fill "currentColor" ] []
819
+ ]
820
+ )
821
+
822
+
823
+ pager : Config msg -> Page -> Html msg
824
+ pager config page =
825
+ let
826
+ order =
827
+ flatten config
828
+
829
+ position =
830
+ order
831
+ |> List.indexedMap Tuple.pair
832
+ |> List.filter (\( _, item ) -> item.route == page.route)
833
+ |> List.head
834
+ |> Maybe.map Tuple.first
835
+
836
+ previous =
837
+ position
838
+ |> Maybe.andThen
839
+ (\index ->
840
+ if index > 0 then
841
+ itemAt (index - 1) order
842
+
843
+ else
844
+ Nothing
845
+ )
846
+
847
+ next =
848
+ position |> Maybe.andThen (\index -> itemAt (index + 1) order)
849
+ in
850
+ if previous == Nothing && next == Nothing then
851
+ Html.text ""
852
+
853
+ else
854
+ Ui.PageNav.view
855
+ { previous = Maybe.map (pageNavItem config) previous
856
+ , next = Maybe.map (pageNavItem config) next
857
+ , attributes = []
858
+ }
859
+
860
+
861
+ pageNavItem : Config msg -> Page.Entry -> Ui.PageNav.Item
862
+ pageNavItem config entry =
863
+ { title = entry.title
864
+ , description = entry.summary
865
+ , href = Page.href config.site entry.route
866
+ }
867
+
868
+
869
+ flatten : Config msg -> List Page.Entry
870
+ flatten config =
871
+ let
872
+ routeOf item =
873
+ case item of
874
+ PageItem page ->
875
+ [ page.route ]
876
+
877
+ Category category ->
878
+ List.concatMap routeOf category.items
879
+
880
+ routes =
881
+ List.concatMap routeOf config.nav
882
+
883
+ entryFor route =
884
+ config.site.entries
885
+ |> List.filter (\entry -> entry.route == route)
886
+ |> List.head
887
+ in
888
+ List.filterMap entryFor routes
889
+
890
+
891
+ itemAt : Int -> List Page.Entry -> Maybe Page.Entry
892
+ itemAt index items =
893
+ items |> List.drop index |> List.head
894
+
895
+
896
+ isActive : Config msg -> String -> Bool
897
+ isActive config route =
898
+ Page.routeOf config.site config.url.path == route
899
+
900
+
901
+ drawer : Config msg -> Html msg
902
+ drawer config =
903
+ Ui.Burger.view
904
+ { label = "Menu"
905
+ , logo =
906
+ Just (Html.span [ A.class "burger-wordmark" ] [ logoView config.site.meta.logo config ])
907
+ , header =
908
+ Just
909
+ (Html.div [ A.class "burger-panel" ]
910
+ [ Maybe.withDefault (Html.text "") (burgerControls config)
911
+ , sidebarView config [ A.class "burger-sidebar" ]
912
+ ]
913
+ )
914
+ , onToggle = config.onBurgerMsg Ui.Burger.Toggled
915
+ , onClose = config.onBurgerMsg Ui.Burger.Closed
916
+ , attributes = []
917
+ }
918
+ config.burger
919
+
920
+
921
+ {-| The controls under the logo band: theme tabs and, when the site has
922
+ more than one collection, the collection switcher. They sit together
923
+ instead of crowding the wordmark's band.
924
+ -}
925
+ burgerControls : Config msg -> Maybe (Html msg)
926
+ burgerControls config =
927
+ let
928
+ chrome =
929
+ config.site.chrome.header
930
+
931
+ parts =
932
+ (if chrome.theme then
933
+ [ Html.map config.onMenuTabs
934
+ (Ui.Tabs.view
935
+ { choices = themeChoices config.site.themeSystem
936
+ , size = Ui.Tabs.Compact
937
+ , attributes = []
938
+ }
939
+ config.menuTabs
940
+ )
941
+ ]
942
+
943
+ else
944
+ []
945
+ )
946
+ ++ (if chrome.docs && List.length config.docs > 1 then
947
+ [ menuDocsTabsView config ]
948
+
949
+ else
950
+ []
951
+ )
952
+ in
953
+ if List.isEmpty parts then
954
+ Nothing
955
+
956
+ else
957
+ Just (Html.div [ A.class "burger-controls" ] parts)