@link-foundation/ui-components 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.
- package/CONFIGURATIONS.md +74 -0
- package/ICONS.md +76 -0
- package/LICENSE +24 -0
- package/README.md +1499 -2
- package/bin/lino-network.mjs +71 -0
- package/dist/icons/ATTRIBUTION.md +602 -0
- package/dist/icons/NOTICE.lino +1261 -0
- package/dist/icons/brand.js +31 -0
- package/dist/icons/brand.svg +3 -0
- package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
- package/dist/icons/licenses/brand/LICENSE.md +30 -0
- package/dist/icons/licenses/lucide/LICENSE +43 -0
- package/dist/icons/licenses/material-symbols/LICENSE +202 -0
- package/dist/icons/licenses/material-symbols/NOTICE +12 -0
- package/dist/icons/licenses/tabler/LICENSE +21 -0
- package/dist/icons/lucide.js +681 -0
- package/dist/icons/lucide.svg +34 -0
- package/dist/icons/material-symbols.js +681 -0
- package/dist/icons/material-symbols.svg +34 -0
- package/dist/icons/own.js +521 -0
- package/dist/icons/own.svg +34 -0
- package/dist/icons/tabler.js +681 -0
- package/dist/icons/tabler.svg +34 -0
- package/dist/network-layout-NOTICE.md +6 -0
- package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
- package/dist/network-layout-d3-force-LICENSE.txt +13 -0
- package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
- package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
- package/dist/network-layout-dagre-LICENSE.txt +19 -0
- package/dist/network-layout.worker.mjs +2 -0
- package/package.json +246 -4
- package/src/a11y/announce.js +88 -0
- package/src/a11y/bind-machine.js +181 -0
- package/src/a11y/focus.js +169 -0
- package/src/a11y/index.d.ts +89 -0
- package/src/a11y/index.js +19 -0
- package/src/a11y/keys.js +182 -0
- package/src/a11y/roving.js +167 -0
- package/src/a11y/typeahead.js +82 -0
- package/src/behavior/actions.js +235 -0
- package/src/behavior/diagnostics.js +73 -0
- package/src/behavior/dom.d.ts +38 -0
- package/src/behavior/dom.js +420 -0
- package/src/behavior/index.d.ts +211 -0
- package/src/behavior/index.js +29 -0
- package/src/behavior/interpret.js +454 -0
- package/src/behavior/machines/disclosure.lino +46 -0
- package/src/behavior/machines/index.js +91 -0
- package/src/behavior/machines/toggle.lino +25 -0
- package/src/behavior/parse-machine.js +367 -0
- package/src/charts/README.md +78 -0
- package/src/charts/activity-layout.js +350 -0
- package/src/charts/activity-model.js +130 -0
- package/src/charts/activity-validation.js +31 -0
- package/src/charts/chart-model.js +667 -0
- package/src/charts/chart.js +518 -0
- package/src/charts/echarts-adapter.d.ts +23 -0
- package/src/charts/echarts-adapter.js +240 -0
- package/src/charts/element.js +330 -0
- package/src/charts/errors.js +62 -0
- package/src/charts/gauge.js +27 -0
- package/src/charts/index.d.ts +344 -0
- package/src/charts/index.js +59 -0
- package/src/charts/layout.js +542 -0
- package/src/charts/lino.js +158 -0
- package/src/charts/mark-options.js +78 -0
- package/src/charts/read.js +101 -0
- package/src/charts/renderer-features.js +8 -0
- package/src/charts/scales.js +223 -0
- package/src/charts/small-model.js +223 -0
- package/src/charts/small-svg.js +269 -0
- package/src/charts/sparkline.js +27 -0
- package/src/charts/stat-tile.js +37 -0
- package/src/charts/summary.js +193 -0
- package/src/charts/svg-renderer.js +226 -0
- package/src/charts/svg.js +69 -0
- package/src/charts/tag-cloud.js +129 -0
- package/src/charts/tokens.js +171 -0
- package/src/charts/tooltip.js +47 -0
- package/src/charts/values.js +146 -0
- package/src/chat/README.md +142 -0
- package/src/chat/actions.js +75 -0
- package/src/chat/chat-contract.js +95 -0
- package/src/chat/chat-list.js +42 -0
- package/src/chat/chat-model.js +125 -0
- package/src/chat/chat.css +228 -0
- package/src/chat/composer.js +131 -0
- package/src/chat/day-separator.js +12 -0
- package/src/chat/dom.js +33 -0
- package/src/chat/follow.js +49 -0
- package/src/chat/index.d.ts +142 -0
- package/src/chat/index.js +13 -0
- package/src/chat/message-bubble.js +191 -0
- package/src/chat/message-stream.js +331 -0
- package/src/chat/reasoning-trace.js +70 -0
- package/src/chat/selection.js +39 -0
- package/src/chat/skins/bubbles.lino +2 -0
- package/src/chat/skins/cards.lino +4 -0
- package/src/chat/skins/compact.lino +4 -0
- package/src/chat/skins/signal.lino +25 -0
- package/src/chat/skins/t3.lino +25 -0
- package/src/chat/skins/telegram.lino +31 -0
- package/src/chat/skins/whatsapp.lino +25 -0
- package/src/chat/stream-keys.js +57 -0
- package/src/chat/stream-window.js +159 -0
- package/src/chat/vocabulary.js +19 -0
- package/src/controls/accordion.js +160 -0
- package/src/controls/avatar.js +80 -0
- package/src/controls/badge.js +48 -0
- package/src/controls/button-template.js +32 -0
- package/src/controls/button.js +97 -0
- package/src/controls/catalog.lino +84 -0
- package/src/controls/checkbox.js +112 -0
- package/src/controls/chip.js +140 -0
- package/src/controls/choices.js +45 -0
- package/src/controls/color-field.js +217 -0
- package/src/controls/color-popover.js +135 -0
- package/src/controls/color-rgb.js +80 -0
- package/src/controls/color.js +67 -0
- package/src/controls/combobox.js +192 -0
- package/src/controls/dom.js +261 -0
- package/src/controls/icon-button.js +33 -0
- package/src/controls/index.d.ts +163 -0
- package/src/controls/index.js +182 -0
- package/src/controls/kinds-text.js +358 -0
- package/src/controls/kinds.lino +350 -0
- package/src/controls/label.js +52 -0
- package/src/controls/link.js +101 -0
- package/src/controls/listbox.js +144 -0
- package/src/controls/machines/button.lino +20 -0
- package/src/controls/machines/checkbox.lino +17 -0
- package/src/controls/machines/chip.lino +20 -0
- package/src/controls/machines/color-field.lino +23 -0
- package/src/controls/machines/combobox.lino +82 -0
- package/src/controls/machines/icon-button.lino +20 -0
- package/src/controls/machines/index.js +586 -0
- package/src/controls/machines/number-field.lino +71 -0
- package/src/controls/machines/radio-group.lino +17 -0
- package/src/controls/machines/select.lino +122 -0
- package/src/controls/machines/slider.lino +99 -0
- package/src/controls/machines/switch.lino +19 -0
- package/src/controls/machines/text-area.lino +26 -0
- package/src/controls/machines/text-field.lino +26 -0
- package/src/controls/number-field.js +239 -0
- package/src/controls/numeric-keys.js +125 -0
- package/src/controls/option.js +54 -0
- package/src/controls/progress.js +76 -0
- package/src/controls/radio-group.js +234 -0
- package/src/controls/select.js +229 -0
- package/src/controls/slider.js +234 -0
- package/src/controls/stories.js +172 -0
- package/src/controls/styles.css +1060 -0
- package/src/controls/switch.js +95 -0
- package/src/controls/text-area.js +39 -0
- package/src/controls/text-field.js +131 -0
- package/src/controls/vocabulary.js +164 -0
- package/src/data/data.css +95 -0
- package/src/data/index.d.ts +83 -0
- package/src/data/index.js +10 -0
- package/src/data/keyboard.js +189 -0
- package/src/data/list.js +215 -0
- package/src/data/render-data.js +116 -0
- package/src/data/selection-dom.js +39 -0
- package/src/data/selection-model.js +43 -0
- package/src/data/sort-model.js +42 -0
- package/src/data/source.js +45 -0
- package/src/data/table.js +160 -0
- package/src/data/tree-model.js +41 -0
- package/src/data/tree.js +55 -0
- package/src/data/viewport.js +216 -0
- package/src/data/virtual-range.js +92 -0
- package/src/data/vocabulary.js +67 -0
- package/src/diagrams/diagram-model.js +511 -0
- package/src/diagrams/diagram.js +204 -0
- package/src/diagrams/index.d.ts +225 -0
- package/src/diagrams/index.js +48 -0
- package/src/diagrams/layout-dagre.js +164 -0
- package/src/diagrams/layout-plugins.js +131 -0
- package/src/diagrams/mermaid-export.js +232 -0
- package/src/diagrams/mermaid-view.js +229 -0
- package/src/diagrams/svg-diagram.js +215 -0
- package/src/editor/code-editor.js +206 -0
- package/src/editor/documents-model.js +170 -0
- package/src/editor/documents-persistence.js +85 -0
- package/src/editor/editor-engine.js +22 -0
- package/src/editor/editor-ui.js +203 -0
- package/src/editor/editor.css +106 -0
- package/src/editor/engines/codemirror.js +227 -0
- package/src/editor/engines/monaco.js +219 -0
- package/src/editor/index.d.ts +111 -0
- package/src/editor/index.js +14 -0
- package/src/editor/lino-highlight.js +106 -0
- package/src/editor/lino-structure.js +85 -0
- package/src/editor/validate-lino.js +43 -0
- package/src/embed/README.md +161 -0
- package/src/embed/controller.js +223 -0
- package/src/embed/element.js +141 -0
- package/src/embed/index.d.ts +75 -0
- package/src/embed/index.js +9 -0
- package/src/embed/providers/telegram.d.ts +3 -0
- package/src/embed/providers/telegram.js +38 -0
- package/src/embed/providers/vk.d.ts +3 -0
- package/src/embed/providers/vk.js +42 -0
- package/src/embed/providers/x.d.ts +3 -0
- package/src/embed/providers/x.js +31 -0
- package/src/embed/registry.js +35 -0
- package/src/embed/script.js +73 -0
- package/src/embed/view.js +122 -0
- package/src/icons/adapters/lucide.d.ts +15 -0
- package/src/icons/adapters/lucide.js +142 -0
- package/src/icons/adapters/material-symbols.d.ts +13 -0
- package/src/icons/adapters/material-symbols.js +113 -0
- package/src/icons/adapters/shared.d.ts +38 -0
- package/src/icons/adapters/shared.js +157 -0
- package/src/icons/adapters/simple-icons.d.ts +9 -0
- package/src/icons/adapters/simple-icons.js +38 -0
- package/src/icons/adapters/tabler.d.ts +9 -0
- package/src/icons/adapters/tabler.js +86 -0
- package/src/icons/icon-registry.js +215 -0
- package/src/icons/icon.js +356 -0
- package/src/icons/index.d.ts +123 -0
- package/src/icons/index.js +30 -0
- package/src/icons/names.js +51 -0
- package/src/icons/own-icons.js +521 -0
- package/src/icons/presentation.js +55 -0
- package/src/icons/svg.js +136 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +40 -0
- package/src/layout/README.md +102 -0
- package/src/layout/app-shell.js +150 -0
- package/src/layout/catalog.lino +27 -0
- package/src/layout/dock-model.js +576 -0
- package/src/layout/dock-view.js +312 -0
- package/src/layout/dock.js +352 -0
- package/src/layout/dom.js +312 -0
- package/src/layout/grid.js +192 -0
- package/src/layout/index.d.ts +267 -0
- package/src/layout/index.js +60 -0
- package/src/layout/layer-manager.js +120 -0
- package/src/layout/layout.css +760 -0
- package/src/layout/menu.js +141 -0
- package/src/layout/nav-strip.js +174 -0
- package/src/layout/page-links.js +166 -0
- package/src/layout/panel.js +26 -0
- package/src/layout/pref-switches.js +209 -0
- package/src/layout/split-model.js +270 -0
- package/src/layout/split.js +430 -0
- package/src/layout/stack.js +86 -0
- package/src/layout/surfaces.js +119 -0
- package/src/layout/tab-group.js +151 -0
- package/src/layout/tab-strip.js +277 -0
- package/src/layout/vocabulary.js +229 -0
- package/src/layout/window-frame.js +222 -0
- package/src/layout/window.js +146 -0
- package/src/links-view/animator.js +144 -0
- package/src/links-view/configuration-classes.js +150 -0
- package/src/links-view/configuration-model.js +191 -0
- package/src/links-view/configuration-notations.js +230 -0
- package/src/links-view/configurations.d.ts +73 -0
- package/src/links-view/configurations.js +33 -0
- package/src/links-view/create-layout-runner.js +79 -0
- package/src/links-view/doublet-curves.js +239 -0
- package/src/links-view/doublet-layout.js +148 -0
- package/src/links-view/doublet-markers.js +109 -0
- package/src/links-view/doublet-options.js +369 -0
- package/src/links-view/doublet-svg.js +156 -0
- package/src/links-view/doublet.js +230 -0
- package/src/links-view/export.js +146 -0
- package/src/links-view/geometry.js +409 -0
- package/src/links-view/index.d.ts +1029 -0
- package/src/links-view/index.js +140 -0
- package/src/links-view/labels.js +28 -0
- package/src/links-view/layout-worker-entry.mjs +2 -0
- package/src/links-view/layout-worker.js +28 -0
- package/src/links-view/layouts/circle.js +7 -0
- package/src/links-view/layouts/force.js +76 -0
- package/src/links-view/layouts/grid.js +7 -0
- package/src/links-view/layouts/hex.js +8 -0
- package/src/links-view/layouts/index.js +15 -0
- package/src/links-view/layouts/layered.js +29 -0
- package/src/links-view/layouts/regular.js +27 -0
- package/src/links-view/layouts/spiral.js +10 -0
- package/src/links-view/link-view.js +494 -0
- package/src/links-view/links-gallery.js +306 -0
- package/src/links-view/links-network.js +496 -0
- package/src/links-view/lino-network-source.js +122 -0
- package/src/links-view/lino-network.js +233 -0
- package/src/links-view/lino-to-network.js +252 -0
- package/src/links-view/markers.js +192 -0
- package/src/links-view/model.js +233 -0
- package/src/links-view/network-editor/dom.js +36 -0
- package/src/links-view/network-editor/editor.js +202 -0
- package/src/links-view/network-editor/model.js +163 -0
- package/src/links-view/network-editor/options.js +265 -0
- package/src/links-view/network-editor/panels.js +423 -0
- package/src/links-view/network-editor/presets.js +76 -0
- package/src/links-view/network-editor/provider.js +93 -0
- package/src/links-view/network-editor/remap.js +45 -0
- package/src/links-view/network-editor/schema.js +224 -0
- package/src/links-view/network-editor/share.js +232 -0
- package/src/links-view/network-editor/styles.js +19 -0
- package/src/links-view/network-editor/url-sync.js +131 -0
- package/src/links-view/network-interaction.js +228 -0
- package/src/links-view/network-model.js +85 -0
- package/src/links-view/network-renderer.js +259 -0
- package/src/links-view/network-scene.js +245 -0
- package/src/links-view/network-source.js +82 -0
- package/src/links-view/network-vocabulary.js +18 -0
- package/src/links-view/presentation.js +199 -0
- package/src/links-view/render-canvas.js +102 -0
- package/src/links-view/render-svg.js +118 -0
- package/src/links-view/scene.js +233 -0
- package/src/links-view/solver-job.js +106 -0
- package/src/links-view/tokens.js +114 -0
- package/src/links-view/zoom-pan.js +203 -0
- package/src/overlays/catalog.lino +89 -0
- package/src/overlays/context-menu.js +110 -0
- package/src/overlays/dialog.js +117 -0
- package/src/overlays/dom.js +168 -0
- package/src/overlays/drawer.js +8 -0
- package/src/overlays/index.d.ts +80 -0
- package/src/overlays/index.js +25 -0
- package/src/overlays/kinds.lino +137 -0
- package/src/overlays/list-popover.js +129 -0
- package/src/overlays/machines/index.js +71 -0
- package/src/overlays/machines/surface.lino +11 -0
- package/src/overlays/machines/tabs.lino +7 -0
- package/src/overlays/machines/toast.lino +16 -0
- package/src/overlays/machines/tooltip.lino +29 -0
- package/src/overlays/menu.js +240 -0
- package/src/overlays/popover.js +194 -0
- package/src/overlays/position.js +84 -0
- package/src/overlays/radial-geometry.js +38 -0
- package/src/overlays/radial-menu.js +50 -0
- package/src/overlays/styles.css +155 -0
- package/src/overlays/tabs.js +125 -0
- package/src/overlays/toast-queue.js +105 -0
- package/src/overlays/toast.js +163 -0
- package/src/overlays/tooltip.js +110 -0
- package/src/overlays/vocabulary.js +3 -0
- package/src/settings/conditions.js +44 -0
- package/src/settings/control-for.js +62 -0
- package/src/settings/field-control.js +201 -0
- package/src/settings/index.d.ts +201 -0
- package/src/settings/index.js +3 -0
- package/src/settings/messages.js +112 -0
- package/src/settings/miniature.js +26 -0
- package/src/settings/panel-actions.js +234 -0
- package/src/settings/panel-model.js +49 -0
- package/src/settings/panel-refresh.js +56 -0
- package/src/settings/panel-rows.js +200 -0
- package/src/settings/preset-cards.js +43 -0
- package/src/settings/saved-looks.js +227 -0
- package/src/settings/section-layout.js +95 -0
- package/src/settings/section-tabs.js +175 -0
- package/src/settings/settings-panel.js +192 -0
- package/src/settings/settings.css +178 -0
- package/stories/accordion.lino +14 -0
- package/stories/alert-dialog.lino +4 -0
- package/stories/app-bar.lino +10 -0
- package/stories/avatar.lino +7 -0
- package/stories/badge.lino +12 -0
- package/stories/button.lino +17 -0
- package/stories/card.lino +10 -0
- package/stories/checkbox.lino +14 -0
- package/stories/chip.lino +19 -0
- package/stories/color-field.lino +9 -0
- package/stories/combobox.lino +10 -0
- package/stories/container.lino +11 -0
- package/stories/context-menu.lino +15 -0
- package/stories/dialog.lino +16 -0
- package/stories/drawer.lino +12 -0
- package/stories/icon-button.lino +13 -0
- package/stories/label.lino +7 -0
- package/stories/link-cards.lino +9 -0
- package/stories/link.lino +9 -0
- package/stories/menu-item.lino +6 -0
- package/stories/menu-separator.lino +7 -0
- package/stories/menu.lino +30 -0
- package/stories/nav-strip.lino +11 -0
- package/stories/number-field.lino +16 -0
- package/stories/option.lino +10 -0
- package/stories/paper.lino +11 -0
- package/stories/popover.lino +4 -0
- package/stories/pref-switches.lino +4 -0
- package/stories/progress.lino +14 -0
- package/stories/radial-menu.lino +19 -0
- package/stories/radio-group.lino +22 -0
- package/stories/radio.lino +10 -0
- package/stories/section-nav.lino +9 -0
- package/stories/select.lino +16 -0
- package/stories/slider.lino +14 -0
- package/stories/switch.lino +10 -0
- package/stories/tab-panel.lino +7 -0
- package/stories/tab.lino +7 -0
- package/stories/tabs.lino +25 -0
- package/stories/text-area.lino +12 -0
- package/stories/text-field.lino +23 -0
- package/stories/titled-section.lino +7 -0
- package/stories/toast.lino +3 -0
- package/stories/toaster.lino +2 -0
- package/stories/tooltip.lino +3 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
telegram: theme
|
|
2
|
+
token chat.bg '#dbddbb'
|
|
3
|
+
token chat.bg.second '#6ba587'
|
|
4
|
+
token chat.bg.third '#d5d88d'
|
|
5
|
+
token chat.bg.fourth '#88b884'
|
|
6
|
+
token chat.sidebar '#ffffff'
|
|
7
|
+
token chat.bubble.in '#ffffff'
|
|
8
|
+
token chat.bubble.in.text '#000000'
|
|
9
|
+
token chat.bubble.out '#effdde'
|
|
10
|
+
token chat.bubble.out.text '#000000'
|
|
11
|
+
token chat.bubble.radius 15px
|
|
12
|
+
token chat.bubble.tail 15px
|
|
13
|
+
token chat.bubble.padding.block 0.4rem
|
|
14
|
+
token chat.bubble.padding.inline 0.7rem
|
|
15
|
+
token chat.text '#17212b'
|
|
16
|
+
token chat.column 44rem
|
|
17
|
+
token chat.selection.bg '#164e63'
|
|
18
|
+
token chat.selection.text '#ffffff'
|
|
19
|
+
mode dark
|
|
20
|
+
token chat.bg '#0e1621'
|
|
21
|
+
token chat.bg.second '#0e1621'
|
|
22
|
+
token chat.bg.third '#0e1621'
|
|
23
|
+
token chat.bg.fourth '#0e1621'
|
|
24
|
+
token chat.sidebar '#17212b'
|
|
25
|
+
token chat.bubble.in '#182533'
|
|
26
|
+
token chat.bubble.in.text '#f5f5f5'
|
|
27
|
+
token chat.bubble.out '#2b5278'
|
|
28
|
+
token chat.bubble.out.text '#f5f5f5'
|
|
29
|
+
token chat.text '#f4f6f8'
|
|
30
|
+
token chat.selection.bg '#b9e6fb'
|
|
31
|
+
token chat.selection.text '#102b39'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
whatsapp: theme
|
|
2
|
+
token chat.bg '#efeae2'
|
|
3
|
+
token chat.sidebar '#ffffff'
|
|
4
|
+
token chat.bubble.in '#ffffff'
|
|
5
|
+
token chat.bubble.in.text '#111b21'
|
|
6
|
+
token chat.bubble.out '#d9fdd3'
|
|
7
|
+
token chat.bubble.out.text '#111b21'
|
|
8
|
+
token chat.bubble.radius 7.5px
|
|
9
|
+
token chat.bubble.tail 11.5px
|
|
10
|
+
token chat.bubble.padding.block 0.35rem
|
|
11
|
+
token chat.bubble.padding.inline 0.6rem
|
|
12
|
+
token chat.text '#17212b'
|
|
13
|
+
token chat.column 44rem
|
|
14
|
+
token chat.selection.bg '#164e63'
|
|
15
|
+
token chat.selection.text '#ffffff'
|
|
16
|
+
mode dark
|
|
17
|
+
token chat.bg '#0b141a'
|
|
18
|
+
token chat.sidebar '#111b21'
|
|
19
|
+
token chat.bubble.in '#202c33'
|
|
20
|
+
token chat.bubble.in.text '#e9edef'
|
|
21
|
+
token chat.bubble.out '#005c4b'
|
|
22
|
+
token chat.bubble.out.text '#e9edef'
|
|
23
|
+
token chat.text '#f4f6f8'
|
|
24
|
+
token chat.selection.bg '#b9e6fb'
|
|
25
|
+
token chat.selection.text '#102b39'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function focusMessage(at, event, state, keys) {
|
|
2
|
+
const { messages, viewport, selection } = state;
|
|
3
|
+
const next = Math.max(0, Math.min(messages.length - 1, at));
|
|
4
|
+
state.active = keys[next];
|
|
5
|
+
viewport.setActive(state.active);
|
|
6
|
+
viewport.scrollTo(next);
|
|
7
|
+
viewport.render();
|
|
8
|
+
viewport.row(state.active)?.focus({ preventScroll: true });
|
|
9
|
+
if (event.shiftKey) {
|
|
10
|
+
selection.select(state.active, { range: true, keys });
|
|
11
|
+
viewport.render();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Keyboard actions never intercept keys from the composer or bubble controls. */
|
|
16
|
+
export function streamKeydown(event, state) {
|
|
17
|
+
const { viewport, messages, selection, root, actions } = state;
|
|
18
|
+
const row = event.target.closest?.('[data-message]');
|
|
19
|
+
if (!row || event.target !== row) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const keys = messages.map((m) => m.id);
|
|
23
|
+
const index = keys.indexOf(row.dataset.message);
|
|
24
|
+
const direction = { ArrowDown: 1, ArrowUp: -1 }[event.key];
|
|
25
|
+
if (direction) {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
focusMessage(index + direction, event, state, keys);
|
|
28
|
+
} else if (event.key === 'Home' || event.key === 'End') {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
focusMessage(
|
|
31
|
+
event.key === 'Home' ? 0 : messages.length - 1,
|
|
32
|
+
event,
|
|
33
|
+
state,
|
|
34
|
+
keys
|
|
35
|
+
);
|
|
36
|
+
} else if (
|
|
37
|
+
event.key === 'Enter' ||
|
|
38
|
+
event.key === 'ContextMenu' ||
|
|
39
|
+
(event.key === 'F10' && event.shiftKey)
|
|
40
|
+
) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
actions.open(messages[index], row);
|
|
43
|
+
} else if (event.key === ' ') {
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
selection.select(row.dataset.message, {
|
|
46
|
+
toggle: event.ctrlKey || event.metaKey,
|
|
47
|
+
range: event.shiftKey,
|
|
48
|
+
keys,
|
|
49
|
+
});
|
|
50
|
+
viewport.render();
|
|
51
|
+
} else if (event.key === 'Escape') {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
selection.clear();
|
|
54
|
+
viewport.render();
|
|
55
|
+
}
|
|
56
|
+
root.setAttribute('aria-label', state.label);
|
|
57
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
function validatePage(page, id, pageSize) {
|
|
2
|
+
if (
|
|
3
|
+
!Array.isArray(page.messages) ||
|
|
4
|
+
page.messages.some((m) => typeof m.id !== 'string') ||
|
|
5
|
+
page.messages.length > pageSize ||
|
|
6
|
+
new Set(page.messages.map((m) => m.id)).size !== page.messages.length
|
|
7
|
+
) {
|
|
8
|
+
throw new TypeError('Invalid stream page');
|
|
9
|
+
}
|
|
10
|
+
if (id !== undefined && !page.messages.some((m) => m.id === id)) {
|
|
11
|
+
throw new Error(`Message not found: ${id}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function mergePage(current, page, direction, id, pageSize, ceiling) {
|
|
16
|
+
validatePage(page, id, pageSize);
|
|
17
|
+
const replace = direction === 'around' || !current.messages.length;
|
|
18
|
+
const incoming = new Set(page.messages.map((m) => m.id));
|
|
19
|
+
const kept = current.messages.filter((m) => !incoming.has(m.id));
|
|
20
|
+
let messages = replace
|
|
21
|
+
? page.messages
|
|
22
|
+
: direction === 'before'
|
|
23
|
+
? [...page.messages, ...kept]
|
|
24
|
+
: [...kept, ...page.messages];
|
|
25
|
+
let hasOlder =
|
|
26
|
+
replace || direction === 'before' ? page.hasOlder : current.hasOlder;
|
|
27
|
+
let hasNewer =
|
|
28
|
+
replace || direction === 'after' ? page.hasNewer : current.hasNewer;
|
|
29
|
+
if (messages.length > ceiling) {
|
|
30
|
+
if (direction === 'before') {
|
|
31
|
+
messages = messages.slice(0, ceiling);
|
|
32
|
+
hasNewer = true;
|
|
33
|
+
} else {
|
|
34
|
+
messages = messages.slice(-ceiling);
|
|
35
|
+
hasOlder = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
messages,
|
|
40
|
+
hasOlder,
|
|
41
|
+
hasNewer,
|
|
42
|
+
highlighted: id ?? current.highlighted,
|
|
43
|
+
loading: false,
|
|
44
|
+
error: null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Bidirectional contiguous history. The source owns ordering and cursors.
|
|
50
|
+
* @typedef {{messages: object[], hasOlder: boolean, hasNewer: boolean,
|
|
51
|
+
* highlighted: string|null, loading: boolean, error: Error|null}} StreamState
|
|
52
|
+
* @typedef {{before?: string, after?: string, around?: string, limit: number,
|
|
53
|
+
* signal: AbortSignal}} StreamQuery
|
|
54
|
+
* @typedef {{load(query: StreamQuery): Promise<{messages: object[], hasOlder: boolean, hasNewer: boolean}>}} StreamSource
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {StreamSource} source
|
|
59
|
+
* @param {{pageSize?: number, prefetch?: number, ceiling?: number}} [options]
|
|
60
|
+
* @returns {{loadOlder(): Promise<void>, loadNewer(): Promise<void>, jumpTo(id: string): Promise<void>, state(): StreamState, subscribe(fn: Function): Function, disconnect(): void, prefetch: number}}
|
|
61
|
+
*/
|
|
62
|
+
export function createStreamWindow(
|
|
63
|
+
source,
|
|
64
|
+
{ pageSize = 50, prefetch = 30, ceiling = 500 } = {}
|
|
65
|
+
) {
|
|
66
|
+
if (
|
|
67
|
+
![pageSize, prefetch, ceiling].every(
|
|
68
|
+
(n) => Number.isSafeInteger(n) && n > 0
|
|
69
|
+
) ||
|
|
70
|
+
ceiling < pageSize
|
|
71
|
+
) {
|
|
72
|
+
throw new RangeError(
|
|
73
|
+
'Positive integer limits required; ceiling must fit one page'
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
let current = {
|
|
77
|
+
messages: [],
|
|
78
|
+
hasOlder: true,
|
|
79
|
+
hasNewer: false,
|
|
80
|
+
highlighted: null,
|
|
81
|
+
loading: false,
|
|
82
|
+
error: null,
|
|
83
|
+
};
|
|
84
|
+
let generation = 0;
|
|
85
|
+
let pending;
|
|
86
|
+
let abort;
|
|
87
|
+
let disposed = false;
|
|
88
|
+
const listeners = new Set();
|
|
89
|
+
const state = () => ({ ...current, messages: [...current.messages] });
|
|
90
|
+
const notify = () => listeners.forEach((fn) => fn(state()));
|
|
91
|
+
|
|
92
|
+
async function load(direction, id) {
|
|
93
|
+
if (disposed) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (direction !== 'around' && pending) {
|
|
97
|
+
return pending;
|
|
98
|
+
}
|
|
99
|
+
if (
|
|
100
|
+
direction === 'before' &&
|
|
101
|
+
current.messages.length &&
|
|
102
|
+
!current.hasOlder
|
|
103
|
+
) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const token = ++generation;
|
|
107
|
+
abort?.abort();
|
|
108
|
+
abort = new AbortController();
|
|
109
|
+
current = { ...current, loading: true, error: null };
|
|
110
|
+
notify();
|
|
111
|
+
const query = { limit: pageSize, signal: abort.signal };
|
|
112
|
+
if (id !== undefined) {
|
|
113
|
+
query.around = id;
|
|
114
|
+
} else if (current.messages.length) {
|
|
115
|
+
query[direction] = (
|
|
116
|
+
direction === 'before' ? current.messages[0] : current.messages.at(-1)
|
|
117
|
+
).id;
|
|
118
|
+
}
|
|
119
|
+
const task = (async () => {
|
|
120
|
+
try {
|
|
121
|
+
const page = await Promise.resolve().then(() => source.load(query));
|
|
122
|
+
if (token !== generation || disposed) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
current = mergePage(current, page, direction, id, pageSize, ceiling);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (token !== generation || disposed) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
current = { ...current, loading: false, error };
|
|
131
|
+
throw error;
|
|
132
|
+
} finally {
|
|
133
|
+
if (token === generation && !disposed) {
|
|
134
|
+
pending = null;
|
|
135
|
+
notify();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
pending = task;
|
|
140
|
+
return await task;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
prefetch,
|
|
144
|
+
state,
|
|
145
|
+
loadOlder: () => load('before'),
|
|
146
|
+
loadNewer: () => load('after'),
|
|
147
|
+
jumpTo: (id) => load('around', id),
|
|
148
|
+
subscribe(fn) {
|
|
149
|
+
listeners.add(fn);
|
|
150
|
+
return () => listeners.delete(fn);
|
|
151
|
+
},
|
|
152
|
+
disconnect() {
|
|
153
|
+
disposed = true;
|
|
154
|
+
generation++;
|
|
155
|
+
abort?.abort();
|
|
156
|
+
listeners.clear();
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defaultVocabulary, loadVocabulary } from '@link-foundation/ui-core';
|
|
2
|
+
export const CHAT_KINDS = Object.freeze([
|
|
3
|
+
'chat-list',
|
|
4
|
+
'message-stream',
|
|
5
|
+
'message-bubble',
|
|
6
|
+
'day-separator',
|
|
7
|
+
'composer',
|
|
8
|
+
'reasoning-trace',
|
|
9
|
+
]);
|
|
10
|
+
export function chatVocabulary() {
|
|
11
|
+
const extra = loadVocabulary(
|
|
12
|
+
CHAT_KINDS.map(
|
|
13
|
+
(kind) =>
|
|
14
|
+
`${kind}: kind\n property label string\n property record string\n property chat string\n property source string\n property time string\n property disabled boolean\n children none`
|
|
15
|
+
).join('\n')
|
|
16
|
+
).kinds;
|
|
17
|
+
const base = defaultVocabulary();
|
|
18
|
+
return { ...base, kinds: new Map([...base.kinds, ...extra]) };
|
|
19
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `accordion`: one disclosure, as a heading with a native button
|
|
3
|
+
* (`aria-expanded`, `aria-controls`) over a labelled `region`. It runs the
|
|
4
|
+
* `disclosure-machine` of the behaviour layer and keeps that machine's
|
|
5
|
+
* events and attributes; focus is the one thing it decides itself, as the
|
|
6
|
+
* APG accordion pattern asks: opening leaves focus on the header, and
|
|
7
|
+
* closing brings focus back only from inside the section (Escape).
|
|
8
|
+
*
|
|
9
|
+
* Enter, Space and a click toggle it. ArrowDown, ArrowUp, Home and End move
|
|
10
|
+
* between the headers of the sibling accordions, which form a group.
|
|
11
|
+
* Every change commits `open` as a `ui-change` event. Only a change after
|
|
12
|
+
* mounting animates (`data-animated`): a section that mounts open has its
|
|
13
|
+
* text at full contrast from the first frame.
|
|
14
|
+
*
|
|
15
|
+
* (shipping: accordion Shipping (open true) (heading-level 2)
|
|
16
|
+
* (details: text 'Two to five days.'))
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { createMachine } from '../behavior/parse-machine.js';
|
|
20
|
+
import { DISCLOSURE_MACHINE } from '../behavior/machines/index.js';
|
|
21
|
+
import {
|
|
22
|
+
changesOf,
|
|
23
|
+
commitValue,
|
|
24
|
+
controlOf,
|
|
25
|
+
driveControl,
|
|
26
|
+
flagOf,
|
|
27
|
+
numberOf,
|
|
28
|
+
partId,
|
|
29
|
+
partOf,
|
|
30
|
+
setAttr,
|
|
31
|
+
startControl,
|
|
32
|
+
stopControl,
|
|
33
|
+
updateLabel,
|
|
34
|
+
} from './dom.js';
|
|
35
|
+
|
|
36
|
+
const machine = createMachine(DISCLOSURE_MACHINE);
|
|
37
|
+
|
|
38
|
+
/** The header button a key moves to, among the sibling accordions. */
|
|
39
|
+
function headerFor(key, trigger, host) {
|
|
40
|
+
const headers = [...(host.parentElement?.children ?? [])]
|
|
41
|
+
.filter((child) => child.localName === 'ui-accordion')
|
|
42
|
+
.map((child) => child.querySelector(':scope [data-part="trigger"]'))
|
|
43
|
+
.filter((header) => !header.disabled);
|
|
44
|
+
const at = headers.indexOf(trigger);
|
|
45
|
+
const count = headers.length;
|
|
46
|
+
const index = {
|
|
47
|
+
ArrowDown: (at + 1) % count,
|
|
48
|
+
ArrowUp: (at - 1 + count) % count,
|
|
49
|
+
Home: 0,
|
|
50
|
+
End: count - 1,
|
|
51
|
+
}[key];
|
|
52
|
+
return headers[index];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function onHeaderKey(event) {
|
|
56
|
+
const { altKey, ctrlKey, metaKey, shiftKey, currentTarget } = event;
|
|
57
|
+
if (event.defaultPrevented || altKey || ctrlKey || metaKey || shiftKey) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const next = headerFor(
|
|
61
|
+
event.key,
|
|
62
|
+
currentTarget,
|
|
63
|
+
currentTarget.closest('ui-accordion')
|
|
64
|
+
);
|
|
65
|
+
if (next) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
next.focus();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function render(control) {
|
|
72
|
+
if (control.mounted) {
|
|
73
|
+
setAttr(control.parts.content, 'data-animated', true);
|
|
74
|
+
}
|
|
75
|
+
if (!control.driven) {
|
|
76
|
+
commitValue(control, 'open', control.service.state === 'open');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const ACCORDION_KIND = Object.freeze({
|
|
81
|
+
tag: 'ui-accordion',
|
|
82
|
+
childrenSlot: (node) => node.children[1],
|
|
83
|
+
attributes: { disabled: 'boolean' },
|
|
84
|
+
eventTarget: (node) => node.firstChild.firstChild,
|
|
85
|
+
create(el, ctx) {
|
|
86
|
+
const doc = ctx.document;
|
|
87
|
+
const node = doc.createElement('ui-accordion');
|
|
88
|
+
const triggerId = partId(el.id, 'trigger');
|
|
89
|
+
const contentId = partId(el.id, 'content');
|
|
90
|
+
const heading = partOf(doc, 'div', 'heading', { role: 'heading' });
|
|
91
|
+
const trigger = partOf(doc, 'button', 'trigger', {
|
|
92
|
+
type: 'button',
|
|
93
|
+
id: triggerId,
|
|
94
|
+
'aria-controls': contentId,
|
|
95
|
+
});
|
|
96
|
+
const label = partOf(doc, 'span', 'label');
|
|
97
|
+
const indicator = partOf(doc, 'span', 'indicator', {
|
|
98
|
+
'aria-hidden': 'true',
|
|
99
|
+
});
|
|
100
|
+
const content = partOf(doc, 'div', 'content', {
|
|
101
|
+
id: contentId,
|
|
102
|
+
role: 'region',
|
|
103
|
+
'aria-labelledby': triggerId,
|
|
104
|
+
});
|
|
105
|
+
trigger.appendChild(label);
|
|
106
|
+
trigger.appendChild(indicator);
|
|
107
|
+
heading.appendChild(trigger);
|
|
108
|
+
node.appendChild(heading);
|
|
109
|
+
node.appendChild(content);
|
|
110
|
+
trigger.addEventListener('keydown', onHeaderKey);
|
|
111
|
+
const control = startControl(node, el, ctx, {
|
|
112
|
+
machine,
|
|
113
|
+
parts: { trigger, content },
|
|
114
|
+
target: trigger,
|
|
115
|
+
render,
|
|
116
|
+
});
|
|
117
|
+
control.label = label;
|
|
118
|
+
control.heading = heading;
|
|
119
|
+
control.value = false;
|
|
120
|
+
control.service.use({
|
|
121
|
+
focus(target) {
|
|
122
|
+
if (target === 'trigger' && content.contains(doc.activeElement)) {
|
|
123
|
+
trigger.focus();
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
return node;
|
|
129
|
+
},
|
|
130
|
+
update(node, el, changed, ctx) {
|
|
131
|
+
const has = changesOf(node, changed);
|
|
132
|
+
const control = controlOf(node);
|
|
133
|
+
const { trigger } = control.parts;
|
|
134
|
+
if (has('label')) {
|
|
135
|
+
updateLabel(control.label, el, ctx);
|
|
136
|
+
}
|
|
137
|
+
if (has('heading-level')) {
|
|
138
|
+
const level = Math.trunc(numberOf(el, 'heading-level', 3));
|
|
139
|
+
setAttr(
|
|
140
|
+
control.heading,
|
|
141
|
+
'aria-level',
|
|
142
|
+
String(Math.min(6, Math.max(1, level)))
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const disabled = flagOf(el, 'disabled');
|
|
146
|
+
if (has('disabled')) {
|
|
147
|
+
trigger.toggleAttribute('disabled', disabled);
|
|
148
|
+
control.assign({ disabled });
|
|
149
|
+
}
|
|
150
|
+
if (has('open')) {
|
|
151
|
+
const open = flagOf(el, 'open');
|
|
152
|
+
driveControl(control, open ? 'open' : 'close', open, disabled);
|
|
153
|
+
}
|
|
154
|
+
control.mounted = true;
|
|
155
|
+
},
|
|
156
|
+
destroy(node) {
|
|
157
|
+
controlOf(node)?.parts.trigger.removeEventListener('keydown', onHeaderKey);
|
|
158
|
+
stopControl(node);
|
|
159
|
+
},
|
|
160
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `avatar`: a person's picture, or their initials when there is no
|
|
3
|
+
* picture (or it fails to load). The picture is an `<img alt=NAME>`; the
|
|
4
|
+
* initials are `role=img` with the name as `aria-label`, so the name is
|
|
5
|
+
* read once either way. A `source` with an unsafe scheme is never loaded.
|
|
6
|
+
*
|
|
7
|
+
* (me: avatar 'Ada Lovelace' (source 'https://example.com/ada.png'))
|
|
8
|
+
* (you: avatar 'Grace Hopper')
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { isUnsafeUrl } from '@link-foundation/ui-dom';
|
|
12
|
+
import { atomOf, changesOf, isLive, partOf, setAttr, setText } from './dom.js';
|
|
13
|
+
|
|
14
|
+
/** The initials of a name: the first letters of its first and last words. */
|
|
15
|
+
export function initialsOf(name) {
|
|
16
|
+
const words = String(name ?? '')
|
|
17
|
+
.trim()
|
|
18
|
+
.split(/[\s\-_.]+/u)
|
|
19
|
+
.filter(Boolean);
|
|
20
|
+
if (words.length === 0) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
const first = [...words[0]][0];
|
|
24
|
+
const last = words.length > 1 ? [...words.at(-1)][0] : '';
|
|
25
|
+
return (first + last).toLocaleUpperCase();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Show the picture, or the initials when it is missing or broken. */
|
|
29
|
+
function show(node, picture) {
|
|
30
|
+
const [root] = node.children;
|
|
31
|
+
const [image, initials] = root.children;
|
|
32
|
+
const name = node.getAttribute('data-name') ?? '';
|
|
33
|
+
image.toggleAttribute('hidden', !picture);
|
|
34
|
+
initials.toggleAttribute('hidden', picture);
|
|
35
|
+
setAttr(root, 'role', picture ? undefined : 'img');
|
|
36
|
+
setAttr(root, 'aria-label', picture ? undefined : name);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const AVATAR_KIND = Object.freeze({
|
|
40
|
+
tag: 'ui-avatar',
|
|
41
|
+
childrenSlot: null,
|
|
42
|
+
attributes: { size: 'string' },
|
|
43
|
+
create(el, ctx) {
|
|
44
|
+
const doc = ctx.document;
|
|
45
|
+
const node = doc.createElement('ui-avatar');
|
|
46
|
+
const root = partOf(doc, 'span', 'root');
|
|
47
|
+
const image = partOf(doc, 'img', 'image', { alt: '', hidden: '' });
|
|
48
|
+
const initials = partOf(doc, 'span', 'label', { 'aria-hidden': 'true' });
|
|
49
|
+
root.appendChild(image);
|
|
50
|
+
root.appendChild(initials);
|
|
51
|
+
node.appendChild(root);
|
|
52
|
+
if (isLive(ctx)) {
|
|
53
|
+
image.addEventListener('error', () => show(node, false));
|
|
54
|
+
}
|
|
55
|
+
return node;
|
|
56
|
+
},
|
|
57
|
+
update(node, el, changed, ctx) {
|
|
58
|
+
const has = changesOf(node, changed);
|
|
59
|
+
const [image, initials] = node.firstChild.children;
|
|
60
|
+
const name = atomOf(el, 'name') ?? '';
|
|
61
|
+
if (has('name')) {
|
|
62
|
+
node.setAttribute('data-name', name);
|
|
63
|
+
setAttr(image, 'alt', name);
|
|
64
|
+
setText(initials, initialsOf(name));
|
|
65
|
+
if (name === '') {
|
|
66
|
+
ctx.diagnostic('missing-label', 'error', { property: 'name' });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (has('name') || has('source')) {
|
|
70
|
+
const src = atomOf(el, 'source');
|
|
71
|
+
const unsafe = src !== undefined && isUnsafeUrl(src);
|
|
72
|
+
if (unsafe) {
|
|
73
|
+
ctx.diagnostic('unsafe-url', 'error', { property: 'source' });
|
|
74
|
+
}
|
|
75
|
+
const picture = src !== undefined && !unsafe;
|
|
76
|
+
setAttr(image, 'src', picture ? src : undefined);
|
|
77
|
+
show(node, picture);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `badge`: a short status or count shown next to something. The value is
|
|
3
|
+
* visible; the label, when there is one, completes it for assistive
|
|
4
|
+
* technology only ("3" → "3 unread messages"). `tone` is `neutral`
|
|
5
|
+
* (default), `primary` or `error`.
|
|
6
|
+
*
|
|
7
|
+
* (unread: badge 3 (label 'unread messages') (tone primary))
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { atomOf, changesOf, partOf, setAttr, setText } from './dom.js';
|
|
11
|
+
|
|
12
|
+
export const BADGE_TONES = Object.freeze(['neutral', 'primary', 'error']);
|
|
13
|
+
|
|
14
|
+
export const BADGE_KIND = Object.freeze({
|
|
15
|
+
tag: 'ui-badge',
|
|
16
|
+
childrenSlot: null,
|
|
17
|
+
attributes: {},
|
|
18
|
+
create(el, ctx) {
|
|
19
|
+
const doc = ctx.document;
|
|
20
|
+
const node = doc.createElement('ui-badge');
|
|
21
|
+
const root = partOf(doc, 'span', 'root');
|
|
22
|
+
root.appendChild(partOf(doc, 'span', 'indicator'));
|
|
23
|
+
root.appendChild(partOf(doc, 'span', 'label'));
|
|
24
|
+
node.appendChild(root);
|
|
25
|
+
return node;
|
|
26
|
+
},
|
|
27
|
+
update(node, el, changed, ctx) {
|
|
28
|
+
const has = changesOf(node, changed);
|
|
29
|
+
const [value, label] = node.firstChild.children;
|
|
30
|
+
if (has('value') || has('label')) {
|
|
31
|
+
const text = atomOf(el, 'value');
|
|
32
|
+
const name = atomOf(el, 'label');
|
|
33
|
+
setText(value, text ?? name);
|
|
34
|
+
setText(
|
|
35
|
+
label,
|
|
36
|
+
text === undefined || name === undefined ? '' : ` ${name}`
|
|
37
|
+
);
|
|
38
|
+
label.toggleAttribute('hidden', text === undefined || name === undefined);
|
|
39
|
+
if (text === undefined && name === undefined) {
|
|
40
|
+
ctx.diagnostic('missing-label', 'warning', { property: 'value' });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (has('tone')) {
|
|
44
|
+
const tone = atomOf(el, 'tone');
|
|
45
|
+
setAttr(node, 'tone', BADGE_TONES.includes(tone) ? tone : 'neutral');
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Template data replaces the visual part tree; the native button keeps its semantics. */
|
|
2
|
+
import { resolveTemplate } from '@link-foundation/ui-tokens/themes';
|
|
3
|
+
import { partOf } from './dom.js';
|
|
4
|
+
|
|
5
|
+
export function buttonParts(button, ctx, kind) {
|
|
6
|
+
const template = resolveTemplate(ctx.theme?.(), kind);
|
|
7
|
+
if (!template) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const doc = ctx.document;
|
|
11
|
+
const append = (part, parent) => {
|
|
12
|
+
const tag =
|
|
13
|
+
part.name === 'icon' ? 'ui-icon' : part.kind === 'box' ? 'div' : 'span';
|
|
14
|
+
const node = partOf(doc, tag, part.name);
|
|
15
|
+
if (part.name === 'icon' || part.name === 'indicator') {
|
|
16
|
+
node.setAttribute('aria-hidden', 'true');
|
|
17
|
+
}
|
|
18
|
+
for (const child of part.children) {
|
|
19
|
+
append(child, node);
|
|
20
|
+
}
|
|
21
|
+
parent.appendChild(node);
|
|
22
|
+
};
|
|
23
|
+
for (const child of template.children) {
|
|
24
|
+
append(child, button);
|
|
25
|
+
}
|
|
26
|
+
if (!button.querySelector('[data-part="icon"]')) {
|
|
27
|
+
button.appendChild(
|
|
28
|
+
partOf(doc, 'ui-icon', 'icon', { hidden: '', 'aria-hidden': 'true' })
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|