@kitn.ai/ui 0.15.0 → 0.16.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 +9 -0
- 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 +93 -0
- package/dist/components/checkpoint.d.ts +20 -0
- package/dist/components/choice-card.d.ts +77 -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/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 +54 -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-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 +71 -0
- package/dist/components/text-shimmer.d.ts +9 -0
- package/dist/components/thinking-bar.d.ts +10 -0
- package/dist/components/tool.d.ts +16 -0
- package/dist/components/use-card-resolution.d.ts +12 -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/elements/artifact.d.ts +1 -0
- package/dist/elements/attachments.d.ts +1 -0
- package/dist/elements/card.d.ts +1 -0
- package/dist/elements/cards.d.ts +0 -0
- package/dist/elements/chain-of-thought.d.ts +13 -0
- package/dist/elements/chat-scope-picker.d.ts +1 -0
- package/dist/elements/chat-types.d.ts +41 -0
- package/dist/elements/chat-workspace.d.ts +1 -0
- package/dist/elements/chat.d.ts +1 -0
- package/dist/elements/checkpoint.d.ts +1 -0
- package/dist/elements/choice.d.ts +1 -0
- package/dist/elements/code-block.d.ts +1 -0
- package/dist/elements/confirm-card.d.ts +1 -0
- package/dist/elements/context-meter.d.ts +1 -0
- package/dist/elements/conversation-list.d.ts +11 -0
- package/dist/elements/css.d.ts +1 -0
- package/dist/elements/default-input.d.ts +40 -0
- package/dist/elements/define.d.ts +42 -0
- package/dist/elements/embed.d.ts +1 -0
- package/dist/elements/empty.d.ts +1 -0
- package/dist/elements/feedback-bar.d.ts +1 -0
- package/dist/elements/file-tree.d.ts +1 -0
- package/dist/elements/file-upload.d.ts +1 -0
- package/dist/elements/form.d.ts +1 -0
- package/dist/elements/image.d.ts +1 -0
- package/dist/elements/link-preview.d.ts +1 -0
- package/dist/elements/loader.d.ts +1 -0
- package/dist/elements/markdown.d.ts +1 -0
- package/dist/elements/message-skills.d.ts +17 -0
- package/dist/elements/message.d.ts +1 -0
- package/dist/elements/model-switcher.d.ts +11 -0
- package/dist/elements/popover.d.ts +1 -0
- package/dist/elements/prompt-input.d.ts +9 -0
- package/dist/elements/prompt-suggestions.d.ts +7 -0
- package/dist/elements/reasoning.d.ts +1 -0
- package/dist/elements/register-impl.d.ts +0 -0
- package/dist/elements/register.d.ts +3 -0
- package/dist/elements/remote.d.ts +1 -0
- package/dist/elements/resizable.d.ts +17 -0
- package/dist/elements/response-stream.d.ts +1 -0
- package/dist/elements/scroll-button.d.ts +1 -0
- package/dist/elements/source.d.ts +18 -0
- package/dist/elements/switch.d.ts +1 -0
- package/dist/elements/tasks.d.ts +1 -0
- package/dist/elements/text-shimmer.d.ts +1 -0
- package/dist/elements/thinking-bar.d.ts +1 -0
- package/dist/elements/tool.d.ts +1 -0
- package/dist/elements/voice-input.d.ts +1 -0
- package/dist/elements.d.ts +732 -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 +112 -2
- package/dist/index.js +13551 -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 +1 -1
- package/dist/llms/llms.txt +1 -1
- package/dist/mcp.es.js +2140 -0
- package/dist/primitives/card-contract.d.ts +103 -0
- package/dist/primitives/card-host.d.ts +12 -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/pdf-preview.d.ts +50 -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 +1118 -0
- package/dist/react/runtime.d.ts +15 -0
- package/dist/react.js +265 -0
- package/dist/register-impl-wCsFPoh9.js +77 -0
- package/dist/register-ujhr1nBS.js +1 -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/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 +8 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/vue-BmIZj4XD.js +33 -1
- package/frameworks/react/index.tsx +4 -0
- package/frameworks/react/runtime.tsx +16 -2
- package/llms-full.txt +1 -1
- package/llms.txt +1 -1
- package/package.json +29 -11
- 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 +305 -0
- package/src/agent-tooling/mcp/tools/reference.ts +132 -0
- package/src/agent-tooling/mcp/tools/scaffold.ts +1627 -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/elements/compiled.css +1 -1
- package/src/elements/define.tsx +7 -1
- package/src/elements/element-types.d.ts +2 -1
- package/src/elements/register-impl.ts +55 -0
- package/src/elements/register.ts +17 -51
- package/theme.css +4 -2
- package/src/components/artifact.stories.tsx +0 -138
- package/src/components/attachments.stories.tsx +0 -303
- package/src/components/attachments.test.tsx +0 -64
- package/src/components/chain-of-thought.stories.tsx +0 -211
- package/src/components/chat-container.stories.tsx +0 -187
- package/src/components/chat-thread.test.tsx +0 -58
- package/src/components/checkpoint.stories.tsx +0 -102
- package/src/components/code-block.stories.tsx +0 -150
- package/src/components/confirm-card.stories.tsx +0 -74
- package/src/components/context.stories.tsx +0 -229
- package/src/components/context.test.tsx +0 -133
- package/src/components/conversation-item.stories.tsx +0 -125
- package/src/components/conversation-list.stories.tsx +0 -133
- package/src/components/default-input.test.tsx +0 -111
- package/src/components/empty.stories.tsx +0 -434
- package/src/components/feedback-bar.stories.tsx +0 -138
- package/src/components/feedback-bar.test.tsx +0 -103
- package/src/components/file-tree.stories.tsx +0 -73
- package/src/components/file-upload.stories.tsx +0 -156
- package/src/components/image.stories.tsx +0 -89
- package/src/components/loader.stories.tsx +0 -181
- package/src/components/markdown.stories.tsx +0 -180
- package/src/components/message-action-bar.test.tsx +0 -128
- package/src/components/message-narrow.stories.tsx +0 -329
- package/src/components/message-skills.stories.tsx +0 -211
- package/src/components/message.stories.tsx +0 -281
- package/src/components/model-switcher.stories.tsx +0 -123
- package/src/components/model-switcher.test.tsx +0 -65
- package/src/components/prompt-input.stories.tsx +0 -222
- package/src/components/prompt-suggestion.stories.tsx +0 -142
- package/src/components/reasoning.stories.tsx +0 -140
- package/src/components/resizable.test.tsx +0 -226
- package/src/components/scroll-button.stories.tsx +0 -100
- package/src/components/slash-command.stories.tsx +0 -163
- package/src/components/source-list.test.tsx +0 -152
- package/src/components/source.stories.tsx +0 -124
- package/src/components/tasks-card.stories.tsx +0 -78
- package/src/components/text-shimmer.stories.tsx +0 -87
- package/src/components/thinking-bar.stories.tsx +0 -87
- package/src/components/tool.stories.tsx +0 -153
- package/src/components/voice-input.stories.tsx +0 -83
- package/src/elements/artifact.stories.tsx +0 -506
- package/src/elements/attachments.stories.tsx +0 -190
- package/src/elements/card.stories.tsx +0 -113
- package/src/elements/cards.stories.tsx +0 -59
- package/src/elements/catalog.stories.tsx +0 -491
- package/src/elements/chain-of-thought.declarative.test.tsx +0 -153
- package/src/elements/chain-of-thought.stories.tsx +0 -113
- package/src/elements/chat-scope-picker.stories.tsx +0 -73
- package/src/elements/chat-workspace.stories.tsx +0 -288
- package/src/elements/chat.stories.tsx +0 -151
- package/src/elements/checkpoint.stories.tsx +0 -72
- package/src/elements/choice.stories.tsx +0 -240
- package/src/elements/code-block.stories.tsx +0 -83
- package/src/elements/composed-shell.stories.tsx +0 -316
- package/src/elements/confirm-card.stories.tsx +0 -227
- package/src/elements/context-meter.stories.tsx +0 -151
- package/src/elements/conversation-list.declarative.test.tsx +0 -137
- package/src/elements/conversation-list.stories.tsx +0 -243
- package/src/elements/embed.stories.tsx +0 -213
- package/src/elements/empty.stories.tsx +0 -111
- package/src/elements/feedback-bar.stories.tsx +0 -114
- package/src/elements/file-tree.stories.tsx +0 -134
- package/src/elements/file-upload.stories.tsx +0 -82
- package/src/elements/form.stories.tsx +0 -248
- package/src/elements/image.stories.tsx +0 -71
- package/src/elements/link-preview.stories.tsx +0 -209
- package/src/elements/loader.stories.tsx +0 -88
- package/src/elements/markdown.stories.tsx +0 -76
- package/src/elements/message-skills.declarative.test.tsx +0 -104
- package/src/elements/message-skills.stories.tsx +0 -114
- package/src/elements/message.stories.tsx +0 -218
- package/src/elements/model-switcher.declarative.test.tsx +0 -130
- package/src/elements/model-switcher.stories.tsx +0 -198
- package/src/elements/popover.stories.tsx +0 -80
- package/src/elements/prompt-input-slash-command.test.tsx +0 -128
- package/src/elements/prompt-input-stoppable.test.tsx +0 -88
- package/src/elements/prompt-input-toolbar-actions.test.tsx +0 -120
- package/src/elements/prompt-input.stories.tsx +0 -331
- package/src/elements/prompt-suggestions.declarative.test.tsx +0 -164
- package/src/elements/prompt-suggestions.stories.tsx +0 -213
- package/src/elements/reasoning.stories.tsx +0 -77
- package/src/elements/remote.stories.tsx +0 -314
- package/src/elements/resizable.stories.tsx +0 -426
- package/src/elements/response-stream.stories.tsx +0 -79
- package/src/elements/scroll-button.stories.tsx +0 -202
- package/src/elements/scroll-button.test.tsx +0 -148
- package/src/elements/source-list.stories.tsx +0 -143
- package/src/elements/source.stories.tsx +0 -88
- package/src/elements/switch.stories.tsx +0 -56
- package/src/elements/tasks.stories.tsx +0 -237
- package/src/elements/text-shimmer.stories.tsx +0 -64
- package/src/elements/thinking-bar.stories.tsx +0 -72
- package/src/elements/tool.stories.tsx +0 -89
- package/src/elements/voice-input.stories.tsx +0 -88
- package/src/primitives/controllable.test.ts +0 -47
- package/src/stories/chat-panel-layout.stories.tsx +0 -145
- package/src/stories/chat-scene.tsx +0 -571
- package/src/stories/checkpoint-restore.stories.tsx +0 -256
- package/src/stories/context-usage.stories.tsx +0 -212
- package/src/stories/conversation-with-reasoning.stories.tsx +0 -182
- package/src/stories/conversation-with-sources.stories.tsx +0 -471
- package/src/stories/docs/Accessibility.mdx +0 -119
- package/src/stories/docs/ChildElements.mdx +0 -269
- package/src/stories/docs/ForAIAgents.mdx +0 -162
- package/src/stories/docs/GettingStarted.mdx +0 -65
- package/src/stories/docs/Installation.mdx +0 -83
- package/src/stories/docs/Introduction.mdx +0 -50
- package/src/stories/docs/SolidJsAdvanced.mdx +0 -17
- package/src/stories/docs/Theming.mdx +0 -85
- package/src/stories/docs/element-controls.ts +0 -121
- package/src/stories/docs/frameworks/Angular.mdx +0 -245
- package/src/stories/docs/frameworks/Html.mdx +0 -227
- package/src/stories/docs/frameworks/Overview.mdx +0 -47
- package/src/stories/docs/frameworks/React.mdx +0 -227
- package/src/stories/docs/frameworks/Solid.mdx +0 -173
- package/src/stories/docs/frameworks/Svelte.mdx +0 -194
- package/src/stories/docs/frameworks/Vue.mdx +0 -238
- package/src/stories/docs/generative-ui-overview.mdx +0 -186
- package/src/stories/docs/recipes/SpeechToText.mdx +0 -7
- package/src/stories/docs/recipes/Streaming.mdx +0 -68
- package/src/stories/docs/recipes/TextToSpeech.mdx +0 -35
- package/src/stories/docs/theme-editor/canvas.tsx +0 -32
- package/src/stories/docs/theme-editor/inspector.tsx +0 -66
- package/src/stories/docs/theme-editor/presets.test.ts +0 -32
- package/src/stories/docs/theme-editor/presets.ts +0 -64
- package/src/stories/docs/theme-editor/theme-css.test.ts +0 -19
- package/src/stories/docs/theme-editor/theme-css.ts +0 -15
- package/src/stories/docs/theme-editor/theme-editor.tsx +0 -146
- package/src/stories/docs/theme-tokens.tsx +0 -174
- package/src/stories/examples/ChoosingComponents.mdx +0 -106
- package/src/stories/examples/sample-data.ts +0 -79
- package/src/stories/examples/usage/checkpoint-restore.ts +0 -156
- package/src/stories/examples/usage/context-usage.ts +0 -591
- package/src/stories/examples/usage/conversation-with-reasoning.ts +0 -224
- package/src/stories/examples/usage/conversation-with-sources.ts +0 -589
- package/src/stories/examples/usage/empty-state.ts +0 -144
- package/src/stories/examples/usage/full-chat-app.ts +0 -277
- package/src/stories/examples/usage/index.ts +0 -63
- package/src/stories/examples/usage/message-actions.ts +0 -704
- package/src/stories/examples/usage/pattern-centered-conversation.ts +0 -446
- package/src/stories/examples/usage/pattern-chat-panel-layout.ts +0 -442
- package/src/stories/examples/usage/pattern-docked-widget.ts +0 -479
- package/src/stories/examples/usage/prompt-input-variants.ts +0 -1356
- package/src/stories/examples/usage/streaming-response.ts +0 -687
- package/src/stories/examples/usage/types.ts +0 -33
- package/src/stories/full-chat.stories.tsx +0 -18
- package/src/stories/message-actions.stories.tsx +0 -230
- package/src/stories/pattern-centered-conversation.stories.tsx +0 -93
- package/src/stories/pattern-docked-widget.stories.tsx +0 -93
- package/src/stories/pattern-empty-state.stories.tsx +0 -76
- package/src/stories/prompt-input-variants.stories.tsx +0 -456
- package/src/stories/streaming-response.stories.tsx +0 -438
- package/src/stories/theme-editor.stories.tsx +0 -16
- package/src/stories/token-reference.stories.tsx +0 -18
- package/src/stories/typography.stories.tsx +0 -78
- package/src/ui/avatar.stories.tsx +0 -103
- package/src/ui/badge.stories.tsx +0 -86
- package/src/ui/button.stories.tsx +0 -145
- package/src/ui/collapsible.stories.tsx +0 -69
- package/src/ui/dropdown.stories.tsx +0 -59
- package/src/ui/hover-card.stories.tsx +0 -77
- package/src/ui/hover-card.test.tsx +0 -30
- package/src/ui/overlay.stories.tsx +0 -115
- package/src/ui/popover.stories.tsx +0 -81
- package/src/ui/popover.test.tsx +0 -99
- package/src/ui/resizable.stories.tsx +0 -236
- package/src/ui/scroll-area.stories.tsx +0 -50
- package/src/ui/separator.stories.tsx +0 -81
- package/src/ui/skeleton.stories.tsx +0 -337
- package/src/ui/switch.stories.tsx +0 -51
- package/src/ui/switch.test.tsx +0 -59
- package/src/ui/textarea.stories.tsx +0 -76
- package/src/ui/tooltip.stories.tsx +0 -74
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
-
import { onMount } from 'solid-js';
|
|
3
|
-
import './register'; // side effect: registers <kai-chat>, <kai-conversations>, <kai-prompt-input>
|
|
4
|
-
import type { AttachmentData } from '../components/attachments';
|
|
5
|
-
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
6
|
-
|
|
7
|
-
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
8
|
-
declare module 'solid-js' {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
-
namespace JSX {
|
|
11
|
-
interface IntrinsicElements {
|
|
12
|
-
'kai-prompt-input': JSX.HTMLAttributes<HTMLElement>;
|
|
13
|
-
'kai-action': JSX.HTMLAttributes<HTMLElement> & { icon?: string; tooltip?: string };
|
|
14
|
-
'kai-slash-command': JSX.HTMLAttributes<HTMLElement> & { command?: string; description?: string; category?: string };
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const sampleSuggestions: string[] = [
|
|
20
|
-
'Summarize this thread',
|
|
21
|
-
'Draft a reply',
|
|
22
|
-
'Explain like I am five',
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
function imgData(fill: string, glyph: string) {
|
|
26
|
-
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="96" height="96"><rect width="96" height="96" rx="12" fill="${fill}"/><text x="48" y="60" font-size="42" text-anchor="middle" fill="white">${glyph}</text></svg>`;
|
|
27
|
-
return 'data:image/svg+xml;utf8,' + encodeURIComponent(svg);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const sampleAttachments: AttachmentData[] = [
|
|
31
|
-
{ id: 'a1', type: 'file', filename: 'architecture.png', mediaType: 'image/png', url: imgData('#7c3aed', '◆') },
|
|
32
|
-
{ id: 'a2', type: 'file', filename: 'spec.pdf', mediaType: 'application/pdf' },
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
interface PromptInputEl extends HTMLElement {
|
|
36
|
-
value?: string;
|
|
37
|
-
placeholder?: string;
|
|
38
|
-
disabled?: boolean;
|
|
39
|
-
loading?: boolean;
|
|
40
|
-
suggestions?: string[];
|
|
41
|
-
search?: boolean;
|
|
42
|
-
voice?: boolean;
|
|
43
|
-
attachments?: AttachmentData[];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Live demo of the actual `<kai-prompt-input>` custom element (Shadow DOM and all). */
|
|
47
|
-
function PromptInputElement(props: { search?: boolean; voice?: boolean; attachments?: AttachmentData[]; args?: Record<string, unknown> }) {
|
|
48
|
-
let el: PromptInputEl | undefined;
|
|
49
|
-
onMount(() => {
|
|
50
|
-
if (!el) return;
|
|
51
|
-
// Default fixed data
|
|
52
|
-
el.placeholder = 'Ask anything...';
|
|
53
|
-
el.suggestions = sampleSuggestions;
|
|
54
|
-
if (props.search) el.setAttribute('search', '');
|
|
55
|
-
if (props.voice) el.setAttribute('voice', '');
|
|
56
|
-
if (props.attachments) el.attachments = props.attachments;
|
|
57
|
-
// Scalar args from Controls
|
|
58
|
-
const args = props.args;
|
|
59
|
-
if (args) {
|
|
60
|
-
const scalarNames = [
|
|
61
|
-
'value', 'placeholder', 'disabled', 'loading', 'suggestionMode',
|
|
62
|
-
'slashCompact', 'search', 'voice',
|
|
63
|
-
];
|
|
64
|
-
for (const name of scalarNames) {
|
|
65
|
-
if (name in args) (el as unknown as Record<string, unknown>)[name] = args[name];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
el.addEventListener('kai-search', () => console.log('search clicked'));
|
|
69
|
-
el.addEventListener('kai-voice', () => console.log('voice clicked'));
|
|
70
|
-
});
|
|
71
|
-
return (
|
|
72
|
-
<kai-prompt-input
|
|
73
|
-
ref={(e) => (el = e as PromptInputEl)}
|
|
74
|
-
style={{ display: 'block', width: '100%', padding: '16px' }}
|
|
75
|
-
/>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
80
|
-
<kai-prompt-input id="input" style="display:block; width:100%;"></kai-prompt-input>
|
|
81
|
-
|
|
82
|
-
<script type="module">
|
|
83
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
84
|
-
|
|
85
|
-
const input = document.getElementById('input');
|
|
86
|
-
input.placeholder = 'Ask anything...';
|
|
87
|
-
input.suggestions = ['Summarize this thread', 'Draft a reply'];
|
|
88
|
-
// input.loading = true; // shows the busy state while a response streams
|
|
89
|
-
// input.disabled = true; // blocks typing and submit
|
|
90
|
-
|
|
91
|
-
// events are CustomEvents on the element (they do not bubble)
|
|
92
|
-
input.addEventListener('kai-submit', (e) => console.log('send:', e.detail.value));
|
|
93
|
-
input.addEventListener('kai-value-change', (e) => console.log('typing:', e.detail.value));
|
|
94
|
-
input.addEventListener('kai-suggestion-click', (e) => console.log('picked:', e.detail.value));
|
|
95
|
-
</script>`;
|
|
96
|
-
|
|
97
|
-
const SOLID_SNIPPET = `import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
98
|
-
import { onMount } from 'solid-js';
|
|
99
|
-
|
|
100
|
-
function Composer() {
|
|
101
|
-
let el: HTMLElement & {
|
|
102
|
-
value?: string;
|
|
103
|
-
placeholder?: string;
|
|
104
|
-
disabled?: boolean;
|
|
105
|
-
loading?: boolean;
|
|
106
|
-
suggestions?: string[];
|
|
107
|
-
};
|
|
108
|
-
onMount(() => {
|
|
109
|
-
el.placeholder = 'Ask anything...';
|
|
110
|
-
el.suggestions = ['Summarize this thread', 'Draft a reply'];
|
|
111
|
-
});
|
|
112
|
-
return (
|
|
113
|
-
<kai-prompt-input
|
|
114
|
-
ref={el}
|
|
115
|
-
style={{ display: 'block', width: '100%' }}
|
|
116
|
-
on:kai-submit={(e) => console.log('send:', e.detail.value)}
|
|
117
|
-
on:kai-value-change={(e) => console.log('typing:', e.detail.value)}
|
|
118
|
-
on:kai-suggestion-click={(e) => console.log('picked:', e.detail.value)}
|
|
119
|
-
/>
|
|
120
|
-
);
|
|
121
|
-
}`;
|
|
122
|
-
|
|
123
|
-
const meta = {
|
|
124
|
-
title: 'Components/PromptInput',
|
|
125
|
-
tags: ['autodocs'],
|
|
126
|
-
argTypes: argTypesFor('kai-prompt-input'),
|
|
127
|
-
parameters: {
|
|
128
|
-
layout: 'fullscreen',
|
|
129
|
-
docs: {
|
|
130
|
-
description: specDescription('kai-prompt-input', [
|
|
131
|
-
'`<kai-prompt-input>` is the framework-agnostic **web component** version of the chat composer — an auto-resizing textarea with a send button and optional suggestion chips, isolated in **Shadow DOM** so the host page\'s CSS can\'t leak in and the kit\'s styles can\'t leak out. SolidJS is bundled in, so the host needs nothing.',
|
|
132
|
-
'**When to use:** adding a message composer to a non-Solid app (React, Vue, Svelte, plain HTML), or anywhere you want zero style conflicts. If you *are* in SolidJS and want fine-grained control, compose the `PromptInput` primitives instead.',
|
|
133
|
-
'**How to use:** register once with `import \'@kitn.ai/ui/elements\'`, configure it with JS **properties** (`placeholder`, `value`, `disabled`, `loading`, `suggestions`, `attachments`) and flag attributes (`search`, `voice` to show the Globe/Mic toolbar buttons), and listen for **CustomEvents** (`kai-submit`, `kai-value-change`, `kai-suggestion-click`, `kai-search`, `kai-voice`) directly on the element. Leave `value` unset to let the element manage its own input state; seed `attachments` to pre-populate staged files. **Custom toolbar buttons:** place `<kai-action id icon tooltip>` elements as children — they are invisible data carriers (Shadow DOM hides them) that the element reads and renders as extra ghost icon buttons in the left toolbar. Each click fires a `kai-toolbar-action` CustomEvent with `detail.action` equal to the action id (the same `<kai-action>` descriptor element that `<kai-message>` uses — composition symmetry).',
|
|
134
|
-
'**Slash commands (declarative):** place `<kai-slash-command command="id" description="…">Label</kai-slash-command>` elements as children — invisible data carriers merged with the `slashCommands` JS property. Typing `/` opens the palette with the combined list; selecting an item fires `kai-slash-select` with `detail.command`. Prop items appear first; declarative children are appended.',
|
|
135
|
-
'**Placement:** pinned to the bottom of a chat surface, full width. Set `loading` while a response streams to show the busy state, and `disabled` to block input entirely.',
|
|
136
|
-
'See the **Code** tab below for the HTML usage; the *SolidJS* story shows the same element inside a Solid component.',
|
|
137
|
-
]),
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
} satisfies Meta;
|
|
141
|
-
|
|
142
|
-
export default meta;
|
|
143
|
-
type Story = StoryObj;
|
|
144
|
-
|
|
145
|
-
/** The element used the plain-HTML / any-framework way. */
|
|
146
|
-
export const Default: Story = {
|
|
147
|
-
args: {
|
|
148
|
-
placeholder: 'Send a message...',
|
|
149
|
-
disabled: false,
|
|
150
|
-
loading: false,
|
|
151
|
-
suggestionMode: 'submit',
|
|
152
|
-
slashCompact: false,
|
|
153
|
-
search: false,
|
|
154
|
-
voice: false,
|
|
155
|
-
},
|
|
156
|
-
render: (args: Record<string, unknown>) => <PromptInputElement args={args} />,
|
|
157
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
/** The same element used inside a SolidJS component (properties via `ref`, events via `on:`). */
|
|
161
|
-
export const InSolidJS: Story = {
|
|
162
|
-
name: 'In SolidJS',
|
|
163
|
-
render: () => <PromptInputElement />,
|
|
164
|
-
parameters: { docs: { source: { code: SOLID_SNIPPET, language: 'tsx' } } },
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const TOOLBAR_SNIPPET = `<!-- show the Search (Globe) + Voice (Mic) toolbar buttons -->
|
|
168
|
-
<kai-prompt-input id="input" search voice></kai-prompt-input>
|
|
169
|
-
|
|
170
|
-
<script type="module">
|
|
171
|
-
import '@kitn.ai/ui/elements';
|
|
172
|
-
const input = document.getElementById('input');
|
|
173
|
-
input.addEventListener('kai-search', () => console.log('search clicked'));
|
|
174
|
-
input.addEventListener('kai-voice', () => console.log('voice clicked'));
|
|
175
|
-
</script>`;
|
|
176
|
-
|
|
177
|
-
/** With the **microphone** (and search) toolbar buttons enabled via the `voice`
|
|
178
|
-
* and `search` flags. Clicking them fires `kai-voice` / `kai-search` CustomEvents. */
|
|
179
|
-
export const WithVoiceAndSearch: Story = {
|
|
180
|
-
name: 'With Voice & Search',
|
|
181
|
-
render: () => <PromptInputElement search voice />,
|
|
182
|
-
parameters: { docs: { source: { code: TOOLBAR_SNIPPET, language: 'html' } } },
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const ATTACHMENTS_SNIPPET = `<!-- seed staged attachments without an upload -->
|
|
186
|
-
<kai-prompt-input id="input" voice></kai-prompt-input>
|
|
187
|
-
|
|
188
|
-
<script type="module">
|
|
189
|
-
import '@kitn.ai/ui/elements';
|
|
190
|
-
const input = document.getElementById('input');
|
|
191
|
-
input.attachments = [
|
|
192
|
-
{ id: 'a1', type: 'file', filename: 'architecture.png',
|
|
193
|
-
mediaType: 'image/png', url: 'data:image/svg+xml;utf8,...' },
|
|
194
|
-
{ id: 'a2', type: 'file', filename: 'spec.pdf', mediaType: 'application/pdf' },
|
|
195
|
-
];
|
|
196
|
-
</script>`;
|
|
197
|
-
|
|
198
|
-
/** Pre-populated with a couple of **attachments** (an image + a file) via the
|
|
199
|
-
* `attachments` property, with the mic shown too. The paperclip still adds
|
|
200
|
-
* more, and each chip can be removed. */
|
|
201
|
-
export const WithAttachments: Story = {
|
|
202
|
-
name: 'With Attachments',
|
|
203
|
-
render: () => <PromptInputElement voice attachments={sampleAttachments} />,
|
|
204
|
-
parameters: { docs: { source: { code: ATTACHMENTS_SNIPPET, language: 'html' } } },
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const CUSTOM_TOOLBAR_SNIPPET = `<kai-prompt-input id="input" voice></kai-prompt-input>
|
|
208
|
-
|
|
209
|
-
<script type="module">
|
|
210
|
-
import '@kitn.ai/ui/elements';
|
|
211
|
-
|
|
212
|
-
const input = document.getElementById('input');
|
|
213
|
-
|
|
214
|
-
// Inject <kai-action> children as toolbar buttons (declarative composition).
|
|
215
|
-
['attach', 'translate', 'bookmark'].forEach((id, i) => {
|
|
216
|
-
const el = document.createElement('kai-action');
|
|
217
|
-
el.id = id;
|
|
218
|
-
el.setAttribute('icon', ['paperclip', 'flag', 'bookmark'][i]);
|
|
219
|
-
el.setAttribute('tooltip', ['Attach', 'Translate', 'Bookmark'][i]);
|
|
220
|
-
input.appendChild(el);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
input.addEventListener('kai-toolbar-action', (e) => {
|
|
224
|
-
console.log('toolbar action:', e.detail.action);
|
|
225
|
-
});
|
|
226
|
-
input.addEventListener('kai-submit', (e) => console.log('submit:', e.detail.value));
|
|
227
|
-
</script>`;
|
|
228
|
-
|
|
229
|
-
const SLASH_COMMAND_SNIPPET = `<kai-prompt-input id="input" style="display:block; width:100%;"></kai-prompt-input>
|
|
230
|
-
|
|
231
|
-
<script type="module">
|
|
232
|
-
import '@kitn.ai/ui/elements';
|
|
233
|
-
|
|
234
|
-
const input = document.getElementById('input');
|
|
235
|
-
|
|
236
|
-
// Inject <kai-slash-command> children — invisible data carriers read via
|
|
237
|
-
// querySelectorAll + MutationObserver, merged with any slashCommands property.
|
|
238
|
-
[
|
|
239
|
-
{ command: 'summarize', description: 'Summarize the thread' },
|
|
240
|
-
{ command: 'translate', description: 'Translate to English' },
|
|
241
|
-
{ command: 'explain', description: "Explain like I'm five" },
|
|
242
|
-
].forEach(({ command, description }) => {
|
|
243
|
-
const el = document.createElement('kai-slash-command');
|
|
244
|
-
el.setAttribute('command', command);
|
|
245
|
-
el.setAttribute('description', description);
|
|
246
|
-
el.textContent = command; // becomes the label
|
|
247
|
-
input.appendChild(el);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
input.addEventListener('kai-slash-select', (e) => {
|
|
251
|
-
console.log('slash selected:', e.detail.command);
|
|
252
|
-
});
|
|
253
|
-
</script>`;
|
|
254
|
-
|
|
255
|
-
/** Composition: place **`<kai-action>`** children inside `<kai-prompt-input>` to add
|
|
256
|
-
* custom ghost icon buttons in the toolbar. Each click fires a `kai-toolbar-action` event
|
|
257
|
-
* with `detail.action` equal to the action id — the same `<kai-action>` descriptor
|
|
258
|
-
* element that `<kai-message>` uses for its action bar (composition symmetry). */
|
|
259
|
-
export const WithCustomToolbarActions: Story = {
|
|
260
|
-
name: 'Custom Toolbar Actions (kai-action)',
|
|
261
|
-
render: () => {
|
|
262
|
-
let el: HTMLElement | undefined;
|
|
263
|
-
onMount(() => {
|
|
264
|
-
if (!el) return;
|
|
265
|
-
el.setAttribute('placeholder', 'Ask anything...');
|
|
266
|
-
el.addEventListener('kai-toolbar-action', (e: Event) => {
|
|
267
|
-
console.log('toolbar action:', (e as CustomEvent<{ action: string }>).detail.action);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
return (
|
|
271
|
-
<div style={{ padding: '16px', width: '100%' }}>
|
|
272
|
-
<kai-prompt-input
|
|
273
|
-
ref={(e: HTMLElement) => (el = e)}
|
|
274
|
-
style={{ display: 'block', width: '100%' }}
|
|
275
|
-
>
|
|
276
|
-
{/* <kai-action> children are invisible data carriers — Shadow DOM hides them.
|
|
277
|
-
The element reads them via querySelectorAll + MutationObserver and renders
|
|
278
|
-
a ghost icon button per entry in the left toolbar. Clicking fires kai-action. */}
|
|
279
|
-
<kai-action id="attach" icon="paperclip" tooltip="Attach" />
|
|
280
|
-
<kai-action id="translate" icon="flag" tooltip="Translate" />
|
|
281
|
-
<kai-action id="bookmark" icon="bookmark" tooltip="Bookmark" />
|
|
282
|
-
</kai-prompt-input>
|
|
283
|
-
<p style={{ 'margin-top': '8px', 'font-size': '12px', color: 'var(--color-muted-foreground)' }}>
|
|
284
|
-
Open the browser console to see <code>kai-action</code> events when you click the extra toolbar buttons.
|
|
285
|
-
</p>
|
|
286
|
-
</div>
|
|
287
|
-
);
|
|
288
|
-
},
|
|
289
|
-
parameters: { docs: { source: { code: CUSTOM_TOOLBAR_SNIPPET, language: 'html' } } },
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
/** Composition: place **`<kai-slash-command>`** children inside `<kai-prompt-input>`
|
|
293
|
-
* to declare slash commands without setting the `slashCommands` JS property.
|
|
294
|
-
* Type `/` in the input to open the palette. Each `<kai-slash-command>` child maps:
|
|
295
|
-
* `command` attr → id, textContent → label, `description` attr → description.
|
|
296
|
-
* Selection fires `kai-slash-select` with `detail.command`.
|
|
297
|
-
* Prop (`slashCommands`) and declarative children are merged — prop items first. */
|
|
298
|
-
export const DeclarativeSlashCommands: Story = {
|
|
299
|
-
name: 'Declarative Slash Commands (kai-slash-command)',
|
|
300
|
-
render: () => {
|
|
301
|
-
let el: HTMLElement | undefined;
|
|
302
|
-
onMount(() => {
|
|
303
|
-
if (!el) return;
|
|
304
|
-
el.setAttribute('placeholder', 'Type / to open the command palette…');
|
|
305
|
-
el.addEventListener('kai-slash-select', (e: Event) => {
|
|
306
|
-
console.log('slash selected:', (e as CustomEvent<{ command: unknown }>).detail.command);
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
return (
|
|
310
|
-
<div style={{ padding: '16px', width: '100%' }}>
|
|
311
|
-
<kai-prompt-input
|
|
312
|
-
ref={(e: HTMLElement) => (el = e)}
|
|
313
|
-
style={{ display: 'block', width: '100%' }}
|
|
314
|
-
>
|
|
315
|
-
{/* <kai-slash-command> children are invisible data carriers — Shadow DOM hides them.
|
|
316
|
-
The element reads them via querySelectorAll + MutationObserver.
|
|
317
|
-
command attr → id, textContent → label, description attr → description. */}
|
|
318
|
-
<kai-slash-command command="summarize" description="Summarize the thread">summarize</kai-slash-command>
|
|
319
|
-
<kai-slash-command command="translate" description="Translate to English">translate</kai-slash-command>
|
|
320
|
-
<kai-slash-command command="explain" description="Explain like I'm five">explain</kai-slash-command>
|
|
321
|
-
</kai-prompt-input>
|
|
322
|
-
<p style={{ 'margin-top': '8px', 'font-size': '12px', color: 'var(--color-muted-foreground)' }}>
|
|
323
|
-
Type <code>/</code> in the input to open the command palette. Open the browser
|
|
324
|
-
console to see <code>kai-slash-select</code> events on selection.
|
|
325
|
-
</p>
|
|
326
|
-
</div>
|
|
327
|
-
);
|
|
328
|
-
},
|
|
329
|
-
parameters: { docs: { source: { code: SLASH_COMMAND_SNIPPET, language: 'html' } } },
|
|
330
|
-
};
|
|
331
|
-
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for the declarative `<kai-suggestion>` light-DOM API of
|
|
3
|
-
* `<kai-suggestions>`.
|
|
4
|
-
*
|
|
5
|
-
* Strategy: the `defineWebComponent` call registers a real Shadow-DOM custom
|
|
6
|
-
* element which requires a full browser environment (Constructable Stylesheets,
|
|
7
|
-
* shadow roots, etc.) and is therefore not suitable for jsdom unit tests.
|
|
8
|
-
* Instead we:
|
|
9
|
-
* 1. Test the exported `parseSuggestionNode` helper in isolation — it has no
|
|
10
|
-
* DOM dependencies beyond `Element`, which jsdom provides perfectly.
|
|
11
|
-
* 2. Test that the merged list of prop + slotted items renders chip buttons
|
|
12
|
-
* and fires click handlers correctly via `PromptSuggestion` directly,
|
|
13
|
-
* mirroring the pattern used in `message-action-bar.test.tsx`.
|
|
14
|
-
*/
|
|
15
|
-
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
16
|
-
import '@testing-library/jest-dom/vitest';
|
|
17
|
-
import { render, cleanup, fireEvent } from '@solidjs/testing-library';
|
|
18
|
-
import { For } from 'solid-js';
|
|
19
|
-
import { parseSuggestionNode } from './prompt-suggestions';
|
|
20
|
-
import { PromptSuggestion } from '../components/prompt-suggestion';
|
|
21
|
-
|
|
22
|
-
afterEach(cleanup);
|
|
23
|
-
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
// parseSuggestionNode — pure helper
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
describe('parseSuggestionNode', () => {
|
|
29
|
-
function makeNode(textContent: string, value?: string): Element {
|
|
30
|
-
const el = document.createElement('kai-suggestion');
|
|
31
|
-
el.textContent = textContent;
|
|
32
|
-
if (value !== undefined) el.setAttribute('value', value);
|
|
33
|
-
return el;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
it('uses textContent as label', () => {
|
|
37
|
-
const item = parseSuggestionNode(makeNode('Use Vue'));
|
|
38
|
-
expect(item).toMatchObject({ label: 'Use Vue' });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('uses value attribute as value when present', () => {
|
|
42
|
-
const item = parseSuggestionNode(makeNode('Use Vue', 'vue'));
|
|
43
|
-
expect(item).toMatchObject({ label: 'Use Vue', value: 'vue' });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('falls back to textContent as value when value attribute is absent', () => {
|
|
47
|
-
const item = parseSuggestionNode(makeNode('Use Vue'));
|
|
48
|
-
expect(item).toMatchObject({ label: 'Use Vue', value: 'Use Vue' });
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('trims leading/trailing whitespace from textContent', () => {
|
|
52
|
-
const item = parseSuggestionNode(makeNode(' Explain the architecture '));
|
|
53
|
-
expect(item).toMatchObject({ label: 'Explain the architecture' });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('handles empty textContent with a value attribute', () => {
|
|
57
|
-
const item = parseSuggestionNode(makeNode('', 'vue'));
|
|
58
|
-
expect(item).toMatchObject({ label: '', value: 'vue' });
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// Merge + render: prop suggestions + slotted suggestions combine correctly
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
|
|
66
|
-
type Item = string | { label: string; value?: string };
|
|
67
|
-
|
|
68
|
-
const labelOf = (s: Item) => (typeof s === 'string' ? s : s.label);
|
|
69
|
-
const valueOf = (s: Item) => (typeof s === 'string' ? s : s.value ?? s.label);
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Minimal test harness that renders a list of `Item`s as `PromptSuggestion`
|
|
73
|
-
* chips and records which value was clicked — mirrors the render path in
|
|
74
|
-
* `prompt-suggestions.tsx`.
|
|
75
|
-
*/
|
|
76
|
-
function SuggestionList(props: { items: Item[]; onSelect: (value: string) => void }) {
|
|
77
|
-
return (
|
|
78
|
-
<div>
|
|
79
|
-
<For each={props.items}>
|
|
80
|
-
{(s) => (
|
|
81
|
-
<PromptSuggestion onClick={() => props.onSelect(valueOf(s))}>
|
|
82
|
-
{labelOf(s)}
|
|
83
|
-
</PromptSuggestion>
|
|
84
|
-
)}
|
|
85
|
-
</For>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
describe('suggestion chip rendering and click events', () => {
|
|
91
|
-
it('renders one chip per item', () => {
|
|
92
|
-
const { getByText } = render(() => (
|
|
93
|
-
<SuggestionList
|
|
94
|
-
items={['Explain the architecture', 'Show me a code example']}
|
|
95
|
-
onSelect={() => {}}
|
|
96
|
-
/>
|
|
97
|
-
));
|
|
98
|
-
expect(getByText('Explain the architecture')).toBeInTheDocument();
|
|
99
|
-
expect(getByText('Show me a code example')).toBeInTheDocument();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('fires onSelect with the string value when a string item is clicked', () => {
|
|
103
|
-
const onSelect = vi.fn();
|
|
104
|
-
const { getByText } = render(() => (
|
|
105
|
-
<SuggestionList items={['Use Vue']} onSelect={onSelect} />
|
|
106
|
-
));
|
|
107
|
-
fireEvent.click(getByText('Use Vue'));
|
|
108
|
-
expect(onSelect).toHaveBeenCalledWith('Use Vue');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('fires onSelect with item.value for an object item with an explicit value', () => {
|
|
112
|
-
const onSelect = vi.fn();
|
|
113
|
-
const { getByText } = render(() => (
|
|
114
|
-
<SuggestionList
|
|
115
|
-
items={[{ label: 'Use Vue', value: 'vue' }]}
|
|
116
|
-
onSelect={onSelect}
|
|
117
|
-
/>
|
|
118
|
-
));
|
|
119
|
-
fireEvent.click(getByText('Use Vue'));
|
|
120
|
-
expect(onSelect).toHaveBeenCalledWith('vue');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('falls back to label as value for an object item without explicit value', () => {
|
|
124
|
-
const onSelect = vi.fn();
|
|
125
|
-
const { getByText } = render(() => (
|
|
126
|
-
<SuggestionList
|
|
127
|
-
items={[{ label: 'Use Vue' }]}
|
|
128
|
-
onSelect={onSelect}
|
|
129
|
-
/>
|
|
130
|
-
));
|
|
131
|
-
fireEvent.click(getByText('Use Vue'));
|
|
132
|
-
expect(onSelect).toHaveBeenCalledWith('Use Vue');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('renders prop items before declarative (slotted) items', () => {
|
|
136
|
-
// Simulate the merge: prop first, slotted second.
|
|
137
|
-
const propItems: Item[] = [{ label: 'Prop item', value: 'prop' }];
|
|
138
|
-
const slottedItems: Item[] = [{ label: 'Slotted item', value: 'slotted' }];
|
|
139
|
-
const merged = [...propItems, ...slottedItems];
|
|
140
|
-
|
|
141
|
-
const { getAllByRole } = render(() => (
|
|
142
|
-
<SuggestionList items={merged} onSelect={() => {}} />
|
|
143
|
-
));
|
|
144
|
-
const buttons = getAllByRole('button');
|
|
145
|
-
expect(buttons).toHaveLength(2);
|
|
146
|
-
expect(buttons[0]).toHaveTextContent('Prop item');
|
|
147
|
-
expect(buttons[1]).toHaveTextContent('Slotted item');
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('parseSuggestionNode produces items that render and fire the correct value', () => {
|
|
151
|
-
// End-to-end: parse a DOM node → render it → click → verify event value.
|
|
152
|
-
const onSelect = vi.fn();
|
|
153
|
-
const el = document.createElement('kai-suggestion');
|
|
154
|
-
el.textContent = 'Use Vue';
|
|
155
|
-
el.setAttribute('value', 'vue');
|
|
156
|
-
|
|
157
|
-
const parsed = parseSuggestionNode(el);
|
|
158
|
-
const { getByText } = render(() => (
|
|
159
|
-
<SuggestionList items={[parsed]} onSelect={onSelect} />
|
|
160
|
-
));
|
|
161
|
-
fireEvent.click(getByText('Use Vue'));
|
|
162
|
-
expect(onSelect).toHaveBeenCalledWith('vue');
|
|
163
|
-
});
|
|
164
|
-
});
|