@aleph-alpha/chat-kit 1.13.0 → 1.14.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.
@@ -1,5 +1,5 @@
1
- import { defineComponent, openBlock, createElementBlock, createElementVNode, renderSlot, createCommentVNode, ref, onMounted, nextTick, onUnmounted, watch, Fragment, renderList, normalizeStyle, createBlock, unref, mergeProps, withCtx, createVNode, Transition, toDisplayString, computed, normalizeClass, toRefs, h, useId, createTextVNode, useAttrs, useSlots, withModifiers, resolveDynamicComponent, useTemplateRef, createSlots, normalizeProps, guardReactiveProps } from "vue";
2
- import { u as useChatKitLabels, d as defaultChatKitLabels, a as useMarkdownParser } from "./useChatKitLabels-DeHxZG2a.js";
1
+ import { defineComponent, openBlock, createElementBlock, createElementVNode, renderSlot, createCommentVNode, ref, onMounted, nextTick, onUnmounted, watch, Fragment, renderList, normalizeStyle, createBlock, unref, mergeProps, withCtx, createVNode, Transition, toDisplayString, computed, normalizeClass, toRefs, h, useId, createTextVNode, useAttrs, useSlots, withModifiers, resolveDynamicComponent, useTemplateRef, onBeforeUnmount, createSlots, normalizeProps, guardReactiveProps } from "vue";
2
+ import { u as useChatKitLabels, d as defaultChatKitLabels, a as useMarkdownParser } from "./useChatKitLabels-BxNkTzr2.js";
3
3
  import { UiButton, UiTooltip, UiIcon, UiDialog, UiDialogContent, UiDialogDescription, UiFieldLabel, UiToggleGroup, UiToggleGroupItem, UiField, UiTextarea, UiFileItem, UiPopover, UiPopoverTrigger, UiFileType, UiPopoverContent, Primitive, UiAvatar, UiAvatarImage, UiSpinner, UiAvatarFallback, UiSidebarPopoverMenu, UiSidebarPopoverMenuItem } from "@aleph-alpha/ui-library";
4
4
  const _hoisted_1$b = {
5
5
  xmlns: "http://www.w3.org/2000/svg",
@@ -1453,26 +1453,78 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
1453
1453
  };
1454
1454
  }
1455
1455
  });
1456
- const _hoisted_1 = { class: "bg-background-surface-primary inline-flex max-w-[600px] flex-col items-end justify-start gap-4 rounded-xl p-6" };
1457
- const _hoisted_2 = { class: "text-content-on-surface-primary justify-start self-stretch text-base leading-6 font-normal" };
1456
+ const _hoisted_1 = { class: "inline-flex max-w-[536px] flex-col items-end justify-start gap-1" };
1457
+ const _hoisted_2 = ["aria-expanded"];
1458
1458
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1459
1459
  ...{ name: "CkUserMessage" },
1460
1460
  __name: "CkUserMessage",
1461
1461
  props: {
1462
- message: {}
1462
+ message: { default: void 0 },
1463
+ collapsedLines: { default: 0 }
1463
1464
  },
