@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,191 @@
|
|
|
1
|
+
import { isUnsafeUrl } from '@link-foundation/ui-dom';
|
|
2
|
+
import { deliveryStatus } from './chat-model.js';
|
|
3
|
+
import {
|
|
4
|
+
capability,
|
|
5
|
+
chatOf,
|
|
6
|
+
chatOptions,
|
|
7
|
+
chatRecords,
|
|
8
|
+
emit,
|
|
9
|
+
make,
|
|
10
|
+
recordOf,
|
|
11
|
+
registerChatKind,
|
|
12
|
+
} from './dom.js';
|
|
13
|
+
import { drawReasoning } from './reasoning-trace.js';
|
|
14
|
+
|
|
15
|
+
export const messageActions = (chat, message) =>
|
|
16
|
+
['reply', 'react', 'edit'].filter((action) =>
|
|
17
|
+
capability(chat, message, `can-${action}`)
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
function messageText(message, document, options) {
|
|
21
|
+
const text = make(document, 'div', { class: 'ui-chat-text' });
|
|
22
|
+
const renderer = options.slots?.message;
|
|
23
|
+
if (renderer) {
|
|
24
|
+
const rendered = renderer(message, { document });
|
|
25
|
+
text.append(
|
|
26
|
+
typeof rendered === 'string'
|
|
27
|
+
? document.createTextNode(rendered)
|
|
28
|
+
: rendered
|
|
29
|
+
);
|
|
30
|
+
} else {
|
|
31
|
+
text.textContent = message.text ?? '';
|
|
32
|
+
}
|
|
33
|
+
return text;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function attachments(message, records, document) {
|
|
37
|
+
const content = [];
|
|
38
|
+
for (const attachment of records.filter(
|
|
39
|
+
(r) => r.kind === 'attachment' && r.message === message.id
|
|
40
|
+
)) {
|
|
41
|
+
const safe = attachment.url && !isUnsafeUrl(attachment.url);
|
|
42
|
+
content.push(
|
|
43
|
+
make(
|
|
44
|
+
document,
|
|
45
|
+
safe ? 'a' : 'span',
|
|
46
|
+
safe
|
|
47
|
+
? {
|
|
48
|
+
href: attachment.url,
|
|
49
|
+
rel: 'noopener noreferrer',
|
|
50
|
+
class: 'ui-chat-attachment',
|
|
51
|
+
}
|
|
52
|
+
: {},
|
|
53
|
+
attachment.name ?? attachment.id
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return content;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function reactions(node, message, chat, records, document) {
|
|
61
|
+
const content = [];
|
|
62
|
+
for (const reaction of records.filter(
|
|
63
|
+
(r) => r.kind === 'reaction' && r.message === message.id
|
|
64
|
+
)) {
|
|
65
|
+
const button = make(
|
|
66
|
+
document,
|
|
67
|
+
'button',
|
|
68
|
+
{
|
|
69
|
+
type: 'button',
|
|
70
|
+
'aria-pressed': String(reaction.selected ?? false),
|
|
71
|
+
disabled: !capability(chat, message, 'can-react'),
|
|
72
|
+
},
|
|
73
|
+
`${reaction.emoji} ${reaction.count ?? 1}`
|
|
74
|
+
);
|
|
75
|
+
button.addEventListener('click', () =>
|
|
76
|
+
emit(node, 'ui-chat-action', {
|
|
77
|
+
action: 'react',
|
|
78
|
+
message: message.id,
|
|
79
|
+
reaction: reaction.id,
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
content.push(button);
|
|
83
|
+
}
|
|
84
|
+
return content;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function delivery(message, document, options) {
|
|
88
|
+
const content = [];
|
|
89
|
+
const status = deliveryStatus(message);
|
|
90
|
+
const ticks = {
|
|
91
|
+
pending: '◷',
|
|
92
|
+
sending: '◷',
|
|
93
|
+
sent: '✓',
|
|
94
|
+
delivered: '✓✓',
|
|
95
|
+
read: '✓✓',
|
|
96
|
+
failed: '!',
|
|
97
|
+
};
|
|
98
|
+
if (status) {
|
|
99
|
+
content.push(
|
|
100
|
+
make(
|
|
101
|
+
document,
|
|
102
|
+
'span',
|
|
103
|
+
{
|
|
104
|
+
class: 'ui-chat-delivery',
|
|
105
|
+
'aria-label': options.labels?.[status] ?? status,
|
|
106
|
+
},
|
|
107
|
+
ticks[status] ?? status
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return content;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function replyQuote(node, message, records, document, options) {
|
|
115
|
+
const content = [];
|
|
116
|
+
const reply = records.find((r) => r.id === message['reply-to']);
|
|
117
|
+
if (message['reply-to']) {
|
|
118
|
+
const quote = make(
|
|
119
|
+
document,
|
|
120
|
+
'button',
|
|
121
|
+
{ type: 'button', class: 'ui-chat-reply' },
|
|
122
|
+
reply?.text ?? options.labels?.unavailable ?? 'Earlier message'
|
|
123
|
+
);
|
|
124
|
+
quote.addEventListener('click', () =>
|
|
125
|
+
emit(node, 'ui-chat-jump', { id: message['reply-to'] })
|
|
126
|
+
);
|
|
127
|
+
content.push(quote);
|
|
128
|
+
}
|
|
129
|
+
return content;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Text is always a text node; rich text is a trusted host renderer slot. */
|
|
133
|
+
export function drawBubble(node, message, ctx) {
|
|
134
|
+
const { document } = ctx;
|
|
135
|
+
const options = chatOptions(ctx);
|
|
136
|
+
const records = chatRecords(ctx);
|
|
137
|
+
const chat = chatOf(message, ctx);
|
|
138
|
+
node.className = `ui-chat-bubble${message.outgoing ? ' outgoing' : ''}${message.service ? ' service' : ''}`;
|
|
139
|
+
node.dataset.status = deliveryStatus(message) ?? '';
|
|
140
|
+
const content = [];
|
|
141
|
+
const person = records.find((r) => r.id === message.sender);
|
|
142
|
+
if (!message.service) {
|
|
143
|
+
content.push(
|
|
144
|
+
make(
|
|
145
|
+
document,
|
|
146
|
+
'strong',
|
|
147
|
+
{ class: 'ui-chat-sender' },
|
|
148
|
+
person?.name ?? message.sender ?? ''
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
content.push(...replyQuote(node, message, records, document, options));
|
|
153
|
+
content.push(messageText(message, document, options));
|
|
154
|
+
content.push(...attachments(message, records, document));
|
|
155
|
+
content.push(...reactions(node, message, chat, records, document));
|
|
156
|
+
const steps = records.filter(
|
|
157
|
+
(r) => r.kind === 'step' && r.message === message.id
|
|
158
|
+
);
|
|
159
|
+
if (steps.length) {
|
|
160
|
+
const trace = make(document, 'div');
|
|
161
|
+
drawReasoning(trace, steps, { document, ...options });
|
|
162
|
+
content.push(trace);
|
|
163
|
+
}
|
|
164
|
+
content.push(...delivery(message, document, options));
|
|
165
|
+
if (!message.service && messageActions(chat, message).length) {
|
|
166
|
+
const button = make(
|
|
167
|
+
document,
|
|
168
|
+
'button',
|
|
169
|
+
{
|
|
170
|
+
type: 'button',
|
|
171
|
+
class: 'ui-chat-actions',
|
|
172
|
+
'aria-label': options.labels?.actions ?? 'Message actions',
|
|
173
|
+
'aria-haspopup': 'menu',
|
|
174
|
+
},
|
|
175
|
+
'···'
|
|
176
|
+
);
|
|
177
|
+
button.addEventListener('click', () =>
|
|
178
|
+
emit(node, 'ui-chat-open-actions', { id: message.id, anchor: button })
|
|
179
|
+
);
|
|
180
|
+
content.push(button);
|
|
181
|
+
}
|
|
182
|
+
node.replaceChildren(...content);
|
|
183
|
+
}
|
|
184
|
+
registerChatKind('message-bubble', (node, _el, ctx) => ({
|
|
185
|
+
update(el) {
|
|
186
|
+
const message = recordOf(el, ctx);
|
|
187
|
+
if (message) {
|
|
188
|
+
drawBubble(node, message, ctx);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
}));
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { calendarDay, messageRuns } from './chat-model.js';
|
|
2
|
+
import { createViewport } from '../data/viewport.js';
|
|
3
|
+
import { drawBubble } from './message-bubble.js';
|
|
4
|
+
import { drawDay } from './day-separator.js';
|
|
5
|
+
import { createFollow, firstUnread } from './follow.js';
|
|
6
|
+
import { createChatSelection } from './selection.js';
|
|
7
|
+
import { createChatActions } from './actions.js';
|
|
8
|
+
import { streamKeydown } from './stream-keys.js';
|
|
9
|
+
import {
|
|
10
|
+
atomOf,
|
|
11
|
+
chatOptions,
|
|
12
|
+
chatRecords,
|
|
13
|
+
make,
|
|
14
|
+
registerChatKind,
|
|
15
|
+
} from './dom.js';
|
|
16
|
+
|
|
17
|
+
function listenStream(
|
|
18
|
+
node,
|
|
19
|
+
state,
|
|
20
|
+
stream,
|
|
21
|
+
follow,
|
|
22
|
+
jump,
|
|
23
|
+
{ ctx, older, newer, newest }
|
|
24
|
+
) {
|
|
25
|
+
let pendingFrame = null;
|
|
26
|
+
const { root, selection, actions, viewport } = state;
|
|
27
|
+
const run = (promise) => promise?.catch(() => {});
|
|
28
|
+
const listeners = [];
|
|
29
|
+
const listen = (target, type, fn) => {
|
|
30
|
+
target.addEventListener(type, fn);
|
|
31
|
+
listeners.push(() => target.removeEventListener(type, fn));
|
|
32
|
+
};
|
|
33
|
+
listen(older, 'click', () => {
|
|
34
|
+
follow.pause();
|
|
35
|
+
run(stream?.loadOlder());
|
|
36
|
+
});
|
|
37
|
+
listen(newer, 'click', () => run(stream?.loadNewer()));
|
|
38
|
+
listen(newest, 'click', () => {
|
|
39
|
+
follow.toBottom();
|
|
40
|
+
});
|
|
41
|
+
listen(node, 'ui-chat-jump', (event) => run(jump(event.detail.id)));
|
|
42
|
+
listen(node, 'ui-chat-open-actions', (event) => {
|
|
43
|
+
const message = state.messages.find((m) => m.id === event.detail.id);
|
|
44
|
+
if (message) {
|
|
45
|
+
actions.open(message, event.detail.anchor);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
listen(root, 'keydown', (event) => streamKeydown(event, state));
|
|
49
|
+
listen(root, 'contextmenu', (event) => {
|
|
50
|
+
const row = event.target.closest('[data-message]');
|
|
51
|
+
const message = state.messages.find((m) => m.id === row?.dataset.message);
|
|
52
|
+
if (message) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
row.focus({ preventScroll: true });
|
|
55
|
+
actions.open(message, row, { x: event.clientX, y: event.clientY });
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
listen(root, 'click', (event) => {
|
|
59
|
+
const row = event.target.closest('[data-message]');
|
|
60
|
+
if (!row || event.target.closest('button, a, summary, details')) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
state.active = row.dataset.message;
|
|
64
|
+
selection.select(state.active, {
|
|
65
|
+
toggle: event.ctrlKey || event.metaKey,
|
|
66
|
+
range: event.shiftKey,
|
|
67
|
+
keys: state.messages.map((m) => m.id),
|
|
68
|
+
});
|
|
69
|
+
viewport.setActive(state.active);
|
|
70
|
+
viewport.render();
|
|
71
|
+
row.focus({ preventScroll: true });
|
|
72
|
+
});
|
|
73
|
+
listen(root, 'scroll', () => {
|
|
74
|
+
if (!state.messages.length || !stream || pendingFrame !== null) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
pendingFrame = ctx.document.defaultView.requestAnimationFrame(() => {
|
|
78
|
+
pendingFrame = null;
|
|
79
|
+
const snapshot = stream.state();
|
|
80
|
+
if (snapshot.loading) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
root.scrollTop < stream.prefetch * 30 &&
|
|
85
|
+
!follow.state().following &&
|
|
86
|
+
snapshot.hasOlder
|
|
87
|
+
) {
|
|
88
|
+
run(stream.loadOlder());
|
|
89
|
+
} else if (
|
|
90
|
+
root.scrollHeight - root.clientHeight - root.scrollTop <
|
|
91
|
+
stream.prefetch * 30 &&
|
|
92
|
+
snapshot.hasNewer
|
|
93
|
+
) {
|
|
94
|
+
run(stream.loadNewer());
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
return () => {
|
|
99
|
+
listeners.forEach((fn) => fn());
|
|
100
|
+
if (pendingFrame !== null) {
|
|
101
|
+
ctx.document.defaultView.cancelAnimationFrame(pendingFrame);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function renderStatus(snapshot, root, older, newer, status, options) {
|
|
107
|
+
root.setAttribute('aria-busy', String(snapshot.loading));
|
|
108
|
+
older.disabled = snapshot.loading || !snapshot.hasOlder;
|
|
109
|
+
newer.disabled = snapshot.loading || !snapshot.hasNewer;
|
|
110
|
+
status.textContent =
|
|
111
|
+
snapshot.error?.message ??
|
|
112
|
+
(snapshot.loading
|
|
113
|
+
? (options.labels?.loading ?? 'Loading')
|
|
114
|
+
: snapshot.messages.length
|
|
115
|
+
? ''
|
|
116
|
+
: (options.labels?.empty ?? 'No messages'));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function sameRowContent(row, message, previous, state) {
|
|
120
|
+
return (
|
|
121
|
+
row._message === message &&
|
|
122
|
+
row._version === state.version &&
|
|
123
|
+
row._previous === previous?.id &&
|
|
124
|
+
row._unread === (state.unread === message.id)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function rowDrawer(state, ctx, options) {
|
|
129
|
+
return (row, message, index) => {
|
|
130
|
+
const { selection, runStarts, highlighted, unread, version } = state;
|
|
131
|
+
row.dataset.message = message.id;
|
|
132
|
+
row.classList.toggle('ui-chat-run-continued', !runStarts.has(message.id));
|
|
133
|
+
row.setAttribute('role', 'article');
|
|
134
|
+
row.setAttribute(
|
|
135
|
+
'aria-label',
|
|
136
|
+
`${message.sender ?? ''}: ${message.text ?? ''}`
|
|
137
|
+
);
|
|
138
|
+
row.tabIndex = message.id === state.active ? 0 : -1;
|
|
139
|
+
row.classList.toggle(
|
|
140
|
+
'ui-chat-selected',
|
|
141
|
+
selection.state().selected.has(message.id)
|
|
142
|
+
);
|
|
143
|
+
row.classList.toggle('ui-chat-highlighted', highlighted === message.id);
|
|
144
|
+
const previous = state.messages[index - 1];
|
|
145
|
+
if (sameRowContent(row, message, previous, state)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const children = [];
|
|
149
|
+
if (
|
|
150
|
+
message.time &&
|
|
151
|
+
(!previous ||
|
|
152
|
+
calendarDay(message.time, options.timeZone) !==
|
|
153
|
+
calendarDay(previous.time, options.timeZone))
|
|
154
|
+
) {
|
|
155
|
+
const day = make(ctx.document, 'div');
|
|
156
|
+
drawDay(day, message.time, options);
|
|
157
|
+
children.push(day);
|
|
158
|
+
}
|
|
159
|
+
if (unread === message.id) {
|
|
160
|
+
children.push(
|
|
161
|
+
make(
|
|
162
|
+
ctx.document,
|
|
163
|
+
'div',
|
|
164
|
+
{
|
|
165
|
+
class: 'ui-chat-unread',
|
|
166
|
+
role: 'separator',
|
|
167
|
+
'aria-label': options.labels?.unread ?? 'Unread messages',
|
|
168
|
+
},
|
|
169
|
+
options.labels?.unread ?? 'Unread messages'
|
|
170
|
+
)
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const bubble = make(ctx.document, 'div');
|
|
174
|
+
drawBubble(bubble, message, ctx);
|
|
175
|
+
children.push(bubble);
|
|
176
|
+
row.replaceChildren(...children);
|
|
177
|
+
row._message = message;
|
|
178
|
+
row._version = version;
|
|
179
|
+
row._previous = previous?.id;
|
|
180
|
+
row._unread = unread === message.id;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function createStream(node, initial, ctx) {
|
|
185
|
+
const options = chatOptions(ctx);
|
|
186
|
+
const stream = options.windows?.[atomOf(initial, 'source')];
|
|
187
|
+
const root = make(ctx.document, 'div', {
|
|
188
|
+
class: 'ui-chat-scroll',
|
|
189
|
+
role: 'region',
|
|
190
|
+
'aria-label': atomOf(initial, 'label') ?? 'Messages',
|
|
191
|
+
tabindex: '0',
|
|
192
|
+
});
|
|
193
|
+
const body = make(ctx.document, 'div', { class: 'ui-chat-body' });
|
|
194
|
+
const status = make(ctx.document, 'div', {
|
|
195
|
+
class: 'ui-chat-status',
|
|
196
|
+
role: 'status',
|
|
197
|
+
'aria-live': 'polite',
|
|
198
|
+
});
|
|
199
|
+
const older = make(
|
|
200
|
+
ctx.document,
|
|
201
|
+
'button',
|
|
202
|
+
{ type: 'button' },
|
|
203
|
+
options.labels?.older ?? 'Load older'
|
|
204
|
+
);
|
|
205
|
+
const newer = make(
|
|
206
|
+
ctx.document,
|
|
207
|
+
'button',
|
|
208
|
+
{ type: 'button' },
|
|
209
|
+
options.labels?.newer ?? 'Load newer'
|
|
210
|
+
);
|
|
211
|
+
const newest = make(
|
|
212
|
+
ctx.document,
|
|
213
|
+
'button',
|
|
214
|
+
{ type: 'button' },
|
|
215
|
+
options.labels?.bottom ?? 'Follow latest'
|
|
216
|
+
);
|
|
217
|
+
const toolbar = make(ctx.document, 'div', { class: 'ui-chat-toolbar' });
|
|
218
|
+
toolbar.append(older, newer, newest);
|
|
219
|
+
root.append(body);
|
|
220
|
+
node.append(toolbar, root, status);
|
|
221
|
+
const selection = createChatSelection();
|
|
222
|
+
const follow = createFollow(root);
|
|
223
|
+
const actions = createChatActions(node, selection, ctx);
|
|
224
|
+
const state = {
|
|
225
|
+
root,
|
|
226
|
+
messages: [],
|
|
227
|
+
active: null,
|
|
228
|
+
selection,
|
|
229
|
+
actions,
|
|
230
|
+
label: root.getAttribute('aria-label'),
|
|
231
|
+
};
|
|
232
|
+
let currentEl = initial;
|
|
233
|
+
state.highlighted = null;
|
|
234
|
+
state.unread = null;
|
|
235
|
+
let initialized = false;
|
|
236
|
+
let disposed = false;
|
|
237
|
+
state.version = 0;
|
|
238
|
+
state.runStarts = new Set();
|
|
239
|
+
const viewport = createViewport(root, body, {
|
|
240
|
+
estimate: 64,
|
|
241
|
+
draw: rowDrawer(state, ctx, options),
|
|
242
|
+
changed: () => follow.refresh(),
|
|
243
|
+
});
|
|
244
|
+
state.viewport = viewport;
|
|
245
|
+
const run = (promise) => promise?.catch(() => {}); // Error is visible in stream state/status.
|
|
246
|
+
const render = (snapshot) => {
|
|
247
|
+
if (disposed) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
state.messages = snapshot.messages;
|
|
251
|
+
state.runStarts = new Set(
|
|
252
|
+
messageRuns(state.messages, options).map((r) => r.messages[0].id)
|
|
253
|
+
);
|
|
254
|
+
state.highlighted = snapshot.highlighted;
|
|
255
|
+
state.unread = firstUnread(snapshot.messages);
|
|
256
|
+
if (!state.messages.some((m) => m.id === state.active)) {
|
|
257
|
+
state.active = state.messages.at(-1)?.id ?? null;
|
|
258
|
+
}
|
|
259
|
+
renderStatus(snapshot, root, older, newer, status, options);
|
|
260
|
+
viewport.setActive(state.active);
|
|
261
|
+
viewport.setItems(state.messages);
|
|
262
|
+
if (!initialized && state.messages.length) {
|
|
263
|
+
initialized = true;
|
|
264
|
+
follow.toBottom();
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const jump = async (id) => {
|
|
268
|
+
if (!stream) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
follow.pause();
|
|
272
|
+
await stream.jumpTo(id);
|
|
273
|
+
state.active = id;
|
|
274
|
+
viewport.setActive(id);
|
|
275
|
+
viewport.scrollTo(state.messages.findIndex((m) => m.id === id));
|
|
276
|
+
viewport.render();
|
|
277
|
+
viewport.row(id)?.focus({ preventScroll: true });
|
|
278
|
+
};
|
|
279
|
+
const unlisten = listenStream(node, state, stream, follow, jump, {
|
|
280
|
+
ctx,
|
|
281
|
+
older,
|
|
282
|
+
newer,
|
|
283
|
+
newest,
|
|
284
|
+
});
|
|
285
|
+
const unsubscribe = stream?.subscribe(render);
|
|
286
|
+
const unsubscribeData = options.data?.subscribe?.(() => {
|
|
287
|
+
state.version++;
|
|
288
|
+
if (stream) {
|
|
289
|
+
render(stream.state());
|
|
290
|
+
} else {
|
|
291
|
+
refreshStatic();
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
const refreshStatic = () =>
|
|
295
|
+
render({
|
|
296
|
+
messages: chatRecords(ctx).filter(
|
|
297
|
+
(r) => r.kind === 'message' && r.chat === atomOf(currentEl, 'chat')
|
|
298
|
+
),
|
|
299
|
+
highlighted: null,
|
|
300
|
+
loading: false,
|
|
301
|
+
hasOlder: false,
|
|
302
|
+
hasNewer: false,
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
update(el) {
|
|
306
|
+
currentEl = el;
|
|
307
|
+
state.label = atomOf(el, 'label') ?? 'Messages';
|
|
308
|
+
root.setAttribute('aria-label', state.label);
|
|
309
|
+
if (stream) {
|
|
310
|
+
render(stream.state());
|
|
311
|
+
if (!initialized && !stream.state().loading) {
|
|
312
|
+
run(stream.loadOlder());
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
refreshStatic();
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
jumpTo: jump,
|
|
319
|
+
selection,
|
|
320
|
+
disconnect() {
|
|
321
|
+
disposed = true;
|
|
322
|
+
unsubscribe?.();
|
|
323
|
+
unsubscribeData?.();
|
|
324
|
+
unlisten();
|
|
325
|
+
actions.disconnect();
|
|
326
|
+
follow.disconnect();
|
|
327
|
+
viewport.disconnect();
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
registerChatKind('message-stream', createStream);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
atomOf,
|
|
3
|
+
chatOptions,
|
|
4
|
+
chatRecords,
|
|
5
|
+
make,
|
|
6
|
+
registerChatKind,
|
|
7
|
+
} from './dom.js';
|
|
8
|
+
|
|
9
|
+
/** Nested disclosure tree; cycles/orphans are reported as roots, never recurse forever. */
|
|
10
|
+
export function drawReasoning(node, steps, { document, labels = {} }) {
|
|
11
|
+
const byId = new Map(steps.map((step) => [step.id, step]));
|
|
12
|
+
const children = new Map();
|
|
13
|
+
for (const step of steps) {
|
|
14
|
+
const parent = byId.has(step.parent) ? step.parent : null;
|
|
15
|
+
if (!children.has(parent)) {
|
|
16
|
+
children.set(parent, []);
|
|
17
|
+
}
|
|
18
|
+
children.get(parent).push(step);
|
|
19
|
+
}
|
|
20
|
+
const visited = new Set();
|
|
21
|
+
const draw = (step) => {
|
|
22
|
+
if (visited.has(step.id)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
visited.add(step.id);
|
|
26
|
+
const details = make(document, 'details', {
|
|
27
|
+
class: 'ui-chat-step',
|
|
28
|
+
open: true,
|
|
29
|
+
'data-state': step.state,
|
|
30
|
+
});
|
|
31
|
+
details.append(
|
|
32
|
+
make(
|
|
33
|
+
document,
|
|
34
|
+
'summary',
|
|
35
|
+
{},
|
|
36
|
+
`${step.title} · ${labels[step.state] ?? step.state}`
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
if (step.text) {
|
|
40
|
+
details.append(make(document, 'p', {}, step.text));
|
|
41
|
+
}
|
|
42
|
+
for (const child of children.get(step.id) ?? []) {
|
|
43
|
+
const rendered = draw(child);
|
|
44
|
+
if (rendered) {
|
|
45
|
+
details.append(rendered);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return details;
|
|
49
|
+
};
|
|
50
|
+
const result = [];
|
|
51
|
+
for (const step of [...(children.get(null) ?? []), ...steps]) {
|
|
52
|
+
const rendered = draw(step);
|
|
53
|
+
if (rendered) {
|
|
54
|
+
result.push(rendered);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
node.replaceChildren(...result);
|
|
58
|
+
node.setAttribute('aria-label', labels.reasoning ?? 'Reasoning');
|
|
59
|
+
node.setAttribute('role', 'group');
|
|
60
|
+
}
|
|
61
|
+
registerChatKind('reasoning-trace', (node, _el, ctx) => ({
|
|
62
|
+
update: (el) =>
|
|
63
|
+
drawReasoning(
|
|
64
|
+
node,
|
|
65
|
+
chatRecords(ctx).filter(
|
|
66
|
+
(r) => r.kind === 'step' && r.message === atomOf(el, 'record')
|
|
67
|
+
),
|
|
68
|
+
{ document: ctx.document, ...chatOptions(ctx) }
|
|
69
|
+
),
|
|
70
|
+
}));
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Context target and multi-selection are deliberately independent. */
|
|
2
|
+
export function createChatSelection() {
|
|
3
|
+
const selected = new Set();
|
|
4
|
+
let target = null;
|
|
5
|
+
let anchor = null;
|
|
6
|
+
return {
|
|
7
|
+
state: () => ({ selected: new Set(selected), target, anchor }),
|
|
8
|
+
target(id) {
|
|
9
|
+
target = id;
|
|
10
|
+
},
|
|
11
|
+
select(id, { toggle = false, range = false, keys = [] } = {}) {
|
|
12
|
+
if (range && anchor !== null && keys.includes(anchor)) {
|
|
13
|
+
const ends = [keys.indexOf(anchor), keys.indexOf(id)].sort(
|
|
14
|
+
(a, b) => a - b
|
|
15
|
+
);
|
|
16
|
+
if (ends[0] < 0) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
selected.clear();
|
|
20
|
+
keys.slice(ends[0], ends[1] + 1).forEach((key) => selected.add(key));
|
|
21
|
+
} else {
|
|
22
|
+
if (!toggle) {
|
|
23
|
+
selected.clear();
|
|
24
|
+
}
|
|
25
|
+
if (toggle && selected.has(id)) {
|
|
26
|
+
selected.delete(id);
|
|
27
|
+
} else {
|
|
28
|
+
selected.add(id);
|
|
29
|
+
}
|
|
30
|
+
anchor = id;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
clear() {
|
|
34
|
+
selected.clear();
|
|
35
|
+
target = null;
|
|
36
|
+
anchor = null;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
signal: theme
|
|
2
|
+
token chat.bg '#ffffff'
|
|
3
|
+
token chat.sidebar '#f6f6f6'
|
|
4
|
+
token chat.bubble.in '#e9e9e9'
|
|
5
|
+
token chat.bubble.in.text '#000000'
|
|
6
|
+
token chat.bubble.out '#2c6bed'
|
|
7
|
+
token chat.bubble.out.text '#ffffff'
|
|
8
|
+
token chat.bubble.radius 18px
|
|
9
|
+
token chat.bubble.tail 18px
|
|
10
|
+
token chat.bubble.padding.block 0.45rem
|
|
11
|
+
token chat.bubble.padding.inline 0.75rem
|
|
12
|
+
token chat.text '#17212b'
|
|
13
|
+
token chat.column 44rem
|
|
14
|
+
token chat.selection.bg '#164e63'
|
|
15
|
+
token chat.selection.text '#ffffff'
|
|
16
|
+
mode dark
|
|
17
|
+
token chat.bg '#121212'
|
|
18
|
+
token chat.sidebar '#1b1b1b'
|
|
19
|
+
token chat.bubble.in '#3b3b3b'
|
|
20
|
+
token chat.bubble.in.text '#ffffff'
|
|
21
|
+
token chat.bubble.out '#2c6bed'
|
|
22
|
+
token chat.bubble.out.text '#ffffff'
|
|
23
|
+
token chat.text '#f4f6f8'
|
|
24
|
+
token chat.selection.bg '#b9e6fb'
|
|
25
|
+
token chat.selection.text '#102b39'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
t3: theme
|
|
2
|
+
token chat.bg '#eef1f4'
|
|
3
|
+
token chat.sidebar '#f6f8fa'
|
|
4
|
+
token chat.bubble.in '#ffffff'
|
|
5
|
+
token chat.bubble.in.text '#1f2328'
|
|
6
|
+
token chat.bubble.out '#d8f3d4'
|
|
7
|
+
token chat.bubble.out.text '#1f2328'
|
|
8
|
+
token chat.bubble.radius 14px
|
|
9
|
+
token chat.bubble.tail 14px
|
|
10
|
+
token chat.bubble.padding.block 0.45rem
|
|
11
|
+
token chat.bubble.padding.inline 0.75rem
|
|
12
|
+
token chat.text '#1f2328'
|
|
13
|
+
token chat.column 44rem
|
|
14
|
+
token chat.selection.bg '#164e63'
|
|
15
|
+
token chat.selection.text '#ffffff'
|
|
16
|
+
mode dark
|
|
17
|
+
token chat.bg '#0e1116'
|
|
18
|
+
token chat.sidebar '#161b22'
|
|
19
|
+
token chat.bubble.in '#1c222b'
|
|
20
|
+
token chat.bubble.in.text '#e6edf3'
|
|
21
|
+
token chat.bubble.out '#1c3a28'
|
|
22
|
+
token chat.bubble.out.text '#e6edf3'
|
|
23
|
+
token chat.text '#e6edf3'
|
|
24
|
+
token chat.selection.bg '#b9e6fb'
|
|
25
|
+
token chat.selection.text '#102b39'
|