@epam/ai-dial-quotations 1.0.0-rc.6 → 1.0.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/components/CitationDropdown/CitationDropdown.d.ts.map +1 -1
- package/hooks/useCitationMarkdownComponents/useCitationMarkdownComponents.d.ts +41 -0
- package/hooks/useCitationMarkdownComponents/useCitationMarkdownComponents.d.ts.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +100 -63
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CitationDropdown.d.ts","sourceRoot":"","sources":["../../../src/components/CitationDropdown/CitationDropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,EAAE,EAAQ,SAAS,EAAwB,MAAM,OAAO,CAAC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAE1C,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,KAAK,EAAE,eAAe,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C,uEAAuE;IACvE,eAAe,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAClD,wDAAwD;IACxD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,uFAAuF;IACvF,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,+CAA+C;IAC/C,UAAU,EAAE,kBAAkB,CAAC;IAC/B,yDAAyD;IACzD,YAAY,EAAE,oBAAoB,CAAC;IACnC,2DAA2D;IAC3D,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,8HAA8H;AAC9H,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,
|
|
1
|
+
{"version":3,"file":"CitationDropdown.d.ts","sourceRoot":"","sources":["../../../src/components/CitationDropdown/CitationDropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,EAAE,EAAQ,SAAS,EAAwB,MAAM,OAAO,CAAC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAE1C,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,KAAK,EAAE,eAAe,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C,uEAAuE;IACvE,eAAe,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAClD,wDAAwD;IACxD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,uFAAuF;IACvF,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,+CAA+C;IAC/C,UAAU,EAAE,kBAAkB,CAAC;IAC/B,yDAAyD;IACzD,YAAY,EAAE,oBAAoB,CAAC;IACnC,2DAA2D;IAC3D,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,8HAA8H;AAC9H,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CAyEtD,CAAC;;AAEF,wBAAsC"}
|
|
@@ -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;
|
|
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;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,qEAAqE,CAAC;AACpH,YAAY,EAAE,sCAAsC,EAAE,MAAM,qEAAqE,CAAC;AAGlI,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,EAAE,kBAAkB,EAAE,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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MIMEType as e, MarkdownRenderer as t, buildCssVars as n, mergeClasses as r } from "@epam/ai-dial-chat-shared";
|
|
2
|
-
import {
|
|
2
|
+
import { ElementSize as i, EllipsisTooltip as a, GhostIconButton as o, NeutralButton as s, PrimaryButton as c, Tooltip as l } from "@epam/ai-dial-ui-kit";
|
|
3
3
|
import { IconChevronLeft as u, IconChevronRight as d } from "@tabler/icons-react";
|
|
4
4
|
import { createContext as f, memo as p, useCallback as m, useContext as h, useMemo as g, useState as _ } from "react";
|
|
5
5
|
import { jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
@@ -9,8 +9,8 @@ var b = {
|
|
|
9
9
|
title: "_title_1kph1_9",
|
|
10
10
|
switcher: "_switcher_1kph1_13",
|
|
11
11
|
sourceName: "_sourceName_1kph1_17"
|
|
12
|
-
}, x = ({ group:
|
|
13
|
-
let S =
|
|
12
|
+
}, x = ({ group: s, activeIndex: l, onIndexChange: f, onPreview: p, onOpenInBrowser: m, headerIcon: h, labels: g, typography: _, colors: x }) => {
|
|
13
|
+
let S = s.annotations.length, C = s.annotations[l] ?? s.primaryAnnotation, w = S > 1, T = s.annotations.some((e) => e.body?.title), E = s.primaryAnnotation.body?.source?.attachment?.type, D = p == null || E === e.HTML || E === e.XHTML, O = _?.sourceNameClassName ?? "dial-tiny-text", k = _?.titleClassName ?? "dial-body-semi-text", A = _?.quoteClassName ?? "dial-small-text", j = _?.switcherClassName ?? "dial-tiny-text", M = n({
|
|
14
14
|
"--cc-card-bg": x?.cardBackground,
|
|
15
15
|
"--cc-quote-text": x?.quoteText,
|
|
16
16
|
"--cc-title-text": x?.titleText,
|
|
@@ -28,34 +28,34 @@ var b = {
|
|
|
28
28
|
className: "flex items-center justify-between gap-2",
|
|
29
29
|
children: [/* @__PURE__ */ y("div", {
|
|
30
30
|
className: "flex min-w-0 items-center gap-1",
|
|
31
|
-
children: [h, /* @__PURE__ */ v(
|
|
32
|
-
text:
|
|
31
|
+
children: [h, /* @__PURE__ */ v(a, {
|
|
32
|
+
text: s.sourceName,
|
|
33
33
|
className: r(O, "min-w-0", b.sourceName)
|
|
34
34
|
})]
|
|
35
35
|
}), w && /* @__PURE__ */ y("div", {
|
|
36
36
|
className: "flex shrink-0 items-center gap-1",
|
|
37
37
|
children: [
|
|
38
|
-
/* @__PURE__ */ v(
|
|
38
|
+
/* @__PURE__ */ v(o, {
|
|
39
39
|
icon: /* @__PURE__ */ v(u, {
|
|
40
40
|
size: 14,
|
|
41
41
|
className: "rtl:scale-x-[-1]"
|
|
42
42
|
}),
|
|
43
|
-
size:
|
|
43
|
+
size: i.Small,
|
|
44
44
|
"aria-label": g.previousCitation,
|
|
45
|
-
onClick: () => f((
|
|
45
|
+
onClick: () => f((l - 1 + S) % S)
|
|
46
46
|
}),
|
|
47
47
|
/* @__PURE__ */ v("span", {
|
|
48
48
|
className: r(j, b.switcher),
|
|
49
|
-
children: g.formatSwitcherText(
|
|
49
|
+
children: g.formatSwitcherText(l + 1, S)
|
|
50
50
|
}),
|
|
51
|
-
/* @__PURE__ */ v(
|
|
51
|
+
/* @__PURE__ */ v(o, {
|
|
52
52
|
icon: /* @__PURE__ */ v(d, {
|
|
53
53
|
size: 14,
|
|
54
54
|
className: "rtl:scale-x-[-1]"
|
|
55
55
|
}),
|
|
56
|
-
size:
|
|
56
|
+
size: i.Small,
|
|
57
57
|
"aria-label": g.nextCitation,
|
|
58
|
-
onClick: () => f((
|
|
58
|
+
onClick: () => f((l + 1) % S)
|
|
59
59
|
})
|
|
60
60
|
]
|
|
61
61
|
})]
|
|
@@ -75,13 +75,13 @@ var b = {
|
|
|
75
75
|
}),
|
|
76
76
|
/* @__PURE__ */ y("div", {
|
|
77
77
|
className: "flex justify-start gap-2",
|
|
78
|
-
children: [p && /* @__PURE__ */ v(
|
|
78
|
+
children: [p && /* @__PURE__ */ v(c, {
|
|
79
79
|
label: g.preview,
|
|
80
|
-
size:
|
|
80
|
+
size: i.Small,
|
|
81
81
|
onClick: () => p(C)
|
|
82
|
-
}), /* @__PURE__ */ v(
|
|
82
|
+
}), /* @__PURE__ */ v(c, {
|
|
83
83
|
label: D ? g.openInBrowser : g.download,
|
|
84
|
-
size:
|
|
84
|
+
size: i.Small,
|
|
85
85
|
onClick: () => m(C)
|
|
86
86
|
})]
|
|
87
87
|
})
|
|
@@ -91,17 +91,17 @@ var b = {
|
|
|
91
91
|
p(x);
|
|
92
92
|
//#endregion
|
|
93
93
|
//#region src/components/CitationMarker/CitationMarker.tsx
|
|
94
|
-
var S = ({ annotationCount: e, onOpen: t, icon: n, labels: r, labelClassName:
|
|
95
|
-
let
|
|
94
|
+
var S = ({ annotationCount: e, onOpen: t, icon: n, labels: r, labelClassName: a = "dial-caption-text" }) => {
|
|
95
|
+
let o = /* @__PURE__ */ y("span", {
|
|
96
96
|
className: "flex items-center gap-1",
|
|
97
97
|
children: [n, /* @__PURE__ */ v("span", {
|
|
98
|
-
className:
|
|
98
|
+
className: a,
|
|
99
99
|
children: e > 1 ? r.labelWithOverflow : r.label
|
|
100
100
|
})]
|
|
101
101
|
});
|
|
102
|
-
return /* @__PURE__ */ v(
|
|
103
|
-
size:
|
|
104
|
-
label:
|
|
102
|
+
return /* @__PURE__ */ v(s, {
|
|
103
|
+
size: i.Small,
|
|
104
|
+
label: o,
|
|
105
105
|
"aria-label": r.ariaLabel,
|
|
106
106
|
onClick: t
|
|
107
107
|
});
|
|
@@ -113,14 +113,13 @@ var C = f(null), w = C.Provider, T = () => {
|
|
|
113
113
|
let e = h(C);
|
|
114
114
|
if (e == null) throw Error("useCitationCardContext must be used within a CitationCardProvider");
|
|
115
115
|
return e;
|
|
116
|
-
}, E = ({ group: e, onPreview: t, onOpenInBrowser: n, icon: r, headerIcon: i, cardLabels:
|
|
116
|
+
}, E = ({ group: e, onPreview: t, onOpenInBrowser: n, icon: r, headerIcon: i, cardLabels: a, markerLabels: o, cardTypography: s, markerLabelClassName: c }) => {
|
|
117
117
|
let u = T(), d = u.isOpen(e.sourceUrl), f = u.getActiveIndex(e.sourceUrl);
|
|
118
|
-
return /* @__PURE__ */ v(
|
|
118
|
+
return /* @__PURE__ */ v(l, {
|
|
119
119
|
open: d,
|
|
120
120
|
onOpenChange: m((e) => {
|
|
121
121
|
e || u.closePopup();
|
|
122
122
|
}, [u]),
|
|
123
|
-
placement: "bottom-end",
|
|
124
123
|
triggerClassName: "ms-1 inline-flex align-middle",
|
|
125
124
|
contentClassName: "!p-0 !bg-transparent !border-0 !shadow-none !max-w-none !rounded-none [&>svg]:stroke-transparent",
|
|
126
125
|
tooltip: /* @__PURE__ */ v(x, {
|
|
@@ -132,16 +131,16 @@ var C = f(null), w = C.Provider, T = () => {
|
|
|
132
131
|
} : void 0, [t, u]),
|
|
133
132
|
onOpenInBrowser: n,
|
|
134
133
|
headerIcon: i,
|
|
135
|
-
labels:
|
|
136
|
-
typography:
|
|
134
|
+
labels: a,
|
|
135
|
+
typography: s
|
|
137
136
|
}),
|
|
138
137
|
children: /* @__PURE__ */ v(S, {
|
|
139
138
|
sourceName: e.sourceName,
|
|
140
139
|
annotationCount: e.annotations.length,
|
|
141
140
|
onOpen: () => u.openPopup(e.sourceUrl),
|
|
142
141
|
icon: r,
|
|
143
|
-
labels:
|
|
144
|
-
labelClassName:
|
|
142
|
+
labels: o,
|
|
143
|
+
labelClassName: c
|
|
145
144
|
})
|
|
146
145
|
});
|
|
147
146
|
};
|
|
@@ -259,20 +258,81 @@ var D = {
|
|
|
259
258
|
i,
|
|
260
259
|
e
|
|
261
260
|
]);
|
|
262
|
-
}, 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) => {
|
|
263
323
|
try {
|
|
264
324
|
return decodeURIComponent(e);
|
|
265
325
|
} catch {
|
|
266
326
|
return e;
|
|
267
327
|
}
|
|
268
|
-
},
|
|
328
|
+
}, H = (e) => {
|
|
269
329
|
try {
|
|
270
330
|
let t = new URL(e);
|
|
271
|
-
return t.pathname.split("/").map((e) =>
|
|
331
|
+
return t.pathname.split("/").map((e) => V(e)).filter(Boolean).at(-1) ?? t.hostname;
|
|
272
332
|
} catch {
|
|
273
|
-
return e.split("/").map((e) =>
|
|
333
|
+
return e.split("/").map((e) => V(e)).filter(Boolean).at(-1) ?? e;
|
|
274
334
|
}
|
|
275
|
-
},
|
|
335
|
+
}, U = (e) => {
|
|
276
336
|
let t = /* @__PURE__ */ new Map();
|
|
277
337
|
for (let n of e) {
|
|
278
338
|
let e = n.body?.source?.attachment?.url;
|
|
@@ -280,43 +340,20 @@ var D = {
|
|
|
280
340
|
let r = t.get(e);
|
|
281
341
|
r ? r.annotations.push(n) : t.set(e, {
|
|
282
342
|
sourceUrl: e,
|
|
283
|
-
sourceName: n.body?.source?.attachment?.title ??
|
|
343
|
+
sourceName: n.body?.source?.attachment?.title ?? H(e),
|
|
284
344
|
annotations: [n],
|
|
285
345
|
primaryAnnotation: n
|
|
286
346
|
});
|
|
287
347
|
}
|
|
288
348
|
return Array.from(t.values());
|
|
289
|
-
},
|
|
290
|
-
let
|
|
291
|
-
let r = t.primaryAnnotation.target?.selector, i = typeof r == "object" && r && "type" in r && r.type === "text_character_range" ? r.end : e.length;
|
|
292
|
-
return {
|
|
293
|
-
idx: n,
|
|
294
|
-
pos: Math.min(i, e.length)
|
|
295
|
-
};
|
|
296
|
-
}).sort((e, t) => t.pos - e.pos), r = e;
|
|
297
|
-
for (let { idx: e, pos: t } of n) r = `${r.slice(0, t)}⟦C${e}⟧${r.slice(t)}`;
|
|
298
|
-
return r;
|
|
299
|
-
}, H = (e, t) => {
|
|
300
|
-
if (typeof e == "string") {
|
|
301
|
-
let n = e.split(B);
|
|
302
|
-
if (n.length === 1) return e;
|
|
303
|
-
let r = [];
|
|
304
|
-
return n.forEach((e, n) => {
|
|
305
|
-
n % 2 == 1 ? r.push(t(parseInt(e, 10))) : e && r.push(e);
|
|
306
|
-
}), r;
|
|
307
|
-
}
|
|
308
|
-
return Array.isArray(e) ? e.flatMap((e) => {
|
|
309
|
-
let n = H(e, t);
|
|
310
|
-
return Array.isArray(n) ? n : [n];
|
|
311
|
-
}) : e;
|
|
312
|
-
}, U = (e) => e.url == null && e.reference_url != null, W = /^(.*\.pdf)(?:#page=(\d+))?$/i, G = (e) => {
|
|
313
|
-
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);
|
|
314
351
|
return t ? {
|
|
315
352
|
baseUrl: t[1],
|
|
316
353
|
page: t[2] == null ? null : Number(t[2])
|
|
317
354
|
} : null;
|
|
318
|
-
},
|
|
319
|
-
let n = t.reference_url, r =
|
|
355
|
+
}, q = (t) => U((t ?? []).filter(W).map((t) => {
|
|
356
|
+
let n = t.reference_url, r = K(n) != null;
|
|
320
357
|
return { body: {
|
|
321
358
|
quote: t.data,
|
|
322
359
|
source: {
|
|
@@ -330,4 +367,4 @@ var D = {
|
|
|
330
367
|
} };
|
|
331
368
|
}));
|
|
332
369
|
//#endregion
|
|
333
|
-
export { x as CitationCard, w as CitationCardProvider, E as CitationDropdown, S as CitationMarker, k as annotationHighlightId, O as annotationsToPdfHighlights,
|
|
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.0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./index.js",
|
|
@@ -17,9 +17,10 @@
|
|
|
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.0.0
|
|
22
|
-
"@epam/ai-dial-ui-kit": "
|
|
22
|
+
"@epam/ai-dial-chat-shared": "1.0.0",
|
|
23
|
+
"@epam/ai-dial-ui-kit": "*",
|
|
23
24
|
"@epam/pdf-highlighter-kit": ">=0.0.14"
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|