@kitnai/chat 0.6.0 → 0.8.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.
Files changed (211) hide show
  1. package/README.md +9 -9
  2. package/dist/custom-elements.json +1676 -881
  3. package/dist/kitn-chat.es.js +36 -36
  4. package/dist/llms/llms-full.txt +316 -155
  5. package/dist/llms/llms.txt +18 -18
  6. package/dist/schemas/card-envelope.schema.json +14 -0
  7. package/dist/schemas/card-event.schema.json +12 -0
  8. package/dist/schemas/confirm.schema.json +65 -0
  9. package/dist/schemas/embed.schema.json +65 -0
  10. package/dist/schemas/form.result.schema.json +7 -0
  11. package/dist/schemas/form.schema.json +33 -0
  12. package/dist/schemas/link.schema.json +56 -0
  13. package/dist/schemas/task-list.result.schema.json +16 -0
  14. package/dist/schemas/task-list.schema.json +78 -0
  15. package/dist/theme.tokens.css +65 -65
  16. package/dist/tsx-B8rCNbgL.js +1 -0
  17. package/dist/typescript-RycA9KXf.js +1 -0
  18. package/frameworks/react/index.tsx +382 -193
  19. package/frameworks/react/runtime.tsx +2 -2
  20. package/llms-full.txt +316 -155
  21. package/llms.txt +18 -18
  22. package/package.json +5 -2
  23. package/src/components/artifact.stories.tsx +138 -0
  24. package/src/components/artifact.tsx +581 -0
  25. package/src/components/attachments.stories.tsx +7 -8
  26. package/src/components/attachments.tsx +2 -2
  27. package/src/components/card.tsx +110 -0
  28. package/src/components/chain-of-thought.stories.tsx +7 -8
  29. package/src/components/chat-container.stories.tsx +7 -8
  30. package/src/components/chat-container.tsx +4 -0
  31. package/src/components/checkpoint.stories.tsx +7 -8
  32. package/src/components/code-block.stories.tsx +8 -9
  33. package/src/components/component-meta.json +3411 -0
  34. package/src/components/confirm-card.stories.tsx +74 -0
  35. package/src/components/confirm-card.tsx +299 -0
  36. package/src/components/context.stories.tsx +7 -8
  37. package/src/components/conversation-item.stories.tsx +7 -8
  38. package/src/components/conversation-item.tsx +2 -2
  39. package/src/components/conversation-list.stories.tsx +7 -8
  40. package/src/components/conversation-list.tsx +1 -1
  41. package/src/components/embed.tsx +196 -0
  42. package/src/components/empty.stories.tsx +8 -9
  43. package/src/components/feedback-bar.stories.tsx +7 -8
  44. package/src/components/file-tree.stories.tsx +73 -0
  45. package/src/components/file-tree.tsx +383 -0
  46. package/src/components/file-upload.stories.tsx +7 -8
  47. package/src/components/form-widgets.tsx +461 -0
  48. package/src/components/form.tsx +796 -0
  49. package/src/components/image.stories.tsx +7 -8
  50. package/src/components/link-card.tsx +194 -0
  51. package/src/components/loader.stories.tsx +7 -8
  52. package/src/components/markdown.stories.tsx +7 -8
  53. package/src/components/message-narrow.stories.tsx +12 -13
  54. package/src/components/message-skills.stories.tsx +16 -17
  55. package/src/components/message.stories.tsx +17 -18
  56. package/src/components/model-switcher.stories.tsx +7 -8
  57. package/src/components/prompt-input.stories.tsx +8 -9
  58. package/src/components/prompt-suggestion.stories.tsx +7 -8
  59. package/src/components/prompt-suggestion.tsx +3 -3
  60. package/src/components/reasoning.stories.tsx +7 -8
  61. package/src/components/scroll-button.stories.tsx +7 -8
  62. package/src/components/slash-command.stories.tsx +8 -9
  63. package/src/components/slash-command.tsx +2 -2
  64. package/src/components/source.stories.tsx +7 -8
  65. package/src/components/source.tsx +1 -1
  66. package/src/components/task-list-card.stories.tsx +78 -0
  67. package/src/components/task-list-card.tsx +388 -0
  68. package/src/components/text-shimmer.stories.tsx +7 -8
  69. package/src/components/thinking-bar.stories.tsx +7 -8
  70. package/src/components/tool.stories.tsx +7 -8
  71. package/src/components/tool.tsx +2 -2
  72. package/src/components/voice-input.stories.tsx +7 -8
  73. package/src/elements/artifact.stories.tsx +291 -0
  74. package/src/elements/artifact.tsx +72 -0
  75. package/src/elements/{kitn-attachments.stories.tsx → attachments.stories.tsx} +11 -11
  76. package/src/elements/attachments.tsx +4 -4
  77. package/src/elements/card.stories.tsx +118 -0
  78. package/src/elements/card.tsx +40 -0
  79. package/src/elements/catalog.stories.tsx +491 -0
  80. package/src/elements/{kitn-chain-of-thought.stories.tsx → chain-of-thought.stories.tsx} +13 -13
  81. package/src/elements/chain-of-thought.tsx +3 -3
  82. package/src/elements/{kitn-chat-scope-picker.stories.tsx → chat-scope-picker.stories.tsx} +10 -10
  83. package/src/elements/chat-scope-picker.tsx +4 -4
  84. package/src/elements/{kitn-chat-workspace.stories.tsx → chat-workspace.stories.tsx} +71 -29
  85. package/src/elements/chat-workspace.tsx +29 -3
  86. package/src/elements/{kitn-chat.stories.tsx → chat.stories.tsx} +61 -16
  87. package/src/elements/chat.tsx +23 -2
  88. package/src/elements/{kitn-checkpoint.stories.tsx → checkpoint.stories.tsx} +11 -11
  89. package/src/elements/checkpoint.tsx +4 -4
  90. package/src/elements/{kitn-code-block.stories.tsx → code-block.stories.tsx} +10 -10
  91. package/src/elements/code-block.tsx +3 -3
  92. package/src/elements/compiled.css +1 -1
  93. package/src/elements/composed-shell.stories.tsx +316 -0
  94. package/src/elements/confirm-card.stories.tsx +186 -0
  95. package/src/elements/confirm-card.tsx +45 -0
  96. package/src/elements/{kitn-context-meter.stories.tsx → context-meter.stories.tsx} +10 -10
  97. package/src/elements/context-meter.tsx +3 -3
  98. package/src/elements/{kitn-conversation-list.stories.tsx → conversation-list.stories.tsx} +35 -22
  99. package/src/elements/conversation-list.tsx +11 -2
  100. package/src/elements/css.ts +1 -1
  101. package/src/elements/define.tsx +10 -10
  102. package/src/elements/element-meta.json +2649 -0
  103. package/src/elements/element-types.d.ts +251 -125
  104. package/src/elements/embed.stories.tsx +197 -0
  105. package/src/elements/embed.tsx +35 -0
  106. package/src/elements/{kitn-empty.stories.tsx → empty.stories.tsx} +12 -12
  107. package/src/elements/empty.tsx +3 -3
  108. package/src/elements/{kitn-feedback-bar.stories.tsx → feedback-bar.stories.tsx} +11 -11
  109. package/src/elements/feedback-bar.tsx +4 -4
  110. package/src/elements/file-tree.stories.tsx +133 -0
  111. package/src/elements/file-tree.tsx +52 -0
  112. package/src/elements/{kitn-file-upload.stories.tsx → file-upload.stories.tsx} +12 -12
  113. package/src/elements/file-upload.tsx +4 -4
  114. package/src/elements/form.stories.tsx +204 -0
  115. package/src/elements/form.tsx +37 -0
  116. package/src/elements/{kitn-image.stories.tsx → image.stories.tsx} +10 -10
  117. package/src/elements/image.tsx +3 -3
  118. package/src/elements/link-card.stories.tsx +193 -0
  119. package/src/elements/link-card.tsx +34 -0
  120. package/src/elements/{kitn-loader.stories.tsx → loader.stories.tsx} +11 -11
  121. package/src/elements/loader.tsx +3 -3
  122. package/src/elements/{kitn-markdown.stories.tsx → markdown.stories.tsx} +10 -10
  123. package/src/elements/markdown.tsx +3 -3
  124. package/src/elements/{kitn-message-skills.stories.tsx → message-skills.stories.tsx} +10 -10
  125. package/src/elements/message-skills.tsx +3 -3
  126. package/src/elements/{kitn-message.stories.tsx → message.stories.tsx} +12 -12
  127. package/src/elements/message.tsx +5 -5
  128. package/src/elements/{kitn-model-switcher.stories.tsx → model-switcher.stories.tsx} +10 -10
  129. package/src/elements/model-switcher.tsx +5 -5
  130. package/src/elements/{kitn-prompt-input.stories.tsx → prompt-input.stories.tsx} +41 -19
  131. package/src/elements/prompt-input.tsx +5 -5
  132. package/src/elements/{kitn-prompt-suggestions.stories.tsx → prompt-suggestions.stories.tsx} +13 -13
  133. package/src/elements/prompt-suggestions.tsx +4 -4
  134. package/src/elements/{kitn-reasoning.stories.tsx → reasoning.stories.tsx} +10 -10
  135. package/src/elements/reasoning.tsx +4 -4
  136. package/src/elements/register.ts +11 -1
  137. package/src/elements/resizable.stories.tsx +200 -0
  138. package/src/elements/resizable.tsx +264 -0
  139. package/src/elements/{kitn-response-stream.stories.tsx → response-stream.stories.tsx} +10 -10
  140. package/src/elements/response-stream.tsx +4 -4
  141. package/src/elements/{kitn-source-list.stories.tsx → source-list.stories.tsx} +11 -11
  142. package/src/elements/{kitn-source.stories.tsx → source.stories.tsx} +12 -12
  143. package/src/elements/source.tsx +5 -5
  144. package/src/elements/styles.css +140 -1
  145. package/src/elements/task-list-card.stories.tsx +194 -0
  146. package/src/elements/task-list-card.tsx +40 -0
  147. package/src/elements/{kitn-text-shimmer.stories.tsx → text-shimmer.stories.tsx} +10 -10
  148. package/src/elements/text-shimmer.tsx +3 -3
  149. package/src/elements/{kitn-thinking-bar.stories.tsx → thinking-bar.stories.tsx} +11 -11
  150. package/src/elements/thinking-bar.tsx +5 -5
  151. package/src/elements/{kitn-tool.stories.tsx → tool.stories.tsx} +10 -10
  152. package/src/elements/tool.tsx +3 -3
  153. package/src/elements/{kitn-voice-input.stories.tsx → voice-input.stories.tsx} +10 -10
  154. package/src/elements/voice-input.tsx +4 -4
  155. package/src/index.ts +94 -2
  156. package/src/primitives/card-contract.ts +60 -0
  157. package/src/primitives/card-host.tsx +35 -0
  158. package/src/primitives/card-routing.ts +79 -0
  159. package/src/primitives/card-schemas/card-envelope.schema.json +14 -0
  160. package/src/primitives/card-schemas/card-event.schema.json +12 -0
  161. package/src/primitives/card-schemas/confirm.schema.json +65 -0
  162. package/src/primitives/card-schemas/embed.schema.json +65 -0
  163. package/src/primitives/card-schemas/form.result.schema.json +7 -0
  164. package/src/primitives/card-schemas/form.schema.json +33 -0
  165. package/src/primitives/card-schemas/link.schema.json +56 -0
  166. package/src/primitives/card-schemas/task-list.result.schema.json +16 -0
  167. package/src/primitives/card-schemas/task-list.schema.json +78 -0
  168. package/src/primitives/card-validate.ts +95 -0
  169. package/src/primitives/embed-providers.ts +254 -0
  170. package/src/primitives/highlighter.ts +4 -0
  171. package/src/primitives/link-preview.ts +87 -0
  172. package/src/primitives/pdf-preview.ts +121 -0
  173. package/src/stories/chat-panel-layout.stories.tsx +2 -1
  174. package/src/stories/chat-scene.tsx +22 -21
  175. package/src/stories/checkpoint-restore.stories.tsx +10 -10
  176. package/src/stories/conversation-with-reasoning.stories.tsx +4 -4
  177. package/src/stories/conversation-with-sources.stories.tsx +7 -7
  178. package/src/stories/docs/Accessibility.mdx +2 -2
  179. package/src/stories/docs/ForAIAgents.mdx +3 -3
  180. package/src/stories/docs/GettingStarted.mdx +2 -2
  181. package/src/stories/docs/Installation.mdx +2 -2
  182. package/src/stories/docs/Integrations.mdx +29 -29
  183. package/src/stories/docs/Introduction.mdx +3 -3
  184. package/src/stories/docs/Theming.mdx +2 -2
  185. package/src/stories/docs/element-controls.ts +60 -0
  186. package/src/stories/docs/theme-editor/theme-editor.tsx +1 -0
  187. package/src/stories/examples/ChoosingComponents.mdx +94 -0
  188. package/src/stories/examples/sample-data.ts +79 -0
  189. package/src/stories/message-actions.stories.tsx +13 -13
  190. package/src/stories/pattern-centered-conversation.stories.tsx +3 -3
  191. package/src/stories/pattern-docked-widget.stories.tsx +1 -1
  192. package/src/stories/pattern-empty-state.stories.tsx +3 -3
  193. package/src/stories/prompt-input-variants.stories.tsx +13 -13
  194. package/src/stories/streaming-response.stories.tsx +3 -3
  195. package/src/stories/typography.stories.tsx +4 -4
  196. package/src/ui/avatar.stories.tsx +7 -8
  197. package/src/ui/badge.stories.tsx +7 -8
  198. package/src/ui/button.stories.tsx +8 -9
  199. package/src/ui/button.tsx +1 -0
  200. package/src/ui/collapsible.stories.tsx +6 -7
  201. package/src/ui/dropdown.stories.tsx +6 -7
  202. package/src/ui/hover-card.stories.tsx +6 -7
  203. package/src/ui/resizable.stories.tsx +74 -9
  204. package/src/ui/resizable.tsx +351 -71
  205. package/src/ui/scroll-area.stories.tsx +6 -7
  206. package/src/ui/scroll-area.tsx +3 -1
  207. package/src/ui/separator.stories.tsx +7 -8
  208. package/src/ui/skeleton.stories.tsx +7 -8
  209. package/src/ui/textarea.stories.tsx +6 -7
  210. package/src/ui/tooltip.stories.tsx +8 -9
  211. package/theme.css +65 -65
