@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,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `split`: two or more panes with draggable dividers, after the WAI-ARIA
|
|
3
|
+
* APG window splitter pattern.
|
|
4
|
+
*
|
|
5
|
+
* chat: split
|
|
6
|
+
* direction row
|
|
7
|
+
* sizes 30 70
|
|
8
|
+
* min 20 40
|
|
9
|
+
* collapsible true false
|
|
10
|
+
* remember-size chat.split
|
|
11
|
+
* chat-list: stack
|
|
12
|
+
* ...
|
|
13
|
+
* chat-view: stack
|
|
14
|
+
* ...
|
|
15
|
+
*
|
|
16
|
+
* Each divider is a focusable `role="separator"` whose `aria-valuenow` is
|
|
17
|
+
* the size of the pane before it, in percent. The arrow keys move it by
|
|
18
|
+
* 1 (10 with Shift), Home gives the pane its smallest size (it collapses
|
|
19
|
+
* when it is collapsible), End its largest, and Enter collapses the pane
|
|
20
|
+
* or restores it. A pointer drag moves it too (`setPointerCapture`).
|
|
21
|
+
*
|
|
22
|
+
* `sizes`, `min` and `max` are percentages, one value for every pane or one
|
|
23
|
+
* per pane; `collapsible` likewise; `collapsed` names the panes that start
|
|
24
|
+
* collapsed. With `remember-size KEY`, the sizes are kept as
|
|
25
|
+
* `sizes 30 70` under KEY in the storage of the render options
|
|
26
|
+
* (`options.layout.storage`, an object with `getItem` and `setItem`, such
|
|
27
|
+
* as `localStorage`) and read back on the next render. Every change sends a
|
|
28
|
+
* `split-resize` event with `detail.sizes`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
32
|
+
import { formatLinks, parseNested } from '@link-foundation/ui-core';
|
|
33
|
+
import { bindKeys } from '../a11y/keys.js';
|
|
34
|
+
import {
|
|
35
|
+
atomOf,
|
|
36
|
+
controllerOf,
|
|
37
|
+
dropController,
|
|
38
|
+
emit,
|
|
39
|
+
findController,
|
|
40
|
+
idOf,
|
|
41
|
+
isLive,
|
|
42
|
+
labelGroup,
|
|
43
|
+
linkId,
|
|
44
|
+
listOf,
|
|
45
|
+
make,
|
|
46
|
+
readStored,
|
|
47
|
+
renderedChildren,
|
|
48
|
+
storageOf,
|
|
49
|
+
titleOf,
|
|
50
|
+
valuesOf,
|
|
51
|
+
watchChildren,
|
|
52
|
+
writeStored,
|
|
53
|
+
} from './dom.js';
|
|
54
|
+
import {
|
|
55
|
+
collapsePane,
|
|
56
|
+
normalizeSizes,
|
|
57
|
+
paneLimits,
|
|
58
|
+
resizeSplit,
|
|
59
|
+
restorePane,
|
|
60
|
+
} from './split-model.js';
|
|
61
|
+
|
|
62
|
+
const TOTAL = 100;
|
|
63
|
+
const STEP = 1;
|
|
64
|
+
const BIG_STEP = 10;
|
|
65
|
+
|
|
66
|
+
/** `row` (side by side, the default) or `column` (one above the other). */
|
|
67
|
+
const axisOf = (el) =>
|
|
68
|
+
['column', 'vertical'].includes(atomOf(el, 'direction')) ? 'column' : 'row';
|
|
69
|
+
|
|
70
|
+
/** The limits of the split model from the element. */
|
|
71
|
+
function limitsOf(el) {
|
|
72
|
+
const number = (v) => (Number.isFinite(Number(v)) ? Number(v) : undefined);
|
|
73
|
+
return {
|
|
74
|
+
min: listOf(el, 'min', number),
|
|
75
|
+
max: listOf(el, 'max', number),
|
|
76
|
+
collapsible: listOf(el, 'collapsible', (v) => v === 'true'),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The `sizes ...` text of remembered sizes: one link written without the
|
|
82
|
+
* parentheses it does not need (#133).
|
|
83
|
+
*/
|
|
84
|
+
export function sizesToLino(sizes) {
|
|
85
|
+
const values = sizes.map((s) => String(Math.round(s * 100) / 100));
|
|
86
|
+
return formatLinks([['sizes', ...values]]).trimEnd();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The sizes of a `sizes ...` text (also `(sizes ...)`, as written before
|
|
91
|
+
* #133); `null` when it is not one.
|
|
92
|
+
*/
|
|
93
|
+
export function sizesFromLino(text) {
|
|
94
|
+
if (typeof text !== 'string' || text === '') {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
let links;
|
|
98
|
+
try {
|
|
99
|
+
links = parseNested(text);
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const values = links[0]?.values ?? [];
|
|
104
|
+
if (values[0]?.id !== 'sizes') {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const sizes = values.slice(1).map((v) => Number(v.id));
|
|
108
|
+
return sizes.length > 0 && sizes.every(Number.isFinite) ? sizes : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The panes in the order of `(children ...)`, else in document order. */
|
|
112
|
+
function panesOf(node, el) {
|
|
113
|
+
const panes = renderedChildren(node);
|
|
114
|
+
const order = valuesOf(el, 'children');
|
|
115
|
+
if (order.length === 0) {
|
|
116
|
+
return panes;
|
|
117
|
+
}
|
|
118
|
+
const rank = (pane) => {
|
|
119
|
+
const i = order.indexOf(linkId(pane));
|
|
120
|
+
return i < 0 ? order.length : i;
|
|
121
|
+
};
|
|
122
|
+
return [...panes].sort((a, b) => rank(a) - rank(b));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The CSS track list of the panes and dividers. */
|
|
126
|
+
function templateOf(sizes) {
|
|
127
|
+
return sizes
|
|
128
|
+
.map((size) => `minmax(0, ${size}fr)`)
|
|
129
|
+
.join(' var(--ui-split-divider-size, 8px) ');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The first sizes: remembered, else `sizes`, else equal; then collapsed. */
|
|
133
|
+
function initialSizes(state, count) {
|
|
134
|
+
const remembered = sizesFromLino(readStored(state.storage, state.key));
|
|
135
|
+
const given = valuesOf(state.el, 'sizes').map(Number);
|
|
136
|
+
let sizes = normalizeSizes(
|
|
137
|
+
remembered?.length === count ? remembered : given,
|
|
138
|
+
count,
|
|
139
|
+
TOTAL
|
|
140
|
+
);
|
|
141
|
+
if (remembered?.length !== count) {
|
|
142
|
+
const collapsed = valuesOf(state.el, 'collapsed');
|
|
143
|
+
state.panes.forEach((pane, i) => {
|
|
144
|
+
if (collapsed.includes(linkId(pane)) || collapsed.includes(String(i))) {
|
|
145
|
+
state.open[i] = sizes[i];
|
|
146
|
+
sizes = collapsePane(sizes, i, state.limits);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return sizes;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Write the sizes to the grid, the panes and the dividers. */
|
|
154
|
+
function apply(node, state) {
|
|
155
|
+
const { sizes, panes, dividers, limits } = state;
|
|
156
|
+
// A row split puts its panes side by side: they are the grid columns.
|
|
157
|
+
const tracks = state.axis === 'row' ? 'column' : 'row';
|
|
158
|
+
const cross = state.axis === 'row' ? 'row' : 'column';
|
|
159
|
+
node.style.setProperty(`grid-template-${tracks}s`, templateOf(sizes));
|
|
160
|
+
node.style.setProperty(`grid-template-${cross}s`, 'minmax(0, 1fr)');
|
|
161
|
+
node.setAttribute('data-direction', state.axis);
|
|
162
|
+
panes.forEach((pane, i) => {
|
|
163
|
+
pane.style.setProperty(`grid-${tracks}`, String(2 * i + 1));
|
|
164
|
+
pane.style.setProperty(`grid-${cross}`, '1');
|
|
165
|
+
pane.toggleAttribute('data-collapsed', sizes[i] === 0);
|
|
166
|
+
pane.toggleAttribute('hidden', sizes[i] === 0);
|
|
167
|
+
});
|
|
168
|
+
dividers.forEach((divider, i) => {
|
|
169
|
+
// The range of the divider: as far as the limits of both panes allow.
|
|
170
|
+
const low = resizeSplit(sizes, i, -TOTAL, limits)[i];
|
|
171
|
+
const high = resizeSplit(sizes, i, TOTAL, limits)[i];
|
|
172
|
+
divider.style.setProperty(`grid-${tracks}`, String(2 * i + 2));
|
|
173
|
+
divider.style.setProperty(`grid-${cross}`, '1');
|
|
174
|
+
divider.setAttribute(
|
|
175
|
+
'aria-orientation',
|
|
176
|
+
state.axis === 'row' ? 'vertical' : 'horizontal'
|
|
177
|
+
);
|
|
178
|
+
divider.setAttribute('aria-valuenow', String(Math.round(sizes[i])));
|
|
179
|
+
divider.setAttribute('aria-valuemin', String(Math.round(low)));
|
|
180
|
+
divider.setAttribute('aria-valuemax', String(Math.round(high)));
|
|
181
|
+
divider.setAttribute('aria-controls', idOf(panes[i], 'ui-split-pane'));
|
|
182
|
+
divider.setAttribute('aria-label', `Resize ${titleOf(panes[i])}`);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Set the sizes; `persist` saves them under the `remember-size` key. */
|
|
187
|
+
function setSizes(split, next, persist = true) {
|
|
188
|
+
const { state, node } = split;
|
|
189
|
+
if (next.every((s, i) => s === state.sizes[i])) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
next.forEach((size, i) => {
|
|
193
|
+
if (state.sizes[i] > 0 && size === 0) {
|
|
194
|
+
state.open[i] = state.sizes[i];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
state.sizes = next;
|
|
198
|
+
apply(node, state);
|
|
199
|
+
if (persist) {
|
|
200
|
+
remember(state);
|
|
201
|
+
}
|
|
202
|
+
emit(node, 'split-resize', { sizes: [...next] });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function remember(state) {
|
|
206
|
+
if (state.key !== undefined) {
|
|
207
|
+
writeStored(state.storage, state.key, sizesToLino(state.sizes));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Collapse pane `i`, or restore it when it is collapsed. */
|
|
212
|
+
function toggle(split, i) {
|
|
213
|
+
const { sizes, limits, open } = split.state;
|
|
214
|
+
if (sizes[i] === 0) {
|
|
215
|
+
const size = open[i] ?? paneLimits(sizes, i, limits).min;
|
|
216
|
+
setSizes(split, restorePane(sizes, i, size, limits));
|
|
217
|
+
} else if (paneLimits(sizes, i, limits).collapsible) {
|
|
218
|
+
setSizes(split, collapsePane(sizes, i, limits));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Move divider `i` by `delta` percent. */
|
|
223
|
+
function moveBy(split, i, delta) {
|
|
224
|
+
const { sizes, limits } = split.state;
|
|
225
|
+
setSizes(split, resizeSplit(sizes, i, delta, limits));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Give pane `i` its smallest size; a collapsible pane collapses. */
|
|
229
|
+
function shrink(split, i) {
|
|
230
|
+
const { sizes, limits } = split.state;
|
|
231
|
+
const own = paneLimits(sizes, i, limits);
|
|
232
|
+
setSizes(
|
|
233
|
+
split,
|
|
234
|
+
own.collapsible
|
|
235
|
+
? collapsePane(sizes, i, limits)
|
|
236
|
+
: resizeSplit(sizes, i, own.min - sizes[i], limits)
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The keys of a divider (WAI-ARIA window splitter); `index()` is its index. */
|
|
241
|
+
function dividerKeys(split, index) {
|
|
242
|
+
const keys = {
|
|
243
|
+
Home: () => shrink(split, index()),
|
|
244
|
+
End: () => moveBy(split, index(), TOTAL),
|
|
245
|
+
Enter: () => toggle(split, index()),
|
|
246
|
+
};
|
|
247
|
+
for (const [key, sign] of [
|
|
248
|
+
['ArrowLeft', -1],
|
|
249
|
+
['ArrowUp', -1],
|
|
250
|
+
['ArrowRight', 1],
|
|
251
|
+
['ArrowDown', 1],
|
|
252
|
+
]) {
|
|
253
|
+
keys[key] = () => moveBy(split, index(), sign * STEP);
|
|
254
|
+
keys[`Shift+${key}`] = () => moveBy(split, index(), sign * BIG_STEP);
|
|
255
|
+
}
|
|
256
|
+
return keys;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function onPointerDown(split, event, i) {
|
|
260
|
+
const { state, node } = split;
|
|
261
|
+
if (event.button !== 0 || state.sizes.length < 2) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const row = state.axis === 'row';
|
|
265
|
+
const divider = state.dividers[i];
|
|
266
|
+
divider.setPointerCapture?.(event.pointerId);
|
|
267
|
+
const box = node.getBoundingClientRect();
|
|
268
|
+
const dividers = state.dividers.reduce(
|
|
269
|
+
(total, d) => total + d.getBoundingClientRect()[row ? 'width' : 'height'],
|
|
270
|
+
0
|
|
271
|
+
);
|
|
272
|
+
state.drag = {
|
|
273
|
+
index: i,
|
|
274
|
+
pointer: event.pointerId,
|
|
275
|
+
from: row ? event.clientX : event.clientY,
|
|
276
|
+
sizes: [...state.sizes],
|
|
277
|
+
length: Math.max(1, (row ? box.width : box.height) - dividers),
|
|
278
|
+
};
|
|
279
|
+
divider.focus();
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The drag of the pointer of `event`, else `null`. */
|
|
284
|
+
const dragOf = (state, event) =>
|
|
285
|
+
state.drag?.pointer === event.pointerId ? state.drag : null;
|
|
286
|
+
|
|
287
|
+
function onPointerMove(split, event) {
|
|
288
|
+
const { state } = split;
|
|
289
|
+
const drag = dragOf(state, event);
|
|
290
|
+
if (drag === null) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const at = state.axis === 'row' ? event.clientX : event.clientY;
|
|
294
|
+
const delta = ((at - drag.from) / drag.length) * TOTAL;
|
|
295
|
+
setSizes(
|
|
296
|
+
split,
|
|
297
|
+
resizeSplit(drag.sizes, drag.index, delta, state.limits),
|
|
298
|
+
false
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function onPointerUp(split, event) {
|
|
303
|
+
const { state } = split;
|
|
304
|
+
const drag = dragOf(state, event);
|
|
305
|
+
if (drag === null) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
state.dividers[drag.index].releasePointerCapture?.(event.pointerId);
|
|
309
|
+
state.drag = null;
|
|
310
|
+
remember(state);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function makeDivider(split) {
|
|
314
|
+
const divider = make(split.document, 'div', {
|
|
315
|
+
class: 'ui-split-divider',
|
|
316
|
+
role: 'separator',
|
|
317
|
+
tabindex: '0',
|
|
318
|
+
});
|
|
319
|
+
const index = () => split.state.dividers.indexOf(divider);
|
|
320
|
+
const up = (e) => onPointerUp(split, e);
|
|
321
|
+
bindKeys(divider, dividerKeys(split, index));
|
|
322
|
+
divider.addEventListener('pointerdown', (e) =>
|
|
323
|
+
onPointerDown(split, e, index())
|
|
324
|
+
);
|
|
325
|
+
divider.addEventListener('pointermove', (e) => onPointerMove(split, e));
|
|
326
|
+
divider.addEventListener('pointerup', up);
|
|
327
|
+
divider.addEventListener('pointercancel', up);
|
|
328
|
+
divider.addEventListener('dblclick', () => toggle(split, index()));
|
|
329
|
+
return divider;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Read the panes again: one divider between two, sizes when they change. */
|
|
333
|
+
function refresh(split) {
|
|
334
|
+
const { state, node } = split;
|
|
335
|
+
const panes = panesOf(node, state.el);
|
|
336
|
+
const count = panes.length;
|
|
337
|
+
const changed =
|
|
338
|
+
count !== state.panes.length || panes.some((p, i) => p !== state.panes[i]);
|
|
339
|
+
state.panes = panes;
|
|
340
|
+
while (state.dividers.length < Math.max(0, count - 1)) {
|
|
341
|
+
state.dividers.push(makeDivider(split));
|
|
342
|
+
}
|
|
343
|
+
while (state.dividers.length > Math.max(0, count - 1)) {
|
|
344
|
+
state.dividers.pop().remove();
|
|
345
|
+
}
|
|
346
|
+
panes.forEach((pane, i) => {
|
|
347
|
+
if (i < state.dividers.length) {
|
|
348
|
+
node.insertBefore(state.dividers[i], pane.nextSibling);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
if (count === 0) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (changed && state.sizes.length !== count) {
|
|
355
|
+
state.open = [];
|
|
356
|
+
state.sizes = count === 1 ? [TOTAL] : initialSizes(state, count);
|
|
357
|
+
}
|
|
358
|
+
apply(node, state);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** Make a split controller for a live node. */
|
|
362
|
+
function createSplit(node, ctx) {
|
|
363
|
+
const state = {
|
|
364
|
+
el: null,
|
|
365
|
+
axis: 'row',
|
|
366
|
+
limits: {},
|
|
367
|
+
key: undefined,
|
|
368
|
+
storage: storageOf(ctx),
|
|
369
|
+
panes: [],
|
|
370
|
+
dividers: [],
|
|
371
|
+
sizes: [],
|
|
372
|
+
open: [],
|
|
373
|
+
drag: null,
|
|
374
|
+
};
|
|
375
|
+
const split = { node, document: ctx.document, state };
|
|
376
|
+
const observer = watchChildren(node, () => refresh(split));
|
|
377
|
+
return {
|
|
378
|
+
state,
|
|
379
|
+
refresh: () => refresh(split),
|
|
380
|
+
setSizes: (next, persist) => setSizes(split, next, persist),
|
|
381
|
+
update(el, changed) {
|
|
382
|
+
state.el = el;
|
|
383
|
+
state.axis = axisOf(el);
|
|
384
|
+
state.limits = limitsOf(el);
|
|
385
|
+
state.key = atomOf(el, 'remember-size');
|
|
386
|
+
if (changed.includes('sizes') && state.panes.length > 1) {
|
|
387
|
+
const given = valuesOf(el, 'sizes').map(Number);
|
|
388
|
+
state.sizes = normalizeSizes(given, state.panes.length, TOTAL);
|
|
389
|
+
}
|
|
390
|
+
refresh(split);
|
|
391
|
+
observer.takeRecords();
|
|
392
|
+
},
|
|
393
|
+
disconnect: () => observer.disconnect(),
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** The static form (ui-dom `renderToHTML`): the grid of the given sizes. */
|
|
398
|
+
function updateStatic(node, el) {
|
|
399
|
+
const sizes = valuesOf(el, 'sizes').map(Number);
|
|
400
|
+
const axis = axisOf(el);
|
|
401
|
+
node.setAttribute('data-direction', axis);
|
|
402
|
+
if (sizes.length > 1) {
|
|
403
|
+
const valid = normalizeSizes(sizes, sizes.length, TOTAL);
|
|
404
|
+
node.style.setProperty(
|
|
405
|
+
axis === 'row' ? 'grid-template-columns' : 'grid-template-rows',
|
|
406
|
+
valid.map((s) => `minmax(0, ${s}fr)`).join(' ')
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
defineKind('split', {
|
|
412
|
+
tag: 'ui-split',
|
|
413
|
+
create: (el, ctx) => ctx.document.createElement('ui-split'),
|
|
414
|
+
update(node, el, changed, ctx) {
|
|
415
|
+
if (changed.includes('label')) {
|
|
416
|
+
labelGroup(node, el);
|
|
417
|
+
}
|
|
418
|
+
if (!isLive(ctx)) {
|
|
419
|
+
updateStatic(node, el);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
controllerOf(node, () => createSplit(node, ctx)).update(el, changed);
|
|
423
|
+
},
|
|
424
|
+
destroy: (node) => dropController(node),
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
/** The current sizes of a rendered split (for tests and tools). */
|
|
428
|
+
export const splitSizes = (node) => [
|
|
429
|
+
...(findController(node)?.state.sizes ?? []),
|
|
430
|
+
];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `stack`: a thin wrapper of CSS flexbox. It replaces the basic stack of
|
|
3
|
+
* ui-dom and accepts the same values, plus `row`/`column` (and their
|
|
4
|
+
* `-reverse` forms), `justify` and `wrap`.
|
|
5
|
+
*
|
|
6
|
+
* (toolbar: stack (direction row) (gap 8px) (align center)
|
|
7
|
+
* (justify space-between) (wrap true) ...)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
11
|
+
import { atomOf, setTypedStyle } from './dom.js';
|
|
12
|
+
|
|
13
|
+
const DIRECTIONS = {
|
|
14
|
+
vertical: 'column',
|
|
15
|
+
horizontal: 'row',
|
|
16
|
+
row: 'row',
|
|
17
|
+
column: 'column',
|
|
18
|
+
'row-reverse': 'row-reverse',
|
|
19
|
+
'column-reverse': 'column-reverse',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const ALIGN = {
|
|
23
|
+
start: 'flex-start',
|
|
24
|
+
center: 'center',
|
|
25
|
+
end: 'flex-end',
|
|
26
|
+
stretch: 'stretch',
|
|
27
|
+
baseline: 'baseline',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const JUSTIFY = {
|
|
31
|
+
start: 'flex-start',
|
|
32
|
+
center: 'center',
|
|
33
|
+
end: 'flex-end',
|
|
34
|
+
'space-between': 'space-between',
|
|
35
|
+
'space-around': 'space-around',
|
|
36
|
+
'space-evenly': 'space-evenly',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const WRAP = { true: 'wrap', false: 'nowrap', reverse: 'wrap-reverse' };
|
|
40
|
+
|
|
41
|
+
/** The CSS property of each enum property and its values. */
|
|
42
|
+
const FLEX = [
|
|
43
|
+
['direction', 'flex-direction', DIRECTIONS],
|
|
44
|
+
['align', 'align-items', ALIGN],
|
|
45
|
+
['justify', 'justify-content', JUSTIFY],
|
|
46
|
+
['wrap', 'flex-wrap', WRAP],
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/** Set an enum property as CSS; an unknown value is reported. */
|
|
50
|
+
function setEnum(node, el, [name, css, map], ctx) {
|
|
51
|
+
const value = atomOf(el, name);
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
node.style.removeProperty(css);
|
|
54
|
+
} else if (Object.hasOwn(map, value)) {
|
|
55
|
+
node.style.setProperty(css, map[value]);
|
|
56
|
+
} else {
|
|
57
|
+
node.style.removeProperty(css);
|
|
58
|
+
ctx.diagnostic('invalid-value', 'error', { property: name });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Write the flexbox properties of the element that changed. */
|
|
63
|
+
export function updateFlex(node, el, changed, ctx) {
|
|
64
|
+
for (const entry of FLEX) {
|
|
65
|
+
if (changed.includes(entry[0])) {
|
|
66
|
+
setEnum(node, el, entry, ctx);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const name of ['gap', 'padding']) {
|
|
70
|
+
if (changed.includes(name)) {
|
|
71
|
+
setTypedStyle(node, el, name, ctx);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
defineKind('stack', {
|
|
77
|
+
tag: 'ui-stack',
|
|
78
|
+
attributes: {
|
|
79
|
+
direction: 'string',
|
|
80
|
+
align: 'string',
|
|
81
|
+
justify: 'string',
|
|
82
|
+
wrap: 'string',
|
|
83
|
+
},
|
|
84
|
+
create: (el, ctx) => ctx.document.createElement('ui-stack'),
|
|
85
|
+
update: updateFlex,
|
|
86
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The surfaces of the layout elements: thin kinds over token styles
|
|
3
|
+
* (layout.css), with no behaviour of their own.
|
|
4
|
+
*
|
|
5
|
+
* (page: container (size medium) ...)
|
|
6
|
+
* (note: paper (elevation 2) ...)
|
|
7
|
+
* (plan: card Starter (subtitle 'For one person') (variant outlined) ...)
|
|
8
|
+
* (top: app-bar Inbox (position sticky) ...)
|
|
9
|
+
*
|
|
10
|
+
* `app-bar` draws a native `<header>`, which is the page's `banner` landmark
|
|
11
|
+
* at page level and a plain group inside `main` or a `section`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
15
|
+
import {
|
|
16
|
+
atomOf,
|
|
17
|
+
flagOf,
|
|
18
|
+
make,
|
|
19
|
+
numberOf,
|
|
20
|
+
setAttr,
|
|
21
|
+
setText,
|
|
22
|
+
uid,
|
|
23
|
+
} from './dom.js';
|
|
24
|
+
|
|
25
|
+
/** Mirror an enum property as an attribute, `fallback` unless it is valid. */
|
|
26
|
+
function setEnum(node, el, name, values, fallback) {
|
|
27
|
+
const value = atomOf(el, name);
|
|
28
|
+
setAttr(node, name, values.includes(value) ? value : fallback);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Write a text part, hiding it while it has no text; whether it has one. */
|
|
32
|
+
function setPartText(part, text) {
|
|
33
|
+
const has = text !== undefined && text !== '';
|
|
34
|
+
setText(part, text);
|
|
35
|
+
setAttr(part, 'hidden', !has);
|
|
36
|
+
return has;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
defineKind('container', {
|
|
40
|
+
tag: 'ui-container',
|
|
41
|
+
create: (el, ctx) => ctx.document.createElement('ui-container'),
|
|
42
|
+
update(node, el) {
|
|
43
|
+
setEnum(
|
|
44
|
+
node,
|
|
45
|
+
el,
|
|
46
|
+
'size',
|
|
47
|
+
['extra-small', 'small', 'medium', 'large', 'extra-large', 'full'],
|
|
48
|
+
'large'
|
|
49
|
+
);
|
|
50
|
+
setAttr(node, 'gutters', flagOf(el, 'gutters', true) ? undefined : 'false');
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
defineKind('paper', {
|
|
55
|
+
tag: 'ui-paper',
|
|
56
|
+
create: (el, ctx) => ctx.document.createElement('ui-paper'),
|
|
57
|
+
update(node, el) {
|
|
58
|
+
const level = Math.trunc(numberOf(el, 'elevation', 1));
|
|
59
|
+
setEnum(node, el, 'variant', ['elevated', 'outlined'], 'elevated');
|
|
60
|
+
setAttr(node, 'elevation', String(Math.min(5, Math.max(0, level))));
|
|
61
|
+
setAttr(node, 'square', flagOf(el, 'square'));
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
defineKind('card', {
|
|
66
|
+
tag: 'ui-card',
|
|
67
|
+
childrenSlot: (node) => node.children[1],
|
|
68
|
+
create(el, ctx) {
|
|
69
|
+
const doc = ctx.document;
|
|
70
|
+
const node = doc.createElement('ui-card');
|
|
71
|
+
const header = make(doc, 'div', { 'data-part': 'header' });
|
|
72
|
+
header.appendChild(
|
|
73
|
+
make(doc, 'div', { 'data-part': 'title', id: uid('ui-card-title') })
|
|
74
|
+
);
|
|
75
|
+
header.appendChild(make(doc, 'div', { 'data-part': 'subtitle' }));
|
|
76
|
+
node.appendChild(header);
|
|
77
|
+
node.appendChild(make(doc, 'div', { 'data-part': 'content' }));
|
|
78
|
+
return node;
|
|
79
|
+
},
|
|
80
|
+
update(node, el) {
|
|
81
|
+
const header = node.firstChild;
|
|
82
|
+
const title = header.firstChild;
|
|
83
|
+
const titled = setPartText(title, atomOf(el, 'title'));
|
|
84
|
+
const subtitled = setPartText(header.children[1], atomOf(el, 'subtitle'));
|
|
85
|
+
setAttr(header, 'hidden', !titled && !subtitled);
|
|
86
|
+
setAttr(node, 'role', titled ? 'group' : undefined);
|
|
87
|
+
setAttr(
|
|
88
|
+
node,
|
|
89
|
+
'aria-labelledby',
|
|
90
|
+
titled ? title.getAttribute('id') : undefined
|
|
91
|
+
);
|
|
92
|
+
setEnum(
|
|
93
|
+
node,
|
|
94
|
+
el,
|
|
95
|
+
'variant',
|
|
96
|
+
['elevated', 'filled', 'outlined'],
|
|
97
|
+
'elevated'
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
defineKind('app-bar', {
|
|
103
|
+
tag: 'ui-app-bar',
|
|
104
|
+
childrenSlot: (node) => node.firstChild.children[1],
|
|
105
|
+
create(el, ctx) {
|
|
106
|
+
const doc = ctx.document;
|
|
107
|
+
const node = doc.createElement('ui-app-bar');
|
|
108
|
+
const root = make(doc, 'header', { 'data-part': 'root' });
|
|
109
|
+
root.appendChild(make(doc, 'div', { 'data-part': 'title' }));
|
|
110
|
+
root.appendChild(make(doc, 'div', { 'data-part': 'content' }));
|
|
111
|
+
node.appendChild(root);
|
|
112
|
+
return node;
|
|
113
|
+
},
|
|
114
|
+
update(node, el) {
|
|
115
|
+
setPartText(node.firstChild.firstChild, atomOf(el, 'title'));
|
|
116
|
+
setEnum(node, el, 'position', ['static', 'sticky', 'fixed'], 'static');
|
|
117
|
+
setEnum(node, el, 'tone', ['surface', 'primary'], 'surface');
|
|
118
|
+
},
|
|
119
|
+
});
|