@epam/ai-dial-quotations 1.1.0-dev.267 → 1.1.0-dev.269

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.
@@ -0,0 +1,41 @@
1
+ import { Annotation } from '@epam/ai-dial-chat-shared';
2
+ import { Components } from 'react-markdown';
3
+ import { CitationCardLabels } from '../../components/CitationCard/CitationCard';
4
+ import { CitationMarkerLabels } from '../../components/CitationMarker/CitationMarker';
5
+ import { AnnotationGroup } from '../../utils/group-annotations-by-source';
6
+ /** Host-supplied callbacks and label builder consumed by `useCitationMarkdownComponents`. */
7
+ export interface UseCitationMarkdownComponentsCallbacks {
8
+ /** Called when a citation marker's preview action is invoked, with the clicked annotation and its group. */
9
+ onPreview(annotation: Annotation, group: AnnotationGroup): void;
10
+ /** Called when a citation marker's open-in-browser action is invoked. */
11
+ onOpenInBrowser(annotation: Annotation): void;
12
+ /** Builds the translated label bundles used by a given citation group's card and marker. */
13
+ buildLabels(group: AnnotationGroup): {
14
+ cardLabels: CitationCardLabels;
15
+ markerLabels: CitationMarkerLabels;
16
+ };
17
+ }
18
+ /**
19
+ * Builds react-markdown component overrides that inject citation markers into
20
+ * rendered paragraph text at the character offsets stored in each annotation
21
+ * group's primary selector.
22
+ *
23
+ * The `p` and `li` component overrides are stable references — they only
24
+ * change when `groups` transitions between empty and non-empty. Citation card
25
+ * open/close state is provided via `CitationCardContext` so that state changes
26
+ * do not recreate the component functions, preventing ReactMarkdown from
27
+ * unmounting and remounting the paragraph subtree on every interaction.
28
+ *
29
+ * Returns both the pre-processed content string (with sentinel placeholders
30
+ * injected at the right offsets) and the `Components` map to pass to the
31
+ * markdown renderer.
32
+ *
33
+ * `isCompactTypography` drops the paragraph class one type-scale step, matching
34
+ * `COMPACT_MARKDOWN_CLASS_NAMES` so cited and uncited paragraphs stay the same
35
+ * size.
36
+ */
37
+ export declare const useCitationMarkdownComponents: (content: string, groups: AnnotationGroup[], callbacks: UseCitationMarkdownComponentsCallbacks, isCompactTypography?: boolean) => {
38
+ processedContent: string;
39
+ markdownComponents: Components;
40
+ };
41
+ //# sourceMappingURL=useCitationMarkdownComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCitationMarkdownComponents.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCitationMarkdownComponents/useCitationMarkdownComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAErF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AAK3F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE/E,6FAA6F;AAC7F,MAAM,WAAW,sCAAsC;IACrD,4GAA4G;IAC5G,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAChE,yEAAyE;IACzE,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9C,4FAA4F;IAC5F,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG;QACnC,UAAU,EAAE,kBAAkB,CAAC;QAC/B,YAAY,EAAE,oBAAoB,CAAC;KACpC,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,6BAA6B,GACxC,SAAS,MAAM,EACf,QAAQ,eAAe,EAAE,EACzB,WAAW,sCAAsC,EACjD,6BAA2B,KAC1B;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,UAAU,CAAA;CAsD5D,CAAC"}
package/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export { CitationCardProvider, useCitationCardContext, } from './context/Citatio
8
8
  export type { CitationCardHook } from './context/CitationCardContext';
9
9
  export { useAnnotations } from './utils/useAnnotations';
10
10
  export { useCitationCard } from './utils/useCitationCard';
11
+ export { useCitationMarkdownComponents } from './hooks/useCitationMarkdownComponents/useCitationMarkdownComponents';
12
+ export type { UseCitationMarkdownComponentsCallbacks } from './hooks/useCitationMarkdownComponents/useCitationMarkdownComponents';
11
13
  export { groupAnnotationsBySource } from './utils/group-annotations-by-source';
12
14
  export type { AnnotationGroup } from './utils/group-annotations-by-source';
