@svadmin/ai-elements 0.7.4 → 0.9.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 +31 -4
- package/THIRD_PARTY_NOTICES.md +67 -6
- package/dist/ai-workspace-contract.d.ts +14 -0
- package/dist/ai-workspace-contract.js +14 -0
- package/dist/ai.css +2 -5
- package/dist/ai.theme.css +1 -0
- package/dist/class-properties.generated.d.ts +1 -0
- package/dist/class-properties.generated.js +2 -0
- package/dist/classnames.d.ts +8 -0
- package/dist/classnames.js +26 -0
- package/dist/components/Response.svelte +2 -2
- package/dist/components/Response.svelte.d.ts +1 -1
- package/dist/components/code/index.d.ts +9 -18
- package/dist/components/code/index.js +8 -11
- package/dist/components/code-block/highlight.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/utilities.css +3172 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +36 -11
- package/vendor/streamdown/AnimatedText.svelte +93 -0
- package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
- package/vendor/streamdown/Block.svelte +96 -0
- package/vendor/streamdown/Block.svelte.d.ts +11 -0
- package/vendor/streamdown/Elements/Alert.svelte +69 -0
- package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Citation.svelte +260 -0
- package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Code.svelte +226 -0
- package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/Element.svelte +574 -0
- package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
- package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
- package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Image.svelte +200 -0
- package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Link.svelte +220 -0
- package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
- package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
- package/vendor/streamdown/Elements/Math.svelte +100 -0
- package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
- package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
- package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/Slot.svelte +23 -0
- package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Table.svelte +195 -0
- package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
- package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
- package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
- package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
- package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
- package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
- package/vendor/streamdown/Elements/icons.d.ts +31 -0
- package/vendor/streamdown/Elements/icons.js +200 -0
- package/vendor/streamdown/Elements/index.d.ts +8 -0
- package/vendor/streamdown/Elements/index.js +8 -0
- package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/popover.svelte.js +45 -0
- package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
- package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
- package/vendor/streamdown/IconProvider.svelte +11 -0
- package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
- package/vendor/streamdown/LICENSE +202 -0
- package/vendor/streamdown/PluginProvider.svelte +11 -0
- package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
- package/vendor/streamdown/README.svadmin.md +5 -0
- package/vendor/streamdown/Streamdown.svelte +447 -0
- package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
- package/vendor/streamdown/block/BlockTokens.svelte +45 -0
- package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
- package/vendor/streamdown/block/html.d.ts +14 -0
- package/vendor/streamdown/block/html.js +27 -0
- package/vendor/streamdown/block/text.d.ts +10 -0
- package/vendor/streamdown/block/text.js +31 -0
- package/vendor/streamdown/context-key.d.ts +1 -0
- package/vendor/streamdown/context-key.js +1 -0
- package/vendor/streamdown/context.svelte.d.ts +24 -0
- package/vendor/streamdown/context.svelte.js +75 -0
- package/vendor/streamdown/contracts/plugins.d.ts +26 -0
- package/vendor/streamdown/contracts/plugins.js +1 -0
- package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
- package/vendor/streamdown/contracts/streamdown.js +29 -0
- package/vendor/streamdown/detect-direction.d.ts +1 -0
- package/vendor/streamdown/detect-direction.js +1 -0
- package/vendor/streamdown/icon-context.d.ts +36 -0
- package/vendor/streamdown/icon-context.js +52 -0
- package/vendor/streamdown/incomplete-code.d.ts +6 -0
- package/vendor/streamdown/incomplete-code.js +23 -0
- package/vendor/streamdown/index.d.ts +22 -0
- package/vendor/streamdown/index.js +20 -0
- package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
- package/vendor/streamdown/markdown-parse-cache.js +109 -0
- package/vendor/streamdown/markdown.d.ts +21 -0
- package/vendor/streamdown/markdown.js +214 -0
- package/vendor/streamdown/marked/index.d.ts +44 -0
- package/vendor/streamdown/marked/index.js +228 -0
- package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
- package/vendor/streamdown/marked/marked-alert.js +47 -0
- package/vendor/streamdown/marked/marked-align.d.ts +10 -0
- package/vendor/streamdown/marked/marked-align.js +45 -0
- package/vendor/streamdown/marked/marked-br.d.ts +6 -0
- package/vendor/streamdown/marked/marked-br.js +15 -0
- package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
- package/vendor/streamdown/marked/marked-citations.js +53 -0
- package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
- package/vendor/streamdown/marked/marked-cjk.js +165 -0
- package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
- package/vendor/streamdown/marked/marked-dl.js +44 -0
- package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
- package/vendor/streamdown/marked/marked-footnotes.js +101 -0
- package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
- package/vendor/streamdown/marked/marked-hr.js +18 -0
- package/vendor/streamdown/marked/marked-list.d.ts +31 -0
- package/vendor/streamdown/marked/marked-list.js +330 -0
- package/vendor/streamdown/marked/marked-math.d.ts +13 -0
- package/vendor/streamdown/marked/marked-math.js +129 -0
- package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
- package/vendor/streamdown/marked/marked-mdx.js +124 -0
- package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
- package/vendor/streamdown/marked/marked-subsup.js +40 -0
- package/vendor/streamdown/marked/marked-table.d.ts +80 -0
- package/vendor/streamdown/marked/marked-table.js +527 -0
- package/vendor/streamdown/plugin-context.d.ts +19 -0
- package/vendor/streamdown/plugin-context.js +40 -0
- package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
- package/vendor/streamdown/plugins/cjk-shared.js +1 -0
- package/vendor/streamdown/plugins.d.ts +19 -0
- package/vendor/streamdown/plugins.js +107 -0
- package/vendor/streamdown/provenance.json +229 -0
- package/vendor/streamdown/remend.d.ts +2 -0
- package/vendor/streamdown/remend.js +1 -0
- package/vendor/streamdown/security/html.d.ts +19 -0
- package/vendor/streamdown/security/html.js +329 -0
- package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
- package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
- package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
- package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
- package/vendor/streamdown/security/types.d.ts +1 -0
- package/vendor/streamdown/security/types.js +1 -0
- package/vendor/streamdown/site/SiteHeader.svelte +94 -0
- package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
- package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
- package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
- package/vendor/streamdown/site/home/HomePage.svelte +293 -0
- package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
- package/vendor/streamdown/site/home/content.d.ts +69 -0
- package/vendor/streamdown/site/home/content.js +144 -0
- package/vendor/streamdown/site/metadata.d.ts +4 -0
- package/vendor/streamdown/site/metadata.js +4 -0
- package/vendor/streamdown/site/navigation.d.ts +6 -0
- package/vendor/streamdown/site/navigation.js +22 -0
- package/vendor/streamdown/streamdown/config.d.ts +41 -0
- package/vendor/streamdown/streamdown/config.js +125 -0
- package/vendor/streamdown/streamdown/context.d.ts +12 -0
- package/vendor/streamdown/streamdown/context.js +2 -0
- package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
- package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
- package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
- package/vendor/streamdown/streamdown/pipeline.js +138 -0
- package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
- package/vendor/streamdown/streamdown/runtime.js +112 -0
- package/vendor/streamdown/streaming.d.ts +5 -0
- package/vendor/streamdown/streaming.js +5 -0
- package/vendor/streamdown/theme.d.ts +486 -0
- package/vendor/streamdown/theme.js +370 -0
- package/vendor/streamdown/translations.d.ts +43 -0
- package/vendor/streamdown/translations.js +54 -0
- package/vendor/streamdown/url-policy.d.ts +1 -0
- package/vendor/streamdown/url-policy.js +1 -0
- package/vendor/streamdown/utils/bind.d.ts +8 -0
- package/vendor/streamdown/utils/bind.js +26 -0
- package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
- package/vendor/streamdown/utils/bundledLanguages.js +1 -0
- package/vendor/streamdown/utils/code-block.d.ts +8 -0
- package/vendor/streamdown/utils/code-block.js +38 -0
- package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
- package/vendor/streamdown/utils/copy.svelte.js +38 -0
- package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
- package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
- package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
- package/vendor/streamdown/utils/detectDirection.js +19 -0
- package/vendor/streamdown/utils/get.d.ts +1 -0
- package/vendor/streamdown/utils/get.js +25 -0
- package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
- package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
- package/vendor/streamdown/utils/index.d.ts +3 -0
- package/vendor/streamdown/utils/index.js +3 -0
- package/vendor/streamdown/utils/mermaid.d.ts +13 -0
- package/vendor/streamdown/utils/mermaid.js +49 -0
- package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
- package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
- package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
- package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
- package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
- package/vendor/streamdown/utils/runtime-env.js +13 -0
- package/vendor/streamdown/utils/save.d.ts +1 -0
- package/vendor/streamdown/utils/save.js +14 -0
- package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
- package/vendor/streamdown/utils/scroll-lock.js +35 -0
- package/vendor/streamdown/utils/table.d.ts +8 -0
- package/vendor/streamdown/utils/table.js +176 -0
- package/vendor/streamdown/utils/url.d.ts +22 -0
- package/vendor/streamdown/utils/url.js +98 -0
- package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
- package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
- package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
- package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown, type TableControlsConfig } from '../context.svelte.js';
|
|
3
|
+
import type { TableToken } from '../marked/index.js';
|
|
4
|
+
import { useKeyDown } from '../utils/useKeyDown.svelte.js';
|
|
5
|
+
import { lockBodyScroll } from '../utils/scroll-lock.js';
|
|
6
|
+
import { fullscreenIcon, resolveIcon } from './icons.js';
|
|
7
|
+
import Slot from './Slot.svelte';
|
|
8
|
+
import TableDownload from './TableDownload.svelte';
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
id,
|
|
12
|
+
token,
|
|
13
|
+
children
|
|
14
|
+
}: {
|
|
15
|
+
id: string;
|
|
16
|
+
token: TableToken;
|
|
17
|
+
children?: import('svelte').Snippet;
|
|
18
|
+
} = $props();
|
|
19
|
+
|
|
20
|
+
const streamdown = useStreamdown();
|
|
21
|
+
const TableComponent = $derived(streamdown.components?.table);
|
|
22
|
+
|
|
23
|
+
const resolveControls = (
|
|
24
|
+
controls: TableControlsConfig
|
|
25
|
+
): {
|
|
26
|
+
showControls: boolean;
|
|
27
|
+
showCopy: boolean;
|
|
28
|
+
showDownload: boolean;
|
|
29
|
+
showFullscreen: boolean;
|
|
30
|
+
} => {
|
|
31
|
+
if (controls === false) {
|
|
32
|
+
return {
|
|
33
|
+
showControls: false,
|
|
34
|
+
showCopy: false,
|
|
35
|
+
showDownload: false,
|
|
36
|
+
showFullscreen: false
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (controls === true || controls === undefined) {
|
|
41
|
+
return {
|
|
42
|
+
showControls: true,
|
|
43
|
+
showCopy: true,
|
|
44
|
+
showDownload: true,
|
|
45
|
+
showFullscreen: true
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const resolved = {
|
|
50
|
+
showControls: true,
|
|
51
|
+
showCopy: controls.copy !== false,
|
|
52
|
+
showDownload: controls.download !== false,
|
|
53
|
+
showFullscreen: controls.fullscreen !== false
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...resolved,
|
|
58
|
+
showControls: resolved.showCopy || resolved.showDownload || resolved.showFullscreen
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const tableControls = $derived(resolveControls(streamdown.controls.table));
|
|
63
|
+
const tableLayout = $derived(token.columnNormalization?.mode ?? 'balanced');
|
|
64
|
+
const tableLayoutIssues = $derived(token.columnNormalization?.issues.join(' ') ?? '');
|
|
65
|
+
let isFullscreen = $state(false);
|
|
66
|
+
|
|
67
|
+
const closeFullscreen = () => {
|
|
68
|
+
isFullscreen = false;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
useKeyDown({
|
|
72
|
+
keys: ['Escape'],
|
|
73
|
+
get isActive() {
|
|
74
|
+
return isFullscreen;
|
|
75
|
+
},
|
|
76
|
+
callback: closeFullscreen
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
$effect(() => {
|
|
80
|
+
if (typeof document === 'undefined' || !isFullscreen) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return lockBodyScroll(document);
|
|
85
|
+
});
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<div class={streamdown.theme.table.wrapper} data-streamdown="table-wrapper">
|
|
89
|
+
{#if tableControls.showControls}
|
|
90
|
+
<div class={streamdown.theme.table.toolbar} data-streamdown="table-toolbar">
|
|
91
|
+
<TableDownload
|
|
92
|
+
showCopy={tableControls.showCopy}
|
|
93
|
+
showDownload={tableControls.showDownload}
|
|
94
|
+
targetSelector={`[data-streamdown-table="${id}"]`}
|
|
95
|
+
/>
|
|
96
|
+
{#if tableControls.showFullscreen}
|
|
97
|
+
<button
|
|
98
|
+
class={streamdown.theme.components.button}
|
|
99
|
+
title={streamdown.translations.viewFullscreen}
|
|
100
|
+
type="button"
|
|
101
|
+
disabled={streamdown.isAnimating}
|
|
102
|
+
onclick={() => {
|
|
103
|
+
if (!streamdown.isAnimating) {
|
|
104
|
+
isFullscreen = true;
|
|
105
|
+
}
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
{@render resolveIcon(streamdown.icons, 'fullscreen', fullscreenIcon)()}
|
|
109
|
+
</button>
|
|
110
|
+
{/if}
|
|
111
|
+
</div>
|
|
112
|
+
{/if}
|
|
113
|
+
|
|
114
|
+
<div
|
|
115
|
+
data-streamdown-table={id}
|
|
116
|
+
data-streamdown-table-layout={tableLayout}
|
|
117
|
+
data-streamdown-table-layout-issues={tableLayoutIssues}
|
|
118
|
+
class={`${streamdown.theme.table.base} ${streamdown.theme.table.container} group`}
|
|
119
|
+
style:overscroll-behavior-x="none"
|
|
120
|
+
>
|
|
121
|
+
<Slot
|
|
122
|
+
props={{ children, token, class: streamdown.theme.table.table }}
|
|
123
|
+
component={TableComponent}
|
|
124
|
+
>
|
|
125
|
+
<table
|
|
126
|
+
data-streamdown="table"
|
|
127
|
+
data-streamdown-table-layout={tableLayout}
|
|
128
|
+
data-streamdown-table-layout-issues={tableLayoutIssues}
|
|
129
|
+
class={streamdown.theme.table.table}
|
|
130
|
+
>
|
|
131
|
+
{@render children?.()}
|
|
132
|
+
</table>
|
|
133
|
+
</Slot>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
{#if isFullscreen}
|
|
138
|
+
<div
|
|
139
|
+
data-streamdown="table-fullscreen"
|
|
140
|
+
class="fixed inset-0 z-50 flex flex-col bg-background p-4"
|
|
141
|
+
role="dialog"
|
|
142
|
+
tabindex="-1"
|
|
143
|
+
aria-modal="true"
|
|
144
|
+
onclick={(event) => {
|
|
145
|
+
if (event.target === event.currentTarget) {
|
|
146
|
+
closeFullscreen();
|
|
147
|
+
}
|
|
148
|
+
}}
|
|
149
|
+
onkeydown={(event) => {
|
|
150
|
+
if (event.target === event.currentTarget && (event.key === 'Enter' || event.key === ' ')) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
closeFullscreen();
|
|
153
|
+
}
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<div class="flex items-start justify-end pb-4">
|
|
157
|
+
<div class={streamdown.theme.table.toolbar} data-streamdown="table-fullscreen-toolbar">
|
|
158
|
+
<TableDownload
|
|
159
|
+
showCopy={tableControls.showCopy}
|
|
160
|
+
showDownload={tableControls.showDownload}
|
|
161
|
+
targetSelector={`[data-streamdown-table-fullscreen="${id}"]`}
|
|
162
|
+
/>
|
|
163
|
+
<button
|
|
164
|
+
class={streamdown.theme.components.button}
|
|
165
|
+
title={streamdown.translations.exitFullscreen}
|
|
166
|
+
type="button"
|
|
167
|
+
onclick={closeFullscreen}
|
|
168
|
+
>
|
|
169
|
+
X
|
|
170
|
+
</button>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<div
|
|
175
|
+
data-streamdown-table-fullscreen={id}
|
|
176
|
+
data-streamdown-table-layout={tableLayout}
|
|
177
|
+
data-streamdown-table-layout-issues={tableLayoutIssues}
|
|
178
|
+
class={`flex-1 overflow-auto ${streamdown.theme.table.base} ${streamdown.theme.table.container}`}
|
|
179
|
+
>
|
|
180
|
+
<Slot
|
|
181
|
+
props={{ children, token, class: streamdown.theme.table.table }}
|
|
182
|
+
component={TableComponent}
|
|
183
|
+
>
|
|
184
|
+
<table
|
|
185
|
+
data-streamdown="table"
|
|
186
|
+
data-streamdown-table-layout={tableLayout}
|
|
187
|
+
data-streamdown-table-layout-issues={tableLayoutIssues}
|
|
188
|
+
class={streamdown.theme.table.table}
|
|
189
|
+
>
|
|
190
|
+
{@render children?.()}
|
|
191
|
+
</table>
|
|
192
|
+
</Slot>
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
{/if}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TableToken } from '../marked/index.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
id: string;
|
|
4
|
+
token: TableToken;
|
|
5
|
+
children?: import('svelte').Snippet;
|
|
6
|
+
};
|
|
7
|
+
declare const Table: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type Table = ReturnType<typeof Table>;
|
|
9
|
+
export default Table;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown } from '../context.svelte.js';
|
|
3
|
+
import { scale } from 'svelte/transition';
|
|
4
|
+
import { checkIcon, copyIcon, downloadIcon, resolveIcon } from './icons.js';
|
|
5
|
+
import { Popover } from './popover.svelte.js';
|
|
6
|
+
import { useClickOutside } from '../utils/useClickOutside.svelte.js';
|
|
7
|
+
import { useKeyDown } from '../utils/useKeyDown.svelte.js';
|
|
8
|
+
import { useCopy } from '../utils/copy.svelte.js';
|
|
9
|
+
import { save } from '../utils/save.js';
|
|
10
|
+
import {
|
|
11
|
+
extractTableDataFromElement,
|
|
12
|
+
tableDataToCSV,
|
|
13
|
+
tableDataToMarkdown,
|
|
14
|
+
tableDataToTSV
|
|
15
|
+
} from '../utils/table.js';
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
showCopy = true,
|
|
19
|
+
showDownload = true,
|
|
20
|
+
targetSelector
|
|
21
|
+
}: {
|
|
22
|
+
showCopy?: boolean;
|
|
23
|
+
showDownload?: boolean;
|
|
24
|
+
targetSelector: string;
|
|
25
|
+
} = $props();
|
|
26
|
+
const streamdown = useStreamdown();
|
|
27
|
+
const popover = new Popover();
|
|
28
|
+
let modeState = $state<'download' | 'copy'>('download');
|
|
29
|
+
|
|
30
|
+
useKeyDown({
|
|
31
|
+
keys: ['Escape'],
|
|
32
|
+
get isActive() {
|
|
33
|
+
return popover.isOpen;
|
|
34
|
+
},
|
|
35
|
+
callback: () => {
|
|
36
|
+
popover.isOpen = false;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const clickOutside = useClickOutside({
|
|
40
|
+
get isActive() {
|
|
41
|
+
return popover.isOpen;
|
|
42
|
+
},
|
|
43
|
+
callback: () => {
|
|
44
|
+
popover.isOpen = false;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
let copyValue = $state('');
|
|
49
|
+
|
|
50
|
+
const copy = useCopy({
|
|
51
|
+
get content() {
|
|
52
|
+
return copyValue;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const copyOrDownload = async (type: 'Markdown' | 'CSV' | 'TSV') => {
|
|
57
|
+
const tableRoot = document.querySelector(targetSelector);
|
|
58
|
+
const table = tableRoot?.querySelector('table');
|
|
59
|
+
if (!table) {
|
|
60
|
+
popover.isOpen = false;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const tableData = extractTableDataFromElement(table);
|
|
65
|
+
if (type === 'Markdown') {
|
|
66
|
+
copyValue = tableDataToMarkdown(tableData);
|
|
67
|
+
if (modeState === 'copy') {
|
|
68
|
+
if (
|
|
69
|
+
typeof navigator?.clipboard?.write === 'function' &&
|
|
70
|
+
typeof ClipboardItem !== 'undefined'
|
|
71
|
+
) {
|
|
72
|
+
const html = table.outerHTML;
|
|
73
|
+
const plainText = copyValue;
|
|
74
|
+
try {
|
|
75
|
+
await navigator.clipboard.write([
|
|
76
|
+
new ClipboardItem({
|
|
77
|
+
'text/plain': new Blob([plainText], { type: 'text/plain' }),
|
|
78
|
+
'text/html': new Blob([html], { type: 'text/html' })
|
|
79
|
+
})
|
|
80
|
+
]);
|
|
81
|
+
} catch {
|
|
82
|
+
await copy.copy();
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
await copy.copy();
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
save('table.md', copyValue, 'text/markdown');
|
|
89
|
+
}
|
|
90
|
+
} else if (type === 'CSV') {
|
|
91
|
+
copyValue = tableDataToCSV(tableData);
|
|
92
|
+
if (modeState === 'copy') {
|
|
93
|
+
if (
|
|
94
|
+
typeof navigator?.clipboard?.write === 'function' &&
|
|
95
|
+
typeof ClipboardItem !== 'undefined'
|
|
96
|
+
) {
|
|
97
|
+
try {
|
|
98
|
+
await navigator.clipboard.write([
|
|
99
|
+
new ClipboardItem({
|
|
100
|
+
'text/plain': new Blob([copyValue], { type: 'text/plain' }),
|
|
101
|
+
'text/html': new Blob([table.outerHTML], { type: 'text/html' })
|
|
102
|
+
})
|
|
103
|
+
]);
|
|
104
|
+
} catch {
|
|
105
|
+
await copy.copy();
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
await copy.copy();
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
save('table.csv', copyValue, 'text/csv');
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
copyValue = tableDataToTSV(tableData);
|
|
115
|
+
await copy.copy();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
popover.isOpen = false;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const menuOptions = $derived(
|
|
122
|
+
modeState === 'download' ? ['Markdown', 'CSV'] : ['Markdown', 'CSV', 'TSV']
|
|
123
|
+
);
|
|
124
|
+
const buttonModes = $derived(
|
|
125
|
+
[showCopy ? 'copy' : null, showDownload ? 'download' : null].filter(
|
|
126
|
+
(mode): mode is 'download' | 'copy' => mode !== null
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
{#if popover.isOpen}
|
|
132
|
+
<div
|
|
133
|
+
id={'table-download-popover'}
|
|
134
|
+
role="dialog"
|
|
135
|
+
aria-modal="false"
|
|
136
|
+
transition:scale|global={{ start: 0.95, duration: 100 }}
|
|
137
|
+
{@attach clickOutside.attachment}
|
|
138
|
+
{@attach popover.popoverAttachment}
|
|
139
|
+
style:width="fit-content !important"
|
|
140
|
+
style:min-width="fit-content !important"
|
|
141
|
+
class={streamdown.theme.components.popover}
|
|
142
|
+
>
|
|
143
|
+
{#each menuOptions as type}
|
|
144
|
+
{@const label =
|
|
145
|
+
modeState === 'download'
|
|
146
|
+
? type === 'Markdown'
|
|
147
|
+
? streamdown.translations.downloadTableAsMarkdown
|
|
148
|
+
: streamdown.translations.downloadTableAsCsv
|
|
149
|
+
: type === 'Markdown'
|
|
150
|
+
? streamdown.translations.copyTableAsMarkdown
|
|
151
|
+
: type === 'CSV'
|
|
152
|
+
? streamdown.translations.copyTableAsCsv
|
|
153
|
+
: streamdown.translations.copyTableAsTsv}
|
|
154
|
+
<button
|
|
155
|
+
style="width: 100%; text-align: left; justify-content: flex-start; padding: 1rem 1rem; margin: 0.2rem 0;"
|
|
156
|
+
onclick={() => copyOrDownload(type as 'Markdown' | 'CSV' | 'TSV')}
|
|
157
|
+
class={streamdown.theme.components.button}
|
|
158
|
+
title={label}
|
|
159
|
+
type="button"
|
|
160
|
+
>
|
|
161
|
+
{type === 'Markdown'
|
|
162
|
+
? streamdown.translations.tableFormatMarkdown
|
|
163
|
+
: type === 'CSV'
|
|
164
|
+
? streamdown.translations.tableFormatCsv
|
|
165
|
+
: streamdown.translations.tableFormatTsv}
|
|
166
|
+
</button>
|
|
167
|
+
{/each}
|
|
168
|
+
</div>
|
|
169
|
+
{/if}
|
|
170
|
+
|
|
171
|
+
{#if buttonModes.length > 0}
|
|
172
|
+
<div
|
|
173
|
+
data-streamdown-table-download
|
|
174
|
+
class=" right-0 ml-auto flex items-center justify-end gap-2 p-1"
|
|
175
|
+
>
|
|
176
|
+
{#each buttonModes as mode (mode)}
|
|
177
|
+
<button
|
|
178
|
+
class={streamdown.theme.components.button}
|
|
179
|
+
onclick={async (e: MouseEvent) => {
|
|
180
|
+
if (streamdown.isAnimating) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (modeState === mode && popover.isOpen) {
|
|
184
|
+
popover.isOpen = false;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (popover.isOpen && modeState !== mode) {
|
|
188
|
+
popover.isOpen = false;
|
|
189
|
+
const wait = new Promise((resolve) => {
|
|
190
|
+
setTimeout(resolve, 80);
|
|
191
|
+
});
|
|
192
|
+
await wait;
|
|
193
|
+
}
|
|
194
|
+
popover.reference = e.target as HTMLButtonElement;
|
|
195
|
+
popover.isOpen = true;
|
|
196
|
+
modeState = mode as 'download' | 'copy';
|
|
197
|
+
}}
|
|
198
|
+
{@attach clickOutside.attachment}
|
|
199
|
+
title={mode === 'download'
|
|
200
|
+
? streamdown.translations.downloadTable
|
|
201
|
+
: streamdown.translations.copyTable}
|
|
202
|
+
disabled={streamdown.isAnimating}
|
|
203
|
+
type="button"
|
|
204
|
+
>
|
|
205
|
+
{#if mode === 'download'}
|
|
206
|
+
{@render resolveIcon(streamdown.icons, 'download', downloadIcon)()}
|
|
207
|
+
{:else if copy.isCopied}
|
|
208
|
+
{@render resolveIcon(streamdown.icons, 'check', checkIcon)()}
|
|
209
|
+
{:else}
|
|
210
|
+
{@render resolveIcon(streamdown.icons, 'copy', copyIcon)()}
|
|
211
|
+
{/if}
|
|
212
|
+
</button>
|
|
213
|
+
{/each}
|
|
214
|
+
</div>
|
|
215
|
+
{/if}
|
|
216
|
+
|
|
217
|
+
<style>
|
|
218
|
+
:global([data-streamdown-table-download] + div) {
|
|
219
|
+
margin-top: 0px;
|
|
220
|
+
}
|
|
221
|
+
</style>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
showCopy?: boolean;
|
|
3
|
+
showDownload?: boolean;
|
|
4
|
+
targetSelector: string;
|
|
5
|
+
};
|
|
6
|
+
declare const TableDownload: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type TableDownload = ReturnType<typeof TableDownload>;
|
|
8
|
+
export default TableDownload;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown } from '../../context.svelte.js';
|
|
3
|
+
import type { Tokens } from 'marked';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
token,
|
|
7
|
+
id,
|
|
8
|
+
isIncomplete = false
|
|
9
|
+
}: {
|
|
10
|
+
token: Tokens.Code;
|
|
11
|
+
id: string;
|
|
12
|
+
isIncomplete?: boolean;
|
|
13
|
+
} = $props();
|
|
14
|
+
|
|
15
|
+
const streamdown = useStreamdown();
|
|
16
|
+
const showLineNumbers = $derived(streamdown.lineNumbers !== false);
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div
|
|
20
|
+
data-streamdown-code={id}
|
|
21
|
+
data-incomplete={isIncomplete || undefined}
|
|
22
|
+
style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
|
|
23
|
+
class={streamdown.theme.code.base}
|
|
24
|
+
>
|
|
25
|
+
<div class={streamdown.theme.code.header}>
|
|
26
|
+
<span class={streamdown.theme.code.language}>{token.lang}</span>
|
|
27
|
+
</div>
|
|
28
|
+
<div style="height: fit-content; width: 100%;" class={streamdown.theme.code.container}>
|
|
29
|
+
<pre class={streamdown.theme.code.pre}><code
|
|
30
|
+
class="block"
|
|
31
|
+
class:sd-line-numbers={showLineNumbers}
|
|
32
|
+
data-streamdown-line-numbers={showLineNumbers}
|
|
33
|
+
>{#each token.text.split('\n') as line}<span
|
|
34
|
+
class={`sd-code-line ${streamdown.theme.code.line}`}
|
|
35
|
+
><span style={streamdown.isMounted ? streamdown.animationTextStyle : ''}
|
|
36
|
+
>{line.trim().length > 0 ? line : '\u200B'}</span
|
|
37
|
+
></span
|
|
38
|
+
>{/each}</code
|
|
39
|
+
></pre>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Tokens } from 'marked';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
token: Tokens.Code;
|
|
4
|
+
id: string;
|
|
5
|
+
isIncomplete?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const CodeFallback: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type CodeFallback = ReturnType<typeof CodeFallback>;
|
|
9
|
+
export default CodeFallback;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown } from '../../context.svelte.js';
|
|
3
|
+
import type { MathToken } from '../../marked/index.js';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
token,
|
|
7
|
+
id
|
|
8
|
+
}: {
|
|
9
|
+
token: MathToken;
|
|
10
|
+
id: string;
|
|
11
|
+
} = $props();
|
|
12
|
+
|
|
13
|
+
const streamdown = useStreamdown();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
{#if token.isInline}
|
|
17
|
+
<span
|
|
18
|
+
data-streamdown-inline-math={id}
|
|
19
|
+
style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
|
|
20
|
+
class={streamdown.theme.math.inline}
|
|
21
|
+
>
|
|
22
|
+
<code>{token.text}</code>
|
|
23
|
+
</span>
|
|
24
|
+
{:else}
|
|
25
|
+
<div
|
|
26
|
+
data-streamdown-block-math={id}
|
|
27
|
+
style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
|
|
28
|
+
style:height="fit-content"
|
|
29
|
+
style:width="100%"
|
|
30
|
+
>
|
|
31
|
+
<div class="overflow-x-auto">
|
|
32
|
+
<pre class={streamdown.theme.math.block}><code>{token.text}</code></pre>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
{/if}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MathToken } from '../../marked/index.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
token: MathToken;
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
declare const MathFallback: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type MathFallback = ReturnType<typeof MathFallback>;
|
|
8
|
+
export default MathFallback;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown } from '../../context.svelte.js';
|
|
3
|
+
import type { Tokens } from 'marked';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
token,
|
|
7
|
+
id,
|
|
8
|
+
isIncomplete = false
|
|
9
|
+
}: {
|
|
10
|
+
token: Tokens.Code;
|
|
11
|
+
id: string;
|
|
12
|
+
isIncomplete?: boolean;
|
|
13
|
+
} = $props();
|
|
14
|
+
|
|
15
|
+
const streamdown = useStreamdown();
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<div data-streamdown-mermaid={id} data-incomplete={isIncomplete || undefined}>
|
|
19
|
+
<div
|
|
20
|
+
style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
|
|
21
|
+
class={streamdown.theme.code.base}
|
|
22
|
+
>
|
|
23
|
+
<div class={streamdown.theme.code.header}>
|
|
24
|
+
<span class={streamdown.theme.code.language}>mermaid</span>
|
|
25
|
+
</div>
|
|
26
|
+
<div style="height: fit-content; width: 100%;" class={streamdown.theme.code.container}>
|
|
27
|
+
<pre class={streamdown.theme.code.pre}><code
|
|
28
|
+
>{#each token.text.split('\n') as line}<span class={streamdown.theme.code.line}
|
|
29
|
+
><span style={streamdown.isMounted ? streamdown.animationTextStyle : ''}
|
|
30
|
+
>{line.trim().length > 0 ? line : '\u200B'}</span
|
|
31
|
+
></span
|
|
32
|
+
>{/each}</code
|
|
33
|
+
></pre>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Tokens } from 'marked';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
token: Tokens.Code;
|
|
4
|
+
id: string;
|
|
5
|
+
isIncomplete?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const MermaidFallback: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type MermaidFallback = ReturnType<typeof MermaidFallback>;
|
|
9
|
+
export default MermaidFallback;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { IconMap } from '../context.svelte.js';
|
|
3
|
+
export type IconSnippet = Snippet<[]>;
|
|
4
|
+
export declare const copyIcon: IconSnippet;
|
|
5
|
+
export declare const downloadIcon: IconSnippet;
|
|
6
|
+
export declare const checkIcon: IconSnippet;
|
|
7
|
+
export declare const zoomInIcon: IconSnippet;
|
|
8
|
+
export declare const zoomOutIcon: IconSnippet;
|
|
9
|
+
export declare const fitViewIcon: IconSnippet;
|
|
10
|
+
export declare const fullscreenIcon: IconSnippet;
|
|
11
|
+
export declare const chevronRight: IconSnippet;
|
|
12
|
+
export declare const chevronLeft: IconSnippet;
|
|
13
|
+
declare const iconAliases: {
|
|
14
|
+
readonly check: readonly ["check", "CheckIcon"];
|
|
15
|
+
readonly copy: readonly ["copy", "CopyIcon"];
|
|
16
|
+
readonly download: readonly ["download", "DownloadIcon"];
|
|
17
|
+
readonly fullscreen: readonly ["fullscreen", "Maximize2Icon", "XIcon"];
|
|
18
|
+
readonly zoomIn: readonly ["zoomIn", "ZoomInIcon"];
|
|
19
|
+
readonly zoomOut: readonly ["zoomOut", "ZoomOutIcon"];
|
|
20
|
+
readonly fitView: readonly ["fitView", "RotateCcwIcon"];
|
|
21
|
+
readonly note: readonly ["note"];
|
|
22
|
+
readonly tip: readonly ["tip"];
|
|
23
|
+
readonly warning: readonly ["warning"];
|
|
24
|
+
readonly caution: readonly ["caution"];
|
|
25
|
+
readonly important: readonly ["important"];
|
|
26
|
+
readonly chevronLeft: readonly ["chevronLeft"];
|
|
27
|
+
readonly chevronRight: readonly ["chevronRight"];
|
|
28
|
+
};
|
|
29
|
+
export type ResolvedIconName = keyof typeof iconAliases;
|
|
30
|
+
export declare const resolveIcon: (icons: Partial<IconMap> | undefined, name: ResolvedIconName, fallback: IconSnippet) => IconSnippet;
|
|
31
|
+
export {};
|