@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,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applySharedLook,
|
|
3
|
+
diff,
|
|
4
|
+
merge,
|
|
5
|
+
fromShareHash,
|
|
6
|
+
looksToLino,
|
|
7
|
+
looksFromLino,
|
|
8
|
+
} from '@link-foundation/ui-settings';
|
|
9
|
+
import { miniature } from './miniature.js';
|
|
10
|
+
|
|
11
|
+
/** Named looks are stored as versioned LiNo, with failures visible to the user. */
|
|
12
|
+
export function createSavedLooks(context) {
|
|
13
|
+
const {
|
|
14
|
+
schema,
|
|
15
|
+
options,
|
|
16
|
+
messages,
|
|
17
|
+
node,
|
|
18
|
+
button,
|
|
19
|
+
getValues,
|
|
20
|
+
commit,
|
|
21
|
+
win,
|
|
22
|
+
status,
|
|
23
|
+
copy,
|
|
24
|
+
} = context;
|
|
25
|
+
let looks = new Map(Object.entries(options.savedLooks ?? {}));
|
|
26
|
+
const key = options.looksStorageKey ?? 'link-ui.settings.looks.v1';
|
|
27
|
+
const storage = () =>
|
|
28
|
+
options.looksStorage === undefined
|
|
29
|
+
? win.localStorage
|
|
30
|
+
: options.looksStorage;
|
|
31
|
+
const report = () => messages.content(status, 'looksError');
|
|
32
|
+
looks = loadLooks(schema, storage, key, looks, report);
|
|
33
|
+
const bar = node('div');
|
|
34
|
+
bar.className = 'settings-toolbar';
|
|
35
|
+
const name = node('input', undefined, bar);
|
|
36
|
+
name.maxLength = 60;
|
|
37
|
+
messages.attr(name, 'aria-label', 'lookName');
|
|
38
|
+
const list = node('div');
|
|
39
|
+
list.className = 'settings-cards settings-looks';
|
|
40
|
+
const empty = node('p', messages.message('emptyLooks'));
|
|
41
|
+
let previews = [];
|
|
42
|
+
let beforeName;
|
|
43
|
+
const normalize = (label) =>
|
|
44
|
+
String(label ?? '')
|
|
45
|
+
.trim()
|
|
46
|
+
.slice(0, 60);
|
|
47
|
+
const nextName = () => {
|
|
48
|
+
let n = 1;
|
|
49
|
+
while (looks.has(defaultName(messages, n))) {
|
|
50
|
+
n++;
|
|
51
|
+
}
|
|
52
|
+
return defaultName(messages, n);
|
|
53
|
+
};
|
|
54
|
+
function persist(next) {
|
|
55
|
+
try {
|
|
56
|
+
storage()?.setItem(key, looksToLino(schema, Object.fromEntries(next)));
|
|
57
|
+
options.onLooksChange?.(Object.fromEntries(next));
|
|
58
|
+
looks = next;
|
|
59
|
+
refresh();
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
report();
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function saveLook(label) {
|
|
67
|
+
const key = normalize(label) || nextName();
|
|
68
|
+
return persist(new Map(looks).set(key, diff(schema, getValues())));
|
|
69
|
+
}
|
|
70
|
+
function applyLook(label) {
|
|
71
|
+
return (
|
|
72
|
+
looks.has(label) &&
|
|
73
|
+
commit(applySharedLook(schema, getValues(), looks.get(label)))
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function deleteLook(label) {
|
|
77
|
+
const next = new Map(looks);
|
|
78
|
+
next.delete(label);
|
|
79
|
+
return persist(next);
|
|
80
|
+
}
|
|
81
|
+
function renameLook(label, nextLabel) {
|
|
82
|
+
const key = normalize(nextLabel);
|
|
83
|
+
if (!key || !looks.has(label)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const next = new Map(looks);
|
|
87
|
+
const value = next.get(label);
|
|
88
|
+
next.delete(label);
|
|
89
|
+
next.set(key, value);
|
|
90
|
+
return persist(next);
|
|
91
|
+
}
|
|
92
|
+
function refresh() {
|
|
93
|
+
previews.forEach((p) => p.destroy());
|
|
94
|
+
previews = [];
|
|
95
|
+
messages.release(list);
|
|
96
|
+
list.replaceChildren();
|
|
97
|
+
empty.hidden = looks.size > 0;
|
|
98
|
+
for (const [label, values] of looks) {
|
|
99
|
+
previews.push(
|
|
100
|
+
lookCard(context, list, label, values, {
|
|
101
|
+
applyLook,
|
|
102
|
+
saveLook,
|
|
103
|
+
renameLook,
|
|
104
|
+
deleteLook,
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
button(messages.message('saveLook'), () => saveLook(name.value), bar);
|
|
110
|
+
button(messages.message('copyLooks'), () => copy(exportLooks()), bar);
|
|
111
|
+
function restoreBeforeLink() {
|
|
112
|
+
return applyLook(beforeName ?? messages.text('beforeLink'));
|
|
113
|
+
}
|
|
114
|
+
function applyShared(hash) {
|
|
115
|
+
const result = fromShareHash(schema, hash, getValues());
|
|
116
|
+
if (result.ok) {
|
|
117
|
+
const label = normalize(messages.text('beforeLink'));
|
|
118
|
+
const previous = new Map(looks);
|
|
119
|
+
if (!saveLook(label)) {
|
|
120
|
+
return { ...result, ok: false };
|
|
121
|
+
}
|
|
122
|
+
if (!commit(result.values)) {
|
|
123
|
+
persist(previous);
|
|
124
|
+
return { ...result, ok: false };
|
|
125
|
+
}
|
|
126
|
+
beforeName = label;
|
|
127
|
+
win.history.replaceState(
|
|
128
|
+
win.history.state,
|
|
129
|
+
'',
|
|
130
|
+
`${win.location.pathname}${win.location.search}`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
const exportLooks = () => looksToLino(schema, Object.fromEntries(looks));
|
|
136
|
+
function importLooks(text) {
|
|
137
|
+
const parsed = looksFromLino(schema, text);
|
|
138
|
+
if (!parsed) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if (!parsed.ok) {
|
|
142
|
+
messages.content(status, 'invalid');
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return persist(new Map([...looks, ...Object.entries(parsed.looks)]));
|
|
146
|
+
}
|
|
147
|
+
refresh();
|
|
148
|
+
return {
|
|
149
|
+
saveLook,
|
|
150
|
+
applyLook,
|
|
151
|
+
deleteLook,
|
|
152
|
+
renameLook,
|
|
153
|
+
applyShared,
|
|
154
|
+
restoreBeforeLink,
|
|
155
|
+
exportLooks,
|
|
156
|
+
importLooks,
|
|
157
|
+
destroyLooks: () => previews.forEach((p) => p.destroy()),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function lookCard(context, list, label, values, actions) {
|
|
162
|
+
const { node, button, schema, messages } = context;
|
|
163
|
+
const { applyLook, saveLook, renameLook, deleteLook } = actions;
|
|
164
|
+
const card = node('div', undefined, list);
|
|
165
|
+
const title = node('strong', label, card);
|
|
166
|
+
const preview = miniature(context, card, values, { look: label });
|
|
167
|
+
preview.update(merge(schema, undefined, values).values);
|
|
168
|
+
|
|
169
|
+
button(messages.message('applyLook'), () => applyLook(label), card);
|
|
170
|
+
button(messages.message('updateLook'), () => saveLook(label), card);
|
|
171
|
+
const input = node('input', undefined, card);
|
|
172
|
+
input.value = label;
|
|
173
|
+
input.maxLength = 60;
|
|
174
|
+
input.hidden = true;
|
|
175
|
+
messages.attr(input, 'aria-label', 'lookName');
|
|
176
|
+
const rename = button(
|
|
177
|
+
messages.message('renameLook'),
|
|
178
|
+
() => {
|
|
179
|
+
input.hidden = false;
|
|
180
|
+
title.hidden = true;
|
|
181
|
+
input.focus();
|
|
182
|
+
input.select();
|
|
183
|
+
},
|
|
184
|
+
card
|
|
185
|
+
);
|
|
186
|
+
input.addEventListener('keydown', (event) => {
|
|
187
|
+
if (event.key === 'Enter') {
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
if (renameLook(label, input.value)) {
|
|
190
|
+
list.querySelector('button')?.focus();
|
|
191
|
+
}
|
|
192
|
+
} else if (event.key === 'Escape') {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
event.stopPropagation();
|
|
195
|
+
input.value = label;
|
|
196
|
+
input.hidden = true;
|
|
197
|
+
title.hidden = false;
|
|
198
|
+
rename.focus();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
button(messages.message('deleteLook'), () => deleteLook(label), card);
|
|
202
|
+
return preview;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function loadLooks(schema, storage, key, looks, report) {
|
|
206
|
+
try {
|
|
207
|
+
const text = storage()?.getItem(key);
|
|
208
|
+
if (text) {
|
|
209
|
+
const parsed = looksFromLino(schema, text);
|
|
210
|
+
if (parsed?.ok) {
|
|
211
|
+
return new Map([...Object.entries(parsed.looks), ...looks]);
|
|
212
|
+
}
|
|
213
|
+
report();
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
report();
|
|
217
|
+
}
|
|
218
|
+
return looks;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function defaultName(messages, count) {
|
|
222
|
+
const text = messages.text('defaultLook', { count }).trim();
|
|
223
|
+
const suffix = ` ${count}`;
|
|
224
|
+
return text.length <= 60
|
|
225
|
+
? text
|
|
226
|
+
: `${text.slice(0, 60 - suffix.length)}${suffix}`;
|
|
227
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { defaults } from '@link-foundation/ui-settings';
|
|
2
|
+
import { fieldVisible } from './conditions.js';
|
|
3
|
+
|
|
4
|
+
/** Stable estimates use defaults and the first tab/level, never the edited value. */
|
|
5
|
+
export function estimateSection(section, schema) {
|
|
6
|
+
const values = defaults(schema);
|
|
7
|
+
const fields = section.fields.filter((field) =>
|
|
8
|
+
fieldVisible(field, values, {}, section)
|
|
9
|
+
);
|
|
10
|
+
if (!fields.length) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
return (
|
|
14
|
+
64 +
|
|
15
|
+
(section.description ? 48 : 0) +
|
|
16
|
+
(section.tabs?.length ? 44 : 0) +
|
|
17
|
+
(section.levels?.length ? 44 : 0) +
|
|
18
|
+
fields.reduce(
|
|
19
|
+
(height, field) => height + 88 + (field.description ? 40 : 0),
|
|
20
|
+
0
|
|
21
|
+
) +
|
|
22
|
+
(section.extraHeight ?? 0)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function references(raw, schema) {
|
|
27
|
+
return (Array.isArray(raw) ? raw.flat(Infinity) : [raw])
|
|
28
|
+
.map((key) => {
|
|
29
|
+
const field = schema.fields.get(key);
|
|
30
|
+
return field ? (field.section ?? '') : undefined;
|
|
31
|
+
})
|
|
32
|
+
.filter((id) => id !== undefined);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Assign once: editing, searching and switching levels cannot reparent a section. */
|
|
36
|
+
export function sectionColumns(context, body, sections) {
|
|
37
|
+
const { options, node, schema } = context;
|
|
38
|
+
const count = Math.max(
|
|
39
|
+
1,
|
|
40
|
+
Math.min(
|
|
41
|
+
12,
|
|
42
|
+
Math.floor(options.columns?.count ?? options.columns ?? 1) || 1
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
body.style.setProperty('--settings-columns', String(count));
|
|
46
|
+
if (options.columns?.balance !== 'estimate') {
|
|
47
|
+
return () => body;
|
|
48
|
+
}
|
|
49
|
+
const columns = Array.from({ length: count }, () => {
|
|
50
|
+
const column = node('div', undefined, body);
|
|
51
|
+
column.className = 'settings-column';
|
|
52
|
+
return { column, height: 0 };
|
|
53
|
+
});
|
|
54
|
+
const placements = new Map();
|
|
55
|
+
const anchors = new Map();
|
|
56
|
+
const waiting = new Map();
|
|
57
|
+
const ids = new Set(sections.map((section) => section.id));
|
|
58
|
+
const place = (section, group) => {
|
|
59
|
+
const dependencies = [
|
|
60
|
+
...references(section['visible-when'], schema),
|
|
61
|
+
...section.fields.flatMap((f) =>
|
|
62
|
+
references(f.props['visible-when'], schema)
|
|
63
|
+
),
|
|
64
|
+
];
|
|
65
|
+
const dependency = dependencies.find(
|
|
66
|
+
(id) => id !== section.id && ids.has(id)
|
|
67
|
+
);
|
|
68
|
+
if (dependency !== undefined && !placements.has(dependency)) {
|
|
69
|
+
const pending = waiting.get(dependency) ?? [];
|
|
70
|
+
pending.push({ section, group });
|
|
71
|
+
waiting.set(dependency, pending);
|
|
72
|
+
return body;
|
|
73
|
+
}
|
|
74
|
+
const target =
|
|
75
|
+
dependency !== undefined
|
|
76
|
+
? placements.get(dependency)
|
|
77
|
+
: columns.reduce((a, b) => (a.height <= b.height ? a : b));
|
|
78
|
+
placements.set(section.id, target);
|
|
79
|
+
target.height += estimateSection(section, schema);
|
|
80
|
+
const anchor = anchors.get(dependency);
|
|
81
|
+
if (anchor) {
|
|
82
|
+
anchor.after(group);
|
|
83
|
+
anchors.set(dependency, group);
|
|
84
|
+
} else {
|
|
85
|
+
target.column.append(group);
|
|
86
|
+
}
|
|
87
|
+
anchors.set(section.id, group);
|
|
88
|
+
for (const pending of waiting.get(section.id) ?? []) {
|
|
89
|
+
place(pending.section, pending.group);
|
|
90
|
+
}
|
|
91
|
+
waiting.delete(section.id);
|
|
92
|
+
return target.column;
|
|
93
|
+
};
|
|
94
|
+
return place;
|
|
95
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { fieldVisible, matchesCondition } from './conditions.js';
|
|
2
|
+
|
|
3
|
+
/** ARIA tabs with automatic activation and roving keyboard focus. */
|
|
4
|
+
export function tabBar(
|
|
5
|
+
context,
|
|
6
|
+
parent,
|
|
7
|
+
labels,
|
|
8
|
+
choose,
|
|
9
|
+
id,
|
|
10
|
+
{ label, shared = false }
|
|
11
|
+
) {
|
|
12
|
+
const { node, button } = context;
|
|
13
|
+
const bar = node('div', undefined, parent);
|
|
14
|
+
bar.setAttribute('role', 'tablist');
|
|
15
|
+
bar.setAttribute('aria-label', label);
|
|
16
|
+
const sharedPanel = shared ? node('div', undefined, parent) : null;
|
|
17
|
+
const entries = labels.map((value, index) => {
|
|
18
|
+
const tab = button(value, () => choose(value), bar);
|
|
19
|
+
tab.dataset.tab = value;
|
|
20
|
+
tab.id = `${id}-tab-${index}`;
|
|
21
|
+
tab.setAttribute('role', 'tab');
|
|
22
|
+
const panel = sharedPanel ?? node('div', undefined, parent);
|
|
23
|
+
panel.id = shared ? `${id}-panel` : `${id}-panel-${index}`;
|
|
24
|
+
panel.setAttribute('role', 'tabpanel');
|
|
25
|
+
panel.setAttribute('aria-labelledby', tab.id);
|
|
26
|
+
tab.setAttribute('aria-controls', panel.id);
|
|
27
|
+
tab.addEventListener('keydown', (event) => {
|
|
28
|
+
const visible = entries.filter((e) => !e.tab.hidden);
|
|
29
|
+
const current = visible.findIndex((e) => e.tab === tab);
|
|
30
|
+
let next;
|
|
31
|
+
if (event.key === 'Home') {
|
|
32
|
+
next = 0;
|
|
33
|
+
} else if (event.key === 'End') {
|
|
34
|
+
next = visible.length - 1;
|
|
35
|
+
} else if (
|
|
36
|
+
['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.key)
|
|
37
|
+
) {
|
|
38
|
+
const direction = ['ArrowLeft', 'ArrowUp'].includes(event.key) ? -1 : 1;
|
|
39
|
+
next = (current + direction + visible.length) % visible.length;
|
|
40
|
+
}
|
|
41
|
+
if (next !== undefined) {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
choose(visible[next].value);
|
|
44
|
+
visible[next].tab.focus();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return { value, tab, panel };
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
bar,
|
|
51
|
+
entries,
|
|
52
|
+
sharedPanel,
|
|
53
|
+
update(active, available = labels) {
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
entry.tab.hidden = !available.includes(entry.value);
|
|
56
|
+
const selected = !entry.tab.hidden && entry.value === active;
|
|
57
|
+
entry.tab.setAttribute('aria-selected', String(selected));
|
|
58
|
+
entry.tab.tabIndex = selected ? 0 : -1;
|
|
59
|
+
if (!shared) {
|
|
60
|
+
entry.panel.hidden = !selected || entry.tab.hidden;
|
|
61
|
+
}
|
|
62
|
+
if (shared && selected) {
|
|
63
|
+
sharedPanel.setAttribute('aria-labelledby', entry.tab.id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function sectionChrome(context, section, group) {
|
|
71
|
+
const { id, setTab, setSectionLevel, messages } = context;
|
|
72
|
+
const key = `${id}-section-${section.id}`;
|
|
73
|
+
const levels = section.levels?.length
|
|
74
|
+
? tabBar(
|
|
75
|
+
context,
|
|
76
|
+
group,
|
|
77
|
+
section.levels,
|
|
78
|
+
(level) => setSectionLevel(section.id, level),
|
|
79
|
+
`${key}-levels`,
|
|
80
|
+
{
|
|
81
|
+
label: messages.text('levels', {
|
|
82
|
+
label: section.label ?? section.id,
|
|
83
|
+
}),
|
|
84
|
+
shared: true,
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
: null;
|
|
88
|
+
// Level panels own the level preview; fields retain their identity outside these panels.
|
|
89
|
+
const tabs = section.tabs?.length
|
|
90
|
+
? tabBar(
|
|
91
|
+
context,
|
|
92
|
+
levels?.sharedPanel ?? group,
|
|
93
|
+
section.tabs,
|
|
94
|
+
(tab) => setTab(section.id, tab),
|
|
95
|
+
key,
|
|
96
|
+
{ label: messages.text('tabs', { label: section.label ?? section.id }) }
|
|
97
|
+
)
|
|
98
|
+
: null;
|
|
99
|
+
const preview = mountSectionPreview(
|
|
100
|
+
context,
|
|
101
|
+
section,
|
|
102
|
+
levels?.sharedPanel ?? group
|
|
103
|
+
);
|
|
104
|
+
return {
|
|
105
|
+
tabs,
|
|
106
|
+
levels,
|
|
107
|
+
preview,
|
|
108
|
+
section,
|
|
109
|
+
content: levels?.sharedPanel ?? group,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function refreshSection(chrome, state, context) {
|
|
114
|
+
const { section, tabs, levels, preview } = chrome;
|
|
115
|
+
const { values, shown, level, sectionLevels, selectedTabs, query } = state;
|
|
116
|
+
const activeLevel = sectionLevels[section.id] ?? level ?? section.levels?.[0];
|
|
117
|
+
if (tabs) {
|
|
118
|
+
const available = section.tabs.filter((tab) =>
|
|
119
|
+
section.fields.some(
|
|
120
|
+
(field) =>
|
|
121
|
+
field.props.tab === tab &&
|
|
122
|
+
fieldVisible(
|
|
123
|
+
field,
|
|
124
|
+
values,
|
|
125
|
+
{ tabs: { [section.id]: tab }, level: activeLevel },
|
|
126
|
+
section
|
|
127
|
+
) &&
|
|
128
|
+
`${field.key} ${field.label ?? ''} ${field.description ?? ''} ${section.label ?? ''}`
|
|
129
|
+
.toLocaleLowerCase()
|
|
130
|
+
.includes(query.toLocaleLowerCase())
|
|
131
|
+
)
|
|
132
|
+
);
|
|
133
|
+
if (!available.includes(selectedTabs[section.id] ?? section.tabs[0])) {
|
|
134
|
+
selectedTabs[section.id] = available[0];
|
|
135
|
+
}
|
|
136
|
+
tabs.update(selectedTabs[section.id] ?? section.tabs[0], available);
|
|
137
|
+
tabs.bar.hidden = available.length === 0;
|
|
138
|
+
tabs.bar.setAttribute(
|
|
139
|
+
'aria-label',
|
|
140
|
+
context.messages.text('tabs', { label: section.label ?? section.id })
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (levels) {
|
|
144
|
+
levels.update(activeLevel);
|
|
145
|
+
for (const entry of levels.entries) {
|
|
146
|
+
const owns = section.fields.some(
|
|
147
|
+
(field) =>
|
|
148
|
+
field.props.level === entry.value &&
|
|
149
|
+
matchesCondition(field.props['visible-when'], values) &&
|
|
150
|
+
values[field.key] !== null
|
|
151
|
+
);
|
|
152
|
+
entry.tab.toggleAttribute('data-owned', owns);
|
|
153
|
+
entry.tab.setAttribute(
|
|
154
|
+
'aria-label',
|
|
155
|
+
`${entry.value}${owns ? `: ${context.messages.text('levelOwned')}` : ''}`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
preview?.update?.(shown, section, activeLevel);
|
|
160
|
+
chrome.presets?.update(values);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function mountSectionPreview(context, section, parent) {
|
|
164
|
+
if (!section.preview) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
const container = context.node('div', undefined, parent);
|
|
168
|
+
container.className = 'settings-sticky-preview';
|
|
169
|
+
return context.options.mountPreview?.({
|
|
170
|
+
container,
|
|
171
|
+
section,
|
|
172
|
+
values: context.getValues(),
|
|
173
|
+
level: section.levels?.[0],
|
|
174
|
+
});
|
|
175
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { merge, diff, countCustomized } from '@link-foundation/ui-settings';
|
|
2
|
+
import { createSavedLooks } from './saved-looks.js';
|
|
3
|
+
import { refreshPanel } from './panel-refresh.js';
|
|
4
|
+
import { createRows, createPanelHeader } from './panel-rows.js';
|
|
5
|
+
import { createToolbar, createSharing } from './panel-actions.js';
|
|
6
|
+
|
|
7
|
+
import { createMessages } from './messages.js';
|
|
8
|
+
|
|
9
|
+
let sequence = 0;
|
|
10
|
+
|
|
11
|
+
function initialValues(schema, options) {
|
|
12
|
+
return merge(schema, options.target?.values() ?? options.values, undefined)
|
|
13
|
+
.values;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Create a light-DOM settings-panel element. The optional target is a
|
|
17
|
+
* ui-settings bindConfig binding (user or session), or the same interface.
|
|
18
|
+
* @param {import('@link-foundation/ui-settings').SettingsSchema} schema
|
|
19
|
+
* @param {object} [options]
|
|
20
|
+
*/
|
|
21
|
+
export function createSettingsPanel(schema, options = {}) {
|
|
22
|
+
const doc = options.document ?? globalThis.document;
|
|
23
|
+
const win = doc.defaultView;
|
|
24
|
+
const id = `settings-${++sequence}`;
|
|
25
|
+
const messages = createMessages(options.messages);
|
|
26
|
+
const element = doc.createElement('settings-panel');
|
|
27
|
+
const mode = options.mode ?? 'page';
|
|
28
|
+
element.dataset.mode = mode;
|
|
29
|
+
let values = initialValues(schema, options);
|
|
30
|
+
const tabs = { ...options.tabs };
|
|
31
|
+
let level = options.level;
|
|
32
|
+
const sectionLevels = { ...options.sectionLevels };
|
|
33
|
+
let peeking = false;
|
|
34
|
+
let opener;
|
|
35
|
+
let destroyed = false;
|
|
36
|
+
const { node, button, heading, search, count } = createPanelHeader({
|
|
37
|
+
doc,
|
|
38
|
+
element,
|
|
39
|
+
options,
|
|
40
|
+
messages,
|
|
41
|
+
close: () => close(),
|
|
42
|
+
onSearch: () => refresh(false),
|
|
43
|
+
});
|
|
44
|
+
const close = () => {
|
|
45
|
+
toolbar.endPeek();
|
|
46
|
+
element.hidden = true;
|
|
47
|
+
opener?.focus();
|
|
48
|
+
};
|
|
49
|
+
const context = {
|
|
50
|
+
node,
|
|
51
|
+
button,
|
|
52
|
+
schema,
|
|
53
|
+
options,
|
|
54
|
+
messages,
|
|
55
|
+
win,
|
|
56
|
+
commit,
|
|
57
|
+
getValues: () => values,
|
|
58
|
+
isPeeking: () => peeking,
|
|
59
|
+
};
|
|
60
|
+
const toolbar = createToolbar({
|
|
61
|
+
...context,
|
|
62
|
+
setPeek(value) {
|
|
63
|
+
peeking = value;
|
|
64
|
+
refresh();
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const { rows, sections, chromes } = createRows({
|
|
68
|
+
...context,
|
|
69
|
+
setTab,
|
|
70
|
+
setSectionLevel,
|
|
71
|
+
id,
|
|
72
|
+
});
|
|
73
|
+
const { changes, status, importText, exportText, copy } = createSharing({
|
|
74
|
+
...context,
|
|
75
|
+
isDestroyed: () => destroyed,
|
|
76
|
+
importLooks: (text) => saved.importLooks(text),
|
|
77
|
+
});
|
|
78
|
+
const saved = createSavedLooks({ ...context, status, copy });
|
|
79
|
+
function setTab(section, tab) {
|
|
80
|
+
tabs[section] = tab;
|
|
81
|
+
refresh();
|
|
82
|
+
}
|
|
83
|
+
function setSectionLevel(section, next) {
|
|
84
|
+
sectionLevels[section] = next;
|
|
85
|
+
refresh();
|
|
86
|
+
}
|
|
87
|
+
function refresh(updateControls = true) {
|
|
88
|
+
refreshPanel(
|
|
89
|
+
context,
|
|
90
|
+
{ rows, sections, chromes, search, count, ...toolbar, changes },
|
|
91
|
+
{ values, peeking, tabs, level, sectionLevels },
|
|
92
|
+
updateControls
|
|
93
|
+
);
|
|
94
|
+
toolbar.updatePeek(peeking);
|
|
95
|
+
options.onChangedCount?.(countCustomized(schema, values));
|
|
96
|
+
}
|
|
97
|
+
function commit(changes) {
|
|
98
|
+
if (destroyed || peeking) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const result = normalizeCommit(schema, values, changes, options);
|
|
102
|
+
if (result.rejected.length) {
|
|
103
|
+
messages.content(status, 'rejected', { keys: result.rejected });
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (options.target) {
|
|
107
|
+
options.target.update(result.values);
|
|
108
|
+
values = merge(schema, options.target.values(), undefined).values;
|
|
109
|
+
} else {
|
|
110
|
+
values = result.values;
|
|
111
|
+
}
|
|
112
|
+
refresh();
|
|
113
|
+
options.onChange?.({ ...values }, diff(schema, values));
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
const unsubscribe = options.target?.subscribe?.((next) => {
|
|
117
|
+
values = merge(schema, next, undefined).values;
|
|
118
|
+
refresh();
|
|
119
|
+
});
|
|
120
|
+
const escape = (event) => {
|
|
121
|
+
if (event.key === 'Escape' && mode === 'drawer' && !element.hidden) {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
close();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
doc.addEventListener('keydown', escape);
|
|
127
|
+
refresh();
|
|
128
|
+
if (options.sharedHash) {
|
|
129
|
+
saved.applyShared(options.sharedHash);
|
|
130
|
+
}
|
|
131
|
+
if (mode === 'drawer') {
|
|
132
|
+
element.hidden = true;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
element,
|
|
136
|
+
values: () => globalThis.structuredClone(values),
|
|
137
|
+
update: commit,
|
|
138
|
+
importText,
|
|
139
|
+
exportText,
|
|
140
|
+
...saved,
|
|
141
|
+
setTab,
|
|
142
|
+
setSectionLevel,
|
|
143
|
+
changedCount: () => countCustomized(schema, values),
|
|
144
|
+
setMessages(catalog) {
|
|
145
|
+
messages.update(catalog);
|
|
146
|
+
refresh();
|
|
147
|
+
},
|
|
148
|
+
setLevel(next) {
|
|
149
|
+
level = next;
|
|
150
|
+
refresh();
|
|
151
|
+
},
|
|
152
|
+
open(trigger = doc.activeElement) {
|
|
153
|
+
opener = trigger;
|
|
154
|
+
element.hidden = false;
|
|
155
|
+
heading.focus();
|
|
156
|
+
},
|
|
157
|
+
close,
|
|
158
|
+
destroy() {
|
|
159
|
+
toolbar.endPeek();
|
|
160
|
+
destroyed = true;
|
|
161
|
+
unsubscribe?.();
|
|
162
|
+
toolbar.destroy();
|
|
163
|
+
saved.destroyLooks();
|
|
164
|
+
destroyControls(rows, chromes);
|
|
165
|
+
doc.removeEventListener('keydown', escape);
|
|
166
|
+
element.remove();
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function normalizeCommit(schema, values, changes, options) {
|
|
172
|
+
let result = merge(schema, values, changes);
|
|
173
|
+
if (!result.rejected.length && options.normalizeChanges) {
|
|
174
|
+
result = merge(
|
|
175
|
+
schema,
|
|
176
|
+
values,
|
|
177
|
+
options.normalizeChanges(result.values, changes)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function destroyControls(rows, chromes) {
|
|
184
|
+
for (const chrome of chromes) {
|
|
185
|
+
chrome.preview?.destroy?.();
|
|
186
|
+
chrome.presets?.destroy();
|
|
187
|
+
}
|
|
188
|
+
for (const entry of rows.values()) {
|
|
189
|
+
entry.control.destroy();
|
|
190
|
+
entry.preview?.destroy?.();
|
|
191
|
+
}
|
|
192
|
+
}
|