@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,576 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure model of a dock: regions (left, right, top, bottom, center) that
|
|
3
|
+
* show panels as tabs, floating panels and closed panels. A layout is read
|
|
4
|
+
* from Links Notation (`dockLayoutFromLinks`) and written back
|
|
5
|
+
* (`dockLayoutToLino`), so it is saved and restored as LiNo:
|
|
6
|
+
*
|
|
7
|
+
* designer-shell: dock
|
|
8
|
+
* persist designer.layout
|
|
9
|
+
* left: region
|
|
10
|
+
* size 16rem
|
|
11
|
+
* panels toolbox outline
|
|
12
|
+
* right: region
|
|
13
|
+
* size 20rem
|
|
14
|
+
* panels properties
|
|
15
|
+
* center: region
|
|
16
|
+
* panels canvas
|
|
17
|
+
* bottom: region
|
|
18
|
+
* size 12rem
|
|
19
|
+
* collapsed true
|
|
20
|
+
* panels problems
|
|
21
|
+
* float search
|
|
22
|
+
* x 40
|
|
23
|
+
* y 60
|
|
24
|
+
* width 320
|
|
25
|
+
* height 240
|
|
26
|
+
* region left
|
|
27
|
+
* closed history right
|
|
28
|
+
*
|
|
29
|
+
* Reading goes through `links-notation` and the ui-core projection (no
|
|
30
|
+
* regular expressions), so any form of the text reads; writing builds
|
|
31
|
+
* `links-notation` `Link` objects and writes them in the nested form with
|
|
32
|
+
* ui-core `formatLinks`, so quoting follows the parser. Every change returns a new
|
|
33
|
+
* layout and leaves its input alone.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import {
|
|
37
|
+
elementLink,
|
|
38
|
+
formatLinks,
|
|
39
|
+
parse as parseUi,
|
|
40
|
+
projectLinks,
|
|
41
|
+
} from '@link-foundation/ui-core';
|
|
42
|
+
import { Link } from 'links-notation';
|
|
43
|
+
import { layoutVocabulary } from './vocabulary.js';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {'left'|'right'|'top'|'bottom'|'center'} Side
|
|
47
|
+
*
|
|
48
|
+
* @typedef {object} DockRegion
|
|
49
|
+
* @property {string} id
|
|
50
|
+
* @property {Side} side
|
|
51
|
+
* @property {string|null} size a CSS length such as `16rem`
|
|
52
|
+
* @property {boolean} collapsed
|
|
53
|
+
* @property {string[]} panels panel ids in tab order
|
|
54
|
+
* @property {string|null} active the panel shown (default the first)
|
|
55
|
+
*
|
|
56
|
+
* @typedef {object} FloatingPanel
|
|
57
|
+
* @property {string} panel
|
|
58
|
+
* @property {number} x
|
|
59
|
+
* @property {number} y
|
|
60
|
+
* @property {number} width
|
|
61
|
+
* @property {number} height
|
|
62
|
+
* @property {string|null} region the region it was floated from
|
|
63
|
+
*
|
|
64
|
+
* @typedef {object} ClosedPanel
|
|
65
|
+
* @property {string} panel
|
|
66
|
+
* @property {string|null} region the region it was closed in
|
|
67
|
+
*
|
|
68
|
+
* @typedef {object} DockLayout
|
|
69
|
+
* @property {string|null} id
|
|
70
|
+
* @property {string|null} persist the storage key of the layout
|
|
71
|
+
* @property {DockRegion[]} regions
|
|
72
|
+
* @property {FloatingPanel[]} floating
|
|
73
|
+
* @property {ClosedPanel[]} closed
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/** The sides of a dock, in the order regions are written. */
|
|
77
|
+
export const SIDES = Object.freeze([
|
|
78
|
+
'left',
|
|
79
|
+
'right',
|
|
80
|
+
'top',
|
|
81
|
+
'bottom',
|
|
82
|
+
'center',
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
/** The default size of a floating panel. */
|
|
86
|
+
export const FLOAT_DEFAULTS = Object.freeze({
|
|
87
|
+
x: 48,
|
|
88
|
+
y: 48,
|
|
89
|
+
width: 320,
|
|
90
|
+
height: 240,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const isSide = (value) => SIDES.includes(value);
|
|
94
|
+
const sideOf = (value) => (value === 'centre' ? 'center' : value);
|
|
95
|
+
|
|
96
|
+
/** The values of the last property `name` of a ui-core node. */
|
|
97
|
+
function propertyValues(node, name) {
|
|
98
|
+
const found = node.properties.filter((p) => p.name === name);
|
|
99
|
+
return found.length === 0 ? undefined : found[found.length - 1].values;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const atomOf = (node, name) => {
|
|
103
|
+
const values = propertyValues(node, name);
|
|
104
|
+
return typeof values?.[0] === 'string' ? values[0] : null;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const textValues = (values) =>
|
|
108
|
+
(values ?? []).filter((value) => typeof value === 'string');
|
|
109
|
+
|
|
110
|
+
/** `(x 40)` sublinks of a `float` property as an object of strings. */
|
|
111
|
+
function fields(values) {
|
|
112
|
+
const out = {};
|
|
113
|
+
for (const value of values) {
|
|
114
|
+
if (Array.isArray(value) && typeof value[0] === 'string') {
|
|
115
|
+
out[value[0]] = value[1];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const numberOr = (text, fallback) => {
|
|
122
|
+
const n = typeof text === 'string' && text.trim() !== '' ? Number(text) : NaN;
|
|
123
|
+
return Number.isFinite(n) ? n : fallback;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
function readRegion(node) {
|
|
127
|
+
const side = sideOf(atomOf(node, 'side') ?? node.id);
|
|
128
|
+
const panels = textValues(propertyValues(node, 'panels'));
|
|
129
|
+
const active = atomOf(node, 'active');
|
|
130
|
+
return {
|
|
131
|
+
id: node.id,
|
|
132
|
+
side: isSide(side) ? side : 'center',
|
|
133
|
+
size: atomOf(node, 'size'),
|
|
134
|
+
collapsed: atomOf(node, 'collapsed') === 'true',
|
|
135
|
+
panels,
|
|
136
|
+
active: panels.includes(active) ? active : (panels[0] ?? null),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function readFloating(values) {
|
|
141
|
+
const [panel, ...rest] = values;
|
|
142
|
+
const f = fields(rest);
|
|
143
|
+
return {
|
|
144
|
+
panel,
|
|
145
|
+
x: numberOr(f.x, FLOAT_DEFAULTS.x),
|
|
146
|
+
y: numberOr(f.y, FLOAT_DEFAULTS.y),
|
|
147
|
+
width: numberOr(f.width, FLOAT_DEFAULTS.width),
|
|
148
|
+
height: numberOr(f.height, FLOAT_DEFAULTS.height),
|
|
149
|
+
region: typeof f.region === 'string' ? f.region : null,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The layout of a ui-core `dock` node.
|
|
155
|
+
* @param {import('@link-foundation/ui-core').UiNode} node
|
|
156
|
+
* @returns {DockLayout}
|
|
157
|
+
*/
|
|
158
|
+
export function dockLayoutFromNode(node) {
|
|
159
|
+
const regions = node.children
|
|
160
|
+
.filter((child) => child.kind === 'region' && child.id !== null)
|
|
161
|
+
.map(readRegion);
|
|
162
|
+
const floating = node.properties
|
|
163
|
+
.filter((p) => p.name === 'float' && typeof p.values[0] === 'string')
|
|
164
|
+
.map((p) => readFloating(p.values));
|
|
165
|
+
const closed = node.properties
|
|
166
|
+
.filter((p) => p.name === 'closed' && typeof p.values[0] === 'string')
|
|
167
|
+
.map((p) => ({
|
|
168
|
+
panel: p.values[0],
|
|
169
|
+
region: typeof p.values[1] === 'string' ? p.values[1] : null,
|
|
170
|
+
}));
|
|
171
|
+
return {
|
|
172
|
+
id: node.id,
|
|
173
|
+
persist: atomOf(node, 'persist'),
|
|
174
|
+
regions,
|
|
175
|
+
floating,
|
|
176
|
+
closed,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The first `dock` node (depth first), or the one with the id `id`. */
|
|
181
|
+
function findDock(nodes, id) {
|
|
182
|
+
for (const node of nodes) {
|
|
183
|
+
if (node.kind === 'dock' && (id === undefined || node.id === id)) {
|
|
184
|
+
return node;
|
|
185
|
+
}
|
|
186
|
+
const inner = findDock(node.children ?? [], id);
|
|
187
|
+
if (inner !== null) {
|
|
188
|
+
return inner;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** ui-core nodes of LiNo text, links-notation links or ui-core nodes. */
|
|
195
|
+
function nodesOf(links) {
|
|
196
|
+
const vocabulary = layoutVocabulary();
|
|
197
|
+
if (typeof links === 'string') {
|
|
198
|
+
return parseUi(links, { vocabulary }).roots;
|
|
199
|
+
}
|
|
200
|
+
if (!Array.isArray(links)) {
|
|
201
|
+
return links?.roots ?? [links];
|
|
202
|
+
}
|
|
203
|
+
const isNode = links.every(
|
|
204
|
+
(l) => l !== null && typeof l?.kind !== 'undefined'
|
|
205
|
+
);
|
|
206
|
+
return isNode ? links : projectLinks(links, vocabulary).roots;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Read a dock layout.
|
|
211
|
+
* @param {string|object[]|object} links LiNo text, the links of the
|
|
212
|
+
* `links-notation` parser, a ui-core document or ui-core nodes
|
|
213
|
+
* @param {{ id?: string }} [options] the id of the dock, when there are
|
|
214
|
+
* several
|
|
215
|
+
* @returns {DockLayout}
|
|
216
|
+
* @throws {TypeError} when there is no dock
|
|
217
|
+
*/
|
|
218
|
+
export function dockLayoutFromLinks(links, options = {}) {
|
|
219
|
+
const node = findDock(nodesOf(links), options.id);
|
|
220
|
+
if (node === null) {
|
|
221
|
+
throw new TypeError(
|
|
222
|
+
options.id === undefined
|
|
223
|
+
? 'dockLayoutFromLinks: no dock element'
|
|
224
|
+
: `dockLayoutFromLinks: no dock "${options.id}"`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
return dockLayoutFromNode(node);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const property = (name, values) => ({ name, values });
|
|
231
|
+
|
|
232
|
+
/** A region as a ui-core node (written on one line). */
|
|
233
|
+
function regionNode(region) {
|
|
234
|
+
const properties = [];
|
|
235
|
+
if (region.side !== region.id) {
|
|
236
|
+
properties.push(property('side', [region.side]));
|
|
237
|
+
}
|
|
238
|
+
if (region.size !== null) {
|
|
239
|
+
properties.push(property('size', [region.size]));
|
|
240
|
+
}
|
|
241
|
+
if (region.collapsed) {
|
|
242
|
+
properties.push(property('collapsed', ['true']));
|
|
243
|
+
}
|
|
244
|
+
if (region.panels.length > 0) {
|
|
245
|
+
properties.push(property('panels', region.panels));
|
|
246
|
+
}
|
|
247
|
+
if (region.active !== null && region.active !== region.panels[0]) {
|
|
248
|
+
properties.push(property('active', [region.active]));
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
id: region.id,
|
|
252
|
+
kind: 'region',
|
|
253
|
+
positional: [],
|
|
254
|
+
properties,
|
|
255
|
+
unknown: [],
|
|
256
|
+
children: [],
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const field = (name, value) =>
|
|
261
|
+
new Link(null, [new Link(name), new Link(String(value))]);
|
|
262
|
+
|
|
263
|
+
function floatLink(f) {
|
|
264
|
+
const values = [
|
|
265
|
+
new Link('float'),
|
|
266
|
+
new Link(f.panel),
|
|
267
|
+
field('x', f.x),
|
|
268
|
+
field('y', f.y),
|
|
269
|
+
field('width', f.width),
|
|
270
|
+
field('height', f.height),
|
|
271
|
+
];
|
|
272
|
+
if (f.region !== null) {
|
|
273
|
+
values.push(field('region', f.region));
|
|
274
|
+
}
|
|
275
|
+
return new Link(null, values);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const closedLink = (c) =>
|
|
279
|
+
new Link(null, [
|
|
280
|
+
new Link('closed'),
|
|
281
|
+
new Link(c.panel),
|
|
282
|
+
...(c.region === null ? [] : [new Link(c.region)]),
|
|
283
|
+
]);
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Write a dock layout as Links Notation in the nested form: the dock line,
|
|
287
|
+
* then one indented block per region, floating panel and closed panel.
|
|
288
|
+
* @param {DockLayout} layout
|
|
289
|
+
* @param {{ indent?: string }} [options]
|
|
290
|
+
* @returns {string}
|
|
291
|
+
*/
|
|
292
|
+
export function dockLayoutToLino(layout, options = {}) {
|
|
293
|
+
const dock = new Link(layout.id ?? null, [
|
|
294
|
+
new Link('dock'),
|
|
295
|
+
...(layout.persist === null
|
|
296
|
+
? []
|
|
297
|
+
: [new Link(null, [new Link('persist'), new Link(layout.persist)])]),
|
|
298
|
+
...layout.regions.map((region) => elementLink(regionNode(region))),
|
|
299
|
+
...layout.floating.map(floatLink),
|
|
300
|
+
...layout.closed.map(closedLink),
|
|
301
|
+
]);
|
|
302
|
+
return formatLinks([dock], { indent: options.indent ?? ' ' });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Where a panel is.
|
|
307
|
+
* @param {DockLayout} layout
|
|
308
|
+
* @param {string} panelId
|
|
309
|
+
* @returns {{ place: 'region', region: DockRegion, index: number }
|
|
310
|
+
* | { place: 'floating', floating: FloatingPanel, index: number }
|
|
311
|
+
* | { place: 'closed', closed: ClosedPanel, index: number }
|
|
312
|
+
* | null}
|
|
313
|
+
*/
|
|
314
|
+
export function findPanel(layout, panelId) {
|
|
315
|
+
for (const region of layout.regions) {
|
|
316
|
+
const index = region.panels.indexOf(panelId);
|
|
317
|
+
if (index >= 0) {
|
|
318
|
+
return { place: 'region', region, index };
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const f = layout.floating.findIndex((x) => x.panel === panelId);
|
|
322
|
+
if (f >= 0) {
|
|
323
|
+
return { place: 'floating', floating: layout.floating[f], index: f };
|
|
324
|
+
}
|
|
325
|
+
const c = layout.closed.findIndex((x) => x.panel === panelId);
|
|
326
|
+
if (c >= 0) {
|
|
327
|
+
return { place: 'closed', closed: layout.closed[c], index: c };
|
|
328
|
+
}
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Every panel of the layout: in regions, floating, then closed. */
|
|
333
|
+
export const panelIds = (layout) => [
|
|
334
|
+
...layout.regions.flatMap((r) => r.panels),
|
|
335
|
+
...layout.floating.map((f) => f.panel),
|
|
336
|
+
...layout.closed.map((c) => c.panel),
|
|
337
|
+
];
|
|
338
|
+
|
|
339
|
+
/** The panels that are open (in a region or floating). */
|
|
340
|
+
export const openPanelIds = (layout) => [
|
|
341
|
+
...layout.regions.flatMap((r) => r.panels),
|
|
342
|
+
...layout.floating.map((f) => f.panel),
|
|
343
|
+
];
|
|
344
|
+
|
|
345
|
+
function locate(layout, panelId, name) {
|
|
346
|
+
const found = findPanel(layout, panelId);
|
|
347
|
+
if (found === null) {
|
|
348
|
+
throw new RangeError(`${name}: no panel "${panelId}"`);
|
|
349
|
+
}
|
|
350
|
+
return found;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** The layout without the panel (a copy), and the region it left. */
|
|
354
|
+
function detach(layout, found) {
|
|
355
|
+
if (found.place === 'region') {
|
|
356
|
+
const regions = layout.regions.map((region) => {
|
|
357
|
+
if (region !== found.region) {
|
|
358
|
+
return region;
|
|
359
|
+
}
|
|
360
|
+
const panels = region.panels.filter((_, i) => i !== found.index);
|
|
361
|
+
const active =
|
|
362
|
+
region.active === region.panels[found.index]
|
|
363
|
+
? (panels[Math.min(found.index, panels.length - 1)] ?? null)
|
|
364
|
+
: region.active;
|
|
365
|
+
return { ...region, panels, active };
|
|
366
|
+
});
|
|
367
|
+
return { layout: { ...layout, regions }, from: found.region.id };
|
|
368
|
+
}
|
|
369
|
+
if (found.place === 'floating') {
|
|
370
|
+
return {
|
|
371
|
+
layout: {
|
|
372
|
+
...layout,
|
|
373
|
+
floating: layout.floating.filter((_, i) => i !== found.index),
|
|
374
|
+
},
|
|
375
|
+
from: found.floating.region,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
layout: {
|
|
380
|
+
...layout,
|
|
381
|
+
closed: layout.closed.filter((_, i) => i !== found.index),
|
|
382
|
+
},
|
|
383
|
+
from: found.closed.region,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** `{ region, index?, activate? }` of a move target. */
|
|
388
|
+
function targetOf(target) {
|
|
389
|
+
if (typeof target === 'string') {
|
|
390
|
+
return { region: target };
|
|
391
|
+
}
|
|
392
|
+
if (
|
|
393
|
+
target === null ||
|
|
394
|
+
typeof target !== 'object' ||
|
|
395
|
+
typeof target.region !== 'string'
|
|
396
|
+
) {
|
|
397
|
+
throw new TypeError(
|
|
398
|
+
'movePanel: the target must be a region id or { region, index }'
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
return target;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** The layout with the panel inserted into a region (made when missing). */
|
|
405
|
+
function attach(layout, panelId, { region: regionId, index, activate }) {
|
|
406
|
+
let regions = layout.regions;
|
|
407
|
+
if (!regions.some((r) => r.id === regionId)) {
|
|
408
|
+
const side = sideOf(regionId);
|
|
409
|
+
if (!isSide(side)) {
|
|
410
|
+
throw new RangeError(`movePanel: no region "${regionId}"`);
|
|
411
|
+
}
|
|
412
|
+
regions = [
|
|
413
|
+
...regions,
|
|
414
|
+
{
|
|
415
|
+
id: regionId,
|
|
416
|
+
side,
|
|
417
|
+
size: null,
|
|
418
|
+
collapsed: false,
|
|
419
|
+
panels: [],
|
|
420
|
+
active: null,
|
|
421
|
+
},
|
|
422
|
+
];
|
|
423
|
+
}
|
|
424
|
+
regions = regions.map((region) => {
|
|
425
|
+
if (region.id !== regionId) {
|
|
426
|
+
return region;
|
|
427
|
+
}
|
|
428
|
+
const panels = [...region.panels];
|
|
429
|
+
const at =
|
|
430
|
+
Number.isInteger(index) && index >= 0 && index <= panels.length
|
|
431
|
+
? index
|
|
432
|
+
: panels.length;
|
|
433
|
+
panels.splice(at, 0, panelId);
|
|
434
|
+
const active =
|
|
435
|
+
activate === true || region.active === null ? panelId : region.active;
|
|
436
|
+
return { ...region, panels, active };
|
|
437
|
+
});
|
|
438
|
+
return { ...layout, regions };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Move a panel to a region, as its last tab or at `index`. The panel may be
|
|
443
|
+
* in another region, in the same one (a reorder), floating or closed. A
|
|
444
|
+
* missing region named after a side (`top`) is made. The shown panel of
|
|
445
|
+
* the target stays the same unless `activate` is true or it had none.
|
|
446
|
+
* @param {DockLayout} layout
|
|
447
|
+
* @param {string} panelId
|
|
448
|
+
* @param {string|{ region: string, index?: number, activate?: boolean }} target
|
|
449
|
+
* @returns {DockLayout}
|
|
450
|
+
*/
|
|
451
|
+
export function movePanel(layout, panelId, target) {
|
|
452
|
+
const to = targetOf(target);
|
|
453
|
+
const { layout: without } = detach(
|
|
454
|
+
layout,
|
|
455
|
+
locate(layout, panelId, 'movePanel')
|
|
456
|
+
);
|
|
457
|
+
return attach(without, panelId, to);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Float a panel: it leaves its region (which it can return to) and gets a
|
|
462
|
+
* position and size; a floating panel only gets the new rectangle.
|
|
463
|
+
* @param {DockLayout} layout
|
|
464
|
+
* @param {string} panelId
|
|
465
|
+
* @param {{ x?: number, y?: number, width?: number, height?: number }} [rect]
|
|
466
|
+
* @returns {DockLayout}
|
|
467
|
+
*/
|
|
468
|
+
export function floatPanel(layout, panelId, rect = {}) {
|
|
469
|
+
const found = locate(layout, panelId, 'floatPanel');
|
|
470
|
+
const { layout: without, from } = detach(layout, found);
|
|
471
|
+
const previous = found.place === 'floating' ? found.floating : FLOAT_DEFAULTS;
|
|
472
|
+
const pick = (name) =>
|
|
473
|
+
Number.isFinite(rect[name]) ? rect[name] : previous[name];
|
|
474
|
+
const entry = {
|
|
475
|
+
panel: panelId,
|
|
476
|
+
x: pick('x'),
|
|
477
|
+
y: pick('y'),
|
|
478
|
+
width: pick('width'),
|
|
479
|
+
height: pick('height'),
|
|
480
|
+
region: from ?? null,
|
|
481
|
+
};
|
|
482
|
+
const floating = [...without.floating];
|
|
483
|
+
floating.splice(
|
|
484
|
+
found.place === 'floating' ? found.index : floating.length,
|
|
485
|
+
0,
|
|
486
|
+
entry
|
|
487
|
+
);
|
|
488
|
+
return { ...without, floating };
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Close a panel; it remembers its region so `restorePanel` puts it back.
|
|
493
|
+
* Closing a closed panel changes nothing.
|
|
494
|
+
* @param {DockLayout} layout
|
|
495
|
+
* @param {string} panelId
|
|
496
|
+
* @returns {DockLayout}
|
|
497
|
+
*/
|
|
498
|
+
export function closePanel(layout, panelId) {
|
|
499
|
+
const found = locate(layout, panelId, 'closePanel');
|
|
500
|
+
if (found.place === 'closed') {
|
|
501
|
+
return layout;
|
|
502
|
+
}
|
|
503
|
+
const { layout: without, from } = detach(layout, found);
|
|
504
|
+
return {
|
|
505
|
+
...without,
|
|
506
|
+
closed: [...without.closed, { panel: panelId, region: from ?? null }],
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Restore a closed panel to the region it was closed in (or `target`), as
|
|
512
|
+
* the shown tab. Without a known region it goes to the center.
|
|
513
|
+
* @param {DockLayout} layout
|
|
514
|
+
* @param {string} panelId
|
|
515
|
+
* @param {string|{ region: string, index?: number }} [target]
|
|
516
|
+
* @returns {DockLayout}
|
|
517
|
+
*/
|
|
518
|
+
export function restorePanel(layout, panelId, target) {
|
|
519
|
+
const found = locate(layout, panelId, 'restorePanel');
|
|
520
|
+
if (found.place !== 'closed') {
|
|
521
|
+
return layout;
|
|
522
|
+
}
|
|
523
|
+
const fallback =
|
|
524
|
+
found.closed.region ??
|
|
525
|
+
layout.regions.find((r) => r.side === 'center')?.id ??
|
|
526
|
+
'center';
|
|
527
|
+
const to = target === undefined ? { region: fallback } : targetOf(target);
|
|
528
|
+
return movePanel(layout, panelId, { ...to, activate: true });
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Show a panel of a region (its tab becomes the selected one).
|
|
533
|
+
* @param {DockLayout} layout
|
|
534
|
+
* @param {string} panelId
|
|
535
|
+
* @returns {DockLayout}
|
|
536
|
+
*/
|
|
537
|
+
export function activatePanel(layout, panelId) {
|
|
538
|
+
const found = locate(layout, panelId, 'activatePanel');
|
|
539
|
+
if (found.place !== 'region' || found.region.active === panelId) {
|
|
540
|
+
return layout;
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
...layout,
|
|
544
|
+
regions: layout.regions.map((r) =>
|
|
545
|
+
r === found.region ? { ...r, active: panelId } : r
|
|
546
|
+
),
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Change a region: its `size` (a CSS length) or `collapsed`.
|
|
552
|
+
* @param {DockLayout} layout
|
|
553
|
+
* @param {string} regionId
|
|
554
|
+
* @param {{ size?: string|null, collapsed?: boolean }} change
|
|
555
|
+
* @returns {DockLayout}
|
|
556
|
+
*/
|
|
557
|
+
export function updateRegion(layout, regionId, change) {
|
|
558
|
+
if (!layout.regions.some((r) => r.id === regionId)) {
|
|
559
|
+
throw new RangeError(`updateRegion: no region "${regionId}"`);
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
...layout,
|
|
563
|
+
regions: layout.regions.map((r) =>
|
|
564
|
+
r.id === regionId
|
|
565
|
+
? {
|
|
566
|
+
...r,
|
|
567
|
+
size: change.size === undefined ? r.size : change.size,
|
|
568
|
+
collapsed:
|
|
569
|
+
change.collapsed === undefined
|
|
570
|
+
? r.collapsed
|
|
571
|
+
: change.collapsed === true,
|
|
572
|
+
}
|
|
573
|
+
: r
|
|
574
|
+
),
|
|
575
|
+
};
|
|
576
|
+
}
|