1464
1465
  setup(__props) {
1466
+ const props = __props;
1467
+ const labels = useChatKitLabels();
1468
+ const showMoreLabel = computed(
1469
+ () => labels.value.userMessageShowMore ?? defaultChatKitLabels.userMessageShowMore
1470
+ );
1471
+ const showLessLabel = computed(
1472
+ () => labels.value.userMessageShowLess ?? defaultChatKitLabels.userMessageShowLess
1473
+ );
1474
+ const clampEnabled = computed(() => (props.collapsedLines ?? 0) > 0);
1475
+ const contentRef = ref(null);
1476
+ const expanded = ref(false);
1477
+ const isOverflowing = ref(false);
1478
+ function measure() {
1479
+ const el = contentRef.value;
1480
+ if (!el || !clampEnabled.value || expanded.value) return;
1481
+ isOverflowing.value = el.scrollHeight - el.clientHeight > 1;
1482
+ }
1483
+ function toggle() {
1484
+ expanded.value = !expanded.value;
1485
+ }
1486
+ let resizeObserver;
1487
+ onMounted(() => {
1488
+ nextTick(measure);
1489
+ if (typeof ResizeObserver !== "undefined") {
1490
+ resizeObserver = new ResizeObserver(() => measure());
1491
+ if (contentRef.value) resizeObserver.observe(contentRef.value);
1492
+ }
1493
+ });
1494
+ onBeforeUnmount(() => resizeObserver?.disconnect());
1495
+ watch([() => props.message, () => props.collapsedLines], () => {
1496
+ expanded.value = false;
1497
+ nextTick(measure);
1498
+ });
1465
1499
  return (_ctx, _cache) => {
1466
1500
  return openBlock(), createElementBlock("div", _hoisted_1, [
1467
- createElementVNode("div", _hoisted_2, [
1501
+ createElementVNode("div", {
1502
+ ref_key: "contentRef",
1503
+ ref: contentRef,
1504
+ class: normalizeClass(["ck-user-message__content text-content-on-surface-muted min-w-0 max-w-full self-stretch text-lg leading-7 font-medium break-words whitespace-pre-wrap [overflow-wrap:anywhere]", {
1505
+ "ck-user-message__content--clamped": clampEnabled.value && !expanded.value,
1506
+ "ck-user-message__content--faded": clampEnabled.value && !expanded.value && isOverflowing.value
1507
+ }]),
1508
+ style: normalizeStyle(
1509
+ clampEnabled.value ? { "--ck-collapsed-lines": __props.collapsedLines } : void 0
1510
+ )
1511
+ }, [
1468
1512
  renderSlot(_ctx.$slots, "default", {}, () => [
1469
1513
  createTextVNode(toDisplayString(__props.message), 1)
1470
- ])
1471
- ])
1514
+ ], true)
1515
+ ], 6),
1516
+ clampEnabled.value && isOverflowing.value ? (openBlock(), createElementBlock("button", {
1517
+ key: 0,
1518
+ type: "button",
1519
+ "aria-expanded": expanded.value,
1520
+ class: "ck-user-message__toggle label-12-medium text-content-on-surface-primary bg-background-surface-floating focus-visible:ring-ring self-center rounded-3xl px-3 py-2 focus-visible:ring-2 focus-visible:outline-none",
1521
+ onClick: toggle
1522
+ }, toDisplayString(expanded.value ? showLessLabel.value : showMoreLabel.value), 9, _hoisted_2)) : createCommentVNode("", true)
1472
1523
  ]);
1473
1524
  };
1474
1525
  }
1475
1526
  });
1527
+ const CkUserMessage = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-c759a863"]]);
1476
1528
  const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1477
1529
  ...{ name: "CkConversation" },
1478
1530
  __name: "CkConversation",
@@ -1501,7 +1553,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1501
1553
  class: normalizeClass({ "ml-8": hasIcon.value })
