@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,206 @@
|
|
|
1
|
+
/** Multi-document source editor. Opening a document only edits text. */
|
|
2
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
3
|
+
import { atomOf } from '../layout/dom.js';
|
|
4
|
+
import { createDocumentsModel } from './documents-model.js';
|
|
5
|
+
import { createEditorEngine } from './editor-engine.js';
|
|
6
|
+
import { createEditorUi } from './editor-ui.js';
|
|
7
|
+
|
|
8
|
+
let instances = 0;
|
|
9
|
+
|
|
10
|
+
/** Mount into any host; also used by the custom element. */
|
|
11
|
+
export function mountCodeEditor(
|
|
12
|
+
host,
|
|
13
|
+
{
|
|
14
|
+
storage,
|
|
15
|
+
clock,
|
|
16
|
+
key,
|
|
17
|
+
model = createDocumentsModel({ storage, clock, key }),
|
|
18
|
+
engine = 'codemirror',
|
|
19
|
+
engineOptions,
|
|
20
|
+
...options
|
|
21
|
+
} = {}
|
|
22
|
+
) {
|
|
23
|
+
instances++;
|
|
24
|
+
let adapter;
|
|
25
|
+
let run = 0;
|
|
26
|
+
let stopped = false;
|
|
27
|
+
const ui = createEditorUi(host, model, {
|
|
28
|
+
...options,
|
|
29
|
+
instance: instances,
|
|
30
|
+
confirmClose:
|
|
31
|
+
options.confirmClose ??
|
|
32
|
+
(() =>
|
|
33
|
+
host.ownerDocument.defaultView.confirm(
|
|
34
|
+
'Unsaved changes. Close this document?'
|
|
35
|
+
)),
|
|
36
|
+
focus: (offset) => adapter?.focus(offset),
|
|
37
|
+
});
|
|
38
|
+
const display = async () => {
|
|
39
|
+
const revision = ++run;
|
|
40
|
+
const diagnostics = ui.render();
|
|
41
|
+
if (!adapter) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const active = model.active;
|
|
45
|
+
if (active) {
|
|
46
|
+
await adapter.setDocument(active);
|
|
47
|
+
}
|
|
48
|
+
if (stopped || revision !== run) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
adapter.setDiagnostics(diagnostics);
|
|
52
|
+
host.dataset.ready = 'true';
|
|
53
|
+
};
|
|
54
|
+
const unsubscribe = model.subscribe(() => {
|
|
55
|
+
void display();
|
|
56
|
+
});
|
|
57
|
+
const ready = createEditorEngine(engine, ui.area, {
|
|
58
|
+
...engineOptions,
|
|
59
|
+
label: ui.label,
|
|
60
|
+
onChange: (text, id) => {
|
|
61
|
+
if (model.get(id)) {
|
|
62
|
+
model.edit(id, text);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
.then(async (loaded) => {
|
|
67
|
+
if (stopped) {
|
|
68
|
+
loaded.destroy();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
adapter = loaded;
|
|
72
|
+
await display();
|
|
73
|
+
})
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
if (!stopped) {
|
|
76
|
+
host.dataset.ready = 'error';
|
|
77
|
+
const message = host.ownerDocument.createElement('p');
|
|
78
|
+
message.setAttribute('role', 'alert');
|
|
79
|
+
message.textContent = `Unable to load editor: ${error.message}`;
|
|
80
|
+
ui.area.append(message);
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
});
|
|
84
|
+
// Escape arms a single native Tab escape, including Monaco's Tab handler.
|
|
85
|
+
let escape = false;
|
|
86
|
+
const keyboard = (event) => {
|
|
87
|
+
if (!ui.area.contains(event.target)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (event.key === 'Tab' && escape) {
|
|
91
|
+
event.stopImmediatePropagation();
|
|
92
|
+
escape = false;
|
|
93
|
+
} else {
|
|
94
|
+
escape = event.key === 'Escape';
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
host.addEventListener('keydown', keyboard, true);
|
|
98
|
+
void display();
|
|
99
|
+
return {
|
|
100
|
+
model,
|
|
101
|
+
ready,
|
|
102
|
+
focus: (offset) => adapter?.focus(offset),
|
|
103
|
+
destroy() {
|
|
104
|
+
stopped = true;
|
|
105
|
+
run++;
|
|
106
|
+
unsubscribe();
|
|
107
|
+
adapter?.destroy();
|
|
108
|
+
ui.destroy();
|
|
109
|
+
model.destroy();
|
|
110
|
+
host.removeEventListener('keydown', keyboard, true);
|
|
111
|
+
delete host.dataset.ready;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Define once per window; import remains safe without a browser. */
|
|
117
|
+
export function defineCodeEditor(win = globalThis.window) {
|
|
118
|
+
if (!win?.customElements || win.customElements.get('ui-code-editor')) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
class CodeEditor extends win.HTMLElement {
|
|
122
|
+
constructor() {
|
|
123
|
+
super();
|
|
124
|
+
this.editorOptions = {};
|
|
125
|
+
this._model = null;
|
|
126
|
+
this._mounted = null;
|
|
127
|
+
}
|
|
128
|
+
get model() {
|
|
129
|
+
this._model ??=
|
|
130
|
+
this.editorOptions.model ?? createDocumentsModel(this.editorOptions);
|
|
131
|
+
return this._model;
|
|
132
|
+
}
|
|
133
|
+
get ready() {
|
|
134
|
+
return this._mounted?.ready ?? Promise.resolve();
|
|
135
|
+
}
|
|
136
|
+
openDocument(doc) {
|
|
137
|
+
return this.model.open(doc);
|
|
138
|
+
}
|
|
139
|
+
externalUpdate(id, text) {
|
|
140
|
+
return this.model.externalUpdate(id, text);
|
|
141
|
+
}
|
|
142
|
+
focusEditor(offset) {
|
|
143
|
+
this._mounted?.focus(offset);
|
|
144
|
+
}
|
|
145
|
+
connectedCallback() {
|
|
146
|
+
this._mounted ??= mountCodeEditor(this, {
|
|
147
|
+
...this.editorOptions,
|
|
148
|
+
model: this.model,
|
|
149
|
+
engine:
|
|
150
|
+
this.getAttribute('engine') ??
|
|
151
|
+
this.editorOptions.engine ??
|
|
152
|
+
'codemirror',
|
|
153
|
+
});
|
|
154
|
+
// A visible error is rendered; keep the public ready promise rejectable.
|
|
155
|
+
this.ready.catch(() => {});
|
|
156
|
+
}
|
|
157
|
+
disconnectedCallback() {
|
|
158
|
+
this._mounted?.destroy();
|
|
159
|
+
this._mounted = null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
win.customElements.define('ui-code-editor', CodeEditor);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** LiNo `(source: code-editor (label Source) (value '...'))` integration. */
|
|
166
|
+
export function registerEditor(target) {
|
|
167
|
+
const spec = {
|
|
168
|
+
tag: 'ui-code-editor',
|
|
169
|
+
childrenSlot: null,
|
|
170
|
+
create(el, ctx) {
|
|
171
|
+
defineCodeEditor(ctx.document.defaultView);
|
|
172
|
+
const node = ctx.document.createElement('ui-code-editor');
|
|
173
|
+
node.editorOptions = ctx.options.editor ?? {};
|
|
174
|
+
return node;
|
|
175
|
+
},
|
|
176
|
+
update(node, el) {
|
|
177
|
+
const label = atomOf(el, 'label') ?? 'Source editor';
|
|
178
|
+
node.setAttribute('label', label);
|
|
179
|
+
node.setAttribute('engine', atomOf(el, 'engine') ?? 'codemirror');
|
|
180
|
+
const id = atomOf(el, 'document-id') ?? el.id;
|
|
181
|
+
const text = atomOf(el, 'value') ?? '';
|
|
182
|
+
if (node.model?.get(id)) {
|
|
183
|
+
node.externalUpdate(id, text);
|
|
184
|
+
} else {
|
|
185
|
+
node.openDocument?.({
|
|
186
|
+
id,
|
|
187
|
+
text,
|
|
188
|
+
title: atomOf(el, 'title') ?? id,
|
|
189
|
+
language: atomOf(el, 'language') ?? 'lino',
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
destroy(node) {
|
|
194
|
+
node._mounted?.destroy();
|
|
195
|
+
node._mounted = null;
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
if (target instanceof Map) {
|
|
199
|
+
target.set('code-editor', spec);
|
|
200
|
+
} else if (target) {
|
|
201
|
+
target['code-editor'] = spec;
|
|
202
|
+
} else {
|
|
203
|
+
defineKind('code-editor', spec);
|
|
204
|
+
}
|
|
205
|
+
return spec;
|
|
206
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/** Pure document state. Persistence is LiNo; storage and time are injected. */
|
|
2
|
+
import { createEditorPersistence } from './documents-persistence.js';
|
|
3
|
+
|
|
4
|
+
const defaultClock = {
|
|
5
|
+
setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
|
|
6
|
+
clearTimeout: (id) => globalThis.clearTimeout(id),
|
|
7
|
+
};
|
|
8
|
+
const copy = (doc) => (doc ? { ...doc } : null);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {{storage?: {getItem: Function, setItem: Function}, clock?: {setTimeout: Function, clearTimeout: Function}, key?: string}} [options]
|
|
12
|
+
* Drafts live at `${key}:draft:${encodeURIComponent(id)}`. `editor-tabs` is
|
|
13
|
+
* written immediately; each draft is written 500ms after its last edit.
|
|
14
|
+
*/
|
|
15
|
+
export function createDocumentsModel({
|
|
16
|
+
storage,
|
|
17
|
+
clock = defaultClock,
|
|
18
|
+
key = 'editor-tabs',
|
|
19
|
+
} = {}) {
|
|
20
|
+
const docs = new Map();
|
|
21
|
+
const timers = new Map();
|
|
22
|
+
const listeners = new Set();
|
|
23
|
+
const persistence = createEditorPersistence(storage, key);
|
|
24
|
+
let activeId = persistence.restore(docs);
|
|
25
|
+
const persistTabs = () => persistence.saveTabs(docs, activeId);
|
|
26
|
+
const cancel = (id) => {
|
|
27
|
+
if (timers.has(id)) {
|
|
28
|
+
clock.clearTimeout(timers.get(id));
|
|
29
|
+
timers.delete(id);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const persistDraft = (id) => {
|
|
33
|
+
cancel(id);
|
|
34
|
+
persistence.saveDraft(docs.get(id));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const notify = (type, id) => listeners.forEach((fn) => fn({ type, id }));
|
|
38
|
+
const requireDoc = (id) => requireDocument(docs, id);
|
|
39
|
+
const updateDirty = (doc) => {
|
|
40
|
+
doc.dirty = doc.text !== doc.saved;
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
get documents() {
|
|
44
|
+
return [...docs.values()].map(copy);
|
|
45
|
+
},
|
|
46
|
+
get active() {
|
|
47
|
+
return copy(docs.get(activeId));
|
|
48
|
+
},
|
|
49
|
+
get: (id) => copy(docs.get(id)),
|
|
50
|
+
subscribe(fn) {
|
|
51
|
+
listeners.add(fn);
|
|
52
|
+
return () => listeners.delete(fn);
|
|
53
|
+
},
|
|
54
|
+
open({ id, text = '', title = id, language = 'lino' }) {
|
|
55
|
+
if (typeof id !== 'string' || !id) {
|
|
56
|
+
throw new TypeError('A document needs a nonempty string id');
|
|
57
|
+
}
|
|
58
|
+
if (!docs.has(id)) {
|
|
59
|
+
docs.set(id, {
|
|
60
|
+
id,
|
|
61
|
+
text,
|
|
62
|
+
title,
|
|
63
|
+
language,
|
|
64
|
+
saved: text,
|
|
65
|
+
dirty: false,
|
|
66
|
+
incoming: null,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
activeId = id;
|
|
70
|
+
persistDraft(id);
|
|
71
|
+
persistTabs();
|
|
72
|
+
notify('open', id);
|
|
73
|
+
return copy(docs.get(id));
|
|
74
|
+
},
|
|
75
|
+
switch(id) {
|
|
76
|
+
requireDoc(id);
|
|
77
|
+
activeId = id;
|
|
78
|
+
persistTabs();
|
|
79
|
+
notify('switch', id);
|
|
80
|
+
},
|
|
81
|
+
edit(id, text) {
|
|
82
|
+
const doc = requireDoc(id);
|
|
83
|
+
doc.text = text;
|
|
84
|
+
updateDirty(doc);
|
|
85
|
+
cancel(id);
|
|
86
|
+
timers.set(
|
|
87
|
+
id,
|
|
88
|
+
clock.setTimeout(() => persistDraft(id), 500)
|
|
89
|
+
);
|
|
90
|
+
notify('edit', id);
|
|
91
|
+
},
|
|
92
|
+
save(id) {
|
|
93
|
+
const doc = requireDoc(id);
|
|
94
|
+
if (doc.incoming !== null) {
|
|
95
|
+
throw new Error('Resolve the source conflict before saving');
|
|
96
|
+
}
|
|
97
|
+
doc.saved = doc.text;
|
|
98
|
+
updateDirty(doc);
|
|
99
|
+
persistDraft(id);
|
|
100
|
+
persistTabs();
|
|
101
|
+
notify('save', id);
|
|
102
|
+
return doc.text;
|
|
103
|
+
},
|
|
104
|
+
close(id, { discard = false } = {}) {
|
|
105
|
+
const doc = requireDoc(id);
|
|
106
|
+
if ((doc.dirty || doc.incoming !== null) && !discard) {
|
|
107
|
+
return 'unsaved';
|
|
108
|
+
}
|
|
109
|
+
cancel(id);
|
|
110
|
+
docs.delete(id);
|
|
111
|
+
if (activeId === id) {
|
|
112
|
+
activeId = docs.keys().next().value ?? null;
|
|
113
|
+
}
|
|
114
|
+
persistTabs();
|
|
115
|
+
notify('close', id);
|
|
116
|
+
return 'closed';
|
|
117
|
+
},
|
|
118
|
+
externalUpdate(id, text) {
|
|
119
|
+
const doc = requireDoc(id);
|
|
120
|
+
if (text === doc.saved) {
|
|
121
|
+
return 'unchanged';
|
|
122
|
+
}
|
|
123
|
+
if (doc.dirty || doc.incoming !== null) {
|
|
124
|
+
doc.incoming = text;
|
|
125
|
+
persistDraft(id);
|
|
126
|
+
notify('conflict', id);
|
|
127
|
+
return 'conflict';
|
|
128
|
+
}
|
|
129
|
+
doc.saved = text;
|
|
130
|
+
doc.text = text;
|
|
131
|
+
updateDirty(doc);
|
|
132
|
+
persistDraft(id);
|
|
133
|
+
persistTabs();
|
|
134
|
+
notify('external', id);
|
|
135
|
+
return 'updated';
|
|
136
|
+
},
|
|
137
|
+
resolve(id, choice) {
|
|
138
|
+
const doc = requireDoc(id);
|
|
139
|
+
if (!['mine', 'theirs'].includes(choice)) {
|
|
140
|
+
throw new TypeError('Choose mine or theirs');
|
|
141
|
+
}
|
|
142
|
+
if (doc.incoming === null) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
doc.saved = doc.incoming;
|
|
146
|
+
if (choice === 'theirs') {
|
|
147
|
+
doc.text = doc.incoming;
|
|
148
|
+
}
|
|
149
|
+
doc.incoming = null;
|
|
150
|
+
updateDirty(doc);
|
|
151
|
+
persistDraft(id);
|
|
152
|
+
persistTabs();
|
|
153
|
+
notify('resolve', id);
|
|
154
|
+
},
|
|
155
|
+
destroy() {
|
|
156
|
+
for (const id of timers.keys()) {
|
|
157
|
+
persistDraft(id);
|
|
158
|
+
}
|
|
159
|
+
persistTabs();
|
|
160
|
+
listeners.clear();
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function requireDocument(docs, id) {
|
|
166
|
+
if (!docs.has(id)) {
|
|
167
|
+
throw new Error(`Unknown editor document: ${id}`);
|
|
168
|
+
}
|
|
169
|
+
return docs.get(id);
|
|
170
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** LiNo storage adapter for document tabs, bases, drafts and conflicts. */
|
|
2
|
+
import { Parser, Link } from 'links-notation';
|
|
3
|
+
import { formatLinks } from '@link-foundation/ui-core';
|
|
4
|
+
|
|
5
|
+
const field = (name, value) =>
|
|
6
|
+
new Link(null, [new Link(name), new Link(value)]);
|
|
7
|
+
const fieldsOf = (group) =>
|
|
8
|
+
new Map(
|
|
9
|
+
group.children.map((g) => [
|
|
10
|
+
g.element.values[0]?.id,
|
|
11
|
+
g.element.values[1]?.id,
|
|
12
|
+
])
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export function createEditorPersistence(storage, key) {
|
|
16
|
+
const draftKey = (id) => `${key}:draft:${encodeURIComponent(id)}`;
|
|
17
|
+
const read = (name) => {
|
|
18
|
+
const text = storage?.getItem(name);
|
|
19
|
+
return text ? new Parser().parseGroups(text) : [];
|
|
20
|
+
};
|
|
21
|
+
const write = (name, links) => storage?.setItem(name, formatLinks(links));
|
|
22
|
+
return {
|
|
23
|
+
restore(docs) {
|
|
24
|
+
const tabs = read(key)[0];
|
|
25
|
+
if (!tabs) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
for (const group of tabs.children.filter(
|
|
29
|
+
(g) => g.element.id === 'document'
|
|
30
|
+
)) {
|
|
31
|
+
const data = fieldsOf(group);
|
|
32
|
+
const id = data.get('id');
|
|
33
|
+
if (typeof id !== 'string') {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const stored = read(draftKey(id))[0];
|
|
37
|
+
const draft = stored ? fieldsOf(stored) : new Map();
|
|
38
|
+
const saved = draft.get('saved') ?? data.get('saved') ?? '';
|
|
39
|
+
const text = draft.get('text') ?? saved;
|
|
40
|
+
docs.set(id, {
|
|
41
|
+
id,
|
|
42
|
+
title: data.get('title') ?? id,
|
|
43
|
+
language: data.get('language') ?? 'lino',
|
|
44
|
+
saved,
|
|
45
|
+
text,
|
|
46
|
+
dirty: text !== saved,
|
|
47
|
+
incoming:
|
|
48
|
+
draft.get('has-conflict') === 'true'
|
|
49
|
+
? (draft.get('incoming') ?? '')
|
|
50
|
+
: null,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const active = fieldsOf(tabs).get('active');
|
|
54
|
+
return docs.has(active) ? active : (docs.keys().next().value ?? null);
|
|
55
|
+
},
|
|
56
|
+
saveTabs(docs, activeId) {
|
|
57
|
+
write(key, [
|
|
58
|
+
new Link('tabs', [
|
|
59
|
+
field('active', activeId ?? ''),
|
|
60
|
+
...[...docs.values()].map(
|
|
61
|
+
(doc) =>
|
|
62
|
+
new Link('document', [
|
|
63
|
+
field('id', doc.id),
|
|
64
|
+
field('title', doc.title),
|
|
65
|
+
field('language', doc.language),
|
|
66
|
+
field('saved', doc.saved),
|
|
67
|
+
])
|
|
68
|
+
),
|
|
69
|
+
]),
|
|
70
|
+
]);
|
|
71
|
+
},
|
|
72
|
+
saveDraft(doc) {
|
|
73
|
+
if (doc) {
|
|
74
|
+
write(draftKey(doc.id), [
|
|
75
|
+
new Link('draft', [
|
|
76
|
+
field('text', doc.text),
|
|
77
|
+
field('saved', doc.saved),
|
|
78
|
+
field('has-conflict', String(doc.incoming !== null)),
|
|
79
|
+
field('incoming', doc.incoming ?? ''),
|
|
80
|
+
]),
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine contract. Adapters own editor state, history, selection and disposal.
|
|
3
|
+
* @typedef {object} EditorEngine
|
|
4
|
+
* @property {(document: {id: string, text: string, language: string}) => (void|Promise<void>)} setDocument
|
|
5
|
+
* @property {(diagnostics: object[]) => void} setDiagnostics
|
|
6
|
+
* @property {(readOnly: boolean) => void} setReadOnly
|
|
7
|
+
* @property {(offset?: number) => void} focus
|
|
8
|
+
* @property {() => void} destroy
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** No engine code or optional Monaco dependency loads until selected. */
|
|
12
|
+
export async function createEditorEngine(name, parent, options = {}) {
|
|
13
|
+
if (name === 'codemirror') {
|
|
14
|
+
const { createCodeMirrorEngine } = await import('./engines/codemirror.js');
|
|
15
|
+
return createCodeMirrorEngine(parent, options);
|
|
16
|
+
}
|
|
17
|
+
if (name === 'monaco') {
|
|
18
|
+
const { createMonacoEngine } = await import('./engines/monaco.js');
|
|
19
|
+
return createMonacoEngine(parent, options);
|
|
20
|
+
}
|
|
21
|
+
throw new TypeError(`Unknown editor engine: ${name}`);
|
|
22
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/** Light DOM parts, using the existing controls and APG roving tabs helper. */
|
|
2
|
+
import { mountControls } from '../controls/index.js';
|
|
3
|
+
import { createRovingTabindex } from '../a11y/index.js';
|
|
4
|
+
import { formatLinks } from '@link-foundation/ui-core';
|
|
5
|
+
import { Link } from 'links-notation';
|
|
6
|
+
import { diagnosticOffset, validateLino } from './validate-lino.js';
|
|
7
|
+
|
|
8
|
+
const make = (doc, tag, attrs = {}, text) => {
|
|
9
|
+
const node = doc.createElement(tag);
|
|
10
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
11
|
+
node.setAttribute(key, value);
|
|
12
|
+
}
|
|
13
|
+
if (text !== undefined) {
|
|
14
|
+
node.textContent = text;
|
|
15
|
+
}
|
|
16
|
+
return node;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function buttons(parent, labels, click) {
|
|
20
|
+
const source = formatLinks(
|
|
21
|
+
labels.map(
|
|
22
|
+
(label, index) =>
|
|
23
|
+
new Link(`${parent.id}-action-${index}`, [
|
|
24
|
+
new Link('button'),
|
|
25
|
+
new Link(null, [new Link('label'), new Link(label)]),
|
|
26
|
+
])
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
const mounted = mountControls(parent, source);
|
|
30
|
+
[...parent.querySelectorAll('button')].forEach((button, index) =>
|
|
31
|
+
button.addEventListener('click', () => click(index))
|
|
32
|
+
);
|
|
33
|
+
return mounted;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function updateTabs(tabs, panel, prefix, documents, current) {
|
|
37
|
+
const doc = tabs.ownerDocument;
|
|
38
|
+
const ids = new Set(documents.map((item) => item.id));
|
|
39
|
+
for (const tab of [...tabs.children]) {
|
|
40
|
+
if (!ids.has(tab.dataset.documentId)) {
|
|
41
|
+
tab.remove();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const item of documents) {
|
|
45
|
+
let tab = [...tabs.children].find((t) => t.dataset.documentId === item.id);
|
|
46
|
+
if (!tab) {
|
|
47
|
+
tab = make(doc, 'button', {
|
|
48
|
+
type: 'button',
|
|
49
|
+
role: 'tab',
|
|
50
|
+
id: `${prefix}-tab-${encodeURIComponent(item.id)}`,
|
|
51
|
+
'aria-controls': panel.id,
|
|
52
|
+
});
|
|
53
|
+
tab.dataset.documentId = item.id;
|
|
54
|
+
tabs.append(tab);
|
|
55
|
+
}
|
|
56
|
+
tab.textContent = `${item.title}${item.dirty ? ' •' : ''}`;
|
|
57
|
+
tab.setAttribute('aria-selected', String(item.id === current?.id));
|
|
58
|
+
tab.tabIndex = item.id === current?.id ? 0 : -1;
|
|
59
|
+
}
|
|
60
|
+
panel.hidden = !current;
|
|
61
|
+
if (current) {
|
|
62
|
+
panel.setAttribute(
|
|
63
|
+
'aria-labelledby',
|
|
64
|
+
`${prefix}-tab-${encodeURIComponent(current.id)}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Create parts once so editing never replaces the focused editor or tab. */
|
|
70
|
+
export function createEditorUi(host, model, options) {
|
|
71
|
+
const doc = host.ownerDocument;
|
|
72
|
+
const label = options.label ?? host.getAttribute('label') ?? 'Source editor';
|
|
73
|
+
const prefix = host.id || `ui-editor-${options.instance}`;
|
|
74
|
+
const tabs = make(doc, 'div', { role: 'tablist', 'aria-label': 'Documents' });
|
|
75
|
+
const toolbar = make(doc, 'div', {
|
|
76
|
+
id: `${prefix}-toolbar`,
|
|
77
|
+
class: 'ui-editor-toolbar',
|
|
78
|
+
'aria-label': 'Document actions',
|
|
79
|
+
role: 'group',
|
|
80
|
+
});
|
|
81
|
+
const panel = make(doc, 'div', { role: 'tabpanel', id: `${prefix}-panel` });
|
|
82
|
+
const area = make(doc, 'div', { class: 'ui-editor-area' });
|
|
83
|
+
const conflicts = make(doc, 'div', {
|
|
84
|
+
class: 'ui-editor-conflict',
|
|
85
|
+
role: 'region',
|
|
86
|
+
'aria-label': 'Source changed',
|
|
87
|
+
hidden: '',
|
|
88
|
+
});
|
|
89
|
+
const prompt = make(doc, 'p', {}, 'The source changed.');
|
|
90
|
+
const actions = make(doc, 'div', { id: `${prefix}-conflict-actions` });
|
|
91
|
+
conflicts.append(prompt, actions);
|
|
92
|
+
const compare = make(doc, 'div', { class: 'ui-editor-compare', hidden: '' });
|
|
93
|
+
const live = make(doc, 'div', {
|
|
94
|
+
'aria-live': 'polite',
|
|
95
|
+
'aria-atomic': 'true',
|
|
96
|
+
});
|
|
97
|
+
const list = make(doc, 'ul', { 'aria-label': 'Diagnostics' });
|
|
98
|
+
live.append(list);
|
|
99
|
+
panel.append(conflicts, compare, area, live);
|
|
100
|
+
host.replaceChildren(tabs, toolbar, panel);
|
|
101
|
+
const mounts = [
|
|
102
|
+
buttons(toolbar, ['Save', 'Close document'], (index) => {
|
|
103
|
+
const current = model.active;
|
|
104
|
+
if (!current) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (index === 0) {
|
|
108
|
+
const text = model.save(current.id);
|
|
109
|
+
host.dispatchEvent(
|
|
110
|
+
new doc.defaultView.CustomEvent('ui-save', {
|
|
111
|
+
bubbles: true,
|
|
112
|
+
detail: { id: current.id, text },
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
} else if (
|
|
116
|
+
model.close(current.id) === 'unsaved' &&
|
|
117
|
+
options.confirmClose(current)
|
|
118
|
+
) {
|
|
119
|
+
model.close(current.id, { discard: true });
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
buttons(actions, ['Keep mine', 'Load theirs', 'Compare'], (index) => {
|
|
123
|
+
if (index === 2) {
|
|
124
|
+
showCompare(model.active);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
model.resolve(model.active.id, index === 0 ? 'mine' : 'theirs');
|
|
128
|
+
compare.hidden = true;
|
|
129
|
+
}),
|
|
130
|
+
];
|
|
131
|
+
const roving = createRovingTabindex(() => [...tabs.children], {
|
|
132
|
+
onChange: (index, tab) => model.switch(tab.dataset.documentId),
|
|
133
|
+
});
|
|
134
|
+
const detach = roving.attach(tabs);
|
|
135
|
+
tabs.addEventListener('click', (event) => {
|
|
136
|
+
const tab = event.target.closest('[role=tab]');
|
|
137
|
+
if (tab && tabs.contains(tab)) {
|
|
138
|
+
roving.focus([...tabs.children].indexOf(tab));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const showCompare = (current) => {
|
|
142
|
+
compare.replaceChildren();
|
|
143
|
+
for (const [title, text] of [
|
|
144
|
+
['Mine', current.text],
|
|
145
|
+
['Theirs', current.incoming],
|
|
146
|
+
]) {
|
|
147
|
+
const section = make(doc, 'section', { 'aria-label': title });
|
|
148
|
+
section.append(make(doc, 'h3', {}, title), make(doc, 'pre', {}, text));
|
|
149
|
+
compare.append(section);
|
|
150
|
+
}
|
|
151
|
+
compare.hidden = false;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
area,
|
|
156
|
+
label,
|
|
157
|
+
render() {
|
|
158
|
+
const current = model.active;
|
|
159
|
+
updateTabs(tabs, panel, prefix, model.documents, current);
|
|
160
|
+
const controls = toolbar.querySelectorAll('button');
|
|
161
|
+
controls[0].disabled = !current || current.incoming !== null;
|
|
162
|
+
controls[1].disabled = !current;
|
|
163
|
+
conflicts.hidden = !current || current.incoming === null;
|
|
164
|
+
if (conflicts.hidden) {
|
|
165
|
+
compare.hidden = true;
|
|
166
|
+
} else if (!compare.hidden) {
|
|
167
|
+
showCompare(current);
|
|
168
|
+
}
|
|
169
|
+
const diagnostics =
|
|
170
|
+
current?.language === 'lino'
|
|
171
|
+
? validateLino(current.text).diagnostics
|
|
172
|
+
: [];
|
|
173
|
+
const summary = diagnostics
|
|
174
|
+
.map((d) => `${d.line}:${d.column} ${d.message}`)
|
|
175
|
+
.join('\n');
|
|
176
|
+
if (list.dataset.summary !== summary) {
|
|
177
|
+
list.dataset.summary = summary;
|
|
178
|
+
list.replaceChildren(
|
|
179
|
+
...diagnostics.map((d) => {
|
|
180
|
+
const item = make(doc, 'li');
|
|
181
|
+
const button = make(
|
|
182
|
+
doc,
|
|
183
|
+
'button',
|
|
184
|
+
{ type: 'button' },
|
|
185
|
+
`${d.line}:${d.column} ${d.message}`
|
|
186
|
+
);
|
|
187
|
+
button.addEventListener('click', () =>
|
|
188
|
+
options.focus(diagnosticOffset(current.text, d))
|
|
189
|
+
);
|
|
190
|
+
item.append(button);
|
|
191
|
+
return item;
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
host.dataset.dirty = String(current?.dirty ?? false);
|
|
196
|
+
return diagnostics;
|
|
197
|
+
},
|
|
198
|
+
destroy() {
|
|
199
|
+
detach();
|
|
200
|
+
mounts.forEach((m) => m.destroy());
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|