@pickaxeproject/react 6.4.2 → 6.5.1

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.
Files changed (55) hide show
  1. package/dist/cjs/common/deploymentWebhooks.js +1 -0
  2. package/dist/cjs/common/pickaxeConfig.js +1 -0
  3. package/dist/cjs/components/Icons/upload-cloud.svg.js +1 -0
  4. package/dist/cjs/components/Pickaxe/Addons/Artifact/Renderer/SaveMenu.js +1 -1
  5. package/dist/cjs/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
  6. package/dist/cjs/components/Pickaxe/Chat/Input.js +1 -1
  7. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.js +1 -0
  8. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.js +1 -1
  9. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Renderer.js +1 -1
  10. package/dist/cjs/components/Pickaxe/common/PickaxeMessageParts/index.js +1 -1
  11. package/dist/cjs/components/Pickaxe/index.js +1 -1
  12. package/dist/cjs/hooks/pickaxe/useSubmitDocument.js +1 -1
  13. package/dist/cjs/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
  14. package/dist/cjs/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
  15. package/dist/cjs/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
  16. package/dist/cjs/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
  17. package/dist/cjs/src/common/deploymentWebhooks.d.ts +30 -0
  18. package/dist/cjs/src/common/pickaxeConfig.d.ts +3 -0
  19. package/dist/cjs/src/components/Pickaxe/Addons/Artifact/Renderer/SaveMenu.d.ts +5 -1
  20. package/dist/cjs/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.d.ts +18 -0
  21. package/dist/cjs/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.d.ts +6 -1
  22. package/dist/cjs/src/components/Pickaxe/common/PickaxeMarkdown/Renderer.d.ts +3 -1
  23. package/dist/cjs/src/hooks/pickaxe/useSubmitDocument.d.ts +4 -2
  24. package/dist/esm/common/deploymentWebhooks.js +1 -0
  25. package/dist/esm/common/pickaxeConfig.js +1 -0
  26. package/dist/esm/components/Icons/upload-cloud.svg.js +1 -0
  27. package/dist/esm/components/Pickaxe/Addons/Artifact/Renderer/SaveMenu.js +1 -1
  28. package/dist/esm/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
  29. package/dist/esm/components/Pickaxe/Chat/Input.js +1 -1
  30. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.js +1 -0
  31. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.js +1 -1
  32. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Renderer.js +1 -1
  33. package/dist/esm/components/Pickaxe/common/PickaxeMessageParts/index.js +1 -1
  34. package/dist/esm/components/Pickaxe/index.js +1 -1
  35. package/dist/esm/hooks/pickaxe/useSubmitDocument.js +1 -1
  36. package/dist/esm/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
  37. package/dist/esm/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
  38. package/dist/esm/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
  39. package/dist/esm/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
  40. package/dist/esm/src/common/deploymentWebhooks.d.ts +30 -0
  41. package/dist/esm/src/common/pickaxeConfig.d.ts +3 -0
  42. package/dist/esm/src/components/Pickaxe/Addons/Artifact/Renderer/SaveMenu.d.ts +5 -1
  43. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.d.ts +18 -0
  44. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.d.ts +6 -1
  45. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Renderer.d.ts +3 -1
  46. package/dist/esm/src/hooks/pickaxe/useSubmitDocument.d.ts +4 -2
  47. package/package.json +1 -1
  48. package/dist/cjs/components/Icons/arrow-up-right.svg.js +0 -1
  49. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/Audio.js +0 -1
  50. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/Html/HtmlModal.js +0 -1
  51. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/Html/index.js +0 -1
  52. package/dist/esm/components/Icons/arrow-up-right.svg.js +0 -1
  53. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/A/Audio.js +0 -1
  54. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/A/Html/HtmlModal.js +0 -1
  55. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/A/Html/index.js +0 -1
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js");const s="deployment_session_initialized",t="deployment_first_message_submitted",i=new Set,o=new Set,n=e=>{if(!e)return null;return e.trim()||null},r=(s,t)=>e.__awaiter(void 0,void 0,void 0,(function*(){var{studioId:i,userEmail:o}=t,r=e.__rest(t,["studioId","userEmail"]);const d=n(i),a=n(process.env.NEXT_PUBLIC_API_URL);if(!d||!a)return;const c=Object.assign({event:s,source:"v2-pickaxe-react",firedAt:(new Date).toISOString(),studioId:d,userEmail:n(o)},r);try{yield fetch(`${a}/fireWebhooks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:s,studioId:d,userEmail:n(o),giftedProducts:[],payload:c})})}catch(e){console.warn(`[px/react] failed to fire deployment webhook event "${s}"`,e)}}));exports.DEPLOYMENT_FIRST_MESSAGE_SUBMITTED_EVENT=t,exports.DEPLOYMENT_SESSION_INITIALIZED_EVENT=s,exports.fireDeploymentFirstMessageSubmittedWebhook=e=>{const s=n(e.sessionId);s&&i.has(s)&&(o.has(s)||(o.add(s),r(t,Object.assign(Object.assign({},e),{sessionId:s}))))},exports.fireDeploymentSessionInitializedWebhook=e=>{const t=n(e.sessionId);t&&!i.has(t)&&(i.add(t),r(s,Object.assign(Object.assign({},e),{sessionId:t})))};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=new Set(["class","style","sso","metadata"]),e=t=>Boolean(t)&&"object"==typeof t&&!Array.isArray(t),a=(e,a)=>{Object.entries(e).forEach((([e,o])=>{t.has(e)||e.startsWith("deployment-")||"function"!=typeof o&&void 0!==o&&(a[e]=o)}))};exports.getPickaxeConfigMetadata=t=>{if("undefined"==typeof window)return;const o=window.PickaxeConfig;if(!e(o))return;const s={};if(a(o,s),e(o.metadata)&&Object.assign(s,o.metadata),t){const n=o[t];e(n)&&(a(n,s),e(n.metadata)&&Object.assign(s,n.metadata))}return Object.keys(s).length>0?s:void 0};
@@ -0,0 +1 @@
1
+ "use strict";function e(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}Object.defineProperty(exports,"__esModule",{value:!0});var t,r,n,o=e(require("react"));function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a.apply(null,arguments)}var c=e=>o.createElement("svg",a({xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24"},e),t||(t=o.createElement("path",{d:"m16 16-4-4-4 4M12 12v9"})),r||(r=o.createElement("path",{d:"M20.39 18.39A5 5 0 0 0 18 9h-1.26A8 8 0 1 0 3 16.3"})),n||(n=o.createElement("path",{d:"m16 16-4-4-4 4"})));exports.default=c;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../Icons/save.svg.js"),t=require("../../../../Core/Menu/index.js"),a=require("../../../../Core/Menu/Button.js"),l=require("../../../../Core/Menu/List.js");exports.default=({variant:n="default",className:i,children:c,data:r,colors:x,onDownload:o,onSaveAsPDF:p,onSaveAsDOCX:d})=>e.jsxs(t.default,Object.assign({id:`save-artifact-${r.id}-${r.version}`},{children:[e.jsx(a.default,Object.assign({variant:n,className:i,style:{color:x.text}},{children:c})),e.jsx(l.default,Object.assign({width:"auto",className:"font-semibold p-1 text-sm",style:{backgroundColor:x.primary,color:x.text},border:`1px solid ${x.primary}`},{children:"text/markdown"===r.type?e.jsxs(e.Fragment,{children:[e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("text/markdown")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"Markdown"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:p},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:d},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"DOCX"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("text/plain")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TXT"]}))]}):"text/html"===r.type?e.jsxs(e.Fragment,{children:[e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("text/html")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"HTML"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:p},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]}))]}):"text/csv"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("text/csv")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"CSV"]})):"text/tab-separated-values"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("text/tab-separated-values")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TSV"]})):"image/svg+xml"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("image/svg+xml")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/pdf"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:p},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]})):"application/vnd.pxe.code"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("application/vnd.pxe.code")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),`${r.programmingLanguage||"Plain Text"}`]})):"application/vnd.pxe.mermaid"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("application/vnd.pxe.mermaid")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.react"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>o("application/vnd.pxe.react")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TSX"]})):null}))]}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../Icons/save.svg.js"),t=require("../../../../Icons/upload-cloud.svg.js"),a=require("../../../../Core/Menu/index.js"),l=require("../../../../Core/Menu/Button.js"),n=require("../../../../Core/Menu/List.js"),i=require("../../../../../hooks/pickaxe/usePickaxeContext.js");exports.default=({variant:c="default",className:o,children:r,data:x,colors:d,onDownload:p,onSaveAsPDF:m,onSaveAsDOCX:u,onSaveToKnowledgeBase:j,isSaveToKnowledgeBaseEnabled:b=!1,isSavingToKnowledgeBase:h=!1,isSavedToKnowledgeBase:k=!1})=>{const{translations:g}=i.usePickaxeContext(),f=(e,s)=>{var t;return null!==(t=null==g?void 0:g[e])&&void 0!==t?t:s},v=b&&j?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left disabled:cursor-not-allowed disabled:opacity-50",disabled:h||k,onClick:e=>{e.stopPropagation(),j()}},{children:[e.jsx(t.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),h?f("saving","Saving..."):k?f("saved","Saved"):f("save-to-knowledge-base","Save to Knowledge Base")]})):null;return e.jsxs(a.default,Object.assign({id:`save-artifact-${x.id}-${x.version}`},{children:[e.jsx(l.default,Object.assign({variant:c,className:o,style:{color:d.text}},{children:r})),e.jsxs(n.default,Object.assign({width:"auto",className:"font-semibold p-1 text-sm",style:{backgroundColor:d.primary,color:d.text},border:`1px solid ${d.primary}`},{children:["text/markdown"===x.type?e.jsxs(e.Fragment,{children:[e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("text/markdown")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"Markdown"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:m},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:u},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"DOCX"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("text/plain")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TXT"]}))]}):"text/html"===x.type?e.jsxs(e.Fragment,{children:[e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("text/html")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"HTML"]})),e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:m},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]}))]}):"text/csv"===x.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("text/csv")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"CSV"]})):"text/tab-separated-values"===x.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("text/tab-separated-values")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TSV"]})):"image/svg+xml"===x.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("image/svg+xml")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/pdf"===x.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:m},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]})):"application/vnd.pxe.code"===x.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("application/vnd.pxe.code")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),`${x.programmingLanguage||"Plain Text"}`]})):"application/vnd.pxe.mermaid"===x.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("application/vnd.pxe.mermaid")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.react"===x.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>p("application/vnd.pxe.react")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TSX"]})):null,v]}))]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("react"),a=require("../hooks/useArtifactContext.js"),n=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Scroll/hooks/useScroll.js"),r=require("../hooks/useArtifact.js"),l=require("react-to-print"),s=require("../../../common/PickaxeMarkdown/index.js"),c=require("../../../common/PickaxeMarkdown/Renderer.js"),d=require("react-syntax-highlighter"),p=require("../../../../../common/docx/index.js"),u=require("file-saver"),x=require("../../Scroll/ScrollLockView.js"),m=require("../../../../Icons/expand.svg.js"),y=require("../../../../Icons/shrink.svg.js"),v=require("../../../../Icons/collapse-new.svg.js"),f=require("../../../../Icons/copy-new.svg.js"),g=require("../../../../Icons/download-new.svg.js"),b=require("../../../common/PickaxeCopyButton.js"),h=require("../../../../Core/ScrollArea.js"),j=require("../../../../Core/TipContainer.js"),w=require("../MermaidRenderer.js"),C=require("./SaveMenu.js"),k=require("./ViewOptions.js"),T=require("csv-to-markdown-table"),F=require("copy-to-clipboard"),O=require("../../../../../common/cn.js");function A(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var S=A(u),D=A(T),N=A(F);const q="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co";exports.default=u=>{var T,F,A,E;const{artifacts:M,currentPopupType:_,currentArtifact:B,setCurrentArtifact:P}=a.useArtifactContext(),{onLoadArtifact:R}=r.useArtifact(),{styles:$,colors:z,translations:L}=n.usePickaxeContext(),[W,H]=o.useState("code"),[I,V]=o.useState(!1),X=o.useRef(),G=o.useRef(null),J=o.useRef(null),K=l.useReactToPrint({contentRef:X}),{scrollContainerRef:Q,scrollStartSession:U,scrollToBottom:Y,scrollEndSession:Z}=i.useScroll({auto:"code"===W}),ee=null!==(F=null===(T=u.styling)||void 0===T?void 0:T.styles)&&void 0!==F?F:$,te=null!==(E=null===(A=u.styling)||void 0===A?void 0:A.colors)&&void 0!==E?E:z,oe=o.useMemo((()=>{var e,t,o,a,n;if(!u.artifact&&!B)return null;const i=null!==(t=null===(e=u.artifact)||void 0===e?void 0:e.id)&&void 0!==t?t:null==B?void 0:B.id,r=null!==(a=null===(o=u.artifact)||void 0===o?void 0:o.version)&&void 0!==a?a:null==B?void 0:B.version;return null!==(n=M.find((e=>e.id===i&&e.version===r)))&&void 0!==n?n:null}),[B,M,u.artifact]),ae=o.useMemo((()=>oe?"text/csv"===oe.type?D.default(oe.content,",",!0):"text/tab-separated-values"===oe.type?D.default(oe.content,"\t",!0):null:null),[oe]),ne=o.useMemo((()=>(te.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==te?void 0:te.secondaryText]),ie=o.useMemo((()=>{const e=u.artifact&&(null==B?void 0:B.id)===u.artifact.id&&(null==B?void 0:B.version)===u.artifact.version;return"inline"===u.type&&("inline-form"===_?!!B:e)}),[B,_,u.type,u.artifact]);o.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){"inline"===u.type&&u.artifact&&(M.some((e=>u.artifact&&e.id===u.artifact.id&&e.version===u.artifact.version))||R({id:u.artifact.id,version:u.artifact.version}))}))}),[M,u.type,u.artifact]),o.useEffect((()=>{if("application/vnd.pxe.code"===(null==oe?void 0:oe.type)&&H("code"),"finished"!==(null==oe?void 0:oe.status))return H("code"),U(),void Y();Z(),"application/vnd.pxe.code"!==oe.type&&H("render")}),[null==oe?void 0:oe.status,null==oe?void 0:oe.type]),o.useEffect((()=>{var e;!J.current||"text/html"!==(null==oe?void 0:oe.type)&&"application/pdf"!==(null==oe?void 0:oe.type)&&"application/vnd.pxe.react"!==(null==oe?void 0:oe.type)||null===(e=J.current.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==oe.type?"HTML_CODE":"REACT_CODE",content:oe.content},q)}),[null==oe?void 0:oe.content,null==oe?void 0:oe.type]);const re=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!oe)return;if("text/html"===oe.type||"application/pdf"===oe.type){const e=oe.content,t=window.open("","_blank");return void(t&&(t.document.open(),t.document.write(e),t.document.close(),t.focus(),t.print()))}const e=W;"code"===e&&(H("render"),yield new Promise((e=>setTimeout(e,50)))),K(),"code"===e&&H(e)})),le=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!oe)return;const e=yield p.convertMarkdownToDocx(oe.content);p.downloadDocx(e,`${oe.title}.docx`)})),se=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!oe)return;let o={mimeType:"text/plain",extension:".txt"};switch(t){case"text/markdown":o={mimeType:"text/markdown",extension:".md"};break;case"text/html":o={mimeType:"text/html",extension:".html"};break;case"text/csv":o={mimeType:"text/csv",extension:".csv"};break;case"text/tab-separated-values":o={mimeType:"text/tab-separated-values",extension:".tsv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":o={mimeType:"image/svg+xml",extension:".svg"};break;case"application/pdf":o={mimeType:"application/pdf",extension:".pdf"};break;case"application/vnd.pxe.code":o={mimeType:`application/${oe.programmingLanguage||"text"};charset=utf-8`,extension:`.${oe.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":o={mimeType:"text/typescript",extension:".tsx"};break;default:o={mimeType:"text/plain",extension:".txt"}}let a=null;if("application/vnd.pxe.mermaid"===oe.type){const t=W;"code"===t&&(H("render"),yield new Promise((e=>setTimeout(e,50))));const o=null===(e=G.current)||void 0===e?void 0:e.querySelector("svg");o&&(a=(new XMLSerializer).serializeToString(o)),"code"===t&&H(t)}const n=new Blob([null!=a?a:oe.content],{type:o.mimeType});S.default(n,`${oe.title}${o.extension}`)})),ce=()=>{"inline"!==u.type||!u.artifact||ie?P(null):P({id:u.artifact.id,version:u.artifact.version})},de=ie||!_.startsWith("inline");return oe?t.jsxs("div",Object.assign({className:O.default("pxe-artifact-renderer flex flex-col","inline"===u.type&&!ie&&"min-h-[320px] mb-6",u.className),style:Object.assign(Object.assign({backgroundColor:te.secondary,color:te.secondaryText},"auto"!==_&&{borderRadius:ee.cornerRadius}),u.style)},{children:[t.jsxs("div",Object.assign({className:"flex items-center gap-4 justify-between px-4 py-3 shadow-sm"},{children:[t.jsxs("div",Object.assign({className:"pxe-artifact-create-header flex min-w-0 items-center gap-4"},{children:[de&&t.jsx(k.default,{type:oe.type,view:W,colors:te,onChange:H}),t.jsx("p",Object.assign({className:"w-[220px] max-w-full truncate text-[18px] font-semilight leading-tight",title:oe.title},{children:oe.title}))]})),"inline"===u.type&&!de&&t.jsx("div",Object.assign({className:"shrink-0"},{children:t.jsx("button",Object.assign({type:"button",style:{color:te.secondaryText},onClick:ce,title:(null==L?void 0:L.expand)||"Expand","aria-label":(null==L?void 0:L.expand)||"Expand artifact"},{children:ie?t.jsx(y.default,{className:"w-6 h-6 shrink-0"}):t.jsx(m.default,{className:"w-6 h-6 shrink-0"})}))}))]})),de&&t.jsx("div",Object.assign({className:"flex items-center justify-between border-y px-4 py-2.5",style:{borderColor:te.primary}},{children:t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100",style:{color:te.secondaryText},onClick:ce,title:"inline"===u.type?(null==L?void 0:L.collapse)||"Collapse":(null==L?void 0:L.close)||"Close","aria-label":"inline"===u.type?(null==L?void 0:L.collapse)||"Collapse artifact":(null==L?void 0:L.close)||"Close artifact"},{children:t.jsx(v.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100 disabled:cursor-not-allowed disabled:opacity-50",style:{color:te.secondaryText},disabled:I,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(oe)try{N.default(oe.content),V(!0),yield new Promise((e=>setTimeout(e,1500)))}finally{V(!1)}})),title:(null==L?void 0:L.copy)||"Copy","aria-label":(null==L?void 0:L.copy)||"Copy artifact content"},{children:t.jsx(f.default,{className:"h-[18px] w-[18px] shrink-0"})})),t.jsx(C.default,Object.assign({data:oe,colors:te,onDownload:se,onSaveAsPDF:re,onSaveAsDOCX:le,className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100"},{children:t.jsx("div",Object.assign({role:"button",className:"cursor-pointer",style:{color:te.secondaryText},title:(null==L?void 0:L.save)||"Download","aria-label":(null==L?void 0:L.save)||"Download artifact content"},{children:t.jsx(g.default,{className:"h-6 w-6 shrink-0"})}))}))]}))})),t.jsx("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:t.jsxs(h.default,Object.assign({ref:Q,innerClassName:"flex-grow w-full"},{children:["render"===W&&"application/vnd.pxe.code"!==oe.type?t.jsx("div",Object.assign({ref:X,className:O.default("p-4 pb-6 flex-grow flex flex-col","text/html"===oe.type&&"p-0","text/csv"===oe.type&&"p-0","application/pdf"===oe.type&&"p-0","application/vnd.pxe.react"===oe.type&&"p-0")},{children:"text/markdown"===oe.type||"text/csv"===oe.type||"text/tab-separated-values"===oe.type||"image/svg+xml"===oe.type?t.jsx(s.PickaxeMarkdown,Object.assign({theme:ee.theme,colors:te},{children:t.jsx(c.PickaxeMarkdownRenderer,{value:null!=ae?ae:oe.content,className:O.default("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full",("text/csv"===oe.type||"text/tab-separated-values"===oe.type)&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===oe.type?t.jsx(w.default,{ref:G,id:`mermaid-${oe.id}-${oe.version}`,data:oe.content}):"text/html"===oe.type||"application/pdf"===oe.type||"application/vnd.pxe.react"===oe.type?t.jsx("iframe",Object.assign({ref:J,title:oe.title,src:`${q}/${"application/vnd.pxe.react"!==oe.type?"html":"react"}?theme=${ne?"dark":"light"}&bg=${te.secondary}&accent=${te.accent}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==te?void 0:te.secondary},loading:"lazy",allow:"fullscreen; camera; microphone; gyroscope; accelerometer; geolocation; clipboard-write; autoplay",sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-popups-to-escape-sandbox allow-pointer-lock allow-popups allow-modals allow-orientation-lock allow-presentation",onLoad:e=>{const t=e.target;setTimeout((()=>{var e;try{null===(e=t.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==oe.type?"HTML_CODE":"REACT_CODE",content:oe.content},q)}catch(e){console.error("Error sending message to iframe:",e)}}),100),Y()}},{children:(null==L?void 0:L["iframe-artifact-fallback"])||"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t.jsx(d.Prism,Object.assign({PreTag:"div",language:"text/markdown"===oe.type?"markdown":"text/html"===oe.type||"image/svg+xml"===oe.type?"xml":"application/vnd.pxe.react"===oe.type?"typescript":oe.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==te?void 0:te.secondaryText},ne&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"}),'pre[class*="language-"]':Object.assign(Object.assign({color:null==te?void 0:te.secondaryText},ne&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",borderRadius:"0.3em",minWidth:0,paddingLeft:"1em",paddingRight:"1em",paddingBottom:"2em",background:null==te?void 0:te.secondary}),':not(pre) > code[class*="language-"]':{background:null==te?void 0:te.secondary,padding:".1em",borderRadius:".3em"},comment:{color:"#7C7C7C"},prolog:{color:"#7C7C7C"},doctype:{color:"#7C7C7C"},cdata:{color:"#7C7C7C"},punctuation:{color:"#c5c8c6"},".namespace":{opacity:".7"},property:{color:"#96CBFE"},keyword:{color:"#96CBFE"},tag:{color:"#96CBFE"},"class-name":{color:"#FFFFB6"},boolean:{color:"#99CC99"},constant:{color:"#99CC99"},symbol:{color:"#f92672"},deleted:{color:"#f92672"},number:{color:"#FF73FD"},selector:{color:"#A8FF60"},"attr-name":{color:"#A8FF60"},string:{color:"#A8FF60"},char:{color:"#A8FF60"},builtin:{color:"#A8FF60"},inserted:{color:"#A8FF60"},variable:{color:"#C6C5FE"},operator:{color:"#EDEDED"},entity:{color:"#FFFFB6",cursor:"help"},url:{color:"#96CBFE"},".language-css .token.string":{color:"#87C38A"},".style .token.string":{color:"#87C38A"},atrule:{color:"#F9EE98"},"attr-value":{color:"#F9EE98"},function:{color:"#DAD085"},regex:{color:"#E9C062"},important:{color:null==te?void 0:te.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!ne&&{comment:{color:"#7D8B99"},prolog:{color:"#7D8B99"},doctype:{color:"#7D8B99"},cdata:{color:"#7D8B99"},punctuation:{color:"#4D4D4C"},property:{color:"#4078F2"},keyword:{color:"#8959A8"},tag:{color:"#8959A8"},"class-name":{color:"#D75F00"},boolean:{color:"#0086B3"},constant:{color:"#0086B3"},symbol:{color:"#990055"},deleted:{color:"#990000"},number:{color:"#005CC5"},selector:{color:"#63A35C"},"attr-name":{color:"#63A35C"},string:{color:"#50A14F"},char:{color:"#50A14F"},builtin:{color:"#50A14F"},inserted:{color:"#50A14F"},variable:{color:"#A626A4"},operator:{color:"#4D4D4C"},entity:{color:"#E45649",cursor:"help"},url:{color:"#4078F2"},".language-css .token.string":{color:"#50A14F"},".style .token.string":{color:"#50A14F"},atrule:{color:"#C18401"},"attr-value":{color:"#986801"},function:{color:"#005CC5"},regex:{color:"#D16969"},important:{color:null==te?void 0:te.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:oe.content})),t.jsx(x.default,{})]}))})),"inline"===u.type&&!ie&&t.jsxs("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t.jsx(j.default,Object.assign({id:`artifact-copy-${oe.id}-${oe.version}`,tip:(null==L?void 0:L.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:te.secondary,color:te.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(b.default,{color:te.secondaryText,text:oe.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t.jsx(j.default,Object.assign({id:`artifact-save-${oe.id}-${oe.version}`,tip:(null==L?void 0:L.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:te.secondary,color:te.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(C.default,Object.assign({data:oe,colors:te,onDownload:se,onSaveAsPDF:re,onSaveAsDOCX:le},{children:t.jsx("button",Object.assign({style:{color:te.secondaryText}},{children:t.jsx(g.default,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("react"),n=require("../hooks/useArtifactContext.js"),a=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Auth/hooks/useAuthContext.js"),r=require("../../Scroll/hooks/useScroll.js"),l=require("../hooks/useArtifact.js"),s=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),c=require("react-to-print"),d=require("../../../common/PickaxeMarkdown/index.js"),p=require("../../../common/PickaxeMarkdown/Renderer.js"),u=require("react-syntax-highlighter"),m=require("../../../../../common/docx/index.js"),x=require("file-saver"),y=require("../../Scroll/ScrollLockView.js"),v=require("../../../../Icons/expand.svg.js"),f=require("../../../../Icons/shrink.svg.js"),g=require("../../../../Icons/collapse-new.svg.js"),h=require("../../../../Icons/copy-new.svg.js"),b=require("../../../../Icons/download-new.svg.js"),w=require("../../../common/PickaxeCopyButton.js"),j=require("../../../../Core/ScrollArea.js"),k=require("../../../../Core/TipContainer.js"),C=require("../MermaidRenderer.js"),T=require("./SaveMenu.js"),S=require("./ViewOptions.js"),F=require("csv-to-markdown-table"),O=require("copy-to-clipboard"),A=require("../../../../../common/cn.js"),D=require("../../../../../common/error.js");function q(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var E=q(x),N=q(F),B=q(O);const M="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",_=e=>{var t;const o=null==e?void 0:e.trim().toLowerCase();if(!o)return".txt";return null!==(t={javascript:".js",js:".js",typescript:".ts",ts:".ts",python:".py",py:".py",json:".json",html:".html",css:".css",markdown:".md",md:".md",sql:".sql",shell:".sh",bash:".sh",sh:".sh",yaml:".yaml",yml:".yml",xml:".xml"}[o])&&void 0!==t?t:`.${o}`};exports.default=x=>{var F,O,q,P;const{artifacts:$,currentPopupType:R,currentArtifact:z,setCurrentArtifact:L}=n.useArtifactContext(),{onLoadArtifact:I}=l.useArtifact(),{contextId:W,pickaxeId:H,pickaxe:K,styles:V,colors:X,translations:U}=a.usePickaxeContext(),{isLoggedIn:G,token:J}=i.useAuthContext(),Q=s.useSubmitDocument(),[Y,Z]=o.useState("code"),[ee,te]=o.useState(!1),[oe,ne]=o.useState(!1),[ae,ie]=o.useState(!1),re=o.useRef(),le=o.useRef(null),se=o.useRef(null),ce=c.useReactToPrint({contentRef:re}),{scrollContainerRef:de,scrollStartSession:pe,scrollToBottom:ue,scrollEndSession:me}=r.useScroll({auto:"code"===Y}),xe=null!==(O=null===(F=x.styling)||void 0===F?void 0:F.styles)&&void 0!==O?O:V,ye=null!==(P=null===(q=x.styling)||void 0===q?void 0:q.colors)&&void 0!==P?P:X,ve=o.useMemo((()=>{var e,t,o,n,a;if(!x.artifact&&!z)return null;const i=null!==(t=null===(e=x.artifact)||void 0===e?void 0:e.id)&&void 0!==t?t:null==z?void 0:z.id,r=null!==(n=null===(o=x.artifact)||void 0===o?void 0:o.version)&&void 0!==n?n:null==z?void 0:z.version;return null!==(a=$.find((e=>e.id===i&&e.version===r)))&&void 0!==a?a:null}),[z,$,x.artifact]),fe=o.useMemo((()=>ve?"text/csv"===ve.type?N.default(ve.content,",",!0):"text/tab-separated-values"===ve.type?N.default(ve.content,"\t",!0):null:null),[ve]),ge=o.useMemo((()=>(ye.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==ye?void 0:ye.secondaryText]),he=o.useMemo((()=>{const e=x.artifact&&(null==z?void 0:z.id)===x.artifact.id&&(null==z?void 0:z.version)===x.artifact.version;return"inline"===x.type&&("inline-form"===R?!!z:e)}),[z,R,x.type,x.artifact]),be=o.useMemo((()=>ve?(e=>{switch(e.type){case"text/markdown":return{extension:".md",mimeType:"text/markdown",content:e.content};case"text/html":return{extension:".html",mimeType:"text/html",content:e.content};case"text/csv":return{extension:".csv",mimeType:"text/csv",content:e.content};case"text/tab-separated-values":return{extension:".tsv",mimeType:"text/tab-separated-values",content:e.content};case"image/svg+xml":return{extension:".svg",mimeType:"image/svg+xml",content:e.content};case"application/pdf":return e.content.trimStart().startsWith("%PDF")?{extension:".pdf",mimeType:"application/pdf",content:e.content}:{extension:".html",mimeType:"text/html",content:e.content};case"application/vnd.pxe.code":return{extension:_(e.programmingLanguage),mimeType:"text/plain",content:e.content};case"application/vnd.pxe.mermaid":return{extension:".mmd",mimeType:"text/plain",content:e.content};case"application/vnd.pxe.react":return{extension:".tsx",mimeType:"text/typescript",content:e.content};default:return null}})(ve):null),[ve]);o.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){"inline"===x.type&&x.artifact&&($.some((e=>x.artifact&&e.id===x.artifact.id&&e.version===x.artifact.version))||I({id:x.artifact.id,version:x.artifact.version}))}))}),[$,x.type,x.artifact]),o.useEffect((()=>{if("application/vnd.pxe.code"===(null==ve?void 0:ve.type)&&Z("code"),"finished"!==(null==ve?void 0:ve.status))return Z("code"),pe(),void ue();me(),"application/vnd.pxe.code"!==ve.type&&Z("render")}),[null==ve?void 0:ve.status,null==ve?void 0:ve.type]),o.useEffect((()=>{var e;!se.current||"text/html"!==(null==ve?void 0:ve.type)&&"application/pdf"!==(null==ve?void 0:ve.type)&&"application/vnd.pxe.react"!==(null==ve?void 0:ve.type)||null===(e=se.current.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==ve.type?"HTML_CODE":"REACT_CODE",content:ve.content},M)}),[null==ve?void 0:ve.content,null==ve?void 0:ve.type]);const we=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!ve)return;if("text/html"===ve.type||"application/pdf"===ve.type){const e=ve.content,t=window.open("","_blank");return void(t&&(t.document.open(),t.document.write(e),t.document.close(),t.focus(),t.print()))}const e=Y;"code"===e&&(Z("render"),yield new Promise((e=>setTimeout(e,50)))),ce(),"code"===e&&Z(e)})),je=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!ve)return;const e=yield m.convertMarkdownToDocx(ve.content);m.downloadDocx(e,`${ve.title}.docx`)})),ke=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!ve)return;let o={mimeType:"text/plain",extension:".txt"};switch(t){case"text/markdown":o={mimeType:"text/markdown",extension:".md"};break;case"text/html":o={mimeType:"text/html",extension:".html"};break;case"text/csv":o={mimeType:"text/csv",extension:".csv"};break;case"text/tab-separated-values":o={mimeType:"text/tab-separated-values",extension:".tsv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":o={mimeType:"image/svg+xml",extension:".svg"};break;case"application/pdf":o={mimeType:"application/pdf",extension:".pdf"};break;case"application/vnd.pxe.code":o={mimeType:`application/${ve.programmingLanguage||"text"};charset=utf-8`,extension:`.${ve.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":o={mimeType:"text/typescript",extension:".tsx"};break;default:o={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===ve.type){const t=Y;"code"===t&&(Z("render"),yield new Promise((e=>setTimeout(e,50))));const o=null===(e=le.current)||void 0===e?void 0:e.querySelector("svg");o&&(n=(new XMLSerializer).serializeToString(o)),"code"===t&&Z(t)}const a=new Blob([null!=n?n:ve.content],{type:o.mimeType});E.default(a,`${ve.title}${o.extension}`)})),Ce=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(ve&&be&&J){ne(!0),ie(!1);try{const t=`${e=ve.title,e.trim().replace(/[\\/:*?"<>|]/g,"-").replace(/\s+/g," ")||"artifact"}${be.extension}`,o=new File([be.content],t,{type:be.mimeType});yield Q.document(Object.assign(Object.assign({contextId:W,pickaxeId:H,file:o},(null==K?void 0:K.workspaceid)&&{workspaceId:K.workspaceid}),{studioSessionToken:J,isUserDocument:!0})),ie(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(D.default(e))}finally{ne(!1),ie(!1)}var e}})),Te=()=>{"inline"!==x.type||!x.artifact||he?L(null):L({id:x.artifact.id,version:x.artifact.version})},Se=he||!R.startsWith("inline");return ve?t.jsxs("div",Object.assign({className:A.default("pxe-artifact-renderer flex flex-col","inline"===x.type&&!he&&"min-h-[320px] mb-6",x.className),style:Object.assign(Object.assign({backgroundColor:ye.secondary,color:ye.secondaryText},"auto"!==R&&{borderRadius:xe.cornerRadius}),x.style)},{children:[t.jsxs("div",Object.assign({className:"flex items-center gap-4 justify-between px-4 py-3 shadow-sm"},{children:[t.jsxs("div",Object.assign({className:"pxe-artifact-create-header flex min-w-0 items-center gap-4"},{children:[Se&&t.jsx(S.default,{type:ve.type,view:Y,colors:ye,onChange:Z}),t.jsx("p",Object.assign({className:"w-[220px] max-w-full truncate text-[18px] font-semilight leading-tight",title:ve.title},{children:ve.title}))]})),"inline"===x.type&&!Se&&t.jsx("div",Object.assign({className:"shrink-0"},{children:t.jsx("button",Object.assign({type:"button",style:{color:ye.secondaryText},onClick:Te,title:(null==U?void 0:U.expand)||"Expand","aria-label":(null==U?void 0:U.expand)||"Expand artifact"},{children:he?t.jsx(f.default,{className:"w-6 h-6 shrink-0"}):t.jsx(v.default,{className:"w-6 h-6 shrink-0"})}))}))]})),Se&&t.jsx("div",Object.assign({className:"flex items-center justify-between border-y px-4 py-2.5",style:{borderColor:ye.primary}},{children:t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100",style:{color:ye.secondaryText},onClick:Te,title:"inline"===x.type?(null==U?void 0:U.collapse)||"Collapse":(null==U?void 0:U.close)||"Close","aria-label":"inline"===x.type?(null==U?void 0:U.collapse)||"Collapse artifact":(null==U?void 0:U.close)||"Close artifact"},{children:t.jsx(g.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100 disabled:cursor-not-allowed disabled:opacity-50",style:{color:ye.secondaryText},disabled:ee,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(ve)try{B.default(ve.content),te(!0),yield new Promise((e=>setTimeout(e,1500)))}finally{te(!1)}})),title:(null==U?void 0:U.copy)||"Copy","aria-label":(null==U?void 0:U.copy)||"Copy artifact content"},{children:t.jsx(h.default,{className:"h-[18px] w-[18px] shrink-0"})})),t.jsx(T.default,Object.assign({data:ve,colors:ye,onDownload:ke,onSaveAsPDF:we,onSaveAsDOCX:je,onSaveToKnowledgeBase:Ce,isSaveToKnowledgeBaseEnabled:G&&Boolean(be),isSavingToKnowledgeBase:oe,isSavedToKnowledgeBase:ae,className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100"},{children:t.jsx("div",Object.assign({role:"button",className:"cursor-pointer",style:{color:ye.secondaryText},title:(null==U?void 0:U.save)||"Download","aria-label":(null==U?void 0:U.save)||"Download artifact content"},{children:t.jsx(b.default,{className:"h-6 w-6 shrink-0"})}))}))]}))})),t.jsx("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:t.jsxs(j.default,Object.assign({ref:de,innerClassName:"flex-grow w-full"},{children:["render"===Y&&"application/vnd.pxe.code"!==ve.type?t.jsx("div",Object.assign({ref:re,className:A.default("p-4 pb-6 flex-grow flex flex-col","text/html"===ve.type&&"p-0","text/csv"===ve.type&&"p-0","application/pdf"===ve.type&&"p-0","application/vnd.pxe.react"===ve.type&&"p-0")},{children:"text/markdown"===ve.type||"text/csv"===ve.type||"text/tab-separated-values"===ve.type||"image/svg+xml"===ve.type?t.jsx(d.PickaxeMarkdown,Object.assign({theme:xe.theme,colors:ye},{children:t.jsx(p.PickaxeMarkdownRenderer,{value:null!=fe?fe:ve.content,className:A.default("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full",("text/csv"===ve.type||"text/tab-separated-values"===ve.type)&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===ve.type?t.jsx(C.default,{ref:le,id:`mermaid-${ve.id}-${ve.version}`,data:ve.content}):"text/html"===ve.type||"application/pdf"===ve.type||"application/vnd.pxe.react"===ve.type?t.jsx("iframe",Object.assign({ref:se,title:ve.title,src:`${M}/${"application/vnd.pxe.react"!==ve.type?"html":"react"}?theme=${ge?"dark":"light"}&bg=${ye.secondary}&accent=${ye.accent}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==ye?void 0:ye.secondary},loading:"lazy",allow:"fullscreen; camera; microphone; gyroscope; accelerometer; geolocation; clipboard-write; autoplay",sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-popups-to-escape-sandbox allow-pointer-lock allow-popups allow-modals allow-orientation-lock allow-presentation",onLoad:e=>{const t=e.target;setTimeout((()=>{var e;try{null===(e=t.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==ve.type?"HTML_CODE":"REACT_CODE",content:ve.content},M)}catch(e){console.error("Error sending message to iframe:",e)}}),100),ue()}},{children:(null==U?void 0:U["iframe-artifact-fallback"])||"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t.jsx(u.Prism,Object.assign({PreTag:"div",language:"text/markdown"===ve.type?"markdown":"text/html"===ve.type||"image/svg+xml"===ve.type?"xml":"application/vnd.pxe.react"===ve.type?"typescript":ve.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==ye?void 0:ye.secondaryText},ge&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"}),'pre[class*="language-"]':Object.assign(Object.assign({color:null==ye?void 0:ye.secondaryText},ge&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",borderRadius:"0.3em",minWidth:0,paddingLeft:"1em",paddingRight:"1em",paddingBottom:"2em",background:null==ye?void 0:ye.secondary}),':not(pre) > code[class*="language-"]':{background:null==ye?void 0:ye.secondary,padding:".1em",borderRadius:".3em"},comment:{color:"#7C7C7C"},prolog:{color:"#7C7C7C"},doctype:{color:"#7C7C7C"},cdata:{color:"#7C7C7C"},punctuation:{color:"#c5c8c6"},".namespace":{opacity:".7"},property:{color:"#96CBFE"},keyword:{color:"#96CBFE"},tag:{color:"#96CBFE"},"class-name":{color:"#FFFFB6"},boolean:{color:"#99CC99"},constant:{color:"#99CC99"},symbol:{color:"#f92672"},deleted:{color:"#f92672"},number:{color:"#FF73FD"},selector:{color:"#A8FF60"},"attr-name":{color:"#A8FF60"},string:{color:"#A8FF60"},char:{color:"#A8FF60"},builtin:{color:"#A8FF60"},inserted:{color:"#A8FF60"},variable:{color:"#C6C5FE"},operator:{color:"#EDEDED"},entity:{color:"#FFFFB6",cursor:"help"},url:{color:"#96CBFE"},".language-css .token.string":{color:"#87C38A"},".style .token.string":{color:"#87C38A"},atrule:{color:"#F9EE98"},"attr-value":{color:"#F9EE98"},function:{color:"#DAD085"},regex:{color:"#E9C062"},important:{color:null==ye?void 0:ye.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!ge&&{comment:{color:"#7D8B99"},prolog:{color:"#7D8B99"},doctype:{color:"#7D8B99"},cdata:{color:"#7D8B99"},punctuation:{color:"#4D4D4C"},property:{color:"#4078F2"},keyword:{color:"#8959A8"},tag:{color:"#8959A8"},"class-name":{color:"#D75F00"},boolean:{color:"#0086B3"},constant:{color:"#0086B3"},symbol:{color:"#990055"},deleted:{color:"#990000"},number:{color:"#005CC5"},selector:{color:"#63A35C"},"attr-name":{color:"#63A35C"},string:{color:"#50A14F"},char:{color:"#50A14F"},builtin:{color:"#50A14F"},inserted:{color:"#50A14F"},variable:{color:"#A626A4"},operator:{color:"#4D4D4C"},entity:{color:"#E45649",cursor:"help"},url:{color:"#4078F2"},".language-css .token.string":{color:"#50A14F"},".style .token.string":{color:"#50A14F"},atrule:{color:"#C18401"},"attr-value":{color:"#986801"},function:{color:"#005CC5"},regex:{color:"#D16969"},important:{color:null==ye?void 0:ye.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:ve.content})),t.jsx(y.default,{})]}))})),"inline"===x.type&&!he&&t.jsxs("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t.jsx(k.default,Object.assign({id:`artifact-copy-${ve.id}-${ve.version}`,tip:(null==U?void 0:U.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:ye.secondary,color:ye.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(w.default,{color:ye.secondaryText,text:ve.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t.jsx(k.default,Object.assign({id:`artifact-save-${ve.id}-${ve.version}`,tip:(null==U?void 0:U.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:ye.secondary,color:ye.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(T.default,Object.assign({data:ve,colors:ye,onDownload:ke,onSaveAsPDF:we,onSaveAsDOCX:je,onSaveToKnowledgeBase:Ce,isSaveToKnowledgeBaseEnabled:G&&Boolean(be),isSavingToKnowledgeBase:oe,isSavedToKnowledgeBase:ae},{children:t.jsx("button",Object.assign({style:{color:ye.secondaryText}},{children:t.jsx(b.default,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),r=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../../../hooks/pickaxe/useDimensionContext.js"),c=require("../Addons/Auth/hooks/useAuthContext.js"),d=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),f=require("../../../hooks/core/useHover.js"),m=require("../../../hooks/core/useMediaQuery.js"),h=require("../../../common/documents.js"),g=require("eventsource-parser"),v=require("../../Icons/attach-vertical.svg.js"),x=require("../../Icons/arrow-right.svg.js"),b=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),I=require("../Addons/Document/List.js"),j=require("../../Core/Textarea.js"),w=require("../../Core/ErrorAlert.js"),N=require("../../../common/error.js"),O=require("../../../common/api/pickaxe.js"),S=require("../../../common/validation.js"),_=require("../../../common/cn.js"),k=require("../../../common/utils.js"),U=require("../../../hooks/studio/useStudio.js"),C=require("../../../hooks/pickaxe/useSpeech.js"),E=require("../common/PickaxeCommon.js");const T=e=>"string"==typeof e&&e.trim().length>0,A=(e,t)=>{if(e&&"object"==typeof e)return e[t]},D=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},L=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const r=Array.isArray(A(e,"uses"))?A(e,"uses"):[],o=(({deploymentId:e,portalId:t})=>T(e)?{type:"deployment",id:e}:T(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:s});if(!o)return{scope:o,record:null};const a=null!==(i=null!==(n=r.find((e=>e.id===o.id&&e.type===o.type)))&&void 0!==n?n:r.find((e=>e.id===o.id)))&&void 0!==i?i:null;return{scope:o,record:a}},P=s.forwardRef((({resubmitPrompt:T,onFocus:A,onBlur:P,onInputHeightChange:q,initSmitheryAuthData:R},F)=>{var M,V,$,B,H,X,Y,K,W;const{origin:J,pickaxeId:z,sessionId:G,sender:Q,senderType:Z,portalId:ee,deploymentId:te,deploymentType:se,pickaxe:ne,styles:ie,colors:re,translations:oe,locale:ae,forceMobile:le,isNewChat:ce,isRtl:de,isShowFeedbackMessage:ue,accessGroup:pe,setIsNewChat:fe,setIsShowIceBreaker:me,setValidationStatus:he,setValidationUpgradeGroups:ge,setValidationUpgradeUrl:ve,onGenerateComplete:xe}=n.usePickaxeContext(),{token:be,isLoggedOut:ye,isSent:Ie,isPricingAuth:je}=c.useAuthContext(),{messages:we,isGenerating:Ne,setMessages:Oe,setStatus:Se,setLimitData:_e,setError:ke}=i.useResponseContext(),{documents:Ue,isUploading:Ce,documentError:Ee,onFileUpload:Te,setDocuments:Ae,setDocumentError:De}=d.useDocument(),{studio:Le}=U.useStudio(),{scrollStartSession:Pe,scrollEndSession:qe,scrollToBottom:Re}=u.useScroll({auto:!0}),{artifacts:Fe,currentPopupType:Me,setArtifacts:Ve,setCurrentArtifact:$e}=p.useArtifactContext(),{height:Be}=l.useDimensionContext(),He=a.useConversation(),[Xe,Ye]=s.useState(""),[Ke,We]=s.useState(!1),[Je,ze]=s.useState(!1),[Ge,Qe]=s.useState(null),[Ze,et]=s.useState(null),[tt,st]=s.useState(!1),[nt,it]=s.useState(0),rt=s.useRef(null),ot=s.useRef(""),at=s.useRef(null),lt=s.useRef(null),ct=s.useRef(null),dt=s.useRef(null),ut=s.useRef(null),pt=Math.max(.4*Be,100),{speechTranscript:ft,isSpeechListening:mt,isSpeechProcessing:ht,isSpeechSupported:gt,onStartListening:vt,onStopListening:xt}=C.useSpeech(),[bt]=m.useMediaQuery("(max-width: 480px)"),yt=f.useHover(),{isHover:It}=yt,jt=e.__rest(yt,["isHover"]),wt=f.useHover(),{isHover:Nt}=wt,Ot=e.__rest(wt,["isHover"]),St=f.useHover(),{isHover:_t}=St,kt=e.__rest(St,["isHover"]),Ut=o.useStyleFontSize(),Ct=r.useStyleInput(),Et="undefined"!=typeof window?window.location.hostname:"",Tt="undefined"!=typeof window?window.location.href:"",At="undefined"!=typeof window&&window.self!==window.top,Dt=Et.includes("pickaxe.co")&&!Tt.includes("https://studio.pickaxe.co/_embed")&&!At,Lt=null===(M=null==ne?void 0:ne.documentuploadtype)||void 0===M?void 0:M.startsWith("enduserupload"),Pt=gt&&(null==ne?void 0:ne.enablevoicetotext),qt="chat-input"===se&&ce&&!Ie,Rt="chat-input"===se&&je&&ye&&Ie,Ft=s.useCallback((e=>{const t=S.getValidationFailure(e);return!!t&&(ke(""),_e(null),he(t.status),ge(t.upgradeGroups),ve(t.upgradeUrl),!0)}),[ke,_e,he,ge,ve]),Mt=null!==(V=null==ne?void 0:ne.placeholdertext)&&void 0!==V?V:de?"بماذا تريد أن تتحدث؟":(null==oe?void 0:oe["what-do-you-want-to-talk-about"])||"What do you want to talk about?",Vt=Ke||Je,$t=s.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/get_user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign(Object.assign(Object.assign({studioId:null==ne?void 0:ne.studioid},Q&&{sender:Q}),be&&{studioSessionToken:be}),!be&&!Q&&{sender:k.initializeEmbedUserId()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),Dt&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(Qe(t.studioUser),et(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}}))),[J,z,G,Z,Q,be,ee,te,Dt]);s.useEffect((()=>{$t()}),[$t]);const Bt=Number(null!==($=null==pe?void 0:pe.limit)&&void 0!==$?$:0),Ht="string"==typeof(null==pe?void 0:pe.limitInterval)?pe.limitInterval:null,Xt=!!(null==Le?void 0:Le.data.usage)&&Le.data.usage.isCredits,Yt=s.useMemo((()=>L({studioUser:Ge,deploymentId:te,portalId:ee})),[te,ee,Ge]),Kt={currentUses:D(null==Ge?void 0:Ge.currentUses),extraUses:D(null==Ge?void 0:Ge.extraUses)},Wt=Yt.scope?{currentUses:null!==(H=D(null===(B=Yt.record)||void 0===B?void 0:B.currentUses))&&void 0!==H?H:0,extraUses:null!==(Y=D(null===(X=Yt.record)||void 0===X?void 0:X.extraUses))&&void 0!==Y?Y:0}:{currentUses:0,extraUses:0},Jt=ye?Wt:Kt;s.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(Xt&&(null===(e=null==Le?void 0:Le.data)||void 0===e?void 0:e.workspaceId))try{const e=yield O.default.get(`/cost_per_run?workspaceId=${Le.data.workspaceId}`,{withCredentials:!1});t&&it(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&it(0)}else t&&it(0)})),()=>{t=!1}}),[Xt,null===(K=null==Le?void 0:Le.data)||void 0===K?void 0:K.workspaceId]);const zt=(({currentUses:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=e?e:0),r=Number(null!=t?t:0);return s===E.STUDIO_INFINITY_VALUE||r===E.STUDIO_INFINITY_VALUE?E.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,r-i):Math.max(0,s-i)+r})({currentUses:Jt.currentUses,extraUses:Jt.extraUses,limit:Bt,limitInterval:Ht}),Gt=zt===E.STUDIO_INFINITY_VALUE?E.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(zt)),Qt=(({extraUses:e,limit:t,limitInterval:s})=>{const n=Number(null!=e?e:0);return t===E.STUDIO_INFINITY_VALUE||n===E.STUDIO_INFINITY_VALUE?E.STUDIO_INFINITY_VALUE:"one_time"===s?Math.max(0,n):Math.max(0,t)+Math.max(0,n)})({extraUses:Jt.extraUses,limit:Bt,limitInterval:Ht}),Zt=Qt===E.STUDIO_INFINITY_VALUE?E.STUDIO_INFINITY_VALUE:Math.ceil(.05*Qt),es=Xt?Math.ceil(5*nt):5,ts=Zt===E.STUDIO_INFINITY_VALUE?E.STUDIO_INFINITY_VALUE:Math.max(Zt,es);console.log("Usage and Limits Debug:",{remaining:Gt,notificationThreshold:ts,studioUser:Ge});const ss=s.useMemo((()=>!!Ge&&(!tt&&(Gt!==E.STUDIO_INFINITY_VALUE&&(!(Gt<=0)&&Gt<=ts)))),[tt,ts,Gt,Ge]),ns=s.useMemo((()=>{var e,t,s;return!!ce&&(!!ne&&(!He.isLoading&&(!((null!==(t=null===(e=He.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=ne.icebreakers)||void 0===s?void 0:s.length)&&(!ue&&!qt)))))}),[ne,ce,ue,qt,He.data,He.isLoading]),is=s.useMemo((()=>{if(Ne||Ce)return!1;const e=Ue.length>0&&Ue.every((e=>"finished"===e.status));return!(!Xe.trim()&&!e)&&Ue.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Ne,Ce,Xe,Ue]);s.useImperativeHandle(F,(()=>({onSubmit:rs}))),s.useEffect((()=>{me(ns)}),[ns]),s.useEffect((()=>{var e;if(T){const t=Array.from(we),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;rs(s,!0)}}),[T]),s.useEffect((()=>{if(!dt.current||!q)return;const e=new ResizeObserver((e=>{for(const t of e)q(t.contentRect.height)}));return e.observe(dt.current),()=>{e.disconnect()}}),[q]),s.useEffect((()=>{if(!mt)return;const e=ot.current?`${ot.current} `:"";Ye(`${e}${ft}`)}),[ft,mt]),s.useEffect((()=>{if(!lt.current)return;(()=>{if(!lt.current)return;let e=lt.current.scrollHeight>52;Xe.includes("\n")||Ue.length?e=!0:Xe.trim()||(e=!1),We(e)})()}),[Xe,Ue]),s.useEffect((()=>{const e=lt.current,t=ct.current;if(!e||!t||Ke||Xe.includes("\n"))return void ze(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,i=document.createElement("span");Object.assign(i.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),i.textContent=Xe||Mt,document.body.appendChild(i);const r=i.offsetWidth;i.remove();const o=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-o-a-t.offsetWidth;ze(r>l)}),[Xe,Ke,Mt]);const rs=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,i;try{if(Ne||Ce)return;const r=Ue.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=r.map((e=>e.documentId)).filter(Boolean),a=r.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),l=o.length>0,c=null!=t?t:Xe;if(!c&&!l)return;ke(""),De(""),_e(null),Ye(""),fe(!1),Se("fetching"),Pe(),Re();const d=null!==(n=null===(e=null==ne?void 0:ne.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&o.length>0,u=[...s?Array.from(we.slice(0,we.length-1)):Array.from(we),...s?[]:[{id:we.length+1,role:"user",parts:[{type:"text",content:c,isVisible:!0}],documentIds:d?o:[]}],{id:we.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];Oe(u),Re(),d&&Ae([]);const p=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:J,pickaxeId:z,sessionId:G,senderType:Z,value:c},d&&{documentIds:o}),Q&&{sender:Q}),be&&{studioSessionToken:be}),!be&&!Q&&{sender:k.initializeEmbedUserId()}),ee&&{portalId:ee}),te&&{deploymentId:te}),a.length>0&&{uploadedModelImages:a})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},Dt&&{credentials:"include"})),f=yield p.json();if(!f.success){if(Ft(f))return;const e=new Error(f.error||f.message||(null==oe?void 0:oe["failed-to-start-generation"])||"Failed to start generation");throw f.limitData&&(e.limitData=f.limitData),e}const m=f.submissionId;Se("streaming"),ut.current=new AbortController;const h=u.length-1,v=[];let x=[...null!=Fe?Fe:[]],b=0,y=!1,I="";for(;!y;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${m}?index=${b}`,{signal:null===(i=ut.current)||void 0===i?void 0:i.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();at.current=t;const s=new TextDecoder,n=g.createParser({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&b++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==oe?void 0:oe["something-went-wrong"])||"Something went wrong.";return Ft(t)||ke(s),void(y=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&R){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw y=!0,R({smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw y=!0,R({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)I="",v.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)I+=n.delta,v[v.length-1].content=I;else if("text-end"===n.type)I="";else if("reasoning-start"===n.type)I="",v.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)I+=n.delta,v[v.length-1].content=I;else if("reasoning-end"===n.type)I="";else if(n.type.startsWith("data-")){const e=n;v.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}Oe([...u.slice(0,h),Object.assign(Object.assign({},u[u.length-1]),{id:we.length+1,role:"assistant",parts:v})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);x=x.filter((e=>!(e.id===t.id&&e.version===t.version))),x.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ve([...x]),Me.startsWith("inline")||$e({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);x=x.filter((e=>!(e.id===t.id&&e.version===t.version))),x.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Ve(x),Me.startsWith("inline")||$e({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);x=x.filter((e=>!(e.id===t.id&&e.version===t.version))),x.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ve(x),Me.startsWith("inline")||$e({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");x=x.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Ve(x)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Ve(x.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==oe?void 0:oe["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(Ft(t))return void(y=!0);ke(s)}else"stop"===e.event&&(y=!0)}else y=!0}});for(;;){const{value:e,done:i}=yield t.read();if(i)break;n.feed(s.decode(e))}y||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||"AbortError"===e.name)return void(y=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==xe||xe(G)}catch(e){if(e.limitData)_e(e.limitData),ke("");else{let t=N.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==oe?void 0:oe["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),Ft(t)||ke(t)}}finally{Re(),Se("idle"),qe(),at.current=null,yield $t()}}));return Rt?null:t.jsx("div",Object.assign({className:_.default("flex w-full flex-shrink-0 flex-col items-center",!qt&&"px-4 pb-8"),dir:de?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:dt,className:_.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===ie.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Ct),{maxHeight:`${pt}px`,overflowY:"auto"})},{children:[ss&&t.jsxs("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:Ct.backgroundColor?`${Ct.backgroundColor}E6`:void 0,borderColor:re.text+"20",color:re.text,borderTopRightRadius:ie.cornerRadius+"px",borderTopLeftRadius:ie.cornerRadius+"px"}},{children:[t.jsx("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:t.jsxs("span",{children:[Gt.toLocaleString()," ",Xt?(null==oe?void 0:oe.credits)||"Credits":(null==oe?void 0:oe.uses)||"Uses"," ",(null==oe?void 0:oe.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:re.accent,color:re.accentText},onClick:e=>{e.preventDefault(),e.stopPropagation();const t=k.buildUpgradeUrl({baseUrl:Ze,accessGroupId:null==pe?void 0:pe.accessGroupId});t&&(k.isInIframe()?window.open(t):location.href=t)}},{children:(null==oe?void 0:oe.upgrade)||"Upgrade"})),t.jsx("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>st(!0)},{children:t.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!Ne&&Ue.length>0&&t.jsx(I.default,{className:"p-4 pb-0",isDisabled:Ne}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[mt&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(W=re.accent)&&void 0!==W?W:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:re.text+"90"}},{children:(null==oe?void 0:oe.listening)||"Listening..."}))]})),t.jsx(j.default,Object.assign({ref:lt,className:_.default(Ut.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!Xe.trim()&&!Xe.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",de?"text-right":"text-left",Vt&&"mb-12",mt&&"text-transparent"),value:Xe,placeholder:Mt,onChange:e=>{Ye(e)},onKeyDown:e=>{le||bt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Ce||Ne||rs()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);e.length>0&&(t.preventDefault(),fe(!1),yield Te(e))}))},A&&{onFocus:A},P&&{onBlur:P},{dir:de?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:ct,className:_.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",Vt?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!Vt&&Ct.backgroundColor&&{backgroundColor:Ct.backgroundColor}),{borderTopRightRadius:ie.cornerRadius+"px",borderBottomRightRadius:ie.cornerRadius+"px"})},{children:Ne?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{ut.current&&(ut.current.abort(),ut.current=null),at.current&&(at.current.cancel(),at.current=null),Se("idle")},style:{backgroundColor:re.accent,color:re.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):mt?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:xt,style:{backgroundColor:re.accent,color:re.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Lt&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Nt?re.accent+"10":void 0,color:Nt?re.accent:re.accent+"80"},disabled:Ce||Ne,onClick:()=>{var e;return null===(e=rt.current)||void 0===e?void 0:e.click()}},Ot,{children:[t.jsx("input",{id:"file-upload",ref:rt,type:"file",accept:[...h.allowedFileMimeTypes,...h.allowedImageMimeTypes,...h.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){fe(!1),yield Te(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(v.default,{className:"h-6 w-6 shrink-0"})]})),Pt&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:mt?re.accent:_t?re.accent+"10":void 0,color:mt?re.accentText:_t?re.accent:re.accent+"80"},disabled:Ce||Ne||ht,onClick:()=>{mt?xt():(ot.current=Xe,vt(ae||"en-US"))}},kt,{children:t.jsx(b.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:It||is?re.accent:re.accent+"10",color:It||is?re.accentText:re.accent+"80"},disabled:!is,onClick:()=>rs()},jt,{children:t.jsx(x.default,{className:_.default("h-6 w-6 shrink-0",de&&"scale-x-[-1] transform")})}))]})}))]}))]})),Ee&&t.jsx(w.default,{error:Ee,className:"mt-3"})]}))}))}));P.displayName="Input",exports.default=P;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../hooks/studio/useStyleInput.js"),r=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../../../hooks/pickaxe/useDimensionContext.js"),d=require("../Addons/Auth/hooks/useAuthContext.js"),c=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/core/useHover.js"),f=require("../../../hooks/core/useMediaQuery.js"),g=require("../../../common/documents.js"),h=require("eventsource-parser"),v=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/arrow-right.svg.js"),x=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),I=require("../Addons/Document/List.js"),j=require("../../Core/Textarea.js"),w=require("../../Core/ErrorAlert.js"),O=require("../../../common/error.js"),N=require("../../../common/api/pickaxe.js"),S=require("../../../common/validation.js"),k=require("../../../common/cn.js"),_=require("../../../common/utils.js"),U=require("../../../common/pickaxeConfig.js"),C=require("../../../common/deploymentWebhooks.js"),E=require("../../../hooks/studio/useStudio.js"),T=require("../../../hooks/pickaxe/useSpeech.js"),A=require("../common/PickaxeCommon.js");const D=e=>"string"==typeof e&&e.trim().length>0,L=(e,t)=>{if(e&&"object"==typeof e)return e[t]},P=(e,t)=>{const s=L(e,t);return D(s)?s:null},q=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},R=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const o=Array.isArray(L(e,"uses"))?L(e,"uses"):[],r=(({deploymentId:e,portalId:t})=>D(e)?{type:"deployment",id:e}:D(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:s});if(!r)return{scope:r,record:null};const a=null!==(i=null!==(n=o.find((e=>e.id===r.id&&e.type===r.type)))&&void 0!==n?n:o.find((e=>e.id===r.id)))&&void 0!==i?i:null;return{scope:r,record:a}},M=s.forwardRef((({resubmitPrompt:L,onFocus:M,onBlur:F,onInputHeightChange:V,initSmitheryAuthData:H},W)=>{var $,B,X,Y,K,z,J,G,Q;const{origin:Z,pickaxeId:ee,sessionId:te,sender:se,senderType:ne,portalId:ie,deploymentId:oe,deploymentType:re,pickaxe:ae,styles:le,colors:de,translations:ce,locale:ue,forceMobile:pe,isNewChat:me,isRtl:fe,isShowFeedbackMessage:ge,accessGroup:he,setIsNewChat:ve,setIsShowIceBreaker:be,setValidationStatus:xe,setValidationUpgradeGroups:ye,setValidationUpgradeUrl:Ie,onGenerateComplete:je}=n.usePickaxeContext(),{token:we,isLoggedOut:Oe,isSent:Ne,isPricingAuth:Se}=d.useAuthContext(),{messages:ke,isGenerating:_e,setMessages:Ue,setStatus:Ce,setLimitData:Ee,setError:Te}=i.useResponseContext(),{documents:Ae,isUploading:De,documentError:Le,onFileUpload:Pe,setDocuments:qe,setDocumentError:Re}=c.useDocument(),{studio:Me}=E.useStudio(),{scrollStartSession:Fe,scrollEndSession:Ve,scrollToBottom:He}=u.useScroll({auto:!0}),{artifacts:We,currentPopupType:$e,setArtifacts:Be,setCurrentArtifact:Xe}=p.useArtifactContext(),{height:Ye}=l.useDimensionContext(),Ke=a.useConversation(),[ze,Je]=s.useState(""),[Ge,Qe]=s.useState(!1),[Ze,et]=s.useState(!1),[tt,st]=s.useState(null),[nt,it]=s.useState(null),[ot,rt]=s.useState(!1),[at,lt]=s.useState(!1),[dt,ct]=s.useState(0),ut=s.useRef(null),pt=s.useRef(""),mt=s.useRef(null),ft=s.useRef(null),gt=s.useRef(null),ht=s.useRef(null),vt=s.useRef(null),bt=s.useRef(new Set),xt=s.useRef(null),yt=Math.max(.4*Ye,100),{speechTranscript:It,isSpeechListening:jt,isSpeechProcessing:wt,isSpeechSupported:Ot,onStartListening:Nt,onStopListening:St}=T.useSpeech(),[kt]=f.useMediaQuery("(max-width: 480px)"),_t=m.useHover(),{isHover:Ut}=_t,Ct=e.__rest(_t,["isHover"]),Et=m.useHover(),{isHover:Tt}=Et,At=e.__rest(Et,["isHover"]),Dt=m.useHover(),{isHover:Lt}=Dt,Pt=e.__rest(Dt,["isHover"]),qt=r.useStyleFontSize(),Rt=o.useStyleInput(),Mt="undefined"!=typeof window?window.location.hostname:"",Ft="undefined"!=typeof window?window.location.href:"",Vt="undefined"!=typeof window&&window.self!==window.top,Ht=Mt.includes("pickaxe.co")&&!Ft.includes("https://studio.pickaxe.co/_embed")&&!Vt,Wt=null===($=null==ae?void 0:ae.documentuploadtype)||void 0===$?void 0:$.startsWith("enduserupload"),$t=Ot&&(null==ae?void 0:ae.enablevoicetotext),Bt=D(oe),Xt="chat-input"===re&&me&&!Ne,Yt="chat-input"===re&&Se&&Oe&&Ne,Kt=s.useCallback((e=>{const t=S.getValidationFailure(e);return!!t&&(Te(""),Ee(null),xe(t.status),ye(t.upgradeGroups),Ie(t.upgradeUrl),!0)}),[Te,Ee,xe,ye,Ie]),zt=null!==(B=null==ae?void 0:ae.placeholdertext)&&void 0!==B?B:fe?"بماذا تريد أن تتحدث؟":(null==ce?void 0:ce["what-do-you-want-to-talk-about"])||"What do you want to talk about?",Jt=Ge||Ze,Gt=s.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){rt(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/get_user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign(Object.assign(Object.assign({studioId:null==ae?void 0:ae.studioid},se&&{sender:se}),we&&{studioSessionToken:we}),!we&&!se&&{sender:_.initializeEmbedUserId()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),Ht&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(st(t.studioUser),it(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{rt(!0)}}))),[Z,ee,te,ne,se,we,ie,oe,Ht]);s.useEffect((()=>{Gt()}),[Gt]);const Qt=Number(null!==(X=null==he?void 0:he.limit)&&void 0!==X?X:0),Zt="string"==typeof(null==he?void 0:he.limitInterval)?he.limitInterval:null,es=!!(null==Me?void 0:Me.data.usage)&&Me.data.usage.isCredits,ts=s.useMemo((()=>R({studioUser:tt,deploymentId:oe,portalId:ie})),[oe,ie,tt]);s.useEffect((()=>{Bt&&me&&te&&bt.current.add(te)}),[me,te,Bt]);const ss=s.useCallback((()=>{var e,t,s;return{studioId:null==ae?void 0:ae.studioid,userEmail:P(tt,"email"),userId:null!==(e=P(tt,"userId"))&&void 0!==e?e:P(tt,"userid"),sessionId:te,deploymentId:oe,deploymentType:re,portalId:ie,accessGroupId:null!==(t=null==he?void 0:he.accessGroupId)&&void 0!==t?t:null,pickaxeId:ee,sender:se,senderType:ne,origin:Z,metadata:null!==(s=U.getPickaxeConfigMetadata(oe))&&void 0!==s?s:null}}),[null==he?void 0:he.accessGroupId,oe,re,Z,null==ae?void 0:ae.studioid,ee,ie,se,ne,te,tt]),ns=s.useCallback((()=>!!(Bt&&ot&&te)&&(!!bt.current.has(te)&&(C.fireDeploymentSessionInitializedWebhook(ss()),bt.current.delete(te),!0))),[ss,ot,te,Bt]);s.useEffect((()=>{if(!ot||!te)return;ns();const e=xt.current;(null==e?void 0:e.sessionId)===te&&(C.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),ss()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),xt.current=null)}),[ns,ss,ot,te]);const is={currentUses:q(null==tt?void 0:tt.currentUses),extraUses:q(null==tt?void 0:tt.extraUses)},os=ts.scope?{currentUses:null!==(K=q(null===(Y=ts.record)||void 0===Y?void 0:Y.currentUses))&&void 0!==K?K:0,extraUses:null!==(J=q(null===(z=ts.record)||void 0===z?void 0:z.extraUses))&&void 0!==J?J:0}:{currentUses:0,extraUses:0},rs=Oe?os:is;s.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(es&&(null===(e=null==Me?void 0:Me.data)||void 0===e?void 0:e.workspaceId))try{const e=yield N.default.get(`/cost_per_run?workspaceId=${Me.data.workspaceId}`,{withCredentials:!1});t&&ct(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&ct(0)}else t&&ct(0)})),()=>{t=!1}}),[es,null===(G=null==Me?void 0:Me.data)||void 0===G?void 0:G.workspaceId]);const as=(({currentUses:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=e?e:0),o=Number(null!=t?t:0);return s===A.STUDIO_INFINITY_VALUE||o===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,o-i):Math.max(0,s-i)+o})({currentUses:rs.currentUses,extraUses:rs.extraUses,limit:Qt,limitInterval:Zt}),ls=as===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(as)),ds=(({extraUses:e,limit:t,limitInterval:s})=>{const n=Number(null!=e?e:0);return t===A.STUDIO_INFINITY_VALUE||n===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:"one_time"===s?Math.max(0,n):Math.max(0,t)+Math.max(0,n)})({extraUses:rs.extraUses,limit:Qt,limitInterval:Zt}),cs=ds===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.ceil(.05*ds),us=es?Math.ceil(5*dt):5,ps=cs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(cs,us);console.log("Usage and Limits Debug:",{remaining:ls,notificationThreshold:ps,studioUser:tt});const ms=s.useMemo((()=>!!tt&&(!at&&(ls!==A.STUDIO_INFINITY_VALUE&&(!(ls<=0)&&ls<=ps)))),[at,ps,ls,tt]),fs=s.useMemo((()=>{var e,t,s;return!!me&&(!!ae&&(!Ke.isLoading&&(!((null!==(t=null===(e=Ke.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=ae.icebreakers)||void 0===s?void 0:s.length)&&(!ge&&!Xt)))))}),[ae,me,ge,Xt,Ke.data,Ke.isLoading]),gs=s.useMemo((()=>{if(_e||De)return!1;const e=Ae.length>0&&Ae.every((e=>"finished"===e.status));return!(!ze.trim()&&!e)&&Ae.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[_e,De,ze,Ae]);s.useImperativeHandle(W,(()=>({onSubmit:hs}))),s.useEffect((()=>{be(fs)}),[fs]),s.useEffect((()=>{var e;if(L){const t=Array.from(ke),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;hs(s,!0)}}),[L]),s.useEffect((()=>{if(!ht.current||!V)return;const e=new ResizeObserver((e=>{for(const t of e)V(t.contentRect.height)}));return e.observe(ht.current),()=>{e.disconnect()}}),[V]),s.useEffect((()=>{if(!jt)return;const e=pt.current?`${pt.current} `:"";Je(`${e}${It}`)}),[It,jt]),s.useEffect((()=>{if(!ft.current)return;(()=>{if(!ft.current)return;let e=ft.current.scrollHeight>52;ze.includes("\n")||Ae.length?e=!0:ze.trim()||(e=!1),Qe(e)})()}),[ze,Ae]),s.useEffect((()=>{const e=ft.current,t=gt.current;if(!e||!t||Ge||ze.includes("\n"))return void et(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,i=document.createElement("span");Object.assign(i.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),i.textContent=ze||zt,document.body.appendChild(i);const o=i.offsetWidth;i.remove();const r=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;et(o>l)}),[ze,Ge,zt]);const hs=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,i;try{if(_e||De)return;const o=Ae.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),r=o.map((e=>e.documentId)).filter(Boolean),a=o.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),l=r.length>0,d=null!=t?t:ze;if(!d&&!l)return;Te(""),Re(""),Ee(null),Je(""),ve(!1),Ce("fetching"),Fe(),He();const c=null!==(n=null===(e=null==ae?void 0:ae.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&r.length>0,u=[...s?Array.from(ke.slice(0,ke.length-1)):Array.from(ke),...s?[]:[{id:ke.length+1,role:"user",parts:[{type:"text",content:d,isVisible:!0}],documentIds:c?r:[]}],{id:ke.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];Ue(u),He(),c&&qe([]);const p=U.getPickaxeConfigMetadata(oe),m=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:Z,pickaxeId:ee,sessionId:te,senderType:ne,value:d},c&&{documentIds:r}),se&&{sender:se}),we&&{studioSessionToken:we}),!we&&!se&&{sender:_.initializeEmbedUserId()}),ie&&{portalId:ie}),oe&&{deploymentId:oe}),p&&{metadata:p}),a.length>0&&{uploadedModelImages:a})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},Ht&&{credentials:"include"})),f=yield m.json();if(!f.success){if(Kt(f))return;const e=new Error(f.error||f.message||(null==ce?void 0:ce["failed-to-start-generation"])||"Failed to start generation");throw f.limitData&&(e.limitData=f.limitData),e}const g=f.submissionId;Bt&&me&&te&&bt.current.add(te);const v=Object.assign(Object.assign({},ss()),{message:d,documentIds:c?r:[],uploadedModelImages:a,hasUploadedDocuments:c,isHidden:s,metadata:null!=p?p:null});ot?(ns(),C.fireDeploymentFirstMessageSubmittedWebhook(v)):xt.current=v,Ce("streaming"),vt.current=new AbortController;const b=u.length-1,x=[];let y=[...null!=We?We:[]],I=0,j=!1,w="";for(;!j;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${g}?index=${I}`,{signal:null===(i=vt.current)||void 0===i?void 0:i.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();mt.current=t;const s=new TextDecoder,n=h.createParser({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&I++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==ce?void 0:ce["something-went-wrong"])||"Something went wrong.";return Kt(t)||Te(s),void(j=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&H){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw j=!0,H({smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw j=!0,H({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)w="",x.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)w+=n.delta,x[x.length-1].content=w;else if("text-end"===n.type)w="";else if("reasoning-start"===n.type)w="",x.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)w+=n.delta,x[x.length-1].content=w;else if("reasoning-end"===n.type)w="";else if(n.type.startsWith("data-")){const e=n;x.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}Ue([...u.slice(0,b),Object.assign(Object.assign({},u[u.length-1]),{id:ke.length+1,role:"assistant",parts:x})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Be([...y]),$e.startsWith("inline")||Xe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Be(y),$e.startsWith("inline")||Xe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Be(y),$e.startsWith("inline")||Xe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");y=y.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Be(y)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Be(y.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==ce?void 0:ce["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(Kt(t))return void(j=!0);Te(s)}else"stop"===e.event&&(j=!0)}else j=!0}});for(;;){const{value:e,done:i}=yield t.read();if(i)break;n.feed(s.decode(e))}j||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||"AbortError"===e.name)return void(j=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==je||je(te)}catch(e){if(e.limitData)Ee(e.limitData),Te("");else{let t=O.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==ce?void 0:ce["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),Kt(t)||Te(t)}}finally{He(),Ce("idle"),Ve(),mt.current=null,yield Gt()}}));return Yt?null:t.jsx("div",Object.assign({className:k.default("flex w-full flex-shrink-0 flex-col items-center",!Xt&&"px-4 pb-8"),dir:fe?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:ht,className:k.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===le.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Rt),{maxHeight:`${yt}px`,overflowY:"auto"})},{children:[ms&&t.jsxs("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:Rt.backgroundColor?`${Rt.backgroundColor}E6`:void 0,borderColor:de.text+"20",color:de.text,borderTopRightRadius:le.cornerRadius+"px",borderTopLeftRadius:le.cornerRadius+"px"}},{children:[t.jsx("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:t.jsxs("span",{children:[ls.toLocaleString()," ",es?(null==ce?void 0:ce.credits)||"Credits":(null==ce?void 0:ce.uses)||"Uses"," ",(null==ce?void 0:ce.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:de.accent,color:de.accentText},onClick:e=>{e.preventDefault(),e.stopPropagation();const t=_.buildUpgradeUrl({baseUrl:nt,accessGroupId:null==he?void 0:he.accessGroupId});t&&(_.isInIframe()?window.open(t):location.href=t)}},{children:(null==ce?void 0:ce.upgrade)||"Upgrade"})),t.jsx("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>lt(!0)},{children:t.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!_e&&Ae.length>0&&t.jsx(I.default,{className:"p-4 pb-0",isDisabled:_e}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[jt&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(Q=de.accent)&&void 0!==Q?Q:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:de.text+"90"}},{children:(null==ce?void 0:ce.listening)||"Listening..."}))]})),t.jsx(j.default,Object.assign({ref:ft,className:k.default(qt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!ze.trim()&&!ze.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",fe?"text-right":"text-left",Jt&&"mb-12",jt&&"text-transparent"),value:ze,placeholder:zt,onChange:e=>{Je(e)},onKeyDown:e=>{pe||kt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),De||_e||hs()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);e.length>0&&(t.preventDefault(),ve(!1),yield Pe(e))}))},M&&{onFocus:M},F&&{onBlur:F},{dir:fe?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:gt,className:k.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",Jt?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!Jt&&Rt.backgroundColor&&{backgroundColor:Rt.backgroundColor}),{borderTopRightRadius:le.cornerRadius+"px",borderBottomRightRadius:le.cornerRadius+"px"})},{children:_e?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{vt.current&&(vt.current.abort(),vt.current=null),mt.current&&(mt.current.cancel(),mt.current=null),Ce("idle")},style:{backgroundColor:de.accent,color:de.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):jt?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:St,style:{backgroundColor:de.accent,color:de.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Wt&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Tt?de.accent+"10":void 0,color:Tt?de.accent:de.accent+"80"},disabled:De||_e,onClick:()=>{var e;return null===(e=ut.current)||void 0===e?void 0:e.click()}},At,{children:[t.jsx("input",{id:"file-upload",ref:ut,type:"file",accept:[...g.allowedFileMimeTypes,...g.allowedImageMimeTypes,...g.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){ve(!1),yield Pe(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(v.default,{className:"h-6 w-6 shrink-0"})]})),$t&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:jt?de.accent:Lt?de.accent+"10":void 0,color:jt?de.accentText:Lt?de.accent:de.accent+"80"},disabled:De||_e||wt,onClick:()=>{jt?St():(pt.current=ze,Nt(ue||"en-US"))}},Pt,{children:t.jsx(x.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Ut||gs?de.accent:de.accent+"10",color:Ut||gs?de.accentText:de.accent+"80"},disabled:!gs,onClick:()=>hs()},Ct,{children:t.jsx(b.default,{className:k.default("h-6 w-6 shrink-0",fe&&"scale-x-[-1] transform")})}))]})}))]}))]})),Le&&t.jsx(w.default,{error:Le,className:"mt-3"})]}))}))}));M.displayName="Input",exports.default=M;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),o=require("../../../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../Addons/Auth/hooks/useAuthContext.js"),i=require("../../../../../../hooks/pickaxe/useSubmitDocument.js"),l=require("../../hooks/usePickaxeMarkdownContext.js"),n=require("../../../../../Icons/download.svg.js"),r=require("../../../../../Icons/copy.svg.js"),c=require("../../../../../Icons/copied.svg.js"),d=require("../../../../../Icons/file.svg.js"),u=require("../../../../../Icons/upload-cloud.svg.js"),p=require("copy-to-clipboard"),m=require("../../../../../../common/error.js");function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=f(p);const b=new Set(["jpeg","jpg","gif","bmp","webp","svg","tiff","avif","png","jfif","pjpeg","pjp"]),g=new Set(["mp3","wav","ogg","flac","aac","wma","alac","m4a","aiff","ape","au","mid","midi","opus"]),v=new Set(["mp4","webm","mov","avi","mkv","m4v"]),h=new Set(["csv","tsv","txt","json","xml","md","log","yaml","yml"]),w=new Set(["doc","docx","xls","xlsx","ppt","pptx"]),j=e=>b.has(e)?"image":g.has(e)?"audio":v.has(e)?"video":"pdf"===e?"pdf":"html"===e||"htm"===e?"html":h.has(e)?"text":w.has(e)?"office":"file",k=e=>{const t=(e=>{let t=e.trim();for(;/[),.;!?]$/.test(t);)t=t.slice(0,-1);return t})(e);return t.startsWith("http://")?`https://${t.slice(7)}`:t.startsWith("www.")?`https://${t}`:t};exports.default=({fileInfo:p,displayName:f})=>{const{theme:b,colors:g,disableHtml:v,disableJs:h}=l.usePickaxeMarkdownContext(),{contextId:w,pickaxeId:j,pickaxe:k,translations:y}=o.usePickaxeContext(),{isLoggedIn:N,token:C}=a.useAuthContext(),O=i.useSubmitDocument(),[S,I]=s.useState(!1),[q,F]=s.useState(!1),[D,$]=s.useState(!1),_=(e,t)=>{var s;return null!==(s=null==y?void 0:y[e])&&void 0!==s?s:t},P="dark"===b?"#30363D":"#D0D7DE",R="dark"===b?"#0D1117":"#F6F8FA",T="dark"===b?"#161B22":"#FFFFFF",U=(null==f?void 0:f.trim())||p.fileName,A=U!==p.fileName,B={display:"inline-flex",width:32,height:32,alignItems:"center",justifyContent:"center",borderRadius:4,color:g.accentText,backgroundColor:g.accent,opacity:.88,flexShrink:0},E=(e,s,o)=>t.jsx("div",Object.assign({className:"flex w-full p-4"},{children:t.jsxs("div",Object.assign({className:"relative w-full overflow-hidden rounded-md shadow-sm",style:{aspectRatio:"8.5 / 11",backgroundColor:T,border:`1px solid ${P}`}},{children:[t.jsx("iframe",Object.assign({src:e,title:s},o,{className:"h-full w-full",scrolling:"no",tabIndex:-1,style:{border:"none",pointerEvents:"none"}})),t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-10",style:{background:"dark"===b?"linear-gradient(to top, rgba(22,27,34,0.95), rgba(22,27,34,0))":"linear-gradient(to top, rgba(255,255,255,0.95), rgba(255,255,255,0))"}})]}))}));return t.jsxs("div",Object.assign({className:"my-2 w-full overflow-hidden rounded-lg",style:{border:`1px solid ${P}`,backgroundColor:R,color:g.secondaryText}},{children:[t.jsxs("div",Object.assign({className:"flex items-center justify-between gap-3 border-b px-3 py-2",style:{borderColor:P}},{children:[t.jsx("a",Object.assign({href:p.url,target:"_blank",rel:"noopener noreferrer",className:"min-w-0 flex-1 truncate text-sm font-semibold hover:underline",style:{color:g.secondaryText},title:A?`${U} (${p.fileName})`:U},{children:U})),t.jsxs("div",Object.assign({className:"flex shrink-0 items-center gap-1.5"},{children:[t.jsx("button",Object.assign({type:"button",onClick:()=>{const e=document.createElement("a");e.href=p.url,e.download=p.fileName,e.target="_blank",e.rel="noopener noreferrer",e.click()},title:_("download","Download"),"aria-label":_("download","Download"),style:B},{children:t.jsx(n.default,{className:"h-[18px] w-[18px]"})})),t.jsx("button",Object.assign({type:"button",onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){try{I(!0),x.default(p.url),yield new Promise((e=>setTimeout(e,1500)))}finally{I(!1)}}))},title:S?_("copied","Copied"):_("copy-link","Copy link"),"aria-label":S?_("copied","Copied"):_("copy-link","Copy link"),style:Object.assign(Object.assign({},B),{opacity:S?1:B.opacity})},{children:S?t.jsx(c.default,{className:"h-[18px] w-[18px]"}):t.jsx(r.default,{className:"h-[18px] w-[18px]"})})),N&&C&&t.jsx("button",Object.assign({type:"button",disabled:q||D,onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){if(C&&!q){F(!0),$(!1);try{const e=yield fetch(p.url);if(!e.ok)throw new Error("Failed to download generated file.");const t=yield e.blob(),s=new File([t],p.fileName,{type:t.type||"application/octet-stream"});yield O.document(Object.assign(Object.assign({contextId:w,pickaxeId:j,file:s},(null==k?void 0:k.workspaceid)&&{workspaceId:k.workspaceid}),{studioSessionToken:C,isUserDocument:!0})),$(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(m.default(e))}finally{F(!1),$(!1)}}}))},title:q?_("saving","Saving..."):D?_("saved","Saved"):_("save-to-knowledge-base","Save to Knowledge Base"),"aria-label":q?_("saving","Saving..."):D?_("saved","Saved"):_("save-to-knowledge-base","Save to Knowledge Base"),style:Object.assign(Object.assign({},B),{opacity:q||D?.55:B.opacity,cursor:q||D?"not-allowed":"pointer"})},{children:t.jsx(u.default,{className:"h-[18px] w-[18px]"})}))]}))]})),t.jsx("div",{children:(()=>{if("image"===p.kind)return t.jsx("img",{src:p.url,alt:p.fileName,className:"block max-h-[420px] w-full object-contain"});if("audio"===p.kind)return t.jsx("div",Object.assign({className:"flex min-h-[72px] items-center p-4"},{children:t.jsx("audio",{className:"w-full",controls:!0,src:p.url})}));if("video"===p.kind)return t.jsx("video",{className:"block max-h-[420px] w-full bg-black",controls:!0,preload:"metadata",src:p.url});if("pdf"===p.kind||"text"===p.kind){const e="pdf"===p.kind?`${p.url}#page=1&toolbar=0&navpanes=0&scrollbar=0&view=FitH`:p.url;return E(e,p.fileName)}if("html"===p.kind&&!v){const e=["allow-same-origin","allow-forms","allow-popups","allow-downloads","allow-modals",h?"":"allow-scripts"].filter(Boolean).join(" ");return E(p.url,p.fileName,{sandbox:e})}return"office"===p.kind?E(`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(p.url)}`,p.fileName):t.jsxs("div",Object.assign({className:"flex min-h-[120px] items-center justify-center gap-3 p-6 text-sm"},{children:[t.jsx(d.default,{className:"h-8 w-8 shrink-0"}),t.jsx("span",Object.assign({className:"break-all"},{children:p.extension.toUpperCase()}))]}))})()})]}))},exports.getFilePreviewInfo=e=>{var t,s;try{const o=k(e),a=new URL(o);if("https:"!==a.protocol&&"http:"!==a.protocol)return null;const i=a.pathname.split("/").filter(Boolean).pop();if(!i)return null;const l=decodeURIComponent(i),n=null===(s=null===(t=l.match(/\.([a-z0-9]{1,10})$/i))||void 0===t?void 0:t[1])||void 0===s?void 0:s.toLowerCase();return n?{url:o,fileName:l,extension:n,kind:j(n)}:null}catch(e){return null}},exports.normalizeMarkdownUrl=k,exports.shouldRenderFilePreview=(e,t)=>!!e&&(!t||!t.current.has(e.url)&&(t.current.add(e.url),!0));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../../hooks/usePickaxeMarkdownContext.js"),s=require("../Img/index.js"),o=require("../common/IframeVideo.js"),i=require("./Audio.js"),a=require("./Html/index.js");exports.A=({href:m="",children:c})=>{const{colors:u}=r.usePickaxeMarkdownContext(),l=t.useMemo((()=>{if(!m)return"";return m.startsWith("http://")?`https://${m.slice(7)}`:m.startsWith("www.")?`https://${m}`:m}),[m]),n=t.useMemo((()=>{const e=l.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const t=l.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(t)return{title:"loom-embed",src:`https://www.loom.com/embed/${t[1]}`};const r=l.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(r)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${r[1]}`};const s=l.match(/streamable\.com\/([\w-]+)/i);return s?{title:"streamable-embed",src:`https://streamable.com/e/${s[1]}`}:null}),[l]),d=t.useMemo((()=>l.match(/\.(jpeg|jpg|gif|bmp|webp|svg|tiff|avif|png|jfif|pjpeg|pjp)$/)),[l]),p=t.useMemo((()=>l.includes("action_generated_files")&&l.match(/\.(mp3|wav|ogg|flac|aac|wma|alac|m4a|aiff|ape|au|mid|midi|opus)$/)),[l]),f=t.useMemo((()=>l.includes("action_generated_files")&&l.match(/\.html$/)),[l]);return n?e.jsx(o.default,{title:n.title,src:n.src}):d?e.jsx(s.Img,{src:l,alt:"string"==typeof c?c:"Markdown Image"}):p?e.jsx(i.default,{url:l}):f?e.jsx(a.default,{url:l}):e.jsx("a",Object.assign({href:l,target:"_blank",rel:"noopener noreferrer",style:{color:u.accent}},{children:c}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),t=require("../../hooks/usePickaxeMarkdownContext.js"),o=require("../common/IframeVideo.js"),i=require("./FilePreview.js");const s=e=>{let t="";return r.Children.forEach(e,(e=>{"string"!=typeof e&&"number"!=typeof e?r.isValidElement(e)&&(t+=s(e.props.children)):t+=e})),t.trim().replace(/\s+/g," ")};exports.A=({href:l="",children:n,filePreviewSeenRef:c})=>{const{colors:m}=t.usePickaxeMarkdownContext(),a=r.useMemo((()=>l?i.normalizeMarkdownUrl(l):""),[l]),u=r.useMemo((()=>i.getFilePreviewInfo(a)),[a]),d=r.useMemo((()=>((e,r)=>{const t=s(e);if(t&&t!==r&&i.normalizeMarkdownUrl(t)!==r)return t})(n,a)),[n,a]),f=r.useMemo((()=>{if(u)return null;const e=a.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const r=a.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(r)return{title:"loom-embed",src:`https://www.loom.com/embed/${r[1]}`};const t=a.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(t)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${t[1]}`};const o=a.match(/streamable\.com\/([\w-]+)/i);return o?{title:"streamable-embed",src:`https://streamable.com/e/${o[1]}`}:null}),[u,a]);return f?e.jsx(o.default,{title:f.title,src:f.src}):u&&i.shouldRenderFilePreview(u,c)?e.jsx(i.default,{fileInfo:u,displayName:d}):e.jsx("a",Object.assign({href:a,target:"_blank",rel:"noopener noreferrer",style:{color:m.accent}},{children:n}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),n=require("react"),t=require("./hooks/usePickaxeMarkdownContext.js"),i=require("./utils/custom-plugins.js"),s=require("react-markdown"),a=require("remark-gfm"),o=require("remark-math"),l=require("rehype-katex"),c=require("rehype-raw"),u=require("./Components/A/index.js"),d=require("./Components/P/index.js"),p=require("./Components/Img/index.js"),h=require("./Components/Iframe/index.js"),m=require("./Components/Code/index.js"),f=require("./Components/Headings/index.js"),x=require("./Components/List/index.js"),g=require("./Components/Table/index.js"),j=require("./Components/Others/index.js"),b=require("./Components/Action/index.js"),q=require("./Components/Artifact/index.js"),C=require("./Components/Others/Think.js"),k=require("../../../../common/cn.js");function w(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var $=w(s),v=w(a),y=w(o),O=w(l),A=w(c);exports.PickaxeMarkdownRenderer=({className:s,style:a,children:o,value:l,maxLines:c,maxChars:w,multiLineBreaks:H,onExpandClick:T})=>{const{colors:M,rtl:P,disableHtml:S,disableJs:_,disableCss:E}=t.usePickaxeMarkdownContext(),[I,L]=n.useState({width:0,height:0}),[B,N]=n.useState(null),R=n.useRef(null),z=n.useMemo((()=>{if(!l)return"";let e=l.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),H&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[l,H]);n.useEffect((()=>{if(w)return void N(z.length>w?z.slice(0,w)+'<span class="pxe-expand-btn">...</span>':null);if(!c)return void N(null);if(!R.current||!z||B)return;const e=R.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),n=c*r;if(!(I.height>n))return;const t=Math.floor(I.width/8),i=Math.floor(t*c);N(z.slice(0,i)+'<span class="pxe-expand-btn">...</span>')}),[z,c,w,I,B]);const J={h1:f.H1,h2:f.H2,h3:f.H3,h4:f.H4,h5:f.H5,p:d.P,a:u.A,img:p.Img,iframe:h.Iframe,code:m.Code,ol:x.Ol,ul:x.Ul,li:x.Li,table:g.Table,th:g.Th,tr:g.Tr,td:g.Td,hr:j.Hr,br:j.Br,blockquote:j.Blockquote,span:n=>{var{children:t}=n,i=e.__rest(n,["children"]);return"pxe-expand-btn"===i.className?r.jsx("span",Object.assign({},i,{style:Object.assign({display:"inline",fontWeight:500,color:M.accent,marginLeft:".25rem",userSelect:"none"},T&&{cursor:"pointer"})},T&&{onClick:T},{children:t})):r.jsx("span",Object.assign({},i,{children:t}))},"action-caption":b.ActionCaption,"action-finished":b.ActionFinished,"action-error":b.ActionError,artifact:q.Artifact,"artifact-error":q.ArtifactError,think:C.Think};n.useEffect((()=>{if(!R.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:n}=r.contentRect;L({width:e,height:n})}}));return e.observe(R.current),()=>{e.disconnect()}}),[]);const W=B||z;return r.jsxs("div",Object.assign({className:"pxe-markdown",ref:R,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},a)},P&&{dir:"rtl"},{children:[r.jsx($.default,Object.assign({className:k.default("pxe-prose",s),components:J,remarkPlugins:[v.default,[y.default,{singleDollarTextMath:!1}]],rehypePlugins:[i.rehypeCode,O.default,...S?[]:[A.default],[i.rehypeSanitize,{disableJs:_,disableCss:E}]]},{children:W})),o]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),n=require("react"),t=require("./hooks/usePickaxeMarkdownContext.js"),i=require("./utils/custom-plugins.js"),s=require("react-markdown"),a=require("remark-gfm"),o=require("remark-math"),l=require("rehype-katex"),c=require("rehype-raw"),u=require("./Components/A/index.js"),d=require("./Components/A/FilePreview.js"),p=require("./Components/P/index.js"),f=require("./Components/Img/index.js"),h=require("./Components/Iframe/index.js"),m=require("./Components/Code/index.js"),x=require("./Components/Headings/index.js"),g=require("./Components/List/index.js"),j=require("./Components/Table/index.js"),b=require("./Components/Others/index.js"),q=require("./Components/Action/index.js"),C=require("./Components/Artifact/index.js"),k=require("./Components/Others/Think.js"),w=require("../../../../common/cn.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var y=v(s),O=v(a),$=v(o),P=v(l),S=v(c);exports.PickaxeMarkdownRenderer=({className:s,style:a,children:o,value:l,maxLines:c,maxChars:v,multiLineBreaks:A,onExpandClick:H,filePreviewSeenRef:T})=>{const{colors:M,rtl:R,disableHtml:I,disableJs:_,disableCss:N}=t.usePickaxeMarkdownContext(),[E,L]=n.useState({width:0,height:0}),[B,F]=n.useState(null),z=n.useRef(null),J=n.useMemo((()=>{if(!l)return"";let e=l.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),A&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[l,A]);n.useEffect((()=>{if(v)return void F(J.length>v?J.slice(0,v)+'<span class="pxe-expand-btn">...</span>':null);if(!c)return void F(null);if(!z.current||!J||B)return;const e=z.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),n=c*r;if(!(E.height>n))return;const t=Math.floor(E.width/8),i=Math.floor(t*c);F(J.slice(0,i)+'<span class="pxe-expand-btn">...</span>')}),[J,c,v,E,B]);const W=n.useRef(new Set);T||(W.current=new Set);const D=null!=T?T:W,U={h1:x.H1,h2:x.H2,h3:x.H3,h4:x.H4,h5:x.H5,p:p.P,a:e=>r.jsx(u.A,Object.assign({},e,{filePreviewSeenRef:D})),img:e=>{const n="string"==typeof e.src?e.src:"",t=d.getFilePreviewInfo(n);return t?d.shouldRenderFilePreview(t,D)?r.jsx(d.default,{fileInfo:t,displayName:"string"==typeof e.alt?e.alt:void 0}):r.jsx("a",Object.assign({href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:M.accent}},{children:e.alt||t.fileName})):r.jsx(f.Img,Object.assign({},e))},iframe:h.Iframe,code:m.Code,ol:g.Ol,ul:g.Ul,li:g.Li,table:j.Table,th:j.Th,tr:j.Tr,td:j.Td,hr:b.Hr,br:b.Br,blockquote:b.Blockquote,span:n=>{var{children:t}=n,i=e.__rest(n,["children"]);return"pxe-expand-btn"===i.className?r.jsx("span",Object.assign({},i,{style:Object.assign({display:"inline",fontWeight:500,color:M.accent,marginLeft:".25rem",userSelect:"none"},H&&{cursor:"pointer"})},H&&{onClick:H},{children:t})):r.jsx("span",Object.assign({},i,{children:t}))},"action-caption":q.ActionCaption,"action-finished":q.ActionFinished,"action-error":q.ActionError,artifact:C.Artifact,"artifact-error":C.ArtifactError,think:k.Think};n.useEffect((()=>{if(!z.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:n}=r.contentRect;L({width:e,height:n})}}));return e.observe(z.current),()=>{e.disconnect()}}),[]);const G=B||J;return r.jsxs("div",Object.assign({className:"pxe-markdown",ref:z,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},a)},R&&{dir:"rtl"},{children:[r.jsx(y.default,Object.assign({className:w.default("pxe-prose",s),components:U,remarkPlugins:[O.default,[$.default,{singleDollarTextMath:!1}]],rehypePlugins:[i.rehypeCode,P.default,...I?[]:[S.default],[i.rehypeSanitize,{disableJs:_,disableCss:N}]]},{children:G})),o]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),n=require("react"),r=require("../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../PickaxeMarkdown/Renderer.js"),t=require("../../../../common/utils.js"),a=require("../../../../common/cn.js");const i=n.lazy((()=>Promise.resolve().then((function(){return require("./TextPart/index.js")})))),o=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningPart/index.js")})))),l=n.lazy((()=>Promise.resolve().then((function(){return require("./ActionToolCaptionPart/index.js")})))),c=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningCaptionPart/index.js")}))));exports.default=({className:u,parts:d})=>{const{translations:x}=r.usePickaxeContext();return e.jsx("div",Object.assign({className:a.default("flex flex-col gap-2",u)},{children:e.jsx(n.Suspense,Object.assign({fallback:e.jsx("div",{})},{children:d.map(((n,r)=>{if(!n.isVisible)return null;if("text"===n.type){const t=/(https?:\/\/[^\s"']+\.mp4)/g,a=n.content.split(t);return e.jsx(i,{children:a.map(((n,r)=>n.match(t)?e.jsx("div",Object.assign({className:"my-3 block w-full max-w-full"},{children:e.jsx("video",Object.assign({controls:!0,preload:"metadata",className:"max-h-[400px] w-auto max-w-full rounded-lg bg-black/5 shadow-sm",src:n},{children:e.jsx("a",Object.assign({href:n,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-500 hover:underline"},{children:(null==x?void 0:x["download-video"])||"Download Video"}))}))}),r):n?e.jsx(s.PickaxeMarkdownRenderer,{value:n},r):null))},r)}if("reasoning"===n.type)return e.jsx(o,Object.assign({isReasoning:r===d.length-1},{children:e.jsx(s.PickaxeMarkdownRenderer,{value:n.content})}),r);if("data-action-tool-caption"===n.type){const s=t.safeJSONParse(n.content);return e.jsx(l,Object.assign({},s&&s,{isLoading:r===d.length-1}),r)}if("data-reasoning-caption"===n.type){const s=t.safeJSONParse(n.content);return e.jsx(c,Object.assign({},s&&s,{isLoading:r===d.length-1}),r)}return null}))}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),n=require("react"),r=require("../PickaxeMarkdown/Renderer.js"),t=require("../PickaxeMarkdown/Components/A/FilePreview.js"),i=require("../../../../common/utils.js"),s=require("../../../../common/cn.js");const a=n.lazy((()=>Promise.resolve().then((function(){return require("./TextPart/index.js")})))),o=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningPart/index.js")})))),l=n.lazy((()=>Promise.resolve().then((function(){return require("./ActionToolCaptionPart/index.js")})))),u=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningCaptionPart/index.js")})))),c=/(!?)\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|www\.[^\s)]+)\)/g;exports.default=({className:d,parts:p})=>{const f=n.useRef(new Set);return f.current=new Set,e.jsx("div",Object.assign({className:s.default("flex flex-col gap-2",d)},{children:e.jsx(n.Suspense,Object.assign({fallback:e.jsx("div",{})},{children:p.map(((n,s)=>{if(!n.isVisible)return null;if("text"===n.type){const i=((e,n)=>{var r,i;const s=[];let a=0;for(const o of e.matchAll(c)){const l=null!==(r=o.index)&&void 0!==r?r:0,u=o[0],c="!"===o[1],d=null===(i=o[2])||void 0===i?void 0:i.trim(),p=o[3],f=t.getFilePreviewInfo(p);if(!f)continue;l>a&&s.push({type:"markdown",value:e.slice(a,l)});const v=d&&t.normalizeMarkdownUrl(d)!==f.url?d:void 0;t.shouldRenderFilePreview(f,n)?s.push({type:"preview",key:`${f.url}-${l}`,fileInfo:f,displayName:v}):s.push({type:"markdown",value:c?u:`[${d||f.fileName}](${f.url})`}),a=l+u.length}return a<e.length&&s.push({type:"markdown",value:e.slice(a)}),s.length?s:[{type:"markdown",value:e}]})(n.content,f);return e.jsx(a,{children:i.map(((n,i)=>"preview"===n.type?e.jsx(t.default,{fileInfo:n.fileInfo,displayName:n.displayName},n.key):n.value?e.jsx(r.PickaxeMarkdownRenderer,{value:n.value,filePreviewSeenRef:f},i):null))},s)}if("reasoning"===n.type)return e.jsx(o,Object.assign({isReasoning:s===p.length-1},{children:e.jsx(r.PickaxeMarkdownRenderer,{value:n.content})}),s);if("data-action-tool-caption"===n.type){const r=i.safeJSONParse(n.content);return e.jsx(l,Object.assign({},r&&r,{isLoading:s===p.length-1}),s)}if("data-reasoning-caption"===n.type){const r=i.safeJSONParse(n.content);return e.jsx(u,Object.assign({},r&&r,{isLoading:s===p.length-1}),s)}return null}))}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("../../hooks/pickaxe/usePickaxe.js"),a=require("react"),i=require("../../hooks/pickaxe/usePickaxeContext.js"),l=require("./Addons/Auth/hooks/useAuthContext.js"),r=require("../../hooks/pickaxe/useResponseContext.js"),o=require("./Addons/Document/hooks/useDocumentContext.js"),c=require("./Addons/Artifact/hooks/useArtifactContext.js"),n=require("uuid"),d=require("./Addons/Scroll/Provider.js"),u=require("./common/PickaxeSkeleton.js"),x=require("./Chat/index.js"),p=require("./Form/index.js"),m=require("./Addons/Auth/index.js"),f=require("../../common/cn.js"),j=require("../../common/api/pickaxe.js"),h=require("../../common/validation.js"),v=require("./common/AccessGroupCardPreview.js"),g=require("./common/PickaxeAvatar.js"),b=require("../Icons/lock.svg.js"),k=require("../../node_modules/.pnpm/@stripe_react-stripe-js@4.0.2_@stripe_stripe-js@7.9.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@stripe/react-stripe-js/dist/react-stripe.esm.mjs.js"),y=require("../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js");const w=({className:e})=>s.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e},{children:s.jsx("polyline",{points:"15 18 9 12 15 6"})}));exports.Pickaxe=({pickaxeId:N,className:q})=>{const{sessionId:O,styles:_,colors:C,responsiveBy:A,deploymentType:I,isNewChat:S,isEmbed:P,opacity:E,deploymentId:U,sender:R,portalId:T,validationStatus:G,validationUpgradeGroups:L,validationUpgradeUrl:D,stripeAccountId:F,clientSecret:M,translations:B,preventInitialSessionId:V,setClientSecret:$,setStripeAccountId:W,setValidationStatus:z,setValidationUpgradeGroups:H,setValidationUpgradeUrl:J,setContextId:K,setPickaxeId:X,setSessionId:Y,setPickaxe:Q,setAccessGroup:Z}=i.usePickaxeContext(),{isSent:ee,token:se}=l.useAuthContext(),{setMessages:te,setResponse:ae,setError:ie,setLimitData:le,setIsSwitchedToChat:re}=r.useResponseContext(),{setDocumentError:oe}=o.useDocumentContext(),{setCurrentArtifact:ce}=c.useArtifactContext(),[ne,de]=a.useState(!1),ue=t.usePickaxe(),xe="chat-input"===I&&S&&!ee,pe=a.useMemo((()=>F?y.loadStripe(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:F}):null),[F]);a.useEffect((()=>{X(N)}),[N]);a.useEffect((()=>{if(!U&&!T||!ue.data)return;if("stripe_checkout"===G)return;e.__awaiter(void 0,void 0,void 0,(function*(){var e;z("loading");try{const s=yield j.default.post("/validate_studio_deployment",{data:{deploymentId:U,sender:R||void 0,studioSessionToken:se,portalId:T,studioId:null===(e=ue.data)||void 0===e?void 0:e.studioid}});if(s.data.success)z("success"),H([]),J(null),Z(s.data.accessGroup);else{const e=h.getValidationFailure(s.data);if(!e)return z("login_required"),H([]),void J(null);z(e.status),H(e.upgradeGroups),J(e.upgradeUrl),de(!0)}}catch(e){console.error("Failed to validate deployment:",e),z("success")}}))}),[U,R,se,T,ue.data]),a.useEffect((()=>{if(!ue.data)return;const e=ue.data.chatflag;V||Y(e?n.v4():""),K(n.v4()),e?te([]):ae(null),ie(""),oe(""),le(null),ce(null),re(!1),Q(ue.data),de(!0)}),[ue.data]),a.useEffect((()=>{ie(""),oe(""),le(null),te([]),ae(null),ce(null)}),[O]);const me=a.useMemo((()=>{const e=null!=E?E:1;if(!C.primary||!C.primary.startsWith("#")||e<0||e>1)return C.primary;const s=Math.round(255*e).toString(16).padStart(2,"0");return`${C.primary}${s}`}),[C.primary,E]);if(!ue.data)return null;return s.jsx("div",Object.assign({className:f.default("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===_.theme&&"dark",q),style:Object.assign({backgroundColor:xe?"transparent":me,color:C.text},_.font&&"Real Head Pro"!==_.font&&{fontFamily:_.font})},{children:"stripe_checkout"===G&&M&&pe?s.jsxs("div",Object.assign({className:"absolute inset-0 z-[999] flex flex-col w-full h-full overflow-hidden",style:{backgroundColor:C.secondary||"#ffffff",color:C.secondaryText||"#000000"}},{children:[s.jsx("div",Object.assign({className:"flex items-center p-4 border-b border-gray-100 shrink-0"},{children:s.jsxs("button",Object.assign({onClick:()=>{$&&$(null),W&&W(null),z("success")},className:"flex items-center gap-2 text-sm font-semibold opacity-70 hover:opacity-100 transition-opacity",style:{color:C.text}},{children:[s.jsx(w,{className:"w-5 h-5"}),s.jsx("span",{children:(null==B?void 0:B.back)||"Back"})]}))})),s.jsx("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s.jsx(k.EmbeddedCheckoutProvider,Object.assign({stripe:pe,options:{clientSecret:M}},{children:s.jsx(k.EmbeddedCheckout,{})}))}))]})):ue.isLoading||!ne||"loading"===G?s.jsx("div",Object.assign({className:f.default("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===A?"min-[767px]:pb-40":"@[767px]/pickaxe-root:pb-40")},{children:s.jsxs("div",Object.assign({className:"flex w-full items-center max-w-[700px] flex-col"},{children:[s.jsx(u.default,{className:"w-[72px] h-[72px]"}),s.jsx(u.default,{className:"h-[20px] mt-6 w-full"}),s.jsx(u.default,{className:"h-[20px] mt-2 w-full"}),s.jsx(u.default,{className:"h-[20px] mt-2 w-full max-w-[400px]"}),s.jsx("div",Object.assign({className:"flex flex-col gap-y-8 w-full mt-6"},{children:s.jsx(u.default,{className:f.default("w-full min-h-[48px]","viewport"===A?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))})):"upgrade_required"===G?s.jsx("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:L&&L.length>0?s.jsxs("div",Object.assign({className:"flex flex-col items-center gap-6 w-full max-w-4xl"},{children:[s.jsxs("div",Object.assign({className:"text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==B?void 0:B["upgrade-required"])||"Upgrade Required"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==B?void 0:B["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool."}))]})),s.jsx("div",Object.assign({className:"flex flex-wrap justify-center gap-4 w-full"},{children:L.map(((e,t)=>s.jsx(v.default,{data:e,upgradeUrl:D},e.id||t)))}))]})):s.jsxs("div",Object.assign({className:"text-center mb-8"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==B?void 0:B["access-locked"])||"Access Locked"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==B?void 0:B["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))})):"login_required"===G&&P?s.jsx(m.default,{}):"login_required"!==G||P?"access_denied"===G?s.jsxs("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:[s.jsxs(g.Avatar,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s.jsx(g.AvatarImage,{src:null===(fe=ue.data)||void 0===fe?void 0:fe.coverphoto,alt:`${null===(je=ue.data)||void 0===je?void 0:je.formtitle} Logo`}),s.jsx(g.AvatarFallback,{})]})),s.jsxs("div",Object.assign({className:"text-center mb-6"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==B?void 0:B["access-denied"])||"Access Denied"})),s.jsxs("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s.jsx(b.default,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s.jsx("p",Object.assign({className:"ml-1"},{children:(null==B?void 0:B["no-access-request-access"])||"It looks like you don't have access to these resources. Please request access to continue."}))]}))]})),s.jsx("button",Object.assign({className:"px-6 py-2 font-medium rounded-md transition-colors",style:{backgroundColor:C.accent,color:C.accentText,borderRadius:_.cornerRadius},onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;const t=L.map((e=>e.accessGroupId));try{const a=yield j.default.post("/request_access",{data:{sender:R||void 0,studioSessionToken:se,studioId:null===(e=ue.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=ue.data)||void 0===s?void 0:s.formid,deploymentId:U,accessGroupIds:t})}});a.data.success?alert((null==B?void 0:B["access-requested-successfully"])||"Successfully requested access!"):alert(a.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==B?void 0:B["request-access"])||"Request Access"})),s.jsx("span",Object.assign({className:"mt-4 mb-2"},{children:(null==B?void 0:B.or)||"or"})),s.jsx("span",Object.assign({className:"font-medium text-lg"},{children:(null==B?void 0:B["sign-in-with-different-account"])||"Sign in with a different account"}))]})):O?s.jsx(d.ScrollProvider,{children:s.jsx(x.default,{})}):s.jsx(d.ScrollProvider,{children:s.jsx(p.default,{})}):s.jsx("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:s.jsxs("div",Object.assign({className:"text-center mb-8"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==B?void 0:B["access-denied"])||"Access Denied"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==B?void 0:B["login-is-required"])||"Login is required."}))]}))}))}));var fe,je};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("../../hooks/pickaxe/usePickaxe.js"),a=require("react"),i=require("../../hooks/pickaxe/usePickaxeContext.js"),r=require("./Addons/Auth/hooks/useAuthContext.js"),l=require("../../hooks/pickaxe/useResponseContext.js"),o=require("./Addons/Document/hooks/useDocumentContext.js"),c=require("./Addons/Artifact/hooks/useArtifactContext.js"),n=require("uuid"),d=require("./Addons/Scroll/Provider.js"),u=require("./common/PickaxeSkeleton.js"),x=require("./Chat/index.js"),p=require("./Form/index.js"),m=require("./Addons/Auth/index.js"),f=require("../../common/cn.js"),j=require("../../common/api/pickaxe.js"),h=require("../../common/validation.js"),v=require("./common/AccessGroupCardPreview.js"),g=require("./common/PickaxeAvatar.js"),b=require("../Icons/lock.svg.js"),k=require("../../node_modules/.pnpm/@stripe_react-stripe-js@4.0.2_@stripe_stripe-js@7.9.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@stripe/react-stripe-js/dist/react-stripe.esm.mjs.js"),w=require("../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js");const y=({className:e})=>s.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e},{children:s.jsx("polyline",{points:"15 18 9 12 15 6"})}));exports.Pickaxe=({pickaxeId:N,className:q})=>{const{sessionId:O,styles:_,colors:C,responsiveBy:A,deploymentType:I,isNewChat:S,isEmbed:P,opacity:E,deploymentId:U,sender:G,portalId:R,validationStatus:T,validationUpgradeGroups:L,validationUpgradeUrl:D,stripeAccountId:F,clientSecret:M,translations:B,preventInitialSessionId:V,setClientSecret:$,setStripeAccountId:W,setValidationStatus:z,setValidationUpgradeGroups:H,setValidationUpgradeUrl:J,setContextId:K,setPickaxeId:X,setSessionId:Y,setPickaxe:Q,setAccessGroup:Z}=i.usePickaxeContext(),{isSent:ee,token:se}=r.useAuthContext(),{setMessages:te,setResponse:ae,setError:ie,setLimitData:re,setIsSwitchedToChat:le}=l.useResponseContext(),{setDocumentError:oe}=o.useDocumentContext(),{setCurrentArtifact:ce}=c.useArtifactContext(),[ne,de]=a.useState(!1),ue=t.usePickaxe(),xe="chat-input"===I&&S&&!ee,pe=a.useMemo((()=>F?w.loadStripe(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:F}):null),[F]);a.useEffect((()=>{X(N)}),[N]);a.useEffect((()=>{if(!U&&!R||!ue.data)return;if("stripe_checkout"===T)return;e.__awaiter(void 0,void 0,void 0,(function*(){var e;z("loading");try{const s=yield j.default.post("/validate_studio_deployment",{data:{deploymentId:U,sender:G||void 0,studioSessionToken:se,portalId:R,studioId:null===(e=ue.data)||void 0===e?void 0:e.studioid}});if(s.data.success)z("success"),H([]),J(null),Z(s.data.accessGroup);else{const e=h.getValidationFailure(s.data);if(!e)return z("login_required"),H([]),void J(null);z(e.status),H(e.upgradeGroups),J(e.upgradeUrl),de(!0)}}catch(e){console.error("Failed to validate deployment:",e),z("success")}}))}),[U,G,se,R,ue.data]),a.useEffect((()=>{if(!ue.data)return;const e=ue.data.chatflag;V||Y(e?n.v4():""),K(n.v4()),e?te([]):ae(null),ie(""),oe(""),re(null),ce(null),le(!1),Q(ue.data),de(!0)}),[ue.data]),a.useEffect((()=>{ie(""),oe(""),re(null),te([]),ae(null),ce(null)}),[O]);const me=a.useMemo((()=>{const e=null!=E?E:1;if(!C.primary||!C.primary.startsWith("#")||e<0||e>1)return C.primary;const s=Math.round(255*e).toString(16).padStart(2,"0");return`${C.primary}${s}`}),[C.primary,E]);if(!ue.data)return null;return s.jsx("div",Object.assign({className:f.default("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===_.theme&&"dark",q),style:Object.assign({backgroundColor:xe?"transparent":me,color:C.text},_.font&&"Real Head Pro"!==_.font&&{fontFamily:_.font})},{children:(()=>{var t,a;if("stripe_checkout"===T&&M&&pe)return s.jsxs("div",Object.assign({className:"absolute inset-0 z-[999] flex flex-col w-full h-full overflow-hidden",style:{backgroundColor:C.secondary||"#ffffff",color:C.secondaryText||"#000000"}},{children:[s.jsx("div",Object.assign({className:"flex items-center p-4 border-b border-gray-100 shrink-0"},{children:s.jsxs("button",Object.assign({onClick:()=>{$&&$(null),W&&W(null),z("success")},className:"flex items-center gap-2 text-sm font-semibold opacity-70 hover:opacity-100 transition-opacity",style:{color:C.text}},{children:[s.jsx(y,{className:"w-5 h-5"}),s.jsx("span",{children:(null==B?void 0:B.back)||"Back"})]}))})),s.jsx("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s.jsx(k.EmbeddedCheckoutProvider,Object.assign({stripe:pe,options:{clientSecret:M}},{children:s.jsx(k.EmbeddedCheckout,{})}))}))]}));if(ue.isLoading||!ne||"loading"===T)return s.jsx("div",Object.assign({className:f.default("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===A?"min-[767px]:pb-40":"@[767px]/pickaxe-root:pb-40")},{children:s.jsxs("div",Object.assign({className:"flex w-full items-center max-w-[700px] flex-col"},{children:[s.jsx(u.default,{className:"w-[72px] h-[72px]"}),s.jsx(u.default,{className:"h-[20px] mt-6 w-full"}),s.jsx(u.default,{className:"h-[20px] mt-2 w-full"}),s.jsx(u.default,{className:"h-[20px] mt-2 w-full max-w-[400px]"}),s.jsx("div",Object.assign({className:"flex flex-col gap-y-8 w-full mt-6"},{children:s.jsx(u.default,{className:f.default("w-full min-h-[48px]","viewport"===A?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))}));if("upgrade_required"===T){const e=L.length>0;return s.jsx("div",Object.assign({className:"flex h-full min-h-0 w-full items-start justify-center overflow-y-auto p-4"},{children:e?s.jsxs("div",Object.assign({className:"flex w-full max-w-4xl flex-col items-center gap-6 py-6"},{children:[s.jsxs("div",Object.assign({className:"max-w-[640px] text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2 break-words"},{children:(null==B?void 0:B["upgrade-required"])||"Upgrade Required"})),s.jsx("p",Object.assign({className:"break-words opacity-80"},{children:(null==B?void 0:B["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool."}))]})),s.jsx("div",Object.assign({className:"flex w-full flex-wrap justify-center gap-4"},{children:L.map(((e,t)=>s.jsx(v.default,{data:e,upgradeUrl:D},e.accessGroupId||e.id||t)))}))]})):s.jsxs("div",Object.assign({className:"m-auto text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==B?void 0:B["access-locked"])||"Access Locked"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==B?void 0:B["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))}))}return"login_required"===T&&P?s.jsx(m.default,{}):"login_required"!==T||P?"access_denied"===T?s.jsxs("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:[s.jsxs(g.Avatar,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s.jsx(g.AvatarImage,{src:null===(t=ue.data)||void 0===t?void 0:t.coverphoto,alt:`${null===(a=ue.data)||void 0===a?void 0:a.formtitle} Logo`}),s.jsx(g.AvatarFallback,{})]})),s.jsxs("div",Object.assign({className:"text-center mb-6"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==B?void 0:B["access-denied"])||"Access Denied"})),s.jsxs("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s.jsx(b.default,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s.jsx("p",Object.assign({className:"ml-1"},{children:(null==B?void 0:B["no-access-request-access"])||"It looks like you don't have access to these resources. Please request access to continue."}))]}))]})),s.jsx("button",Object.assign({className:"px-6 py-2 font-medium rounded-md transition-colors",style:{backgroundColor:C.accent,color:C.accentText,borderRadius:_.cornerRadius},onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;const t=L.map((e=>e.accessGroupId));try{const a=yield j.default.post("/request_access",{data:{sender:G||void 0,studioSessionToken:se,studioId:null===(e=ue.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=ue.data)||void 0===s?void 0:s.formid,deploymentId:U,accessGroupIds:t})}});a.data.success?alert((null==B?void 0:B["access-requested-successfully"])||"Successfully requested access!"):alert(a.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==B?void 0:B["request-access"])||"Request Access"})),s.jsx("span",Object.assign({className:"mt-4 mb-2"},{children:(null==B?void 0:B.or)||"or"})),s.jsx("span",Object.assign({className:"font-medium text-lg"},{children:(null==B?void 0:B["sign-in-with-different-account"])||"Sign in with a different account"}))]})):O?s.jsx(d.ScrollProvider,{children:s.jsx(x.default,{})}):s.jsx(d.ScrollProvider,{children:s.jsx(p.default,{})}):s.jsx("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:s.jsxs("div",Object.assign({className:"text-center mb-8"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==B?void 0:B["access-denied"])||"Access Denied"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==B?void 0:B["login-is-required"])||"Login is required."}))]}))}))})()}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("../../common/utils.js");exports.useSubmitDocument=()=>({document:({contextId:s,pickaxeId:o,file:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,l;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const _=i.name.split(".").pop(),p="md"===_?"md":i.type,u={sessionid:s,formid:o,mimetype:p,extension:_,responseid:t,workspaceid:n},O=new URLSearchParams(Object.entries(u).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),g=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${O.toString()}`,f=yield fetch(g),w=yield f.json();if(!w.success)throw new Error(null!==(e=w.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const b=new FormData;Object.entries(Object.assign(Object.assign({},w.fields),{file:i})).forEach((([e,s])=>{b.append(e,s)}));const m=yield fetch(w.url,{method:"POST",body:b});if(!m.ok)throw new Error(m.statusText);const I=`${w.url}${w.fields.key}`;"development"===process.env.NODE_ENV&&console.log("[S3URL]",I);const j=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o,documentId:w.documentId,fileName:i.name,fileSize:i.size},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),P=yield j.json();if(!P.success)throw new Error(null!==(l=P.error)&&void 0!==l?l:"Failed processing document, try again or contact support.");return Object.assign(Object.assign({},P),{folder:w.folder})})),website:({pickaxeId:o,website:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const l=s.generateId(20),_=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o,documentId:l,website:i},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),p=yield _.json();if(!p.success)throw new Error(null!==(e=p.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return p}))});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("../../common/utils.js");exports.useSubmitDocument=()=>({document:({contextId:s,pickaxeId:o,file:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isUserDocument:a,isBlocking:l})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,u;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const _=i.name.split(".").pop(),p="md"===_?"md":i.type,O={sessionid:s,formid:o,mimetype:p,extension:_,responseid:t,workspaceid:n},g=new URLSearchParams(Object.entries(O).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),m=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${g.toString()}`,b=yield fetch(m),f=yield b.json();if(!f.success)throw new Error(null!==(e=f.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const w=new FormData;Object.entries(Object.assign(Object.assign({},f.fields),{file:i})).forEach((([e,s])=>{w.append(e,s)}));const j=yield fetch(f.url,{method:"POST",body:w});if(!j.ok)throw new Error(j.statusText);const I=`${f.url}${f.fields.key}`;"development"===process.env.NODE_ENV&&console.log("[S3URL]",I);const P=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o,documentId:f.documentId,fileName:i.name,fileSize:i.size},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isUserDocument:a}),l&&{isBlocking:l})),headers:{"Content-Type":"application/json"}}),U=yield P.json();if(!U.success)throw new Error(null!==(u=U.error)&&void 0!==u?u:"Failed processing document, try again or contact support.");return Object.assign(Object.assign({},U),{folder:f.folder})})),website:({pickaxeId:o,website:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isUserDocument:a,isBlocking:l})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const u=s.generateId(20),_=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o,documentId:u,website:i},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isUserDocument:a}),l&&{isBlocking:l})),headers:{"Content-Type":"application/json"}}),p=yield _.json();if(!p.success)throw new Error(null!==(e=p.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return p}))});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("../../../../../_virtual/_commonjsHelpers.js"),r=require("../../../../../_virtual/cose-base.js"),i=require("../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js");r.__module.exports,exports.__require=function(){return t||(t=1,o=r.__module,r.__module.exports,e.commonjsGlobal,n=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},o.exports=n(i.__require())),r.__module.exports;var o,n};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("../../../../../_virtual/_commonjsHelpers.js"),r=require("../../../../../_virtual/cose-base2.js"),i=require("../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js");r.__module.exports,exports.__require=function(){return t||(t=1,o=r.__module,r.__module.exports,e.commonjsGlobal,n=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},o.exports=n(i.__require())),r.__module.exports;var o,n};