1502
1554
  }, [
1503
1555
  renderSlot(_ctx.$slots, "user-message", { message }, () => [
1504
- createVNode(_sfc_main$3, null, {
1556
+ createVNode(CkUserMessage, null, {
1505
1557
  default: withCtx(() => [
1506
1558
  renderSlot(_ctx.$slots, "user-message-content", { message }, () => [
1507
1559
  createTextVNode(toDisplayString(getMessageText(message)), 1)
@@ -1815,5 +1867,5 @@ export {
1815
1867
  _sfc_main$6 as o,
1816
1868
  _sfc_main$k as p,
1817
1869
  _sfc_main$j as q,
1818
- _sfc_main$3 as r
1870
+ CkUserMessage as r
1819
1871
  };
package/dist/chat-kit.css CHANGED
@@ -41,3 +41,31 @@
41
41
  .ck-feedback-dialog__response[data-v-eaffd2d5] p:last-child {
42
42
  margin-bottom: 0;
43
43
  }
44
+
45
+ /* Floating pill per design — the inset white + soft drop shadow aren't
46
+ expressible with the design-system shadow utilities, so set them here. */
47
+ .ck-user-message__toggle[data-v-c759a863] {
48
+ box-shadow:
49
+ 0 2px 2px 0 rgba(0, 0, 0, 0.05),
50
+ 0 0 4px 0 #fff inset;
51
+ }
52
+
53
+ /* text-lg has a 1.75rem (28px) line-height; clamp height = lines × line-height. */
54
+ .ck-user-message__content--clamped[data-v-c759a863] {
55
+ max-height: calc(var(--ck-collapsed-lines) * 1.75rem);
56
+ overflow: hidden;
57
+ }
58
+
59
+ /* Fade the last visible line to low opacity. */
60
+ .ck-user-message__content--faded[data-v-c759a863] {
61
+ -webkit-mask-image: linear-gradient(
62
+ to bottom,
63
+ #000 calc(100% - 1.75rem),
64
+ transparent 100%
65
+ );
66
+ mask-image: linear-gradient(
67
+ to bottom,
68
+ #000 calc(100% - 1.75rem),
69
+ transparent 100%
70
+ );
71
+ }
@@ -22,4 +22,10 @@ export declare const MultilineMessage: Story;
22
22
  * attachments). Use when a plain string is not sufficient.
23
23
  */
24
24
  export declare const WithSlotContent: Story;
25
+ /**
26
+ * Long message clamped to 4 lines. The last visible line fades out and a
27
+ * centered "Show more" / "Show less" toggle expands and collapses the text.
28
+ * The toggle only appears when the content actually overflows the clamp.
29
+ */
30
+ export declare const Collapsible: Story;
25
31
  //# sourceMappingURL=CkUserMessage.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CkUserMessage.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/base/CkUserMessage/CkUserMessage.stories.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE3D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,aAAa,CAiBpC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAwCnC;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,KAMzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAM9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,KAU7B,CAAC"}
1
+ {"version":3,"file":"CkUserMessage.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/base/CkUserMessage/CkUserMessage.stories.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE3D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,aAAa,CAsBpC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAwDnC;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,KAMzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAM9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,KAU7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,KAMzB,CAAC"}
@@ -3,7 +3,10 @@ declare var __VLS_1: {};
3
3
  type __VLS_Slots = {} & {
4
4
  default?: (props: typeof __VLS_1) => any;
5
5
  };
6
- declare const __VLS_base: import("vue").DefineComponent<CkUserMessageProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CkUserMessageProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const __VLS_base: import("vue").DefineComponent<CkUserMessageProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CkUserMessageProps> & Readonly<{}>, {
7
+ message: string;
8
+ collapsedLines: number;
9
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
10
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
8
11
  declare const _default: typeof __VLS_export;
9
12
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"CkUserMessage.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/base/CkUserMessage/CkUserMessage.vue"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA6ClD,QAAA,IAAI,OAAO,IAAW,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAK/C,QAAA,MAAM,UAAU,gTAEd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"CkUserMessage.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/base/CkUserMessage/CkUserMessage.vue"],"names":[],"mappings":"AAwIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA2JlD,QAAA,IAAI,OAAO,IAAW,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAO/C,QAAA,MAAM,UAAU;;;6EAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -1,15 +1,24 @@
1
1
  /**
2
- * Bubble layout for a single user turn in a conversation. Renders the message
3
- * text on the right side with a tokenized background and max-width; supports
4
- * a default slot for custom inline content.
2
+ * Layout for a single user turn in a conversation. Renders the message text
3
+ * right-aligned in the muted on-surface color with a max-width; supports a
4
+ * default slot for custom inline content. When `collapsedLines` is set, long
5
+ * messages are clamped with a fade and a "Show more" / "Show less" toggle.
5
6
  *
6
7
  * @category Messages
7
- * @useCases render user message bubble, conversation turn from user, chat input preview, right-aligned message
8
- * @keywords user, message, bubble, chat, conversation, turn
8
+ * @useCases render user message, conversation turn from user, chat input preview, right-aligned message, collapsible long message
9
+ * @keywords user, message, chat, conversation, turn, collapse, show more
9
10
  * @related CkAgentMessage, CkConversation
10
11
  */
11
12
  export interface CkUserMessageProps {
12
13
  /** Text content of the user message. Rendered inside the bubble when no default slot is provided. */
13
14
  message?: string;
15
+ /**
16
+ * When greater than `0`, collapse the message to at most this many lines.
17
+ * The last visible line fades out and a "Show more" / "Show less" toggle is
18
+ * revealed only when the content actually overflows. Omit or pass `0`
19
+ * (the default) to render the full message with no clamping — preserving the
20
+ * original behavior for existing consumers.
21
+ */
22
+ collapsedLines?: number;
14
23
  }
15
24
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/base/CkUserMessage/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB;IACjC,qGAAqG;IACrG,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/base/CkUserMessage/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IACjC,qGAAqG;IACrG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -1,4 +1,4 @@
1
- import { _, a, b, C, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r } from "../CkInput.vue_vue_type_script_setup_true_lang-DCZTSiBj.js";
1
+ import { _, a, b, C, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r } from "../CkInput.vue_vue_type_script_setup_true_lang-BVZ7FG88.js";
2
2
  export {
3
3
  _ as CkAgentMessage,
4
4
  a as CkConversation,
@@ -1,5 +1,5 @@
1
1
  import { u } from "../useMessageHandler-CMdy-lm0.js";
2
- import { C, d, p, u as u2, a } from "../useChatKitLabels-DeHxZG2a.js";
2
+ import { C, d, p, u as u2, a } from "../useChatKitLabels-BxNkTzr2.js";
3
3
  export {
4
4
  C as CHAT_KIT_LABELS,
5
5
  d as defaultChatKitLabels,
@@ -63,6 +63,10 @@ export type ChatKitLabels = {
63
63
  feedbackDialogCancelLabel?: string;
64
64
  /** Submit button label in `CkFeedbackDialog`. */
65
65
  feedbackDialogSubmitLabel?: string;
66
+ /** Label for the `CkUserMessage` toggle when the message is collapsed. */
67
+ userMessageShowMore?: string;
68
+ /** Label for the `CkUserMessage` toggle when the message is expanded. */
69
+ userMessageShowLess?: string;
66
70
  /** Fallback title used by `CkHistory` when a conversation has no `title`. */
67
71
  historyItemUntitled: string;
68
72
  /** Accessible name for the trailing kebab trigger on each `CkHistory` row. */
@@ -1 +1 @@
1
- {"version":3,"file":"useChatKitLabels.d.ts","sourceRoot":"","sources":["../../src/handlers/useChatKitLabels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,0CAA0C;IAC1C,cAAc,EAAE,MAAM,CAAC;IACvB,4CAA4C;IAC5C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,sFAAsF;IACtF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,4FAA4F;IAC5F,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,+DAA+D;IAC/D,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,gEAAgE;IAChE,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC,kFAAkF;IAClF,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,qEAAqE;IACrE,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,qEAAqE;IACrE,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,iEAAiE;IACjE,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C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,KAAK,cAAc,GACf,GAAG,CAAC,aAAa,CAAC,GAClB,WAAW,CAAC,aAAa,CAAC,GAC1B,CAAC,MAAM,aAAa,CAAC,CAAC;AAE1B;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAKjE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,CAAC,aAAa,CAAC,CAK7D"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { u } from "./useMessageHandler-CMdy-lm0.js";
2
- import { C, d, p, u as u2, a } from "./useChatKitLabels-DeHxZG2a.js";
2
+ import { C, d, p, u as u2, a } from "./useChatKitLabels-BxNkTzr2.js";
3
3
  import { S, c, d as d2, a as a2, u as u3, b, e, f } from "./index-Ct5hD214.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 } from "./CkInput.vue_vue_type_script_setup_true_lang-DCZTSiBj.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 } from "./CkInput.vue_vue_type_script_setup_true_lang-BVZ7FG88.js";
5
5
  export {
6
6
  C as CHAT_KIT_LABELS,
7
7
  _ as CkAgentMessage,
@@ -12717,6 +12717,8 @@ const defaultChatKitLabels = {
12717
12717
  feedbackDialogFreeTextPlaceholder: "Write down some additional details",
12718
12718
  feedbackDialogCancelLabel: "Cancel",
12719
12719
  feedbackDialogSubmitLabel: "Submit",
12720
+ userMessageShowMore: "Show more",
12721
+ userMessageShowLess: "Show less",
12720
12722
  historyItemUntitled: "Untitled conversation",
12721
12723
  historyItemActionAriaLabel: "Conversation options",
12722
12724
  historyItemEditAction: "Edit",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aleph-alpha/chat-kit",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Chat kit package for building chat interfaces with Vue",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,9 @@
1
1
  import CkUserMessage from './CkUserMessage.vue';
2
2
  import { render, screen } from '@testing-library/vue';
3
3
 
4
+ const CONTENT_SELECTOR = '.ck-user-message__content';
5
+ const CLAMPED_CLASS = 'ck-user-message__content--clamped';
6
+
4
7
  describe('CkUserMessage', () => {
5
8
  it('displays the message text from prop', () => {
6
9
  render(CkUserMessage, { props: { message: 'Hello from tests' } });
@@ -17,4 +20,26 @@ describe('CkUserMessage', () => {
17
20
  expect(screen.getByText('Custom slot content')).toBeInTheDocument();
18
21
  expect(screen.queryByText('Fallback text')).not.toBeInTheDocument();
19
22
  });
23
+
24
+ describe('collapsedLines clamping', () => {
25
+ it('does not clamp or render a toggle when collapsedLines is omitted', () => {
26
+ const { container } = render(CkUserMessage, {
27
+ props: { message: 'A message' },
28
+ });
29
+
30
+ const content = container.querySelector(CONTENT_SELECTOR);
31
+ expect(content).not.toHaveClass(CLAMPED_CLASS);
32
+ expect(screen.queryByRole('button')).not.toBeInTheDocument();
33
+ });
34
+
35
+ it('clamps the content to the requested number of lines', () => {
36
+ const { container } = render(CkUserMessage, {
37
+ props: { message: 'A long message', collapsedLines: 3 },
38
+ });
39
+
40
+ const content = container.querySelector<HTMLElement>(CONTENT_SELECTOR);
41
+ expect(content).toHaveClass(CLAMPED_CLASS);
42
+ expect(content?.style.getPropertyValue('--ck-collapsed-lines')).toBe('3');
43
+ });
44
+ });
20
45
  });
@@ -11,6 +11,11 @@ const meta: Meta<typeof CkUserMessage> = {
11
11
  description:
12
12
  'The message text to display. Can also be provided via the default slot.',
13
13
  },
14
+ collapsedLines: {
15
+ control: { type: 'number', min: 0 },
16
+ description:
17
+ 'When > 0, clamp the message to this many lines with a fade and a "Show more" / "Show less" toggle (shown only when the content overflows). 0 disables clamping.',
18
+ },
14
19
  },
15
20
  decorators: [
16
21
  () => ({
@@ -61,6 +66,22 @@ import { CkUserMessage } from '@aleph-alpha/chat-kit';
61
66
  </CkUserMessage>
62
67
  </template>`;
63
68
 
69
+ const collapsibleMessage =
70
+ 'Lorem ipsum dolor sit amet consectetur. Scelerisque justo pharetra enim eros risus. ' +
71
+ 'Urna dictumst ultrices mattis tristique lacus in in. Elit sed in a pellentesque purus ' +
72
+ 'lectus quis. Massa facilisis eget etiam maecenas eget libero iaculis consectetur. ' +
73
+ 'Curabitur vivamus a nulla cras venenatis nec ultrices donec. Dui tempus posuere nulla ' +
74
+ 'in id dictumst id congue odio. At lacus elit sit amet. Sodales lorem lacus faucibus ' +
75
+ 'condimentum lectus auctor.';
76
+
77
+ const collapsibleTemplateSource = `<script setup lang="ts">
78
+ import { CkUserMessage } from '@aleph-alpha/chat-kit';
79
+ </script>
80
+
81
+ <template>
82
+ <CkUserMessage :collapsed-lines="4" message="..." />
83
+ </template>`;
84
+
64
85
  /**
65
86
  * Standard user message bubble populated via the `message` prop. Use as the
66
87
  * default way to render the user turn in a conversation.
@@ -110,3 +131,16 @@ export const WithSlotContent: Story = {
110
131
  }),
111
132
  parameters: { docs: { source: { code: withSlotContentTemplateSource } } },
112
133
  };
134
+
135
+ /**
136
+ * Long message clamped to 4 lines. The last visible line fades out and a
137
+ * centered "Show more" / "Show less" toggle expands and collapses the text.
138
+ * The toggle only appears when the content actually overflows the clamp.
139
+ */
140
+ export const Collapsible: Story = {
141
+ args: {
142
+ message: collapsibleMessage,
143
+ collapsedLines: 4,
144
+ },
145
+ parameters: { docs: { source: { code: collapsibleTemplateSource } } },
146
+ };
@@ -1,19 +1,129 @@
1
1
  <script setup lang="ts">
2
+ import {
3
+ defaultChatKitLabels,
4
+ useChatKitLabels,
5
+ } from '../../../handlers/useChatKitLabels';
2
6
  import type { CkUserMessageProps } from './types';
7
+ import {
8
+ computed,
9
+ nextTick,
10
+ onBeforeUnmount,
11
+ onMounted,
12
+ ref,
13
+ watch,
14
+ } from 'vue';
3
15
 
4
16
  defineOptions({ name: 'CkUserMessage' });
5
17
 
6
- defineProps<CkUserMessageProps>();
18
+ const props = withDefaults(defineProps<CkUserMessageProps>(), {
19
+ message: undefined,
20
+ collapsedLines: 0,
21
+ });
22
+
23
+ const labels = useChatKitLabels();
24
+
25
+ // Resolution order: injected label, English default.
26
+ const showMoreLabel = computed(
27
+ () =>
28
+ labels.value.userMessageShowMore ??
29
+ defaultChatKitLabels.userMessageShowMore!,
30
+ );
31
+ const showLessLabel = computed(
32
+ () =>
33
+ labels.value.userMessageShowLess ??
34
+ defaultChatKitLabels.userMessageShowLess!,
35
+ );
36
+
37
+ /** Clamping is opt-in: only active when a positive `collapsedLines` is given. */
38
+ const clampEnabled = computed(() => (props.collapsedLines ?? 0) > 0);
39
+
40
+ const contentRef = ref<HTMLElement | null>(null);
41
+ const expanded = ref(false);
42
+ const isOverflowing = ref(false);
43
+
44
+ function measure() {
45
+ const el = contentRef.value;
46
+ if (!el || !clampEnabled.value || expanded.value) return;
47
+ isOverflowing.value = el.scrollHeight - el.clientHeight > 1;
48
+ }
49
+
50
+ function toggle() {
51
+ expanded.value = !expanded.value;
52
+ }
53
+
54
+ let resizeObserver: ResizeObserver | undefined;
55
+
56
+ onMounted(() => {
57
+ nextTick(measure);
58
+ if (typeof ResizeObserver !== 'undefined') {
59
+ resizeObserver = new ResizeObserver(() => measure());
60
+ if (contentRef.value) resizeObserver.observe(contentRef.value);
61
+ }
62
+ });
63
+
64
+ onBeforeUnmount(() => resizeObserver?.disconnect());
65
+
66
+ // New content (or a changed clamp) re-evaluates from the collapsed state.
67
+ watch([() => props.message, () => props.collapsedLines], () => {
68
+ expanded.value = false;
69
+ nextTick(measure);
70
+ });
7
71
  </script>
8
72
 
9
73
  <template>
10
- <div
11
- class="bg-background-surface-primary inline-flex max-w-[600px] flex-col items-end justify-start gap-4 rounded-xl p-6"
12
- >
74
+ <div class="inline-flex max-w-[536px] flex-col items-end justify-start gap-1">
13
75
  <div
14
- class="text-content-on-surface-primary justify-start self-stretch text-base leading-6 font-normal"
76
+ ref="contentRef"
77
+ class="ck-user-message__content text-content-on-surface-muted min-w-0 max-w-full self-stretch text-lg leading-7 font-medium break-words whitespace-pre-wrap [overflow-wrap:anywhere]"
78
+ :class="{
79
+ 'ck-user-message__content--clamped': clampEnabled && !expanded,
80
+ 'ck-user-message__content--faded':
81
+ clampEnabled && !expanded && isOverflowing,
82
+ }"
83
+ :style="
84
+ clampEnabled ? { '--ck-collapsed-lines': collapsedLines } : undefined
85
+ "
15
86
  >
16
87
  <slot>{{ message }}</slot>
17
88
  </div>
89
+ <button
90
+ v-if="clampEnabled && isOverflowing"
91
+ type="button"
92
+ :aria-expanded="expanded"
93
+ class="ck-user-message__toggle label-12-medium text-content-on-surface-primary bg-background-surface-floating focus-visible:ring-ring self-center rounded-3xl px-3 py-2 focus-visible:ring-2 focus-visible:outline-none"
94
+ @click="toggle"
95
+ >
96
+ {{ expanded ? showLessLabel : showMoreLabel }}
97
+ </button>
18
98
  </div>
19
99
  </template>
100
+
101
+ <style scoped>
102
+ /* Floating pill per design — the inset white + soft drop shadow aren't
103
+ expressible with the design-system shadow utilities, so set them here. */
104
+ .ck-user-message__toggle {
105
+ box-shadow:
106
+ 0 2px 2px 0 rgba(0, 0, 0, 0.05),
107
+ 0 0 4px 0 #fff inset;
108
+ }
109
+
110
+ /* text-lg has a 1.75rem (28px) line-height; clamp height = lines × line-height. */
111
+ .ck-user-message__content--clamped {
112
+ max-height: calc(var(--ck-collapsed-lines) * 1.75rem);
113
+ overflow: hidden;
114
+ }
115
+
116
+ /* Fade the last visible line to low opacity. */
117
+ .ck-user-message__content--faded {
118
+ -webkit-mask-image: linear-gradient(
119
+ to bottom,
120
+ #000 calc(100% - 1.75rem),
121
+ transparent 100%
122
+ );
123
+ mask-image: linear-gradient(
124
+ to bottom,
125
+ #000 calc(100% - 1.75rem),
126
+ transparent 100%
127
+ );
128
+ }
129
+ </style>
@@ -1,14 +1,23 @@
1
1
  /**
2
- * Bubble layout for a single user turn in a conversation. Renders the message
3
- * text on the right side with a tokenized background and max-width; supports
4
- * a default slot for custom inline content.
2
+ * Layout for a single user turn in a conversation. Renders the message text
3
+ * right-aligned in the muted on-surface color with a max-width; supports a
4
+ * default slot for custom inline content. When `collapsedLines` is set, long
5
+ * messages are clamped with a fade and a "Show more" / "Show less" toggle.
5
6
  *
6
7
  * @category Messages
7
- * @useCases render user message bubble, conversation turn from user, chat input preview, right-aligned message
8
- * @keywords user, message, bubble, chat, conversation, turn
8
+ * @useCases render user message, conversation turn from user, chat input preview, right-aligned message, collapsible long message
9
+ * @keywords user, message, chat, conversation, turn, collapse, show more
9
10
  * @related CkAgentMessage, CkConversation
10
11
  */
11
12
  export interface CkUserMessageProps {
12
13
  /** Text content of the user message. Rendered inside the bubble when no default slot is provided. */
13
14
  message?: string;
15
+ /**
16
+ * When greater than `0`, collapse the message to at most this many lines.
17
+ * The last visible line fades out and a "Show more" / "Show less" toggle is
18
+ * revealed only when the content actually overflows. Omit or pass `0`
19
+ * (the default) to render the full message with no clamping — preserving the
20
+ * original behavior for existing consumers.
21
+ */
22
+ collapsedLines?: number;
14
23
  }
@@ -54,6 +54,8 @@ describe('useChatKitLabels', () => {
54
54
  feedbackDialogFreeTextPlaceholder: 'Zusätzliche Details eingeben',
55
55
  feedbackDialogCancelLabel: 'Abbrechen',
56
56
  feedbackDialogSubmitLabel: 'Senden',
57
+ userMessageShowMore: 'Mehr anzeigen',
58
+ userMessageShowLess: 'Weniger anzeigen',
57
59
  historyItemUntitled: 'Unbenannte Konversation',
58
60
  historyItemActionAriaLabel: 'Konversationsoptionen',
59
61
  historyItemEditAction: 'Bearbeiten',
@@ -65,6 +65,10 @@ export type ChatKitLabels = {
65
65
  feedbackDialogCancelLabel?: string;
66
66
  /** Submit button label in `CkFeedbackDialog`. */
67
67
  feedbackDialogSubmitLabel?: string;
68
+ /** Label for the `CkUserMessage` toggle when the message is collapsed. */
69
+ userMessageShowMore?: string;
70
+ /** Label for the `CkUserMessage` toggle when the message is expanded. */
71
+ userMessageShowLess?: string;
68
72
  /** Fallback title used by `CkHistory` when a conversation has no `title`. */
69
73
  historyItemUntitled: string;
70
74
  /** Accessible name for the trailing kebab trigger on each `CkHistory` row. */
@@ -96,6 +100,8 @@ export const defaultChatKitLabels: ChatKitLabels = {
96
100
  feedbackDialogFreeTextPlaceholder: 'Write down some additional details',
97
101
  feedbackDialogCancelLabel: 'Cancel',
98
102
  feedbackDialogSubmitLabel: 'Submit',
103
+ userMessageShowMore: 'Show more',
104
+ userMessageShowLess: 'Show less',
99
105
  historyItemUntitled: 'Untitled conversation',
100
106
  historyItemActionAriaLabel: 'Conversation options',
101
107
  historyItemEditAction: 'Edit',