@kitn.ai/ui 0.14.1
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/LICENSE +21 -0
- package/README.md +394 -0
- package/dist/bash-InADTalH.js +1 -0
- package/dist/core-AYMC6_lb.js +12 -0
- package/dist/css-M7EaDHN_.js +1 -0
- package/dist/custom-elements.json +4739 -0
- package/dist/engine-javascript-vq0WuIJl.js +141 -0
- package/dist/github-dark-dimmed-DUshB20C.js +1 -0
- package/dist/github-light-JYsPkUQd.js +1 -0
- package/dist/host-embed.d.ts +33 -0
- package/dist/html-CPZ3oZQ7.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/javascript-C25yR2R2.js +1 -0
- package/dist/json-DxJze_jm.js +1 -0
- package/dist/kitn-chat-provider.d.ts +2 -0
- package/dist/kitn-chat-provider.es.js +240 -0
- package/dist/kitn-chat.es.js +77 -0
- package/dist/llms/llms-full.txt +1018 -0
- package/dist/llms/llms.txt +104 -0
- package/dist/origin.d.ts +5 -0
- package/dist/provider-runtime.d.ts +27 -0
- package/dist/schemas/card-envelope.schema.json +14 -0
- package/dist/schemas/card-event.schema.json +12 -0
- package/dist/schemas/choice.schema.json +70 -0
- package/dist/schemas/confirm.schema.json +65 -0
- package/dist/schemas/embed.schema.json +65 -0
- package/dist/schemas/form.result.schema.json +7 -0
- package/dist/schemas/form.schema.json +33 -0
- package/dist/schemas/link.schema.json +56 -0
- package/dist/schemas/tasks.result.schema.json +16 -0
- package/dist/schemas/tasks.schema.json +78 -0
- package/dist/svelte--5p79yCD.js +1 -0
- package/dist/theme.tokens.css +176 -0
- package/dist/tsx-B8rCNbgL.js +1 -0
- package/dist/typescript-RycA9KXf.js +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/version.d.ts +4 -0
- package/dist/vue-BmIZj4XD.js +1 -0
- package/dist/wire.d.ts +53 -0
- package/frameworks/react/index.tsx +948 -0
- package/frameworks/react/runtime.tsx +94 -0
- package/llms-full.txt +1018 -0
- package/llms.txt +104 -0
- package/package.json +141 -0
- package/src/components/artifact.stories.tsx +138 -0
- package/src/components/artifact.tsx +743 -0
- package/src/components/attachments.stories.tsx +303 -0
- package/src/components/attachments.test.tsx +64 -0
- package/src/components/attachments.tsx +399 -0
- package/src/components/card-fallback.tsx +28 -0
- package/src/components/card-renderer.tsx +52 -0
- package/src/components/card.tsx +110 -0
- package/src/components/chain-of-thought.stories.tsx +211 -0
- package/src/components/chain-of-thought.tsx +139 -0
- package/src/components/chat-container.stories.tsx +187 -0
- package/src/components/chat-container.tsx +82 -0
- package/src/components/chat-scope-picker.tsx +47 -0
- package/src/components/chat-thread.test.tsx +58 -0
- package/src/components/chat-thread.tsx +249 -0
- package/src/components/checkpoint.stories.tsx +102 -0
- package/src/components/checkpoint.tsx +88 -0
- package/src/components/choice-card.tsx +569 -0
- package/src/components/code-block.stories.tsx +150 -0
- package/src/components/code-block.tsx +105 -0
- package/src/components/component-meta.json +3735 -0
- package/src/components/confirm-card.stories.tsx +74 -0
- package/src/components/confirm-card.tsx +315 -0
- package/src/components/context.stories.tsx +229 -0
- package/src/components/context.test.tsx +133 -0
- package/src/components/context.tsx +363 -0
- package/src/components/conversation-item.stories.tsx +125 -0
- package/src/components/conversation-item.tsx +16 -0
- package/src/components/conversation-list.stories.tsx +133 -0
- package/src/components/conversation-list.tsx +101 -0
- package/src/components/default-input.test.tsx +111 -0
- package/src/components/embed.tsx +196 -0
- package/src/components/empty.stories.tsx +434 -0
- package/src/components/empty.tsx +166 -0
- package/src/components/feedback-bar.stories.tsx +138 -0
- package/src/components/feedback-bar.test.tsx +103 -0
- package/src/components/feedback-bar.tsx +166 -0
- package/src/components/file-tree.stories.tsx +73 -0
- package/src/components/file-tree.tsx +383 -0
- package/src/components/file-upload.stories.tsx +156 -0
- package/src/components/file-upload.tsx +161 -0
- package/src/components/form-widgets.tsx +461 -0
- package/src/components/form.tsx +873 -0
- package/src/components/image.stories.tsx +89 -0
- package/src/components/image.tsx +67 -0
- package/src/components/link-preview.tsx +194 -0
- package/src/components/loader.stories.tsx +181 -0
- package/src/components/loader.tsx +333 -0
- package/src/components/markdown.stories.tsx +180 -0
- package/src/components/markdown.tsx +81 -0
- package/src/components/message-action-bar.test.tsx +128 -0
- package/src/components/message-narrow.stories.tsx +329 -0
- package/src/components/message-skills.stories.tsx +211 -0
- package/src/components/message-skills.tsx +36 -0
- package/src/components/message.stories.tsx +281 -0
- package/src/components/message.tsx +227 -0
- package/src/components/model-switcher.stories.tsx +123 -0
- package/src/components/model-switcher.test.tsx +65 -0
- package/src/components/model-switcher.tsx +87 -0
- package/src/components/prompt-input.stories.tsx +222 -0
- package/src/components/prompt-input.tsx +211 -0
- package/src/components/prompt-suggestion.stories.tsx +142 -0
- package/src/components/prompt-suggestion.tsx +115 -0
- package/src/components/reasoning.stories.tsx +140 -0
- package/src/components/reasoning.tsx +156 -0
- package/src/components/resizable.test.tsx +226 -0
- package/src/components/response-stream.tsx +103 -0
- package/src/components/scroll-button.stories.tsx +100 -0
- package/src/components/scroll-button.tsx +34 -0
- package/src/components/slash-command.stories.tsx +163 -0
- package/src/components/slash-command.tsx +232 -0
- package/src/components/source-list.test.tsx +152 -0
- package/src/components/source.stories.tsx +124 -0
- package/src/components/source.tsx +129 -0
- package/src/components/tasks-card.stories.tsx +78 -0
- package/src/components/tasks-card.tsx +432 -0
- package/src/components/text-shimmer.stories.tsx +87 -0
- package/src/components/text-shimmer.tsx +37 -0
- package/src/components/thinking-bar.stories.tsx +87 -0
- package/src/components/thinking-bar.tsx +50 -0
- package/src/components/tool.stories.tsx +153 -0
- package/src/components/tool.tsx +184 -0
- package/src/components/use-card-resolution.ts +28 -0
- package/src/components/voice-input.stories.tsx +83 -0
- package/src/components/voice-input.tsx +107 -0
- package/src/elements/artifact.stories.tsx +506 -0
- package/src/elements/artifact.tsx +137 -0
- package/src/elements/attachments.stories.tsx +190 -0
- package/src/elements/attachments.tsx +136 -0
- package/src/elements/card.stories.tsx +113 -0
- package/src/elements/card.tsx +40 -0
- package/src/elements/cards.stories.tsx +59 -0
- package/src/elements/cards.tsx +97 -0
- package/src/elements/catalog.stories.tsx +491 -0
- package/src/elements/chain-of-thought.declarative.test.tsx +153 -0
- package/src/elements/chain-of-thought.stories.tsx +113 -0
- package/src/elements/chain-of-thought.tsx +92 -0
- package/src/elements/chat-scope-picker.stories.tsx +73 -0
- package/src/elements/chat-scope-picker.tsx +36 -0
- package/src/elements/chat-types.ts +42 -0
- package/src/elements/chat-workspace.stories.tsx +288 -0
- package/src/elements/chat-workspace.tsx +161 -0
- package/src/elements/chat.stories.tsx +151 -0
- package/src/elements/chat.tsx +80 -0
- package/src/elements/checkpoint.stories.tsx +72 -0
- package/src/elements/checkpoint.tsx +47 -0
- package/src/elements/choice.stories.tsx +240 -0
- package/src/elements/choice.tsx +48 -0
- package/src/elements/code-block.stories.tsx +83 -0
- package/src/elements/code-block.tsx +42 -0
- package/src/elements/compiled.css +2 -0
- package/src/elements/composed-shell.stories.tsx +316 -0
- package/src/elements/confirm-card.stories.tsx +227 -0
- package/src/elements/confirm-card.tsx +51 -0
- package/src/elements/context-meter.stories.tsx +151 -0
- package/src/elements/context-meter.tsx +121 -0
- package/src/elements/conversation-list.declarative.test.tsx +137 -0
- package/src/elements/conversation-list.stories.tsx +243 -0
- package/src/elements/conversation-list.tsx +80 -0
- package/src/elements/css.ts +5 -0
- package/src/elements/default-input.tsx +247 -0
- package/src/elements/define.tsx +171 -0
- package/src/elements/element-meta.json +3314 -0
- package/src/elements/element-types.d.ts +710 -0
- package/src/elements/embed.stories.tsx +213 -0
- package/src/elements/embed.tsx +35 -0
- package/src/elements/empty.stories.tsx +111 -0
- package/src/elements/empty.tsx +29 -0
- package/src/elements/feedback-bar.stories.tsx +114 -0
- package/src/elements/feedback-bar.tsx +61 -0
- package/src/elements/file-tree.stories.tsx +134 -0
- package/src/elements/file-tree.tsx +52 -0
- package/src/elements/file-upload.stories.tsx +82 -0
- package/src/elements/file-upload.tsx +44 -0
- package/src/elements/form.stories.tsx +248 -0
- package/src/elements/form.tsx +43 -0
- package/src/elements/framework-usage.json +563 -0
- package/src/elements/image.stories.tsx +71 -0
- package/src/elements/image.tsx +32 -0
- package/src/elements/link-preview.stories.tsx +209 -0
- package/src/elements/link-preview.tsx +34 -0
- package/src/elements/loader.stories.tsx +88 -0
- package/src/elements/loader.tsx +25 -0
- package/src/elements/markdown.stories.tsx +76 -0
- package/src/elements/markdown.tsx +38 -0
- package/src/elements/message-skills.declarative.test.tsx +104 -0
- package/src/elements/message-skills.stories.tsx +114 -0
- package/src/elements/message-skills.tsx +85 -0
- package/src/elements/message.stories.tsx +218 -0
- package/src/elements/message.tsx +162 -0
- package/src/elements/model-switcher.declarative.test.tsx +130 -0
- package/src/elements/model-switcher.stories.tsx +198 -0
- package/src/elements/model-switcher.tsx +93 -0
- package/src/elements/popover.stories.tsx +80 -0
- package/src/elements/popover.tsx +59 -0
- package/src/elements/prompt-input-slash-command.test.tsx +128 -0
- package/src/elements/prompt-input-stoppable.test.tsx +88 -0
- package/src/elements/prompt-input-toolbar-actions.test.tsx +120 -0
- package/src/elements/prompt-input.stories.tsx +331 -0
- package/src/elements/prompt-input.tsx +185 -0
- package/src/elements/prompt-suggestions.declarative.test.tsx +164 -0
- package/src/elements/prompt-suggestions.stories.tsx +213 -0
- package/src/elements/prompt-suggestions.tsx +94 -0
- package/src/elements/reasoning.stories.tsx +77 -0
- package/src/elements/reasoning.tsx +50 -0
- package/src/elements/register.ts +56 -0
- package/src/elements/remote.stories.tsx +314 -0
- package/src/elements/remote.tsx +221 -0
- package/src/elements/resizable.d.ts +27 -0
- package/src/elements/resizable.stories.tsx +426 -0
- package/src/elements/resizable.tsx +553 -0
- package/src/elements/response-stream.stories.tsx +79 -0
- package/src/elements/response-stream.tsx +40 -0
- package/src/elements/scroll-button.stories.tsx +202 -0
- package/src/elements/scroll-button.test.tsx +148 -0
- package/src/elements/scroll-button.tsx +126 -0
- package/src/elements/source-list.stories.tsx +143 -0
- package/src/elements/source.stories.tsx +88 -0
- package/src/elements/source.tsx +120 -0
- package/src/elements/styles.css +199 -0
- package/src/elements/switch.stories.tsx +56 -0
- package/src/elements/switch.tsx +43 -0
- package/src/elements/tasks.stories.tsx +237 -0
- package/src/elements/tasks.tsx +46 -0
- package/src/elements/text-shimmer.stories.tsx +64 -0
- package/src/elements/text-shimmer.tsx +28 -0
- package/src/elements/thinking-bar.stories.tsx +72 -0
- package/src/elements/thinking-bar.tsx +34 -0
- package/src/elements/tool.stories.tsx +89 -0
- package/src/elements/tool.tsx +23 -0
- package/src/elements/voice-input.stories.tsx +88 -0
- package/src/elements/voice-input.tsx +41 -0
- package/src/index.ts +253 -0
- package/src/primitives/card-contract.ts +71 -0
- package/src/primitives/card-host.tsx +35 -0
- package/src/primitives/card-registry.tsx +67 -0
- package/src/primitives/card-resolution.ts +36 -0
- package/src/primitives/card-routing.ts +79 -0
- package/src/primitives/card-schemas/card-envelope.schema.json +14 -0
- package/src/primitives/card-schemas/card-event.schema.json +12 -0
- package/src/primitives/card-schemas/choice.schema.json +70 -0
- package/src/primitives/card-schemas/confirm.schema.json +65 -0
- package/src/primitives/card-schemas/embed.schema.json +65 -0
- package/src/primitives/card-schemas/form.result.schema.json +7 -0
- package/src/primitives/card-schemas/form.schema.json +33 -0
- package/src/primitives/card-schemas/link.schema.json +56 -0
- package/src/primitives/card-schemas/tasks.result.schema.json +16 -0
- package/src/primitives/card-schemas/tasks.schema.json +78 -0
- package/src/primitives/card-validate.ts +95 -0
- package/src/primitives/chat-config.tsx +76 -0
- package/src/primitives/controllable.test.ts +47 -0
- package/src/primitives/controllable.ts +21 -0
- package/src/primitives/embed-providers.ts +254 -0
- package/src/primitives/highlighter.ts +157 -0
- package/src/primitives/link-preview.ts +87 -0
- package/src/primitives/pdf-preview.ts +121 -0
- package/src/primitives/use-auto-resize.ts +31 -0
- package/src/primitives/use-resize-observer.ts +12 -0
- package/src/primitives/use-stick-to-bottom.ts +43 -0
- package/src/primitives/use-text-stream.ts +112 -0
- package/src/primitives/use-voice-recorder.ts +50 -0
- package/src/remote/host-embed.ts +345 -0
- package/src/remote/index.ts +2 -0
- package/src/remote/origin.ts +30 -0
- package/src/remote/provider-runtime.ts +259 -0
- package/src/remote/provider.ts +2 -0
- package/src/remote/validate.ts +22 -0
- package/src/remote/version.ts +12 -0
- package/src/remote/wire.ts +48 -0
- package/src/stories/chat-panel-layout.stories.tsx +145 -0
- package/src/stories/chat-scene.tsx +571 -0
- package/src/stories/checkpoint-restore.stories.tsx +256 -0
- package/src/stories/context-usage.stories.tsx +212 -0
- package/src/stories/conversation-with-reasoning.stories.tsx +182 -0
- package/src/stories/conversation-with-sources.stories.tsx +471 -0
- package/src/stories/docs/Accessibility.mdx +119 -0
- package/src/stories/docs/ChildElements.mdx +269 -0
- package/src/stories/docs/ForAIAgents.mdx +162 -0
- package/src/stories/docs/GettingStarted.mdx +65 -0
- package/src/stories/docs/Installation.mdx +83 -0
- package/src/stories/docs/Introduction.mdx +50 -0
- package/src/stories/docs/SolidJsAdvanced.mdx +17 -0
- package/src/stories/docs/Theming.mdx +85 -0
- package/src/stories/docs/element-controls.ts +121 -0
- package/src/stories/docs/frameworks/Angular.mdx +245 -0
- package/src/stories/docs/frameworks/Html.mdx +227 -0
- package/src/stories/docs/frameworks/Overview.mdx +47 -0
- package/src/stories/docs/frameworks/React.mdx +227 -0
- package/src/stories/docs/frameworks/Solid.mdx +173 -0
- package/src/stories/docs/frameworks/Svelte.mdx +194 -0
- package/src/stories/docs/frameworks/Vue.mdx +238 -0
- package/src/stories/docs/generative-ui-overview.mdx +186 -0
- package/src/stories/docs/recipes/SpeechToText.mdx +7 -0
- package/src/stories/docs/recipes/Streaming.mdx +68 -0
- package/src/stories/docs/recipes/TextToSpeech.mdx +35 -0
- package/src/stories/docs/theme-editor/canvas.tsx +32 -0
- package/src/stories/docs/theme-editor/inspector.tsx +66 -0
- package/src/stories/docs/theme-editor/presets.test.ts +32 -0
- package/src/stories/docs/theme-editor/presets.ts +64 -0
- package/src/stories/docs/theme-editor/theme-css.test.ts +19 -0
- package/src/stories/docs/theme-editor/theme-css.ts +15 -0
- package/src/stories/docs/theme-editor/theme-editor.tsx +146 -0
- package/src/stories/docs/theme-tokens.tsx +174 -0
- package/src/stories/examples/ChoosingComponents.mdx +106 -0
- package/src/stories/examples/sample-data.ts +79 -0
- package/src/stories/examples/usage/checkpoint-restore.ts +156 -0
- package/src/stories/examples/usage/context-usage.ts +591 -0
- package/src/stories/examples/usage/conversation-with-reasoning.ts +224 -0
- package/src/stories/examples/usage/conversation-with-sources.ts +589 -0
- package/src/stories/examples/usage/empty-state.ts +144 -0
- package/src/stories/examples/usage/full-chat-app.ts +277 -0
- package/src/stories/examples/usage/index.ts +63 -0
- package/src/stories/examples/usage/message-actions.ts +704 -0
- package/src/stories/examples/usage/pattern-centered-conversation.ts +446 -0
- package/src/stories/examples/usage/pattern-chat-panel-layout.ts +442 -0
- package/src/stories/examples/usage/pattern-docked-widget.ts +479 -0
- package/src/stories/examples/usage/prompt-input-variants.ts +1356 -0
- package/src/stories/examples/usage/streaming-response.ts +687 -0
- package/src/stories/examples/usage/types.ts +33 -0
- package/src/stories/full-chat.stories.tsx +18 -0
- package/src/stories/message-actions.stories.tsx +230 -0
- package/src/stories/pattern-centered-conversation.stories.tsx +93 -0
- package/src/stories/pattern-docked-widget.stories.tsx +93 -0
- package/src/stories/pattern-empty-state.stories.tsx +76 -0
- package/src/stories/prompt-input-variants.stories.tsx +456 -0
- package/src/stories/streaming-response.stories.tsx +438 -0
- package/src/stories/theme-editor.stories.tsx +16 -0
- package/src/stories/token-reference.stories.tsx +18 -0
- package/src/stories/typography.stories.tsx +78 -0
- package/src/types.ts +47 -0
- package/src/ui/action-icons.ts +52 -0
- package/src/ui/avatar.stories.tsx +103 -0
- package/src/ui/avatar.tsx +23 -0
- package/src/ui/badge.stories.tsx +86 -0
- package/src/ui/badge.tsx +21 -0
- package/src/ui/button.stories.tsx +145 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.stories.tsx +69 -0
- package/src/ui/collapsible.tsx +125 -0
- package/src/ui/dropdown.stories.tsx +59 -0
- package/src/ui/dropdown.tsx +196 -0
- package/src/ui/hover-card.stories.tsx +77 -0
- package/src/ui/hover-card.test.tsx +30 -0
- package/src/ui/hover-card.tsx +172 -0
- package/src/ui/overlay.stories.tsx +115 -0
- package/src/ui/overlay.tsx +158 -0
- package/src/ui/popover.stories.tsx +81 -0
- package/src/ui/popover.test.tsx +99 -0
- package/src/ui/popover.tsx +92 -0
- package/src/ui/resizable.stories.tsx +236 -0
- package/src/ui/resizable.tsx +576 -0
- package/src/ui/scroll-area.stories.tsx +50 -0
- package/src/ui/scroll-area.tsx +15 -0
- package/src/ui/separator.stories.tsx +81 -0
- package/src/ui/separator.tsx +10 -0
- package/src/ui/skeleton.stories.tsx +337 -0
- package/src/ui/skeleton.tsx +16 -0
- package/src/ui/switch.stories.tsx +51 -0
- package/src/ui/switch.test.tsx +59 -0
- package/src/ui/switch.tsx +62 -0
- package/src/ui/textarea.stories.tsx +76 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/tooltip.stories.tsx +74 -0
- package/src/ui/tooltip.tsx +68 -0
- package/src/utils/cn.ts +24 -0
- package/theme.css +187 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { onMount } from 'solid-js';
|
|
3
|
+
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
7
|
+
declare module 'solid-js' {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'kai-image': JSX.HTMLAttributes<HTMLElement>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// A small inline SVG, base64-encoded — the same trick the composable example uses.
|
|
17
|
+
const sampleSvg =
|
|
18
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="96" height="96"><rect width="96" height="96" rx="16" fill="#7c3aed"/><text x="48" y="62" font-size="44" text-anchor="middle" fill="white">★</text></svg>';
|
|
19
|
+
const sampleBase64 = btoa(unescape(encodeURIComponent(sampleSvg)));
|
|
20
|
+
|
|
21
|
+
/** Render the actual `<kai-image>` custom element with base64 + media-type. */
|
|
22
|
+
function ImageElement() {
|
|
23
|
+
let el: (HTMLElement & { base64?: string; alt?: string }) | undefined;
|
|
24
|
+
onMount(() => {
|
|
25
|
+
if (el) {
|
|
26
|
+
el.base64 = sampleBase64;
|
|
27
|
+
el.alt = 'A purple star';
|
|
28
|
+
el.setAttribute('media-type', 'image/svg+xml');
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return <kai-image ref={(e) => (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '16px' }} />;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
35
|
+
<kai-image id="img" media-type="image/png" alt="A chart"></kai-image>
|
|
36
|
+
|
|
37
|
+
<script type="module">
|
|
38
|
+
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
39
|
+
|
|
40
|
+
const img = document.getElementById('img');
|
|
41
|
+
img.base64 = '<...base64 image data...>';
|
|
42
|
+
// or set raw bytes as a property:
|
|
43
|
+
// img.bytes = new Uint8Array([...]);
|
|
44
|
+
</script>`;
|
|
45
|
+
|
|
46
|
+
const meta = {
|
|
47
|
+
title: 'Components/Image',
|
|
48
|
+
tags: ['autodocs'],
|
|
49
|
+
argTypes: argTypesFor('kai-image'),
|
|
50
|
+
parameters: {
|
|
51
|
+
layout: 'fullscreen',
|
|
52
|
+
docs: {
|
|
53
|
+
description: specDescription('kai-image', [
|
|
54
|
+
'`<kai-image>` is the framework-agnostic **web component** that renders a base64 or byte-array image, showing a skeleton fallback while it resolves, isolated in **Shadow DOM**.',
|
|
55
|
+
'**When to use:** displaying model-generated or in-memory images (without a hosted URL) in a non-Solid app. In SolidJS, use the `Image` primitive directly.',
|
|
56
|
+
'**Placement:** inside a message bubble, card body, or artifact preview panel; size it via the parent container — the element is `display: inline-block` and the image fills to the parent\'s width.',
|
|
57
|
+
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, set `base64` (paired with the `media-type` attribute) or set raw `bytes` as a **property**, and add `alt` text.",
|
|
58
|
+
'See the **Code** tab for HTML usage.',
|
|
59
|
+
]),
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
} satisfies Meta;
|
|
63
|
+
|
|
64
|
+
export default meta;
|
|
65
|
+
type Story = StoryObj;
|
|
66
|
+
|
|
67
|
+
/** A base64-encoded SVG with a media type and alt text. */
|
|
68
|
+
export const Default: Story = {
|
|
69
|
+
render: () => <ImageElement />,
|
|
70
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
71
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
|
+
import { Image } from '../components/image';
|
|
3
|
+
|
|
4
|
+
interface Props extends Record<string, unknown> {
|
|
5
|
+
/** Base64-encoded image data (pair with `media-type`). */
|
|
6
|
+
base64?: string;
|
|
7
|
+
/** Raw image bytes (set as a JS property). */
|
|
8
|
+
bytes?: Uint8Array;
|
|
9
|
+
/** Alt text. */
|
|
10
|
+
alt?: string;
|
|
11
|
+
/** MIME type (default `image/png`). */
|
|
12
|
+
mediaType?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `<kai-image>` — renders a base64 or byte-array image with a skeleton
|
|
17
|
+
* fallback while it resolves. `base64`/`alt`/`media-type` via attributes;
|
|
18
|
+
* `bytes` via property.
|
|
19
|
+
*/
|
|
20
|
+
defineWebComponent<Props>('kai-image', {
|
|
21
|
+
base64: undefined,
|
|
22
|
+
bytes: undefined,
|
|
23
|
+
alt: '',
|
|
24
|
+
mediaType: undefined,
|
|
25
|
+
}, (props) => (
|
|
26
|
+
<Image
|
|
27
|
+
alt={props.alt ?? ''}
|
|
28
|
+
base64={props.base64}
|
|
29
|
+
uint8Array={props.bytes}
|
|
30
|
+
mediaType={props.mediaType}
|
|
31
|
+
/>
|
|
32
|
+
));
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { createSignal, onMount, type JSX } from 'solid-js';
|
|
3
|
+
import './link-preview'; // side effect: registers <kai-link-preview>
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
import type { LinkPreviewData } from '../primitives/link-preview';
|
|
6
|
+
import { configureLinkPreview } from '../primitives/link-preview';
|
|
7
|
+
import type { CardEvent } from '../primitives/card-contract';
|
|
8
|
+
|
|
9
|
+
// Custom DOM element — declare the tag for JSX.
|
|
10
|
+
declare module 'solid-js' {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
12
|
+
namespace JSX {
|
|
13
|
+
interface IntrinsicElements {
|
|
14
|
+
'kai-link-preview': JSX.HTMLAttributes<HTMLElement> & {
|
|
15
|
+
'card-id'?: string;
|
|
16
|
+
ref?: (el: HTMLElement) => void;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type LinkPreviewEl = HTMLElement & { cardId?: string; data?: LinkPreviewData };
|
|
23
|
+
|
|
24
|
+
/** A sized box the card sits in (cards expand to their container width). */
|
|
25
|
+
function Frame(props: { children: JSX.Element }) {
|
|
26
|
+
return <div style={{ width: '100%', 'max-width': '420px' }}>{props.children}</div>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Mounts a <kai-link-preview>, sets `.data`, logs emitted CardEvents under the render. */
|
|
30
|
+
function LinkPreviewDemo(props: { cardId: string; data: LinkPreviewData }) {
|
|
31
|
+
const [log, setLog] = createSignal<CardEvent[]>([]);
|
|
32
|
+
let el: LinkPreviewEl | undefined;
|
|
33
|
+
onMount(() => {
|
|
34
|
+
if (!el) return;
|
|
35
|
+
el.cardId = props.cardId;
|
|
36
|
+
el.data = props.data;
|
|
37
|
+
el.addEventListener('kai-card', (e) => {
|
|
38
|
+
const detail = (e as CustomEvent<CardEvent>).detail;
|
|
39
|
+
setLog((prev) => [...prev, detail]);
|
|
40
|
+
if (detail.kind === 'open' && detail.target === 'tab') {
|
|
41
|
+
window.open(detail.url, '_blank', 'noopener,noreferrer');
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return (
|
|
46
|
+
<Frame>
|
|
47
|
+
<div style={{ display: 'flex', 'flex-direction': 'column', gap: '12px' }}>
|
|
48
|
+
<kai-link-preview ref={(e) => (el = e as LinkPreviewEl)} card-id={props.cardId} />
|
|
49
|
+
<pre
|
|
50
|
+
style={{
|
|
51
|
+
margin: 0,
|
|
52
|
+
'max-height': '180px',
|
|
53
|
+
overflow: 'auto',
|
|
54
|
+
background: 'var(--color-muted, #f4f4f5)',
|
|
55
|
+
'border-radius': '8px',
|
|
56
|
+
padding: '8px',
|
|
57
|
+
'font-size': '12px',
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{log().length === 0 ? '// emitted CardEvents appear here' : JSON.stringify(log(), null, 2)}
|
|
61
|
+
</pre>
|
|
62
|
+
</div>
|
|
63
|
+
</Frame>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const FULL_ENVELOPE = {
|
|
68
|
+
type: 'link',
|
|
69
|
+
id: 'card-link-1',
|
|
70
|
+
title: 'Shared link',
|
|
71
|
+
data: {
|
|
72
|
+
url: 'https://example.com/blog/generative-ui',
|
|
73
|
+
title: 'Generative UI, explained',
|
|
74
|
+
description:
|
|
75
|
+
'How agents render typed, themed cards in the chat — across native components and provider iframes.',
|
|
76
|
+
image: 'https://placehold.co/1200x630/6366f1/ffffff/png?text=Generative+UI',
|
|
77
|
+
imageAlt: 'Diagram of the card contract',
|
|
78
|
+
favicon: 'https://example.com/favicon.ico',
|
|
79
|
+
siteName: 'Example Blog',
|
|
80
|
+
domain: 'example.com',
|
|
81
|
+
},
|
|
82
|
+
} satisfies { type: string; id: string; title: string; data: LinkPreviewData };
|
|
83
|
+
|
|
84
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
85
|
+
<kai-link-preview id="lc"></kai-link-preview>
|
|
86
|
+
|
|
87
|
+
<script type="module">
|
|
88
|
+
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
89
|
+
|
|
90
|
+
const lc = document.getElementById('lc');
|
|
91
|
+
lc.cardId = 'card-link-1';
|
|
92
|
+
// \`data\` is a JS property (the CardEnvelope \`data\`):
|
|
93
|
+
lc.data = ${JSON.stringify(FULL_ENVELOPE.data, null, 2).replace(/\n/g, '\n ')};
|
|
94
|
+
|
|
95
|
+
// Cards bubble a composed \`kai-card\` event carrying a typed CardEvent.
|
|
96
|
+
// kai-link-preview emits: ready (on mount), open (on click), error (invalid/broken url).
|
|
97
|
+
lc.addEventListener('kai-card', (e) => {
|
|
98
|
+
const ev = e.detail; // CardEvent
|
|
99
|
+
if (ev.kind === 'open' && ev.target === 'tab') {
|
|
100
|
+
window.open(ev.url, '_blank', 'noopener,noreferrer');
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
</script>`;
|
|
104
|
+
|
|
105
|
+
const meta = {
|
|
106
|
+
title: 'Generative UI/Cards/kai-link-preview',
|
|
107
|
+
tags: ['autodocs'],
|
|
108
|
+
argTypes: argTypesFor('kai-link-preview'),
|
|
109
|
+
parameters: {
|
|
110
|
+
layout: 'padded',
|
|
111
|
+
docs: {
|
|
112
|
+
description: specDescription('kai-link-preview', [
|
|
113
|
+
'`<kai-link-preview>` is a themed, accessible **rich link / Open-Graph preview** card for the generative-UI feature. It speaks the **Card Contract**: data down (a `link` `CardEnvelope`), events up (only the `open` verb, plus lifecycle `ready` / failure `error`).',
|
|
114
|
+
'**Pure by default:** the card renders from the metadata you supply (`title`, `description`, `image`, `favicon`, `siteName`, `domain`) — it **never fetches**. For the bare-`{ url }` case, an app may opt in to a resolver with `configureLinkPreview({ fetchMetadata })` (CORS means OG scraping needs YOUR backend; there is no built-in network call).',
|
|
115
|
+
'**Interaction:** the whole card is one link target. Activating it (click / Enter / Space) dispatches the bubbling, composed **`kai-card`** event with `{ kind: \'open\', url, target: \'tab\' }` so a host-level listener routes it through `CardPolicy` (which performs the navigation, after scheme validation).',
|
|
116
|
+
'**Graceful degradation:** a missing/broken image drops the image region (not an error); an invalid url renders a non-clickable "Invalid link" chip and emits one `error`.',
|
|
117
|
+
'See the **Code** tab for the `CardEnvelope` JSON + HTML wiring.',
|
|
118
|
+
]),
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
} satisfies Meta;
|
|
122
|
+
|
|
123
|
+
export default meta;
|
|
124
|
+
type Story = StoryObj;
|
|
125
|
+
|
|
126
|
+
/** Full OG metadata — image, site name, title, description. Click the card to see the emitted `open` event. */
|
|
127
|
+
export const FullPreview: Story = {
|
|
128
|
+
name: 'Full preview',
|
|
129
|
+
render: () => <LinkPreviewDemo cardId={FULL_ENVELOPE.id} data={FULL_ENVELOPE.data} />,
|
|
130
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** No image — the card degrades gracefully to the text + domain layout. */
|
|
134
|
+
export const NoImage: Story = {
|
|
135
|
+
name: 'No image',
|
|
136
|
+
render: () => (
|
|
137
|
+
<LinkPreviewDemo
|
|
138
|
+
cardId="card-link-2"
|
|
139
|
+
data={{
|
|
140
|
+
url: 'https://docs.example.com/guide',
|
|
141
|
+
title: 'API Guide',
|
|
142
|
+
description: 'Reference for the public endpoints, auth, and rate limits.',
|
|
143
|
+
siteName: 'Example Docs',
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
),
|
|
147
|
+
parameters: {
|
|
148
|
+
docs: {
|
|
149
|
+
source: {
|
|
150
|
+
code: JSON.stringify(
|
|
151
|
+
{
|
|
152
|
+
type: 'link',
|
|
153
|
+
id: 'card-link-2',
|
|
154
|
+
data: {
|
|
155
|
+
url: 'https://docs.example.com/guide',
|
|
156
|
+
title: 'API Guide',
|
|
157
|
+
description: 'Reference for the public endpoints, auth, and rate limits.',
|
|
158
|
+
siteName: 'Example Docs',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
null,
|
|
162
|
+
2,
|
|
163
|
+
),
|
|
164
|
+
language: 'json',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** Bare URL + a configured fetcher — shows the skeleton → merged render path. */
|
|
171
|
+
export const BareUrlWithFetcher: Story = {
|
|
172
|
+
name: 'Bare URL + fetcher',
|
|
173
|
+
render: () => {
|
|
174
|
+
// Demo only: an app would point this at its own backend/proxy.
|
|
175
|
+
configureLinkPreview({
|
|
176
|
+
fetchMetadata: async (url) => {
|
|
177
|
+
await new Promise((r) => setTimeout(r, 900)); // show the skeleton
|
|
178
|
+
return {
|
|
179
|
+
title: 'Resolved by your backend',
|
|
180
|
+
description: `Metadata for ${url} fetched via configureLinkPreview.`,
|
|
181
|
+
siteName: 'example.com',
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
return <LinkPreviewDemo cardId="card-link-3" data={{ url: 'https://example.com/bare' }} />;
|
|
186
|
+
},
|
|
187
|
+
parameters: {
|
|
188
|
+
docs: {
|
|
189
|
+
source: {
|
|
190
|
+
code: `import { configureLinkPreview } from '@kitn.ai/ui';
|
|
191
|
+
|
|
192
|
+
// Opt in once (points at YOUR backend/proxy — there is no built-in network call):
|
|
193
|
+
configureLinkPreview({
|
|
194
|
+
fetchMetadata: (url) => fetch('/api/og?url=' + encodeURIComponent(url)).then((r) => r.json()),
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Then a bare { url } envelope resolves to a full preview:
|
|
198
|
+
lc.data = { url: 'https://example.com/bare' };`,
|
|
199
|
+
language: 'ts',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/** Invalid link — a non-clickable error chip; one `error` event is emitted (visible in the log below). */
|
|
206
|
+
export const InvalidLink: Story = {
|
|
207
|
+
name: 'Invalid link',
|
|
208
|
+
render: () => <LinkPreviewDemo cardId="card-link-4" data={{ url: 'not-a-valid-url' }} />,
|
|
209
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
|
+
import { LinkPreview } from '../components/link-preview';
|
|
3
|
+
import type { LinkPreviewData } from '../primitives/link-preview';
|
|
4
|
+
import { emitCardEvent } from '../primitives/card-routing';
|
|
5
|
+
|
|
6
|
+
interface Props extends Record<string, unknown> {
|
|
7
|
+
/** Stable card id correlating every emitted event. Set as an attribute or property. */
|
|
8
|
+
cardId?: string;
|
|
9
|
+
/** The link payload (OG metadata). Set as a JS **property** (object). */
|
|
10
|
+
data?: LinkPreviewData;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `<kai-link-preview>` — a themed, accessible rich link / Open-Graph preview card. It
|
|
15
|
+
* renders from the supplied `data` (it never fetches; an app may register a
|
|
16
|
+
* `configureLinkPreview` fetcher for the bare-`{ url }` path). Activating the card
|
|
17
|
+
* dispatches the bubbling, composed **`kai-card`** CustomEvent with the contract
|
|
18
|
+
* `open` verb (`{ kind:'open', url, target:'tab' }`) so a host-level listener
|
|
19
|
+
* routes it through CardPolicy. Set `data` as a JS property; `card-id` via attribute.
|
|
20
|
+
*/
|
|
21
|
+
defineWebComponent<Props>(
|
|
22
|
+
'kai-link-preview',
|
|
23
|
+
{
|
|
24
|
+
cardId: undefined,
|
|
25
|
+
data: undefined,
|
|
26
|
+
},
|
|
27
|
+
(props, { element }) => (
|
|
28
|
+
<LinkPreview
|
|
29
|
+
cardId={props.cardId ?? ''}
|
|
30
|
+
data={props.data ?? ({ url: '' } as LinkPreviewData)}
|
|
31
|
+
onEmit={(event) => emitCardEvent(element, event)}
|
|
32
|
+
/>
|
|
33
|
+
),
|
|
34
|
+
);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import './register'; // side effect: registers the custom elements
|
|
3
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
4
|
+
|
|
5
|
+
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
6
|
+
declare module 'solid-js' {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
8
|
+
namespace JSX {
|
|
9
|
+
interface IntrinsicElements {
|
|
10
|
+
'kai-loader': JSX.HTMLAttributes<HTMLElement> & {
|
|
11
|
+
variant?: string;
|
|
12
|
+
size?: string;
|
|
13
|
+
text?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
20
|
+
<kai-loader variant="dots" size="md"></kai-loader>
|
|
21
|
+
|
|
22
|
+
<script type="module">
|
|
23
|
+
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
24
|
+
</script>`;
|
|
25
|
+
|
|
26
|
+
const meta = {
|
|
27
|
+
title: 'Components/Loader',
|
|
28
|
+
tags: ['autodocs'],
|
|
29
|
+
argTypes: argTypesFor('kai-loader'),
|
|
30
|
+
parameters: {
|
|
31
|
+
layout: 'fullscreen',
|
|
32
|
+
docs: {
|
|
33
|
+
description: specDescription('kai-loader', [
|
|
34
|
+
'`<kai-loader>` is the framework-agnostic **web component** for an animated busy indicator — a dozen styles (circular, dots, wave, bars, text-shimmer, …) selected via the `variant` attribute, isolated in **Shadow DOM**.',
|
|
35
|
+
'**When to use:** showing a small "working" indicator anywhere outside the chat thread (toolbars, buttons, panels). In SolidJS, use the `Loader` primitive directly.',
|
|
36
|
+
'**Placement:** inline anywhere a busy state is needed — centered inside a button, floated in a toolbar corner, or as a standalone skeleton in an empty panel; it is `display: inline-flex` by default so it follows normal inline flow.',
|
|
37
|
+
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, then set `variant`, `size`, and (for text variants) `text` as plain HTML attributes.",
|
|
38
|
+
'See the **Code** tab for HTML usage.',
|
|
39
|
+
]),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
} satisfies Meta;
|
|
43
|
+
|
|
44
|
+
export default meta;
|
|
45
|
+
type Story = StoryObj;
|
|
46
|
+
|
|
47
|
+
const VARIANTS = [
|
|
48
|
+
'circular', 'classic', 'pulse', 'pulse-dot', 'dots', 'typing',
|
|
49
|
+
'wave', 'bars', 'terminal', 'text-blink', 'text-shimmer', 'loading-dots',
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** The default circular spinner. */
|
|
53
|
+
export const Default: Story = {
|
|
54
|
+
render: () => (
|
|
55
|
+
<div style={{ padding: '24px' }}>
|
|
56
|
+
<kai-loader variant="circular" size="md" />
|
|
57
|
+
</div>
|
|
58
|
+
),
|
|
59
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Every variant at the medium size, side by side. */
|
|
63
|
+
export const AllVariants: Story = {
|
|
64
|
+
render: () => (
|
|
65
|
+
<div style={{ display: 'flex', 'flex-wrap': 'wrap', gap: '32px', 'align-items': 'center', padding: '24px' }}>
|
|
66
|
+
{VARIANTS.map((v) => (
|
|
67
|
+
<div style={{ display: 'flex', 'flex-direction': 'column', 'align-items': 'center', gap: '8px', 'min-width': '90px' }}>
|
|
68
|
+
<kai-loader variant={v} size="md" text="Loading" />
|
|
69
|
+
<code style={{ 'font-size': '11px', opacity: 0.6 }}>{v}</code>
|
|
70
|
+
</div>
|
|
71
|
+
))}
|
|
72
|
+
</div>
|
|
73
|
+
),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** The three sizes (`sm` / `md` / `lg`) of the dots variant. */
|
|
77
|
+
export const Sizes: Story = {
|
|
78
|
+
render: () => (
|
|
79
|
+
<div style={{ display: 'flex', gap: '32px', 'align-items': 'center', padding: '24px' }}>
|
|
80
|
+
{['sm', 'md', 'lg'].map((s) => (
|
|
81
|
+
<div style={{ display: 'flex', 'flex-direction': 'column', 'align-items': 'center', gap: '8px' }}>
|
|
82
|
+
<kai-loader variant="dots" size={s} />
|
|
83
|
+
<code style={{ 'font-size': '11px', opacity: 0.6 }}>{s}</code>
|
|
84
|
+
</div>
|
|
85
|
+
))}
|
|
86
|
+
</div>
|
|
87
|
+
),
|
|
88
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
|
+
import { Loader, type LoaderVariant, type LoaderSize } from '../components/loader';
|
|
3
|
+
|
|
4
|
+
interface Props extends Record<string, unknown> {
|
|
5
|
+
/** The animation style: `'circular' | 'classic' | 'pulse' | 'pulse-dot' |
|
|
6
|
+
* 'dots' | 'typing' | 'wave' | 'bars' | 'terminal' | 'text-blink' |
|
|
7
|
+
* 'text-shimmer' | 'loading-dots'`. Defaults to `'circular'`. */
|
|
8
|
+
variant?: LoaderVariant;
|
|
9
|
+
/** Loader size: `'sm' | 'md' | 'lg'`. Defaults to `'md'`. */
|
|
10
|
+
size?: LoaderSize;
|
|
11
|
+
/** Label for the text-based variants. */
|
|
12
|
+
text?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `<kai-loader>` — an animated loader. `variant` selects the style (circular,
|
|
17
|
+
* dots, wave, text-shimmer, …); `size` and `text` are attributes.
|
|
18
|
+
*/
|
|
19
|
+
defineWebComponent<Props>('kai-loader', {
|
|
20
|
+
variant: 'circular',
|
|
21
|
+
size: 'md',
|
|
22
|
+
text: undefined,
|
|
23
|
+
}, (props) => (
|
|
24
|
+
<Loader variant={props.variant} size={props.size} text={props.text} />
|
|
25
|
+
));
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { onMount } from 'solid-js';
|
|
3
|
+
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
7
|
+
declare module 'solid-js' {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'kai-markdown': JSX.HTMLAttributes<HTMLElement>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const sampleMarkdown = `### Markdown
|
|
17
|
+
Renders **bold**, _italic_, \`code\`, and lists:
|
|
18
|
+
- one
|
|
19
|
+
- two
|
|
20
|
+
|
|
21
|
+
> and blockquotes.
|
|
22
|
+
|
|
23
|
+
\`\`\`ts
|
|
24
|
+
export function add(a: number, b: number): number {
|
|
25
|
+
return a + b;
|
|
26
|
+
}
|
|
27
|
+
\`\`\``;
|
|
28
|
+
|
|
29
|
+
/** Render the actual `<kai-markdown>` custom element with a `content` property. */
|
|
30
|
+
function MarkdownElement(props: { content: string }) {
|
|
31
|
+
let el: (HTMLElement & { content?: string }) | undefined;
|
|
32
|
+
onMount(() => {
|
|
33
|
+
if (el) el.content = props.content;
|
|
34
|
+
});
|
|
35
|
+
return (
|
|
36
|
+
<kai-markdown ref={(e) => (el = e as HTMLElement)} style={{ display: 'block', padding: '16px', 'max-width': '720px' }} />
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
41
|
+
<kai-markdown id="md" code-theme="github-dark-dimmed"></kai-markdown>
|
|
42
|
+
|
|
43
|
+
<script type="module">
|
|
44
|
+
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
45
|
+
|
|
46
|
+
const md = document.getElementById('md');
|
|
47
|
+
md.content = '### Hello\\nRenders **bold**, _italic_, and \\\`code\\\`.';
|
|
48
|
+
// md.setAttribute('code-highlight', 'false'); // skip Shiki entirely
|
|
49
|
+
</script>`;
|
|
50
|
+
|
|
51
|
+
const meta = {
|
|
52
|
+
title: 'Components/Markdown',
|
|
53
|
+
tags: ['autodocs'],
|
|
54
|
+
argTypes: argTypesFor('kai-markdown'),
|
|
55
|
+
parameters: {
|
|
56
|
+
layout: 'fullscreen',
|
|
57
|
+
docs: {
|
|
58
|
+
description: specDescription('kai-markdown', [
|
|
59
|
+
'`<kai-markdown>` is the framework-agnostic **web component** that renders a markdown string (with fenced-code syntax highlighting via Shiki) as a standalone element, isolated in **Shadow DOM**.',
|
|
60
|
+
'**When to use:** showing model output or any markdown in a non-Solid app without pulling in a markdown stack. In SolidJS, use the `Markdown` primitive directly.',
|
|
61
|
+
'**Placement:** as a block inside a message row, doc viewer, or standalone content pane; it is `display: block` and expands to fill its container width, so constrain width on the parent.',
|
|
62
|
+
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, set the source via the `content` **property** (`el.content = '...'`), and tune rendering with the `prose-size`, `code-theme`, and `code-highlight` attributes.",
|
|
63
|
+
'See the **Code** tab for HTML usage.',
|
|
64
|
+
]),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
} satisfies Meta;
|
|
68
|
+
|
|
69
|
+
export default meta;
|
|
70
|
+
type Story = StoryObj;
|
|
71
|
+
|
|
72
|
+
/** Headings, emphasis, lists, a blockquote, and a highlighted code fence. */
|
|
73
|
+
export const Default: Story = {
|
|
74
|
+
render: () => <MarkdownElement content={sampleMarkdown} />,
|
|
75
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
76
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
|
+
import { Markdown } from '../components/markdown';
|
|
3
|
+
import { ChatConfig, useChatConfig, type ProseSize } from '../primitives/chat-config';
|
|
4
|
+
|
|
5
|
+
interface Props extends Record<string, unknown> {
|
|
6
|
+
/** The markdown source to render. */
|
|
7
|
+
content: string;
|
|
8
|
+
/** Text/markdown sizing. */
|
|
9
|
+
proseSize?: ProseSize;
|
|
10
|
+
/** Shiki theme for fenced code blocks. */
|
|
11
|
+
codeTheme?: string;
|
|
12
|
+
/** Disable syntax highlighting (no Shiki loads). */
|
|
13
|
+
codeHighlight?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `<kai-markdown>` — renders markdown (with fenced-code syntax highlighting) as
|
|
18
|
+
* a standalone element. Content via the `content` property; sizing/highlighting
|
|
19
|
+
* via attributes.
|
|
20
|
+
*/
|
|
21
|
+
defineWebComponent<Props>('kai-markdown', {
|
|
22
|
+
content: '',
|
|
23
|
+
proseSize: 'sm',
|
|
24
|
+
codeTheme: 'github-dark-dimmed',
|
|
25
|
+
codeHighlight: true,
|
|
26
|
+
}, (props, { flag }) => {
|
|
27
|
+
const outer = useChatConfig();
|
|
28
|
+
return (
|
|
29
|
+
<ChatConfig
|
|
30
|
+
proseSize={props.proseSize}
|
|
31
|
+
codeTheme={props.codeTheme}
|
|
32
|
+
codeHighlight={flag('codeHighlight')}
|
|
33
|
+
portalMount={outer.portalMount()}
|
|
34
|
+
>
|
|
35
|
+
<Markdown content={props.content} />
|
|
36
|
+
</ChatConfig>
|
|
37
|
+
);
|
|
38
|
+
});
|