@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.
- package/README.md +9 -9
- package/dist/custom-elements.json +1676 -881
- package/dist/kitn-chat.es.js +36 -36
- package/dist/llms/llms-full.txt +316 -155
- package/dist/llms/llms.txt +18 -18
- package/dist/schemas/card-envelope.schema.json +14 -0
- package/dist/schemas/card-event.schema.json +12 -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/task-list.result.schema.json +16 -0
- package/dist/schemas/task-list.schema.json +78 -0
- package/dist/theme.tokens.css +65 -65
- package/dist/tsx-B8rCNbgL.js +1 -0
- package/dist/typescript-RycA9KXf.js +1 -0
- package/frameworks/react/index.tsx +382 -193
- package/frameworks/react/runtime.tsx +2 -2
- package/llms-full.txt +316 -155
- package/llms.txt +18 -18
- package/package.json +5 -2
- package/src/components/artifact.stories.tsx +138 -0
- package/src/components/artifact.tsx +581 -0
- package/src/components/attachments.stories.tsx +7 -8
- package/src/components/attachments.tsx +2 -2
- package/src/components/card.tsx +110 -0
- package/src/components/chain-of-thought.stories.tsx +7 -8
- package/src/components/chat-container.stories.tsx +7 -8
- package/src/components/chat-container.tsx +4 -0
- package/src/components/checkpoint.stories.tsx +7 -8
- package/src/components/code-block.stories.tsx +8 -9
- package/src/components/component-meta.json +3411 -0
- package/src/components/confirm-card.stories.tsx +74 -0
- package/src/components/confirm-card.tsx +299 -0
- package/src/components/context.stories.tsx +7 -8
- package/src/components/conversation-item.stories.tsx +7 -8
- package/src/components/conversation-item.tsx +2 -2
- package/src/components/conversation-list.stories.tsx +7 -8
- package/src/components/conversation-list.tsx +1 -1
- package/src/components/embed.tsx +196 -0
- package/src/components/empty.stories.tsx +8 -9
- package/src/components/feedback-bar.stories.tsx +7 -8
- package/src/components/file-tree.stories.tsx +73 -0
- package/src/components/file-tree.tsx +383 -0
- package/src/components/file-upload.stories.tsx +7 -8
- package/src/components/form-widgets.tsx +461 -0
- package/src/components/form.tsx +796 -0
- package/src/components/image.stories.tsx +7 -8
- package/src/components/link-card.tsx +194 -0
- package/src/components/loader.stories.tsx +7 -8
- package/src/components/markdown.stories.tsx +7 -8
- package/src/components/message-narrow.stories.tsx +12 -13
- package/src/components/message-skills.stories.tsx +16 -17
- package/src/components/message.stories.tsx +17 -18
- package/src/components/model-switcher.stories.tsx +7 -8
- package/src/components/prompt-input.stories.tsx +8 -9
- package/src/components/prompt-suggestion.stories.tsx +7 -8
- package/src/components/prompt-suggestion.tsx +3 -3
- package/src/components/reasoning.stories.tsx +7 -8
- package/src/components/scroll-button.stories.tsx +7 -8
- package/src/components/slash-command.stories.tsx +8 -9
- package/src/components/slash-command.tsx +2 -2
- package/src/components/source.stories.tsx +7 -8
- package/src/components/source.tsx +1 -1
- package/src/components/task-list-card.stories.tsx +78 -0
- package/src/components/task-list-card.tsx +388 -0
- package/src/components/text-shimmer.stories.tsx +7 -8
- package/src/components/thinking-bar.stories.tsx +7 -8
- package/src/components/tool.stories.tsx +7 -8
- package/src/components/tool.tsx +2 -2
- package/src/components/voice-input.stories.tsx +7 -8
- package/src/elements/artifact.stories.tsx +291 -0
- package/src/elements/artifact.tsx +72 -0
- package/src/elements/{kitn-attachments.stories.tsx → attachments.stories.tsx} +11 -11
- package/src/elements/attachments.tsx +4 -4
- package/src/elements/card.stories.tsx +118 -0
- package/src/elements/card.tsx +40 -0
- package/src/elements/catalog.stories.tsx +491 -0
- package/src/elements/{kitn-chain-of-thought.stories.tsx → chain-of-thought.stories.tsx} +13 -13
- package/src/elements/chain-of-thought.tsx +3 -3
- package/src/elements/{kitn-chat-scope-picker.stories.tsx → chat-scope-picker.stories.tsx} +10 -10
- package/src/elements/chat-scope-picker.tsx +4 -4
- package/src/elements/{kitn-chat-workspace.stories.tsx → chat-workspace.stories.tsx} +71 -29
- package/src/elements/chat-workspace.tsx +29 -3
- package/src/elements/{kitn-chat.stories.tsx → chat.stories.tsx} +61 -16
- package/src/elements/chat.tsx +23 -2
- package/src/elements/{kitn-checkpoint.stories.tsx → checkpoint.stories.tsx} +11 -11
- package/src/elements/checkpoint.tsx +4 -4
- package/src/elements/{kitn-code-block.stories.tsx → code-block.stories.tsx} +10 -10
- package/src/elements/code-block.tsx +3 -3
- package/src/elements/compiled.css +1 -1
- package/src/elements/composed-shell.stories.tsx +316 -0
- package/src/elements/confirm-card.stories.tsx +186 -0
- package/src/elements/confirm-card.tsx +45 -0
- package/src/elements/{kitn-context-meter.stories.tsx → context-meter.stories.tsx} +10 -10
- package/src/elements/context-meter.tsx +3 -3
- package/src/elements/{kitn-conversation-list.stories.tsx → conversation-list.stories.tsx} +35 -22
- package/src/elements/conversation-list.tsx +11 -2
- package/src/elements/css.ts +1 -1
- package/src/elements/define.tsx +10 -10
- package/src/elements/element-meta.json +2649 -0
- package/src/elements/element-types.d.ts +251 -125
- package/src/elements/embed.stories.tsx +197 -0
- package/src/elements/embed.tsx +35 -0
- package/src/elements/{kitn-empty.stories.tsx → empty.stories.tsx} +12 -12
- package/src/elements/empty.tsx +3 -3
- package/src/elements/{kitn-feedback-bar.stories.tsx → feedback-bar.stories.tsx} +11 -11
- package/src/elements/feedback-bar.tsx +4 -4
- package/src/elements/file-tree.stories.tsx +133 -0
- package/src/elements/file-tree.tsx +52 -0
- package/src/elements/{kitn-file-upload.stories.tsx → file-upload.stories.tsx} +12 -12
- package/src/elements/file-upload.tsx +4 -4
- package/src/elements/form.stories.tsx +204 -0
- package/src/elements/form.tsx +37 -0
- package/src/elements/{kitn-image.stories.tsx → image.stories.tsx} +10 -10
- package/src/elements/image.tsx +3 -3
- package/src/elements/link-card.stories.tsx +193 -0
- package/src/elements/link-card.tsx +34 -0
- package/src/elements/{kitn-loader.stories.tsx → loader.stories.tsx} +11 -11
- package/src/elements/loader.tsx +3 -3
- package/src/elements/{kitn-markdown.stories.tsx → markdown.stories.tsx} +10 -10
- package/src/elements/markdown.tsx +3 -3
- package/src/elements/{kitn-message-skills.stories.tsx → message-skills.stories.tsx} +10 -10
- package/src/elements/message-skills.tsx +3 -3
- package/src/elements/{kitn-message.stories.tsx → message.stories.tsx} +12 -12
- package/src/elements/message.tsx +5 -5
- package/src/elements/{kitn-model-switcher.stories.tsx → model-switcher.stories.tsx} +10 -10
- package/src/elements/model-switcher.tsx +5 -5
- package/src/elements/{kitn-prompt-input.stories.tsx → prompt-input.stories.tsx} +41 -19
- package/src/elements/prompt-input.tsx +5 -5
- package/src/elements/{kitn-prompt-suggestions.stories.tsx → prompt-suggestions.stories.tsx} +13 -13
- package/src/elements/prompt-suggestions.tsx +4 -4
- package/src/elements/{kitn-reasoning.stories.tsx → reasoning.stories.tsx} +10 -10
- package/src/elements/reasoning.tsx +4 -4
- package/src/elements/register.ts +11 -1
- package/src/elements/resizable.stories.tsx +200 -0
- package/src/elements/resizable.tsx +264 -0
- package/src/elements/{kitn-response-stream.stories.tsx → response-stream.stories.tsx} +10 -10
- package/src/elements/response-stream.tsx +4 -4
- package/src/elements/{kitn-source-list.stories.tsx → source-list.stories.tsx} +11 -11
- package/src/elements/{kitn-source.stories.tsx → source.stories.tsx} +12 -12
- package/src/elements/source.tsx +5 -5
- package/src/elements/styles.css +140 -1
- package/src/elements/task-list-card.stories.tsx +194 -0
- package/src/elements/task-list-card.tsx +40 -0
- package/src/elements/{kitn-text-shimmer.stories.tsx → text-shimmer.stories.tsx} +10 -10
- package/src/elements/text-shimmer.tsx +3 -3
- package/src/elements/{kitn-thinking-bar.stories.tsx → thinking-bar.stories.tsx} +11 -11
- package/src/elements/thinking-bar.tsx +5 -5
- package/src/elements/{kitn-tool.stories.tsx → tool.stories.tsx} +10 -10
- package/src/elements/tool.tsx +3 -3
- package/src/elements/{kitn-voice-input.stories.tsx → voice-input.stories.tsx} +10 -10
- package/src/elements/voice-input.tsx +4 -4
- package/src/index.ts +94 -2
- package/src/primitives/card-contract.ts +60 -0
- package/src/primitives/card-host.tsx +35 -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/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/task-list.result.schema.json +16 -0
- package/src/primitives/card-schemas/task-list.schema.json +78 -0
- package/src/primitives/card-validate.ts +95 -0
- package/src/primitives/embed-providers.ts +254 -0
- package/src/primitives/highlighter.ts +4 -0
- package/src/primitives/link-preview.ts +87 -0
- package/src/primitives/pdf-preview.ts +121 -0
- package/src/stories/chat-panel-layout.stories.tsx +2 -1
- package/src/stories/chat-scene.tsx +22 -21
- package/src/stories/checkpoint-restore.stories.tsx +10 -10
- package/src/stories/conversation-with-reasoning.stories.tsx +4 -4
- package/src/stories/conversation-with-sources.stories.tsx +7 -7
- package/src/stories/docs/Accessibility.mdx +2 -2
- package/src/stories/docs/ForAIAgents.mdx +3 -3
- package/src/stories/docs/GettingStarted.mdx +2 -2
- package/src/stories/docs/Installation.mdx +2 -2
- package/src/stories/docs/Integrations.mdx +29 -29
- package/src/stories/docs/Introduction.mdx +3 -3
- package/src/stories/docs/Theming.mdx +2 -2
- package/src/stories/docs/element-controls.ts +60 -0
- package/src/stories/docs/theme-editor/theme-editor.tsx +1 -0
- package/src/stories/examples/ChoosingComponents.mdx +94 -0
- package/src/stories/examples/sample-data.ts +79 -0
- package/src/stories/message-actions.stories.tsx +13 -13
- package/src/stories/pattern-centered-conversation.stories.tsx +3 -3
- package/src/stories/pattern-docked-widget.stories.tsx +1 -1
- package/src/stories/pattern-empty-state.stories.tsx +3 -3
- package/src/stories/prompt-input-variants.stories.tsx +13 -13
- package/src/stories/streaming-response.stories.tsx +3 -3
- package/src/stories/typography.stories.tsx +4 -4
- package/src/ui/avatar.stories.tsx +7 -8
- package/src/ui/badge.stories.tsx +7 -8
- package/src/ui/button.stories.tsx +8 -9
- package/src/ui/button.tsx +1 -0
- package/src/ui/collapsible.stories.tsx +6 -7
- package/src/ui/dropdown.stories.tsx +6 -7
- package/src/ui/hover-card.stories.tsx +6 -7
- package/src/ui/resizable.stories.tsx +74 -9
- package/src/ui/resizable.tsx +351 -71
- package/src/ui/scroll-area.stories.tsx +6 -7
- package/src/ui/scroll-area.tsx +3 -1
- package/src/ui/separator.stories.tsx +7 -8
- package/src/ui/skeleton.stories.tsx +7 -8
- package/src/ui/textarea.stories.tsx +6 -7
- package/src/ui/tooltip.stories.tsx +8 -9
- package/theme.css +65 -65
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { onMount, onCleanup, type JSX } from 'solid-js';
|
|
3
|
+
import './embed'; // side effect: registers <kc-embed>
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
import type { EmbedCardData } from '../primitives/embed-providers';
|
|
6
|
+
import { configureEmbedAllowlist } from '../primitives/embed-providers';
|
|
7
|
+
|
|
8
|
+
// Custom DOM element — declare the tag for JSX.
|
|
9
|
+
declare module 'solid-js' {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
11
|
+
namespace JSX {
|
|
12
|
+
interface IntrinsicElements {
|
|
13
|
+
'kc-embed': JSX.HTMLAttributes<HTMLElement> & {
|
|
14
|
+
'card-id'?: string;
|
|
15
|
+
ref?: (el: HTMLElement) => void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A sized box the embed sits in. */
|
|
22
|
+
function Frame(props: { children: JSX.Element }) {
|
|
23
|
+
return <div style={{ width: '100%', 'max-width': '560px' }}>{props.children}</div>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Mount a kc-embed, set its `data` property, and route `open` to a console log. */
|
|
27
|
+
function Embed(props: { cardId: string; data: EmbedCardData }) {
|
|
28
|
+
let el: HTMLElement & { cardId?: string; data?: EmbedCardData };
|
|
29
|
+
const onCard = (e: Event) => {
|
|
30
|
+
const ev = (e as CustomEvent).detail;
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log('[kc-card]', ev);
|
|
33
|
+
if (ev.kind === 'open' && ev.target === 'tab') {
|
|
34
|
+
window.open(ev.url, '_blank', 'noopener,noreferrer');
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
onMount(() => {
|
|
38
|
+
if (el) {
|
|
39
|
+
el.cardId = props.cardId;
|
|
40
|
+
el.data = props.data;
|
|
41
|
+
}
|
|
42
|
+
document.addEventListener('kc-card', onCard);
|
|
43
|
+
onCleanup(() => document.removeEventListener('kc-card', onCard));
|
|
44
|
+
});
|
|
45
|
+
return (
|
|
46
|
+
<Frame>
|
|
47
|
+
<kc-embed ref={(e) => (el = e as HTMLElement & { cardId?: string; data?: EmbedCardData })} />
|
|
48
|
+
</Frame>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const YT_ENVELOPE = {
|
|
53
|
+
type: 'embed',
|
|
54
|
+
id: 'card-embed-1',
|
|
55
|
+
title: 'Intro video',
|
|
56
|
+
data: { provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Product intro', aspectRatio: '16:9' },
|
|
57
|
+
} satisfies { type: string; id: string; title: string; data: EmbedCardData };
|
|
58
|
+
|
|
59
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
60
|
+
<kc-embed id="em"></kc-embed>
|
|
61
|
+
|
|
62
|
+
<script type="module">
|
|
63
|
+
import '@kitnai/chat/elements'; // registers the custom elements
|
|
64
|
+
|
|
65
|
+
const em = document.getElementById('em');
|
|
66
|
+
em.cardId = 'card-embed-1';
|
|
67
|
+
// \`data\` is a JS property (the CardEnvelope \`data\`):
|
|
68
|
+
em.data = { provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Product intro' };
|
|
69
|
+
|
|
70
|
+
// NO network to YouTube until the user clicks play (privacy-first lazy facade).
|
|
71
|
+
// The optional "Open on YouTube" affordance bubbles a composed \`kc-card\` open event:
|
|
72
|
+
document.addEventListener('kc-card', (e) => {
|
|
73
|
+
const ev = e.detail;
|
|
74
|
+
if (ev.kind === 'open' && ev.target === 'tab') {
|
|
75
|
+
window.open(ev.url, '_blank', 'noopener,noreferrer');
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
</script>`;
|
|
79
|
+
|
|
80
|
+
const meta = {
|
|
81
|
+
title: 'Generative UI/Cards/kc-embed',
|
|
82
|
+
tags: ['autodocs'],
|
|
83
|
+
argTypes: argTypesFor('kc-embed'),
|
|
84
|
+
parameters: {
|
|
85
|
+
layout: 'padded',
|
|
86
|
+
docs: {
|
|
87
|
+
description: specDescription('kc-embed', [
|
|
88
|
+
'`<kc-embed>` is a **privacy-first lazy media embed** (YouTube / Vimeo / allowlisted generic player) for the generative-UI feature. It speaks the **Card Contract**: data down (an `embed` `CardEnvelope`), events up (only the `open` verb, plus lifecycle `ready` / failure `error`).',
|
|
89
|
+
'**Lazy facade:** the initial render is just a **poster + play button** — NO provider iframe, NO third-party JS, NO cookies until the user clicks play. YouTube loads via `youtube-nocookie.com`; Vimeo with `dnt=1`. This buys privacy (no tracking until opt-in) and performance (no player JS on load).',
|
|
90
|
+
'**Security:** `generic` embeds frame an arbitrary https URL, so they are **rejected unless the app allowlists their origin** with `configureEmbedAllowlist([...])` (defaults to empty — an agent cannot frame an arbitrary origin). The player iframe is sandboxed for a *trusted provider* (`allow-scripts allow-same-origin` on a cross-origin player) — contrast `<kc-artifact>`, which trusts nothing.',
|
|
91
|
+
'**Never a dead end:** a persistent "Open on {provider}" affordance dispatches the `open` verb (so a provider that refuses framing still has a way out). Set `data` as a JS property; `card-id` via attribute.',
|
|
92
|
+
'See the **Code** tab for the `CardEnvelope` JSON + HTML wiring.',
|
|
93
|
+
]),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
} satisfies Meta;
|
|
97
|
+
|
|
98
|
+
export default meta;
|
|
99
|
+
type Story = StoryObj;
|
|
100
|
+
|
|
101
|
+
/** YouTube (lazy) — poster + play; the iframe loads (youtube-nocookie) only on click. */
|
|
102
|
+
export const YouTube: Story = {
|
|
103
|
+
name: 'YouTube (lazy)',
|
|
104
|
+
render: () => <Embed cardId={YT_ENVELOPE.id} data={YT_ENVELOPE.data} />,
|
|
105
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** Vimeo — supply a `poster` (Vimeo has no static thumbnail URL). */
|
|
109
|
+
export const Vimeo: Story = {
|
|
110
|
+
render: () => (
|
|
111
|
+
<Embed
|
|
112
|
+
cardId="card-embed-2"
|
|
113
|
+
data={{
|
|
114
|
+
provider: 'vimeo',
|
|
115
|
+
id: '76979871',
|
|
116
|
+
title: 'Vimeo staff pick',
|
|
117
|
+
poster: 'https://placehold.co/1280x720/1ab7ea/ffffff/png?text=Vimeo',
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Generic player — an https embed URL whose origin the app has allowlisted. */
|
|
124
|
+
export const Generic: Story = {
|
|
125
|
+
name: 'Generic player',
|
|
126
|
+
render: () => {
|
|
127
|
+
configureEmbedAllowlist(['https://www.youtube-nocookie.com']);
|
|
128
|
+
return (
|
|
129
|
+
<Embed
|
|
130
|
+
cardId="card-embed-3"
|
|
131
|
+
data={{
|
|
132
|
+
provider: 'generic',
|
|
133
|
+
url: 'https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ',
|
|
134
|
+
title: 'Generic embed',
|
|
135
|
+
poster: 'https://placehold.co/1280x720/444/fff/png?text=Generic+player',
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
parameters: {
|
|
141
|
+
docs: {
|
|
142
|
+
source: {
|
|
143
|
+
code: `import { configureEmbedAllowlist } from '@kitnai/chat';
|
|
144
|
+
|
|
145
|
+
// Generic embeds are blocked by default — allowlist the trusted origin first:
|
|
146
|
+
configureEmbedAllowlist(['https://your-player.example.com']);
|
|
147
|
+
|
|
148
|
+
em.data = {
|
|
149
|
+
provider: 'generic',
|
|
150
|
+
url: 'https://your-player.example.com/embed/abc',
|
|
151
|
+
title: 'Generic embed',
|
|
152
|
+
poster: 'https://your-cdn.example.com/poster.jpg',
|
|
153
|
+
};`,
|
|
154
|
+
language: 'ts',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** Custom aspect ratio — a vertical 9:16 short. */
|
|
161
|
+
export const CustomAspectRatio: Story = {
|
|
162
|
+
name: 'Custom aspect ratio (9:16)',
|
|
163
|
+
render: () => (
|
|
164
|
+
<div style={{ width: '100%', 'max-width': '280px' }}>
|
|
165
|
+
<EmbedRaw
|
|
166
|
+
cardId="card-embed-4"
|
|
167
|
+
data={{ provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Short', aspectRatio: '9:16' }}
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** Blocked-embed fallback — the "Open on provider" affordance is always present. */
|
|
174
|
+
export const BlockedFallback: Story = {
|
|
175
|
+
name: 'Blocked-embed fallback',
|
|
176
|
+
render: () => <Embed cardId="card-embed-5" data={{ provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Maybe blocked' }} />,
|
|
177
|
+
parameters: {
|
|
178
|
+
docs: {
|
|
179
|
+
description: {
|
|
180
|
+
story:
|
|
181
|
+
'Some providers refuse framing (X-Frame-Options / CSP `frame-ancestors`). We can\'t detect that cross-origin in JS, so the **"Open on {provider}"** affordance is *always* available — a blocked embed is never a dead end.',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// A frame-less variant so the 9:16 story controls its own width.
|
|
188
|
+
function EmbedRaw(props: { cardId: string; data: EmbedCardData }) {
|
|
189
|
+
let el: HTMLElement & { cardId?: string; data?: EmbedCardData };
|
|
190
|
+
onMount(() => {
|
|
191
|
+
if (el) {
|
|
192
|
+
el.cardId = props.cardId;
|
|
193
|
+
el.data = props.data;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return <kc-embed ref={(e) => (el = e as HTMLElement & { cardId?: string; data?: EmbedCardData })} />;
|
|
197
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
|
+
import { Embed } from '../components/embed';
|
|
3
|
+
import type { EmbedCardData } from '../primitives/embed-providers';
|
|
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 embed payload (provider + id/url + options). Set as a JS **property** (object). */
|
|
10
|
+
data?: EmbedCardData;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `<kc-embed>` — a privacy-first **lazy media embed** (YouTube / Vimeo / allowlisted
|
|
15
|
+
* generic player). Initial render is a poster + play button: NO provider iframe, JS,
|
|
16
|
+
* or cookies until the user clicks play (YouTube via `youtube-nocookie`, Vimeo with
|
|
17
|
+
* `dnt=1`). A persistent "Open on {provider}" affordance dispatches the contract
|
|
18
|
+
* `open` verb via the bubbling `kc-card` event. `generic` URLs are rejected unless
|
|
19
|
+
* their origin was allowlisted with `configureEmbedAllowlist`. Set `data` as a JS
|
|
20
|
+
* property; `card-id` via attribute.
|
|
21
|
+
*/
|
|
22
|
+
defineWebComponent<Props>(
|
|
23
|
+
'kc-embed',
|
|
24
|
+
{
|
|
25
|
+
cardId: undefined,
|
|
26
|
+
data: undefined,
|
|
27
|
+
},
|
|
28
|
+
(props, { element }) => (
|
|
29
|
+
<Embed
|
|
30
|
+
cardId={props.cardId ?? ''}
|
|
31
|
+
data={props.data ?? ({ provider: 'generic' } as EmbedCardData)}
|
|
32
|
+
onEmit={(event) => emitCardEvent(element, event)}
|
|
33
|
+
/>
|
|
34
|
+
),
|
|
35
|
+
);
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
2
|
import { onMount } from 'solid-js';
|
|
3
3
|
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
4
5
|
|
|
5
6
|
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
6
7
|
declare module 'solid-js' {
|
|
7
8
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
8
9
|
namespace JSX {
|
|
9
10
|
interface IntrinsicElements {
|
|
10
|
-
'
|
|
11
|
+
'kc-empty': JSX.HTMLAttributes<HTMLElement>;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
16
|
-
<
|
|
17
|
+
<kc-empty
|
|
17
18
|
empty-title="No conversations yet"
|
|
18
19
|
description="Start a new chat to see it appear here."
|
|
19
20
|
>
|
|
@@ -37,26 +38,25 @@ const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
|
37
38
|
</svg>
|
|
38
39
|
New chat
|
|
39
40
|
</button>
|
|
40
|
-
</
|
|
41
|
+
</kc-empty>
|
|
41
42
|
|
|
42
43
|
<script type="module">
|
|
43
44
|
import '@kitnai/chat/elements'; // registers the custom elements
|
|
44
45
|
</script>`;
|
|
45
46
|
|
|
46
47
|
const meta = {
|
|
47
|
-
title: 'Web Components/
|
|
48
|
+
title: 'Web Components/kc-empty',
|
|
48
49
|
tags: ['autodocs'],
|
|
50
|
+
argTypes: argTypesFor('kc-empty'),
|
|
49
51
|
parameters: {
|
|
50
52
|
layout: 'fullscreen',
|
|
51
53
|
docs: {
|
|
52
|
-
description:
|
|
53
|
-
|
|
54
|
-
'`<kitn-empty>` is the framework-agnostic **web component** for an empty-state block — an icon, a title, a description, and actions — isolated in **Shadow DOM**.',
|
|
54
|
+
description: specDescription('kc-empty', [
|
|
55
|
+
'`<kc-empty>` is the framework-agnostic **web component** for an empty-state block — an icon, a title, a description, and actions — isolated in **Shadow DOM**.',
|
|
55
56
|
'**When to use:** placeholder UI for an empty list/thread in a non-Solid app. In SolidJS, compose the `Empty*` primitives.',
|
|
56
57
|
"**How to use:** register once with `import '@kitnai/chat/elements'`, set `empty-title` (note `empty-title`, not `title`) and `description` via attributes, and use the **slots** (\"Route 2\") to project your own icon (`slot=\"media\"`) and actions (the default slot).",
|
|
57
58
|
'See the **Code** tab for HTML usage.',
|
|
58
|
-
]
|
|
59
|
-
},
|
|
59
|
+
]),
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
} satisfies Meta;
|
|
@@ -64,7 +64,7 @@ const meta = {
|
|
|
64
64
|
export default meta;
|
|
65
65
|
type Story = StoryObj;
|
|
66
66
|
|
|
67
|
-
/** Render the actual `<
|
|
67
|
+
/** Render the actual `<kc-empty>` custom element with slotted children. */
|
|
68
68
|
function EmptyElement() {
|
|
69
69
|
let el: HTMLElement | undefined;
|
|
70
70
|
onMount(() => {
|
|
@@ -73,7 +73,7 @@ function EmptyElement() {
|
|
|
73
73
|
el.setAttribute('description', 'Start a new chat to see it appear here.');
|
|
74
74
|
});
|
|
75
75
|
return (
|
|
76
|
-
<
|
|
76
|
+
<kc-empty ref={(e) => (el = e as HTMLElement)} style={{ display: 'block', padding: '24px' }}>
|
|
77
77
|
<svg slot="media" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
78
78
|
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
79
79
|
</svg>
|
|
@@ -99,7 +99,7 @@ function EmptyElement() {
|
|
|
99
99
|
</svg>
|
|
100
100
|
New chat
|
|
101
101
|
</button>
|
|
102
|
-
</
|
|
102
|
+
</kc-empty>
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
package/src/elements/empty.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Show } from 'solid-js';
|
|
2
|
-
import {
|
|
2
|
+
import { defineWebComponent } from './define';
|
|
3
3
|
import { Empty, EmptyHeader, EmptyMedia, EmptyTitle, EmptyDescription, EmptyContent } from '../components/empty';
|
|
4
4
|
|
|
5
5
|
interface Props extends Record<string, unknown> {
|
|
@@ -10,11 +10,11 @@ interface Props extends Record<string, unknown> {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* `<
|
|
13
|
+
* `<kc-empty>` — an empty-state block. `empty-title`/`description` via
|
|
14
14
|
* attributes; slot your own icon into `slot="media"` and actions into the
|
|
15
15
|
* default slot (Route 2 slots).
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
defineWebComponent<Props>('kc-empty', {
|
|
18
18
|
emptyTitle: '',
|
|
19
19
|
description: '',
|
|
20
20
|
}, (props) => (
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
2
|
import './register'; // side effect: registers the custom elements
|
|
3
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
3
4
|
|
|
4
5
|
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
5
6
|
declare module 'solid-js' {
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
7
8
|
namespace JSX {
|
|
8
9
|
interface IntrinsicElements {
|
|
9
|
-
'
|
|
10
|
+
'kc-feedback-bar': JSX.HTMLAttributes<HTMLElement> & {
|
|
10
11
|
'bar-title'?: string;
|
|
11
12
|
'on:helpful'?: (e: CustomEvent) => void;
|
|
12
13
|
'on:nothelpful'?: (e: CustomEvent) => void;
|
|
@@ -17,31 +18,30 @@ declare module 'solid-js' {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
20
|
-
<
|
|
21
|
+
<kc-feedback-bar bar-title="Was this helpful?"></kc-feedback-bar>
|
|
21
22
|
|
|
22
23
|
<script type="module">
|
|
23
24
|
import '@kitnai/chat/elements'; // registers the custom elements
|
|
24
25
|
|
|
25
|
-
const bar = document.querySelector('
|
|
26
|
+
const bar = document.querySelector('kc-feedback-bar');
|
|
26
27
|
bar.addEventListener('helpful', () => console.log('👍'));
|
|
27
28
|
bar.addEventListener('nothelpful', () => console.log('👎'));
|
|
28
29
|
bar.addEventListener('close', () => bar.remove());
|
|
29
30
|
</script>`;
|
|
30
31
|
|
|
31
32
|
const meta = {
|
|
32
|
-
title: 'Web Components/
|
|
33
|
+
title: 'Web Components/kc-feedback-bar',
|
|
33
34
|
tags: ['autodocs'],
|
|
35
|
+
argTypes: argTypesFor('kc-feedback-bar'),
|
|
34
36
|
parameters: {
|
|
35
37
|
layout: 'fullscreen',
|
|
36
38
|
docs: {
|
|
37
|
-
description:
|
|
38
|
-
|
|
39
|
-
'`<kitn-feedback-bar>` is the framework-agnostic **web component** for an inline thumbs up/down feedback banner with a dismiss button — isolated in **Shadow DOM**.',
|
|
39
|
+
description: specDescription('kc-feedback-bar', [
|
|
40
|
+
'`<kc-feedback-bar>` is the framework-agnostic **web component** for an inline thumbs up/down feedback banner with a dismiss button — isolated in **Shadow DOM**.',
|
|
40
41
|
'**When to use:** collecting a quick reaction after an answer or a completed task. In SolidJS, use the `FeedbackBar` primitive.',
|
|
41
42
|
"**How to use:** register once with `import '@kitnai/chat/elements'`, set the label via the `bar-title` attribute (`title` is avoided — it's a global HTML attribute), and listen for the `helpful` / `nothelpful` / `close` **CustomEvents**.",
|
|
42
43
|
'See the **Code** tab for HTML usage.',
|
|
43
|
-
]
|
|
44
|
-
},
|
|
44
|
+
]),
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
} satisfies Meta;
|
|
@@ -53,7 +53,7 @@ type Story = StoryObj;
|
|
|
53
53
|
export const Default: Story = {
|
|
54
54
|
render: () => (
|
|
55
55
|
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
56
|
-
<
|
|
56
|
+
<kc-feedback-bar
|
|
57
57
|
on:helpful={() => console.log('helpful')}
|
|
58
58
|
on:nothelpful={() => console.log('not helpful')}
|
|
59
59
|
on:close={() => console.log('closed')}
|
|
@@ -67,7 +67,7 @@ export const Default: Story = {
|
|
|
67
67
|
export const CustomTitle: Story = {
|
|
68
68
|
render: () => (
|
|
69
69
|
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
70
|
-
<
|
|
70
|
+
<kc-feedback-bar bar-title="Did this answer your question?" />
|
|
71
71
|
</div>
|
|
72
72
|
),
|
|
73
73
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
2
|
import { FeedbackBar } from '../components/feedback-bar';
|
|
3
3
|
|
|
4
4
|
interface Props extends Record<string, unknown> {
|
|
@@ -7,7 +7,7 @@ interface Props extends Record<string, unknown> {
|
|
|
7
7
|
barTitle?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
/** Events fired by `<
|
|
10
|
+
/** Events fired by `<kc-feedback-bar>`. */
|
|
11
11
|
interface Events {
|
|
12
12
|
/** The user clicked thumbs-up. */
|
|
13
13
|
helpful: void;
|
|
@@ -18,10 +18,10 @@ interface Events {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* `<
|
|
21
|
+
* `<kc-feedback-bar>` — an inline thumbs up/down feedback banner. Emits
|
|
22
22
|
* `helpful` / `nothelpful` / `close`.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
defineWebComponent<Props, Events>('kc-feedback-bar', {
|
|
25
25
|
barTitle: 'Was this helpful?',
|
|
26
26
|
}, (props, { dispatch }) => (
|
|
27
27
|
<FeedbackBar
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { createSignal, onMount, type JSX } from 'solid-js';
|
|
3
|
+
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
import type { FileTreeFile } from '../components/file-tree';
|
|
6
|
+
|
|
7
|
+
declare module 'solid-js' {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'kc-file-tree': JSX.HTMLAttributes<HTMLElement> & {
|
|
12
|
+
'active-file'?: string;
|
|
13
|
+
ref?: (el: HTMLElement) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const FILES: FileTreeFile[] = [
|
|
20
|
+
{ path: 'index.html', type: 'html' },
|
|
21
|
+
{ path: 'about.html', type: 'html' },
|
|
22
|
+
{ path: 'css/site.css', type: 'other', language: 'css' },
|
|
23
|
+
{ path: 'src/app.ts', type: 'other', language: 'ts' },
|
|
24
|
+
{ path: 'src/lib/format.ts', type: 'other', language: 'ts' },
|
|
25
|
+
{ path: 'src/lib/parse.ts', type: 'other', language: 'ts' },
|
|
26
|
+
{ path: 'assets/logo.svg', type: 'image' },
|
|
27
|
+
{ path: 'assets/report.pdf', type: 'pdf' },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
/** A bordered, sized box the tree fills + scrolls within. */
|
|
31
|
+
function Frame(props: { children: JSX.Element }) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
style={{
|
|
35
|
+
height: '320px',
|
|
36
|
+
width: '280px',
|
|
37
|
+
border: '1px solid var(--color-border, #e4e4e7)',
|
|
38
|
+
'border-radius': '10px',
|
|
39
|
+
overflow: 'hidden',
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
{props.children}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
48
|
+
<kc-file-tree style="display:block;height:320px"></kc-file-tree>
|
|
49
|
+
|
|
50
|
+
<script type="module">
|
|
51
|
+
import '@kitnai/chat/elements'; // registers the custom elements
|
|
52
|
+
|
|
53
|
+
const tree = document.querySelector('kc-file-tree');
|
|
54
|
+
// \`files\` is a JS property (array). Folders are derived from \`/\` in each path.
|
|
55
|
+
tree.files = [
|
|
56
|
+
{ path: 'index.html', type: 'html' },
|
|
57
|
+
{ path: 'src/app.ts', type: 'other' },
|
|
58
|
+
{ path: 'src/lib/format.ts', type: 'other' },
|
|
59
|
+
{ path: 'assets/logo.svg', type: 'image' },
|
|
60
|
+
];
|
|
61
|
+
tree.setAttribute('active-file', 'src/app.ts');
|
|
62
|
+
tree.addEventListener('select', (e) => console.log('selected', e.detail.path));
|
|
63
|
+
</script>`;
|
|
64
|
+
|
|
65
|
+
const meta = {
|
|
66
|
+
title: 'Web Components/kc-file-tree',
|
|
67
|
+
tags: ['autodocs'],
|
|
68
|
+
argTypes: argTypesFor('kc-file-tree'),
|
|
69
|
+
parameters: {
|
|
70
|
+
layout: 'padded',
|
|
71
|
+
docs: {
|
|
72
|
+
description: specDescription('kc-file-tree', [
|
|
73
|
+
'`<kc-file-tree>` is the framework-agnostic **web component** for a collapsible, keyboard-navigable **file explorer** built from a flat list of `/`-delimited paths (nested folders are derived automatically). ARIA `tree`/`treeitem`. Isolated in **Shadow DOM**.',
|
|
74
|
+
'**When to use:** any time you need a file/folder tree — the Code tab of `<kc-artifact>` uses it, but it ships public so you can reuse it standalone (a project explorer, an attachments browser, a doc outline).',
|
|
75
|
+
"**How to use:** register once with `import '@kitnai/chat/elements'`, then set the `files` **property** (a JS array of `{ path, url?, code?, language?, type? }`). Folders come from the `/` in each `path`; `type` picks the icon. Set `active-file` to highlight a row, `default-expanded` to control which folders open. Listen for **`select`** (`detail.path`). Arrow keys navigate; Enter/Space selects or toggles.",
|
|
76
|
+
'**Placement:** a sidebar/explorer column — inside `<kc-artifact>`, a `<kc-resizable>` panel, or any file-picker surface. It **fills** its container, so give the parent (or the element) a height.',
|
|
77
|
+
'See the **Code** tab for HTML usage.',
|
|
78
|
+
]),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
} satisfies Meta;
|
|
82
|
+
|
|
83
|
+
export default meta;
|
|
84
|
+
type Story = StoryObj;
|
|
85
|
+
|
|
86
|
+
/** Interactive playground — click rows, use arrow keys / Enter to navigate. */
|
|
87
|
+
export const Playground: Story = {
|
|
88
|
+
render: () => {
|
|
89
|
+
const [selected, setSelected] = createSignal('src/app.ts');
|
|
90
|
+
let el: HTMLElement & { files?: FileTreeFile[] };
|
|
91
|
+
onMount(() => {
|
|
92
|
+
if (!el) return;
|
|
93
|
+
el.files = FILES;
|
|
94
|
+
el.addEventListener('select', (e) => {
|
|
95
|
+
const path = (e as CustomEvent).detail.path as string;
|
|
96
|
+
setSelected(path);
|
|
97
|
+
el.setAttribute('active-file', path);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return (
|
|
101
|
+
<div style={{ display: 'flex', 'flex-direction': 'column', gap: '8px' }}>
|
|
102
|
+
<Frame>
|
|
103
|
+
<kc-file-tree
|
|
104
|
+
ref={(e) => (el = e as HTMLElement & { files?: FileTreeFile[] })}
|
|
105
|
+
active-file={selected()}
|
|
106
|
+
/>
|
|
107
|
+
</Frame>
|
|
108
|
+
<span style={{ 'font-size': '13px', color: 'var(--color-muted-foreground, #71717a)' }}>
|
|
109
|
+
Selected: <code>{selected()}</code>
|
|
110
|
+
</span>
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** A deeper, nested layout with mixed file types. */
|
|
118
|
+
export const Nested: Story = {
|
|
119
|
+
render: () => {
|
|
120
|
+
let el: HTMLElement & { files?: FileTreeFile[] };
|
|
121
|
+
onMount(() => {
|
|
122
|
+
if (el) el.files = FILES;
|
|
123
|
+
});
|
|
124
|
+
return (
|
|
125
|
+
<Frame>
|
|
126
|
+
<kc-file-tree
|
|
127
|
+
ref={(e) => (el = e as HTMLElement & { files?: FileTreeFile[] })}
|
|
128
|
+
active-file="src/lib/format.ts"
|
|
129
|
+
/>
|
|
130
|
+
</Frame>
|
|
131
|
+
);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
|
+
import { FileTree, type FileTreeFile } from '../components/file-tree';
|
|
3
|
+
|
|
4
|
+
interface Props extends Record<string, unknown> {
|
|
5
|
+
/** The files to render. Set as a JS property (array of `{ path, url?, code?, language?, type? }`). */
|
|
6
|
+
files: FileTreeFile[];
|
|
7
|
+
/** Selected file path — highlighted in the tree. */
|
|
8
|
+
activeFile?: string;
|
|
9
|
+
/** Folder paths expanded initially. Omit to start with all folders open. */
|
|
10
|
+
defaultExpanded?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Events extends Record<string, unknown> {
|
|
14
|
+
/** Fired when a file is selected. `detail.path` = the file's path. */
|
|
15
|
+
select: { path: string };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `<kc-file-tree>` — a collapsible, keyboard-navigable file explorer built from a
|
|
20
|
+
* flat list of `/`-delimited paths (folders are derived). ARIA `tree`/`treeitem`.
|
|
21
|
+
* Selecting a file fires a `select` event (`detail.path`). Fills its container.
|
|
22
|
+
*/
|
|
23
|
+
defineWebComponent<Props, Events>('kc-file-tree', {
|
|
24
|
+
files: [],
|
|
25
|
+
activeFile: undefined,
|
|
26
|
+
defaultExpanded: undefined,
|
|
27
|
+
}, (props, { dispatch }) => (
|
|
28
|
+
<>
|
|
29
|
+
{/* Fill the container + own the scroll (see resizable.tsx fill technique:
|
|
30
|
+
a definite `1fr` grid cell scoped to a wrapper, NOT :host, so the facade's
|
|
31
|
+
sibling portal-mount div can't steal a grid track). */}
|
|
32
|
+
<style>{':host{display:block;height:100%;min-height:0}'}</style>
|
|
33
|
+
<div
|
|
34
|
+
style={{
|
|
35
|
+
display: 'grid',
|
|
36
|
+
'grid-template-rows': 'minmax(0, 1fr)',
|
|
37
|
+
'grid-template-columns': 'minmax(0, 1fr)',
|
|
38
|
+
height: '100%',
|
|
39
|
+
'min-height': '0',
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
<div class="overflow-auto scrollbar-thin py-1.5" style={{ 'min-height': '0' }}>
|
|
43
|
+
<FileTree
|
|
44
|
+
files={props.files}
|
|
45
|
+
activeFile={props.activeFile}
|
|
46
|
+
defaultExpanded={props.defaultExpanded}
|
|
47
|
+
onSelect={(path) => dispatch('select', { path })}
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</>
|
|
52
|
+
));
|