wealth-alpha-chat-widget 1.0.8 → 1.0.9

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.mjs CHANGED
@@ -885,24 +885,43 @@ function isRootMenuChips(chips) {
885
885
  return chips.length > 0 && chips.every((c) => ROOT_MENU_CHIP_IDS.has(c.id));
886
886
  }
887
887
  var CARD_DISCLAIMER = "AI-assisted, educational only. Not financial advice. Consult a SEBI-registered advisor.";
888
+ var SECTOR_TOGGLE_PREFIX = "__portfolio_sector_toggle:::";
889
+ var SECTORS_DONE_ID = "__portfolio_sectors_done";
890
+ var escapeHtml = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
891
+ function collectSelectedSectors(root) {
892
+ return Array.from(
893
+ root.querySelectorAll(`.srow[data-chip^="${SECTOR_TOGGLE_PREFIX}"]`)
894
+ ).filter((row) => row.classList.contains("selected")).map((row) => (row.getAttribute("data-chip") ?? "").slice(SECTOR_TOGGLE_PREFIX.length)).filter(Boolean);
895
+ }
888
896
  function MessageBubble({ message, onChipClick, onFeedback }) {
889
897
  const isBot = message.role === "bot";
890
898
  const [rating, setRating] = useState(null);
899
+ const markdownRef = useRef(null);
900
+ const isSectorCard = isBot && message.content.includes(SECTOR_TOGGLE_PREFIX);
891
901
  const rate = (value) => {
892
902
  setRating(value);
893
903
  onFeedback?.(message.id, value);
894
904
  };
895
905
  const isCard = isBot && message.content.includes("<div");
896
906
  const bubbleClass = isBot ? `${chat_default.bubble} ${isCard ? chat_default.bubbleCard : chat_default.bubbleBot}` : `${chat_default.bubble} ${chat_default.bubbleUser}`;
907
+ const refreshSectorSummary = () => {
908
+ const root = markdownRef.current;
909
+ if (!root) return;
910
+ const names = collectSelectedSectors(root);
911
+ const summary = root.querySelector(".wa-sel-summary");
912
+ if (summary) {
913
+ const list = names.length ? names.map(escapeHtml).join(", ") : "\u2014";
914
+ summary.innerHTML = `<span class="chk">\u2705</span>Selected (<b>${names.length}</b>): <b>${list}</b>`;
915
+ }
916
+ };
897
917
  const handleMarkdownClick = (e) => {
898
- const row = e.target.closest(".srow[data-chip]");
899
- if (row) {
918
+ const toggleRow = e.target.closest(
919
+ `.srow[data-chip^="${SECTOR_TOGGLE_PREFIX}"]`
920
+ );
921
+ if (toggleRow) {
900
922
  e.preventDefault();
901
- const chipId = row.getAttribute("data-chip");
902
- if (chipId) {
903
- const label = row.querySelector(".nm")?.textContent?.trim() ?? "";
904
- onChipClick({ id: chipId, label });
905
- }
923
+ toggleRow.classList.toggle("selected");
924
+ refreshSectorSummary();
906
925
  return;
907
926
  }
908
927
  const anchor = e.target.closest("a");
@@ -910,12 +929,22 @@ function MessageBubble({ message, onChipClick, onFeedback }) {
910
929
  e.preventDefault();
911
930
  window.location.assign(anchor.href);
912
931
  };
932
+ const handleChipClick = (chip) => {
933
+ if (isSectorCard && chip.id === SECTORS_DONE_ID) {
934
+ const names = markdownRef.current ? collectSelectedSectors(markdownRef.current) : [];
935
+ const id = names.length ? `${SECTORS_DONE_ID}:::${names.join(",")}` : SECTORS_DONE_ID;
936
+ onChipClick({ ...chip, id });
937
+ return;
938
+ }
939
+ onChipClick(chip);
940
+ };
913
941
  const chips = message.chips ?? [];
914
942
  const showMenuGrid = isBot && message.chipsActive && isRootMenuChips(chips);
915
943
  return /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column" }, children: [
916
944
  /* @__PURE__ */ jsx("div", { className: bubbleClass, children: isBot ? /* @__PURE__ */ jsx(
917
945
  "div",
918
946
  {
947
+ ref: markdownRef,
919
948
  className: chat_default.markdown,
920
949
  dangerouslySetInnerHTML: { __html: renderMarkdown(message.content) },
921
950
  onClick: handleMarkdownClick
@@ -990,7 +1019,7 @@ function MessageBubble({ message, onChipClick, onFeedback }) {
990
1019
  {
991
1020
  chips,
992
1021
  disabled: !message.chipsActive,
993
- onClick: onChipClick
1022
+ onClick: handleChipClick
994
1023
  }
995
1024
  ) : null
996
1025
  ] });