markstream-svelte 2.0.17 → 2.0.19
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { CodeBlockOptions, CodeBlockTheme, CodeBlockThemeProp, CodeBlockThemes } from '../types/codeBlock'
|
|
3
|
-
import type { SvelteRenderableNode, SvelteRenderContext } from './shared/node-helpers'
|
|
3
|
+
import type { NodeRendererCodeBlockProps, SvelteRenderableNode, SvelteRenderContext } from './shared/node-helpers'
|
|
4
4
|
import { onDestroy, onMount, tick } from 'svelte'
|
|
5
5
|
import { useSafeI18n } from '../i18n/useSafeI18n'
|
|
6
6
|
import { getStreamDiffsRuntime } from '../optional/streamDiffs'
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
loading?: boolean | undefined
|
|
19
19
|
stream?: boolean | undefined
|
|
20
20
|
codeBlockOptions?: CodeBlockOptions | undefined
|
|
21
|
+
clipboardWriter?: NodeRendererCodeBlockProps['clipboardWriter']
|
|
21
22
|
theme?: CodeBlockThemeProp | undefined
|
|
22
23
|
darkTheme?: CodeBlockTheme | undefined
|
|
23
24
|
lightTheme?: CodeBlockTheme | undefined
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
loading = undefined,
|
|
45
46
|
stream = undefined,
|
|
46
47
|
codeBlockOptions = undefined,
|
|
48
|
+
clipboardWriter = undefined,
|
|
47
49
|
theme = undefined,
|
|
48
50
|
darkTheme = undefined,
|
|
49
51
|
lightTheme = undefined,
|
|
@@ -1048,8 +1050,20 @@ ${configuredUnsafeCSS}`.trim(),
|
|
|
1048
1050
|
}
|
|
1049
1051
|
|
|
1050
1052
|
async function copy() {
|
|
1051
|
-
|
|
1052
|
-
context?.
|
|
1053
|
+
const text = code
|
|
1054
|
+
const writer = clipboardWriter ?? context?.codeBlockProps?.clipboardWriter
|
|
1055
|
+
if (writer) {
|
|
1056
|
+
try {
|
|
1057
|
+
await writer(text)
|
|
1058
|
+
}
|
|
1059
|
+
catch {
|
|
1060
|
+
return
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
await copyTextToClipboard(text)
|
|
1065
|
+
}
|
|
1066
|
+
context?.events?.onCopy?.(text)
|
|
1053
1067
|
copied = true
|
|
1054
1068
|
if (copyTimer)
|
|
1055
1069
|
clearTimeout(copyTimer)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CodeBlockOptions, CodeBlockTheme, CodeBlockThemeProp, CodeBlockThemes } from '../types/codeBlock';
|
|
2
|
-
import type { SvelteRenderableNode, SvelteRenderContext } from './shared/node-helpers';
|
|
2
|
+
import type { NodeRendererCodeBlockProps, SvelteRenderableNode, SvelteRenderContext } from './shared/node-helpers';
|
|
3
3
|
type Props = {
|
|
4
4
|
node: SvelteRenderableNode;
|
|
5
5
|
context?: SvelteRenderContext | undefined;
|
|
@@ -7,6 +7,7 @@ type Props = {
|
|
|
7
7
|
loading?: boolean | undefined;
|
|
8
8
|
stream?: boolean | undefined;
|
|
9
9
|
codeBlockOptions?: CodeBlockOptions | undefined;
|
|
10
|
+
clipboardWriter?: NodeRendererCodeBlockProps['clipboardWriter'];
|
|
10
11
|
theme?: CodeBlockThemeProp | undefined;
|
|
11
12
|
darkTheme?: CodeBlockTheme | undefined;
|
|
12
13
|
lightTheme?: CodeBlockTheme | undefined;
|
|
@@ -746,6 +746,7 @@ function decodeDataPayload(value) {
|
|
|
746
746
|
return '';
|
|
747
747
|
}
|
|
748
748
|
function createEnhancedBlockShell(kind, label, source, showSourceDetails, options, shellOptions = {}) {
|
|
749
|
+
var _a;
|
|
749
750
|
const wrapper = document.createElement('div');
|
|
750
751
|
wrapper.className = `markstream-svelte-enhanced-block markstream-svelte-enhanced-block--${kind}`;
|
|
751
752
|
if (shellOptions.showHeader !== false) {
|
|
@@ -755,7 +756,7 @@ function createEnhancedBlockShell(kind, label, source, showSourceDetails, option
|
|
|
755
756
|
badge.className = 'markstream-svelte-enhanced-block__badge';
|
|
756
757
|
badge.textContent = label;
|
|
757
758
|
header.appendChild(badge);
|
|
758
|
-
header.appendChild(createHeaderActions(source, options));
|
|
759
|
+
header.appendChild(createHeaderActions(source, options, kind === 'code' ? (_a = options.codeBlockProps) === null || _a === void 0 ? void 0 : _a.clipboardWriter : undefined));
|
|
759
760
|
wrapper.appendChild(header);
|
|
760
761
|
}
|
|
761
762
|
const body = document.createElement('div');
|
|
@@ -777,7 +778,7 @@ function createEnhancedBlockShell(kind, label, source, showSourceDetails, option
|
|
|
777
778
|
}
|
|
778
779
|
return { wrapper, body };
|
|
779
780
|
}
|
|
780
|
-
function createHeaderActions(source, options) {
|
|
781
|
+
function createHeaderActions(source, options, clipboardWriter) {
|
|
781
782
|
const actions = document.createElement('div');
|
|
782
783
|
actions.className = 'markstream-svelte-enhanced-block__actions';
|
|
783
784
|
const copyButton = document.createElement('button');
|
|
@@ -786,9 +787,19 @@ function createHeaderActions(source, options) {
|
|
|
786
787
|
copyButton.textContent = 'Copy';
|
|
787
788
|
if (options.showTooltips !== false)
|
|
788
789
|
copyButton.title = 'Copy source';
|
|
789
|
-
copyButton.addEventListener('click', () => {
|
|
790
|
+
copyButton.addEventListener('click', async () => {
|
|
790
791
|
var _a;
|
|
791
|
-
|
|
792
|
+
if (clipboardWriter) {
|
|
793
|
+
try {
|
|
794
|
+
await clipboardWriter(source);
|
|
795
|
+
}
|
|
796
|
+
catch {
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
else {
|
|
801
|
+
void copyText(source);
|
|
802
|
+
}
|
|
792
803
|
(_a = options.onCopy) === null || _a === void 0 ? void 0 : _a.call(options, source);
|
|
793
804
|
});
|
|
794
805
|
actions.appendChild(copyButton);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markstream-svelte",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.19",
|
|
5
5
|
"description": "Svelte 5 and SvelteKit streaming Markdown renderer for AI chat, LLM token streams, SSE/WebSocket output, incomplete Markdown, Mermaid, KaTeX, stream-diffs powered code blocks, and custom Svelte components.",
|
|
6
6
|
"author": "Simon He",
|
|
7
7
|
"license": "MIT",
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
},
|
|
101
101
|
"dependencies": {
|
|
102
102
|
"@floating-ui/dom": "^1.8.0",
|
|
103
|
-
"markstream-core": "2.0.
|
|
104
|
-
"stream-markdown-parser": "1.2.
|
|
103
|
+
"markstream-core": "2.0.19",
|
|
104
|
+
"stream-markdown-parser": "1.2.20"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@sveltejs/package": "^2.5.8",
|