@charmland/gem 0.0.0-stage → 0.1.0

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 +13652 -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 +1275 -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 +964 -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 +409 -0
  40. package/src/core/Gem/Render.elm +472 -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,964 @@
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 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 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 : { label : String, href : String } -> Html msg
246
+ headerAction 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
+ 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 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 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 route
452
+ , active = isActive config.url.path 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 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.blocks 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
+ relative (so it still works in dev) when it doesn't.
603
+ -}
604
+ pageMarkdownUrl : Config msg -> Page -> String
605
+ pageMarkdownUrl config page =
606
+ let
607
+ raw =
608
+ String.trim config.site.meta.url
609
+
610
+ origin =
611
+ if String.endsWith "/" raw then
612
+ String.dropRight 1 raw
613
+
614
+ else
615
+ raw
616
+ in
617
+ if String.isEmpty origin then
618
+ Page.markdownPath page
619
+
620
+ else
621
+ origin ++ Page.markdownPath page
622
+
623
+
624
+ tocView : Config msg -> Page -> Html msg
625
+ tocView config page =
626
+ if List.isEmpty page.toc then
627
+ Html.text ""
628
+
629
+ else
630
+ Html.aside [ A.class "docs-toc" ]
631
+ [ Html.div [ A.class "docs-toc-sticky" ]
632
+ [ Ui.ToC.view
633
+ { title = "On this page"
634
+ , items = tocTree page.toc
635
+ , active = config.activeSection
636
+ , disclosure = Just { open = config.tocOpen, onToggle = config.onTocToggle }
637
+ , attributes = []
638
+ }
639
+ ]
640
+ ]
641
+
642
+
643
+ tocTree : List Page.Heading -> List Ui.ToC.Item
644
+ tocTree headings =
645
+ buildToc 2 headings |> Tuple.first
646
+
647
+
648
+ buildToc : Int -> List Page.Heading -> ( List Ui.ToC.Item, List Page.Heading )
649
+ buildToc level headings =
650
+ case headings of
651
+ [] ->
652
+ ( [], [] )
653
+
654
+ first :: rest ->
655
+ if first.depth < level then
656
+ ( [], headings )
657
+
658
+ else
659
+ let
660
+ ( children, afterChildren ) =
661
+ buildToc (first.depth + 1) rest
662
+
663
+ ( siblings, remaining ) =
664
+ buildToc level afterChildren
665
+ in
666
+ ( Ui.ToC.Item
667
+ { label = first.text
668
+ , href = "#" ++ first.id
669
+ , children = children
670
+ }
671
+ :: siblings
672
+ , remaining
673
+ )
674
+
675
+
676
+ {-| The page toolbar's actions, each behind its `[toolbar]` flag.
677
+ -}
678
+ toolbarActions : Config msg -> List (Html msg)
679
+ toolbarActions config =
680
+ let
681
+ toolbar =
682
+ config.site.chrome.toolbar
683
+ in
684
+ (if toolbar.copy then
685
+ [ copyPageButton config ]
686
+
687
+ else
688
+ []
689
+ )
690
+ ++ (if toolbar.openIn then
691
+ [ aiDropdown config ]
692
+
693
+ else
694
+ []
695
+ )
696
+
697
+
698
+ {-| The compact copy action: an outlined (Secondary) button, so its hit
699
+ area reads at rest, beside the chatbot menu's matching outline.
700
+ -}
701
+ copyPageButton : Config msg -> Html msg
702
+ copyPageButton config =
703
+ Ui.Button.view
704
+ { label =
705
+ if config.pageCopied then
706
+ "Copied"
707
+
708
+ else
709
+ "Copy page"
710
+ , variant = Ui.Button.Secondary
711
+ , size = Ui.Button.Compact
712
+ , wide = False
713
+ , disabled = False
714
+ , busy = Nothing
715
+ , icon =
716
+ Just
717
+ (if config.pageCopied then
718
+ Ui.Icon.view Ui.Icon.Check
719
+
720
+ else
721
+ Ui.Icon.view Ui.Icon.Copy
722
+ )
723
+ , onClick = config.onCopyPage
724
+ , attributes =
725
+ [ A.class "page-copy"
726
+ , A.classList [ ( "done", config.pageCopied ) ]
727
+ ]
728
+ }
729
+
730
+
731
+ aiDropdown : Config msg -> Html msg
732
+ aiDropdown config =
733
+ Ui.Dropdown.view
734
+ { options =
735
+ List.map
736
+ (\bot -> Ui.Dropdown.option bot.label bot.id)
737
+ chatbots
738
+ , selected = ""
739
+ , trigger = "Open in"
740
+ , open = config.aiOpen
741
+ , flip = config.aiFlip
742
+ , id = "ai-dropdown"
743
+ , onToggle = config.onAiToggle
744
+ , onSelect = config.onAiPick
745
+ , search = Nothing
746
+ , action = Nothing
747
+ , compact = True
748
+ , triggerIcon = Just (Ui.Icon.view Ui.Icon.Chevron)
749
+ , attributes = [ A.class "ai-dropdown" ]
750
+ }
751
+
752
+
753
+ chatbots : List { id : String, label : String }
754
+ chatbots =
755
+ [ { id = "chatgpt", label = "Open in ChatGPT" }
756
+ , { id = "claude", label = "Open in Claude" }
757
+ , { id = "perplexity", label = "Open in Perplexity" }
758
+ , { id = "copilot", label = "Open in Copilot" }
759
+ , { id = "you", label = "Open in You.com" }
760
+ , { id = "phind", label = "Open in Phind" }
761
+ ]
762
+
763
+
764
+ {-| The theme tabs: light and dark at the ends, and the system preference
765
+ between them when the site enables it. `themeIcon "system"` falls through to
766
+ the half-filled circle.
767
+ -}
768
+ themeChoices : Bool -> List (Ui.Tabs.Choice String)
769
+ themeChoices system =
770
+ [ { label = "", icon = Just (themeIcon "light"), value = "light" } ]
771
+ ++ (if system then
772
+ [ { label = "", icon = Just (themeIcon "system"), value = "system" } ]
773
+
774
+ else
775
+ []
776
+ )
777
+ ++ [ { label = "", icon = Just (themeIcon "dark"), value = "dark" } ]
778
+
779
+
780
+ themeIcon : String -> Html msg
781
+ themeIcon kind =
782
+ Svg.svg
783
+ [ S.viewBox "0 0 24 24", S.class "theme-icon", S.fill "none" ]
784
+ (case kind of
785
+ "light" ->
786
+ [ Svg.circle
787
+ [ S.cx "12", S.cy "12", S.r "4.5", S.stroke "currentColor", S.strokeWidth "2" ]
788
+ []
789
+ , Svg.path
790
+ [ 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"
791
+ , S.stroke "currentColor"
792
+ , S.strokeWidth "2"
793
+ , S.strokeLinecap "round"
794
+ ]
795
+ []
796
+ ]
797
+
798
+ "dark" ->
799
+ [ Svg.path
800
+ [ S.d "M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z", S.fill "currentColor" ]
801
+ []
802
+ ]
803
+
804
+ _ ->
805
+ [ Svg.circle
806
+ [ S.cx "12", S.cy "12", S.r "9", S.stroke "currentColor", S.strokeWidth "2" ]
807
+ []
808
+ , Svg.path [ S.d "M12 3a9 9 0 0 1 0 18Z", S.fill "currentColor" ] []
809
+ ]
810
+ )
811
+
812
+
813
+ pager : Config msg -> Page -> Html msg
814
+ pager config page =
815
+ let
816
+ order =
817
+ flatten config
818
+
819
+ position =
820
+ order
821
+ |> List.indexedMap Tuple.pair
822
+ |> List.filter (\( _, item ) -> item.route == page.route)
823
+ |> List.head
824
+ |> Maybe.map Tuple.first
825
+
826
+ previous =
827
+ position
828
+ |> Maybe.andThen
829
+ (\index ->
830
+ if index > 0 then
831
+ itemAt (index - 1) order
832
+
833
+ else
834
+ Nothing
835
+ )
836
+
837
+ next =
838
+ position |> Maybe.andThen (\index -> itemAt (index + 1) order)
839
+ in
840
+ if previous == Nothing && next == Nothing then
841
+ Html.text ""
842
+
843
+ else
844
+ Ui.PageNav.view
845
+ { previous = Maybe.map pageNavItem previous
846
+ , next = Maybe.map pageNavItem next
847
+ , attributes = []
848
+ }
849
+
850
+
851
+ pageNavItem : Page.Entry -> Ui.PageNav.Item
852
+ pageNavItem entry =
853
+ { title = entry.title
854
+ , description = entry.summary
855
+ , href = entry.route
856
+ }
857
+
858
+
859
+ flatten : Config msg -> List Page.Entry
860
+ flatten config =
861
+ let
862
+ routeOf item =
863
+ case item of
864
+ PageItem page ->
865
+ [ page.route ]
866
+
867
+ Category category ->
868
+ List.concatMap routeOf category.items
869
+
870
+ routes =
871
+ List.concatMap routeOf config.nav
872
+
873
+ entryFor route =
874
+ config.site.entries
875
+ |> List.filter (\entry -> entry.route == route)
876
+ |> List.head
877
+ in
878
+ List.filterMap entryFor routes
879
+
880
+
881
+ itemAt : Int -> List Page.Entry -> Maybe Page.Entry
882
+ itemAt index items =
883
+ items |> List.drop index |> List.head
884
+
885
+
886
+ isActive : String -> String -> Bool
887
+ isActive path route =
888
+ normalize path == normalize route
889
+
890
+
891
+ normalize : String -> String
892
+ normalize path =
893
+ let
894
+ trimmed =
895
+ if String.length path > 1 && String.endsWith "/" path then
896
+ String.dropRight 1 path
897
+
898
+ else
899
+ path
900
+ in
901
+ if trimmed == "" then
902
+ "/"
903
+
904
+ else
905
+ trimmed
906
+
907
+
908
+ drawer : Config msg -> Html msg
909
+ drawer config =
910
+ Ui.Burger.view
911
+ { label = "Menu"
912
+ , logo =
913
+ Just (Html.span [ A.class "burger-wordmark" ] [ logoView config.site.meta.logo config ])
914
+ , header =
915
+ Just
916
+ (Html.div [ A.class "burger-panel" ]
917
+ [ Maybe.withDefault (Html.text "") (burgerControls config)
918
+ , sidebarView config [ A.class "burger-sidebar" ]
919
+ ]
920
+ )
921
+ , onToggle = config.onBurgerMsg Ui.Burger.Toggled
922
+ , onClose = config.onBurgerMsg Ui.Burger.Closed
923
+ , attributes = []
924
+ }
925
+ config.burger
926
+
927
+
928
+ {-| The controls under the logo band: theme tabs and, when the site has
929
+ more than one collection, the collection switcher. They sit together
930
+ instead of crowding the wordmark's band.
931
+ -}
932
+ burgerControls : Config msg -> Maybe (Html msg)
933
+ burgerControls config =
934
+ let
935
+ chrome =
936
+ config.site.chrome.header
937
+
938
+ parts =
939
+ (if chrome.theme then
940
+ [ Html.map config.onMenuTabs
941
+ (Ui.Tabs.view
942
+ { choices = themeChoices config.site.themeSystem
943
+ , size = Ui.Tabs.Compact
944
+ , attributes = []
945
+ }
946
+ config.menuTabs
947
+ )
948
+ ]
949
+
950
+ else
951
+ []
952
+ )
953
+ ++ (if chrome.docs && List.length config.docs > 1 then
954
+ [ menuDocsTabsView config ]
955
+
956
+ else
957
+ []
958
+ )
959
+ in
960
+ if List.isEmpty parts then
961
+ Nothing
962
+
963
+ else
964
+ Just (Html.div [ A.class "burger-controls" ] parts)