@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,396 @@
1
+ module Ui.Search exposing
2
+ ( Item
3
+ , Model
4
+ , Msg(..)
5
+ , init
6
+ , subscriptions
7
+ , update
8
+ , view
9
+ )
10
+
11
+ {-| The search combobox: an input whose results menu opens while the
12
+ field is focused and closes on blur, Escape, or selection. A host that
13
+ mounts the combobox in a dialog passes `persistent = True`, so the list
14
+ stays while focus moves around the dialog. The host owns the query and
15
+ the filtering; the component owns the focus state.
16
+
17
+ type Msg
18
+ = SearchMsg Ui.Search.Msg
19
+
20
+ model =
21
+ { search = Ui.Search.init "nav-search" }
22
+
23
+ Ui.Search.view
24
+ { query = model.query
25
+ , placeholder = "Search components…"
26
+ , onInput = QueryChanged
27
+ , onClear = QueryCleared
28
+ , items = model.results
29
+ , onSelect = Navigate
30
+ , emptyText = "No matches"
31
+ , persistent = False
32
+ , attributes = []
33
+ }
34
+ model.search
35
+
36
+ `onSelect` fires with the chosen item's value; the host navigates (or
37
+ acts) there. While focused, Escape closes the menu.
38
+
39
+ -}
40
+
41
+ import Browser.Events
42
+ import Html exposing (Attribute, Html, button, div, form, input, span, text)
43
+ import Html.Attributes as Attr
44
+ import Html.Events
45
+ import Json.Decode as Decode
46
+ import Ui.Icon
47
+
48
+
49
+
50
+ -- MODEL
51
+
52
+
53
+ {-| Whether the results menu is open (the field is focused).
54
+ -}
55
+ type alias Model =
56
+ { id : String
57
+ , focused : Bool
58
+ , selected : Int
59
+ }
60
+
61
+
62
+ {-| Create the model. The id must be unique per page instance.
63
+ -}
64
+ init : String -> Model
65
+ init id =
66
+ { id = id
67
+ , focused = False
68
+ , selected = 0
69
+ }
70
+
71
+
72
+
73
+ -- MSG
74
+
75
+
76
+ {-| Internal messages; the host maps them wholesale. `Select` carries
77
+ the chosen item's value — the host acts there.
78
+ -}
79
+ type Msg value
80
+ = Focused
81
+ | Blurred
82
+ | Move { up : Bool, count : Int }
83
+ | Select value
84
+
85
+
86
+ {-| While focused, Escape closes the menu.
87
+ -}
88
+ subscriptions : Model -> Sub (Msg value)
89
+ subscriptions model =
90
+ if model.focused then
91
+ Browser.Events.onKeyDown
92
+ (Decode.field "key" Decode.string
93
+ |> Decode.andThen
94
+ (\key ->
95
+ if key == "Escape" then
96
+ Decode.succeed Blurred
97
+
98
+ else
99
+ Decode.fail "not escape"
100
+ )
101
+ )
102
+
103
+ else
104
+ Sub.none
105
+
106
+
107
+
108
+ -- UPDATE
109
+
110
+
111
+ {-| Advance the focus state. On `Select` the menu closes; the host
112
+ acts on the value in its own mapping.
113
+ -}
114
+ update : Msg value -> Model -> ( Model, Cmd (Msg value) )
115
+ update msg model =
116
+ case msg of
117
+ Focused ->
118
+ ( { model | focused = True, selected = 0 }, Cmd.none )
119
+
120
+ Blurred ->
121
+ ( { model | focused = False }, Cmd.none )
122
+
123
+ Move { up, count } ->
124
+ if count <= 1 then
125
+ ( { model | selected = 0 }, Cmd.none )
126
+
127
+ else
128
+ let
129
+ step =
130
+ if up then
131
+ -1
132
+
133
+ else
134
+ 1
135
+ in
136
+ ( { model
137
+ | selected =
138
+ modBy count (model.selected + count + step)
139
+ }
140
+ , Cmd.none
141
+ )
142
+
143
+ Select _ ->
144
+ ( { model | focused = False }, Cmd.none )
145
+
146
+
147
+
148
+ -- VIEW
149
+
150
+
151
+ {-| One result: a label, an optional muted detail line, and the value
152
+ the host owns.
153
+ -}
154
+ type alias Item value =
155
+ { label : String
156
+ , detail : Maybe String
157
+ , snippet : Maybe String
158
+ , value : value
159
+ }
160
+
161
+
162
+ {-| Render the combobox. `items` are the (already filtered) results
163
+ for the current query. The menu opens on focus, or stays open with
164
+ `persistent = True`; Enter selects the top result; a click on a result
165
+ selects it without losing focus mid-click.
166
+ -}
167
+ view :
168
+ { query : String
169
+ , placeholder : String
170
+ , onInput : String -> msg
171
+ , onClear : msg
172
+ , items : List (Item value)
173
+ , toMsg : Msg value -> msg
174
+ , emptyText : String
175
+ , persistent : Bool
176
+ , attributes : List (Attribute msg)
177
+ }
178
+ -> Model
179
+ -> Html msg
180
+ view config model =
181
+ let
182
+ hasText =
183
+ not (String.isEmpty config.query)
184
+
185
+ menu =
186
+ -- A dialog owns the search surface, so its results stay put
187
+ -- even when focus moves to the legend or the dismiss chip;
188
+ -- in a header field the menu still closes on blur.
189
+ if model.focused || config.persistent then
190
+ [ div [ Attr.class "search-menu" ]
191
+ (if List.isEmpty config.items then
192
+ [ div [ Attr.class "search-empty" ] [ text config.emptyText ] ]
193
+
194
+ else
195
+ List.indexedMap resultNode config.items
196
+ )
197
+ ]
198
+
199
+ else
200
+ []
201
+
202
+ itemCount =
203
+ List.length config.items
204
+
205
+ selected =
206
+ if itemCount == 0 then
207
+ 0
208
+
209
+ else
210
+ modBy itemCount model.selected
211
+
212
+ selectedValue =
213
+ case List.drop selected config.items |> List.head of
214
+ Just item ->
215
+ Just item.value
216
+
217
+ Nothing ->
218
+ List.head config.items |> Maybe.map .value
219
+
220
+ resultNode index item =
221
+ div
222
+ [ Attr.classList
223
+ [ ( "search-item", True )
224
+ , ( "selected", index == selected )
225
+ ]
226
+ , Html.Events.preventDefaultOn "mousedown"
227
+ (Decode.succeed ( config.toMsg (Select item.value), True ))
228
+ ]
229
+ [ div [ Attr.class "search-item-head" ]
230
+ [ span [ Attr.class "label" ] [ text item.label ]
231
+ , case item.detail of
232
+ Just detail ->
233
+ span [ Attr.class "detail" ] [ text detail ]
234
+
235
+ Nothing ->
236
+ Html.text ""
237
+ ]
238
+ , case item.snippet of
239
+ Just snippet ->
240
+ div [ Attr.class "search-snippet" ]
241
+ (highlightWords
242
+ (queryNeedles config.query)
243
+ snippet
244
+ )
245
+
246
+ Nothing ->
247
+ Html.text ""
248
+ ]
249
+
250
+ in
251
+ form
252
+ ([ Attr.classList [ ( "search", True ) ]
253
+ , Attr.id model.id
254
+ , case selectedValue of
255
+ Just value ->
256
+ Html.Events.onSubmit (config.toMsg (Select value))
257
+
258
+ Nothing ->
259
+ Html.Events.onSubmit (config.toMsg Focused)
260
+ ]
261
+ ++ config.attributes
262
+ )
263
+ ([ input
264
+ [ Attr.type_ "search"
265
+ , Attr.class "search-input"
266
+ , Attr.id (model.id ++ "-input")
267
+ , Attr.placeholder config.placeholder
268
+ , Attr.value config.query
269
+ , Attr.autocomplete False
270
+ , Html.Events.onInput config.onInput
271
+ , Html.Events.onFocus (config.toMsg Focused)
272
+ , Html.Events.onBlur (config.toMsg Blurred)
273
+ , Html.Events.preventDefaultOn "keydown"
274
+ (Decode.field "key" Decode.string
275
+ |> Decode.andThen
276
+ (\key ->
277
+ case key of
278
+ "ArrowUp" ->
279
+ Decode.succeed
280
+ ( config.toMsg (Move { up = True, count = itemCount })
281
+ , True
282
+ )
283
+
284
+ "ArrowDown" ->
285
+ Decode.succeed
286
+ ( config.toMsg (Move { up = False, count = itemCount })
287
+ , True
288
+ )
289
+
290
+ _ ->
291
+ Decode.fail "not an arrow"
292
+ )
293
+ )
294
+ ]
295
+ []
296
+ , button
297
+ [ Attr.classList [ ( "clear", True ), ( "visible", hasText ) ]
298
+ , Attr.type_ "button"
299
+ , Html.Events.onClick config.onClear
300
+ , Attr.attribute "aria-label" "Clear search"
301
+ , Attr.attribute "tabindex"
302
+ (if hasText then
303
+ "0"
304
+
305
+ else
306
+ "-1"
307
+ )
308
+ ]
309
+ [ Ui.Icon.view Ui.Icon.Clear ]
310
+ ]
311
+ ++ menu
312
+ )
313
+
314
+
315
+
316
+ -- SNIPPET HIGHLIGHTING
317
+
318
+
319
+ {-| The query as the needles the snippet highlighter looks for:
320
+ whitespace-split, lowercased empties dropped.
321
+ -}
322
+ queryWords : String -> List String
323
+ queryWords query =
324
+ query
325
+ |> String.words
326
+ |> List.map String.toLower
327
+ |> List.filter (String.isEmpty >> not)
328
+
329
+
330
+ {-| The needles in priority order. A multi-word query is tried as one run
331
+ first, so "openai response" marks the phrase, space included, instead of
332
+ two adjacent chips. The phrase leads because the highlighter takes the
333
+ first needle at the earliest index.
334
+ -}
335
+ queryNeedles : String -> List String
336
+ queryNeedles query =
337
+ let
338
+ words =
339
+ queryWords query
340
+ in
341
+ if List.length words > 1 then
342
+ String.toLower (String.trim query) :: words
343
+
344
+ else
345
+ words
346
+
347
+
348
+ {-| The snippet with every query word wrapped in a hit mark. Case
349
+ insensitive; the hit keeps the snippet's own casing.
350
+ -}
351
+ highlightWords : List String -> String -> List (Html msg)
352
+ highlightWords needles snippet =
353
+ if List.isEmpty needles then
354
+ [ text snippet ]
355
+
356
+ else
357
+ highlightHelp snippet needles []
358
+
359
+
360
+ highlightHelp : String -> List String -> List (Html msg) -> List (Html msg)
361
+ highlightHelp rest needles acc =
362
+ if String.isEmpty rest then
363
+ List.reverse acc
364
+
365
+ else
366
+ case earliestHit rest needles of
367
+ Nothing ->
368
+ List.reverse (text rest :: acc)
369
+
370
+ Just ( index, needle ) ->
371
+ let
372
+ hit =
373
+ String.slice index (index + String.length needle) rest
374
+ in
375
+ highlightHelp
376
+ (String.dropLeft (index + String.length needle) rest)
377
+ needles
378
+ (span [ Attr.class "search-hit" ] [ text hit ]
379
+ :: text (String.slice 0 index rest)
380
+ :: acc
381
+ )
382
+
383
+
384
+ {-| The earliest case-insensitive occurrence of any needle.
385
+ -}
386
+ earliestHit : String -> List String -> Maybe ( Int, String )
387
+ earliestHit rest needles =
388
+ needles
389
+ |> List.filterMap
390
+ (\needle ->
391
+ String.indices (String.toLower needle) (String.toLower rest)
392
+ |> List.head
393
+ |> Maybe.map (\index -> ( index, needle ))
394
+ )
395
+ |> List.sortBy Tuple.first
396
+ |> List.head
@@ -0,0 +1,78 @@
1
+ module Ui.SearchBox exposing (Size(..), view)
2
+
3
+ {-| A search input with a clear button that appears while there is text
4
+ to clear. Shared by the API-keys and models toolbars in the reference
5
+ app.
6
+ -}
7
+
8
+ import Html exposing (Attribute, Html, button, div, input)
9
+ import Html.Attributes exposing (attribute, type_, value)
10
+ import Html.Events
11
+ import Ui.Icon
12
+
13
+
14
+ {-| The control height. `Regular` matches toolbar controls; `Compact`
15
+ is the dense height used next to compact buttons and dropdowns.
16
+ -}
17
+ type Size
18
+ = Regular
19
+ | Compact
20
+
21
+
22
+ {-| Render a search box. The clear button fades in while there is text
23
+ and fades out again when the box empties; it stays mounted so the
24
+ fade-out can play and is inert while hidden. Clicking it sends
25
+ `onClear`; the caller is responsible for emptying the query (and, if
26
+ it likes, refocusing the input).
27
+ -}
28
+ view :
29
+ { id : String
30
+ , value : String
31
+ , placeholder : String
32
+ , onInput : String -> msg
33
+ , onClear : msg
34
+ , size : Size
35
+ , attributes : List (Attribute msg)
36
+ }
37
+ -> Html msg
38
+ view config =
39
+ let
40
+ hasText =
41
+ not (String.isEmpty config.value)
42
+
43
+ compactClass =
44
+ case config.size of
45
+ Regular ->
46
+ []
47
+
48
+ Compact ->
49
+ [ ( "compact", True ) ]
50
+ in
51
+ div
52
+ ([ Html.Attributes.classList (( "search-box", True ) :: compactClass) ]
53
+ ++ config.attributes
54
+ )
55
+ [ input
56
+ [ type_ "search"
57
+ , Html.Attributes.class "search"
58
+ , Html.Attributes.id config.id
59
+ , Html.Attributes.placeholder config.placeholder
60
+ , value config.value
61
+ , Html.Events.onInput config.onInput
62
+ ]
63
+ []
64
+ , button
65
+ [ Html.Attributes.classList [ ( "clear", True ), ( "visible", hasText ) ]
66
+ , type_ "button"
67
+ , Html.Events.onClick config.onClear
68
+ , attribute "aria-label" "Clear search"
69
+ , attribute "tabindex"
70
+ (if hasText then
71
+ "0"
72
+
73
+ else
74
+ "-1"
75
+ )
76
+ ]
77
+ [ Ui.Icon.view Ui.Icon.Clear ]
78
+ ]
@@ -0,0 +1,21 @@
1
+ module Ui.Section exposing (view)
2
+
3
+ {-| The labeled section: a `section-label` heading followed by body
4
+ content, the pattern every catalog sample and settings block uses.
5
+ -}
6
+
7
+ import Html exposing (Attribute, Html)
8
+ import Ui.Typography
9
+
10
+
11
+ {-| Render a section: a small bold label heading the content below it.
12
+ -}
13
+ view :
14
+ { label : String
15
+ , content : List (Html msg)
16
+ , attributes : List (Attribute msg)
17
+ }
18
+ -> Html msg
19
+ view config =
20
+ Html.section config.attributes
21
+ (Ui.Typography.sectionLabel [ Html.text config.label ] :: config.content)