@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,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `progress`: a `progressbar` from 0 to `max` (default 100). Without a
|
|
3
|
+
* `value` it is indeterminate: `aria-valuenow` is left out (the APG
|
|
4
|
+
* reading of "busy, amount unknown") and the indicator animates.
|
|
5
|
+
*
|
|
6
|
+
* (upload: progress 'Uploading' (value 40))
|
|
7
|
+
* (busy: progress 'Loading')
|
|
8
|
+
*
|
|
9
|
+
* `(shape circular)` draws the same progressbar as a ring; the ARIA is the
|
|
10
|
+
* same in both shapes.
|
|
11
|
+
*
|
|
12
|
+
* (sync: progress 'Syncing' (shape circular) (value 40))
|
|
13
|
+
* (spinner: progress 'Loading' (shape circular))
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
atomOf,
|
|
18
|
+
changesOf,
|
|
19
|
+
numberOf,
|
|
20
|
+
partId,
|
|
21
|
+
partOf,
|
|
22
|
+
setAttr,
|
|
23
|
+
updateLabel,
|
|
24
|
+
} from './dom.js';
|
|
25
|
+
|
|
26
|
+
export const PROGRESS_SHAPES = Object.freeze(['linear', 'circular']);
|
|
27
|
+
|
|
28
|
+
export const PROGRESS_KIND = Object.freeze({
|
|
29
|
+
tag: 'ui-progress',
|
|
30
|
+
childrenSlot: null,
|
|
31
|
+
attributes: {},
|
|
32
|
+
create(el, ctx) {
|
|
33
|
+
const doc = ctx.document;
|
|
34
|
+
const node = doc.createElement('ui-progress');
|
|
35
|
+
const labelId = partId(el.id, 'label');
|
|
36
|
+
const label = partOf(doc, 'span', 'label', { id: labelId });
|
|
37
|
+
const track = partOf(doc, 'div', 'track', {
|
|
38
|
+
role: 'progressbar',
|
|
39
|
+
id: partId(el.id),
|
|
40
|
+
'aria-labelledby': labelId,
|
|
41
|
+
'aria-valuemin': '0',
|
|
42
|
+
});
|
|
43
|
+
track.appendChild(partOf(doc, 'div', 'indicator'));
|
|
44
|
+
node.appendChild(label);
|
|
45
|
+
node.appendChild(track);
|
|
46
|
+
return node;
|
|
47
|
+
},
|
|
48
|
+
update(node, el, changed, ctx) {
|
|
49
|
+
const has = changesOf(node, changed);
|
|
50
|
+
const [label, track] = node.children;
|
|
51
|
+
if (has('label')) {
|
|
52
|
+
updateLabel(label, el, ctx);
|
|
53
|
+
}
|
|
54
|
+
if (has('shape')) {
|
|
55
|
+
const shape = atomOf(el, 'shape');
|
|
56
|
+
setAttr(
|
|
57
|
+
node,
|
|
58
|
+
'shape',
|
|
59
|
+
PROGRESS_SHAPES.includes(shape) ? shape : 'linear'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (has('value') || has('max')) {
|
|
63
|
+
const max = Math.max(Number.MIN_VALUE, numberOf(el, 'max', 100));
|
|
64
|
+
const raw = numberOf(el, 'value', Number.NaN);
|
|
65
|
+
const known = Number.isFinite(raw);
|
|
66
|
+
const value = known ? Math.min(max, Math.max(0, raw)) : null;
|
|
67
|
+
setAttr(track, 'aria-valuemax', String(max));
|
|
68
|
+
setAttr(track, 'aria-valuenow', known ? String(value) : undefined);
|
|
69
|
+
node.toggleAttribute('data-indeterminate', !known);
|
|
70
|
+
node.style.setProperty(
|
|
71
|
+
'--ui-progress-value',
|
|
72
|
+
known ? String(value / max) : '0'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `radio-group` and its `radio` children: one choice among several, a
|
|
3
|
+
* single tab stop (`createRovingTabindex`). Tab reaches the checked radio
|
|
4
|
+
* (or the first), the arrow keys move focus and check the radio they
|
|
5
|
+
* reach (APG), Space checks the focused one. The group's `value` is the
|
|
6
|
+
* `value` (else the ID) of its checked radio; a form submits it under the
|
|
7
|
+
* group's `name`.
|
|
8
|
+
*
|
|
9
|
+
* (size: radio-group 'Size' (name size) (value m)
|
|
10
|
+
* (s: radio 'Small') (m: radio 'Medium') (l: radio 'Large'))
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createRovingTabindex } from '../a11y/roving.js';
|
|
14
|
+
import { watchChildren } from '../layout/dom.js';
|
|
15
|
+
import {
|
|
16
|
+
choiceLabel,
|
|
17
|
+
choiceValue,
|
|
18
|
+
recordChosen,
|
|
19
|
+
wasChosen,
|
|
20
|
+
} from './choices.js';
|
|
21
|
+
import {
|
|
22
|
+
atomOf,
|
|
23
|
+
changesOf,
|
|
24
|
+
commitValue,
|
|
25
|
+
controlOf,
|
|
26
|
+
flagOf,
|
|
27
|
+
isLive,
|
|
28
|
+
partId,
|
|
29
|
+
partOf,
|
|
30
|
+
receive,
|
|
31
|
+
setAttr,
|
|
32
|
+
setText,
|
|
33
|
+
startControl,
|
|
34
|
+
stopControl,
|
|
35
|
+
updateLabel,
|
|
36
|
+
} from './dom.js';
|
|
37
|
+
|
|
38
|
+
const RADIO = ':scope > ui-radio > [role="radio"]';
|
|
39
|
+
|
|
40
|
+
/** The radio buttons of a group root. */
|
|
41
|
+
const radiosOf = (root) => [...root.querySelectorAll(RADIO)];
|
|
42
|
+
|
|
43
|
+
/** The value of a radio button (set by the `radio` kind). */
|
|
44
|
+
const valueOf = (radio) => radio.parentNode.getAttribute('data-value');
|
|
45
|
+
|
|
46
|
+
/** Sync the form input and the radios, then commit a user change. */
|
|
47
|
+
function render(control) {
|
|
48
|
+
const { value, disabled } = control.service.context;
|
|
49
|
+
setAttr(control.hidden, 'value', value ?? '');
|
|
50
|
+
control.hidden.toggleAttribute(
|
|
51
|
+
'disabled',
|
|
52
|
+
value === null || value === undefined
|
|
53
|
+
);
|
|
54
|
+
if (control.roving) {
|
|
55
|
+
renderRadios(control, value, disabled);
|
|
56
|
+
}
|
|
57
|
+
commitValue(control);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Check the radio of the value and keep it the tab stop (live). */
|
|
61
|
+
function renderRadios(control, value, disabled) {
|
|
62
|
+
const { root } = control.parts;
|
|
63
|
+
let checked = -1;
|
|
64
|
+
radiosOf(root).forEach((radio, i) => {
|
|
65
|
+
const on =
|
|
66
|
+
value !== null && value !== undefined && valueOf(radio) === value;
|
|
67
|
+
if (on) {
|
|
68
|
+
checked = i;
|
|
69
|
+
}
|
|
70
|
+
setAttr(radio, 'aria-checked', String(on));
|
|
71
|
+
radio.toggleAttribute(
|
|
72
|
+
'disabled',
|
|
73
|
+
disabled === true || radio.parentNode.hasAttribute('disabled')
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
const focused = root.contains(root.ownerDocument.activeElement);
|
|
77
|
+
if (checked !== -1 && !focused) {
|
|
78
|
+
control.roving.select(checked);
|
|
79
|
+
}
|
|
80
|
+
control.roving.update();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Make the group interactive: roving focus, click and Space selection. */
|
|
84
|
+
function connect(control, root) {
|
|
85
|
+
let pending = null;
|
|
86
|
+
const send = (radio) => {
|
|
87
|
+
pending = radio;
|
|
88
|
+
control.service.send('select');
|
|
89
|
+
pending = null;
|
|
90
|
+
};
|
|
91
|
+
control.choose = (args, meta) => {
|
|
92
|
+
const radio =
|
|
93
|
+
pending ?? root.ownerDocument.activeElement?.closest?.('[role="radio"]');
|
|
94
|
+
if (radio && radiosOf(root).includes(radio) && !radio.disabled) {
|
|
95
|
+
meta.assign({ value: valueOf(radio) });
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
control.roving = createRovingTabindex(() => radiosOf(root), {
|
|
99
|
+
orientation: 'both',
|
|
100
|
+
onChange: (index, radio) => send(radio),
|
|
101
|
+
});
|
|
102
|
+
const detach = control.roving.attach(root);
|
|
103
|
+
const onClick = (event) => {
|
|
104
|
+
pending = event.target.closest?.('[role="radio"]') ?? null;
|
|
105
|
+
};
|
|
106
|
+
root.addEventListener('click', onClick, true);
|
|
107
|
+
const observer = watchChildren(root, () => render(control), [
|
|
108
|
+
'data-value',
|
|
109
|
+
'disabled',
|
|
110
|
+
]);
|
|
111
|
+
return () => {
|
|
112
|
+
detach();
|
|
113
|
+
root.removeEventListener('click', onClick, true);
|
|
114
|
+
observer.disconnect();
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const RADIO_GROUP_KIND = Object.freeze({
|
|
119
|
+
tag: 'ui-radio-group',
|
|
120
|
+
childrenSlot: (node) => node.children[1],
|
|
121
|
+
attributes: {
|
|
122
|
+
disabled: 'boolean',
|
|
123
|
+
invalid: 'boolean',
|
|
124
|
+
orientation: 'string',
|
|
125
|
+
},
|
|
126
|
+
create(el, ctx) {
|
|
127
|
+
const doc = ctx.document;
|
|
128
|
+
const node = doc.createElement('ui-radio-group');
|
|
129
|
+
const labelId = partId(el.id, 'label');
|
|
130
|
+
const label = partOf(doc, 'span', 'label', { id: labelId });
|
|
131
|
+
const root = partOf(doc, 'div', 'root', { 'aria-labelledby': labelId });
|
|
132
|
+
const hidden = partOf(doc, 'input', null, { type: 'hidden', disabled: '' });
|
|
133
|
+
node.appendChild(label);
|
|
134
|
+
node.appendChild(root);
|
|
135
|
+
node.appendChild(hidden);
|
|
136
|
+
let control = null;
|
|
137
|
+
control = startControl(node, el, ctx, {
|
|
138
|
+
kind: 'radio-group',
|
|
139
|
+
parts: { root, label },
|
|
140
|
+
target: root,
|
|
141
|
+
actions: { 'choose-radio': (args, meta) => control.choose?.(args, meta) },
|
|
142
|
+
render: (c) => render(c),
|
|
143
|
+
});
|
|
144
|
+
control.hidden = hidden;
|
|
145
|
+
if (isLive(ctx)) {
|
|
146
|
+
const disconnect = connect(control, root);
|
|
147
|
+
const stop = control.stop;
|
|
148
|
+
control.stop = () => {
|
|
149
|
+
disconnect();
|
|
150
|
+
stop();
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return node;
|
|
154
|
+
},
|
|
155
|
+
eventTarget: (node) => node.children[1],
|
|
156
|
+
update(node, el, changed, ctx) {
|
|
157
|
+
const has = changesOf(node, changed);
|
|
158
|
+
const control = controlOf(node);
|
|
159
|
+
if (has('label')) {
|
|
160
|
+
updateLabel(control.parts.label, el, ctx);
|
|
161
|
+
}
|
|
162
|
+
if (has('name')) {
|
|
163
|
+
setAttr(control.hidden, 'name', atomOf(el, 'name'));
|
|
164
|
+
}
|
|
165
|
+
if (has('orientation')) {
|
|
166
|
+
const vertical = atomOf(el, 'orientation') === 'vertical';
|
|
167
|
+
setAttr(
|
|
168
|
+
control.parts.root,
|
|
169
|
+
'aria-orientation',
|
|
170
|
+
vertical ? 'vertical' : 'horizontal'
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
if (has('required')) {
|
|
174
|
+
const required = flagOf(el, 'required');
|
|
175
|
+
setAttr(
|
|
176
|
+
control.parts.root,
|
|
177
|
+
'aria-required',
|
|
178
|
+
required ? 'true' : undefined
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
for (const name of ['disabled', 'invalid']) {
|
|
182
|
+
if (has(name)) {
|
|
183
|
+
control.assign({ [name]: flagOf(el, name) });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (has('value')) {
|
|
187
|
+
const value = atomOf(el, 'value') ?? null;
|
|
188
|
+
recordChosen(ctx, value);
|
|
189
|
+
receive(control, value);
|
|
190
|
+
}
|
|
191
|
+
render(control);
|
|
192
|
+
},
|
|
193
|
+
destroy: stopControl,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
export const RADIO_KIND = Object.freeze({
|
|
197
|
+
tag: 'ui-radio',
|
|
198
|
+
childrenSlot: null,
|
|
199
|
+
attributes: { disabled: 'boolean' },
|
|
200
|
+
create(el, ctx) {
|
|
201
|
+
const doc = ctx.document;
|
|
202
|
+
const node = doc.createElement('ui-radio');
|
|
203
|
+
const input = partOf(doc, 'button', 'input', {
|
|
204
|
+
type: 'button',
|
|
205
|
+
role: 'radio',
|
|
206
|
+
id: partId(el.id),
|
|
207
|
+
'aria-checked': String(wasChosen(ctx, el.id)),
|
|
208
|
+
tabindex: wasChosen(ctx, el.id) ? '0' : '-1',
|
|
209
|
+
});
|
|
210
|
+
input.appendChild(
|
|
211
|
+
partOf(doc, 'span', 'indicator', { 'aria-hidden': 'true' })
|
|
212
|
+
);
|
|
213
|
+
input.appendChild(partOf(doc, 'span', 'label'));
|
|
214
|
+
node.appendChild(input);
|
|
215
|
+
return node;
|
|
216
|
+
},
|
|
217
|
+
eventTarget: (node) => node.firstChild,
|
|
218
|
+
update(node, el, changed, ctx) {
|
|
219
|
+
const has = changesOf(node, changed);
|
|
220
|
+
const input = node.firstChild;
|
|
221
|
+
if (has('label') || has('value')) {
|
|
222
|
+
setText(input.children[1], choiceLabel(el));
|
|
223
|
+
if (atomOf(el, 'label') === undefined) {
|
|
224
|
+
ctx.diagnostic('missing-label', 'warning', { property: 'label' });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (has('value')) {
|
|
228
|
+
node.setAttribute('data-value', choiceValue(el));
|
|
229
|
+
}
|
|
230
|
+
if (has('disabled')) {
|
|
231
|
+
input.toggleAttribute('disabled', flagOf(el, 'disabled'));
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
});
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `select`: a select-only combobox (APG) — a button that shows the chosen
|
|
3
|
+
* option and opens a `listbox` of `option` children. The focus stays on
|
|
4
|
+
* the button; the active option is its `aria-activedescendant`. The arrow
|
|
5
|
+
* keys, Home, End, PageUp and PageDown move through the options (and
|
|
6
|
+
* open the list), Enter, Space and a click choose, Escape and leaving
|
|
7
|
+
* close, and typing letters jumps to an option (`createTypeahead`).
|
|
8
|
+
*
|
|
9
|
+
* (size: select 'Size' (name size) (value m)
|
|
10
|
+
* (s: option 'Small') (m: option 'Medium') (l: option 'Large'))
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { recordChosen } from './choices.js';
|
|
14
|
+
import { connectListPopover } from '../overlays/list-popover.js';
|
|
15
|
+
import {
|
|
16
|
+
atomOf,
|
|
17
|
+
changesOf,
|
|
18
|
+
commitValue,
|
|
19
|
+
controlOf,
|
|
20
|
+
flagOf,
|
|
21
|
+
isLive,
|
|
22
|
+
partId,
|
|
23
|
+
partOf,
|
|
24
|
+
receive,
|
|
25
|
+
setAttr,
|
|
26
|
+
setText,
|
|
27
|
+
startControl,
|
|
28
|
+
stopControl,
|
|
29
|
+
updateLabel,
|
|
30
|
+
} from './dom.js';
|
|
31
|
+
import {
|
|
32
|
+
connectListbox,
|
|
33
|
+
createListState,
|
|
34
|
+
labelAmong,
|
|
35
|
+
listboxActions,
|
|
36
|
+
optionFor,
|
|
37
|
+
optionLabel,
|
|
38
|
+
renderOptions,
|
|
39
|
+
} from './listbox.js';
|
|
40
|
+
|
|
41
|
+
/** Show the chosen option, mark the options, then commit a user change. */
|
|
42
|
+
function render(control) {
|
|
43
|
+
const { context } = control.service;
|
|
44
|
+
const { listbox, value: shown } = control.parts;
|
|
45
|
+
const option = control.live ? optionFor(listbox, context.value) : null;
|
|
46
|
+
const label = option ? optionLabel(option) : control.labelOf?.(context.value);
|
|
47
|
+
setText(shown, label ?? control.placeholder ?? '');
|
|
48
|
+
shown.toggleAttribute('data-placeholder', !label);
|
|
49
|
+
setAttr(control.hidden, 'value', context.value ?? '');
|
|
50
|
+
control.hidden.toggleAttribute('disabled', context.value === null);
|
|
51
|
+
if (control.live) {
|
|
52
|
+
renderOptions(listbox, context);
|
|
53
|
+
}
|
|
54
|
+
commitValue(control);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Send a printable key to the typeahead (the machine binds no letters). */
|
|
58
|
+
function typeaheadKeys(control, list, input) {
|
|
59
|
+
const onKeyDown = (event) => {
|
|
60
|
+
if (
|
|
61
|
+
event.key === 'Tab' &&
|
|
62
|
+
!event.ctrlKey &&
|
|
63
|
+
!event.altKey &&
|
|
64
|
+
!event.metaKey
|
|
65
|
+
) {
|
|
66
|
+
control.service.send('blur');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const plain = !event.ctrlKey && !event.altKey && !event.metaKey;
|
|
70
|
+
if (!plain || [...event.key].length !== 1 || event.key === ' ') {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
list.typed = event.key;
|
|
74
|
+
control.service.send('typeahead');
|
|
75
|
+
list.typed = null;
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
};
|
|
78
|
+
input.addEventListener('keydown', onKeyDown);
|
|
79
|
+
return () => input.removeEventListener('keydown', onKeyDown);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function updateNaming(control, el, has) {
|
|
83
|
+
const { input } = control.parts;
|
|
84
|
+
if (
|
|
85
|
+
[
|
|
86
|
+
'label',
|
|
87
|
+
'external-label',
|
|
88
|
+
'aria-label',
|
|
89
|
+
'aria-labelledby',
|
|
90
|
+
'list-label',
|
|
91
|
+
'list-labelledby',
|
|
92
|
+
].some(has)
|
|
93
|
+
) {
|
|
94
|
+
const external = flagOf(el, 'external-label');
|
|
95
|
+
control.parts.label.toggleAttribute('hidden', external);
|
|
96
|
+
if (external) {
|
|
97
|
+
setText(control.parts.label, '');
|
|
98
|
+
}
|
|
99
|
+
setAttr(input, 'aria-label', atomOf(el, 'aria-label'));
|
|
100
|
+
setAttr(
|
|
101
|
+
input,
|
|
102
|
+
'aria-labelledby',
|
|
103
|
+
atomOf(el, 'aria-labelledby') ??
|
|
104
|
+
(external || atomOf(el, 'aria-label')
|
|
105
|
+
? undefined
|
|
106
|
+
: partId(el.id, 'label'))
|
|
107
|
+
);
|
|
108
|
+
setAttr(control.parts.listbox, 'aria-label', atomOf(el, 'list-label'));
|
|
109
|
+
setAttr(
|
|
110
|
+
control.parts.listbox,
|
|
111
|
+
'aria-labelledby',
|
|
112
|
+
atomOf(el, 'list-labelledby') ??
|
|
113
|
+
(external || atomOf(el, 'list-label')
|
|
114
|
+
? undefined
|
|
115
|
+
: partId(el.id, 'label'))
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
for (const name of ['menu-min-width', 'menu-max-height']) {
|
|
119
|
+
if (has(name)) {
|
|
120
|
+
control.node.style.setProperty(`--${name}`, atomOf(el, name) ?? '');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const SELECT_KIND = Object.freeze({
|
|
126
|
+
tag: 'ui-select',
|
|
127
|
+
childrenSlot: (node) => controlOf(node).parts.listbox,
|
|
128
|
+
attributes: { disabled: 'boolean', invalid: 'boolean' },
|
|
129
|
+
create(el, ctx) {
|
|
130
|
+
const doc = ctx.document;
|
|
131
|
+
const node = doc.createElement('ui-select');
|
|
132
|
+
const labelId = partId(el.id, 'label');
|
|
133
|
+
const listboxId = partId(el.id, 'listbox');
|
|
134
|
+
const label = partOf(doc, 'span', 'label', { id: labelId });
|
|
135
|
+
const input = partOf(doc, 'button', 'input', {
|
|
136
|
+
type: 'button',
|
|
137
|
+
id: partId(el.id),
|
|
138
|
+
'aria-labelledby': labelId,
|
|
139
|
+
'aria-controls': listboxId,
|
|
140
|
+
});
|
|
141
|
+
const value = partOf(doc, 'span', 'value');
|
|
142
|
+
const indicator = partOf(doc, 'span', 'indicator', {
|
|
143
|
+
'aria-hidden': 'true',
|
|
144
|
+
});
|
|
145
|
+
input.appendChild(value);
|
|
146
|
+
input.appendChild(indicator);
|
|
147
|
+
const listbox = partOf(doc, 'div', 'listbox', {
|
|
148
|
+
id: listboxId,
|
|
149
|
+
'aria-labelledby': labelId,
|
|
150
|
+
tabindex: '-1',
|
|
151
|
+
});
|
|
152
|
+
const hidden = partOf(doc, 'input', null, { type: 'hidden', disabled: '' });
|
|
153
|
+
for (const part of [label, input, listbox, hidden]) {
|
|
154
|
+
node.appendChild(part);
|
|
155
|
+
}
|
|
156
|
+
const list = createListState(listbox);
|
|
157
|
+
const control = startControl(node, el, ctx, {
|
|
158
|
+
kind: 'select',
|
|
159
|
+
parts: { label, input, value, indicator, listbox },
|
|
160
|
+
target: input,
|
|
161
|
+
actions: listboxActions(list),
|
|
162
|
+
context: { value: null, active: null },
|
|
163
|
+
render: (c) => render(c),
|
|
164
|
+
});
|
|
165
|
+
control.hidden = hidden;
|
|
166
|
+
control.live = isLive(ctx);
|
|
167
|
+
if (control.live) {
|
|
168
|
+
const disconnect = connectListbox(list, control, () => render(control));
|
|
169
|
+
const untype = typeaheadKeys(control, list, input);
|
|
170
|
+
const focus = () => input.focus({ preventScroll: true });
|
|
171
|
+
input.addEventListener('click', focus, true);
|
|
172
|
+
const unpopover = connectListPopover(control);
|
|
173
|
+
const stop = control.stop;
|
|
174
|
+
control.stop = () => {
|
|
175
|
+
disconnect();
|
|
176
|
+
untype();
|
|
177
|
+
input.removeEventListener('click', focus, true);
|
|
178
|
+
unpopover();
|
|
179
|
+
stop();
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return node;
|
|
183
|
+
},
|
|
184
|
+
eventTarget: (node) => node.children[1],
|
|
185
|
+
update(node, el, changed, ctx) {
|
|
186
|
+
const has = changesOf(node, changed);
|
|
187
|
+
const control = controlOf(node);
|
|
188
|
+
const { input } = control.parts;
|
|
189
|
+
if (
|
|
190
|
+
(has('label') || has('external-label')) &&
|
|
191
|
+
!flagOf(el, 'external-label')
|
|
192
|
+
) {
|
|
193
|
+
updateLabel(control.parts.label, el, ctx);
|
|
194
|
+
}
|
|
195
|
+
updateNaming(control, el, has);
|
|
196
|
+
if (has('name')) {
|
|
197
|
+
setAttr(control.hidden, 'name', atomOf(el, 'name'));
|
|
198
|
+
}
|
|
199
|
+
if (has('placeholder')) {
|
|
200
|
+
control.placeholder = atomOf(el, 'placeholder');
|
|
201
|
+
}
|
|
202
|
+
if (has('required')) {
|
|
203
|
+
setAttr(
|
|
204
|
+
input,
|
|
205
|
+
'aria-required',
|
|
206
|
+
flagOf(el, 'required') ? 'true' : undefined
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
for (const name of ['disabled', 'invalid']) {
|
|
210
|
+
if (has(name)) {
|
|
211
|
+
const on = flagOf(el, name);
|
|
212
|
+
if (name === 'disabled') {
|
|
213
|
+
input.toggleAttribute('disabled', on);
|
|
214
|
+
}
|
|
215
|
+
control.assign({ [name]: on });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (has('value')) {
|
|
219
|
+
const value = atomOf(el, 'value') ?? null;
|
|
220
|
+
recordChosen(ctx, value);
|
|
221
|
+
control.labelOf = (v) => labelAmong(ctx.children(), v);
|
|
222
|
+
receive(control, value);
|
|
223
|
+
} else {
|
|
224
|
+
render(control);
|
|
225
|
+
}
|
|
226
|
+
control.syncListPopover?.();
|
|
227
|
+
},
|
|
228
|
+
destroy: stopControl,
|
|
229
|
+
});
|