@kitn.ai/ui 0.15.1 → 0.17.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/README.md +37 -13
- package/bin/mcp.js +22 -0
- package/dist/bash-InADTalH.js +6 -1
- package/dist/components/artifact.d.ts +58 -0
- package/dist/components/attachments.d.ts +67 -0
- package/dist/components/card-fallback.d.ts +10 -0
- package/dist/components/card-renderer.d.ts +13 -0
- package/dist/components/card.d.ts +28 -0
- package/dist/components/chain-of-thought.d.ts +29 -0
- package/dist/components/chat-container.d.ts +19 -0
- package/dist/components/chat-scope-picker.d.ts +9 -0
- package/dist/components/chat-thread.d.ts +91 -0
- package/dist/components/checkpoint.d.ts +20 -0
- package/dist/components/choice-card.d.ts +78 -0
- package/dist/components/code-block.d.ts +16 -0
- package/dist/components/confirm-card.d.ts +57 -0
- package/dist/components/context.d.ts +65 -0
- package/dist/components/conversation-item.d.ts +8 -0
- package/dist/components/conversation-list.d.ts +11 -0
- package/dist/components/dismissed-stub.d.ts +22 -0
- package/dist/components/embed.d.ts +21 -0
- package/dist/components/empty.d.ts +43 -0
- package/dist/components/feedback-bar.d.ts +45 -0
- package/dist/components/file-tree.d.ts +57 -0
- package/dist/components/file-upload.d.ts +16 -0
- package/dist/components/form-widgets.d.ts +31 -0
- package/dist/components/form.d.ts +103 -0
- package/dist/components/image.d.ts +12 -0
- package/dist/components/link-preview.d.ts +23 -0
- package/dist/components/loader.d.ts +60 -0
- package/dist/components/markdown.d.ts +8 -0
- package/dist/components/message-skills.d.ts +15 -0
- package/dist/components/message.d.ts +111 -0
- package/dist/components/model-switcher.d.ts +8 -0
- package/dist/components/prompt-input.d.ts +38 -0
- package/dist/components/prompt-suggestion.d.ts +13 -0
- package/dist/components/reasoning.d.ts +20 -0
- package/dist/components/response-compare-types.d.ts +66 -0
- package/dist/components/response-compare.d.ts +51 -0
- package/dist/components/response-stream.d.ts +14 -0
- package/dist/components/scroll-button.d.ts +7 -0
- package/dist/components/slash-command.d.ts +15 -0
- package/dist/components/source.d.ts +23 -0
- package/dist/components/tasks-card.d.ts +72 -0
- package/dist/components/text-shimmer.d.ts +9 -0
- package/dist/components/thinking-bar.d.ts +10 -0
- package/dist/components/toast.d.ts +48 -0
- package/dist/components/tool.d.ts +16 -0
- package/dist/components/use-card-resolution.d.ts +16 -0
- package/dist/components/voice-input.d.ts +7 -0
- package/dist/core-AYMC6_lb.js +5874 -12
- package/dist/css-M7EaDHN_.js +6 -1
- package/dist/custom-elements.json +260 -11
- package/dist/elements/artifact.d.ts +1 -0
- package/dist/elements/artifact.js +1 -0
- package/dist/elements/attachments.d.ts +1 -0
- package/dist/elements/attachments.js +1 -0
- package/dist/elements/autoloader.d.ts +2 -0
- package/dist/elements/autoloader.js +1 -0
- package/dist/elements/card.d.ts +1 -0
- package/dist/elements/card.js +1 -0
- package/dist/elements/cards.d.ts +1 -0
- package/dist/elements/cards.js +1 -0
- package/dist/elements/chain-of-thought.d.ts +1 -0
- package/dist/elements/chain-of-thought.js +1 -0
- package/dist/elements/chat-scope-picker.d.ts +1 -0
- package/dist/elements/chat-scope-picker.js +1 -0
- package/dist/elements/chat-workspace.d.ts +1 -0
- package/dist/elements/chat-workspace.js +1 -0
- package/dist/elements/chat.d.ts +1 -0
- package/dist/elements/chat.js +1 -0
- package/dist/elements/checkpoint.d.ts +1 -0
- package/dist/elements/checkpoint.js +1 -0
- package/dist/elements/choice.d.ts +1 -0
- package/dist/elements/choice.js +1 -0
- package/dist/elements/chunks/Icon-D_Zmwmwh.js +1 -0
- package/dist/elements/chunks/action-icons-PVfIvcuG.js +1 -0
- package/dist/elements/chunks/attachments-Dp6vqtrc.js +1 -0
- package/dist/elements/chunks/bash-InADTalH.js +1 -0
- package/dist/elements/chunks/button-CKyYD9G4.js +1 -0
- package/dist/elements/chunks/card-Cjho-PYk.js +1 -0
- package/dist/elements/chunks/card-routing-C986KuUA.js +1 -0
- package/dist/elements/chunks/chat-thread-RT808iPf.js +1 -0
- package/dist/elements/chunks/check-CDYaMYrM.js +1 -0
- package/dist/elements/chunks/chevron-down-3SBiq8HF.js +1 -0
- package/dist/elements/chunks/chevron-right-k2UFlIVK.js +1 -0
- package/dist/elements/chunks/cn-Dogu6PbV.js +1 -0
- package/dist/elements/chunks/code-block-BYUmfFSd.js +1 -0
- package/dist/elements/chunks/collapsible-BiNwdOn6.js +1 -0
- package/dist/elements/chunks/context-18g6oi4J.js +1 -0
- package/dist/elements/chunks/conversation-list-D9Y0NVdo.js +1 -0
- package/dist/elements/chunks/core-AYMC6_lb.js +12 -0
- package/dist/elements/chunks/css-M7EaDHN_.js +1 -0
- package/dist/elements/chunks/default-input-CSAoYYMd.js +1 -0
- package/dist/elements/chunks/download-D8K0Je8r.js +1 -0
- package/dist/elements/chunks/dropdown-bUs2iTia.js +1 -0
- package/dist/elements/chunks/engine-javascript-vq0WuIJl.js +141 -0
- package/dist/elements/chunks/external-link-6mA0wxab.js +1 -0
- package/dist/elements/chunks/file-text-DnaYk3Dm.js +1 -0
- package/dist/elements/chunks/file-tree-CgtRLlxK.js +1 -0
- package/dist/elements/chunks/github-dark-dimmed-DUshB20C.js +1 -0
- package/dist/elements/chunks/github-light-JYsPkUQd.js +1 -0
- package/dist/elements/chunks/hover-card-CIGw62gP.js +1 -0
- package/dist/elements/chunks/html-CPZ3oZQ7.js +1 -0
- package/dist/elements/chunks/index-CTBEJeo6.js +1 -0
- package/dist/elements/chunks/javascript-C25yR2R2.js +1 -0
- package/dist/elements/chunks/json-DxJze_jm.js +1 -0
- package/dist/elements/chunks/link-BlGSeoPy.js +1 -0
- package/dist/elements/chunks/loader-DvhR4qa0.js +1 -0
- package/dist/elements/chunks/markdown-CMTGx9r8.js +64 -0
- package/dist/elements/chunks/message-CDZwXjhL.js +1 -0
- package/dist/elements/chunks/message-feedback-CYx81QiA.js +1 -0
- package/dist/elements/chunks/model-switcher-O_tUhoOT.js +1 -0
- package/dist/elements/chunks/overlay-DydXYMQW.js +1 -0
- package/dist/elements/chunks/prompt-suggestion-ldlWV5kd.js +1 -0
- package/dist/elements/chunks/reasoning-2PUnHlmr.js +1 -0
- package/dist/elements/chunks/resizable-B5WNbSeb.js +1 -0
- package/dist/elements/chunks/star-t9tI-P0q.js +1 -0
- package/dist/elements/chunks/store-C6rIooZz.js +1 -0
- package/dist/elements/chunks/svelte--5p79yCD.js +1 -0
- package/dist/elements/chunks/text-shimmer-uh9V_KUh.js +1 -0
- package/dist/elements/chunks/textarea-3nm6Ia9U.js +1 -0
- package/dist/elements/chunks/thumbs-up-BBtguGld.js +1 -0
- package/dist/elements/chunks/toast-store-D8cL3fWl.js +1 -0
- package/dist/elements/chunks/tool-GJ3vwp1U.js +1 -0
- package/dist/elements/chunks/tooltip-DwKAz4XR.js +1 -0
- package/dist/elements/chunks/triangle-alert-Ct1zt2JL.js +1 -0
- package/dist/elements/chunks/tsx-B8rCNbgL.js +1 -0
- package/dist/elements/chunks/typescript-RycA9KXf.js +1 -0
- package/dist/elements/chunks/use-card-resolution-D-_0Alzy.js +1 -0
- package/dist/elements/chunks/video-mVYiM99-.js +1 -0
- package/dist/elements/chunks/vue-BmIZj4XD.js +1 -0
- package/dist/elements/chunks/x-CzxL27Ch.js +1 -0
- package/dist/elements/code-block.d.ts +1 -0
- package/dist/elements/code-block.js +1 -0
- package/dist/elements/compare.d.ts +1 -0
- package/dist/elements/compare.js +1 -0
- package/dist/elements/confirm-card.d.ts +1 -0
- package/dist/elements/confirm-card.js +1 -0
- package/dist/elements/context-meter.d.ts +1 -0
- package/dist/elements/context-meter.js +1 -0
- package/dist/elements/conversation-list.d.ts +1 -0
- package/dist/elements/conversation-list.js +1 -0
- package/dist/elements/embed.d.ts +1 -0
- package/dist/elements/embed.js +1 -0
- package/dist/elements/empty.d.ts +1 -0
- package/dist/elements/empty.js +1 -0
- package/dist/elements/feedback-bar.d.ts +1 -0
- package/dist/elements/feedback-bar.js +1 -0
- package/dist/elements/file-tree.d.ts +1 -0
- package/dist/elements/file-tree.js +1 -0
- package/dist/elements/file-upload.d.ts +1 -0
- package/dist/elements/file-upload.js +1 -0
- package/dist/elements/form.d.ts +1 -0
- package/dist/elements/form.js +1 -0
- package/dist/elements/image.d.ts +1 -0
- package/dist/elements/image.js +1 -0
- package/dist/elements/link-preview.d.ts +1 -0
- package/dist/elements/link-preview.js +1 -0
- package/dist/elements/loader.d.ts +1 -0
- package/dist/elements/loader.js +1 -0
- package/dist/elements/markdown.d.ts +1 -0
- package/dist/elements/markdown.js +1 -0
- package/dist/elements/message-skills.d.ts +1 -0
- package/dist/elements/message-skills.js +1 -0
- package/dist/elements/message.d.ts +1 -0
- package/dist/elements/message.js +1 -0
- package/dist/elements/model-switcher.d.ts +1 -0
- package/dist/elements/model-switcher.js +1 -0
- package/dist/elements/popover.d.ts +1 -0
- package/dist/elements/popover.js +1 -0
- package/dist/elements/prompt-input.d.ts +1 -0
- package/dist/elements/prompt-input.js +1 -0
- package/dist/elements/prompt-suggestions.d.ts +1 -0
- package/dist/elements/prompt-suggestions.js +1 -0
- package/dist/elements/reasoning.d.ts +1 -0
- package/dist/elements/reasoning.js +1 -0
- package/dist/elements/resizable.d.ts +1 -0
- package/dist/elements/resizable.js +1 -0
- package/dist/elements/response-stream.d.ts +1 -0
- package/dist/elements/response-stream.js +14 -0
- package/dist/elements/scroll-button.d.ts +1 -0
- package/dist/elements/scroll-button.js +1 -0
- package/dist/elements/source.d.ts +1 -0
- package/dist/elements/source.js +1 -0
- package/dist/elements/switch.d.ts +1 -0
- package/dist/elements/switch.js +1 -0
- package/dist/elements/tasks.d.ts +1 -0
- package/dist/elements/tasks.js +1 -0
- package/dist/elements/text-shimmer.d.ts +1 -0
- package/dist/elements/text-shimmer.js +1 -0
- package/dist/elements/thinking-bar.d.ts +1 -0
- package/dist/elements/thinking-bar.js +1 -0
- package/dist/elements/toast.d.ts +1 -0
- package/dist/elements/toast.js +1 -0
- package/dist/elements/tool.d.ts +1 -0
- package/dist/elements/tool.js +1 -0
- package/dist/elements/voice-input.d.ts +1 -0
- package/dist/elements/voice-input.js +1 -0
- package/dist/elements.d.ts +768 -0
- package/dist/engine-javascript-vq0WuIJl.js +2516 -14
- package/dist/github-dark-dimmed-DUshB20C.js +4 -1
- package/dist/github-light-JYsPkUQd.js +4 -1
- package/dist/html-CPZ3oZQ7.js +10 -1
- package/dist/index.d.ts +124 -2
- package/dist/index.js +15593 -0
- package/dist/javascript-C25yR2R2.js +6 -1
- package/dist/json-DxJze_jm.js +6 -1
- package/dist/kitn-chat.es.js +1 -77
- package/dist/llms/llms-full.txt +57 -12
- package/dist/llms/llms.txt +3 -3
- package/dist/mcp.es.js +2296 -0
- package/dist/primitives/card-contract.d.ts +119 -0
- package/dist/primitives/card-host.d.ts +12 -0
- package/dist/primitives/card-recovery.d.ts +55 -0
- package/dist/primitives/card-registry.d.ts +17 -0
- package/dist/primitives/card-resolution.d.ts +8 -0
- package/dist/primitives/card-routing.d.ts +12 -0
- package/dist/primitives/card-validate.d.ts +25 -0
- package/dist/primitives/chat-config.d.ts +31 -0
- package/dist/primitives/controllable.d.ts +13 -0
- package/dist/primitives/embed-providers.d.ts +65 -0
- package/dist/primitives/highlighter.d.ts +23 -0
- package/dist/primitives/link-preview.d.ts +47 -0
- package/dist/primitives/message-feedback.d.ts +35 -0
- package/dist/primitives/pdf-preview.d.ts +50 -0
- package/dist/primitives/toast-store.d.ts +88 -0
- package/dist/primitives/use-auto-resize.d.ts +8 -0
- package/dist/primitives/use-resize-observer.d.ts +1 -0
- package/dist/primitives/use-stick-to-bottom.d.ts +5 -0
- package/dist/primitives/use-text-stream.d.ts +19 -0
- package/dist/primitives/use-voice-recorder.d.ts +9 -0
- package/dist/react/index.d.ts +1198 -0
- package/dist/react/runtime.d.ts +15 -0
- package/dist/react.js +275 -0
- package/dist/register-JyTglR6m.js +1 -0
- package/dist/register-impl-C6wlSsts.js +77 -0
- package/dist/remote/host-embed.d.ts +33 -0
- package/dist/remote/index.d.ts +2 -0
- package/dist/remote/origin.d.ts +5 -0
- package/dist/remote/provider-runtime.d.ts +27 -0
- package/dist/remote/provider.d.ts +2 -0
- package/dist/remote/validate.d.ts +4 -0
- package/dist/remote/version.d.ts +4 -0
- package/dist/remote/wire.d.ts +53 -0
- package/dist/schemas/choice.schema.json +5 -0
- package/dist/schemas/tasks.schema.json +5 -0
- package/dist/svelte--5p79yCD.js +15 -1
- package/dist/tsx-B8rCNbgL.js +6 -1
- package/dist/types.d.ts +42 -0
- package/dist/typescript-RycA9KXf.js +6 -1
- package/dist/ui/action-icons.d.ts +11 -0
- package/dist/ui/avatar.d.ts +8 -0
- package/dist/ui/badge.d.ts +9 -0
- package/dist/ui/button.d.ts +10 -0
- package/dist/ui/collapsible.d.ts +27 -0
- package/dist/ui/dropdown.d.ts +20 -0
- package/dist/ui/hover-card.d.ts +28 -0
- package/dist/ui/overlay.d.ts +67 -0
- package/dist/ui/popover.d.ts +32 -0
- package/dist/ui/resizable.d.ts +76 -0
- package/dist/ui/scroll-area.d.ts +5 -0
- package/dist/ui/separator.d.ts +5 -0
- package/dist/ui/skeleton.d.ts +5 -0
- package/dist/ui/switch.d.ts +19 -0
- package/dist/ui/textarea.d.ts +6 -0
- package/dist/ui/tooltip.d.ts +9 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/vue-BmIZj4XD.js +33 -1
- package/frameworks/react/index.tsx +67 -11
- package/frameworks/react/runtime.tsx +16 -2
- package/llms-full.txt +57 -12
- package/llms.txt +3 -3
- package/package.json +36 -14
- package/src/agent-tooling/archetypes.ts +46 -0
- package/src/agent-tooling/integrations/cloudflare.ts +88 -0
- package/src/agent-tooling/integrations/langgraph.ts +60 -0
- package/src/agent-tooling/integrations/mastra.ts +27 -0
- package/src/agent-tooling/integrations/mock.ts +34 -0
- package/src/agent-tooling/integrations/ollama.ts +47 -0
- package/src/agent-tooling/integrations/openrouter.ts +26 -0
- package/src/agent-tooling/integrations/pi.ts +40 -0
- package/src/agent-tooling/integrations/pydantic-ai.ts +52 -0
- package/src/agent-tooling/integrations/vercel-ai-sdk.ts +44 -0
- package/src/agent-tooling/mcp/manifest.ts +128 -0
- package/src/agent-tooling/mcp/server.ts +59 -0
- package/src/agent-tooling/mcp/stdio.ts +18 -0
- package/src/agent-tooling/mcp/tools/debug.ts +489 -0
- package/src/agent-tooling/mcp/tools/reference.ts +132 -0
- package/src/agent-tooling/mcp/tools/scaffold.ts +1759 -0
- package/src/agent-tooling/mcp/tools/theme.ts +340 -0
- package/src/agent-tooling/mcp/tools/types.ts +14 -0
- package/src/agent-tooling/registry.ts +41 -0
- package/src/agent-tooling/types.ts +30 -0
- package/src/components/chat-thread.tsx +27 -35
- package/src/components/choice-card.tsx +33 -4
- package/src/components/component-meta.json +250 -26
- package/src/components/confirm-card.tsx +15 -1
- package/src/components/dismissed-stub.tsx +80 -0
- package/src/components/form.tsx +21 -3
- package/src/components/message.tsx +151 -10
- package/src/components/response-compare-types.ts +127 -0
- package/src/components/response-compare.tsx +431 -0
- package/src/components/tasks-card.tsx +33 -3
- package/src/components/toast.tsx +398 -0
- package/src/components/use-card-resolution.ts +24 -8
- package/src/elements/autoloader.ts +89 -0
- package/src/elements/chat-types.ts +7 -0
- package/src/elements/chat-workspace.tsx +4 -2
- package/src/elements/chat.tsx +4 -2
- package/src/elements/compare.tsx +88 -0
- package/src/elements/compiled.css +1 -1
- package/src/elements/define.tsx +7 -1
- package/src/elements/element-manifest.json +182 -0
- package/src/elements/element-meta.json +191 -68
- package/src/elements/element-types.d.ts +43 -6
- package/src/elements/framework-usage.json +25 -0
- package/src/elements/message.tsx +27 -45
- package/src/elements/register-impl.ts +58 -0
- package/src/elements/register.ts +26 -51
- package/src/elements/remote.tsx +4 -0
- package/src/elements/styles.css +19 -0
- package/src/elements/toast.tsx +74 -0
- package/src/index.ts +30 -0
- package/src/primitives/card-contract.ts +14 -5
- package/src/primitives/card-recovery.ts +149 -0
- package/src/primitives/card-routing.ts +3 -0
- package/src/primitives/card-schemas/choice.schema.json +5 -0
- package/src/primitives/card-schemas/tasks.schema.json +5 -0
- package/src/primitives/message-feedback.ts +123 -0
- package/src/primitives/toast-store.ts +235 -0
- package/src/ui/tooltip.tsx +8 -2
- package/theme.css +4 -2
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSignal, createEffect, onCleanup, on, For, Show, createMemo,
|
|
3
|
+
} from 'solid-js';
|
|
4
|
+
import { X, Check } from 'lucide-solid';
|
|
5
|
+
import { cn } from '../utils/cn';
|
|
6
|
+
import { createPresence } from '../ui/overlay';
|
|
7
|
+
import {
|
|
8
|
+
type ToastItem, type ToastVariant, resolveDuration,
|
|
9
|
+
} from '../primitives/toast-store';
|
|
10
|
+
|
|
11
|
+
export type { ToastItem, ToastVariant };
|
|
12
|
+
|
|
13
|
+
/** Why a toast went away — surfaced to `onDismiss` (and the facade event). */
|
|
14
|
+
export type ToastDismissReason = 'timeout' | 'close' | 'action';
|
|
15
|
+
|
|
16
|
+
export type ToastPosition = 'top-center' | 'top-right' | 'top-left' | 'bottom-center' | 'bottom-right' | 'bottom-left';
|
|
17
|
+
|
|
18
|
+
export interface ToastRegionProps {
|
|
19
|
+
/** The toasts to render. Newest is shown on top. Set as a JS property on the
|
|
20
|
+
* element; mutate by passing a new array reference. */
|
|
21
|
+
toasts: ToastItem[];
|
|
22
|
+
/** Where the stack anchors. Defaults to `'top-center'`. */
|
|
23
|
+
position?: ToastPosition;
|
|
24
|
+
/** Max simultaneously-visible toasts; the rest queue and promote as slots
|
|
25
|
+
* free up. Defaults to `3`. */
|
|
26
|
+
max?: number;
|
|
27
|
+
/** Stacking: 'expanded' (default, full column) | 'collapsed' (Sonner-style
|
|
28
|
+
* pile that expands on hover/focus). Attribute: stack. */
|
|
29
|
+
stack?: 'expanded' | 'collapsed';
|
|
30
|
+
/** When set, this region renders only the toasts scoped to that element and
|
|
31
|
+
* anchors over its bounds (top-center), following it on scroll/resize. Unset =
|
|
32
|
+
* the global, viewport-anchored region. */
|
|
33
|
+
target?: HTMLElement;
|
|
34
|
+
/** Fired when a toast leaves, with the reason. */
|
|
35
|
+
onDismiss?: (id: string, reason: ToastDismissReason) => void;
|
|
36
|
+
/** Fired when a toast's action button is pressed. */
|
|
37
|
+
onAction?: (id: string, label: string) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Reactive `prefers-reduced-motion`. SSR-safe (returns false when no window). */
|
|
41
|
+
function usePrefersReducedMotion() {
|
|
42
|
+
const [reduced, setReduced] = createSignal(
|
|
43
|
+
typeof window !== 'undefined' && window.matchMedia?.('(prefers-reduced-motion: reduce)').matches === true,
|
|
44
|
+
);
|
|
45
|
+
if (typeof window !== 'undefined' && window.matchMedia) {
|
|
46
|
+
const mq = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
47
|
+
const on = () => setReduced(mq.matches);
|
|
48
|
+
mq.addEventListener?.('change', on);
|
|
49
|
+
onCleanup(() => mq.removeEventListener?.('change', on));
|
|
50
|
+
}
|
|
51
|
+
return reduced;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ── Single toast pill ────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
interface ToastProps {
|
|
57
|
+
item: ToastItem;
|
|
58
|
+
onDismiss: (reason: ToastDismissReason) => void;
|
|
59
|
+
onAction?: (label: string) => void;
|
|
60
|
+
/** Hold the auto-dismiss timer (the region sets this true while the whole stack
|
|
61
|
+
* is hovered/expanded, so peers don't dismiss out from under the cursor). */
|
|
62
|
+
paused?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A single toast pill. Auto-dismisses after its (action-floored) duration, holds
|
|
67
|
+
* the timer while hovered (this pill) OR while `paused` (the whole stack is
|
|
68
|
+
* hovered), and animates in/out via `createPresence`. Pure + prop-driven — the
|
|
69
|
+
* parent `ToastRegion` owns the list + queue.
|
|
70
|
+
*/
|
|
71
|
+
export function Toast(props: ToastProps) {
|
|
72
|
+
const [open, setOpen] = createSignal(true);
|
|
73
|
+
const presence = createPresence(open);
|
|
74
|
+
const variant = () => props.item.variant ?? 'neutral';
|
|
75
|
+
const dismissible = () => props.item.dismissible !== false;
|
|
76
|
+
|
|
77
|
+
let remaining = resolveDuration(props.item);
|
|
78
|
+
let startedAt = 0;
|
|
79
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
80
|
+
let reason: ToastDismissReason = 'timeout';
|
|
81
|
+
|
|
82
|
+
const clear = () => { if (timer !== undefined) { clearTimeout(timer); timer = undefined; } };
|
|
83
|
+
|
|
84
|
+
const begin = () => {
|
|
85
|
+
clear();
|
|
86
|
+
if (remaining <= 0) return; // sticky (duration 0)
|
|
87
|
+
startedAt = Date.now();
|
|
88
|
+
timer = setTimeout(() => { reason = 'timeout'; setOpen(false); }, remaining);
|
|
89
|
+
};
|
|
90
|
+
const pause = () => {
|
|
91
|
+
if (timer === undefined) return;
|
|
92
|
+
clear();
|
|
93
|
+
remaining -= Date.now() - startedAt;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const [hovered, setHovered] = createSignal(false);
|
|
97
|
+
// Held = this pill is hovered, OR the region says the whole stack is hovered.
|
|
98
|
+
const held = (): boolean => props.paused === true || hovered();
|
|
99
|
+
|
|
100
|
+
// (Re)start the timer whenever the resolved duration changes (mount + update());
|
|
101
|
+
// resets the remaining time to full. Holds instead of running if currently held.
|
|
102
|
+
createEffect(on(() => resolveDuration(props.item), (d) => {
|
|
103
|
+
remaining = d;
|
|
104
|
+
if (held()) clear();
|
|
105
|
+
else begin();
|
|
106
|
+
}));
|
|
107
|
+
// Pause/resume on hover (this pill or the whole stack) WITHOUT resetting remaining,
|
|
108
|
+
// so the countdown continues from where it left off. Deferred — the duration
|
|
109
|
+
// effect already armed it on mount.
|
|
110
|
+
createEffect(on(held, (isHeld) => {
|
|
111
|
+
if (isHeld) pause();
|
|
112
|
+
else begin();
|
|
113
|
+
}, { defer: true }));
|
|
114
|
+
onCleanup(clear);
|
|
115
|
+
|
|
116
|
+
// When presence has fully exited, notify the parent so it drops the item.
|
|
117
|
+
createEffect(() => {
|
|
118
|
+
if (!presence.present() && !open()) props.onDismiss(reason);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const close = () => { clear(); reason = 'close'; setOpen(false); };
|
|
122
|
+
|
|
123
|
+
const act = () => {
|
|
124
|
+
const action = props.item.action;
|
|
125
|
+
if (!action) return;
|
|
126
|
+
props.onAction?.(action.label);
|
|
127
|
+
const keepOpen = action.onAction() === false;
|
|
128
|
+
if (!keepOpen) { clear(); reason = 'action'; setOpen(false); }
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<Show when={presence.present()}>
|
|
133
|
+
<div
|
|
134
|
+
ref={presence.setRef}
|
|
135
|
+
role="status"
|
|
136
|
+
data-closed={presence.state() === 'closed' ? '' : undefined}
|
|
137
|
+
onPointerEnter={() => setHovered(true)}
|
|
138
|
+
onPointerLeave={() => setHovered(false)}
|
|
139
|
+
class={cn(
|
|
140
|
+
'pointer-events-auto flex items-center gap-3 rounded-full border px-4 py-2.5 text-sm shadow-lg',
|
|
141
|
+
'bg-popover text-popover-foreground border-border',
|
|
142
|
+
'animate-in fade-in-0 slide-in-from-top-4',
|
|
143
|
+
'data-[closed]:animate-out data-[closed]:fade-out-0 data-[closed]:slide-out-to-top-2',
|
|
144
|
+
)}
|
|
145
|
+
>
|
|
146
|
+
<Show when={variant() === 'success'}>
|
|
147
|
+
<Check class="size-4 shrink-0 text-emerald-500" />
|
|
148
|
+
</Show>
|
|
149
|
+
<span class="min-w-0 flex-1 truncate">{props.item.message}</span>
|
|
150
|
+
<Show when={props.item.action}>
|
|
151
|
+
{(action) => (
|
|
152
|
+
<button
|
|
153
|
+
type="button"
|
|
154
|
+
onClick={act}
|
|
155
|
+
class="text-primary hover:text-primary/80 shrink-0 rounded-md text-sm font-medium underline-offset-2 hover:underline"
|
|
156
|
+
>
|
|
157
|
+
{action().label}
|
|
158
|
+
</button>
|
|
159
|
+
)}
|
|
160
|
+
</Show>
|
|
161
|
+
<Show when={dismissible()}>
|
|
162
|
+
<button
|
|
163
|
+
type="button"
|
|
164
|
+
onClick={close}
|
|
165
|
+
aria-label="Dismiss"
|
|
166
|
+
class="text-muted-foreground hover:text-foreground -mr-1 flex size-5 shrink-0 items-center justify-center rounded-md transition-colors"
|
|
167
|
+
>
|
|
168
|
+
<X class="size-3.5" />
|
|
169
|
+
</button>
|
|
170
|
+
</Show>
|
|
171
|
+
</div>
|
|
172
|
+
</Show>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ── Region (stack + queue) ───────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
const POSITION_CLASSES: Record<ToastPosition, string> = {
|
|
179
|
+
'top-center': 'top-4 left-1/2 -translate-x-1/2 items-center',
|
|
180
|
+
'top-right': 'top-4 right-4 items-end',
|
|
181
|
+
'top-left': 'top-4 left-4 items-start',
|
|
182
|
+
'bottom-center': 'bottom-4 left-1/2 -translate-x-1/2 items-center flex-col-reverse',
|
|
183
|
+
'bottom-right': 'bottom-4 right-4 items-end flex-col-reverse',
|
|
184
|
+
'bottom-left': 'bottom-4 left-4 items-start flex-col-reverse',
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Flex alignment + stack direction per position, for a TARGET-anchored region (the
|
|
188
|
+
// stack hugs the chosen corner; bottom rows grow upward so the newest sits at the
|
|
189
|
+
// anchored edge). Mirrors POSITION_CLASSES minus the viewport-edge offsets.
|
|
190
|
+
const ANCHOR_FLEX: Record<ToastPosition, string> = {
|
|
191
|
+
'top-center': 'items-center',
|
|
192
|
+
'top-left': 'items-start',
|
|
193
|
+
'top-right': 'items-end',
|
|
194
|
+
'bottom-center': 'items-center flex-col-reverse',
|
|
195
|
+
'bottom-left': 'items-start flex-col-reverse',
|
|
196
|
+
'bottom-right': 'items-end flex-col-reverse',
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/** Inset from the target's edges, in px. */
|
|
200
|
+
const ANCHOR_PAD = 12;
|
|
201
|
+
|
|
202
|
+
interface TargetRect { top: number; left: number; right: number; bottom: number; width: number }
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The fixed-position style pinning a target-anchored stack to the corner named by
|
|
206
|
+
* `position`, computed from the target's rect. The region is `position: fixed`, so
|
|
207
|
+
* we resolve absolute top/left + a transform that grows the stack inward from that
|
|
208
|
+
* edge. (Rect-based, like the popover's anchor math — no collision flipping needed.)
|
|
209
|
+
*/
|
|
210
|
+
function anchorStyle(position: ToastPosition, r: TargetRect): Record<string, string> {
|
|
211
|
+
const cx = r.left + r.width / 2;
|
|
212
|
+
const top = r.top + ANCHOR_PAD;
|
|
213
|
+
const bottom = r.bottom - ANCHOR_PAD;
|
|
214
|
+
const left = r.left + ANCHOR_PAD;
|
|
215
|
+
const right = r.right - ANCHOR_PAD;
|
|
216
|
+
const maxWidth = `${Math.max(0, r.width - ANCHOR_PAD * 2)}px`;
|
|
217
|
+
switch (position) {
|
|
218
|
+
case 'top-left':
|
|
219
|
+
return { top: `${top}px`, left: `${left}px`, transform: 'none', 'max-width': maxWidth };
|
|
220
|
+
case 'top-right':
|
|
221
|
+
return { top: `${top}px`, left: `${right}px`, transform: 'translateX(-100%)', 'max-width': maxWidth };
|
|
222
|
+
case 'bottom-center':
|
|
223
|
+
return { top: `${bottom}px`, left: `${cx}px`, transform: 'translate(-50%, -100%)', 'max-width': maxWidth };
|
|
224
|
+
case 'bottom-left':
|
|
225
|
+
return { top: `${bottom}px`, left: `${left}px`, transform: 'translateY(-100%)', 'max-width': maxWidth };
|
|
226
|
+
case 'bottom-right':
|
|
227
|
+
return { top: `${bottom}px`, left: `${right}px`, transform: 'translate(-100%, -100%)', 'max-width': maxWidth };
|
|
228
|
+
case 'top-center':
|
|
229
|
+
default:
|
|
230
|
+
return { top: `${top}px`, left: `${cx}px`, transform: 'translateX(-50%)', 'max-width': maxWidth };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Renders a stack of toasts at a viewport edge. Caps the visible count at `max`
|
|
236
|
+
* (newest on top); overflow waits in a queue and is promoted as visible toasts
|
|
237
|
+
* leave. `aria-live=polite` / `role=region` so screen readers announce new
|
|
238
|
+
* toasts without stealing focus.
|
|
239
|
+
*/
|
|
240
|
+
export function ToastRegion(props: ToastRegionProps) {
|
|
241
|
+
const max = () => props.max ?? 3;
|
|
242
|
+
const position = () => props.position ?? 'top-center';
|
|
243
|
+
|
|
244
|
+
const stack = () => props.stack ?? 'expanded';
|
|
245
|
+
const reduced = usePrefersReducedMotion();
|
|
246
|
+
const collapsed = () => stack() === 'collapsed' && !reduced();
|
|
247
|
+
// Expanded while the stack is hovered OR holds focus (collapsed mode). These are
|
|
248
|
+
// tracked SEPARATELY and OR'd: dismissing a toast (clicking its ×) removes the
|
|
249
|
+
// focused button → a focusout — but if the pointer is still over the stack we must
|
|
250
|
+
// stay expanded (and paused), so focusout alone must not collapse it.
|
|
251
|
+
const [hovered, setHovered] = createSignal(false);
|
|
252
|
+
const [focused, setFocused] = createSignal(false);
|
|
253
|
+
const open = () => hovered() || focused();
|
|
254
|
+
|
|
255
|
+
// Tunable look (IVP). Resting peek + per-depth shrink; uniform expanded row height.
|
|
256
|
+
const OFFSET = 20; // px each deeper toast peeks past the one in front
|
|
257
|
+
const SCALE_STEP = 0.05; // each deeper toast is 5% smaller
|
|
258
|
+
const ROW_FALLBACK = 48; // px; used until the front pill is measured
|
|
259
|
+
const GAP = 8; // matches gap-2 in the expanded column
|
|
260
|
+
|
|
261
|
+
const isBottom = () => position().startsWith('bottom');
|
|
262
|
+
const dir = () => (isBottom() ? -1 : 1);
|
|
263
|
+
|
|
264
|
+
// Measure ONE pill (all are single-line/uniform) to size the expanded spacing.
|
|
265
|
+
const [rowH, setRowH] = createSignal(ROW_FALLBACK);
|
|
266
|
+
const measure = (el: HTMLElement | undefined) => {
|
|
267
|
+
if (!el || typeof window === 'undefined') return;
|
|
268
|
+
const set = () => { const h = el.offsetHeight; if (h) setRowH(h); };
|
|
269
|
+
set();
|
|
270
|
+
// jsdom (and SSR) lack ResizeObserver; the fallback height is fine there.
|
|
271
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
272
|
+
const ro = new ResizeObserver(set);
|
|
273
|
+
ro.observe(el);
|
|
274
|
+
onCleanup(() => ro.disconnect());
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// The transform for the wrapper at depth i, given the current open/resting state.
|
|
278
|
+
const depthTransform = (i: number): string => {
|
|
279
|
+
if (open()) return `translateY(${dir() * (rowH() + GAP) * i}px) scale(1)`;
|
|
280
|
+
return `translateY(${dir() * OFFSET * i}px) scale(${1 - SCALE_STEP * i})`;
|
|
281
|
+
};
|
|
282
|
+
// The collapsed stage gets an explicit height covering the whole stack extent —
|
|
283
|
+
// resting (the pile) vs expanded (the full column) — so the region is ONE
|
|
284
|
+
// continuous hover surface. Without it the cursor falls into the gaps between
|
|
285
|
+
// expanded pills (or the spot a just-dismissed pill vacated) and the region
|
|
286
|
+
// flickers collapsed→expanded. Grows away from the anchored edge in both modes.
|
|
287
|
+
const stageHeight = (): number => {
|
|
288
|
+
const n = visible().length;
|
|
289
|
+
if (!n) return 0;
|
|
290
|
+
return open() ? n * rowH() + (n - 1) * GAP : rowH() + (n - 1) * OFFSET;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// Only the toasts for THIS region's target (undefined target = the global one).
|
|
294
|
+
// Newest-first so the freshest toast sits at the top; the queue (past `max`)
|
|
295
|
+
// stays mounted-but-hidden until a slot frees up.
|
|
296
|
+
const ordered = createMemo(() =>
|
|
297
|
+
[...(props.toasts ?? []).filter((t) => (t.target ?? undefined) === props.target)].reverse(),
|
|
298
|
+
);
|
|
299
|
+
const visible = createMemo(() => ordered().slice(0, max()));
|
|
300
|
+
|
|
301
|
+
// Scoped to a target → anchor the stack to the `position` corner of the target,
|
|
302
|
+
// following it on scroll/resize. Otherwise it's a viewport-fixed corner/center.
|
|
303
|
+
const [anchor, setAnchor] = createSignal<TargetRect | null>(null);
|
|
304
|
+
createEffect(() => {
|
|
305
|
+
const t = props.target;
|
|
306
|
+
if (!t || typeof window === 'undefined') { setAnchor(null); return; }
|
|
307
|
+
const update = () => {
|
|
308
|
+
const r = t.getBoundingClientRect();
|
|
309
|
+
setAnchor({ top: r.top, left: r.left, right: r.right, bottom: r.bottom, width: r.width });
|
|
310
|
+
};
|
|
311
|
+
update();
|
|
312
|
+
const ro = new ResizeObserver(update);
|
|
313
|
+
ro.observe(t);
|
|
314
|
+
window.addEventListener('scroll', update, true);
|
|
315
|
+
window.addEventListener('resize', update);
|
|
316
|
+
onCleanup(() => {
|
|
317
|
+
ro.disconnect();
|
|
318
|
+
window.removeEventListener('scroll', update, true);
|
|
319
|
+
window.removeEventListener('resize', update);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return (
|
|
324
|
+
<Show
|
|
325
|
+
when={collapsed()}
|
|
326
|
+
fallback={
|
|
327
|
+
<div
|
|
328
|
+
role="region"
|
|
329
|
+
aria-label="Notifications"
|
|
330
|
+
aria-live="polite"
|
|
331
|
+
data-stack="expanded"
|
|
332
|
+
class={cn(
|
|
333
|
+
'pointer-events-none fixed z-[100] flex flex-col gap-2',
|
|
334
|
+
anchor()
|
|
335
|
+
? ANCHOR_FLEX[position()]
|
|
336
|
+
: cn('max-w-[min(28rem,calc(100vw-2rem))]', POSITION_CLASSES[position()]),
|
|
337
|
+
)}
|
|
338
|
+
style={anchor() ? anchorStyle(position(), anchor()!) : undefined}
|
|
339
|
+
>
|
|
340
|
+
<For each={visible()}>
|
|
341
|
+
{(item) => (
|
|
342
|
+
<Toast
|
|
343
|
+
item={item}
|
|
344
|
+
onDismiss={(reason) => props.onDismiss?.(item.id, reason)}
|
|
345
|
+
onAction={(label) => props.onAction?.(item.id, label)}
|
|
346
|
+
/>
|
|
347
|
+
)}
|
|
348
|
+
</For>
|
|
349
|
+
</div>
|
|
350
|
+
}
|
|
351
|
+
>
|
|
352
|
+
<div
|
|
353
|
+
role="region"
|
|
354
|
+
aria-label="Notifications"
|
|
355
|
+
aria-live="polite"
|
|
356
|
+
data-stack="collapsed"
|
|
357
|
+
data-expanded={open() ? '' : undefined}
|
|
358
|
+
onPointerEnter={() => setHovered(true)}
|
|
359
|
+
onPointerLeave={() => setHovered(false)}
|
|
360
|
+
onFocusIn={() => setFocused(true)}
|
|
361
|
+
onFocusOut={() => setFocused(false)}
|
|
362
|
+
class={cn('pointer-events-none fixed z-[100]', !anchor() && POSITION_CLASSES[position()])}
|
|
363
|
+
style={anchor() ? anchorStyle(position(), anchor()!) : undefined}
|
|
364
|
+
>
|
|
365
|
+
{/* Relative stage with an explicit height so it's ONE continuous hover
|
|
366
|
+
surface (pointer-events-auto) — no flicker when the cursor crosses gaps
|
|
367
|
+
or a dismissed pill's vacated spot. Pills are absolutely stacked from the
|
|
368
|
+
anchored edge. */}
|
|
369
|
+
<div
|
|
370
|
+
class="pointer-events-auto relative transition-[height] duration-200 ease-out"
|
|
371
|
+
style={{ 'min-width': '16rem', 'max-width': 'min(28rem, calc(100vw - 2rem))', height: `${stageHeight()}px` }}
|
|
372
|
+
>
|
|
373
|
+
<For each={visible()}>
|
|
374
|
+
{(item, i) => (
|
|
375
|
+
<div
|
|
376
|
+
data-depth={i()}
|
|
377
|
+
ref={(el) => { if (i() === 0) measure(el); }}
|
|
378
|
+
class={cn(
|
|
379
|
+
'absolute inset-x-0 flex transition-[transform,opacity] duration-200 ease-out',
|
|
380
|
+
isBottom() ? 'bottom-0 origin-bottom' : 'top-0 origin-top',
|
|
381
|
+
position().endsWith('right') ? 'justify-end' : position().endsWith('left') ? 'justify-start' : 'justify-center',
|
|
382
|
+
)}
|
|
383
|
+
style={{ 'z-index': String(max() - i()), transform: depthTransform(i()) }}
|
|
384
|
+
>
|
|
385
|
+
<Toast
|
|
386
|
+
item={item}
|
|
387
|
+
paused={open()}
|
|
388
|
+
onDismiss={(reason) => props.onDismiss?.(item.id, reason)}
|
|
389
|
+
onAction={(label) => props.onAction?.(item.id, label)}
|
|
390
|
+
/>
|
|
391
|
+
</div>
|
|
392
|
+
)}
|
|
393
|
+
</For>
|
|
394
|
+
</div>
|
|
395
|
+
</div>
|
|
396
|
+
</Show>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
@@ -3,26 +3,42 @@
|
|
|
3
3
|
// A new `data` identity clears the local flip (a fresh card definition is interactive
|
|
4
4
|
// again), but an explicit prop keeps it resolved. `isOptimistic` is true only for a
|
|
5
5
|
// flip made this session (used to announce via role="status"; silent on re-hydrate).
|
|
6
|
+
//
|
|
7
|
+
// A resolution is `isResolved` when present at all; `isTerminal` for the finished
|
|
8
|
+
// states (action | submit | expired) and `isDeferred` for `dismissed` — a set-aside
|
|
9
|
+
// card that still offers a Reopen affordance.
|
|
6
10
|
import { createSignal, createMemo, createEffect, on, type Accessor } from 'solid-js';
|
|
7
11
|
import type { CardResolution } from '../primitives/card-contract';
|
|
8
12
|
|
|
9
|
-
export interface ResolutionController {
|
|
10
|
-
resolution: Accessor<
|
|
13
|
+
export interface ResolutionController<R extends CardResolution = CardResolution> {
|
|
14
|
+
resolution: Accessor<R | undefined>;
|
|
11
15
|
isResolved: Accessor<boolean>;
|
|
16
|
+
/** A finished resolution the user can't take back here (action | submit | expired). */
|
|
17
|
+
isTerminal: Accessor<boolean>;
|
|
18
|
+
/** A deferred resolution (`dismissed`) — set aside, still re-openable. */
|
|
19
|
+
isDeferred: Accessor<boolean>;
|
|
12
20
|
isOptimistic: Accessor<boolean>;
|
|
13
|
-
setLocal: (r:
|
|
21
|
+
setLocal: (r: R) => void;
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
/** The resolution kinds that are finished and not re-openable from the card. */
|
|
25
|
+
const TERMINAL_KINDS = new Set<CardResolution['kind']>(['action', 'submit', 'expired']);
|
|
26
|
+
|
|
27
|
+
export function useCardResolution<R extends CardResolution = CardResolution>(opts: {
|
|
28
|
+
prop: Accessor<R | undefined>;
|
|
18
29
|
data: Accessor<unknown>;
|
|
19
|
-
}): ResolutionController {
|
|
20
|
-
const [local, setLocal] = createSignal<
|
|
30
|
+
}): ResolutionController<R> {
|
|
31
|
+
const [local, setLocal] = createSignal<R | undefined>(undefined);
|
|
21
32
|
// Reset the optimistic flip when a NEW data identity arrives (deferred so mount
|
|
22
33
|
// doesn't clobber an initial prop). The prop still wins via the memo below.
|
|
23
34
|
createEffect(on(opts.data, () => setLocal(undefined), { defer: true }));
|
|
24
35
|
const resolution = createMemo(() => opts.prop() ?? local());
|
|
25
36
|
const isResolved = createMemo(() => resolution() !== undefined);
|
|
37
|
+
const isTerminal = createMemo(() => {
|
|
38
|
+
const r = resolution();
|
|
39
|
+
return r !== undefined && TERMINAL_KINDS.has(r.kind);
|
|
40
|
+
});
|
|
41
|
+
const isDeferred = createMemo(() => resolution()?.kind === 'dismissed');
|
|
26
42
|
const isOptimistic = createMemo(() => opts.prop() === undefined && local() !== undefined);
|
|
27
|
-
return { resolution, isResolved, isOptimistic, setLocal };
|
|
43
|
+
return { resolution, isResolved, isTerminal, isDeferred, isOptimistic, setLocal };
|
|
28
44
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The kai-* autoloader (opt-in, additive — the Web Awesome model).
|
|
2
|
+
//
|
|
3
|
+
// Include this ONE module (via a CDN/static `<script type="module">` tag) and it
|
|
4
|
+
// watches the DOM for undefined kai-* elements and dynamically imports each
|
|
5
|
+
// element's module on demand — so a page that only uses <kai-chat> never downloads
|
|
6
|
+
// the others. The register-all bundle (@kitn.ai/ui/elements) stays the default;
|
|
7
|
+
// this is the delivery for NO-BUILD / CDN / static-served pages.
|
|
8
|
+
//
|
|
9
|
+
// IMPORTANT — this is a CDN / static-file pattern (it resolves sibling element
|
|
10
|
+
// modules relative to its own URL). It is NOT importable through a bundler: Vite /
|
|
11
|
+
// webpack relocate `import.meta.url` away from the element files and cannot analyze
|
|
12
|
+
// the dynamic import, so it 404s. In a BUNDLED app use per-element imports
|
|
13
|
+
// (`import '@kitn.ai/ui/elements/<el>'`) or the register-all bundle. (Advanced: host
|
|
14
|
+
// dist/elements/ yourself and call setAutoloaderBasePath('<url>/') before use.)
|
|
15
|
+
//
|
|
16
|
+
// Tag → module is resolved through the generated manifest (filenames don't always
|
|
17
|
+
// equal the tag, and some modules register more than one tag), and modules are
|
|
18
|
+
// fetched relative to THIS module's URL.
|
|
19
|
+
import manifest from './element-manifest.json';
|
|
20
|
+
|
|
21
|
+
const tagToModule: Record<string, string> = manifest.tags;
|
|
22
|
+
const inFlight = new Set<string>();
|
|
23
|
+
|
|
24
|
+
// Base = the directory of this module. Computed via string ops on import.meta.url
|
|
25
|
+
// (NOT `new URL('./x', import.meta.url)`, which Vite rewrites into a static-asset
|
|
26
|
+
// glob that resolves to undefined at runtime).
|
|
27
|
+
const BASE = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
|
|
28
|
+
|
|
29
|
+
/** Override where element modules are fetched from (e.g. a CDN). Call before use. */
|
|
30
|
+
let baseOverride: string | null = null;
|
|
31
|
+
export function setAutoloaderBasePath(path: string): void {
|
|
32
|
+
baseOverride = path.endsWith('/') ? path : path + '/';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function register(tag: string): Promise<void> {
|
|
36
|
+
if (customElements.get(tag) || inFlight.has(tag)) return;
|
|
37
|
+
const file = tagToModule[tag];
|
|
38
|
+
if (!file) return; // not one of ours
|
|
39
|
+
inFlight.add(tag);
|
|
40
|
+
try {
|
|
41
|
+
await import(/* @vite-ignore */ `${baseOverride ?? BASE}${file}.js`);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
inFlight.delete(tag);
|
|
44
|
+
warnOnce(tag, err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// One actionable warning per session (the failure is almost always "imported
|
|
49
|
+
// through a bundler" — see the header note), instead of a silent per-tag error.
|
|
50
|
+
let warned = false;
|
|
51
|
+
function warnOnce(tag: string, err: unknown): void {
|
|
52
|
+
if (warned) return;
|
|
53
|
+
warned = true;
|
|
54
|
+
const msg = (err as { message?: string })?.message ?? String(err);
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
console.warn(
|
|
57
|
+
`[kai-autoloader] could not load "${tag}" (${msg}). The autoloader is a CDN / ` +
|
|
58
|
+
`static-file tool — load it from a <script type="module" src=".../@kitn.ai/ui/dist/elements/autoloader.js">. ` +
|
|
59
|
+
`It is NOT importable through a bundler. In a bundled app, register elements with per-element imports ` +
|
|
60
|
+
`(import '@kitn.ai/ui/elements/<el>') or the register-all bundle (import '@kitn.ai/ui/elements'). To drive ` +
|
|
61
|
+
`the autoloader from a bundler, host dist/elements/ and call setAutoloaderBasePath('<url>/') before use.`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function discover(root: ParentNode | Element): void {
|
|
66
|
+
const tags = new Set<string>();
|
|
67
|
+
const self = (root as Element).tagName?.toLowerCase?.();
|
|
68
|
+
if (self && self in tagToModule && !customElements.get(self)) tags.add(self);
|
|
69
|
+
root.querySelectorAll?.(':not(:defined)').forEach((el) => {
|
|
70
|
+
const t = el.tagName.toLowerCase();
|
|
71
|
+
if (t in tagToModule) tags.add(t);
|
|
72
|
+
});
|
|
73
|
+
tags.forEach(register);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Start watching `root` (default: the whole document) for undefined kai-* elements. */
|
|
77
|
+
export function startAutoloader(root: ParentNode = document): void {
|
|
78
|
+
discover(root as Element);
|
|
79
|
+
new MutationObserver((mutations) => {
|
|
80
|
+
for (const m of mutations)
|
|
81
|
+
for (const node of m.addedNodes)
|
|
82
|
+
if (node.nodeType === 1) discover(node as Element);
|
|
83
|
+
}).observe(document.documentElement, { childList: true, subtree: true });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Self-start on import (the <script type="module"> use case). Deferred to a
|
|
87
|
+
// microtask so a consumer that calls setAutoloaderBasePath() right after importing
|
|
88
|
+
// (the advanced bundler-from-CDN path) takes effect before the first discovery pass.
|
|
89
|
+
if (typeof document !== 'undefined') queueMicrotask(() => startAutoloader());
|
|
@@ -4,6 +4,9 @@ import type { AttachmentData } from '../components/attachments';
|
|
|
4
4
|
/** The five built-in action buttons (each carries its own curated icon + label). */
|
|
5
5
|
export type ChatMessageAction = 'copy' | 'like' | 'dislike' | 'regenerate' | 'edit';
|
|
6
6
|
|
|
7
|
+
/** A like/dislike feedback vote on an assistant message. */
|
|
8
|
+
export type FeedbackVote = 'like' | 'dislike';
|
|
9
|
+
|
|
7
10
|
/** A host-defined action button. `icon` is a curated registry name (see
|
|
8
11
|
* `src/ui/action-icons.ts`); unknown/absent icons render label-only. */
|
|
9
12
|
export interface CustomAction {
|
|
@@ -39,4 +42,8 @@ export interface ChatMessage {
|
|
|
39
42
|
actions?: (ChatMessageAction | CustomAction)[];
|
|
40
43
|
/** Optional speaker avatar shown to the left of the message column. */
|
|
41
44
|
avatar?: AvatarData;
|
|
45
|
+
/** Controlled feedback vote. When set, it wins over the facade's internal
|
|
46
|
+
* optimistic state (`m.feedback ?? feedbackMap[m.id]`), so a host that
|
|
47
|
+
* persists votes can re-hydrate them. */
|
|
48
|
+
feedback?: FeedbackVote;
|
|
42
49
|
}
|
|
@@ -67,8 +67,10 @@ interface Events {
|
|
|
67
67
|
'kai-value-change': { value: string };
|
|
68
68
|
/** The header model switcher changed. */
|
|
69
69
|
'kai-model-change': { modelId: string };
|
|
70
|
-
/** An action button on a message was clicked.
|
|
71
|
-
'
|
|
70
|
+
/** An action button on a message was clicked. `state` is present only for the
|
|
71
|
+
* toggleable feedback votes: `'on'` when a like/dislike is set, `'off'` when
|
|
72
|
+
* re-tapped to clear. */
|
|
73
|
+
'kai-message-action': { messageId: string; action: string; state?: 'on' | 'off' };
|
|
72
74
|
/** The Search button was clicked. */
|
|
73
75
|
'kai-search': Record<string, never>;
|
|
74
76
|
/** The Mic / voice button was clicked. */
|
package/src/elements/chat.tsx
CHANGED
|
@@ -17,8 +17,10 @@ interface Events {
|
|
|
17
17
|
'kai-value-change': { value: string };
|
|
18
18
|
/** A suggestion chip was clicked (only in `suggestion-mode="fill"`). */
|
|
19
19
|
'kai-suggestion-click': { value: string };
|
|
20
|
-
/** An action button on a message was clicked. `action` is the built-in name or
|
|
21
|
-
|
|
20
|
+
/** An action button on a message was clicked. `action` is the built-in name or
|
|
21
|
+
* custom id. `state` is present only for the toggleable feedback votes:
|
|
22
|
+
* `'on'` when a like/dislike is set, `'off'` when re-tapped to clear. */
|
|
23
|
+
'kai-message-action': { messageId: string; action: string; state?: 'on' | 'off' };
|
|
22
24
|
/** The header model switcher changed. */
|
|
23
25
|
'kai-model-change': { modelId: string };
|
|
24
26
|
/** A slash command was chosen from the palette. */
|