@@ -1,6 +1,7 @@
1
1
  import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
2
  import { fn } from 'storybook/test';
3
- import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from './resizable';
3
+ import { ResizablePanelGroup, ResizablePanel, ResizableHandle, Resizable } from './resizable';
4
+ import { componentDescription } from '../stories/docs/element-controls';
4
5
 
5
6
  const meta = {
6
7
  title: 'UI/Resizable',
@@ -10,14 +11,12 @@ const meta = {
10
11
  layout: 'padded',
11
12
  docs: {
12
13
  controls: { exclude: ['use:eventListener'] },
13
- description: {
14
- component: [
15
- 'A **resizable split layout**: `ResizablePanelGroup` lays out `ResizablePanel` children along an axis, divided by a draggable `ResizableHandle`.',
16
- '**When to use:** to let users adjust the relative size of two or more regions e.g. a collapsible sidebar next to the main chat, or a chat pane next to an inspector.',
17
- '**How to use:** wrap panels in `ResizablePanelGroup` and set `orientation` (`horizontal` row / `vertical` column). Give panels a `defaultSize` (percent) and optional `minSize`/`maxSize`; min/max are read from `data-min-size`/`data-max-size` attributes at drag time. Place a `ResizableHandle` (add `withHandle` for a visible grip) between panels. The group needs a sized container (height/width).',
18
- '**Placement:** app shells — sidebar + conversation, conversation + context/inspector panels, or stacked editor/preview regions.',
19
- ].join('\n\n'),
20
- },
14
+ description: componentDescription([
15
+ 'A **resizable split layout**: `ResizablePanelGroup` lays out `ResizablePanel` children along an axis, divided by a draggable `ResizableHandle`.',
16
+ '**When to use:** to let users adjust the relative size of two or more regions — e.g. a collapsible sidebar next to the main chat, or a chat pane next to an inspector.',
17
+ '**How to use:** wrap panels in `ResizablePanelGroup` and set `orientation` (`horizontal` row / `vertical` column). Give panels a `defaultSize` (percent) and optional `minSize`/`maxSize`; min/max are read from `data-min-size`/`data-max-size` attributes at drag time. Place a `ResizableHandle` (add `withHandle` for a visible grip) between panels. The group needs a sized container (height/width).',
18
+ '**Placement:** app shells sidebar + conversation, conversation + context/inspector panels, or stacked editor/preview regions.',
19
+ ]),
21
20
  },
22
21
  },
23
22
  argTypes: {
@@ -169,3 +168,69 @@ export const NoHandle: Story = {
169
168
  <ResizablePanel>Panel B</ResizablePanel>
170
169
  </ResizablePanelGroup>`),
171
170
  };
171
+
172
+ /**
173
+ * The `Resizable` convenience: pass `ResizablePanel` children and it
174
+ * auto-inserts a handle between each visible pair. A `locked` panel makes its
175
+ * neighbouring handle a static (non-draggable) divider; a `hidden` panel drops
176
+ * its divider entirely.
177
+ */
178
+ export const ConvenienceGroup: Story = {
179
+ name: 'Resizable (convenience)',
180
+ render: () => (
181
+ <div class="h-48 w-full max-w-2xl rounded-lg border border-border overflow-hidden">
182
+ <Resizable orientation="horizontal" withHandle onChange={(sizes) => console.log('sizes', sizes)}>
183
+ <ResizablePanel defaultSize="240px" locked>
184
+ <div class="flex h-full items-center justify-center bg-muted/30 p-4">
185
+ <span class="text-sm text-muted-foreground">Locked sidebar (240px)</span>
186
+ </div>
187
+ </ResizablePanel>
188
+ <ResizablePanel>
189
+ <div class="flex h-full items-center justify-center p-4">
190
+ <span class="text-sm text-muted-foreground">Chat</span>
191
+ </div>
192
+ </ResizablePanel>
193
+ <ResizablePanel defaultSize="30%" minSize="160px">
194
+ <div class="flex h-full items-center justify-center bg-muted/30 p-4">
195
+ <span class="text-sm text-muted-foreground">Preview</span>
196
+ </div>
197
+ </ResizablePanel>
198
+ </Resizable>
199
+ </div>
200
+ ),
201
+ ...src(`<Resizable orientation="horizontal" withHandle onChange={(sizes) => console.log(sizes)}>
202
+ <ResizablePanel defaultSize="240px" locked>Locked sidebar</ResizablePanel>
203
+ <ResizablePanel>Chat</ResizablePanel>
204
+ <ResizablePanel defaultSize="30%" minSize="160px">Preview</ResizablePanel>
205
+ </Resizable>`),
206
+ };
207
+
208
+ /**
209
+ * Min/max + keyboard: focus the handle (Tab) and use ←/→ to nudge, Home/End to
210
+ * jump to the panel's min/max. Sizes accept px or %.
211
+ */
212
+ export const MinMaxKeyboard: Story = {
213
+ name: 'Min/Max + Keyboard',
214
+ render: () => (
215
+ <div class="h-48 w-full max-w-2xl rounded-lg border border-border overflow-hidden">
216
+ <ResizablePanelGroup orientation="horizontal">
217
+ <ResizablePanel defaultSize="30%" minSize="120px" maxSize="50%">
218
+ <div class="flex h-full items-center justify-center bg-muted/30 p-4">
219
+ <span class="text-sm text-muted-foreground">min 120px · max 50%</span>
220
+ </div>
221
+ </ResizablePanel>
222
+ <ResizableHandle withHandle />
223
+ <ResizablePanel minSize="160px">
224
+ <div class="flex h-full items-center justify-center p-4">
225
+ <span class="text-sm text-muted-foreground">Content (min 160px)</span>
226
+ </div>
227
+ </ResizablePanel>
228
+ </ResizablePanelGroup>
229
+ </div>
230
+ ),
231
+ ...src(`<ResizablePanelGroup orientation="horizontal">
232
+ <ResizablePanel defaultSize="30%" minSize="120px" maxSize="50%">Sidebar</ResizablePanel>
233
+ <ResizableHandle withHandle />
234
+ <ResizablePanel minSize="160px">Content</ResizablePanel>
235
+ </ResizablePanelGroup>`),
236
+ };
@@ -1,16 +1,57 @@
1
- import { type JSX, splitProps, createSignal, createContext, useContext, onCleanup, children as resolveChildren } from 'solid-js';
1
+ import { type JSX, splitProps, createSignal, createContext, useContext, For, Show, children as resolveChildren } from 'solid-js';
2
2
  import { cn } from '../utils/cn';
3
3
 
4
4
  // --- Types ---
5
5
 
6
6
  type Orientation = 'horizontal' | 'vertical';
7
7
 
8
+ /** A size value: a number (percent), `"25%"` (percent), or `"280px"` (pixels). */
9
+ export type SizeValue = number | string;
10
+
8
11
  interface ResizableContextValue {
9
12
  orientation: Orientation;
10
- registerPanel: (id: string, opts: { defaultSize?: number; minSize?: number; maxSize?: number }) => void;
11
13
  }
12
14
 
13
- const ResizableContext = createContext<ResizableContextValue>();
15
+ export const ResizableContext = createContext<ResizableContextValue>();
16
+
17
+ /**
18
+ * Normalize a px-or-% size into a CSS length string usable as `flex-basis`.
19
+ * - number → percent (`30` → `"30%"`)
20
+ * - `"25%"` → percent passthrough
21
+ * - `"280px"` → pixel passthrough
22
+ * Returns `undefined` for unset values (caller falls back to flexible `flex: 1`).
23
+ */
24
+ export function normalizeSize(value: SizeValue | undefined): string | undefined {
25
+ if (value === undefined || value === null || value === '') return undefined;
26
+ if (typeof value === 'number') return Number.isFinite(value) ? `${value}%` : undefined;
27
+ const trimmed = value.trim();
28
+ if (trimmed === '') return undefined;
29
+ if (trimmed.endsWith('%') || trimmed.endsWith('px')) return trimmed;
30
+ // bare numeric string → percent
31
+ const n = Number(trimmed);
32
+ return Number.isFinite(n) ? `${n}%` : undefined;
33
+ }
34
+
35
+ /**
36
+ * Resolve a px-or-% size to pixels, given the container's main-axis size.
37
+ * Used to seed `data-min-size` / `data-max-size` (which the handle reads as px).
38
+ * Returns `undefined` when the value is unset.
39
+ */
40
+ export function resolveToPx(value: SizeValue | undefined, containerPx: number): number | undefined {
41
+ if (value === undefined || value === null || value === '') return undefined;
42
+ if (typeof value === 'number') return Number.isFinite(value) ? (value / 100) * containerPx : undefined;
43
+ const trimmed = value.trim();
44
+ if (trimmed.endsWith('px')) {
45
+ const n = parseFloat(trimmed);
46
+ return Number.isFinite(n) ? n : undefined;
47
+ }
48
+ if (trimmed.endsWith('%')) {
49
+ const n = parseFloat(trimmed);
50
+ return Number.isFinite(n) ? (n / 100) * containerPx : undefined;
51
+ }
52
+ const n = Number(trimmed);
53
+ return Number.isFinite(n) ? (n / 100) * containerPx : undefined;
54
+ }
14
55
 
15
56
  // --- ResizablePanelGroup ---
16
57
 
@@ -24,7 +65,7 @@ function ResizablePanelGroup(props: ResizablePanelGroupProps) {
24
65
  const orientation = () => local.orientation ?? 'horizontal';
25
66
 
26
67
  return (
27
- <ResizableContext.Provider value={{ orientation: orientation(), registerPanel: () => {} }}>
68
+ <ResizableContext.Provider value={{ orientation: orientation() }}>
28
69
  <div
29
70
  class={cn(
30
71
  'flex h-full w-full',
@@ -43,27 +84,76 @@ function ResizablePanelGroup(props: ResizablePanelGroupProps) {
43
84
  // --- ResizablePanel ---
44
85
 
45
86
  export interface ResizablePanelProps extends JSX.HTMLAttributes<HTMLDivElement> {
46
- defaultSize?: number;
47
- minSize?: number;
48
- maxSize?: number;
87
+ /** Initial main-axis size: number/`"25%"` (percent) or `"280px"` (pixels). Omitted → flexible. */
88
+ defaultSize?: SizeValue;
89
+ /** Minimum size during resize (px or %). */
90
+ minSize?: SizeValue;
91
+ /** Maximum size during resize (px or %). */
92
+ maxSize?: SizeValue;
93
+ /** When true, the panel's size is fixed and adjacent handles are non-draggable. */
94
+ locked?: boolean;
95
+ /** When true, the panel is not visible (used by the `Resizable` convenience to drop dividers). */
96
+ hidden?: boolean;
49
97
  children: JSX.Element;
50
98
  }
51
99
 
52
100
  function ResizablePanel(props: ResizablePanelProps) {
53
- const [local, rest] = splitProps(props, ['defaultSize', 'minSize', 'maxSize', 'children', 'class', 'style']);
101
+ const [local, rest] = splitProps(props, [
102
+ 'defaultSize', 'minSize', 'maxSize', 'locked', 'hidden', 'children', 'class', 'style',
103
+ ]);
104
+ // GRID-FILL model: the panel sizes itself on the MAIN axis via flex-basis (or
105
+ // flex:1 when flexible) as a flex item of the group — the handle rewrites that
106
+ // basis, so the drag math is plain flex. For the FILL it is itself a
107
+ // `display:grid` with a single `minmax(0,1fr)` cell on BOTH axes: a grid item
108
+ // (the child) stretches to fill its cell on both axes by default, and `1fr` of
109
+ // a definite-sized grid is a *definite* length — so arbitrary child content
110
+ // fills the panel on width AND height without needing `height:100%`, in both
111
+ // orientations. (A flex panel only stretches the CROSS axis, collapsing the
112
+ // main axis to content size — the bug this replaces.) Mirrors the
113
+ // `<kc-resizable>` web-component panel and the Shoelace/Web Awesome grid layout.
114
+ // min:0 on BOTH axes enables shrink-to-scroll; overflow hidden.
115
+ const sizeStyle = (): Record<string, string> => {
116
+ const basis = normalizeSize(local.defaultSize);
117
+ const base: Record<string, string> = basis !== undefined
118
+ ? { 'flex-basis': basis, 'flex-grow': '0', 'flex-shrink': '0' }
119
+ : { flex: '1 1 0%' };
120
+ return {
121
+ ...base,
122
+ display: 'grid',
123
+ 'grid-template-rows': 'minmax(0, 1fr)',
124
+ 'grid-template-columns': 'minmax(0, 1fr)',
125
+ 'min-width': '0',
126
+ 'min-height': '0',
127
+ };
128
+ };
54
129
 
55
- const sizeStyle = () => {
56
- const s = local.defaultSize;
57
- if (s !== undefined) {
58
- return { 'flex-basis': `${s}%`, 'flex-grow': '0', 'flex-shrink': '0' };
59
- }
60
- return { flex: '1 1 0%' };
130
+ // Reflect min/max to data-* in pixels where statically resolvable. The handle
131
+ // reads `data-min-size`/`data-max-size` (as px) at drag time. Percent values
132
+ // are resolved against the container by the handle at drag time when expressed
133
+ // as `data-min-size-pct` / `data-max-size-pct`; pixel values go straight to
134
+ // `data-min-size` / `data-max-size`.
135
+ const dataAttrs = () => {
136
+ const out: Record<string, string | undefined> = {};
137
+ const setBound = (val: SizeValue | undefined, pxKey: string, pctKey: string) => {
138
+ if (val === undefined || val === null || val === '') return;
139
+ if (typeof val === 'number') { out[pctKey] = String(val); return; }
140
+ const t = val.trim();
141
+ if (t.endsWith('px')) out[pxKey] = String(parseFloat(t));
142
+ else if (t.endsWith('%')) out[pctKey] = String(parseFloat(t));
143
+ else if (Number.isFinite(Number(t))) out[pctKey] = t;
144
+ };
145
+ setBound(local.minSize, 'data-min-size', 'data-min-size-pct');
146
+ setBound(local.maxSize, 'data-max-size', 'data-max-size-pct');
147
+ return out;
61
148
  };
62
149
 
63
150
  return (
64
151
  <div
65
152
  class={cn('overflow-hidden', local.class)}
66
153
  style={{ ...sizeStyle(), ...(typeof local.style === 'object' ? local.style : {}) }}
154
+ data-locked={local.locked ? '' : undefined}
155
+ hidden={local.hidden || undefined}
156
+ {...dataAttrs()}
67
157
  {...rest}
68
158
  >
69
159
  {local.children}
@@ -76,13 +166,38 @@ function ResizablePanel(props: ResizablePanelProps) {
76
166
  export interface ResizableHandleProps extends JSX.HTMLAttributes<HTMLDivElement> {
77
167
  withHandle?: boolean;
78
168
  onPanelResize?: (delta: number) => void;
169
+ /** Keyboard nudge step in pixels (default 16). Home/End jump to min/max. */
170
+ keyboardStep?: number;
171
+ /** Render as a static, non-interactive divider (e.g. between locked panels). */
172
+ static?: boolean;
173
+ /** Explicit axis; overrides `ResizableContext`. Needed by facades that render
174
+ * handles outside a context provider (e.g. `<kc-resizable>`). */
175
+ orientation?: Orientation;
176
+ }
177
+
178
+ /** Read a panel's min/max bound (px), resolving percent against the container. */
179
+ function readBound(el: HTMLElement, kind: 'min' | 'max', containerPx: number, fallback: number): number {
180
+ const px = el.dataset[kind === 'min' ? 'minSize' : 'maxSize'];
181
+ if (px !== undefined && px !== '') {
182
+ const n = parseFloat(px);
183
+ if (Number.isFinite(n)) return n;
184
+ }
185
+ const pct = el.dataset[kind === 'min' ? 'minSizePct' : 'maxSizePct'];
186
+ if (pct !== undefined && pct !== '') {
187
+ const n = parseFloat(pct);
188
+ if (Number.isFinite(n)) return (n / 100) * containerPx;
189
+ }
190
+ return fallback;
79
191
  }
80
192
 
81
193
  function ResizableHandle(props: ResizableHandleProps) {
82
- const [local, rest] = splitProps(props, ['withHandle', 'onPanelResize', 'class']);
194
+ const [local, rest] = splitProps(props, [
195
+ 'withHandle', 'onPanelResize', 'class', 'keyboardStep', 'static', 'orientation',
196
+ ]);
83
197
  const ctx = useContext(ResizableContext);
84
- const orientation = () => ctx?.orientation ?? 'horizontal';
198
+ const orientation = () => local.orientation ?? ctx?.orientation ?? 'horizontal';
85
199
  const [isDragging, setIsDragging] = createSignal(false);
200
+ const isStatic = () => !!local.static;
86
201
 
87
202
  let startPos = 0;
88
203
  let prevEl: HTMLElement | null = null;
@@ -90,7 +205,11 @@ function ResizableHandle(props: ResizableHandleProps) {
90
205
  let prevSize = 0;
91
206
  let nextSize = 0;
92
207
 
208
+ const isHoriz = () => orientation() === 'horizontal';
209
+ const dim = (): 'width' | 'height' => (isHoriz() ? 'width' : 'height');
210
+
93
211
  const handlePointerDown = (e: PointerEvent) => {
212
+ if (isStatic()) return;
94
213
  const handle = e.currentTarget as HTMLElement;
95
214
  prevEl = handle.previousElementSibling as HTMLElement;
96
215
  nextEl = handle.nextElementSibling as HTMLElement;
@@ -101,33 +220,52 @@ function ResizableHandle(props: ResizableHandleProps) {
101
220
  setIsDragging(true);
102
221
  handle.setPointerCapture(e.pointerId);
103
222
 
104
- if (orientation() === 'horizontal') {
105
- startPos = e.clientX;
106
- prevSize = prevEl.getBoundingClientRect().width;
107
- nextSize = nextEl.getBoundingClientRect().width;
108
- } else {
109
- startPos = e.clientY;
110
- prevSize = prevEl.getBoundingClientRect().height;
111
- nextSize = nextEl.getBoundingClientRect().height;
112
- }
223
+ startPos = isHoriz() ? e.clientX : e.clientY;
224
+ prevSize = prevEl.getBoundingClientRect()[dim()];
225
+ nextSize = nextEl.getBoundingClientRect()[dim()];
113
226
  };
114
227
 
115
228
  const handlePointerMove = (e: PointerEvent) => {
116
229
  if (!isDragging() || !prevEl || !nextEl) return;
117
230
 
118
- const currentPos = orientation() === 'horizontal' ? e.clientX : e.clientY;
231
+ const currentPos = isHoriz() ? e.clientX : e.clientY;
119
232
  const delta = currentPos - startPos;
233
+ applyDelta(delta);
234
+ };
120
235
 
121
- const newPrevSize = prevSize + delta;
122
- const newNextSize = nextSize - delta;
123
-
124
- // Get min/max from data attributes or use defaults
125
- const prevMin = parseInt(prevEl.dataset.minSize || '0', 10);
126
- const prevMax = parseInt(prevEl.dataset.maxSize || '999999', 10);
127
- const nextMin = parseInt(nextEl.dataset.minSize || '0', 10);
128
- const nextMax = parseInt(nextEl.dataset.maxSize || '999999', 10);
129
-
130
- if (newPrevSize < prevMin || newNextSize < nextMin || newPrevSize > prevMax || newNextSize > nextMax) return;
236
+ /**
237
+ * Apply a pixel delta to the adjacent panels. The delta is CLAMPED (not
238
+ * rejected) so the dragged panel lands exactly on the nearest min/max bound
239
+ * this avoids the stair-step where a step that would cross a bound was
240
+ * dropped wholesale, leaving the panel short of its limit.
241
+ */
242
+ function applyDelta(delta: number): boolean {
243
+ if (!prevEl || !nextEl) return false;
244
+ const container = prevEl.parentElement;
245
+ const containerPx = container ? container.getBoundingClientRect()[dim()] : 0;
246
+
247
+ const prevMin = readBound(prevEl, 'min', containerPx, 0);
248
+ const prevMax = readBound(prevEl, 'max', containerPx, 999999);
249
+ const nextMin = readBound(nextEl, 'min', containerPx, 0);
250
+ const nextMax = readBound(nextEl, 'max', containerPx, 999999);
251
+
252
+ // Clamp the delta to the tightest bound across both panels. prev grows by
253
+ // +delta, next shrinks by -delta (and vice versa), so each bound maps to a
254
+ // limit on delta. Intersect them all, then clamp the requested delta.
255
+ let lo = -Infinity; // most-negative allowed delta
256
+ let hi = Infinity; // most-positive allowed delta
257
+ // prev: prevSize + delta in [prevMin, prevMax]
258
+ lo = Math.max(lo, prevMin - prevSize);
259
+ hi = Math.min(hi, prevMax - prevSize);
260
+ // next: nextSize - delta in [nextMin, nextMax] → delta in [nextSize-nextMax, nextSize-nextMin]
261
+ lo = Math.max(lo, nextSize - nextMax);
262
+ hi = Math.min(hi, nextSize - nextMin);
263
+
264
+ if (lo > hi) return false; // no feasible delta (contradictory bounds)
265
+ const clamped = Math.max(lo, Math.min(hi, delta));
266
+
267
+ const newPrevSize = prevSize + clamped;
268
+ const newNextSize = nextSize - clamped;
131
269
 
132
270
  prevEl.style.flexBasis = `${newPrevSize}px`;
133
271
  prevEl.style.flexGrow = '0';
@@ -136,44 +274,103 @@ function ResizableHandle(props: ResizableHandleProps) {
136
274
  nextEl.style.flexGrow = '0';
137
275
  nextEl.style.flexShrink = '0';
138
276
 
139
- local.onPanelResize?.(delta);
140
- };
277
+ local.onPanelResize?.(clamped);
278
+ return true;
279
+ }
280
+
281
+ /**
282
+ * Convert the pixel flex-basis on the TWO adjacent panels to percentages of
283
+ * the container, INDEPENDENTLY of one another. With >2 panels, `nextPct` is
284
+ * NOT `100 - prevPct` (that would steal the other panels' space and overflow
285
+ * the container) — each panel's percent is its own pixel size over the total.
286
+ * All other panels are left untouched.
287
+ */
288
+ function settleToPercent() {
289
+ if (!prevEl || !nextEl) return;
290
+ const container = prevEl.parentElement;
291
+ if (!container) return;
292
+ const total = container.getBoundingClientRect()[dim()];
293
+ if (total <= 0) return;
294
+ const prevPct = (prevEl.getBoundingClientRect()[dim()] / total) * 100;
295
+ const nextPct = (nextEl.getBoundingClientRect()[dim()] / total) * 100;
296
+ prevEl.style.flexBasis = `${prevPct}%`;
297
+ nextEl.style.flexBasis = `${nextPct}%`;
298
+ }
141
299
 
142
300
  const handlePointerUp = () => {
143
- // Convert pixel flex-basis to percentages so panels scale with window resize
144
- if (prevEl && nextEl) {
145
- const container = prevEl.parentElement;
146
- if (container) {
147
- const totalSize = orientation() === 'horizontal'
148
- ? container.getBoundingClientRect().width
149
- : container.getBoundingClientRect().height;
150
- const handleSize = (prevEl.nextElementSibling as HTMLElement)?.getBoundingClientRect()[
151
- orientation() === 'horizontal' ? 'width' : 'height'
152
- ] ?? 0;
153
- const available = totalSize - handleSize;
154
- if (available > 0) {
155
- const prevPct = (prevEl.getBoundingClientRect()[orientation() === 'horizontal' ? 'width' : 'height'] / available) * 100;
156
- const nextPct = 100 - prevPct;
157
- prevEl.style.flexBasis = `${prevPct}%`;
158
- nextEl.style.flexBasis = `${nextPct}%`;
159
- }
160
- }
161
- }
301
+ settleToPercent();
162
302
  setIsDragging(false);
163
303
  prevEl = null;
164
304
  nextEl = null;
165
305
  };
166
306
 
167
- const isHoriz = () => orientation() === 'horizontal';
307
+ // --- Keyboard resize ---
308
+ const aria = createSignal(50);
309
+ const [valueNow, setValueNow] = aria;
310
+
311
+ /** Seed prev/next refs + sizes for a keyboard nudge starting from a key event. */
312
+ function beginKeyboard(handle: HTMLElement) {
313
+ prevEl = handle.previousElementSibling as HTMLElement;
314
+ nextEl = handle.nextElementSibling as HTMLElement;
315
+ if (!prevEl || !nextEl) return false;
316
+ prevSize = prevEl.getBoundingClientRect()[dim()];
317
+ nextSize = nextEl.getBoundingClientRect()[dim()];
318
+ return true;
319
+ }
320
+
321
+ function updateAria() {
322
+ if (!prevEl) return;
323
+ const container = prevEl.parentElement;
324
+ if (!container) return;
325
+ const total = container.getBoundingClientRect()[dim()];
326
+ if (total <= 0) return;
327
+ const pct = (prevEl.getBoundingClientRect()[dim()] / total) * 100;
328
+ setValueNow(Math.round(pct));
329
+ }
330
+
331
+ const handleKeyDown = (e: KeyboardEvent) => {
332
+ if (isStatic()) return;
333
+ const handle = e.currentTarget as HTMLElement;
334
+ const step = local.keyboardStep ?? 16;
335
+ const horiz = isHoriz();
336
+ const decKey = horiz ? 'ArrowLeft' : 'ArrowUp';
337
+ const incKey = horiz ? 'ArrowRight' : 'ArrowDown';
338
+
339
+ let delta: number | 'min' | 'max' | null = null;
340
+ if (e.key === decKey) delta = -step;
341
+ else if (e.key === incKey) delta = step;
342
+ else if (e.key === 'Home') delta = 'min';
343
+ else if (e.key === 'End') delta = 'max';
344
+ else return;
345
+
346
+ e.preventDefault();
347
+ if (!beginKeyboard(handle)) return;
348
+
349
+ if (delta === 'min') {
350
+ // Shrink prev to its minimum.
351
+ const container = prevEl!.parentElement;
352
+ const containerPx = container ? container.getBoundingClientRect()[dim()] : 0;
353
+ const prevMin = readBound(prevEl!, 'min', containerPx, 0);
354
+ applyDelta(prevMin - prevSize);
355
+ } else if (delta === 'max') {
356
+ const container = prevEl!.parentElement;
357
+ const containerPx = container ? container.getBoundingClientRect()[dim()] : 0;
358
+ const prevMax = readBound(prevEl!, 'max', containerPx, 999999);
359
+ applyDelta(prevMax - prevSize);
360
+ } else {
361
+ applyDelta(delta);
362
+ }
363
+ updateAria();
364
+ settleToPercent();
365
+ prevEl = null;
366
+ nextEl = null;
367
+ };
168
368
 
169
369
  return (
170
370
  <div
171
- class={cn(
172
- 'relative flex items-center justify-center',
173
- local.class
174
- )}
371
+ class={cn('relative flex items-center justify-center', local.class)}
175
372
  style={{
176
- cursor: isHoriz() ? 'col-resize' : 'row-resize',
373
+ cursor: isStatic() ? 'default' : isHoriz() ? 'col-resize' : 'row-resize',
177
374
  [isHoriz() ? 'width' : 'height']: '8px',
178
375
  'background': isDragging() ? 'var(--color-muted-foreground, #98989f)' : 'transparent',
179
376
  'opacity': isDragging() ? '0.3' : '1',
@@ -181,24 +378,28 @@ function ResizableHandle(props: ResizableHandleProps) {
181
378
  onPointerDown={handlePointerDown}
182
379
  onPointerMove={handlePointerMove}
183
380
  onPointerUp={handlePointerUp}
381
+ onKeyDown={handleKeyDown}
184
382
  role="separator"
185
- tabIndex={0}
383
+ tabIndex={isStatic() ? undefined : 0}
186
384
  data-orientation={orientation()}
385
+ data-static={isStatic() ? '' : undefined}
386
+ aria-orientation={isHoriz() ? 'vertical' : 'horizontal'}
387
+ aria-valuemin={0}
388
+ aria-valuemax={100}
389
+ aria-valuenow={valueNow()}
187
390
  {...rest}
188
391
  >
189
- {local.withHandle && (
392
+ <Show when={local.withHandle}>
190
393
  <div
191
394
  class={cn(
192
395
  'z-10 flex items-center justify-center',
193
- orientation() === 'horizontal'
194
- ? 'h-6 w-3 flex-col'
195
- : 'h-3 w-6 flex-row',
396
+ isHoriz() ? 'h-6 w-3 flex-col' : 'h-3 w-6 flex-row',
196
397
  )}
197
398
  >
198
399
  <svg
199
400
  class={cn(
200
401
  'text-muted-foreground/40',
201
- orientation() === 'horizontal' ? 'h-3 w-2' : 'h-2 w-3 rotate-90'
402
+ isHoriz() ? 'h-3 w-2' : 'h-2 w-3 rotate-90'
202
403
  )}
203
404
  viewBox="0 0 4 8"
204
405
  fill="currentColor"
@@ -211,9 +412,88 @@ function ResizableHandle(props: ResizableHandleProps) {
211
412
  <circle cx="3" cy="6.5" r="0.6" />
212
413
  </svg>
213
414
  </div>
214
- )}
415
+ </Show>
215
416
  </div>
216
417
  );
217
418
  }
218
419
 
219
- export { ResizablePanelGroup, ResizablePanel, ResizableHandle };
420
+ // --- Resizable (convenience: auto-inserts handles between visible panels) ---
421
+
422
+ export interface ResizableProps {
423
+ orientation?: Orientation;
424
+ /** Fired on drag-end / keyboard resize / visibility change with the current panel sizes (percent). */
425
+ onChange?: (sizes: number[]) => void;
426
+ /** Show a visible grip on each interactive handle. */
427
+ withHandle?: boolean;
428
+ class?: string;
429
+ /** `ResizablePanel` children. */
430
+ children: JSX.Element;
431
+ }
432
+
433
+ /**
434
+ * Convenience group that takes `ResizablePanel` children and AUTO-INSERTS a
435
+ * `ResizableHandle` between each pair of visible (non-`hidden`) panels. A handle
436
+ * is interactive only between two unlocked neighbors; otherwise it renders as a
437
+ * static divider. Power users who need manual control can keep using
438
+ * `ResizablePanelGroup` + explicit `ResizableHandle`s.
439
+ */
440
+ function Resizable(props: ResizableProps) {
441
+ const [local] = splitProps(props, ['orientation', 'onChange', 'withHandle', 'class', 'children']);
442
+ const orientation = () => local.orientation ?? 'horizontal';
443
+
444
+ // Resolve children to the actual panel elements so we can read their props.
445
+ const resolved = resolveChildren(() => local.children);
446
+
447
+ const panels = (): { el: Element; locked: boolean; hidden: boolean }[] => {
448
+ const arr = resolved.toArray().filter((c): c is Element => c instanceof Element);
449
+ return arr.map((el) => ({
450
+ el,
451
+ locked: el.hasAttribute('data-locked'),
452
+ hidden: (el as HTMLElement).hidden || el.hasAttribute('hidden'),
453
+ }));
454
+ };
455
+
456
+ const visible = () => panels().filter((p) => !p.hidden);
457
+
458
+ function emitChange() {
459
+ if (!local.onChange) return;
460
+ const sizes = visible().map((p) => {
461
+ const r = (p.el as HTMLElement).getBoundingClientRect();
462
+ const parent = (p.el as HTMLElement).parentElement;
463
+ const total = parent ? parent.getBoundingClientRect()[orientation() === 'horizontal' ? 'width' : 'height'] : 0;
464
+ const dimVal = r[orientation() === 'horizontal' ? 'width' : 'height'];
465
+ return total > 0 ? Math.round((dimVal / total) * 100) : 0;
466
+ });
467
+ local.onChange(sizes);
468
+ }
469
+
470
+ return (
471
+ <ResizableContext.Provider value={{ orientation: orientation() }}>
472
+ <div
473
+ class={cn(
474
+ 'flex h-full w-full',
475
+ orientation() === 'vertical' ? 'flex-col' : 'flex-row',
476
+ local.class,
477
+ )}
478
+ data-orientation={orientation()}
479
+ >
480
+ <For each={visible()}>
481
+ {(panel, i) => (
482
+ <>
483
+ <Show when={i() > 0}>
484
+ <ResizableHandle
485
+ withHandle={local.withHandle}
486
+ static={panel.locked || visible()[i() - 1]?.locked}
487
+ onPanelResize={() => emitChange()}
488
+ />
489
+ </Show>
490
+ {panel.el as unknown as JSX.Element}
491
+ </>
492
+ )}
493
+ </For>
494
+ </div>
495
+ </ResizableContext.Provider>
496
+ );
497
+ }
498
+
499
+ export { ResizablePanelGroup, ResizablePanel, ResizableHandle, Resizable };
@@ -1,6 +1,7 @@
1
1
  import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
2
  import { For } from 'solid-js';
3
3
  import { ScrollArea } from './scroll-area';
4
+ import { componentDescription } from '../stories/docs/element-controls';
4
5
 
5
6
  const meta = {
6
7
  title: 'UI/ScrollArea',
@@ -9,13 +10,11 @@ const meta = {
9
10
  parameters: {
10
11
  layout: 'padded',
11
12
  docs: {
12
- description: {
13
- component: [
14
- 'A vertically scrollable container with thin, themed scrollbars (`scrollbar-thin` + muted thumb, transparent track). A thin styling layer over native overflow no custom scroll hijacking, so momentum, keyboard, and accessibility behave exactly like the platform expects. Constrain it with a height (or let a flex parent bound it) and overflow content scrolls.',
15
- '**When to use:** any bounded region whose content can exceed its height the conversation/history sidebar, a long menu, a tall card body.',
16
- '**How to use:** set a height via `class` and drop the scrollable content inside. All other div props (e.g. `aria-label`) are forwarded.',
17
- ].join('\n\n'),
18
- },
13
+ description: componentDescription([
14
+ 'A vertically scrollable container with thin, themed scrollbars (`scrollbar-thin` + muted thumb, transparent track). A thin styling layer over native overflow — no custom scroll hijacking, so momentum, keyboard, and accessibility behave exactly like the platform expects. Constrain it with a height (or let a flex parent bound it) and overflow content scrolls.',
15
+ '**When to use:** any bounded region whose content can exceed its heightthe conversation/history sidebar, a long menu, a tall card body.',
16
+ '**How to use:** set a height via `class` and drop the scrollable content inside. All other div props (e.g. `aria-label`) are forwarded.',
17
+ ]),
19
18
  },
20
19
  },
21
20
  render: () => (