13
15
  export { annotationsToPdfHighlights, annotationHighlightId, normalizeRawAnnotations, resolveMessageAnnotations, } from './utils/annotation';
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,YAAY,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AAG5F,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,YAAY,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,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AAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC"}
package/index.js CHANGED
@@ -258,20 +258,81 @@ var D = {
258
258
  i,
259
259
  e
260
260
  ]);
261
- }, L = (e) => {
261
+ }, L = /⟦C(\d+)⟧/g, R = (e, t) => {
262
+ let n = t.map((t, n) => {
263
+ let r = t.primaryAnnotation.target?.selector, i = typeof r == "object" && r && "type" in r && r.type === "text_character_range" ? r.end : e.length;
264
+ return {
265
+ idx: n,
266
+ pos: Math.min(i, e.length)
267
+ };
268
+ }).sort((e, t) => t.pos - e.pos), r = e;
269
+ for (let { idx: e, pos: t } of n) r = `${r.slice(0, t)}⟦C${e}⟧${r.slice(t)}`;
270
+ return r;
271
+ }, z = (e, t) => {
272
+ if (typeof e == "string") {
273
+ let n = e.split(L);
274
+ if (n.length === 1) return e;
275
+ let r = [];
276
+ return n.forEach((e, n) => {
277
+ n % 2 == 1 ? r.push(t(parseInt(e, 10))) : e && r.push(e);
278
+ }), r;
279
+ }
280
+ return Array.isArray(e) ? e.flatMap((e) => {
281
+ let n = z(e, t);
282
+ return Array.isArray(n) ? n : [n];
283
+ }) : e;
284
+ }, B = (e, t, n, i = !1) => {
285
+ let { onPreview: a, onOpenInBrowser: o, buildLabels: s } = n;
286
+ return {
287
+ processedContent: g(() => t.length > 0 ? R(e, t) : e, [e, t]),
288
+ markdownComponents: g(() => {
289
+ if (t.length === 0) return {};
290
+ let e = (e) => {
291
+ let n = t[e];
292
+ if (!n) return null;
293
+ let { cardLabels: r, markerLabels: i } = s(n);
294
+ return /* @__PURE__ */ v(E, {
295
+ group: n,
296
+ onPreview: (e) => a(e, n),
297
+ onOpenInBrowser: o,
298
+ cardLabels: r,
299
+ markerLabels: i
300
+ }, `citation-${n.sourceUrl}`);
301
+ };
302
+ return {
303
+ p: ({ children: t, ...n }) => /* @__PURE__ */ v("p", {
304
+ ...n,
305
+ className: r(i ? "dial-small-paragraph-text" : "dial-body-paragraph-text", "mb-3 [overflow-wrap:anywhere] [text-wrap:pretty] last:mb-0"),
306
+ children: z(t, e)
307
+ }),
308
+ li: ({ children: t, ...n }) => /* @__PURE__ */ v("li", {
309
+ ...n,
310
+ className: "mb-1.5 last:mb-0",
311
+ children: z(t, e)
312
+ })
313
+ };
314
+ }, [
315
+ t,
316
+ a,
317
+ o,
318
+ s,
319
+ i
320
+ ])
321
+ };
322
+ }, V = (e) => {
262
323
  try {
263
324
  return decodeURIComponent(e);
264
325
  } catch {
265
326
  return e;
266
327
  }
267
- }, R = (e) => {
328
+ }, H = (e) => {
268
329
  try {
269
330
  let t = new URL(e);
270
- return t.pathname.split("/").map((e) => L(e)).filter(Boolean).at(-1) ?? t.hostname;
331
+ return t.pathname.split("/").map((e) => V(e)).filter(Boolean).at(-1) ?? t.hostname;
271
332
  } catch {
272
- return e.split("/").map((e) => L(e)).filter(Boolean).at(-1) ?? e;
333
+ return e.split("/").map((e) => V(e)).filter(Boolean).at(-1) ?? e;
273
334
  }
274
- }, z = (e) => {
335
+ }, U = (e) => {
275
336
  let t = /* @__PURE__ */ new Map();
276
337
  for (let n of e) {
277
338
  let e = n.body?.source?.attachment?.url;
@@ -279,43 +340,20 @@ var D = {
279
340
  let r = t.get(e);
280
341
  r ? r.annotations.push(n) : t.set(e, {
281
342
  sourceUrl: e,
282
- sourceName: n.body?.source?.attachment?.title ?? R(e),
343
+ sourceName: n.body?.source?.attachment?.title ?? H(e),
283
344
  annotations: [n],
284
345
  primaryAnnotation: n
285
346
  });
286
347
  }
287
348
  return Array.from(t.values());
288
- }, B = /⟦C(\d+)⟧/g, V = (e, t) => {
289
- let n = t.map((t, n) => {
290
- let r = t.primaryAnnotation.target?.selector, i = typeof r == "object" && r && "type" in r && r.type === "text_character_range" ? r.end : e.length;
291
- return {
292
- idx: n,
293
- pos: Math.min(i, e.length)
294
- };
295
- }).sort((e, t) => t.pos - e.pos), r = e;
296
- for (let { idx: e, pos: t } of n) r = `${r.slice(0, t)}⟦C${e}⟧${r.slice(t)}`;
297
- return r;
298
- }, H = (e, t) => {
299
- if (typeof e == "string") {
300
- let n = e.split(B);
301
- if (n.length === 1) return e;
302
- let r = [];
303
- return n.forEach((e, n) => {
304
- n % 2 == 1 ? r.push(t(parseInt(e, 10))) : e && r.push(e);
305
- }), r;
306
- }
307
- return Array.isArray(e) ? e.flatMap((e) => {
308
- let n = H(e, t);
309
- return Array.isArray(n) ? n : [n];
310
- }) : e;
311
- }, U = (e) => e.url == null && e.reference_url != null, W = /^(.*\.pdf)(?:#page=(\d+))?$/i, G = (e) => {
312
- let t = W.exec(e);
349
+ }, W = (e) => e.url == null && e.reference_url != null, G = /^(.*\.pdf)(?:#page=(\d+))?$/i, K = (e) => {
350
+ let t = G.exec(e);
313
351
  return t ? {
314
352
  baseUrl: t[1],
315
353
  page: t[2] == null ? null : Number(t[2])
316
354
  } : null;
317
- }, K = (t) => z((t ?? []).filter(U).map((t) => {
318
- let n = t.reference_url, r = G(n) != null;
355
+ }, q = (t) => U((t ?? []).filter(W).map((t) => {
356
+ let n = t.reference_url, r = K(n) != null;
319
357
  return { body: {
320
358
  quote: t.data,
321
359
  source: {
@@ -329,4 +367,4 @@ var D = {
329
367
  } };
330
368
  }));
331
369
  //#endregion
332
- export { x as CitationCard, w as CitationCardProvider, E as CitationDropdown, S as CitationMarker, k as annotationHighlightId, O as annotationsToPdfHighlights, K as getReferenceAttachmentGroups, z as groupAnnotationsBySource, V as injectCitationSentinels, U as isReferenceOnlyAttachment, M as normalizeRawAnnotations, G as parsePdfPageReference, H as replaceSentinelsInChildren, N as resolveMessageAnnotations, P as useAnnotations, I as useCitationCard, T as useCitationCardContext };
370
+ export { x as CitationCard, w as CitationCardProvider, E as CitationDropdown, S as CitationMarker, k as annotationHighlightId, O as annotationsToPdfHighlights, q as getReferenceAttachmentGroups, U as groupAnnotationsBySource, R as injectCitationSentinels, W as isReferenceOnlyAttachment, M as normalizeRawAnnotations, K as parsePdfPageReference, z as replaceSentinelsInChildren, N as resolveMessageAnnotations, P as useAnnotations, I as useCitationCard, T as useCitationCardContext, B as useCitationMarkdownComponents };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@epam/ai-dial-quotations",
3
3
  "description": "Citation and annotation components, hooks, and utilities for AI DIAL conversations",
4
- "version": "1.1.0-dev.267",
4
+ "version": "1.1.0-dev.269",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "./index.js",
@@ -17,8 +17,9 @@
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0",
20
+ "react-markdown": "^10.1.0",
20
21
  "@tabler/icons-react": "^3.0.0",
21
- "@epam/ai-dial-chat-shared": "1.1.0-dev.267",
22
+ "@epam/ai-dial-chat-shared": "1.1.0-dev.269",
22
23
  "@epam/ai-dial-ui-kit": "*",
23
24
  "@epam/pdf-highlighter-kit": ">=0.0.14"
24
25
  },