wealth-alpha-chat-widget 1.0.8 → 2.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/dist/index.cjs +44 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +21 -24
- package/dist/index.css.map +1 -1
- package/dist/index.mjs +45 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -891,23 +891,50 @@ function isRootMenuChips(chips) {
|
|
|
891
891
|
return chips.length > 0 && chips.every((c) => ROOT_MENU_CHIP_IDS.has(c.id));
|
|
892
892
|
}
|
|
893
893
|
var CARD_DISCLAIMER = "AI-assisted, educational only. Not financial advice. Consult a SEBI-registered advisor.";
|
|
894
|
+
var SECTOR_TOGGLE_PREFIX = "__portfolio_sector_toggle:::";
|
|
895
|
+
var SECTORS_DONE_ID = "__portfolio_sectors_done";
|
|
896
|
+
var escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
897
|
+
var sectorNameOf = (row) => (row.getAttribute("data-chip") ?? "").slice(SECTOR_TOGGLE_PREFIX.length);
|
|
894
898
|
function MessageBubble({ message, onChipClick, onFeedback }) {
|
|
895
899
|
const isBot = message.role === "bot";
|
|
896
900
|
const [rating, setRating] = react.useState(null);
|
|
901
|
+
const markdownRef = react.useRef(null);
|
|
902
|
+
const isSectorCard = isBot && message.content.includes(SECTOR_TOGGLE_PREFIX);
|
|
903
|
+
const [selectedSectors, setSelectedSectors] = react.useState(() => /* @__PURE__ */ new Set());
|
|
897
904
|
const rate = (value) => {
|
|
898
905
|
setRating(value);
|
|
899
906
|
onFeedback?.(message.id, value);
|
|
900
907
|
};
|
|
901
908
|
const isCard = isBot && message.content.includes("<div");
|
|
902
909
|
const bubbleClass = isBot ? `${chat_default.bubble} ${isCard ? chat_default.bubbleCard : chat_default.bubbleBot}` : `${chat_default.bubble} ${chat_default.bubbleUser}`;
|
|
910
|
+
const applySelectionToDom = react.useCallback(() => {
|
|
911
|
+
const root = markdownRef.current;
|
|
912
|
+
if (!root) return;
|
|
913
|
+
root.querySelectorAll(`.srow[data-chip^="${SECTOR_TOGGLE_PREFIX}"]`).forEach((row) => row.classList.toggle("selected", selectedSectors.has(sectorNameOf(row))));
|
|
914
|
+
const summary = root.querySelector(".wa-sel-summary");
|
|
915
|
+
if (summary) {
|
|
916
|
+
const names = Array.from(selectedSectors);
|
|
917
|
+
const list = names.length ? names.map(escapeHtml).join(", ") : "\u2014";
|
|
918
|
+
summary.innerHTML = `<span class="chk">\u2705</span>Selected (<b>${names.length}</b>): <b>${list}</b>`;
|
|
919
|
+
}
|
|
920
|
+
}, [selectedSectors]);
|
|
921
|
+
react.useLayoutEffect(() => {
|
|
922
|
+
if (isSectorCard) applySelectionToDom();
|
|
923
|
+
}, [isSectorCard, applySelectionToDom, message.content]);
|
|
903
924
|
const handleMarkdownClick = (e) => {
|
|
904
|
-
const
|
|
905
|
-
|
|
925
|
+
const toggleRow = e.target.closest(
|
|
926
|
+
`.srow[data-chip^="${SECTOR_TOGGLE_PREFIX}"]`
|
|
927
|
+
);
|
|
928
|
+
if (toggleRow) {
|
|
906
929
|
e.preventDefault();
|
|
907
|
-
const
|
|
908
|
-
if (
|
|
909
|
-
|
|
910
|
-
|
|
930
|
+
const name = sectorNameOf(toggleRow);
|
|
931
|
+
if (name) {
|
|
932
|
+
setSelectedSectors((prev) => {
|
|
933
|
+
const next = new Set(prev);
|
|
934
|
+
if (next.has(name)) next.delete(name);
|
|
935
|
+
else next.add(name);
|
|
936
|
+
return next;
|
|
937
|
+
});
|
|
911
938
|
}
|
|
912
939
|
return;
|
|
913
940
|
}
|
|
@@ -916,12 +943,22 @@ function MessageBubble({ message, onChipClick, onFeedback }) {
|
|
|
916
943
|
e.preventDefault();
|
|
917
944
|
window.location.assign(anchor.href);
|
|
918
945
|
};
|
|
946
|
+
const handleChipClick = (chip) => {
|
|
947
|
+
if (isSectorCard && chip.id === SECTORS_DONE_ID) {
|
|
948
|
+
const names = Array.from(selectedSectors);
|
|
949
|
+
const id = names.length ? `${SECTORS_DONE_ID}:::${names.join(",")}` : SECTORS_DONE_ID;
|
|
950
|
+
onChipClick({ ...chip, id });
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
onChipClick(chip);
|
|
954
|
+
};
|
|
919
955
|
const chips = message.chips ?? [];
|
|
920
956
|
const showMenuGrid = isBot && message.chipsActive && isRootMenuChips(chips);
|
|
921
957
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column" }, children: [
|
|
922
958
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: bubbleClass, children: isBot ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
923
959
|
"div",
|
|
924
960
|
{
|
|
961
|
+
ref: markdownRef,
|
|
925
962
|
className: chat_default.markdown,
|
|
926
963
|
dangerouslySetInnerHTML: { __html: renderMarkdown(message.content) },
|
|
927
964
|
onClick: handleMarkdownClick
|
|
@@ -996,7 +1033,7 @@ function MessageBubble({ message, onChipClick, onFeedback }) {
|
|
|
996
1033
|
{
|
|
997
1034
|
chips,
|
|
998
1035
|
disabled: !message.chipsActive,
|
|
999
|
-
onClick:
|
|
1036
|
+
onClick: handleChipClick
|
|
1000
1037
|
}
|
|
1001
1038
|
) : null
|
|
1002
1039
|
] });
|