@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,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `slider`: a value in a range, set by dragging the thumb (or pressing
|
|
3
|
+
* the track) or with the keys: the arrows step (×10 with Shift; Left and
|
|
4
|
+
* Right swap in right-to-left text), PageUp/PageDown move ten steps,
|
|
5
|
+
* Home/End go to the ends. The thumb is the `slider` role with
|
|
6
|
+
* `aria-valuenow`, `-valuemin`, `-valuemax` and `aria-valuetext`
|
|
7
|
+
* (`value-text` with `{value}` in it, else the number). A drag commits
|
|
8
|
+
* a single value on pointer release; every key commits its new value.
|
|
9
|
+
*
|
|
10
|
+
* (volume: slider 'Volume' (name volume) (min 0) (max 100) (step 5) (value 40)
|
|
11
|
+
* (value-text '{value} %'))
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
atomOf,
|
|
16
|
+
changesOf,
|
|
17
|
+
commitValue,
|
|
18
|
+
controlOf,
|
|
19
|
+
flagOf,
|
|
20
|
+
isLive,
|
|
21
|
+
maybeNumber,
|
|
22
|
+
numberOf,
|
|
23
|
+
partId,
|
|
24
|
+
partOf,
|
|
25
|
+
receive,
|
|
26
|
+
setAttr,
|
|
27
|
+
startControl,
|
|
28
|
+
stopControl,
|
|
29
|
+
updateLabel,
|
|
30
|
+
} from './dom.js';
|
|
31
|
+
import { clampStep, nextValue } from './numeric-keys.js';
|
|
32
|
+
|
|
33
|
+
const DEFAULT_RANGE = Object.freeze({ min: 0, max: 100, step: 1 });
|
|
34
|
+
|
|
35
|
+
/** The range of the slider context. */
|
|
36
|
+
const rangeOf = (context) => ({
|
|
37
|
+
min: context.min,
|
|
38
|
+
max: context.max,
|
|
39
|
+
step: context.step,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** The fraction (0–1) of the range a value is at. */
|
|
43
|
+
export function fractionOf(value, { min, max }) {
|
|
44
|
+
if (!(max > min) || !Number.isFinite(value)) {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
return Math.min(1, Math.max(0, (value - min) / (max - min)));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The text of a value: the `value-text` template, else the number. */
|
|
51
|
+
export const valueText = (template, value) =>
|
|
52
|
+
template === undefined || template === null
|
|
53
|
+
? String(value)
|
|
54
|
+
: template.replaceAll('{value}', String(value));
|
|
55
|
+
|
|
56
|
+
/** The value a pointer position on the track stands for. */
|
|
57
|
+
function pointerValue(event, track, context) {
|
|
58
|
+
const box = track.getBoundingClientRect();
|
|
59
|
+
const vertical = context.orientation === 'vertical';
|
|
60
|
+
let fraction = vertical
|
|
61
|
+
? (box.bottom - event.clientY) / (box.height || 1)
|
|
62
|
+
: (event.clientX - box.left) / (box.width || 1);
|
|
63
|
+
const rtl =
|
|
64
|
+
!vertical &&
|
|
65
|
+
track.ownerDocument.defaultView.getComputedStyle(track).direction === 'rtl';
|
|
66
|
+
if (rtl) {
|
|
67
|
+
fraction = 1 - fraction;
|
|
68
|
+
}
|
|
69
|
+
const { min, max } = context;
|
|
70
|
+
return clampStep(min + Math.min(1, Math.max(0, fraction)) * (max - min), {
|
|
71
|
+
...rangeOf(context),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The machine actions; `pointer` is the pointer event being handled. */
|
|
76
|
+
function actionsOf(state) {
|
|
77
|
+
return {
|
|
78
|
+
'numeric-key': ([key, shift], meta) => {
|
|
79
|
+
const { context } = meta;
|
|
80
|
+
const rtl =
|
|
81
|
+
context.orientation !== 'vertical' &&
|
|
82
|
+
state.track.ownerDocument.defaultView.getComputedStyle(state.track)
|
|
83
|
+
.direction === 'rtl';
|
|
84
|
+
const value = nextValue(key, {
|
|
85
|
+
...rangeOf(context),
|
|
86
|
+
value: context.value,
|
|
87
|
+
shift: shift === 'shift',
|
|
88
|
+
rtl,
|
|
89
|
+
});
|
|
90
|
+
if (value !== null) {
|
|
91
|
+
meta.assign({ value });
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
'move-to-pointer': (args, meta) => {
|
|
95
|
+
if (state.pointer !== null) {
|
|
96
|
+
meta.assign({
|
|
97
|
+
value: pointerValue(state.pointer, state.track, meta.context),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Capture the pointer on the track while dragging; focus the thumb. */
|
|
105
|
+
function trackPointer(state, thumb) {
|
|
106
|
+
const { track } = state;
|
|
107
|
+
const hold = (event) => {
|
|
108
|
+
state.pointer = event.type === 'lostpointercapture' ? null : event;
|
|
109
|
+
if (event.type === 'pointerdown' && event.button === 0) {
|
|
110
|
+
track.setPointerCapture?.(event.pointerId);
|
|
111
|
+
thumb.focus();
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
for (const type of [
|
|
116
|
+
'pointerdown',
|
|
117
|
+
'pointermove',
|
|
118
|
+
'pointerup',
|
|
119
|
+
'lostpointercapture',
|
|
120
|
+
]) {
|
|
121
|
+
track.addEventListener(type, hold, true);
|
|
122
|
+
}
|
|
123
|
+
return () => {
|
|
124
|
+
for (const type of [
|
|
125
|
+
'pointerdown',
|
|
126
|
+
'pointermove',
|
|
127
|
+
'pointerup',
|
|
128
|
+
'lostpointercapture',
|
|
129
|
+
]) {
|
|
130
|
+
track.removeEventListener(type, hold, true);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Show the value; commit it unless a drag is going on. */
|
|
136
|
+
function render(control) {
|
|
137
|
+
const { context, state } = control.service;
|
|
138
|
+
const fraction = fractionOf(context.value, context);
|
|
139
|
+
control.node.style.setProperty('--ui-slider-fraction', String(fraction));
|
|
140
|
+
setAttr(control.hidden, 'value', String(context.value));
|
|
141
|
+
const text = valueText(control.template, context.value);
|
|
142
|
+
if (context.text !== text) {
|
|
143
|
+
control.assign({ text });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (state !== 'dragging') {
|
|
147
|
+
commitValue(control);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const SLIDER_KIND = Object.freeze({
|
|
152
|
+
tag: 'ui-slider',
|
|
153
|
+
childrenSlot: null,
|
|
154
|
+
attributes: { disabled: 'boolean', orientation: 'string' },
|
|
155
|
+
create(el, ctx) {
|
|
156
|
+
const doc = ctx.document;
|
|
157
|
+
const node = doc.createElement('ui-slider');
|
|
158
|
+
const labelId = partId(el.id, 'label');
|
|
159
|
+
const label = partOf(doc, 'span', 'label', { id: labelId });
|
|
160
|
+
const track = partOf(doc, 'span', 'track');
|
|
161
|
+
const indicator = partOf(doc, 'span', 'indicator', {
|
|
162
|
+
'aria-hidden': 'true',
|
|
163
|
+
});
|
|
164
|
+
const thumb = partOf(doc, 'span', 'thumb', {
|
|
165
|
+
id: partId(el.id),
|
|
166
|
+
tabindex: '0',
|
|
167
|
+
'aria-labelledby': labelId,
|
|
168
|
+
});
|
|
169
|
+
const hidden = partOf(doc, 'input', null, { type: 'hidden' });
|
|
170
|
+
track.appendChild(indicator);
|
|
171
|
+
track.appendChild(thumb);
|
|
172
|
+
node.appendChild(label);
|
|
173
|
+
node.appendChild(track);
|
|
174
|
+
node.appendChild(hidden);
|
|
175
|
+
const state = { track, pointer: null };
|
|
176
|
+
const control = startControl(node, el, ctx, {
|
|
177
|
+
kind: 'slider',
|
|
178
|
+
parts: { label, track, indicator, thumb },
|
|
179
|
+
target: thumb,
|
|
180
|
+
actions: actionsOf(state),
|
|
181
|
+
context: { ...DEFAULT_RANGE, value: DEFAULT_RANGE.min },
|
|
182
|
+
render: (c) => render(c),
|
|
183
|
+
});
|
|
184
|
+
control.hidden = hidden;
|
|
185
|
+
if (isLive(ctx)) {
|
|
186
|
+
const release = trackPointer(state, thumb);
|
|
187
|
+
const stop = control.stop;
|
|
188
|
+
control.stop = () => {
|
|
189
|
+
release();
|
|
190
|
+
stop();
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return node;
|
|
194
|
+
},
|
|
195
|
+
eventTarget: (node) => node.children[1].children[1],
|
|
196
|
+
update(node, el, changed, ctx) {
|
|
197
|
+
const has = changesOf(node, changed);
|
|
198
|
+
const control = controlOf(node);
|
|
199
|
+
const { thumb } = control.parts;
|
|
200
|
+
if (has('label')) {
|
|
201
|
+
updateLabel(control.parts.label, el, ctx);
|
|
202
|
+
}
|
|
203
|
+
if (has('name')) {
|
|
204
|
+
setAttr(control.hidden, 'name', atomOf(el, 'name'));
|
|
205
|
+
}
|
|
206
|
+
if (has('value-text')) {
|
|
207
|
+
control.template = atomOf(el, 'value-text');
|
|
208
|
+
}
|
|
209
|
+
const patch = {};
|
|
210
|
+
for (const name of ['min', 'max', 'step']) {
|
|
211
|
+
if (has(name)) {
|
|
212
|
+
patch[name] = maybeNumber(el, name) ?? DEFAULT_RANGE[name];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (has('orientation')) {
|
|
216
|
+
patch.orientation =
|
|
217
|
+
atomOf(el, 'orientation') === 'vertical' ? 'vertical' : 'horizontal';
|
|
218
|
+
}
|
|
219
|
+
if (has('disabled')) {
|
|
220
|
+
patch.disabled = flagOf(el, 'disabled');
|
|
221
|
+
setAttr(thumb, 'tabindex', patch.disabled ? '-1' : '0');
|
|
222
|
+
control.hidden.toggleAttribute('disabled', patch.disabled);
|
|
223
|
+
}
|
|
224
|
+
control.assign(patch);
|
|
225
|
+
if (Object.keys(patch).length > 0 || has('value')) {
|
|
226
|
+
const range = rangeOf(control.service.context);
|
|
227
|
+
const value = clampStep(numberOf(el, 'value', range.min), range);
|
|
228
|
+
receive(control, value, {
|
|
229
|
+
text: valueText(control.template, value),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
destroy: stopControl,
|
|
234
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stories and the control catalog.
|
|
3
|
+
*
|
|
4
|
+
* A story file (`stories/<kind>.lino`) names its component and holds one
|
|
5
|
+
* `story` per example, each an element without an ID:
|
|
6
|
+
*
|
|
7
|
+
* (button-stories: stories
|
|
8
|
+
* (component button)
|
|
9
|
+
* (story filled (button 'Save' (variant filled)))
|
|
10
|
+
* (story disabled (button 'Save' (disabled true))))
|
|
11
|
+
*
|
|
12
|
+
* Child elements of a story (radios, options) keep their IDs. The catalog
|
|
13
|
+
* (`src/controls/catalog.lino`) has one entry per control:
|
|
14
|
+
*
|
|
15
|
+
* (button: control (title 'Button') (stories button-stories) (apg button))
|
|
16
|
+
*
|
|
17
|
+
* `storiesDocument(sets)` writes every story as one document, the gallery
|
|
18
|
+
* of `e2e/pages/controls.html`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { parseNested, projectLinks } from '@link-foundation/ui-core';
|
|
22
|
+
import { Link } from 'links-notation';
|
|
23
|
+
|
|
24
|
+
/** A bootstrap kind whose properties hold any values (`*`: multi). */
|
|
25
|
+
const kindSpec = (names) => ({
|
|
26
|
+
positional: [],
|
|
27
|
+
children: 'any',
|
|
28
|
+
properties: new Map(
|
|
29
|
+
names.map((name) => {
|
|
30
|
+
const multi = name.endsWith('*');
|
|
31
|
+
return [multi ? name.slice(0, -1) : name, { type: 'any', multi }];
|
|
32
|
+
})
|
|
33
|
+
),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const BOOTSTRAP = Object.freeze({
|
|
37
|
+
version: null,
|
|
38
|
+
kinds: new Map([
|
|
39
|
+
['stories', kindSpec(['component', 'description', 'story*'])],
|
|
40
|
+
['control', kindSpec(['title', 'stories', 'apg', 'description'])],
|
|
41
|
+
]),
|
|
42
|
+
actions: new Map(),
|
|
43
|
+
multiValued: new Set(),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/** Project a LiNo file of bootstrap elements; throws on a diagnostic. */
|
|
47
|
+
function project(text, what) {
|
|
48
|
+
const { roots, diagnostics } = projectLinks(parseNested(text), BOOTSTRAP);
|
|
49
|
+
if (diagnostics.length > 0) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Invalid ${what}: ${diagnostics.map((d) => d.message).join('; ')}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return roots;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The single atom of a property, or `null`. */
|
|
58
|
+
const atomOf = (element, name) => {
|
|
59
|
+
const values = element.properties.find((p) => p.name === name)?.values;
|
|
60
|
+
return typeof values?.[0] === 'string' ? values[0] : null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Read a story file.
|
|
65
|
+
* @param {string} text
|
|
66
|
+
* @returns {{id: string, component: string,
|
|
67
|
+
* stories: {name: string, element: unknown[]}[]}}
|
|
68
|
+
*/
|
|
69
|
+
export function parseStories(text) {
|
|
70
|
+
const roots = project(text, 'stories');
|
|
71
|
+
if (roots.length !== 1 || roots[0].kind !== 'stories') {
|
|
72
|
+
throw new Error('A story file holds one `stories` element');
|
|
73
|
+
}
|
|
74
|
+
const [root] = roots;
|
|
75
|
+
const component = atomOf(root, 'component');
|
|
76
|
+
if (component === null) {
|
|
77
|
+
throw new Error(`${root.id}: no (component KIND)`);
|
|
78
|
+
}
|
|
79
|
+
const stories = root.properties
|
|
80
|
+
.filter((p) => p.name === 'story')
|
|
81
|
+
.map(({ values: [name, element] }) => {
|
|
82
|
+
if (typeof name !== 'string' || !Array.isArray(element)) {
|
|
83
|
+
throw new Error(`${root.id}: a story is (story NAME (KIND ...))`);
|
|
84
|
+
}
|
|
85
|
+
return Object.freeze({ name, element: Object.freeze(element) });
|
|
86
|
+
});
|
|
87
|
+
return Object.freeze({
|
|
88
|
+
id: root.id,
|
|
89
|
+
component,
|
|
90
|
+
stories: Object.freeze(stories),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Read the control catalog.
|
|
96
|
+
* @param {string} text
|
|
97
|
+
* @returns {Map<string, {title: string|null, stories: string|null,
|
|
98
|
+
* apg: string|null}>} the entries by kind name, in file order
|
|
99
|
+
*/
|
|
100
|
+
export function parseCatalog(text) {
|
|
101
|
+
const entries = new Map();
|
|
102
|
+
for (const element of project(text, 'catalog')) {
|
|
103
|
+
if (element.kind !== 'control') {
|
|
104
|
+
throw new Error(`${element.id}: a catalog entry is a \`control\``);
|
|
105
|
+
}
|
|
106
|
+
entries.set(
|
|
107
|
+
element.id,
|
|
108
|
+
Object.freeze({
|
|
109
|
+
title: atomOf(element, 'title'),
|
|
110
|
+
stories: atomOf(element, 'stories'),
|
|
111
|
+
apg: atomOf(element, 'apg'),
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return entries;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** One value of a story element as Links Notation. */
|
|
119
|
+
const linkOf = (value) =>
|
|
120
|
+
Array.isArray(value)
|
|
121
|
+
? new Link(null, value.map(linkOf))
|
|
122
|
+
: new Link(String(value));
|
|
123
|
+
|
|
124
|
+
const isChild = (value) =>
|
|
125
|
+
value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The lines of an element: `(ID: KIND values...)` with every child element
|
|
129
|
+
* on its own indented line. Child IDs get the `prefix` so the stories of
|
|
130
|
+
* one document never share an ID.
|
|
131
|
+
*/
|
|
132
|
+
function elementLines(id, [kind, ...values], prefix, indent) {
|
|
133
|
+
const head = values.filter((v) => !isChild(v)).map(linkOf);
|
|
134
|
+
const children = values.filter(isChild);
|
|
135
|
+
const text = new Link(id, [new Link(kind), ...head]).format();
|
|
136
|
+
if (children.length === 0) {
|
|
137
|
+
return [`${indent}${text}`];
|
|
138
|
+
}
|
|
139
|
+
return [
|
|
140
|
+
`${indent}${text.slice(0, -1)}`,
|
|
141
|
+
...children.flatMap((child, i) => {
|
|
142
|
+
const lines = elementLines(
|
|
143
|
+
`${prefix}-${child.id}`,
|
|
144
|
+
child.values,
|
|
145
|
+
prefix,
|
|
146
|
+
`${indent} `
|
|
147
|
+
);
|
|
148
|
+
return i === children.length - 1
|
|
149
|
+
? [...lines.slice(0, -1), `${lines.at(-1)})`]
|
|
150
|
+
: lines;
|
|
151
|
+
}),
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The document ID of a story: `<component>-<story>`. */
|
|
156
|
+
export const storyId = (component, name) => `${component}-${name}`;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Every story of the story sets as one document (`(ID: document ...)`),
|
|
160
|
+
* one element per story with the ID `<component>-<story>`.
|
|
161
|
+
* @param {ReturnType<typeof parseStories>[]} sets
|
|
162
|
+
* @param {{id?: string}} [options]
|
|
163
|
+
*/
|
|
164
|
+
export function storiesDocument(sets, options = {}) {
|
|
165
|
+
const lines = sets.flatMap((set) =>
|
|
166
|
+
set.stories.flatMap((story) => {
|
|
167
|
+
const id = storyId(set.component, story.name);
|
|
168
|
+
return elementLines(id, story.element, id, ' ');
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
return `(${options.id ?? 'stories'}: document\n${lines.join('\n')})`;
|
|
172
|
+
}
|