@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,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small menu button popup (WAI-ARIA APG menu button pattern), used by the
|
|
3
|
+
* tab strip overflow menu and the panel actions of a dock.
|
|
4
|
+
*
|
|
5
|
+
* `openMenu(button, items)` shows `role="menu"` after the button with one
|
|
6
|
+
* `role="menuitem"` per item and focuses the first one. Up and Down move
|
|
7
|
+
* between the items (Home and End to the ends), Enter and Space choose one,
|
|
8
|
+
* and Escape or Tab close the menu; focus goes back to the button, unless
|
|
9
|
+
* the chosen action moved it.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { bindKeys } from '../a11y/keys.js';
|
|
13
|
+
import { createRovingTabindex } from '../a11y/roving.js';
|
|
14
|
+
import { make } from './dom.js';
|
|
15
|
+
|
|
16
|
+
const open = new WeakMap();
|
|
17
|
+
|
|
18
|
+
/** Close the menu of a button, if it is open. */
|
|
19
|
+
export function closeMenu(button, { restoreFocus = true } = {}) {
|
|
20
|
+
const menu = open.get(button);
|
|
21
|
+
if (menu === undefined) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
open.delete(button);
|
|
25
|
+
menu.cleanup();
|
|
26
|
+
menu.element.remove();
|
|
27
|
+
button.setAttribute('aria-expanded', 'false');
|
|
28
|
+
if (restoreFocus) {
|
|
29
|
+
button.focus();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A menu button: a `button` with `aria-haspopup="menu"` that opens the
|
|
35
|
+
* menu of `items()` (called each time it opens).
|
|
36
|
+
* @param {Document} document
|
|
37
|
+
* @param {{label: string, text: string, className?: string,
|
|
38
|
+
* items: () => {label: string, run: () => void, disabled?: boolean}[]}} spec
|
|
39
|
+
*/
|
|
40
|
+
export function menuButton(document, { label, text, className, items }) {
|
|
41
|
+
const button = make(
|
|
42
|
+
document,
|
|
43
|
+
'button',
|
|
44
|
+
{
|
|
45
|
+
type: 'button',
|
|
46
|
+
class: className,
|
|
47
|
+
'aria-label': label,
|
|
48
|
+
'aria-haspopup': 'menu',
|
|
49
|
+
'aria-expanded': 'false',
|
|
50
|
+
},
|
|
51
|
+
text
|
|
52
|
+
);
|
|
53
|
+
const toggle = (focusLast = false) => {
|
|
54
|
+
if (open.has(button)) {
|
|
55
|
+
closeMenu(button);
|
|
56
|
+
} else {
|
|
57
|
+
openMenu(button, items(), { focusLast });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
button.addEventListener('click', () => toggle());
|
|
61
|
+
const openWith = (focusLast) => () => {
|
|
62
|
+
if (!open.has(button)) {
|
|
63
|
+
toggle(focusLast);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
bindKeys(button, { ArrowDown: openWith(false), ArrowUp: openWith(true) });
|
|
67
|
+
return button;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Open a menu for `button`.
|
|
72
|
+
* @param {HTMLElement} button
|
|
73
|
+
* @param {{label: string, run: () => void, disabled?: boolean}[]} items
|
|
74
|
+
* @param {{focusLast?: boolean}} [options]
|
|
75
|
+
*/
|
|
76
|
+
export function openMenu(button, items, options = {}) {
|
|
77
|
+
closeMenu(button, { restoreFocus: false });
|
|
78
|
+
const document = button.ownerDocument;
|
|
79
|
+
const element = make(document, 'div', {
|
|
80
|
+
class: 'ui-menu',
|
|
81
|
+
role: 'menu',
|
|
82
|
+
'aria-label': button.getAttribute('aria-label'),
|
|
83
|
+
});
|
|
84
|
+
const nodes = items.map((item) => {
|
|
85
|
+
const node = make(
|
|
86
|
+
document,
|
|
87
|
+
'button',
|
|
88
|
+
{
|
|
89
|
+
type: 'button',
|
|
90
|
+
role: 'menuitem',
|
|
91
|
+
tabindex: '-1',
|
|
92
|
+
'aria-disabled': item.disabled ? 'true' : undefined,
|
|
93
|
+
},
|
|
94
|
+
item.label
|
|
95
|
+
);
|
|
96
|
+
node.addEventListener('click', () => {
|
|
97
|
+
if (item.disabled) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
closeMenu(button);
|
|
101
|
+
item.run();
|
|
102
|
+
});
|
|
103
|
+
return node;
|
|
104
|
+
});
|
|
105
|
+
element.append(...nodes);
|
|
106
|
+
// Up, Down, Home and End move among the enabled items (around the ends).
|
|
107
|
+
const roving = createRovingTabindex(nodes, { orientation: 'vertical' });
|
|
108
|
+
roving.attach(element);
|
|
109
|
+
// The keys of an open menu stay in it (a menu in a window keeps Escape).
|
|
110
|
+
bindKeys(element, {
|
|
111
|
+
Escape: (event) => {
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
closeMenu(button);
|
|
114
|
+
},
|
|
115
|
+
Tab: () => {
|
|
116
|
+
closeMenu(button, { restoreFocus: false });
|
|
117
|
+
return false;
|
|
118
|
+
},
|
|
119
|
+
'Shift+Tab': () => {
|
|
120
|
+
closeMenu(button, { restoreFocus: false });
|
|
121
|
+
return false;
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
const onOutside = (event) => {
|
|
125
|
+
if (!element.contains(event.target) && event.target !== button) {
|
|
126
|
+
closeMenu(button, { restoreFocus: false });
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
document.addEventListener('pointerdown', onOutside, true);
|
|
130
|
+
button.after(element);
|
|
131
|
+
button.setAttribute('aria-expanded', 'true');
|
|
132
|
+
open.set(button, {
|
|
133
|
+
element,
|
|
134
|
+
cleanup: () => document.removeEventListener('pointerdown', onOutside, true),
|
|
135
|
+
});
|
|
136
|
+
const enabled = (node) => node.getAttribute('aria-disabled') !== 'true';
|
|
137
|
+
roving.focus(
|
|
138
|
+
options.focusLast ? nodes.findLastIndex(enabled) : nodes.findIndex(enabled)
|
|
139
|
+
);
|
|
140
|
+
return element;
|
|
141
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/** Logical edge detection uses geometry, independent of RTL scrollLeft models. */
|
|
2
|
+
import { focusAnchor } from './page-links.js';
|
|
3
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
4
|
+
import {
|
|
5
|
+
atomOf,
|
|
6
|
+
controllerOf,
|
|
7
|
+
dropController,
|
|
8
|
+
isLive,
|
|
9
|
+
make,
|
|
10
|
+
setAttr,
|
|
11
|
+
setText,
|
|
12
|
+
} from './dom.js';
|
|
13
|
+
|
|
14
|
+
function createStrip(node) {
|
|
15
|
+
const win = node.ownerDocument.defaultView;
|
|
16
|
+
const nav = node.firstChild;
|
|
17
|
+
const list = nav.firstChild;
|
|
18
|
+
let active;
|
|
19
|
+
let direction;
|
|
20
|
+
let frame;
|
|
21
|
+
let breakpoint;
|
|
22
|
+
let media;
|
|
23
|
+
let el;
|
|
24
|
+
const links = () => [...list.querySelectorAll('a')];
|
|
25
|
+
const edges = () => {
|
|
26
|
+
const items = links();
|
|
27
|
+
const box = nav.getBoundingClientRect();
|
|
28
|
+
const rtl = win.getComputedStyle(nav).direction === 'rtl';
|
|
29
|
+
const left = items.some(
|
|
30
|
+
(a) => a.getBoundingClientRect().left < box.left - 1
|
|
31
|
+
);
|
|
32
|
+
const right = items.some(
|
|
33
|
+
(a) => a.getBoundingClientRect().right > box.right + 1
|
|
34
|
+
);
|
|
35
|
+
const more = [rtl ? right : left, rtl ? left : right]
|
|
36
|
+
.map((value, i) => (value ? ['start', 'end'][i] : ''))
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.join(' ');
|
|
39
|
+
setAttr(nav, 'data-more', more || undefined);
|
|
40
|
+
};
|
|
41
|
+
const refresh = () => {
|
|
42
|
+
const items = links();
|
|
43
|
+
const wanted = atomOf(el, 'active');
|
|
44
|
+
const current = items.find(
|
|
45
|
+
(a) =>
|
|
46
|
+
a.closest('[data-link-id]')?.getAttribute('data-link-id') === wanted ||
|
|
47
|
+
a.getAttribute('href') === wanted
|
|
48
|
+
);
|
|
49
|
+
for (const a of items) {
|
|
50
|
+
setAttr(
|
|
51
|
+
a,
|
|
52
|
+
'aria-current',
|
|
53
|
+
a === current
|
|
54
|
+
? node.localName === 'ui-section-nav'
|
|
55
|
+
? 'location'
|
|
56
|
+
: 'page'
|
|
57
|
+
: undefined
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const nextDirection = win.getComputedStyle(nav).direction;
|
|
61
|
+
if (
|
|
62
|
+
current &&
|
|
63
|
+
(current !== active || direction !== nextDirection) &&
|
|
64
|
+
nav.scrollWidth > nav.clientWidth + 1
|
|
65
|
+
) {
|
|
66
|
+
const a = current.getBoundingClientRect();
|
|
67
|
+
const box = nav.getBoundingClientRect();
|
|
68
|
+
nav.scrollBy?.({
|
|
69
|
+
left: (a.left + a.right - box.left - box.right) / 2,
|
|
70
|
+
behavior: 'instant',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
active = current;
|
|
74
|
+
direction = nextDirection;
|
|
75
|
+
edges();
|
|
76
|
+
};
|
|
77
|
+
const schedule = () => {
|
|
78
|
+
win.cancelAnimationFrame(frame);
|
|
79
|
+
frame = win.requestAnimationFrame(refresh);
|
|
80
|
+
};
|
|
81
|
+
const wrap = () => {
|
|
82
|
+
setAttr(node, 'data-wrapped', media?.matches ?? false);
|
|
83
|
+
schedule();
|
|
84
|
+
};
|
|
85
|
+
const observer = new win.MutationObserver(schedule);
|
|
86
|
+
observer.observe(list, {
|
|
87
|
+
childList: true,
|
|
88
|
+
subtree: true,
|
|
89
|
+
attributes: true,
|
|
90
|
+
attributeFilter: ['href'],
|
|
91
|
+
});
|
|
92
|
+
observer.observe(node.ownerDocument.documentElement, {
|
|
93
|
+
attributes: true,
|
|
94
|
+
attributeFilter: ['dir'],
|
|
95
|
+
});
|
|
96
|
+
const resize =
|
|
97
|
+
typeof win.ResizeObserver === 'function'
|
|
98
|
+
? new win.ResizeObserver(schedule)
|
|
99
|
+
: null;
|
|
100
|
+
resize?.observe(nav);
|
|
101
|
+
resize?.observe(list);
|
|
102
|
+
nav.addEventListener('scroll', edges, { passive: true });
|
|
103
|
+
win.addEventListener('resize', schedule);
|
|
104
|
+
return {
|
|
105
|
+
update(next) {
|
|
106
|
+
el = next;
|
|
107
|
+
const width = atomOf(el, 'wrap-below');
|
|
108
|
+
if (width !== breakpoint) {
|
|
109
|
+
media?.removeEventListener('change', wrap);
|
|
110
|
+
breakpoint = width;
|
|
111
|
+
media = /^\d+(?:\.\d+)?(?:px|rem|em)$/.test(width ?? '')
|
|
112
|
+
? win.matchMedia?.(`(width < ${width})`)
|
|
113
|
+
: null;
|
|
114
|
+
media?.addEventListener('change', wrap);
|
|
115
|
+
}
|
|
116
|
+
refresh();
|
|
117
|
+
wrap();
|
|
118
|
+
},
|
|
119
|
+
disconnect() {
|
|
120
|
+
win.cancelAnimationFrame(frame);
|
|
121
|
+
observer.disconnect();
|
|
122
|
+
resize?.disconnect();
|
|
123
|
+
media?.removeEventListener('change', wrap);
|
|
124
|
+
nav.removeEventListener('scroll', edges);
|
|
125
|
+
win.removeEventListener('resize', schedule);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (const kind of ['nav-strip', 'section-nav']) {
|
|
131
|
+
defineKind(kind, {
|
|
132
|
+
tag: `ui-${kind}`,
|
|
133
|
+
childrenSlot: (node) => node.firstChild.firstChild,
|
|
134
|
+
create(el, ctx) {
|
|
135
|
+
const node = ctx.document.createElement(`ui-${kind}`);
|
|
136
|
+
const nav = make(ctx.document, 'nav');
|
|
137
|
+
nav.appendChild(make(ctx.document, 'ul'));
|
|
138
|
+
node.appendChild(nav);
|
|
139
|
+
return node;
|
|
140
|
+
},
|
|
141
|
+
update(node, el, changed, ctx) {
|
|
142
|
+
const nav = node.firstChild;
|
|
143
|
+
setAttr(
|
|
144
|
+
nav,
|
|
145
|
+
'aria-label',
|
|
146
|
+
atomOf(el, 'label') ?? (kind === 'nav-strip' ? 'Pages' : 'Sections')
|
|
147
|
+
);
|
|
148
|
+
const href = atomOf(el, 'back-to-top');
|
|
149
|
+
let back = nav.querySelector('[data-part="back"]');
|
|
150
|
+
if (kind === 'section-nav' && href?.startsWith('#')) {
|
|
151
|
+
if (!back) {
|
|
152
|
+
back = make(ctx.document, 'li', { 'data-part': 'back' });
|
|
153
|
+
const a = make(ctx.document, 'a');
|
|
154
|
+
back.appendChild(a);
|
|
155
|
+
nav.firstChild.insertBefore(back, nav.firstChild.firstChild);
|
|
156
|
+
a.addEventListener('click', focusAnchor);
|
|
157
|
+
}
|
|
158
|
+
setAttr(back.firstChild, 'href', href);
|
|
159
|
+
setAttr(
|
|
160
|
+
back.firstChild,
|
|
161
|
+
'aria-label',
|
|
162
|
+
atomOf(el, 'back-label') ?? 'Back to top'
|
|
163
|
+
);
|
|
164
|
+
setText(back.firstChild, '↑');
|
|
165
|
+
} else {
|
|
166
|
+
back?.remove();
|
|
167
|
+
}
|
|
168
|
+
if (isLive(ctx)) {
|
|
169
|
+
controllerOf(node, () => createStrip(node)).update(el);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
destroy: dropController,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/** Native page links share the controls' URL policy and ui-navigate event. */
|
|
2
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
3
|
+
import { LINK_KIND } from '../controls/link.js';
|
|
4
|
+
import { atomOf, make, numberOf, setAttr, setText, uid } from './dom.js';
|
|
5
|
+
|
|
6
|
+
function isModified(event) {
|
|
7
|
+
return (
|
|
8
|
+
event.button !== 0 ||
|
|
9
|
+
event.ctrlKey ||
|
|
10
|
+
event.metaKey ||
|
|
11
|
+
event.shiftKey ||
|
|
12
|
+
event.altKey
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function focusAnchor(event) {
|
|
17
|
+
if (event.defaultPrevented || isModified(event)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const a = event.currentTarget;
|
|
21
|
+
const href = a.getAttribute('href');
|
|
22
|
+
if (!a.closest('ui-section-nav') || !href?.startsWith('#')) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let id;
|
|
26
|
+
try {
|
|
27
|
+
id = decodeURIComponent(href.slice(1));
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const doc = a.ownerDocument;
|
|
32
|
+
const target =
|
|
33
|
+
doc.getElementById(id) ??
|
|
34
|
+
[...doc.querySelectorAll('[data-link-id]')].find(
|
|
35
|
+
(node) => node.getAttribute('data-link-id') === id
|
|
36
|
+
);
|
|
37
|
+
if (target) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
const temporary = !target.hasAttribute('tabindex');
|
|
40
|
+
if (temporary) {
|
|
41
|
+
target.tabIndex = -1;
|
|
42
|
+
target.addEventListener(
|
|
43
|
+
'blur',
|
|
44
|
+
() => target.removeAttribute('tabindex'),
|
|
45
|
+
{ once: true }
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
target.focus({ preventScroll: true });
|
|
49
|
+
target.scrollIntoView?.({ block: 'start', behavior: 'auto' });
|
|
50
|
+
if (doc.defaultView.location.protocol !== 'about:') {
|
|
51
|
+
doc.defaultView.history?.replaceState(null, '', href);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function drawCard(a, el, ctx) {
|
|
57
|
+
for (const child of [...a.childNodes]) {
|
|
58
|
+
a.removeChild(child);
|
|
59
|
+
}
|
|
60
|
+
const glyph = make(
|
|
61
|
+
ctx.document,
|
|
62
|
+
'span',
|
|
63
|
+
{ 'data-part': 'glyph', 'aria-hidden': 'true' },
|
|
64
|
+
atomOf(el, 'glyph') ?? atomOf(el, 'icon') ?? ''
|
|
65
|
+
);
|
|
66
|
+
const title = make(
|
|
67
|
+
ctx.document,
|
|
68
|
+
'span',
|
|
69
|
+
{ 'data-part': 'title' },
|
|
70
|
+
atomOf(el, 'title') ??
|
|
71
|
+
atomOf(el, 'label') ??
|
|
72
|
+
el.positional?.[0] ??
|
|
73
|
+
atomOf(el, 'href')
|
|
74
|
+
);
|
|
75
|
+
const summary = make(
|
|
76
|
+
ctx.document,
|
|
77
|
+
'span',
|
|
78
|
+
{ 'data-part': 'summary' },
|
|
79
|
+
atomOf(el, 'summary') ?? ''
|
|
80
|
+
);
|
|
81
|
+
for (const part of [glyph, title, summary]) {
|
|
82
|
+
a.appendChild(part);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function linkSpec(card) {
|
|
87
|
+
return {
|
|
88
|
+
tag: card ? 'ui-link-card' : 'ui-nav-link',
|
|
89
|
+
childrenSlot: null,
|
|
90
|
+
eventTarget: (node) => node.firstChild,
|
|
91
|
+
create(el, ctx) {
|
|
92
|
+
const node = ctx.document.createElement(card ? 'ui-link-card' : 'li');
|
|
93
|
+
const link = LINK_KIND.create(el, ctx);
|
|
94
|
+
node.appendChild(link.firstChild);
|
|
95
|
+
if (ctx.document.defaultView) {
|
|
96
|
+
node.firstChild.addEventListener('click', focusAnchor);
|
|
97
|
+
}
|
|
98
|
+
return node;
|
|
99
|
+
},
|
|
100
|
+
update(node, el, changed, ctx) {
|
|
101
|
+
const label = atomOf(el, card ? 'title' : 'label') ?? el.positional?.[0];
|
|
102
|
+
const props = new Map(el.props);
|
|
103
|
+
if (!props.has('label') && label !== undefined) {
|
|
104
|
+
props.set('label', [label]);
|
|
105
|
+
}
|
|
106
|
+
LINK_KIND.update(node, { ...el, props }, changed, ctx);
|
|
107
|
+
if (card) {
|
|
108
|
+
drawCard(node.firstChild, el, ctx);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
defineKind('nav-link', linkSpec(false));
|
|
115
|
+
defineKind('link-card', linkSpec(true));
|
|
116
|
+
|
|
117
|
+
defineKind('link-cards', {
|
|
118
|
+
tag: 'ui-link-cards',
|
|
119
|
+
create: (el, ctx) => ctx.document.createElement('ui-link-cards'),
|
|
120
|
+
update(node, el) {
|
|
121
|
+
const min = atomOf(el, 'min');
|
|
122
|
+
// CSS.supports is unavailable during static rendering. Accept dimensions
|
|
123
|
+
// only, never a declaration or arbitrary CSS expression.
|
|
124
|
+
const valid = min && /^(?:\d+(?:\.\d+)?)(?:px|rem|em|ch|vw|%)$/.test(min);
|
|
125
|
+
node.style.setProperty('--min', valid ? min : '240px');
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
defineKind('titled-section', {
|
|
130
|
+
tag: 'ui-titled-section',
|
|
131
|
+
childrenSlot: (node) => node.firstChild.children[2],
|
|
132
|
+
create(el, ctx) {
|
|
133
|
+
const node = ctx.document.createElement('ui-titled-section');
|
|
134
|
+
const section = make(ctx.document, 'section');
|
|
135
|
+
const parts = [
|
|
136
|
+
make(ctx.document, 'div', { 'data-part': 'kicker' }),
|
|
137
|
+
make(ctx.document, 'h2', { id: uid('ui-section-title') }),
|
|
138
|
+
make(ctx.document, 'div', { 'data-part': 'content' }),
|
|
139
|
+
];
|
|
140
|
+
for (const part of parts) {
|
|
141
|
+
section.appendChild(part);
|
|
142
|
+
}
|
|
143
|
+
node.appendChild(section);
|
|
144
|
+
return node;
|
|
145
|
+
},
|
|
146
|
+
update(node, el, changed, ctx) {
|
|
147
|
+
const section = node.firstChild;
|
|
148
|
+
const level = Math.max(
|
|
149
|
+
1,
|
|
150
|
+
Math.min(6, Math.trunc(numberOf(el, 'level', 2)))
|
|
151
|
+
);
|
|
152
|
+
let heading = section.children[1];
|
|
153
|
+
if (heading.localName !== `h${level}`) {
|
|
154
|
+
const next = make(ctx.document, `h${level}`, {
|
|
155
|
+
id: heading.getAttribute('id'),
|
|
156
|
+
});
|
|
157
|
+
section.insertBefore(next, heading);
|
|
158
|
+
section.removeChild(heading);
|
|
159
|
+
heading = next;
|
|
160
|
+
}
|
|
161
|
+
setText(heading, atomOf(el, 'title') ?? el.positional?.[0] ?? 'Section');
|
|
162
|
+
setAttr(section, 'aria-labelledby', heading.getAttribute('id'));
|
|
163
|
+
setText(section.firstChild, atomOf(el, 'kicker'));
|
|
164
|
+
setAttr(section.firstChild, 'hidden', !atomOf(el, 'kicker'));
|
|
165
|
+
},
|
|
166
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `panel`: a titled panel, the content of a tab of a tab group or of a dock.
|
|
3
|
+
* Its `title` and `closable` are written as `data-title` and
|
|
4
|
+
* `data-closable`, which the tab group or the dock reads.
|
|
5
|
+
*
|
|
6
|
+
* (outline: panel (title Outline) (closable true) ...)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
10
|
+
import { atomOf, setAttr } from './dom.js';
|
|
11
|
+
|
|
12
|
+
defineKind('panel', {
|
|
13
|
+
tag: 'ui-panel',
|
|
14
|
+
create: (el, ctx) => ctx.document.createElement('ui-panel'),
|
|
15
|
+
update(node, el, changed) {
|
|
16
|
+
if (changed.includes('title')) {
|
|
17
|
+
setAttr(node, 'data-title', atomOf(el, 'title') ?? el.name ?? undefined);
|
|
18
|
+
}
|
|
19
|
+
if (changed.includes('closable')) {
|
|
20
|
+
setAttr(node, 'data-closable', atomOf(el, 'closable'));
|
|
21
|
+
}
|
|
22
|
+
if (!node.hasAttribute('data-title') && el.name !== null) {
|
|
23
|
+
node.setAttribute('data-title', el.name);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|