@kitn.ai/ui 0.14.1 → 0.15.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.
Files changed (179) hide show
  1. package/dist/kitn-chat.es.js +1 -1
  2. package/package.json +6 -1
  3. package/src/components/component-meta.json +10 -10
  4. package/src/elements/compiled.css +1 -1
  5. package/src/remote/host-embed.ts +1 -1
  6. package/src/components/artifact.stories.tsx +0 -138
  7. package/src/components/attachments.stories.tsx +0 -303
  8. package/src/components/attachments.test.tsx +0 -64
  9. package/src/components/chain-of-thought.stories.tsx +0 -211
  10. package/src/components/chat-container.stories.tsx +0 -187
  11. package/src/components/chat-thread.test.tsx +0 -58
  12. package/src/components/checkpoint.stories.tsx +0 -102
  13. package/src/components/code-block.stories.tsx +0 -150
  14. package/src/components/confirm-card.stories.tsx +0 -74
  15. package/src/components/context.stories.tsx +0 -229
  16. package/src/components/context.test.tsx +0 -133
  17. package/src/components/conversation-item.stories.tsx +0 -125
  18. package/src/components/conversation-list.stories.tsx +0 -133
  19. package/src/components/default-input.test.tsx +0 -111
  20. package/src/components/empty.stories.tsx +0 -434
  21. package/src/components/feedback-bar.stories.tsx +0 -138
  22. package/src/components/feedback-bar.test.tsx +0 -103
  23. package/src/components/file-tree.stories.tsx +0 -73
  24. package/src/components/file-upload.stories.tsx +0 -156
  25. package/src/components/image.stories.tsx +0 -89
  26. package/src/components/loader.stories.tsx +0 -181
  27. package/src/components/markdown.stories.tsx +0 -180
  28. package/src/components/message-action-bar.test.tsx +0 -128
  29. package/src/components/message-narrow.stories.tsx +0 -329
  30. package/src/components/message-skills.stories.tsx +0 -211
  31. package/src/components/message.stories.tsx +0 -281
  32. package/src/components/model-switcher.stories.tsx +0 -123
  33. package/src/components/model-switcher.test.tsx +0 -65
  34. package/src/components/prompt-input.stories.tsx +0 -222
  35. package/src/components/prompt-suggestion.stories.tsx +0 -142
  36. package/src/components/reasoning.stories.tsx +0 -140
  37. package/src/components/resizable.test.tsx +0 -226
  38. package/src/components/scroll-button.stories.tsx +0 -100
  39. package/src/components/slash-command.stories.tsx +0 -163
  40. package/src/components/source-list.test.tsx +0 -152
  41. package/src/components/source.stories.tsx +0 -124
  42. package/src/components/tasks-card.stories.tsx +0 -78
  43. package/src/components/text-shimmer.stories.tsx +0 -87
  44. package/src/components/thinking-bar.stories.tsx +0 -87
  45. package/src/components/tool.stories.tsx +0 -153
  46. package/src/components/voice-input.stories.tsx +0 -83
  47. package/src/elements/artifact.stories.tsx +0 -506
  48. package/src/elements/attachments.stories.tsx +0 -190
  49. package/src/elements/card.stories.tsx +0 -113
  50. package/src/elements/cards.stories.tsx +0 -59
  51. package/src/elements/catalog.stories.tsx +0 -491
  52. package/src/elements/chain-of-thought.declarative.test.tsx +0 -153
  53. package/src/elements/chain-of-thought.stories.tsx +0 -113
  54. package/src/elements/chat-scope-picker.stories.tsx +0 -73
  55. package/src/elements/chat-workspace.stories.tsx +0 -288
  56. package/src/elements/chat.stories.tsx +0 -151
  57. package/src/elements/checkpoint.stories.tsx +0 -72
  58. package/src/elements/choice.stories.tsx +0 -240
  59. package/src/elements/code-block.stories.tsx +0 -83
  60. package/src/elements/composed-shell.stories.tsx +0 -316
  61. package/src/elements/confirm-card.stories.tsx +0 -227
  62. package/src/elements/context-meter.stories.tsx +0 -151
  63. package/src/elements/conversation-list.declarative.test.tsx +0 -137
  64. package/src/elements/conversation-list.stories.tsx +0 -243
  65. package/src/elements/embed.stories.tsx +0 -213
  66. package/src/elements/empty.stories.tsx +0 -111
  67. package/src/elements/feedback-bar.stories.tsx +0 -114
  68. package/src/elements/file-tree.stories.tsx +0 -134
  69. package/src/elements/file-upload.stories.tsx +0 -82
  70. package/src/elements/form.stories.tsx +0 -248
  71. package/src/elements/image.stories.tsx +0 -71
  72. package/src/elements/link-preview.stories.tsx +0 -209
  73. package/src/elements/loader.stories.tsx +0 -88
  74. package/src/elements/markdown.stories.tsx +0 -76
  75. package/src/elements/message-skills.declarative.test.tsx +0 -104
  76. package/src/elements/message-skills.stories.tsx +0 -114
  77. package/src/elements/message.stories.tsx +0 -218
  78. package/src/elements/model-switcher.declarative.test.tsx +0 -130
  79. package/src/elements/model-switcher.stories.tsx +0 -198
  80. package/src/elements/popover.stories.tsx +0 -80
  81. package/src/elements/prompt-input-slash-command.test.tsx +0 -128
  82. package/src/elements/prompt-input-stoppable.test.tsx +0 -88
  83. package/src/elements/prompt-input-toolbar-actions.test.tsx +0 -120
  84. package/src/elements/prompt-input.stories.tsx +0 -331
  85. package/src/elements/prompt-suggestions.declarative.test.tsx +0 -164
  86. package/src/elements/prompt-suggestions.stories.tsx +0 -213
  87. package/src/elements/reasoning.stories.tsx +0 -77
  88. package/src/elements/remote.stories.tsx +0 -314
  89. package/src/elements/resizable.stories.tsx +0 -426
  90. package/src/elements/response-stream.stories.tsx +0 -79
  91. package/src/elements/scroll-button.stories.tsx +0 -202
  92. package/src/elements/scroll-button.test.tsx +0 -148
  93. package/src/elements/source-list.stories.tsx +0 -143
  94. package/src/elements/source.stories.tsx +0 -88
  95. package/src/elements/switch.stories.tsx +0 -56
  96. package/src/elements/tasks.stories.tsx +0 -237
  97. package/src/elements/text-shimmer.stories.tsx +0 -64
  98. package/src/elements/thinking-bar.stories.tsx +0 -72
  99. package/src/elements/tool.stories.tsx +0 -89
  100. package/src/elements/voice-input.stories.tsx +0 -88
  101. package/src/primitives/controllable.test.ts +0 -47
  102. package/src/stories/chat-panel-layout.stories.tsx +0 -145
  103. package/src/stories/chat-scene.tsx +0 -571
  104. package/src/stories/checkpoint-restore.stories.tsx +0 -256
  105. package/src/stories/context-usage.stories.tsx +0 -212
  106. package/src/stories/conversation-with-reasoning.stories.tsx +0 -182
  107. package/src/stories/conversation-with-sources.stories.tsx +0 -471
  108. package/src/stories/docs/Accessibility.mdx +0 -119
  109. package/src/stories/docs/ChildElements.mdx +0 -269
  110. package/src/stories/docs/ForAIAgents.mdx +0 -162
  111. package/src/stories/docs/GettingStarted.mdx +0 -65
  112. package/src/stories/docs/Installation.mdx +0 -83
  113. package/src/stories/docs/Introduction.mdx +0 -50
  114. package/src/stories/docs/SolidJsAdvanced.mdx +0 -17
  115. package/src/stories/docs/Theming.mdx +0 -85
  116. package/src/stories/docs/element-controls.ts +0 -121
  117. package/src/stories/docs/frameworks/Angular.mdx +0 -245
  118. package/src/stories/docs/frameworks/Html.mdx +0 -227
  119. package/src/stories/docs/frameworks/Overview.mdx +0 -47
  120. package/src/stories/docs/frameworks/React.mdx +0 -227
  121. package/src/stories/docs/frameworks/Solid.mdx +0 -173
  122. package/src/stories/docs/frameworks/Svelte.mdx +0 -194
  123. package/src/stories/docs/frameworks/Vue.mdx +0 -238
  124. package/src/stories/docs/generative-ui-overview.mdx +0 -186
  125. package/src/stories/docs/recipes/SpeechToText.mdx +0 -7
  126. package/src/stories/docs/recipes/Streaming.mdx +0 -68
  127. package/src/stories/docs/recipes/TextToSpeech.mdx +0 -35
  128. package/src/stories/docs/theme-editor/canvas.tsx +0 -32
  129. package/src/stories/docs/theme-editor/inspector.tsx +0 -66
  130. package/src/stories/docs/theme-editor/presets.test.ts +0 -32
  131. package/src/stories/docs/theme-editor/presets.ts +0 -64
  132. package/src/stories/docs/theme-editor/theme-css.test.ts +0 -19
  133. package/src/stories/docs/theme-editor/theme-css.ts +0 -15
  134. package/src/stories/docs/theme-editor/theme-editor.tsx +0 -146
  135. package/src/stories/docs/theme-tokens.tsx +0 -174
  136. package/src/stories/examples/ChoosingComponents.mdx +0 -106
  137. package/src/stories/examples/sample-data.ts +0 -79
  138. package/src/stories/examples/usage/checkpoint-restore.ts +0 -156
  139. package/src/stories/examples/usage/context-usage.ts +0 -591
  140. package/src/stories/examples/usage/conversation-with-reasoning.ts +0 -224
  141. package/src/stories/examples/usage/conversation-with-sources.ts +0 -589
  142. package/src/stories/examples/usage/empty-state.ts +0 -144
  143. package/src/stories/examples/usage/full-chat-app.ts +0 -277
  144. package/src/stories/examples/usage/index.ts +0 -63
  145. package/src/stories/examples/usage/message-actions.ts +0 -704
  146. package/src/stories/examples/usage/pattern-centered-conversation.ts +0 -446
  147. package/src/stories/examples/usage/pattern-chat-panel-layout.ts +0 -442
  148. package/src/stories/examples/usage/pattern-docked-widget.ts +0 -479
  149. package/src/stories/examples/usage/prompt-input-variants.ts +0 -1356
  150. package/src/stories/examples/usage/streaming-response.ts +0 -687
  151. package/src/stories/examples/usage/types.ts +0 -33
  152. package/src/stories/full-chat.stories.tsx +0 -18
  153. package/src/stories/message-actions.stories.tsx +0 -230
  154. package/src/stories/pattern-centered-conversation.stories.tsx +0 -93
  155. package/src/stories/pattern-docked-widget.stories.tsx +0 -93
  156. package/src/stories/pattern-empty-state.stories.tsx +0 -76
  157. package/src/stories/prompt-input-variants.stories.tsx +0 -456
  158. package/src/stories/streaming-response.stories.tsx +0 -438
  159. package/src/stories/theme-editor.stories.tsx +0 -16
  160. package/src/stories/token-reference.stories.tsx +0 -18
  161. package/src/stories/typography.stories.tsx +0 -78
  162. package/src/ui/avatar.stories.tsx +0 -103
  163. package/src/ui/badge.stories.tsx +0 -86
  164. package/src/ui/button.stories.tsx +0 -145
  165. package/src/ui/collapsible.stories.tsx +0 -69
  166. package/src/ui/dropdown.stories.tsx +0 -59
  167. package/src/ui/hover-card.stories.tsx +0 -77
  168. package/src/ui/hover-card.test.tsx +0 -30
  169. package/src/ui/overlay.stories.tsx +0 -115
  170. package/src/ui/popover.stories.tsx +0 -81
  171. package/src/ui/popover.test.tsx +0 -99
  172. package/src/ui/resizable.stories.tsx +0 -236
  173. package/src/ui/scroll-area.stories.tsx +0 -50
  174. package/src/ui/separator.stories.tsx +0 -81
  175. package/src/ui/skeleton.stories.tsx +0 -337
  176. package/src/ui/switch.stories.tsx +0 -51
  177. package/src/ui/switch.test.tsx +0 -59
  178. package/src/ui/textarea.stories.tsx +0 -76
  179. package/src/ui/tooltip.stories.tsx +0 -74
