You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
8.8 KiB
JavaScript
1 line
8.8 KiB
JavaScript
|
9 months ago
|
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6303],{2901:function(e,t,r){"use strict";r.r(t),r.d(t,{Artifacts:function(){return S},ArtifactsShareButton:function(){return b},HTMLPreview:function(){return C}});var n=r(57437),o=r(2265),s=r(59208),i=r(35499),a=r(84065),l=r(12637),c=r(84193),u=r(72495),d=r(59566),f=r(49111),h=r(98829),m=r(13894),x=r(65878),v=r(92944),g=r(75591),p=r(34307),j=r(99164),w=r.n(j);let C=(0,o.forwardRef)(function(e,t){let r=(0,o.useRef)(null),[s,i]=(0,o.useState)((0,a.x0)()),[l,c]=(0,o.useState)(600),[u,d]=(0,o.useState)("");(0,o.useEffect)(()=>{let e=e=>{let{id:t,height:r,title:n}=e.data;d(n),t==s&&c(r)};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[s]),(0,o.useImperativeHandle)(t,()=>({reload:()=>{i((0,a.x0)())}}));let f=(0,o.useMemo)(()=>{if(!e.autoHeight)return e.height||600;if("string"==typeof e.height)return e.height;let t=e.height||600;return l+40>t?t:l+40},[e.autoHeight,e.height,l]),h=(0,o.useMemo)(()=>{let t='<script>window.addEventListener("DOMContentLoaded", () => new ResizeObserver((entries) => parent.postMessage({id: \''.concat(s,"', height: entries[0].target.clientHeight}, '*')).observe(document.body))</script>");return e.code.includes("<!DOCTYPE html>")&&e.code.replace("<!DOCTYPE html>","<!DOCTYPE html>"+t),t+e.code},[e.code,s]);return(0,n.jsx)("iframe",{className:w()["artifacts-iframe"],ref:r,sandbox:"allow-forms allow-modals allow-scripts",style:{height:f},srcDoc:h,onLoad:()=>{(null==e?void 0:e.onLoad)&&e.onLoad(u)}},s)});function b(e){let{getCode:t,id:r,style:s,fileName:a}=e,[d,h]=(0,o.useState)(!1),[p,j]=(0,o.useState)(r),[w,C]=(0,o.useState)(!1),b=(0,o.useMemo)(()=>[location.origin,"#",g.y$.Artifacts,"/",p].join(""),[p]),S=e=>r?Promise.resolve({id:r}):fetch(g.L.Artifacts,{method:"POST",body:e}).then(e=>e.json()).then(e=>{let{id:t}=e;if(t)return{id:t};throw Error()}).catch(e=>{(0,x.CF)(m.ZP.Export.Artifacts.Error)});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"window-action-button",style:s,children:(0,n.jsx)(i.h,{icon:d?(0,n.jsx)(f.Z,{}):(0,n.jsx)(l.Z,{}),bordered:!0,title:m.ZP.Export.Artifacts.Title,onClick:()=>{d||(h(!0),S(t()).then(e=>{(null==e?void 0:e.id)&&(C(!0),j(null==e?void 0:e.id))}).finally(()=>h(!1)))}})}),w&&(0,n.jsx)("div",{className:"modal-mask",children:(0,n.jsx)(x.u_,{title:m.ZP.Export.Artifacts.Title,onClose:()=>C(!1),actions:[(0,n.jsx)(i.h,{icon:(0,n.jsx)(u.Z,{}),bordered:!0,text:m.ZP.Export.Download,onClick:()=>{(0,v.CP)(t(),"".concat(a||p,".html")).then(()=>C(!1))}},"download"),(0,n.jsx)(i.h,{icon:(0,n.jsx)(c.Z,{}),bordered:!0,text:m.ZP.Chat.Actions.Copy,onClick:()=>{(0,v.vQ)(b).then(()=>C(!1))}},"copy")],children:(0,n.jsx)("div",{children:(0,n.jsx)("a",{target:"_blank",href:b,children:b})})})})]})}function S(){let{id:e}=(0,s.UO)(),[t,r]=(0,o.useState)(""),[a,l]=(0,o.useState)(!0),[c,u]=(0,o.useState)(""),f=(0,o.useRef)(null);return(0,o.useEffect)(()=>{e&&fetch("".concat(g.L.Artifacts,"?id=").concat(e)).then(e=>{if(e.status>300)throw Error("can not get content");return e}).then(e=>e.text()).then(r).catch(e=>{(0,x.CF)(m.ZP.Export.Artifacts.Error)})},[e]),(0,n.jsxs)("div",{className:w().artifacts,children:[(0,n.jsxs)("div",{className:w()["artifacts-header"],children:[(0,n.jsx)("a",{href:g.Bv,target:"_blank",rel:"noopener noreferrer",children:(0,n.jsx)(i.h,{bordered:!0,icon:(0,n.jsx)(d.Z,{}),shadow:!0})}),(0,n.jsx)(i.h,{bordered:!0,style:{marginLeft:20},icon:(0,n.jsx)(h.Z,{}),shadow:!0,onClick:()=>{var e;return null===(e=f.current)||void 0===e?void 0:e.reload()}}),(0,n.jsx)("div",{className:w()["artifacts-title"],children:"NextChat Artifacts"}),(0,n.jsx)(b,{id:e,getCode:()=>t,fileName:c})]}),(0,n.jsxs)("div",{className:w()["artifacts-content"],children:[a&&(0,n.jsx)(p.Loading,{}),t&&(0,n.jsx)(C,{code:t,ref:f,autoHeight:!1,height:"100%",onLoad:e=>{u(e),l(!1)}})]})]})}},42896:function(e,t,r){"use strict";r.r(t),r.d(t,{Markdown:function(){return Z},MarkdownContent:function(){return k},Mermaid:function(){return S},PreCode:function(){return y}});var n=r(57437),o=r(28993);r(68128);var s=r(
|