@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,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostics of the behaviour layer, in the ui-core shape
|
|
3
|
+
* `{ code, severity, message, at }`. Machines, guards and actions never
|
|
4
|
+
* throw on document content: every problem becomes a diagnostic.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const quote = (value) => JSON.stringify(String(value));
|
|
8
|
+
|
|
9
|
+
const MESSAGES = {
|
|
10
|
+
'invalid-machine': (at) =>
|
|
11
|
+
`${at.machine === undefined ? 'The source' : `Machine ${quote(at.machine)}`} is not a machine (${at.reason})`,
|
|
12
|
+
'missing-initial': (at) =>
|
|
13
|
+
`Machine ${quote(at.machine)} has no (initial <state>)`,
|
|
14
|
+
'unknown-initial': (at) =>
|
|
15
|
+
`Machine ${quote(at.machine)} starts in the unknown state ${quote(at.state)}`,
|
|
16
|
+
'duplicate-state': (at) =>
|
|
17
|
+
`Machine ${quote(at.machine)} declares the state ${quote(at.state)} more than once`,
|
|
18
|
+
'unknown-target': (at) =>
|
|
19
|
+
`Machine ${quote(at.machine)}: state ${quote(at.state)} has a transition to the unknown state ${quote(at.target)}`,
|
|
20
|
+
'invalid-transition': (at) =>
|
|
21
|
+
`Machine ${quote(at.machine)}: state ${quote(at.state)} has an (on ...) without an event name`,
|
|
22
|
+
'invalid-delay': (at) =>
|
|
23
|
+
`Machine ${quote(at.machine)}: state ${quote(at.state)} has the invalid delay ${quote(at.delay)}`,
|
|
24
|
+
'invalid-action': (at) =>
|
|
25
|
+
`Machine ${quote(at.machine)} has an action that is neither a name nor a link`,
|
|
26
|
+
'duplicate-action': (at) =>
|
|
27
|
+
`Machine ${quote(at.machine)} defines the action ${quote(at.action)} more than once`,
|
|
28
|
+
'unknown-field': (at) =>
|
|
29
|
+
`Machine ${quote(at.machine)} has the unknown field ${quote(at.field)}; it is ignored`,
|
|
30
|
+
'unknown-guard': (at) =>
|
|
31
|
+
`The guard ${quote(at.guard)} is not registered; the transition is blocked`,
|
|
32
|
+
'guard-error': (at) =>
|
|
33
|
+
`The guard ${quote(at.guard)} failed (${at.error}); the transition is blocked`,
|
|
34
|
+
'unknown-action': (at) =>
|
|
35
|
+
`The action ${quote(at.action)} is not registered; nothing is run`,
|
|
36
|
+
'action-error': (at) => `The action ${quote(at.action)} failed (${at.error})`,
|
|
37
|
+
'unsafe-url': (at) =>
|
|
38
|
+
`The action ${quote(at.action)} has an unsafe URL; it is not run`,
|
|
39
|
+
'invalid-argument': (at) =>
|
|
40
|
+
`The action ${quote(at.action)} has an invalid argument (${at.reason})`,
|
|
41
|
+
'unhandled-action': (at) =>
|
|
42
|
+
`The action ${quote(at.action)} has no host handler; nothing is run`,
|
|
43
|
+
'unknown-machine': (at) =>
|
|
44
|
+
`Element ${quote(at.element)} refers to the unknown machine ${quote(at.machine)}`,
|
|
45
|
+
'unknown-part': (at) =>
|
|
46
|
+
`Machine ${quote(at.machine)} has no element for the part ${quote(at.part)}`,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} code
|
|
51
|
+
* @param {'error'|'warning'|'info'} severity
|
|
52
|
+
* @param {Record<string, unknown>} [at]
|
|
53
|
+
*/
|
|
54
|
+
export function diagnostic(code, severity, at = {}) {
|
|
55
|
+
const message = MESSAGES[code]?.(at) ?? code;
|
|
56
|
+
return Object.freeze({ code, severity, message, at: Object.freeze(at) });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether a URL uses a scheme that runs code (`javascript:`, `vbscript:`)
|
|
61
|
+
* or embeds content (`data:`). Spaces and control characters are ignored,
|
|
62
|
+
* as browsers ignore them when they read a URL.
|
|
63
|
+
* @param {unknown} url
|
|
64
|
+
*/
|
|
65
|
+
export function isUnsafeUrl(url) {
|
|
66
|
+
const visible = [...String(url ?? '')]
|
|
67
|
+
.filter((c) => c.codePointAt(0) > 0x20)
|
|
68
|
+
.join('')
|
|
69
|
+
.toLowerCase();
|
|
70
|
+
return ['javascript:', 'data:', 'vbscript:'].some((scheme) =>
|
|
71
|
+
visible.startsWith(scheme)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Store } from '@link-foundation/ui-store';
|
|
2
|
+
import type { mountDocument, render } from '@link-foundation/ui-dom';
|
|
3
|
+
import type {
|
|
4
|
+
ActionFn,
|
|
5
|
+
ActionRegistry,
|
|
6
|
+
Clock,
|
|
7
|
+
Diagnostic,
|
|
8
|
+
Guard,
|
|
9
|
+
HostActions,
|
|
10
|
+
Machine,
|
|
11
|
+
Service,
|
|
12
|
+
} from '@link-foundation/ui-components/behavior';
|
|
13
|
+
|
|
14
|
+
export interface BehaviorOptions {
|
|
15
|
+
actions?: ActionRegistry | Record<string, ActionFn>;
|
|
16
|
+
host?: HostActions;
|
|
17
|
+
machines?: Record<string, Machine | string>;
|
|
18
|
+
referenceMachines?: boolean;
|
|
19
|
+
guards?: Record<string, Guard>;
|
|
20
|
+
clock?: Clock;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BehaviorHandle {
|
|
24
|
+
store: Store;
|
|
25
|
+
handle: ReturnType<typeof render>;
|
|
26
|
+
registry: ActionRegistry;
|
|
27
|
+
diagnostics: Diagnostic[];
|
|
28
|
+
serviceFor(id: string): Service | null;
|
|
29
|
+
destroy(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const BEHAVIOR_CSS: string;
|
|
33
|
+
|
|
34
|
+
export function mountBehavior(
|
|
35
|
+
container: Element,
|
|
36
|
+
text: string,
|
|
37
|
+
options?: BehaviorOptions & NonNullable<Parameters<typeof mountDocument>[2]>
|
|
38
|
+
): BehaviorHandle;
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@link-foundation/ui-components/behavior/dom`: behaviour on top of the
|
|
3
|
+
* ui-dom renderer. `mountBehavior(container, text, options)` mounts a
|
|
4
|
+
* document like ui-dom `mountDocument` and
|
|
5
|
+
*
|
|
6
|
+
* - routes every `ui-action` (an `(on EVENT ACTION...)` handler) through
|
|
7
|
+
* the actions registry, so an action name only ever selects a registered
|
|
8
|
+
* function;
|
|
9
|
+
* - starts a machine service for each element with
|
|
10
|
+
* `(machine NAME (PART ELEMENT-ID)...)` when the element is mounted, binds
|
|
11
|
+
* it to the element with `bindMachine`, and stops it when the element is
|
|
12
|
+
* removed or the document is destroyed.
|
|
13
|
+
*
|
|
14
|
+
* Machines come from `options.machines`, from `machine` elements of the
|
|
15
|
+
* document, and from the reference machines (`toggle-machine`,
|
|
16
|
+
* `disclosure-machine`).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { getKind, mountDocument, defineKind } from '@link-foundation/ui-dom';
|
|
20
|
+
import { bindMachine } from '../a11y/bind-machine.js';
|
|
21
|
+
import { checkHandler, createActionRegistry } from './actions.js';
|
|
22
|
+
import { diagnostic } from './diagnostics.js';
|
|
23
|
+
import { interpret } from './interpret.js';
|
|
24
|
+
import { REFERENCE_MACHINES } from './machines/index.js';
|
|
25
|
+
import { createMachine, parseMachines, toValue } from './parse-machine.js';
|
|
26
|
+
|
|
27
|
+
/** A `machine` element is a definition: it renders as a hidden node. */
|
|
28
|
+
defineKind('machine', {
|
|
29
|
+
tag: 'ui-machine',
|
|
30
|
+
childrenSlot: null,
|
|
31
|
+
create(el, ctx) {
|
|
32
|
+
const node = ctx.document.createElement('ui-machine');
|
|
33
|
+
node.hidden = true;
|
|
34
|
+
return node;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The rules behaviour needs on top of the ui-dom base CSS: a hidden part
|
|
40
|
+
* is hidden even when its kind sets `display`.
|
|
41
|
+
*/
|
|
42
|
+
export const BEHAVIOR_CSS = `ui-machine { display: none; }
|
|
43
|
+
[data-part][hidden] { display: none !important; }
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
/** Every element view of a store, depth first. */
|
|
47
|
+
function* viewsOf(store) {
|
|
48
|
+
const stack = [...store.roots()].reverse();
|
|
49
|
+
while (stack.length > 0) {
|
|
50
|
+
const id = stack.pop();
|
|
51
|
+
const view = store.get(id);
|
|
52
|
+
if (view !== undefined) {
|
|
53
|
+
yield view;
|
|
54
|
+
stack.push(...[...store.children(id)].reverse());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The values of the last property `name` of a view, or `undefined`. */
|
|
60
|
+
const propOf = (view, name) =>
|
|
61
|
+
view.properties.findLast((p) => p.name === name)?.values;
|
|
62
|
+
|
|
63
|
+
/** The single atom value of a property, or `undefined`. */
|
|
64
|
+
const atomOf = (view, name) => {
|
|
65
|
+
const values = propOf(view, name);
|
|
66
|
+
return values?.length === 1 && typeof values[0] === 'string'
|
|
67
|
+
? values[0]
|
|
68
|
+
: undefined;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** Machines of the `machines` option: machine objects or LiNo text. */
|
|
72
|
+
function machinesOption(machines, report) {
|
|
73
|
+
const map = new Map();
|
|
74
|
+
for (const [name, value] of Object.entries(machines ?? {})) {
|
|
75
|
+
if (typeof value === 'string') {
|
|
76
|
+
const read = parseMachines(value);
|
|
77
|
+
read.diagnostics.forEach(report);
|
|
78
|
+
const [machine] = read.machines.values();
|
|
79
|
+
if (machine) {
|
|
80
|
+
map.set(name, machine);
|
|
81
|
+
}
|
|
82
|
+
} else if (value && typeof value === 'object') {
|
|
83
|
+
map.set(name, value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return map;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The machine reference of an element: `(machine NAME (PART ID)...)`.
|
|
91
|
+
* @returns {{name: string, parts: Record<string, string>, key: string}|null}
|
|
92
|
+
*/
|
|
93
|
+
function machineRef(view) {
|
|
94
|
+
const values = propOf(view, 'machine');
|
|
95
|
+
if (!values || typeof values[0] !== 'string') {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const parts = {};
|
|
99
|
+
for (const link of values.slice(1)) {
|
|
100
|
+
if (
|
|
101
|
+
Array.isArray(link) &&
|
|
102
|
+
typeof link[0] === 'string' &&
|
|
103
|
+
typeof link[1] === 'string'
|
|
104
|
+
) {
|
|
105
|
+
parts[link[0]] = link[1];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { name: values[0], parts, key: JSON.stringify(values) };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Host functions for the vocabulary actions, on the store and the nodes.
|
|
113
|
+
* `navigate` has no default: the host decides what navigation means.
|
|
114
|
+
*/
|
|
115
|
+
function storeHost(state, container) {
|
|
116
|
+
const requireElement = (target) => {
|
|
117
|
+
if (!state.store.has(target)) {
|
|
118
|
+
throw new Error(`no element ${JSON.stringify(target)}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
set(target, property, value) {
|
|
123
|
+
requireElement(target);
|
|
124
|
+
state.store.setProp(target, property, [String(value)]);
|
|
125
|
+
},
|
|
126
|
+
toggle(target, property) {
|
|
127
|
+
requireElement(target);
|
|
128
|
+
const current = atomOf(state.store.get(target), property);
|
|
129
|
+
state.store.setProp(target, property, [String(current !== 'true')]);
|
|
130
|
+
},
|
|
131
|
+
focus(target) {
|
|
132
|
+
requireElement(target);
|
|
133
|
+
const node = state.partNode(target);
|
|
134
|
+
node?.focus();
|
|
135
|
+
return node !== null;
|
|
136
|
+
},
|
|
137
|
+
emit(event, args, meta) {
|
|
138
|
+
const win = container.ownerDocument.defaultView;
|
|
139
|
+
container.dispatchEvent(
|
|
140
|
+
new win.CustomEvent('ui-emit', {
|
|
141
|
+
bubbles: true,
|
|
142
|
+
composed: true,
|
|
143
|
+
detail: Object.freeze({ event, args, source: meta.source ?? null }),
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @typedef {object} BehaviorOptions
|
|
152
|
+
* @property {import('./actions.js').ActionRegistry |
|
|
153
|
+
* Record<string, import('./actions.js').ActionFn>} [actions] a
|
|
154
|
+
* registry, or actions to add to the default one
|
|
155
|
+
* @property {import('./actions.js').HostActions} [host] host functions
|
|
156
|
+
* for the vocabulary actions (`navigate` has no default)
|
|
157
|
+
* @property {Record<string, import('./parse-machine.js').Machine | string>}
|
|
158
|
+
* [machines] machines by name, before the document and the reference
|
|
159
|
+
* machines
|
|
160
|
+
* @property {boolean} [referenceMachines] `false` leaves out the
|
|
161
|
+
* reference machines
|
|
162
|
+
* @property {Record<string, import('./interpret.js').Guard>} [guards]
|
|
163
|
+
* @property {import('./interpret.js').Clock} [clock]
|
|
164
|
+
*
|
|
165
|
+
* @typedef {object} BehaviorHandle
|
|
166
|
+
* @property {import('@link-foundation/ui-store').Store} store
|
|
167
|
+
* @property {ReturnType<typeof import('@link-foundation/ui-dom').render>} handle
|
|
168
|
+
* @property {import('./actions.js').ActionRegistry} registry
|
|
169
|
+
* @property {object[]} diagnostics
|
|
170
|
+
* @property {(id: string) => import('./interpret.js').Service | null}
|
|
171
|
+
* serviceFor the running service of an element
|
|
172
|
+
* @property {() => void} destroy stop every service and remove the
|
|
173
|
+
* document
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/** The registry of the options: a registry, or the default one plus actions. */
|
|
177
|
+
function registryOf(options, host, report) {
|
|
178
|
+
if (options.actions && typeof options.actions.dispatch === 'function') {
|
|
179
|
+
return options.actions;
|
|
180
|
+
}
|
|
181
|
+
const registry = createActionRegistry({
|
|
182
|
+
host: { ...host, ...options.host },
|
|
183
|
+
onDiagnostic: report,
|
|
184
|
+
});
|
|
185
|
+
for (const [name, fn] of Object.entries(options.actions ?? {})) {
|
|
186
|
+
registry.register(name, fn);
|
|
187
|
+
}
|
|
188
|
+
return registry;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The machines of `machine` elements in the store, by name and store ID. */
|
|
192
|
+
function documentMachines(store, reportOnce) {
|
|
193
|
+
const map = new Map();
|
|
194
|
+
for (const view of viewsOf(store)) {
|
|
195
|
+
if (view.kind === 'machine') {
|
|
196
|
+
const read = parseMachines({ ...view, children: [] });
|
|
197
|
+
read.diagnostics.forEach((d) =>
|
|
198
|
+
reportOnce(`${view.id}:${d.code}:${JSON.stringify(d.at)}`, d)
|
|
199
|
+
);
|
|
200
|
+
const [machine] = read.machines.values();
|
|
201
|
+
map.set(view.name ?? view.id, machine);
|
|
202
|
+
map.set(view.id, machine);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return map;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Find machines by name: the `machines` option, then the document, then
|
|
210
|
+
* the reference machines (read once).
|
|
211
|
+
*/
|
|
212
|
+
function machineFinder(options, report) {
|
|
213
|
+
const known = machinesOption(options.machines, report);
|
|
214
|
+
return (name, local) => {
|
|
215
|
+
if (known.has(name)) {
|
|
216
|
+
return known.get(name);
|
|
217
|
+
}
|
|
218
|
+
if (local.has(name)) {
|
|
219
|
+
return local.get(name);
|
|
220
|
+
}
|
|
221
|
+
if (
|
|
222
|
+
options.referenceMachines !== false &&
|
|
223
|
+
Object.hasOwn(REFERENCE_MACHINES, name)
|
|
224
|
+
) {
|
|
225
|
+
known.set(name, createMachine(REFERENCE_MACHINES[name]));
|
|
226
|
+
return known.get(name);
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The initial context: machine context fields the element sets. */
|
|
233
|
+
function contextOf(view, machine) {
|
|
234
|
+
const context = {};
|
|
235
|
+
for (const name of Object.keys(machine.context)) {
|
|
236
|
+
const value = atomOf(view, name);
|
|
237
|
+
if (value !== undefined) {
|
|
238
|
+
context[name] = toValue(value);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return context;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Report handler actions that are text, not links, such as
|
|
246
|
+
* `(on press 'alert(1)')`, as `unknown-action`: ui-dom drops them as
|
|
247
|
+
* `invalid-handler`, and none ever runs. (ui-dom itself reports links
|
|
248
|
+
* whose name `registry.has` does not know.)
|
|
249
|
+
*/
|
|
250
|
+
function checkHandlers(store, registry, reportOnce) {
|
|
251
|
+
for (const view of viewsOf(store)) {
|
|
252
|
+
for (const property of view.properties) {
|
|
253
|
+
if (property.name === 'on') {
|
|
254
|
+
const at = { element: view.name ?? view.id };
|
|
255
|
+
const [event, ...actions] = property.values;
|
|
256
|
+
const texts = actions.filter((action) => !Array.isArray(action));
|
|
257
|
+
checkHandler(registry, [event, ...texts], at).forEach((d) =>
|
|
258
|
+
reportOnce(`${view.id}:${JSON.stringify(d.at)}`, d)
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The services of the machine elements of a store: `sync()` starts,
|
|
267
|
+
* updates and stops them to match the store.
|
|
268
|
+
*/
|
|
269
|
+
function createServices(state, options, registry, report, reportOnce) {
|
|
270
|
+
const findMachine = machineFinder(options, report);
|
|
271
|
+
/** @type {Map<string, {key: string, machine: object, service: object, unbind: () => void}>} */
|
|
272
|
+
const services = new Map();
|
|
273
|
+
|
|
274
|
+
const stop = (id) => {
|
|
275
|
+
const entry = services.get(id);
|
|
276
|
+
if (entry) {
|
|
277
|
+
entry.unbind();
|
|
278
|
+
entry.service.stop();
|
|
279
|
+
services.delete(id);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const start = (view, ref, machine) => {
|
|
284
|
+
const service = interpret(machine, {
|
|
285
|
+
actions: registry,
|
|
286
|
+
guards: options.guards,
|
|
287
|
+
clock: options.clock,
|
|
288
|
+
context: contextOf(view, machine),
|
|
289
|
+
onDiagnostic: report,
|
|
290
|
+
});
|
|
291
|
+
const element = state.partNode(view.id);
|
|
292
|
+
const parts = (part) =>
|
|
293
|
+
Object.hasOwn(ref.parts, part)
|
|
294
|
+
? state.partNode(ref.parts[part])
|
|
295
|
+
: element;
|
|
296
|
+
const unbind = bindMachine(element, service, parts, {
|
|
297
|
+
onDiagnostic: report,
|
|
298
|
+
});
|
|
299
|
+
services.set(view.id, { key: ref.key, machine, service, unbind });
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/** Pass changed element properties that the context has to the service. */
|
|
303
|
+
const update = (view, machine) => {
|
|
304
|
+
const { service } = services.get(view.id);
|
|
305
|
+
const context = contextOf(view, machine);
|
|
306
|
+
if (Object.entries(context).some(([k, v]) => service.context[k] !== v)) {
|
|
307
|
+
service.assign(context);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const syncOne = (view, ref, local) => {
|
|
312
|
+
const machine = findMachine(ref.name, local);
|
|
313
|
+
const entry = services.get(view.id);
|
|
314
|
+
if (entry && (entry.key !== ref.key || entry.machine !== machine)) {
|
|
315
|
+
stop(view.id);
|
|
316
|
+
}
|
|
317
|
+
if (machine === null) {
|
|
318
|
+
reportOnce(
|
|
319
|
+
`${view.id}:unknown-machine:${ref.name}`,
|
|
320
|
+
diagnostic('unknown-machine', 'error', {
|
|
321
|
+
element: view.name ?? view.id,
|
|
322
|
+
machine: ref.name,
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
} else if (services.has(view.id)) {
|
|
326
|
+
update(view, machine);
|
|
327
|
+
} else {
|
|
328
|
+
start(view, ref, machine);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
get: (id) => services.get(id)?.service ?? null,
|
|
334
|
+
sync() {
|
|
335
|
+
const seen = new Set();
|
|
336
|
+
let local = null;
|
|
337
|
+
for (const view of viewsOf(state.store)) {
|
|
338
|
+
const ref = machineRef(view);
|
|
339
|
+
if (ref !== null) {
|
|
340
|
+
seen.add(view.id);
|
|
341
|
+
local ??= documentMachines(state.store, reportOnce);
|
|
342
|
+
syncOne(view, ref, local);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
[...services.keys()].filter((id) => !seen.has(id)).forEach(stop);
|
|
346
|
+
},
|
|
347
|
+
stopAll: () => [...services.keys()].forEach(stop),
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Mount a document with behaviour.
|
|
353
|
+
* @param {Element} container
|
|
354
|
+
* @param {string} text
|
|
355
|
+
* @param {BehaviorOptions & Parameters<typeof mountDocument>[2]} [options]
|
|
356
|
+
* every ui-dom `mountDocument` option, plus the behaviour options
|
|
357
|
+
* @returns {BehaviorHandle}
|
|
358
|
+
*/
|
|
359
|
+
export function mountBehavior(container, text, options = {}) {
|
|
360
|
+
const diagnostics = [];
|
|
361
|
+
const report = (d) => {
|
|
362
|
+
diagnostics.push(d);
|
|
363
|
+
options.onDiagnostic?.(d);
|
|
364
|
+
};
|
|
365
|
+
const reported = new Set();
|
|
366
|
+
const reportOnce = (key, d) => {
|
|
367
|
+
if (!reported.has(key)) {
|
|
368
|
+
reported.add(key);
|
|
369
|
+
report(d);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
const state = { store: null, handle: null };
|
|
373
|
+
/** The node a part binds to: the kind's event target (the `<button>`). */
|
|
374
|
+
state.partNode = (id) => {
|
|
375
|
+
const node = state.handle?.nodeFor(id) ?? null;
|
|
376
|
+
const view = state.store?.get(id);
|
|
377
|
+
if (node === null || view === undefined) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
return getKind(view.kind, options.kinds)?.eventTarget?.(node) ?? node;
|
|
381
|
+
};
|
|
382
|
+
const registry = registryOf(options, storeHost(state, container), report);
|
|
383
|
+
const services = createServices(state, options, registry, report, reportOnce);
|
|
384
|
+
|
|
385
|
+
const mounted = mountDocument(container, text, {
|
|
386
|
+
...options,
|
|
387
|
+
css: `${BEHAVIOR_CSS}${options.css ?? ''}`,
|
|
388
|
+
onDiagnostic: report,
|
|
389
|
+
isAction: (name) => registry.has(name),
|
|
390
|
+
onAction(detail, event) {
|
|
391
|
+
const [name, ...args] = detail.action;
|
|
392
|
+
registry.dispatch(name, args, {
|
|
393
|
+
source: detail.source,
|
|
394
|
+
event: detail.event,
|
|
395
|
+
});
|
|
396
|
+
options.onAction?.(detail, event);
|
|
397
|
+
},
|
|
398
|
+
onPatch(events) {
|
|
399
|
+
services.sync();
|
|
400
|
+
checkHandlers(state.store, registry, reportOnce);
|
|
401
|
+
options.onPatch?.(events);
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
state.store = mounted.store;
|
|
405
|
+
state.handle = mounted.handle;
|
|
406
|
+
checkHandlers(state.store, registry, reportOnce);
|
|
407
|
+
services.sync();
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
store: mounted.store,
|
|
411
|
+
handle: mounted.handle,
|
|
412
|
+
registry,
|
|
413
|
+
diagnostics,
|
|
414
|
+
serviceFor: services.get,
|
|
415
|
+
destroy() {
|
|
416
|
+
services.stopAll();
|
|
417
|
+
mounted.handle.destroy();
|
|
418
|
+
},
|
|
419
|
+
};
|
|
420
|
+
}
|