@aleph-alpha/chat-kit 2.1.1 → 2.3.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/dist/{CkInput.vue_vue_type_script_setup_true_lang-DPZedAQS.js → CkInput.vue_vue_type_script_setup_true_lang-DYTizPsB.js} +361 -72
- package/dist/chat-kit.css +40 -5
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneIllustration.vue.d.ts +4 -0
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneIllustration.vue.d.ts.map +1 -0
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneOverlay.stories.d.ts +17 -0
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneOverlay.stories.d.ts.map +1 -0
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneOverlay.vue.d.ts +31 -0
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneOverlay.vue.d.ts.map +1 -0
- package/dist/components/base/CkDropZoneOverlay/index.d.ts +3 -0
- package/dist/components/base/CkDropZoneOverlay/index.d.ts.map +1 -0
- package/dist/components/base/CkDropZoneOverlay/types.d.ts +88 -0
- package/dist/components/base/CkDropZoneOverlay/types.d.ts.map +1 -0
- package/dist/components/base/CkFeedbackDialog/CkFeedbackDialog.vue.d.ts.map +1 -1
- package/dist/components/base/CkFileItemsList/CkFileItemsList.stories.d.ts +7 -0
- package/dist/components/base/CkFileItemsList/CkFileItemsList.stories.d.ts.map +1 -1
- package/dist/components/base/CkFileItemsList/CkFileItemsList.vue.d.ts +1 -0
- package/dist/components/base/CkFileItemsList/CkFileItemsList.vue.d.ts.map +1 -1
- package/dist/components/base/CkFileItemsList/types.d.ts +9 -0
- package/dist/components/base/CkFileItemsList/types.d.ts.map +1 -1
- package/dist/components/base/index.d.ts +2 -0
- package/dist/components/base/index.d.ts.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +19 -18
- package/dist/composables/fileUpload/index.d.ts.map +1 -1
- package/dist/composables/fileUpload/types.d.ts +1 -1
- package/dist/composables/fileUpload/types.d.ts.map +1 -1
- package/dist/composables/fileUpload/useFileUpload.d.ts.map +1 -1
- package/dist/composables/index.js +1 -1
- package/dist/{index-BPXg1Yf6.js → index-THzZwfMU.js} +45 -23
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -20
- package/package.json +1 -1
- package/src/components/base/CkDropZoneOverlay/CkDropZoneIllustration.vue +125 -0
- package/src/components/base/CkDropZoneOverlay/CkDropZoneOverlay.spec.ts +104 -0
- package/src/components/base/CkDropZoneOverlay/CkDropZoneOverlay.stories.ts +130 -0
- package/src/components/base/CkDropZoneOverlay/CkDropZoneOverlay.vue +272 -0
- package/src/components/base/CkDropZoneOverlay/index.ts +2 -0
- package/src/components/base/CkDropZoneOverlay/types.ts +93 -0
- package/src/components/base/CkFeedbackDialog/CkFeedbackDialog.vue +22 -1
- package/src/components/base/CkFileItemsList/CkFileItemsList.spec.ts +67 -0
- package/src/components/base/CkFileItemsList/CkFileItemsList.stories.ts +48 -0
- package/src/components/base/CkFileItemsList/CkFileItemsList.vue +78 -4
- package/src/components/base/CkFileItemsList/types.ts +9 -0
- package/src/components/base/index.ts +7 -0
- package/src/components/index.ts +5 -0
- package/src/composables/fileUpload/index.spec.ts +18 -7
- package/src/composables/fileUpload/index.ts +39 -19
- package/src/composables/fileUpload/types.ts +1 -1
- package/src/composables/fileUpload/useFileUpload.spec.ts +26 -0
- package/src/composables/fileUpload/useFileUpload.ts +12 -3
- package/src/composables/fileUpload/useFileUploadWrapper.ts +1 -1
- package/src/index.ts +5 -0
package/dist/index.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import { u } from "./useMessageHandler-CMdy-lm0.js";
|
|
2
2
|
import { C, d, p, u as u2, a } from "./useChatKitLabels-ZutacPad.js";
|
|
3
|
-
import { S, c, d as d2, a as a2, u as u3, b, e, f } from "./index-
|
|
4
|
-
import { _, a as a3, b as b2, C as C2, c as c2, d as d3, e as e2, f as f2, g, h, i, j, k, l, m, n, o, p as p2, q, r, s, t } from "./CkInput.vue_vue_type_script_setup_true_lang-
|
|
3
|
+
import { S, c, d as d2, a as a2, u as u3, b, e, f } from "./index-THzZwfMU.js";
|
|
4
|
+
import { _, a as a3, b as b2, C as C2, c as c2, d as d3, e as e2, f as f2, g, h, i, j, k, l, m, n, o, p as p2, q, r, s, t, u as u4 } from "./CkInput.vue_vue_type_script_setup_true_lang-DYTizPsB.js";
|
|
5
5
|
export {
|
|
6
6
|
C as CHAT_KIT_LABELS,
|
|
7
7
|
_ as CkAgentMessage,
|
|
8
8
|
a3 as CkConversation,
|
|
9
9
|
b2 as CkConversationLayout,
|
|
10
10
|
C2 as CkCopyMessageActionButton,
|
|
11
|
-
c2 as
|
|
12
|
-
d3 as
|
|
13
|
-
e2 as
|
|
14
|
-
f2 as
|
|
15
|
-
g as
|
|
16
|
-
h as
|
|
17
|
-
i as
|
|
18
|
-
j as
|
|
19
|
-
k as
|
|
20
|
-
l as
|
|
21
|
-
m as
|
|
22
|
-
n as
|
|
23
|
-
o as
|
|
24
|
-
p2 as
|
|
25
|
-
q as
|
|
26
|
-
r as
|
|
27
|
-
s as
|
|
11
|
+
c2 as CkDropZoneOverlay,
|
|
12
|
+
d3 as CkFeedbackButton,
|
|
13
|
+
e2 as CkFeedbackDialog,
|
|
14
|
+
f2 as CkFileItemsList,
|
|
15
|
+
g as CkHistory,
|
|
16
|
+
h as CkHistoryItem,
|
|
17
|
+
i as CkHistoryWrapper,
|
|
18
|
+
j as CkInput,
|
|
19
|
+
k as CkMarkdownRenderer,
|
|
20
|
+
l as CkMessageActionButton,
|
|
21
|
+
m as CkModelSelector,
|
|
22
|
+
n as CkPromptActionButton,
|
|
23
|
+
o as CkPromptInput,
|
|
24
|
+
p2 as CkPromptInputDisclaimer,
|
|
25
|
+
q as CkPromptStopButton,
|
|
26
|
+
r as CkSendIcon,
|
|
27
|
+
s as CkStopIcon,
|
|
28
|
+
t as CkUserMessage,
|
|
28
29
|
S as SdkError,
|
|
29
30
|
c as createDocumentUploadProvider,
|
|
30
31
|
d as defaultChatKitLabels,
|
|
31
32
|
d2 as defaultDocumentUploadConfig,
|
|
32
33
|
a2 as defaultEndpoints,
|
|
33
|
-
|
|
34
|
+
u4 as formatRelativeTime,
|
|
34
35
|
p as provideChatKitLabels,
|
|
35
36
|
u3 as useChat,
|
|
36
37
|
u2 as useChatKitLabels,
|
package/package.json
CHANGED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineOptions({ name: 'CkDropZoneIllustration' });
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<svg
|
|
7
|
+
width="208"
|
|
8
|
+
height="144"
|
|
9
|
+
viewBox="0 0 208 144"
|
|
10
|
+
fill="none"
|
|
11
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
12
|
+
aria-hidden="true"
|
|
13
|
+
focusable="false"
|
|
14
|
+
>
|
|
15
|
+
<g clip-path="url(#ck-drop-zone-clip)">
|
|
16
|
+
<path
|
|
17
|
+
d="M0 71.5391C0 32.0292 32.0292 0 71.5391 0H135.739C175.249 0 207.278 32.0292 207.278 71.5391C207.278 111.049 175.249 143.078 135.739 143.078H71.5392C32.0292 143.078 0 111.049 0 71.5391Z"
|
|
18
|
+
fill="#F2EBE8"
|
|
19
|
+
/>
|
|
20
|
+
<path
|
|
21
|
+
d="M120.899 98.2608L134.973 45.7385C135.223 44.805 136.182 44.251 137.116 44.5011L172.976 54.1098C173.909 54.3599 174.463 55.3195 174.213 56.2531L160.14 108.775C159.89 109.709 158.93 110.263 157.997 110.013L122.137 100.404C121.203 100.154 120.649 99.1943 120.899 98.2608Z"
|
|
22
|
+
fill="#FFCCBB"
|
|
23
|
+
stroke="#333333"
|
|
24
|
+
/>
|
|
25
|
+
<g>
|
|
26
|
+
<path
|
|
27
|
+
d="M153.839 69.86L144.18 67.2718C143.118 66.9871 142.015 67.6235 141.731 68.686L137.589 84.1409C137.305 85.2034 137.941 86.3056 139.004 86.5904L150.595 89.6962C151.657 89.9809 152.76 89.3445 153.044 88.282L156.668 74.759L153.839 69.86Z"
|
|
28
|
+
stroke="#1D1D1B"
|
|
29
|
+
stroke-width="1.75"
|
|
30
|
+
stroke-linecap="round"
|
|
31
|
+
stroke-linejoin="round"
|
|
32
|
+
/>
|
|
33
|
+
<path
|
|
34
|
+
d="M153.839 69.86L153.063 72.7578C152.921 73.2891 153.239 73.8402 153.77 73.9825L156.668 74.759"
|
|
35
|
+
stroke="#1D1D1B"
|
|
36
|
+
stroke-width="1.75"
|
|
37
|
+
stroke-linecap="round"
|
|
38
|
+
stroke-linejoin="round"
|
|
39
|
+
/>
|
|
40
|
+
<path
|
|
41
|
+
d="M143.783 76.4828L151.51 78.5534"
|
|
42
|
+
stroke="#1D1D1B"
|
|
43
|
+
stroke-width="1.75"
|
|
44
|
+
stroke-linecap="round"
|
|
45
|
+
stroke-linejoin="round"
|
|
46
|
+
/>
|
|
47
|
+
<path
|
|
48
|
+
d="M143.006 79.3806L150.733 81.4511"
|
|
49
|
+
stroke="#1D1D1B"
|
|
50
|
+
stroke-width="1.75"
|
|
51
|
+
stroke-linecap="round"
|
|
52
|
+
stroke-linejoin="round"
|
|
53
|
+
/>
|
|
54
|
+
<path
|
|
55
|
+
d="M142.23 82.2784L147.059 83.5725"
|
|
56
|
+
stroke="#1D1D1B"
|
|
57
|
+
stroke-width="1.75"
|
|
58
|
+
stroke-linecap="round"
|
|
59
|
+
stroke-linejoin="round"
|
|
60
|
+
/>
|
|
61
|
+
</g>
|
|
62
|
+
<path
|
|
63
|
+
d="M86.3795 98.2608L72.3062 45.7385C72.0561 44.805 71.0965 44.251 70.1629 44.5011L34.3029 54.1098C33.3694 54.3599 32.8153 55.3195 33.0655 56.2531L47.1388 108.775C47.3889 109.709 48.3485 110.263 49.2821 110.013L85.1421 100.404C86.0756 100.154 86.6297 99.1943 86.3795 98.2608Z"
|
|
64
|
+
fill="#FFE9B5"
|
|
65
|
+
stroke="#333333"
|
|
66
|
+
/>
|
|
67
|
+
<g>
|
|
68
|
+
<path
|
|
69
|
+
d="M60.3294 76.0227L58.0001 67.3293C60.3057 66.7116 62.7623 67.035 64.8294 68.2284C66.8966 69.4219 68.405 71.3877 69.0228 73.6933L60.3294 76.0227Z"
|
|
70
|
+
stroke="#1D1D1B"
|
|
71
|
+
stroke-width="1.75"
|
|
72
|
+
stroke-linecap="round"
|
|
73
|
+
stroke-linejoin="round"
|
|
74
|
+
/>
|
|
75
|
+
<path
|
|
76
|
+
d="M55.3303 68.8899C54.4077 69.3934 53.5755 70.0573 52.8752 70.8559C51.7015 72.1942 50.9511 73.8504 50.7187 75.6152C50.4864 77.38 50.7826 79.1741 51.5699 80.7706C52.3572 82.367 53.6002 83.6942 55.1417 84.5842C56.6833 85.4742 58.4541 85.8871 60.2304 85.7707C62.0066 85.6543 63.7084 85.0138 65.1206 83.9302C66.5328 82.8465 67.5919 81.3685 68.1641 79.6829C68.5135 78.6536 68.6717 77.5751 68.6371 76.4998"
|
|
77
|
+
stroke="#1D1D1B"
|
|
78
|
+
stroke-width="1.75"
|
|
79
|
+
stroke-linecap="round"
|
|
80
|
+
stroke-linejoin="round"
|
|
81
|
+
/>
|
|
82
|
+
</g>
|
|
83
|
+
<path
|
|
84
|
+
d="M76.5186 107.5L76.5185 35C76.5185 33.6193 77.6378 32.5 79.0185 32.5H128.519C129.899 32.5 131.019 33.6193 131.019 35V107.5C131.019 108.881 129.899 110 128.519 110H79.0186C77.6378 110 76.5186 108.881 76.5186 107.5Z"
|
|
85
|
+
fill="#FFB3DD"
|
|
86
|
+
stroke="#333333"
|
|
87
|
+
/>
|
|
88
|
+
<g>
|
|
89
|
+
<path
|
|
90
|
+
d="M107.519 56.8335H95.519C94.419 56.8335 93.519 57.7335 93.519 58.8335V82.1665C93.519 83.2675 94.419 84.1665 95.519 84.1665H111.519C112.619 84.1665 113.519 83.2675 113.519 82.1665V64.8335L107.519 56.8335Z"
|
|
91
|
+
stroke="#1D1D1B"
|
|
92
|
+
stroke-width="1.75"
|
|
93
|
+
stroke-linecap="round"
|
|
94
|
+
stroke-linejoin="round"
|
|
95
|
+
/>
|
|
96
|
+
<path
|
|
97
|
+
d="M107.519 56.8335V62.8335C107.519 63.9335 108.419 64.8335 109.519 64.8335H113.519"
|
|
98
|
+
stroke="#1D1D1B"
|
|
99
|
+
stroke-width="1.75"
|
|
100
|
+
stroke-linecap="round"
|
|
101
|
+
stroke-linejoin="round"
|
|
102
|
+
/>
|
|
103
|
+
<path
|
|
104
|
+
d="M103.519 78.8335V70.8335"
|
|
105
|
+
stroke="#1D1D1B"
|
|
106
|
+
stroke-width="1.75"
|
|
107
|
+
stroke-linecap="round"
|
|
108
|
+
stroke-linejoin="round"
|
|
109
|
+
/>
|
|
110
|
+
<path
|
|
111
|
+
d="M99.519 74.8335L103.519 70.8335L107.519 74.8335"
|
|
112
|
+
stroke="#1D1D1B"
|
|
113
|
+
stroke-width="1.75"
|
|
114
|
+
stroke-linecap="round"
|
|
115
|
+
stroke-linejoin="round"
|
|
116
|
+
/>
|
|
117
|
+
</g>
|
|
118
|
+
</g>
|
|
119
|
+
<defs>
|
|
120
|
+
<clipPath id="ck-drop-zone-clip">
|
|
121
|
+
<rect width="208" height="144" fill="white" />
|
|
122
|
+
</clipPath>
|
|
123
|
+
</defs>
|
|
124
|
+
</svg>
|
|
125
|
+
</template>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
3
|
+
import { nextTick } from 'vue';
|
|
4
|
+
import CkDropZoneOverlay from './CkDropZoneOverlay.vue';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* jsdom has no real `DataTransfer`/`DragEvent`, so we fake the minimal surface
|
|
8
|
+
* the component reads: `dataTransfer.types` (drag detection) and
|
|
9
|
+
* `dataTransfer.files` (the drop payload).
|
|
10
|
+
*/
|
|
11
|
+
function fileDragEvent(type: string, files: File[] = []): Event {
|
|
12
|
+
const event = new Event(type, { bubbles: true, cancelable: true });
|
|
13
|
+
Object.defineProperty(event, 'dataTransfer', {
|
|
14
|
+
value: { types: ['Files'], files },
|
|
15
|
+
});
|
|
16
|
+
return event;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const overlay = () =>
|
|
20
|
+
document.querySelector<HTMLElement>('[data-slot="drop-zone-overlay"]');
|
|
21
|
+
const errorToast = () =>
|
|
22
|
+
document.querySelector<HTMLElement>('[data-slot="drop-zone-errors"]');
|
|
23
|
+
|
|
24
|
+
async function enterDrag() {
|
|
25
|
+
window.dispatchEvent(fileDragEvent('dragenter'));
|
|
26
|
+
await nextTick();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
// Reset window drag state between tests in case a drop didn't fire.
|
|
31
|
+
window.dispatchEvent(fileDragEvent('drop'));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('CkDropZoneOverlay', () => {
|
|
35
|
+
it('is hidden until a file drag enters the window', async () => {
|
|
36
|
+
render(CkDropZoneOverlay);
|
|
37
|
+
expect(overlay()).toBeNull();
|
|
38
|
+
|
|
39
|
+
await enterDrag();
|
|
40
|
+
expect(overlay()).not.toBeNull();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('stays hidden while disabled', async () => {
|
|
44
|
+
render(CkDropZoneOverlay, { props: { disabled: true } });
|
|
45
|
+
await enterDrag();
|
|
46
|
+
expect(overlay()).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('emits accepted files on drop', async () => {
|
|
50
|
+
const { emitted } = render(CkDropZoneOverlay);
|
|
51
|
+
await enterDrag();
|
|
52
|
+
|
|
53
|
+
const file = new File(['hello'], 'report.pdf', { type: 'application/pdf' });
|
|
54
|
+
overlay()!.dispatchEvent(fileDragEvent('drop', [file]));
|
|
55
|
+
await nextTick();
|
|
56
|
+
|
|
57
|
+
expect(emitted('files')).toEqual([[[file]]]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('rejects files that do not match `accept`', async () => {
|
|
61
|
+
const { emitted } = render(CkDropZoneOverlay, {
|
|
62
|
+
props: { accept: '.pdf' },
|
|
63
|
+
});
|
|
64
|
+
await enterDrag();
|
|
65
|
+
|
|
66
|
+
const file = new File(['x'], 'image.png', { type: 'image/png' });
|
|
67
|
+
overlay()!.dispatchEvent(fileDragEvent('drop', [file]));
|
|
68
|
+
await nextTick();
|
|
69
|
+
|
|
70
|
+
expect(emitted('files')).toBeUndefined();
|
|
71
|
+
const rejected = emitted('rejected') as unknown[][] | undefined;
|
|
72
|
+
expect(rejected).toBeTruthy();
|
|
73
|
+
expect(rejected![0][0]).toMatchObject([{ reason: 'unsupported-type' }]);
|
|
74
|
+
expect(errorToast()).not.toBeNull();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('caps the drop to `maxFiles` and reports the overflow', async () => {
|
|
78
|
+
const { emitted } = render(CkDropZoneOverlay, { props: { maxFiles: 1 } });
|
|
79
|
+
await enterDrag();
|
|
80
|
+
|
|
81
|
+
const a = new File(['a'], 'a.txt', { type: 'text/plain' });
|
|
82
|
+
const b = new File(['b'], 'b.txt', { type: 'text/plain' });
|
|
83
|
+
overlay()!.dispatchEvent(fileDragEvent('drop', [a, b]));
|
|
84
|
+
await nextTick();
|
|
85
|
+
|
|
86
|
+
expect(emitted('files')).toEqual([[[a]]]);
|
|
87
|
+
const rejected = emitted('rejected') as unknown[][];
|
|
88
|
+
expect(rejected[0][0]).toMatchObject([{ reason: 'too-many' }]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('suppresses the built-in toast when showErrors is false', async () => {
|
|
92
|
+
const { emitted } = render(CkDropZoneOverlay, {
|
|
93
|
+
props: { accept: '.pdf', showErrors: false },
|
|
94
|
+
});
|
|
95
|
+
await enterDrag();
|
|
96
|
+
|
|
97
|
+
const file = new File(['x'], 'image.png', { type: 'image/png' });
|
|
98
|
+
overlay()!.dispatchEvent(fileDragEvent('drop', [file]));
|
|
99
|
+
await nextTick();
|
|
100
|
+
|
|
101
|
+
expect(emitted('rejected')).toBeTruthy();
|
|
102
|
+
expect(errorToast()).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import CkDropZoneOverlay from './CkDropZoneOverlay.vue';
|
|
4
|
+
import type { CkDropZoneRejection } from './types';
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof CkDropZoneOverlay> = {
|
|
7
|
+
title: 'Base/CkDropZoneOverlay',
|
|
8
|
+
component: CkDropZoneOverlay,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
docs: {
|
|
13
|
+
description: {
|
|
14
|
+
component:
|
|
15
|
+
'Full-window drag-and-drop overlay. It listens for file drags anywhere on the page, reveals a teleported overlay, validates dropped files against `accept`, `maxFileSizeBytes` and `maxFiles`, then emits the accepted files. Drag a real file from your desktop onto the canvas to see it, or use the "Simulate drag" button to preview the overlay.',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
argTypes: {
|
|
20
|
+
accept: { control: 'text' },
|
|
21
|
+
maxFiles: { control: { type: 'number', min: 1, max: 20, step: 1 } },
|
|
22
|
+
disabled: { control: 'boolean' },
|
|
23
|
+
heading: { control: 'text' },
|
|
24
|
+
hint: { control: 'text' },
|
|
25
|
+
showErrors: { control: 'boolean' },
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default meta;
|
|
30
|
+
|
|
31
|
+
type Story = StoryObj<typeof CkDropZoneOverlay>;
|
|
32
|
+
|
|
33
|
+
const usageSource = `<script setup lang="ts">
|
|
34
|
+
import { CkDropZoneOverlay } from '@aleph-alpha/chat-kit';
|
|
35
|
+
|
|
36
|
+
const MAX_FILES = 10;
|
|
37
|
+
const isStreaming = false;
|
|
38
|
+
|
|
39
|
+
function onFiles(files: File[]) {
|
|
40
|
+
// hand off to your upload pipeline
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<CkDropZoneOverlay
|
|
46
|
+
:accept="'.txt,.docx,.pdf,.md,.csv'"
|
|
47
|
+
:max-files="MAX_FILES"
|
|
48
|
+
:disabled="isStreaming"
|
|
49
|
+
hint="Add txt, docx, pdf, md, or csv"
|
|
50
|
+
@files="onFiles"
|
|
51
|
+
/>
|
|
52
|
+
</template>`;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The overlay is invisible until a file drag enters the window. The "Simulate
|
|
56
|
+
* drag" button dispatches a synthetic `dragenter` so you can preview the
|
|
57
|
+
* overlay without an OS-level drag; dropping a real file emits `files`.
|
|
58
|
+
*/
|
|
59
|
+
export const Default: Story = {
|
|
60
|
+
args: {
|
|
61
|
+
accept: '.txt,.docx,.pdf,.md,.csv',
|
|
62
|
+
maxFiles: 10,
|
|
63
|
+
hint: 'Add txt, docx, pdf, md, or csv',
|
|
64
|
+
},
|
|
65
|
+
render: (args) => ({
|
|
66
|
+
components: { CkDropZoneOverlay },
|
|
67
|
+
setup() {
|
|
68
|
+
const lastFiles = ref<string[]>([]);
|
|
69
|
+
const lastRejections = ref<string[]>([]);
|
|
70
|
+
function simulateDrag() {
|
|
71
|
+
const event = new Event('dragenter', { bubbles: true });
|
|
72
|
+
Object.defineProperty(event, 'dataTransfer', {
|
|
73
|
+
value: { types: ['Files'], files: [] },
|
|
74
|
+
});
|
|
75
|
+
window.dispatchEvent(event);
|
|
76
|
+
}
|
|
77
|
+
function onFiles(files: File[]) {
|
|
78
|
+
lastFiles.value = files.map((f) => f.name);
|
|
79
|
+
}
|
|
80
|
+
function onRejected(rejections: CkDropZoneRejection[]) {
|
|
81
|
+
lastRejections.value = rejections.map((r) => r.message);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
args,
|
|
85
|
+
lastFiles,
|
|
86
|
+
lastRejections,
|
|
87
|
+
simulateDrag,
|
|
88
|
+
onFiles,
|
|
89
|
+
onRejected,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
template: `
|
|
93
|
+
<div class="min-h-[60vh] bg-background-surface-primary p-8 text-content-on-surface-primary">
|
|
94
|
+
<button
|
|
95
|
+
type="button"
|
|
96
|
+
class="rounded-lg bg-background-surface-secondary px-4 py-2 body-14-medium"
|
|
97
|
+
@click="simulateDrag"
|
|
98
|
+
>
|
|
99
|
+
Simulate drag
|
|
100
|
+
</button>
|
|
101
|
+
<p class="label-12-regular mt-4 text-content-on-surface-muted">
|
|
102
|
+
Last accepted: {{ lastFiles.length ? lastFiles.join(', ') : '—' }}
|
|
103
|
+
</p>
|
|
104
|
+
<p class="label-12-regular mt-1 text-content-on-surface-muted">
|
|
105
|
+
Last rejected: {{ lastRejections.length ? lastRejections.join(' · ') : '—' }}
|
|
106
|
+
</p>
|
|
107
|
+
<CkDropZoneOverlay
|
|
108
|
+
v-bind="args"
|
|
109
|
+
@files="onFiles"
|
|
110
|
+
@rejected="onRejected"
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
`,
|
|
114
|
+
}),
|
|
115
|
+
parameters: { docs: { source: { code: usageSource } } },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A single-file zone (`maxFiles="1"`) switches the default heading to its
|
|
120
|
+
* singular form and rejects extra files with a `too-many` reason.
|
|
121
|
+
*/
|
|
122
|
+
export const SingleFile: Story = {
|
|
123
|
+
args: {
|
|
124
|
+
maxFiles: 1,
|
|
125
|
+
accept: '.pdf',
|
|
126
|
+
hint: 'Add a pdf',
|
|
127
|
+
},
|
|
128
|
+
render: Default.render,
|
|
129
|
+
parameters: { docs: { source: { code: usageSource } } },
|
|
130
|
+
};
|