bi-components-library 1.2.55 → 1.2.56

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.umd.js CHANGED
@@ -15,7 +15,7 @@ ${(e||"").replace(/\r\n/g,`
15
15
  `)}
16
16
  \`\`\``,Yr=e=>{const t=(e||"").replace(/\r\n/g,`
17
17
  `).trim(),a=t.match(/^```[a-zA-Z0-9_-]*\n([\s\S]*?)\n```$/);return a?`<pre><code>${ce(a[1]||"")}</code></pre>`:`<div style="white-space:pre-wrap;">${ce(t)}</div>`},Wr=e=>{const t=e.trim();if(!t)return{url:""};let a=null;try{a=new URL(t)}catch{try{a=new URL(`https://${t}`)}catch{return{url:t}}}const l=a.pathname.split("/").filter(Boolean),n=l.findIndex(s=>s==="report"),r=n>=0?l[n+1]:void 0,i=l[0]&&l[0].length<=5?l[0]:void 0,u=a.searchParams.get("agentId")||void 0;return{url:t,reportId:r,agentId:u,lang:i}},oc=e=>(e?.modules||[]).map((t,a)=>{const l=(t?.title||`模块${a+1}`).trim()||`模块${a+1}`,n=(t?.content||"").trim();return{title:l,content:n.length>0?n:`请补充:${l}`}}),zl=e=>(e?.modules||[]).map((t,a)=>{const l=(t?.title||`模块${a+1}`).trim()||`模块${a+1}`,n=(t?.markdown||"").trim(),r=(t?.content||"").trim()||(n?Yr(n):"");return{title:l,content:r.length>0?r:`请补充:${l}`,markdown:n}}),cc="https://sealseek-public-read.oss-cn-hangzhou.aliyuncs.com/file/website/kongzhuangtai.svg",dc=({host:e,reportListFetch:t,onSelect:a,onGoGenerate:l,onViewReport:n,hideCurrentSessionReport:r})=>{const i=e.dataset.key||"",u=e.dataset.nodeType||"report-url",[s,o]=w.useState(!1),[c,d]=w.useState(!1),[h,f]=w.useState(null),[y,E]=w.useState(""),[m,g]=w.useState("bottomLeft"),[v,b]=w.useState(0),x=w.useRef(0),C=w.useCallback(()=>e.closest('[data-type="variable"]'),[e]),A=w.useCallback(()=>{const U=C();if(!U)return{mode:"all",rawValue:"",signature:"all:"};const X=U.getAttribute("data-report-url")?.trim();if(X)return{mode:"all",rawValue:"",signature:`resolved:${X}`};const Z=(U.innerText||"").replace(/[\u200B\n]/g,"").trim();return/^https?:\/\//i.test(Z)?{mode:"precise",rawValue:Z,signature:`precise:${Z}`}:{mode:"all",rawValue:Z,signature:`all:${Z}`}},[C]),[I,N]=w.useState(()=>A()),S=w.useCallback(()=>{const U=A();N(X=>X.signature===U.signature?X:U)},[A]),O=w.useCallback(U=>{const X=U.trim();if(!X)return"";const Z=Wr(X);return Z.reportId?`report:${Z.reportId}`:`url:${X}`},[]),L=I.mode==="precise"?O(I.rawValue):"",F=w.useCallback(U=>L?U.filter(X=>O(X.url)===L):U,[O,L]),D=w.useCallback(()=>{if(!document.body.contains(e))return console.log("[RTE-REPORT][anchor] skip: host detached"),!1;const U=C();if(!U||!document.body.contains(U))return console.log("[RTE-REPORT][anchor] skip: chip missing"),!1;const X=U.getBoundingClientRect();if(X.width===0&&X.height===0)return console.log("[RTE-REPORT][anchor] skip: chipRect zero"),!1;const Z=e.getBoundingClientRect();if(Z.width===0&&Z.height===0)return console.log("[RTE-REPORT][anchor] skip: iconRect zero"),!1;const W=X.left-Z.left;console.log("[RTE-REPORT][anchor]",{chipLeft:X.left,chipWidth:X.width,iconLeft:Z.left,nextOffsetX:W,ts:performance.now().toFixed(1)}),b(W);const le=240,se=window.innerHeight-X.bottom;return g(se<le?"topLeft":"bottomLeft"),!0},[C,e,s]),_=w.useCallback(async()=>{if(Date.now()-x.current>200){console.log("[RTE-REPORT] openDropdown skip: not user-initiated");return}if(!D()){console.log("[RTE-REPORT] openDropdown skip: anchor unavailable");return}document.dispatchEvent(new CustomEvent("rte-report-dropdown-opening",{detail:e})),o(!0),d(!0);try{const U=await t({nodeKey:i,nodeType:u}),X=r?U.tabs.filter(W=>W.key!=="currentConversationReports"):U.tabs,Z={...U,tabs:X};f(Z),X.length>0&&E(X[0].key)}catch{}finally{d(!1)}},[r,i,u,t,D]);w.useEffect(()=>{const U=C();if(!U)return;if(U.getAttribute("data-report-url")){e.classList.remove("hidden");return}const X=(U.innerText||"").replace(/[\u200B\n]/g,"").trim().length>0;e.classList.toggle("hidden",X)},[C,e,s,I.signature]),w.useEffect(()=>{S();const U=C();if(!U)return;const X=new MutationObserver(()=>{S()});return X.observe(U,{attributes:!0,attributeFilter:["data-report-url","data-report-name"],childList:!0,characterData:!0,subtree:!0}),U.addEventListener("input",S),()=>{X.disconnect(),U.removeEventListener("input",S)}},[C,e,S]),w.useEffect(()=>{const U=C();if(!U)return;const X=Z=>{Z.target.closest(".rte-report-chip-clear-host")||(U.getAttribute("data-report-url")&&(Z.preventDefault(),Z.stopPropagation(),window.getSelection()?.removeAllRanges()),!s&&(x.current=Date.now(),_()))};return U.addEventListener("mousedown",X,!0),()=>{U.removeEventListener("mousedown",X,!0)}},[C,e,s,_,i]),w.useEffect(()=>{const U=X=>{X.detail!==e&&o(!1)};return document.addEventListener("rte-report-dropdown-opening",U),()=>document.removeEventListener("rte-report-dropdown-opening",U)},[e]),w.useEffect(()=>{if(!s)return;const U=()=>{document.body.contains(e)||o(!1)};U();const X=window.setInterval(U,200);return()=>window.clearInterval(X)},[s,e]),w.useEffect(()=>{const U=X=>{const Z=X.detail;Z?.exceptKey!==i&&(!Z||!Z.key||Z.key===i)&&o(!1)};return document.addEventListener("rte-report-dropdown-force-close",U),()=>document.removeEventListener("rte-report-dropdown-force-close",U)},[i]),w.useLayoutEffect(()=>{s&&(console.log("[RTE-REPORT][sig-effect] layout sync",{signature:I.signature,ts:performance.now().toFixed(1)}),D())},[s,e,I.signature,D]),w.useEffect(()=>{if(!s)return;const U=C();if(!U)return;console.log("[RTE-REPORT][ro] attach observer to chip",{chipWidth:U.getBoundingClientRect().width});const X=new ResizeObserver(Z=>{const W=Z[0]?.contentRect;console.log("[RTE-REPORT][ro] chip resize fired",{width:W?.width,ts:performance.now().toFixed(1)}),mt.flushSync(()=>{D()})});return X.observe(U),()=>{console.log("[RTE-REPORT][ro] detach observer"),X.disconnect()}},[s,C,D]),w.useEffect(()=>{if(!s)return;const U=X=>{const Z=X.target;e.closest('[data-type="variable"]')?.contains(Z)||Z.closest(".rte-report-dropdown-overlay")||o(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[s,e]);const T=w.useCallback(U=>{a(i,u,U),o(!1)},[i,u,a]),B=w.useCallback((U,X)=>{U.stopPropagation(),n?(n(X),o(!1)):window.open(X.viewUrl||X.url,"_blank")},[n]),V=L&&h&&h.tabs.find(U=>F(U.items).length>0)?.key||"";w.useEffect(()=>{!s||!V||E(U=>U===V?U:V)},[s,V,I.signature]);const $=h?.tabs.find(U=>U.key===y),H=$?F($.items):[],k=w.useRef(null),G=w.useCallback(U=>{const X=U.currentTarget;X.classList.add("is-scrolling"),k.current&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{X.classList.remove("is-scrolling"),k.current=null},300)},[]),j=w.useMemo(()=>({offset:[v,m==="bottomLeft"?4:-4],overflow:{adjustX:!1,adjustY:!1}}),[v,m]),P=z.jsx("div",{className:"rte-report-dropdown-panel",onMouseDown:U=>U.preventDefault(),children:c?z.jsx("div",{className:"rte-report-dropdown-loading",children:z.jsx(fe.Spin,{size:"small"})}):h?z.jsxs(z.Fragment,{children:[h.tabs.length>1&&z.jsx("div",{className:"rte-report-dropdown-tab-outer",children:z.jsx("div",{className:"rte-report-dropdown-tab-inner",children:h.tabs.map(U=>z.jsx("div",{className:`rte-report-dropdown-tab-item${y===U.key?" active":""}`,onMouseDown:()=>E(U.key),children:U.label},U.key))})}),z.jsx("div",{className:"rte-report-dropdown-list",onScroll:G,children:!$||H.length===0?z.jsxs("div",{className:"rte-report-dropdown-empty",children:[z.jsx("img",{className:"rte-report-dropdown-empty-img",src:cc,alt:""}),z.jsxs("div",{className:"rte-report-dropdown-empty-text",children:[z.jsx("span",{className:"rte-report-dropdown-empty-label",children:L?"未找到匹配的报告":"暂无生成的报告"}),$?.agentType!=null&&l&&z.jsx("span",{className:"rte-report-dropdown-empty-link",onMouseDown:()=>{l($.agentType),o(!1)},children:"去生成"})]})]}):H.map((U,X)=>z.jsxs("div",{className:"rte-report-dropdown-item",onMouseDown:()=>T(U),children:[z.jsx("span",{className:"rte-report-dropdown-item-name",title:U.name,children:U.name}),z.jsxs("span",{className:"rte-report-dropdown-item-action",onMouseDown:Z=>{Z.stopPropagation(),B(Z,U)},children:[z.jsx("i",{className:"iconfont icon-chakanbaogao"}),"查看报告"]})]},`${U.url}-${X}`))})]}):null});return mt.createPortal(z.jsx("div",{className:"rte-report-dropdown-trigger-wrapper",contentEditable:!1,onClick:U=>{U.preventDefault(),U.stopPropagation()},children:z.jsx(fe.Popover,{content:P,trigger:[],open:s,placement:m,align:j,autoAdjustOverflow:!1,getPopupContainer:()=>document.body,overlayClassName:"rte-report-dropdown-overlay",arrow:!1,children:z.jsx("i",{className:"iconfont icon-qiehuan-xiayizhang rte-report-dropdown-icon "})})}),e)},fc=(e,t,a,l,n,r,i)=>{const[u,s]=w.useState([]),o=w.useRef(t),c=w.useRef(a),d=w.useRef(l),h=w.useRef(n),f=w.useRef(i);o.current=t,c.current=a,d.current=l,h.current=n,f.current=i;const y=w.useRef(new WeakSet),E=w.useCallback(()=>{const m=e.current;if(!m||!o.current){s([]);return}const g=m.querySelectorAll(".rte-report-dropdown-host"),v=[];g.forEach(b=>{const x=b,C=x.getAttribute("data-key");if(C){if(!y.current.has(x)){for(;x.firstChild;)x.removeChild(x.firstChild);y.current.add(x)}v.push(z.jsx(dc,{host:x,reportListFetch:o.current,onSelect:c.current,onGoGenerate:d.current,onViewReport:h.current,hideCurrentSessionReport:f.current},`report-dropdown-${C}-${x.getAttribute("data-node-type")}`))}}),s(v)},[e]);return w.useEffect(()=>{if(!t)return;const m=e.current;if(!m)return;const g=new MutationObserver(v=>{let b=!1;for(const x of v)if(x.type==="childList"){let C=!1;if(x.addedNodes.forEach(A=>{if(A.nodeType===Node.ELEMENT_NODE){const I=A;(I.classList?.contains("rte-report-dropdown-host")||I.querySelector?.(".rte-report-dropdown-host"))&&(C=!0)}}),x.removedNodes.forEach(A=>{if(A.nodeType===Node.ELEMENT_NODE){const I=A;(I.classList?.contains("rte-report-dropdown-host")||I.querySelector?.(".rte-report-dropdown-host"))&&(C=!0)}}),C){b=!0;break}}b&&E()});return g.observe(m,{childList:!0,subtree:!0}),()=>g.disconnect()},[e,t,E]),w.useEffect(()=>{if(!t)return;const m=requestAnimationFrame(()=>{E()});return()=>cancelAnimationFrame(m)},[t,E,r]),u},pc=({host:e,onClear:t})=>{const a=w.useCallback(l=>{l.preventDefault(),l.stopPropagation();const n=e.closest('[data-type="variable"]');n&&t(n)},[e,t]);return mt.createPortal(z.jsx("span",{className:"rte-report-chip-clear-icon",contentEditable:!1,onMouseDown:a,title:"清除",children:z.jsx(bt.CloseCircleFilled,{})}),e)},hc=(e,t,a)=>{const[l,n]=w.useState([]),r=w.useRef(t);r.current=t;const i=w.useCallback(o=>{r.current(o)},[]),u=w.useRef(new WeakSet),s=w.useCallback(()=>{const o=e.current;if(!o){n([]);return}const c=o.querySelectorAll(".rte-report-chip-clear-host"),d=[];c.forEach(h=>{const f=h;if(!u.current.has(f)){for(;f.firstChild;)f.removeChild(f.firstChild);u.current.add(f)}const y=f.getAttribute("data-key")||"",E=f.getAttribute("data-node-type")||"",m=f.getAttribute("data-multi-key")||"";d.push(z.jsx(pc,{host:f,onClear:i},`report-clear-${m?`${m}:`:""}${y}-${E}`))}),n(d)},[e,i]);return w.useEffect(()=>{const o=e.current;if(!o)return;const c=new MutationObserver(d=>{let h=!1;for(const f of d){if(f.type!=="childList")continue;const y=E=>{if(E.nodeType!==Node.ELEMENT_NODE)return!1;const m=E;return m.classList?.contains("rte-report-chip-clear-host")||!!m.querySelector?.(".rte-report-chip-clear-host")};if(f.addedNodes.forEach(E=>{y(E)&&(h=!0)}),f.removedNodes.forEach(E=>{y(E)&&(h=!0)}),h)break}h&&s()});return c.observe(o,{childList:!0,subtree:!0}),()=>c.disconnect()},[e,s]),w.useEffect(()=>{const o=requestAnimationFrame(()=>{s()});return()=>cancelAnimationFrame(o)},[s,a]),l};function bc(e){const t=e.dataset.key||"",a=e.getAttribute("data-node-type")||"",l=e.dataset.multiKey||"";e.removeAttribute("data-report-url"),e.removeAttribute("data-report-name"),e.classList.remove("rte-report-name-chip"),e.contentEditable="true";const n=e.querySelector(".rte-report-dropdown-host");n?.parentNode&&n.parentNode.removeChild(n);const r=e.querySelector(".rte-report-chip-clear-host");for(r?.parentNode&&r.parentNode.removeChild(r);e.firstChild;)e.removeChild(e.firstChild);if(e.appendChild(document.createTextNode("​")),e.classList.add("show-placeholder"),n)n.classList.remove("hidden","rte-report-dropdown-host-quiet"),n.style.display="",n.style.visibility="",e.appendChild(n);else{const i=document.createElement("span");i.contentEditable="false",i.className="rte-report-dropdown-host",i.dataset.key=t,i.dataset.nodeType=a,l&&(i.dataset.multiKey=l),e.appendChild(i)}return e.classList.add("rte-variable-with-icon"),{nodeKey:t,nodeType:a,multiKey:l}}function Vl(e){if(e.querySelector(".rte-report-chip-clear-host"))return;const t=document.createElement("span");t.contentEditable="false",t.className="rte-report-chip-clear-host";const a=e.dataset.key||"",l=e.getAttribute("data-node-type")||"",n=e.dataset.multiKey||"";t.dataset.key=a,l&&(t.dataset.nodeType=l),n&&(t.dataset.multiKey=n),e.appendChild(t)}const Gl="rte-resolve-tokens-invalidate";function ca(e){document.dispatchEvent(new CustomEvent(Gl,{detail:e}))}function mc(e,t,a=[]){const l=w.useRef(t);w.useEffect(()=>{l.current=t},[t]),w.useEffect(()=>{const n=e.current;if(!n)return;const r=i=>{const u=i.target?.closest?.('[data-type="variable"][data-node-type="markdown-name"]');if(!u||!n.contains(u))return;const s=u.dataset.key;if(!s)return;const o=u.innerText.replace(/[\u200B\n]/g,"").trim();requestAnimationFrame(()=>{u.isConnected&&l.current(s,o)})};return n.addEventListener("focusout",r,!1),()=>{n.removeEventListener("focusout",r,!1)}},[e])}function vc(e,t,a=[]){w.useLayoutEffect(()=>{if(!e.current)return;const l=new Map,n=window.setTimeout(()=>{if(!e.current)return;l.forEach((u,s)=>s.removeEventListener("blur",u,!1)),l.clear();const r=e.current.querySelectorAll('[data-type="variable"][data-node-type="markdown"]'),i=u=>{u.stopPropagation(),u.stopImmediatePropagation();const s=u.target?.closest('[data-type="variable"][data-node-type="markdown"]');if(!s||!e.current||!e.current.contains(s))return;const o=s.dataset.key;if(!o)return;const c=s.innerText.replace(/[\u200B\n]/g,"").trim();t(o,c)};r.forEach(u=>{u.addEventListener("blur",i,!1),l.set(u,i)})},0);return()=>{window.clearTimeout(n),l.forEach((r,i)=>i.removeEventListener("blur",r,!1)),l.clear()}},[e,t,...a])}const gc=({config:e,messageApi:t,activeBatchKey:a,activeFileKey:l,activeBatchStartIndex:n,setActiveFileKey:r,setActiveBatchKey:i,setActiveBatchStartIndex:u,setFiles:s})=>{const o=w.useCallback(d=>{if(!d.target.files){d.target&&(d.target.value=""),r(null),i(null),u(null);return}const h=10*1024*1024,f=E=>E.type?.startsWith("image/")?!0:/\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(E.name||""),y=E=>f(E)&&E.size>h;if(a&&d.target.files&&d.target.files.length>0){const E=a,m=e.find(x=>x.type==="upload"&&x.key===E),g=Array.from(d.target.files),v=g.filter(x=>!y(x)),b=g.length-v.length;if(b>0&&t.error(`已自动过滤 ${b} 张超过 10MB 的图片,仅允许上传 10MB 以内图片`),m&&typeof m.maxCount=="number"&&typeof m.minCount=="number"){const x=m.maxCount,C=typeof n=="number"?n:0;s(A=>{const I={...A};let N=Math.min(Math.max(C,0),x-1);for(const S of v){for(;N<x&&I[`${E}-${N}`]!=null;)N+=1;if(N>=x)break;I[`${E}-${N}`]=S,N+=1}return I})}}else if(l&&d.target.files[0]){const E=d.target.files[0],m=l;y(E)?t.error("图片大小不能超过 10MB(仅允许上传 10MB 以内图片)"):s(g=>({...g,[m]:E}))}d.target&&(d.target.value=""),r(null),i(null),u(null)},[a,n,l,e,t,i,u,r,s]),c=w.useCallback(d=>{s(h=>{const f={...h};return delete f[d],f})},[s]);return{handleFileChange:o,handleRemoveFile:c}};function Ec(e){const t=e.trim();try{const l=new URL(t);if(l.protocol==="http:"||l.protocol==="https:")return t}catch{}const a=t.match(/https?:\/\/[^\s\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]+/);return a?a[0]:t}function yc(e){return new Promise((t,a)=>{const l=document.createElement("video"),n=URL.createObjectURL(e);l.preload="auto",l.muted=!0,l.src=n,l.onloadeddata=()=>{l.currentTime=0},l.onseeked=()=>{try{const r=document.createElement("canvas");r.width=l.videoWidth,r.height=l.videoHeight;const i=r.getContext("2d");if(!i)return URL.revokeObjectURL(n),a(new Error("canvas context unavailable"));i.drawImage(l,0,0,r.width,r.height);const u=r.toDataURL("image/jpeg",.7);URL.revokeObjectURL(n),t(u)}catch(r){URL.revokeObjectURL(n),a(r)}},l.onerror=()=>{URL.revokeObjectURL(n),a(new Error("video load error"))}})}function Tc(e){return new Promise(t=>{const a=document.createElement("video");a.crossOrigin="anonymous",a.preload="auto",a.muted=!0,a.playsInline=!0,a.src=e;const l=setTimeout(()=>{n(),t("")},1e4),n=()=>{clearTimeout(l),a.onloadeddata=null,a.onseeked=null,a.onerror=null};a.onloadeddata=()=>{a.currentTime=0},a.onseeked=()=>{try{const r=document.createElement("canvas");r.width=a.videoWidth||320,r.height=a.videoHeight||180;const i=r.getContext("2d");if(i){i.drawImage(a,0,0,r.width,r.height);const u=r.toDataURL("image/jpeg",.7);n(),t(u)}else n(),t("")}catch{n(),t("")}},a.onerror=()=>{n(),t("")}})}function xc(e,t,a,l,n=[]){const r=w.useRef(a);r.current=a;const i=w.useCallback(async(u,s)=>{if(!t||!s.trim())return;const o=Ec(s);l(f=>({...f,[u]:{status:"loading",progress:0}}));const c=2*Math.PI*6.5;let d=0;const h=setInterval(()=>{d=Math.min(d+Math.random()*15+5,90);const f=e.current?.querySelector(`[data-type="video-url"][data-key="${u}"] .video-upload-progress-ring circle:last-child`);f&&f.setAttribute("stroke-dashoffset",String(c*(1-d/100)))},400);try{const f=await t({url:o});if(clearInterval(h),l(y=>({...y,[u]:{status:"success",videoUrl:f.videoUrl,thumbnail:f.thumbnail||"",fileName:o}})),!f.thumbnail&&f.videoUrl){const y=`/api/download-report-pdf?url=${encodeURIComponent(f.videoUrl)}`;Tc(y).then(E=>{E&&l(m=>{const g=m[u];return!g||g.status!=="success"?m:{...m,[u]:{...g,thumbnail:E}}})})}}catch(f){clearInterval(h),l(y=>({...y,[u]:{status:"error",errorMsg:f instanceof Error?f.message:"解析失败"}}))}},[t,l,e]);w.useEffect(()=>{const u=e.current;if(!u||!t)return;const s=c=>{const d=c.target?.closest?.('[data-node-type="video-url"]');if(!d)return;const h=d.dataset.key;h&&setTimeout(()=>{const f=(d.innerText||"").replace(/\u200B/g,"").trim();f&&i(h,f)},0)},o=c=>{const d=c.target?.closest?.('[data-node-type="video-url"]');if(!d)return;const h=d.dataset.key;if(!h)return;const f=r.current[h];if(f?.status==="success"||f?.status==="loading")return;const y=(d.innerText||"").replace(/\u200B/g,"").trim();y&&i(h,y)};return u.addEventListener("paste",s,!0),u.addEventListener("focusout",o,!0),()=>{u.removeEventListener("paste",s,!0),u.removeEventListener("focusout",o,!0)}},[e,t,i,...n])}function Cc(e,t,a){return w.useCallback(async(l,n)=>{if(!e)return;t(s=>({...s,[l]:{status:"loading",file:n,fileName:n.name,progress:0}}));const r=await yc(n).catch(()=>"");r&&t(s=>{const o=s[l];return!o||o.status!=="loading"?s:{...s,[l]:{...o,thumbnail:r}}});const i=2*Math.PI*6.5,u=s=>{const o=Math.min(Math.max(s,0),100),c=a.current?.querySelector(`[data-type="video-upload"][data-key="${l}"] .video-upload-progress-ring circle:last-child`);c&&c.setAttribute("stroke-dashoffset",String(i*(1-o/100)))};try{const s=await e(n,u);t(o=>({...o,[l]:{status:"success",videoUrl:s.videoUrl,thumbnail:s.thumbnail||r,file:n,fileName:n.name}}))}catch(s){t(o=>({...o,[l]:{status:"error",file:n,fileName:n.name,errorMsg:s instanceof Error?s.message:"上传失败"}}))}},[e,t,a])}function Sc(e,t,a,l){w.useEffect(()=>{const n=e.current;if(!n)return;const r=u=>{const s=u.target?.closest?.('[data-type="video-url"], [data-type="video-upload"]');if(!s)return;const o=s.dataset.key;if(!o)return;const c=t[o];c?.status==="success"&&c.videoUrl&&a({key:o,anchorEl:s,type:"video-preview"})},i=u=>{if(l)return;const s=u.target?.closest?.('[data-type="video-url"], [data-type="video-upload"]');if(!s)return;const o=u.relatedTarget;o?.closest?.(".rte-tooltip-overlay")||o&&s.contains(o)||a(null)};return n.addEventListener("mouseover",r,!0),n.addEventListener("mouseout",i,!0),()=>{n.removeEventListener("mouseover",r,!0),n.removeEventListener("mouseout",i,!0)}},[e,t,a,l])}const Ac=({config:e,editorRef:t,files:a,setFiles:l,multiVariableCounts:n,setMultiVariableCounts:r,reportAnalyzeState:i,setReportAnalyzeState:u,markdownAnalyzeState:s,setMarkdownAnalyzeState:o,markdownNameAnalyzeState:c,setMarkdownNameAnalyzeState:d,nodeValues:h,resolvedReportNamesRef:f})=>{const y=w.useRef({}),E=w.useRef({}),m=w.useRef({}),g=w.useRef(i),v=w.useRef(s),b=w.useRef(c),x=w.useCallback(I=>I.find(S=>S.type==="tag")?.text||null,[]),C=w.useRef(e),A=w.useRef(null);w.useEffect(()=>{E.current=a},[a]),w.useEffect(()=>{m.current=n},[n]),w.useEffect(()=>{g.current=i},[i]),w.useEffect(()=>{v.current=s},[s]),w.useEffect(()=>{b.current=c},[c]),w.useEffect(()=>{const I=x(C.current),N=x(e);if(I&&I!==N&&t.current){const S={};t.current.querySelectorAll('[data-type="variable"]').forEach(_=>{const T=_.dataset.key;if(!T)return;const B=_.getAttribute("data-node-type")||"";if(B==="report-url"){const $=_.getAttribute("data-report-url");$&&(S[`${T}__url`]=$);return}if(B==="markdown-name"){const $=_.innerText.replace(/[​\n]/g,"").trim();$&&(S[`${T}__name`]=$);return}const V=_.innerText.replace(/[​\n]/g,"").trim();V&&(S[T]=V)}),t.current.querySelectorAll('[data-type="select"]').forEach(_=>{const T=_.dataset.key;if(T){const B=(_.getAttribute("data-value")||"").trim();B&&(S[T]=B)}}),t.current.querySelectorAll('[data-type="searchable-select"]').forEach(_=>{const T=_.dataset.key;if(T){const B=(_.getAttribute("data-value")||"").trim();B&&(S[T]=B)}}),t.current.querySelectorAll('[data-type="textarea"]').forEach(_=>{const T=_.dataset.key;if(T){const B=_.value.replace(/[​]/g,"").trim();B&&(S[T]=B)}}),y.current[I]={variableValues:S,files:{...E.current},multiVariableCounts:{...m.current},reportAnalyzeState:{...g.current},markdownAnalyzeState:{...v.current},markdownNameAnalyzeState:{...b.current},resolvedReportNames:f?.current?{...f.current}:{}}}if(N&&y.current[N]){const S=y.current[N];A.current=S,l(S.files),r(S.multiVariableCounts),u(S.reportAnalyzeState),o(S.markdownAnalyzeState),d(S.markdownNameAnalyzeState),f&&(f.current={...S.resolvedReportNames}),ca({clearAll:!0})}else if(N){A.current=null;const S={};e.forEach(O=>{if(Ue(O.type)&&O.key){const L=h?.[O.key],F=Array.isArray(L)?L.filter(D=>String(D??"").trim().length>0):L;Array.isArray(F)&&F.length>0?S[O.key]=Math.min(F.length+1,O.maxCount??9):S[O.key]=1}}),r(S),l({}),u({}),o({}),d({}),f&&(f.current={}),ca({clearAll:!0})}else A.current=null,r({}),l({}),u({}),o({}),d({}),f&&(f.current={}),ca({clearAll:!0});C.current=e},[e,t,x,l,r,u,o,d,f]),w.useLayoutEffect(()=>{A.current&&t.current&&(t.current.__tempVariableValues=A.current.variableValues,setTimeout(()=>{A.current&&(A.current=null)},0))})},wc=e=>{const t={},a=e.current;return a&&(a.querySelectorAll('[data-type="variable"]').forEach(l=>{const n=l.dataset.key;if(!n)return;if(l.dataset.variableRender==="antd-textarea"){const u=(l.getAttribute("data-value")||"").trim();if(!u)return;try{const o=(decodeURIComponent(u)||"").replace(/\r\n/g,`
18
- `).trim();o&&(t[n]=o)}catch{const s=u.trim();s&&(t[n]=s)}return}const r=l.getAttribute("data-node-type")||"";if(r==="report-url"){const u=l.getAttribute("data-report-url");u&&(t[`${n}__url`]=u);return}const i=(l.innerText||"").replace(/​/g,"").replace(/\r\n/g,`
18
+ `).trim();o&&(t[n]=o)}catch{const s=u.trim();s&&(t[n]=s)}return}const r=l.getAttribute("data-node-type")||"";if(r==="report-url"){const u=l.getAttribute("data-report-url");if(u)t[`${n}__url`]=u;else{const s=(l.innerText||"").replace(/[\u200B\n]/g,"").trim();/^https?:\/\//i.test(s)&&(t[`${n}__url`]=s)}return}const i=(l.innerText||"").replace(/​/g,"").replace(/\r\n/g,`
19
19
  `).trim();i&&(r==="markdown-name"?t[`${n}__name`]=i:t[n]=i)}),a.querySelectorAll('[data-type="select"]').forEach(l=>{const n=l.dataset.key;if(!n)return;const r=(l.getAttribute("data-value")||"").trim();r&&(t[n]=r)}),a.querySelectorAll('[data-type="textarea"]').forEach(l=>{const n=l.dataset.key;if(!n)return;const r=l.value.replace(/[​]/g,"").trim();r&&(t[n]=r)}),a.querySelectorAll('[data-type="richtext"]').forEach(l=>{const n=l.dataset.key;if(!n)return;const r=l.getAttribute("data-node-type")||"";if(r==="report-module"||r==="markdown-module"){const u=Number.parseInt(l.getAttribute("data-module-index")||"0",10),s=(l.innerHTML||"").replace(/[​]/g,"").trim();t[`${n}__module_${Number.isFinite(u)?u:0}`]=s;return}const i=(l.textContent||"").replace(/[​]/g,"").trim();i&&(t[n]=i)}),a.querySelectorAll('[data-type="datepicker"]').forEach(l=>{const n=l.dataset.key;if(!n)return;const r=(l.getAttribute("data-value")||"").trim();r&&(t[n]=r)}),a.querySelectorAll('[data-type="number-input"]').forEach(l=>{const n=l.dataset.key;if(!n)return;const r=(l.value||"").trim();r&&(t[n]=r)}),a.querySelectorAll('[data-type="searchable-select"]').forEach(l=>{const n=l.dataset.key;if(!n)return;const r=(l.getAttribute("data-value")||"").trim();r&&(t[n]=r)}),a.querySelectorAll('[data-type="cascader"]').forEach(l=>{const n=l.dataset.key;if(!n)return;const r=(l.getAttribute("data-value")||"").trim();r&&(t[n]=r)})),t},_c=({reportAnalyze:e,markdownAnalyze:t,markdownNameAnalyze:a,reportAnalyzeState:l,setReportAnalyzeState:n,markdownAnalyzeState:r,setMarkdownAnalyzeState:i,markdownNameAnalyzeState:u,setMarkdownNameAnalyzeState:s,editorRef:o,reportAnalyzeRef:c,markdownAnalyzeRef:d,markdownNameAnalyzeRef:h,markdownAnalyzeStateRef:f,markdownNameAnalyzeStateRef:y,reportNameResolve:E,applyReportNameChipRef:m})=>{const g=w.useCallback(()=>wc(o),[o]),v=w.useRef(new Map),b=w.useRef(0),x=w.useCallback(D=>{b.current+=1;const _=b.current;return v.current.set(D,_),_},[]),C=w.useCallback((D,_)=>v.current.get(D)===_,[]);w.useEffect(()=>{const D=_=>{const T=_.detail;if(T){if("clearAll"in T&&T.clearAll){v.current.clear();return}if("keys"in T)for(const B of T.keys)v.current.delete(B)}};return document.addEventListener(Gl,D),()=>document.removeEventListener(Gl,D)},[]);const A=w.useCallback((D,_)=>{const T=(_||"").trim();if(!D)return;if(!T){n(H=>({...H,[D]:{status:"idle",modules:[],lastParsedUrl:void 0,error:void 0}}));return}if(E&&m&&!(o.current?.querySelector(`[data-type="variable"][data-key="${D}"]`)?.getAttribute("data-report-url")===T)){const G=x(D);E({url:T,nodeKey:D,nodeType:"report-url"}).then(({name:j,url:P})=>{C(D,G)&&m.current(D,j,P||T)}).catch(()=>{})}const B=l[D];if(B?.lastParsedUrl&&B.lastParsedUrl===T&&(B.status==="loading"||B.status==="success"))return;n(H=>({...H,[D]:{...H[D],status:"loading",error:void 0,lastParsedUrl:T}}));const V=Wr(T);(e||(async H=>({modules:[{title:"第1张:人群+场景直击图",content:`视觉要求:养宠人在客厅场景中,宠物(猫/狗)自然趴在旁;画面聚焦“人+宠+整洁氛围”。
20
20
  (reportId=${H.reportId||"unknown"}, agentId=${H.agentId||"1"})`},{title:"第2张:痛点放大对比图",content:"左侧:杂乱堆放、难清理;右侧:分区收纳、拿取方便。文案≤15字,绑定人群+场景+需求。"}]})))(V).then(H=>{const k=oc(H);if(o.current){const G=g();k.forEach((j,P)=>{G[`${D}__module_${P}`]=j.content}),o.current.__tempVariableValues=G}n(G=>({...G,[D]:{status:"success",error:void 0,lastParsedUrl:T,modules:k}}))}).catch(H=>{const k=H instanceof Error?H.message:String(H);n(G=>({...G,[D]:{...G[D]||{modules:[]},status:"error",error:k||"解析失败",lastParsedUrl:T,modules:[]}}))})},[g,o,e,l,n,E,m,x,C]),I=w.useCallback((D,_)=>{const T=(_||"").trim();if(!D)return;if(!T){i(G=>({...G,[D]:{status:"idle",modules:[],lastParsedText:void 0,error:void 0}}));return}const B=r[D];if(B?.lastParsedText&&B.lastParsedText===T&&B.status==="success")return;if(!t){const G=Gr(T),j=zl({modules:[{title:"内容",content:Yr(G),markdown:G}]});if(o.current){const P=g();j.forEach((U,X)=>{P[`${D}__module_${X}`]=U.content}),o.current.__tempVariableValues=P}i(P=>({...P,[D]:{status:"success",error:void 0,lastParsedText:T,modules:j}}));return}const V=f.current[D]?.status==="loading";V||i(G=>({...G,[D]:{...G[D],status:"loading",error:void 0,lastParsedText:T}}));const $=500,H=Date.now();setTimeout(()=>{t({text:T}).then(j=>{const P=zl(j),U=Date.now()-H,X=Math.max(0,$-U);setTimeout(()=>{if(o.current){const Z=g();P.forEach((W,le)=>{Z[`${D}__module_${le}`]=W.content}),o.current.__tempVariableValues=Z}i(Z=>({...Z,[D]:{status:"success",error:void 0,lastParsedText:T,modules:P}}))},X)}).catch(j=>{const P=j instanceof Error?j.message:String(j);i(U=>({...U,[D]:{...U[D]||{modules:[]},status:"error",error:P,lastParsedText:T}}))})},V?0:50)},[g,o,t,r,f,i]),N=w.useCallback((D,_)=>{const T=(_||"").trim();if(!D)return;if(!T){s(G=>({...G,[D]:{status:"idle",modules:[],lastParsedText:void 0,error:void 0}}));return}const B=y.current[D];if(B?.lastParsedText&&B.lastParsedText===T&&B.status==="success"||!a)return;const V=y.current[D]?.status==="loading";V||s(G=>({...G,[D]:{...G[D],status:"loading",error:void 0,lastParsedText:T}}));const $=500,H=Date.now();setTimeout(()=>{a({text:T}).then(j=>{const P=zl(j),U=Date.now()-H,X=Math.max(0,$-U);setTimeout(()=>{if(o.current){const Z=g();P.forEach((W,le)=>{Z[`${D}__module_${le}`]=W.content}),o.current.__tempVariableValues=Z}s(Z=>({...Z,[D]:{status:"success",error:void 0,lastParsedText:T,modules:P}}))},X)}).catch(j=>{const P=j instanceof Error?j.message:String(j);s(U=>({...U,[D]:{...U[D]||{modules:[]},status:"error",error:P,lastParsedText:T}}))})},V?0:50)},[g,o,a,y,s]);w.useEffect(()=>{c.current=A},[c,A]),w.useEffect(()=>{d.current=I},[d,I]),w.useLayoutEffect(()=>{h.current=N},[h,N]);const S=w.useCallback((D,_)=>{c.current(D,_)},[c]),O=w.useCallback((D,_)=>{d.current(D,_)},[d]),L=w.useCallback((D,_)=>{h.current(D,_)},[h]),F=w.useCallback((D,_,T="multi-variable")=>{const B=(_||"").trim();if(!B||!E||!m||!/^https?:\/\//i.test(B))return;const V=x(D);E({url:B,nodeKey:D,nodeType:T}).then(({name:$,url:H})=>{if(!C(D,V))return;const k=H||B;m.current(D,$,k),T==="multi-variable-select"&&c.current(D,k)}).catch(()=>{})},[E,m,c,x,C]);return{handleReportUrlBlur:S,handleMarkdownBlur:O,handleMarkdownNameBlur:L,handleMultiVariableNameResolve:F}},kc=({collapsed:e,collapseTransitionMs:t,contentRef:a,contentBodyRef:l,editorRef:n,debugIdRef:r,setCollapsedContentMaxHeightPx:i,setExpandedContentMaxHeightPx:u,setIsCollapseAnimating:s,effectiveConfig:o,files:c,multiVariableCounts:d,selectPortalsLength:h,datePickerPortalsLength:f,variablePortalsLength:y})=>{const E=w.useRef(""),m=w.useCallback(()=>{const v=l.current;if(!v)return;const b=Math.max(0,Math.ceil(v.scrollHeight||0));!Number.isFinite(b)||b<=0||u(x=>x===b?x:b)},[l,u]);w.useLayoutEffect(()=>{if(!e)return;const v=a.current,b=n.current;if(!(!v||!b))try{const x=b.getBoundingClientRect(),C=document.createRange();C.selectNodeContents(b);const A=Array.from(C.getClientRects());let I;if(A.length>0){const N=Math.min(...A.map(L=>L.top)),S=2;let O=0;for(const L of A)Math.abs(L.top-N)<=S&&(O=Math.max(O,L.bottom));I=O>0?Math.max(0,Math.ceil(O-x.top)):58}else{const N=window.getComputedStyle(b),S=Number.parseFloat(N.paddingTop)||0,O=Number.parseFloat(N.lineHeight)||34;I=Math.max(0,Math.ceil(S+O))||58}if(!Number.isFinite(I)||I<=0)return;i(N=>N===I?N:I)}catch{}},[e,a,n,o,c,d,h,f,y,i]),w.useLayoutEffect(()=>{if(!e)return;const v=a.current,b=l.current,x=n.current;if(!v)return;const C=()=>{v.scrollTop=0,v.scrollLeft=0,b&&(b.scrollTop=0,b.scrollLeft=0),x&&(x.scrollTop=0,x.scrollLeft=0)},I=(typeof t=="number"&&Number.isFinite(t)&&t>=0?t:260)+220;C();const N=D=>{D.preventDefault(),D.stopPropagation(),C()};v.addEventListener("wheel",N,{passive:!1}),v.addEventListener("touchmove",N,{passive:!1}),b&&(b.addEventListener("wheel",N,{passive:!1}),b.addEventListener("touchmove",N,{passive:!1}));const S=performance.now();let O=0;const L=D=>{C(),D-S<I&&(O=window.requestAnimationFrame(L))};O=window.requestAnimationFrame(L);const F=window.setTimeout(()=>{C()},I);return()=>{v.removeEventListener("wheel",N),v.removeEventListener("touchmove",N),b&&(b.removeEventListener("wheel",N),b.removeEventListener("touchmove",N)),window.cancelAnimationFrame(O),window.clearTimeout(F)}},[e,t,l,a,r,n]);const g=o.filter(v=>v.key&&v.type!=="report-module"&&v.type!=="markdown-module").map(v=>`${v.type}:${v.key}`).join("|");return g!==""&&E.current!==g&&(e||u(9999)),E.current=g,w.useEffect(()=>{if(e)return;const v=window.requestAnimationFrame(()=>{m();const b=window.setTimeout(()=>{m()},150);window.__rteSecondMeasureTimer=b});return()=>{window.cancelAnimationFrame(v);const b=window.__rteSecondMeasureTimer;b&&window.clearTimeout(b)}},[e,o,c,d,h,f,y,m]),w.useEffect(()=>{const v=typeof t=="number"&&Number.isFinite(t)&&t>=0?t:260;if(v<=0){s(!1);return}s(!0);const b=window.setTimeout(()=>s(!1),v);return()=>window.clearTimeout(b)},[e,t,s]),{measureExpandedContentHeight:m}},Nc=({config:e,editorRef:t,setIsEmpty:a,setIsFormValid:l})=>{w.useEffect(()=>{if(e.length>0){a(!1);return}const n=()=>{if(!t.current){a(!0);return}const i=t.current.textContent?.replace(/[\u200B\n]/g,"").trim()||"",u=t.current.querySelectorAll('[data-type="variable"]'),s=t.current.querySelectorAll('[data-type="upload"]');let o=!1;u.forEach(d=>{(d.textContent?.replace(/[\u200B\n]/g,"").trim()||"")&&(o=!0)}),s.forEach(d=>{d.querySelector(".upload-inner-wrapper.has-file")&&(o=!0)});const c=!i&&!o;a(c),e.length===0&&l(!c)};n();const r=new MutationObserver(n);return t.current&&r.observe(t.current,{childList:!0,subtree:!0,characterData:!0}),()=>{r.disconnect()}},[e,t,a,l])},Ic=({config:e,reportAnalyzeState:t,markdownAnalyzeState:a,markdownNameAnalyzeState:l})=>w.useMemo(()=>{if(e.length===0)return e;const n=[];let r=!1;for(const i of e){if(i.type==="markdown"&&i.key==="tableData"||(r&&i.type==="text"&&i.text?.startsWith(`
21
21
  `)?(n.push({...i,text:i.text.slice(1)}),r=!1):n.push(i)),i.type==="report-url"&&i.key){const u=t[i.key],s=u?.status??"idle",o=u?.modules??[];s==="loading"&&n.push({type:"text",className:"rte-report-parsing",text:`解析中...