@link-foundation/ui-components 0.0.0-stage → 0.0.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,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Announcements for screen readers through one shared live region per
|
|
3
|
+
* document: a visually hidden container with a polite region
|
|
4
|
+
* (`role="status"`) and an assertive one (`role="alert"`). Each message is
|
|
5
|
+
* a new node, so the same text said twice is announced twice.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const REGION_ID = 'ui-live-region';
|
|
9
|
+
|
|
10
|
+
/** Visually hidden but read by screen readers. */
|
|
11
|
+
const VISUALLY_HIDDEN = [
|
|
12
|
+
'position: absolute',
|
|
13
|
+
'width: 1px',
|
|
14
|
+
'height: 1px',
|
|
15
|
+
'margin: -1px',
|
|
16
|
+
'padding: 0',
|
|
17
|
+
'border: 0',
|
|
18
|
+
'overflow: hidden',
|
|
19
|
+
'clip: rect(0 0 0 0)',
|
|
20
|
+
'clip-path: inset(50%)',
|
|
21
|
+
'white-space: nowrap',
|
|
22
|
+
].join('; ');
|
|
23
|
+
|
|
24
|
+
const POLITENESS = {
|
|
25
|
+
polite: 'status',
|
|
26
|
+
assertive: 'alert',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The shared live region of a document, created on first use.
|
|
31
|
+
* @param {Document} document
|
|
32
|
+
* @returns {HTMLElement}
|
|
33
|
+
*/
|
|
34
|
+
export function liveRegion(document) {
|
|
35
|
+
const found = document.getElementById(REGION_ID);
|
|
36
|
+
if (found) {
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
39
|
+
const container = document.createElement('div');
|
|
40
|
+
container.id = REGION_ID;
|
|
41
|
+
container.setAttribute('style', VISUALLY_HIDDEN);
|
|
42
|
+
for (const [politeness, role] of Object.entries(POLITENESS)) {
|
|
43
|
+
const region = document.createElement('div');
|
|
44
|
+
region.setAttribute('role', role);
|
|
45
|
+
region.setAttribute('aria-live', politeness);
|
|
46
|
+
region.setAttribute('aria-atomic', 'true');
|
|
47
|
+
region.dataset.politeness = politeness;
|
|
48
|
+
container.appendChild(region);
|
|
49
|
+
}
|
|
50
|
+
document.body.appendChild(container);
|
|
51
|
+
return container;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Announce a message.
|
|
56
|
+
* @param {string} message
|
|
57
|
+
* @param {{politeness?: 'polite'|'assertive', document?: Document}} [options]
|
|
58
|
+
* `politeness` (default `polite`); `document` (default the global one)
|
|
59
|
+
* @returns {HTMLElement} the node that holds the message
|
|
60
|
+
*/
|
|
61
|
+
export function announce(message, options = {}) {
|
|
62
|
+
const { politeness = 'polite' } = options;
|
|
63
|
+
if (!Object.hasOwn(POLITENESS, politeness)) {
|
|
64
|
+
throw new TypeError(
|
|
65
|
+
`announce: politeness must be "polite" or "assertive", not ${JSON.stringify(politeness)}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const document = options.document ?? globalThis.document;
|
|
69
|
+
const region = liveRegion(document).querySelector(
|
|
70
|
+
`[data-politeness="${politeness}"]`
|
|
71
|
+
);
|
|
72
|
+
const node = document.createElement('div');
|
|
73
|
+
node.textContent = String(message);
|
|
74
|
+
region.replaceChildren(node);
|
|
75
|
+
return node;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Remove the messages of the live region (the region itself stays, as
|
|
80
|
+
* screen readers track it).
|
|
81
|
+
* @param {Document} [document]
|
|
82
|
+
*/
|
|
83
|
+
export function clearAnnouncements(document = globalThis.document) {
|
|
84
|
+
const container = document.getElementById(REGION_ID);
|
|
85
|
+
for (const region of container?.children ?? []) {
|
|
86
|
+
region.replaceChildren();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `bindMachine(root, service, parts)`: connect a running machine to DOM
|
|
3
|
+
* elements. Every part of the machine gets its `(attr ...)` values (kept
|
|
4
|
+
* in sync with the state and context), its `(key KEY EVENT)` bindings and
|
|
5
|
+
* its `(on EVENT SEND)` UI events, and the `focus` action of the machine
|
|
6
|
+
* focuses a part element.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { diagnostic } from '../behavior/diagnostics.js';
|
|
10
|
+
import { firesInField, isTextField, keyOf, normalizeKey } from './keys.js';
|
|
11
|
+
|
|
12
|
+
/** UI events of a part → DOM events (as in ui-dom). */
|
|
13
|
+
const DOM_EVENTS = {
|
|
14
|
+
press: 'click',
|
|
15
|
+
focus: 'focusin',
|
|
16
|
+
blur: 'focusout',
|
|
17
|
+
hover: 'pointerenter',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The part elements: the `parts` given, else `[data-part="NAME"]` in the
|
|
22
|
+
* root; the part `root` defaults to the root itself.
|
|
23
|
+
*/
|
|
24
|
+
function resolveParts(root, service, parts) {
|
|
25
|
+
const resolved = {};
|
|
26
|
+
for (const name of Object.keys(service.machine.parts)) {
|
|
27
|
+
const given = typeof parts === 'function' ? parts(name) : parts?.[name];
|
|
28
|
+
resolved[name] =
|
|
29
|
+
given ??
|
|
30
|
+
(name === 'root'
|
|
31
|
+
? root
|
|
32
|
+
: root.querySelector(`[data-part="${CSS_ESCAPE(name)}"]`));
|
|
33
|
+
}
|
|
34
|
+
return resolved;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Escape a part name for an attribute selector (names are LiNo atoms). */
|
|
38
|
+
const CSS_ESCAPE = (name) => String(name).replace(/["\\]/g, '\\$&');
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Set attributes to the current values, and remove the ones that are gone.
|
|
42
|
+
* @param {HTMLElement} element
|
|
43
|
+
* @param {Record<string, string>} attrs
|
|
44
|
+
* @param {Set<string>} owned the attributes set before
|
|
45
|
+
*/
|
|
46
|
+
function applyAttrs(element, attrs, owned) {
|
|
47
|
+
for (const name of owned) {
|
|
48
|
+
if (!Object.hasOwn(attrs, name)) {
|
|
49
|
+
element.removeAttribute(name);
|
|
50
|
+
owned.delete(name);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
54
|
+
if (name.toLowerCase().startsWith('on')) {
|
|
55
|
+
continue; // an on* attribute would run its value as code
|
|
56
|
+
}
|
|
57
|
+
if (element.getAttribute(name) !== value) {
|
|
58
|
+
element.setAttribute(name, value);
|
|
59
|
+
}
|
|
60
|
+
owned.add(name);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {HTMLElement} root the element of the component
|
|
66
|
+
* @param {import('../behavior/interpret.js').Service} service
|
|
67
|
+
* @param {Record<string, HTMLElement|null|undefined> |
|
|
68
|
+
* ((part: string) => HTMLElement|null|undefined)} [parts] the part
|
|
69
|
+
* elements by name (default: `[data-part]` in the root)
|
|
70
|
+
* @param {{onDiagnostic?: (d: object) => void, ignoreInFields?: boolean}}
|
|
71
|
+
* [options]
|
|
72
|
+
* @returns {() => void} unbind: removes the listeners and the effects
|
|
73
|
+
* (the attributes stay as they are)
|
|
74
|
+
*/
|
|
75
|
+
export function bindMachine(root, service, parts, options = {}) {
|
|
76
|
+
const { ignoreInFields = true } = options;
|
|
77
|
+
const elements = resolveParts(root, service, parts);
|
|
78
|
+
const cleanups = [];
|
|
79
|
+
const owned = new Map();
|
|
80
|
+
|
|
81
|
+
for (const [name, spec] of Object.entries(service.machine.parts)) {
|
|
82
|
+
const element = elements[name];
|
|
83
|
+
if (!element) {
|
|
84
|
+
options.onDiagnostic?.(
|
|
85
|
+
diagnostic('unknown-part', 'warning', {
|
|
86
|
+
machine: service.machine.id,
|
|
87
|
+
part: name,
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
owned.set(name, new Set());
|
|
93
|
+
if (!element.hasAttribute('data-part')) {
|
|
94
|
+
element.setAttribute('data-part', name);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const keys = new Map(
|
|
98
|
+
spec.keys.map(({ key, event }) => [normalizeKey(key), event])
|
|
99
|
+
);
|
|
100
|
+
if (keys.size > 0) {
|
|
101
|
+
const onKey = (event) => {
|
|
102
|
+
const combo = keyOf(event);
|
|
103
|
+
if (!keys.has(combo) || event.defaultPrevented || event.isComposing) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (
|
|
107
|
+
ignoreInFields &&
|
|
108
|
+
isTextField(event.target) &&
|
|
109
|
+
!firesInField(combo)
|
|
110
|
+
) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// The machine handles the key: a native button must not also
|
|
114
|
+
// turn it into a click (Enter on keydown, Space on keyup).
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
if (event.type === 'keydown') {
|
|
117
|
+
service.send({ type: keys.get(combo), key: combo, part: name });
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
element.addEventListener('keydown', onKey);
|
|
121
|
+
element.addEventListener('keyup', onKey);
|
|
122
|
+
cleanups.push(() => {
|
|
123
|
+
element.removeEventListener('keydown', onKey);
|
|
124
|
+
element.removeEventListener('keyup', onKey);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for (const { event, send } of spec.events) {
|
|
129
|
+
const type = DOM_EVENTS[event] ?? event;
|
|
130
|
+
const listener = () => service.send({ type: send, part: name });
|
|
131
|
+
element.addEventListener(type, listener);
|
|
132
|
+
cleanups.push(() => element.removeEventListener(type, listener));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const sync = () => {
|
|
137
|
+
for (const [name, attrs] of owned) {
|
|
138
|
+
applyAttrs(elements[name], service.attrs(name), attrs);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
sync();
|
|
142
|
+
cleanups.push(service.subscribe(sync));
|
|
143
|
+
|
|
144
|
+
cleanups.push(
|
|
145
|
+
service.use({
|
|
146
|
+
focus(target) {
|
|
147
|
+
const element = elements[target] ?? null;
|
|
148
|
+
if (!element) {
|
|
149
|
+
options.onDiagnostic?.(
|
|
150
|
+
diagnostic('unknown-part', 'warning', {
|
|
151
|
+
machine: service.machine.id,
|
|
152
|
+
part: target,
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
// Make the part focusable by script without adding it to the Tab
|
|
158
|
+
// order (content regions, dialogs).
|
|
159
|
+
if (element.tabIndex < 0 && !element.hasAttribute('tabindex')) {
|
|
160
|
+
element.setAttribute('tabindex', '-1');
|
|
161
|
+
}
|
|
162
|
+
// Apply the attributes first: a part hidden a moment ago cannot
|
|
163
|
+
// take focus.
|
|
164
|
+
sync();
|
|
165
|
+
element.focus();
|
|
166
|
+
return true;
|
|
167
|
+
},
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
let bound = true;
|
|
172
|
+
return () => {
|
|
173
|
+
if (!bound) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
bound = false;
|
|
177
|
+
for (const cleanup of cleanups.reverse()) {
|
|
178
|
+
cleanup();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus management: a focus trap for modal content and focus restoration.
|
|
3
|
+
* The trap moves focus itself on Tab and Shift+Tab, so it cycles in the
|
|
4
|
+
* same order in every browser (and in jsdom).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Elements that can take focus with the keyboard, before filtering. */
|
|
8
|
+
export const FOCUSABLE = [
|
|
9
|
+
'a[href]',
|
|
10
|
+
'area[href]',
|
|
11
|
+
'button',
|
|
12
|
+
'input',
|
|
13
|
+
'select',
|
|
14
|
+
'textarea',
|
|
15
|
+
'iframe',
|
|
16
|
+
'audio[controls]',
|
|
17
|
+
'video[controls]',
|
|
18
|
+
'summary',
|
|
19
|
+
'[contenteditable]',
|
|
20
|
+
'[tabindex]',
|
|
21
|
+
].join(',');
|
|
22
|
+
|
|
23
|
+
/** Whether an element or an ancestor is hidden, inert or disabled. */
|
|
24
|
+
function isUnavailable(element) {
|
|
25
|
+
if (element.disabled === true || element.getAttribute('tabindex') === '-1') {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (element.localName === 'input' && element.type === 'hidden') {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
for (
|
|
32
|
+
let node = element;
|
|
33
|
+
node && node.nodeType === 1;
|
|
34
|
+
node = node.parentElement
|
|
35
|
+
) {
|
|
36
|
+
if (node.hidden || node.inert || node.hasAttribute('inert')) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (node.getAttribute('aria-hidden') === 'true') {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The elements of a container that Tab reaches, in Tab order: positive
|
|
48
|
+
* `tabindex` first (ascending), then document order.
|
|
49
|
+
* @param {Element} container
|
|
50
|
+
* @returns {HTMLElement[]}
|
|
51
|
+
*/
|
|
52
|
+
export function tabbables(container) {
|
|
53
|
+
const found = [...container.querySelectorAll(FOCUSABLE)].filter(
|
|
54
|
+
(element) =>
|
|
55
|
+
!isUnavailable(element) &&
|
|
56
|
+
element.getAttribute('contenteditable') !== 'false'
|
|
57
|
+
);
|
|
58
|
+
const order = (element) => Math.max(0, element.tabIndex || 0);
|
|
59
|
+
return found
|
|
60
|
+
.map((element, index) => ({ element, index }))
|
|
61
|
+
.sort((a, b) => {
|
|
62
|
+
const [x, y] = [order(a.element), order(b.element)];
|
|
63
|
+
if (x === y) {
|
|
64
|
+
return a.index - b.index;
|
|
65
|
+
}
|
|
66
|
+
if (x === 0 || y === 0) {
|
|
67
|
+
return x === 0 ? 1 : -1;
|
|
68
|
+
}
|
|
69
|
+
return x - y;
|
|
70
|
+
})
|
|
71
|
+
.map(({ element }) => element);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Focus an element if it is still in the document; returns whether it was
|
|
76
|
+
* focused.
|
|
77
|
+
* @param {Element|null|undefined} previous
|
|
78
|
+
*/
|
|
79
|
+
export function restoreFocus(previous) {
|
|
80
|
+
if (
|
|
81
|
+
!previous ||
|
|
82
|
+
!previous.isConnected ||
|
|
83
|
+
typeof previous.focus !== 'function'
|
|
84
|
+
) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
previous.focus();
|
|
88
|
+
return previous.ownerDocument.activeElement === previous;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Keep keyboard focus inside a container: Tab after the last tabbable
|
|
93
|
+
* element goes to the first one, Shift+Tab before the first goes to the
|
|
94
|
+
* last, and focus that leaves the container (a click outside, a script)
|
|
95
|
+
* comes back. Focus moves into the container at once.
|
|
96
|
+
* @param {HTMLElement} container
|
|
97
|
+
* @param {{initialFocus?: HTMLElement|null, restore?: boolean}} [options]
|
|
98
|
+
* `initialFocus` (default: the first tabbable element, else the
|
|
99
|
+
* container); `restore` (default `true`): `release` focuses the element
|
|
100
|
+
* that had focus before the trap
|
|
101
|
+
* @returns {() => void} release
|
|
102
|
+
*/
|
|
103
|
+
export function trapFocus(container, options = {}) {
|
|
104
|
+
const document = container.ownerDocument;
|
|
105
|
+
const previous = document.activeElement;
|
|
106
|
+
const { restore = true } = options;
|
|
107
|
+
|
|
108
|
+
const focusEdge = (last) => {
|
|
109
|
+
const items = tabbables(container);
|
|
110
|
+
const target = last ? items.at(-1) : items[0];
|
|
111
|
+
if (target) {
|
|
112
|
+
target.focus();
|
|
113
|
+
} else {
|
|
114
|
+
if (!container.hasAttribute('tabindex')) {
|
|
115
|
+
container.setAttribute('tabindex', '-1');
|
|
116
|
+
}
|
|
117
|
+
container.focus();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const onKeyDown = (event) => {
|
|
122
|
+
if (event.key !== 'Tab' || event.ctrlKey || event.altKey || event.metaKey) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const items = tabbables(container);
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
if (items.length === 0) {
|
|
128
|
+
focusEdge(false);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const index = items.indexOf(document.activeElement);
|
|
132
|
+
const step = event.shiftKey ? -1 : 1;
|
|
133
|
+
const next =
|
|
134
|
+
index === -1
|
|
135
|
+
? event.shiftKey
|
|
136
|
+
? items.length - 1
|
|
137
|
+
: 0
|
|
138
|
+
: (index + step + items.length) % items.length;
|
|
139
|
+
items[next].focus();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const onFocusIn = (event) => {
|
|
143
|
+
if (!container.contains(event.target)) {
|
|
144
|
+
focusEdge(false);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
container.addEventListener('keydown', onKeyDown);
|
|
149
|
+
document.addEventListener('focusin', onFocusIn);
|
|
150
|
+
const initial = options.initialFocus;
|
|
151
|
+
if (initial && container.contains(initial)) {
|
|
152
|
+
initial.focus();
|
|
153
|
+
} else if (!container.contains(document.activeElement)) {
|
|
154
|
+
focusEdge(false);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let released = false;
|
|
158
|
+
return () => {
|
|
159
|
+
if (released) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
released = true;
|
|
163
|
+
container.removeEventListener('keydown', onKeyDown);
|
|
164
|
+
document.removeEventListener('focusin', onFocusIn);
|
|
165
|
+
if (restore) {
|
|
166
|
+
restoreFocus(previous);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Diagnostic,
|
|
3
|
+
Service,
|
|
4
|
+
} from '@link-foundation/ui-components/behavior';
|
|
5
|
+
|
|
6
|
+
export const FOCUSABLE: string;
|
|
7
|
+
export function tabbables(container: Element): HTMLElement[];
|
|
8
|
+
export function restoreFocus(previous: Element | null | undefined): boolean;
|
|
9
|
+
export function trapFocus(
|
|
10
|
+
container: HTMLElement,
|
|
11
|
+
options?: { initialFocus?: HTMLElement | null; restore?: boolean }
|
|
12
|
+
): () => void;
|
|
13
|
+
|
|
14
|
+
export interface RovingTabindex {
|
|
15
|
+
readonly index: number;
|
|
16
|
+
readonly item: HTMLElement | null;
|
|
17
|
+
focus(index: number): boolean;
|
|
18
|
+
/** Make an item the tab stop without focusing it. */
|
|
19
|
+
select(index: number): boolean;
|
|
20
|
+
update(): void;
|
|
21
|
+
handleKeyDown(event: KeyboardEvent): boolean;
|
|
22
|
+
attach(container: HTMLElement): () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createRovingTabindex(
|
|
26
|
+
items: HTMLElement[] | (() => HTMLElement[]),
|
|
27
|
+
options?: {
|
|
28
|
+
orientation?: 'horizontal' | 'vertical' | 'both';
|
|
29
|
+
loop?: boolean;
|
|
30
|
+
initial?: number;
|
|
31
|
+
rtl?: boolean;
|
|
32
|
+
onChange?: (index: number, item: HTMLElement) => void;
|
|
33
|
+
}
|
|
34
|
+
): RovingTabindex;
|
|
35
|
+
|
|
36
|
+
export interface Typeahead {
|
|
37
|
+
readonly query: string;
|
|
38
|
+
handleKey(key: string, current?: number): number;
|
|
39
|
+
reset(): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createTypeahead(
|
|
43
|
+
getLabels: () => readonly string[],
|
|
44
|
+
options?: {
|
|
45
|
+
timeout?: number;
|
|
46
|
+
clock?: {
|
|
47
|
+
setTimeout(fn: () => void, ms: number): unknown;
|
|
48
|
+
clearTimeout(handle: unknown): void;
|
|
49
|
+
};
|
|
50
|
+
locale?: string;
|
|
51
|
+
}
|
|
52
|
+
): Typeahead;
|
|
53
|
+
|
|
54
|
+
export interface KeyLike {
|
|
55
|
+
key: string;
|
|
56
|
+
ctrlKey?: boolean;
|
|
57
|
+
altKey?: boolean;
|
|
58
|
+
shiftKey?: boolean;
|
|
59
|
+
metaKey?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function keyOf(event: KeyLike): string;
|
|
63
|
+
export function normalizeKey(combo: string): string;
|
|
64
|
+
export function isTextField(element: EventTarget | null | undefined): boolean;
|
|
65
|
+
export function firesInField(combo: string): boolean;
|
|
66
|
+
export function bindKeys(
|
|
67
|
+
element: EventTarget,
|
|
68
|
+
map: Record<string, (event: KeyboardEvent) => unknown>,
|
|
69
|
+
options?: { ignoreInFields?: boolean; type?: 'keydown' | 'keyup' }
|
|
70
|
+
): () => void;
|
|
71
|
+
|
|
72
|
+
export function liveRegion(document: Document): HTMLElement;
|
|
73
|
+
export function announce(
|
|
74
|
+
message: string,
|
|
75
|
+
options?: { politeness?: 'polite' | 'assertive'; document?: Document }
|
|
76
|
+
): HTMLElement;
|
|
77
|
+
export function clearAnnouncements(document?: Document): void;
|
|
78
|
+
|
|
79
|
+
export function bindMachine(
|
|
80
|
+
root: HTMLElement,
|
|
81
|
+
service: Service,
|
|
82
|
+
parts?:
|
|
83
|
+
| Record<string, HTMLElement | null | undefined>
|
|
84
|
+
| ((part: string) => HTMLElement | null | undefined),
|
|
85
|
+
options?: {
|
|
86
|
+
onDiagnostic?: (diagnostic: Diagnostic) => void;
|
|
87
|
+
ignoreInFields?: boolean;
|
|
88
|
+
}
|
|
89
|
+
): () => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@link-foundation/ui-components/a11y`: DOM accessibility helpers —
|
|
3
|
+
* focus trap and restoration, roving tabindex, typeahead, key bindings,
|
|
4
|
+
* a shared live region, and `bindMachine` to connect a behaviour machine
|
|
5
|
+
* to elements.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { trapFocus, restoreFocus, tabbables, FOCUSABLE } from './focus.js';
|
|
9
|
+
export { createRovingTabindex } from './roving.js';
|
|
10
|
+
export { createTypeahead } from './typeahead.js';
|
|
11
|
+
export {
|
|
12
|
+
bindKeys,
|
|
13
|
+
keyOf,
|
|
14
|
+
normalizeKey,
|
|
15
|
+
isTextField,
|
|
16
|
+
firesInField,
|
|
17
|
+
} from './keys.js';
|
|
18
|
+
export { announce, clearAnnouncements, liveRegion } from './announce.js';
|
|
19
|
+
export { bindMachine } from './bind-machine.js';
|