@@ -1,248 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { createSignal, onMount, type JSX } from 'solid-js';
3
- import './form';
4
- import { argTypesFor, specDescription } from '../stories/docs/element-controls';
5
- import type { FormDefinition } from '../components/form';
6
- import type { CardEvent } from '../primitives/card-contract';
7
-
8
- declare module 'solid-js' {
9
- // eslint-disable-next-line @typescript-eslint/no-namespace
10
- namespace JSX {
11
- interface IntrinsicElements {
12
- 'kai-form': JSX.HTMLAttributes<HTMLElement> & {
13
- heading?: string;
14
- 'card-id'?: string;
15
- ref?: (el: HTMLElement) => void;
16
- };
17
- }
18
- }
19
- }
20
-
21
- type FormEl = HTMLElement & { data?: FormDefinition; resolution?: Record<string, unknown> };
22
-
23
- /** A bordered box the form sits inside. */
24
- function Frame(props: { children: JSX.Element }) {
25
- return <div style={{ 'max-width': '460px' }}>{props.children}</div>;
26
- }
27
-
28
- /** Mounts a <kai-form>, sets `.data`, logs the emitted CardEvent under the render. */
29
- function FormDemo(props: { def: FormDefinition; cardId: string }) {
30
- const [log, setLog] = createSignal<CardEvent[]>([]);
31
- let el: FormEl | undefined;
32
- onMount(() => {
33
- if (!el) return;
34
- el.data = props.def;
35
- el.addEventListener('kai-card', (e) => {
36
- const detail = (e as CustomEvent<CardEvent>).detail;
37
- setLog((prev) => [...prev, detail]);
38
- });
39
- });
40
- return (
41
- <Frame>
42
- <div style={{ display: 'flex', 'flex-direction': 'column', gap: '12px' }}>
43
- <kai-form ref={(e) => (el = e as FormEl)} card-id={props.cardId} />
44
- <pre
45
- style={{
46
- margin: 0,
47
- 'max-height': '180px',
48
- overflow: 'auto',
49
- background: 'var(--color-muted, #f4f4f5)',
50
- 'border-radius': '8px',
51
- padding: '8px',
52
- 'font-size': '12px',
53
- }}
54
- >
55
- {log().length === 0 ? '// emitted CardEvents appear here' : JSON.stringify(log(), null, 2)}
56
- </pre>
57
- </div>
58
- </Frame>
59
- );
60
- }
61
-
62
- const FEEDBACK: FormDefinition = {
63
- type: 'object',
64
- title: 'How did we do?',
65
- description: 'Two quick questions.',
66
- required: ['rating', 'contactOk'],
67
- 'x-kai-order': ['rating', 'comments', 'plan', 'contactOk'],
68
- 'x-kai-submitLabel': 'Send feedback',
69
- 'x-kai-actions': [{ id: 'skip', label: 'Skip', variant: 'ghost' }],
70
- properties: {
71
- rating: { type: 'integer', title: 'Overall rating', minimum: 1, maximum: 5, 'x-kai-widget': 'rating' },
72
- comments: {
73
- type: 'string',
74
- title: 'Comments',
75
- maxLength: 500,
76
- 'x-kai-widget': 'textarea',
77
- 'x-kai-placeholder': "What worked, what didn't…",
78
- },
79
- plan: { type: 'string', title: 'Your plan', enum: ['free', 'pro', 'team'], default: 'free' },
80
- contactOk: { type: 'boolean', title: 'OK to contact me about this', default: false },
81
- },
82
- };
83
-
84
- const ALL_WIDGETS: FormDefinition = {
85
- type: 'object',
86
- title: 'Every widget',
87
- 'x-kai-submitLabel': 'Submit all',
88
- properties: {
89
- name: { type: 'string', title: 'Name' },
90
- bio: { type: 'string', title: 'Bio', maxLength: 300 },
91
- email: { type: 'string', title: 'Email', format: 'email' },
92
- website: { type: 'string', title: 'Website', format: 'uri' },
93
- birthday: { type: 'string', title: 'Birthday', format: 'date' },
94
- secret: { type: 'string', title: 'Password', 'x-kai-widget': 'password' },
95
- size: { type: 'string', title: 'Size', enum: ['S', 'M', 'L'] },
96
- country: { type: 'string', title: 'Country', enum: ['US', 'UK', 'DE', 'FR', 'JP'] },
97
- age: { type: 'integer', title: 'Age', minimum: 0, maximum: 120 },
98
- volume: { type: 'integer', title: 'Volume', minimum: 0, maximum: 11, 'x-kai-widget': 'slider' },
99
- stars: { type: 'integer', title: 'Stars', minimum: 1, maximum: 5, 'x-kai-widget': 'rating' },
100
- notify: { type: 'boolean', title: 'Email me updates' },
101
- agree: { type: 'boolean', title: 'I agree', 'x-kai-widget': 'checkbox' },
102
- tags: { type: 'array', title: 'Tags', items: { type: 'string' } },
103
- topics: { type: 'array', title: 'Topics', items: { enum: ['news', 'sports', 'tech'] } },
104
- contacts: {
105
- type: 'array',
106
- title: 'Contacts',
107
- items: {
108
- type: 'object',
109
- properties: { label: { type: 'string', title: 'Label' }, phone: { type: 'string', title: 'Phone' } },
110
- },
111
- },
112
- address: {
113
- type: 'object',
114
- title: 'Address',
115
- properties: { street: { type: 'string', title: 'Street' }, city: { type: 'string', title: 'City' } },
116
- },
117
- },
118
- };
119
-
120
- const VALIDATION: FormDefinition = {
121
- type: 'object',
122
- title: 'Create account',
123
- required: ['username', 'email', 'age'],
124
- properties: {
125
- username: { type: 'string', title: 'Username', minLength: 3, maxLength: 12 },
126
- email: { type: 'string', title: 'Email', format: 'email' },
127
- age: { type: 'integer', title: 'Age', minimum: 13, maximum: 120 },
128
- },
129
- };
130
-
131
- const HTML_SNIPPET = (def: FormDefinition) => `<kai-form></kai-form>
132
- <script type="module">
133
- import '@kitn.ai/ui/elements'; // registers the custom elements
134
-
135
- const form = document.querySelector('kai-form');
136
- // \`data\` is the CardEnvelope.data — a JSON Schema + x-kai-* UI hints (set as a property).
137
- form.data = ${JSON.stringify(def, null, 2)};
138
-
139
- // Cards bubble ONE \`kai-card\` CustomEvent carrying a typed CardEvent.
140
- form.addEventListener('kai-card', (e) => {
141
- const ev = e.detail; // { kind:'submit', cardId, data } | { kind:'action', ... } | ...
142
- if (ev.kind === 'submit') console.log('submission', ev.data);
143
- });
144
- </script>`;
145
-
146
- const meta = {
147
- title: 'Generative UI/Cards/kai-form',
148
- tags: ['autodocs'],
149
- argTypes: argTypesFor('kai-form'),
150
- parameters: {
151
- layout: 'padded',
152
- docs: {
153
- description: specDescription('kai-form', [
154
- '`<kai-form>` turns an agent\'s **JSON Schema** "shape" (set via the `data` **property**) into a themed, accessible, validated form inside `<kai-card>` chrome. A valid submission is emitted **up the Card contract** as a bubbling **`kai-card`** CustomEvent of `{ kind: \'submit\', cardId, data }`.',
155
- '**Anatomy:** `<kai-card>` chrome (optional heading from `data.title` or `heading` attr) → **field rows** (one per schema property in `x-kai-order` / key order: label + widget; `object` properties become a `<fieldset>`, `array` items become a repeater/checkbox-group/tag-list) → **card footer** (`x-kai-submitLabel` submit `<Button>` + optional `x-kai-actions` secondary buttons; replaced by a read-only `<dl>` summary after a resolved submission).',
156
- '**The mapping is deterministic:** `string`→text, `string`+`enum`→radio/select, `string`+`format`→typed inputs, `number`/`integer`→number (or `slider`/`rating` via `x-kai-widget`), `boolean`→switch, `array`→checkbox-group / multi-select / repeater / tag-list, nested `object`→fieldset. `x-kai-*` hints (`x-kai-widget`, `x-kai-order`, `x-kai-submitLabel`, `x-kai-actions`, `x-kai-dismissible`, …) refine the UI and live **inside** the schema, so one source of truth drives both the form and validation.',
157
- "**Events** (all frozen Card-contract verbs): `ready` on mount, `submit` on a valid submit, `action` for secondary buttons (`x-kai-actions`), `dismiss` when dismissible, `error` for a malformed definition (renders the inline `kai-card` error). It **never invents events**.",
158
- '**The same `CardEnvelope`/`CardEvent` shapes flow over the remote iframe transport unchanged** — this is the *native* card. See the **Code** tab for the full envelope JSON + the HTML wiring.',
159
- ]),
160
- },
161
- },
162
- } satisfies Meta;
163
-
164
- export default meta;
165
- type Story = StoryObj;
166
-
167
- /** The worked example: a rating + textarea + enum radio + switch, with a Skip action. */
168
- export const Feedback: Story = {
169
- render: () => <FormDemo def={FEEDBACK} cardId="card-feedback-7f3" />,
170
- parameters: { docs: { source: { code: HTML_SNIPPET(FEEDBACK), language: 'html' } } },
171
- };
172
-
173
- /** One form exercising every row of the mapping table. */
174
- export const AllWidgets: Story = {
175
- render: () => <FormDemo def={ALL_WIDGETS} cardId="card-all" />,
176
- parameters: { docs: { source: { code: HTML_SNIPPET(ALL_WIDGETS), language: 'html' } } },
177
- };
178
-
179
- /** Required + min/max + format: try submitting empty (inline errors), then fill it in. */
180
- export const Validation: Story = {
181
- render: () => <FormDemo def={VALIDATION} cardId="card-signup" />,
182
- parameters: { docs: { source: { code: HTML_SNIPPET(VALIDATION), language: 'html' } } },
183
- };
184
-
185
- const RESOLVED_FORM: FormDefinition = {
186
- type: 'object',
187
- title: 'Book a demo',
188
- 'x-kai-order': ['name', 'optIn'],
189
- properties: {
190
- name: { type: 'string', title: 'Full name' },
191
- optIn: { type: 'boolean', title: 'Email me' },
192
- },
193
- };
194
-
195
- /** The form after a valid submission — read-only `<dl>` summary + "✓ Submitted", no inputs. */
196
- export const Resolved: Story = {
197
- name: 'Resolved (read-only)',
198
- render: () => {
199
- let el: FormEl | undefined;
200
- onMount(() => {
201
- if (!el) return;
202
- el.data = RESOLVED_FORM;
203
- el.resolution = { kind: 'submit', data: { name: 'Jane Cooper', optIn: true } };
204
- });
205
- return (
206
- <Frame>
207
- <kai-form ref={(e) => (el = e as FormEl)} card-id="card-resolved-form" />
208
- </Frame>
209
- );
210
- },
211
- parameters: {
212
- docs: {
213
- source: {
214
- code: `<kai-form></kai-form>
215
- <script type="module">
216
- import '@kitn.ai/ui/elements';
217
- const form = document.querySelector('kai-form');
218
- form.data = ${JSON.stringify(RESOLVED_FORM, null, 2)};
219
- // Setting .resolution renders the chromed read-only summary — no inputs or submit button.
220
- form.resolution = { kind: 'submit', data: { name: 'Jane Cooper', optIn: true } };
221
- </script>`,
222
- language: 'html',
223
- },
224
- },
225
- },
226
- };
227
-
228
- /** A malformed `data` → the inline error state + an `error` event (no form rendered). */
229
- export const InvalidEnvelope: Story = {
230
- render: () => <FormDemo def={{ type: 'array' } as unknown as FormDefinition} cardId="card-bad" />,
231
- parameters: {
232
- docs: {
233
- source: {
234
- code: `<kai-form></kai-form>
235
- <script type="module">
236
- import '@kitn.ai/ui/elements';
237
- const form = document.querySelector('kai-form');
238
- // A definition that isn't a JSON-Schema object → inline error + an \`error\` event.
239
- form.data = { type: 'array' };
240
- form.addEventListener('kai-card', (e) => {
241
- if (e.detail.kind === 'error') console.warn('form error:', e.detail.message);
242
- });
243
- </script>`,
244
- language: 'html',
245
- },
246
- },
247
- },
248
- };
@@ -1,71 +0,0 @@
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
- };
@@ -1,209 +0,0 @@
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
- };
@@ -1,88 +0,0 @@
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
- };