@aleph-alpha/chat-kit 5.12.0 → 5.13.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/{CkHistory.vue_vue_type_script_setup_true_lang-CImSzLYs.js → CkHistory.vue_vue_type_script_setup_true_lang-BNcJURkq.js} +105 -20
- package/dist/chat-kit.css +2 -2
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts +1 -4
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts.map +1 -1
- package/dist/components/base/CkCitation/CkCitation.vue.d.ts.map +1 -1
- package/dist/components/base/CkCitation/types.d.ts +6 -1
- package/dist/components/base/CkCitation/types.d.ts.map +1 -1
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts +13 -2
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts.map +1 -1
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts +1 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts.map +1 -1
- package/dist/components/base/CkCitationCard/types.d.ts +6 -1
- package/dist/components/base/CkCitationCard/types.d.ts.map +1 -1
- package/dist/components/base/CkCitationLabel/CkCitationLabel.vue.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/composables/useIsTruncated.d.ts +22 -0
- package/dist/composables/useIsTruncated.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/components/base/CkCitation/CkCitation.spec.ts +3 -3
- package/src/components/base/CkCitation/CkCitation.stories.ts +85 -3
- package/src/components/base/CkCitation/CkCitation.vue +5 -1
- package/src/components/base/CkCitation/types.ts +6 -1
- package/src/components/base/CkCitationCard/CkCitationCard.spec.ts +37 -0
- package/src/components/base/CkCitationCard/CkCitationCard.stories.ts +30 -3
- package/src/components/base/CkCitationCard/CkCitationCard.vue +53 -11
- package/src/components/base/CkCitationCard/types.ts +6 -1
- package/src/components/base/CkCitationLabel/CkCitationLabel.spec.ts +3 -3
- package/src/components/base/CkCitationLabel/CkCitationLabel.vue +6 -5
- package/src/components/base/CkFeedbackDialog/CkFeedbackDialog.spec.ts +1 -1
- package/src/composables/useIsTruncated.ts +82 -0
|
@@ -257,7 +257,7 @@ describe('CkFeedbackDialog', () => {
|
|
|
257
257
|
const marker = document.body.querySelector('.ck-citation')!;
|
|
258
258
|
expect(marker.tagName).toBe('SPAN');
|
|
259
259
|
expect(marker).toHaveTextContent('1');
|
|
260
|
-
expect(marker.className).toContain('bg-background-
|
|
260
|
+
expect(marker.className).toContain('bg-background-surface-citation');
|
|
261
261
|
// Announced as its own labelled object, and never as a control.
|
|
262
262
|
expect(screen.getByRole('img', { name: 'Source 1' })).toBeInTheDocument();
|
|
263
263
|
expect(
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local copy of ui-library's internal probe of the same name. chat-kit's
|
|
3
|
+
* supported ui-library range (^5.3.0) does not export it, and it is too small
|
|
4
|
+
* to justify widening that package's public API. Drop this file once the range
|
|
5
|
+
* moves up to a version that exports it.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { onScopeDispose, ref, watch, type Ref, type ShallowRef } from 'vue';
|
|
9
|
+
|
|
10
|
+
/** An element ref as produced by `useTemplateRef`. */
|
|
11
|
+
type ElementRef = Readonly<ShallowRef<HTMLElement | null>>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One observer for every caller. `ResizeObserver` is built to watch many
|
|
15
|
+
* targets and delivers them in a single batched callback, so a list of rows
|
|
16
|
+
* costs one callback and one layout pass rather than one per row. Created
|
|
17
|
+
* lazily so importing this module never touches the DOM.
|
|
18
|
+
*/
|
|
19
|
+
const measurers = new WeakMap<Element, () => void>();
|
|
20
|
+
let sharedObserver: ResizeObserver | undefined;
|
|
21
|
+
|
|
22
|
+
function getSharedObserver(): ResizeObserver | undefined {
|
|
23
|
+
if (typeof ResizeObserver === 'undefined') return undefined;
|
|
24
|
+
sharedObserver ??= new ResizeObserver((entries) => {
|
|
25
|
+
for (const entry of entries) measurers.get(entry.target)?.();
|
|
26
|
+
});
|
|
27
|
+
return sharedObserver;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function watchElement(el: Element, measure: () => void): void {
|
|
31
|
+
measurers.set(el, measure);
|
|
32
|
+
getSharedObserver()?.observe(el);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function unwatchElement(el: Element): void {
|
|
36
|
+
measurers.delete(el);
|
|
37
|
+
getSharedObserver()?.unobserve(el);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Whether an element's text is currently clipped by `text-overflow: ellipsis`.
|
|
42
|
+
*
|
|
43
|
+
* Re-measures when the element resizes and whenever `watchSource` changes, so
|
|
44
|
+
* it stays correct as the container narrows or the text is swapped out. Use it
|
|
45
|
+
* to show a tooltip only for names that are actually cut off.
|
|
46
|
+
* @param elementRef - The element whose text may be clipped
|
|
47
|
+
* @param watchSource - Value to re-measure on, e.g. the rendered text
|
|
48
|
+
* @returns Reactive truncation state
|
|
49
|
+
*/
|
|
50
|
+
export function useIsTruncated(
|
|
51
|
+
elementRef: ElementRef,
|
|
52
|
+
watchSource?: () => unknown,
|
|
53
|
+
): Ref<boolean> {
|
|
54
|
+
const isTruncated = ref(false);
|
|
55
|
+
|
|
56
|
+
function measure(): void {
|
|
57
|
+
const el = elementRef.value;
|
|
58
|
+
// Sub-pixel widths round differently per browser, so require a whole
|
|
59
|
+
// pixel of overflow before calling it truncated.
|
|
60
|
+
isTruncated.value = el ? el.scrollWidth - el.clientWidth >= 1 : false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A resize alone doesn't cover a text swap that keeps the box the same size.
|
|
64
|
+
if (watchSource) watch(watchSource, measure, { flush: 'post' });
|
|
65
|
+
|
|
66
|
+
// Runs on mount too, when the template ref goes null -> element.
|
|
67
|
+
watch(
|
|
68
|
+
elementRef,
|
|
69
|
+
(el, previous) => {
|
|
70
|
+
if (previous) unwatchElement(previous);
|
|
71
|
+
if (el) watchElement(el, measure);
|
|
72
|
+
measure();
|
|
73
|
+
},
|
|
74
|
+
{ immediate: true, flush: 'post' },
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
onScopeDispose(() => {
|
|
78
|
+
if (elementRef.value) unwatchElement(elementRef.value);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return isTruncated;
|
|
82
|
+
}
|