@pickaxeproject/react 3.5.3 → 3.6.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.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),n=require("docx");function t(e,t){const i=[];let a="",l=!1,o=!1,s=!1,g=-1,p=-1;for(let c=0;c<e.length;c++)if("\\"===e[c]&&c+1<e.length){const n=e[c+1];if("*"===n||"`"===n||"\\"===n){a+=n,c++;continue}a+=e[c]}else"`"!==e[c]||s?"`"===e[c]&&s?(a&&(i.push(r(a,t)),a=""),s=!1):s?a+=e[c]:c+1<e.length&&"*"===e[c]&&"*"===e[c+1]?(a&&(i.push(new n.TextRun({text:a,bold:l,italics:o,color:"000000",size:(null==t?void 0:t.paragraphSize)||24})),a=""),g=l?-1:c,l=!l,c++):"*"!==e[c]||0!==c&&"*"===e[c-1]||c!==e.length-1&&"*"===e[c+1]?a+=e[c]:(a&&(i.push(new n.TextRun({text:a,bold:l,italics:o,color:"000000",size:(null==t?void 0:t.paragraphSize)||24})),a=""),p=o?-1:c,o=!o):(a&&(i.push(new n.TextRun({text:a,bold:l,italics:o,color:"000000",size:(null==t?void 0:t.paragraphSize)||24})),a=""),s=!0);if(a){if(l&&g>=0){a="**"+a,l=!1}if(o&&p>=0){a="*"+a,o=!1}s&&(a="`"+a),a.trim()&&i.push(new n.TextRun({text:a,bold:l,italics:o,color:"000000",size:(null==t?void 0:t.paragraphSize)||24}))}return 0===i.length&&i.push(new n.TextRun({text:"",color:"000000",size:(null==t?void 0:t.paragraphSize)||24})),i}function r(e,t){return new n.TextRun({text:e,font:"Courier New",size:(null==t?void 0:t.paragraphSize)?t.paragraphSize-2:20,color:"444444",shading:{fill:"F5F5F5"}})}exports.collectTables=function(e){const n=[];for(let t=0;t<e.length;t++){const r=e[t];if(r.trim().startsWith("|")&&t+1<e.length&&/^\s*\|(?:\s*:?-+:?\s*\|)+\s*$/.test(e[t+1])){const i=r.split("|").filter(Boolean).map((e=>e.trim())),a=[];let l=t+2;for(;l<e.length&&e[l].trim().startsWith("|");){const n=e[l].split("|").filter(Boolean).map((e=>e.trim()));a.push(n),l++}n.push({headers:i,rows:a})}}return n},exports.processBlockquote=function(e,t){let r;if(t.blockquoteAlignment)switch(t.blockquoteAlignment){case"LEFT":r=n.AlignmentType.LEFT;break;case"CENTER":r=n.AlignmentType.CENTER;break;case"RIGHT":r=n.AlignmentType.RIGHT;break;case"JUSTIFIED":r=n.AlignmentType.JUSTIFIED;break;default:r=void 0}return new n.Paragraph({children:[new n.TextRun({text:e,italics:!0,color:"000000",size:t.blockquoteSize||24})],indent:{left:720},spacing:{before:t.paragraphSpacing,after:t.paragraphSpacing},border:{left:{style:n.BorderStyle.SINGLE,size:3,color:"AAAAAA"}},alignment:r})},exports.processCodeBlock=function(e,t,r){const i=e.split("\n"),a=[];return t&&a.push(new n.TextRun({text:t,font:"Courier New",size:r.codeBlockSize||18,color:"666666",bold:!0}),new n.TextRun({text:"\n",font:"Courier New",size:r.codeBlockSize||18,break:1})),i.forEach(((e,t)=>{var l;const o=(null===(l=e.match(/^\s*/))||void 0===l?void 0:l[0].length)||0,s=" ".repeat(o)+e.slice(o);a.push(new n.TextRun({text:s,font:"Courier New",size:r.codeBlockSize||20,color:"444444"})),t<i.length-1&&a.push(new n.TextRun({text:"\n",font:"Courier New",size:r.codeBlockSize||20,break:1}))})),new n.Paragraph({children:a,spacing:{before:r.paragraphSpacing,after:r.paragraphSpacing,line:360,lineRule:"exact"},shading:{fill:"F5F5F5"},border:{top:{style:n.BorderStyle.SINGLE,size:1,color:"DDDDDD"},bottom:{style:n.BorderStyle.SINGLE,size:1,color:"DDDDDD"},left:{style:n.BorderStyle.SINGLE,size:1,color:"DDDDDD"},right:{style:n.BorderStyle.SINGLE,size:1,color:"DDDDDD"}},indent:{left:360}})},exports.processComment=function(e,t){return new n.Paragraph({children:[new n.TextRun({text:"Comment: "+e,italics:!0,color:"666666"})],spacing:{before:t.paragraphSpacing,after:t.paragraphSpacing}})},exports.processFormattedText=t,exports.processHeading=function(e,t,r,i){const a=e.replace(new RegExp(`^#{${t.level}} `),""),l=t.level,o=`_Toc_${function(e){let n=e.replace(/[^a-zA-Z0-9_\s]/g,"").replace(/\s+/g,"_");return/^[a-zA-Z_]/.test(n)||(n="_"+n),n.substring(0,40)}(a.replace(/\*\*/g,"").replace(/\*/g,""))}_${Date.now()}`;let s,g=r.titleSize;1===l&&r.heading1Size?g=r.heading1Size:2===l&&r.heading2Size?g=r.heading2Size:3===l&&r.heading3Size?g=r.heading3Size:4===l&&r.heading4Size?g=r.heading4Size:5===l&&r.heading5Size?g=r.heading5Size:l>1&&(g=r.titleSize-4*(l-1)),1===l&&r.heading1Alignment?s=n.AlignmentType[r.heading1Alignment]:2===l&&r.heading2Alignment?s=n.AlignmentType[r.heading2Alignment]:3===l&&r.heading3Alignment?s=n.AlignmentType[r.heading3Alignment]:4===l&&r.heading4Alignment?s=n.AlignmentType[r.heading4Alignment]:5===l&&r.heading5Alignment?s=n.AlignmentType[r.heading5Alignment]:r.headingAlignment&&(s=n.AlignmentType[r.headingAlignment]);const p=function(e,t){const r=[];let i="",a=!1,l=!1,o=-1,s=-1;for(let g=0;g<e.length;g++)if("\\"===e[g]&&g+1<e.length){const n=e[g+1];if("*"===n||"\\"===n){i+=n,g++;continue}i+=e[g]}else g+1<e.length&&"*"===e[g]&&"*"===e[g+1]?(i&&(r.push(new n.TextRun({text:i,bold:a,italics:l,color:"000000",size:t})),i=""),o=a?-1:g,a=!a,g++):"*"!==e[g]||0!==g&&"*"===e[g-1]||g!==e.length-1&&"*"===e[g+1]?i+=e[g]:(i&&(r.push(new n.TextRun({text:i,bold:a,italics:l,color:"000000",size:t})),i=""),s=l?-1:g,l=!l);if(i){if(a&&o>=0){i="**"+i,a=!1}if(l&&s>=0){i="*"+i,l=!1}i.trim()&&r.push(new n.TextRun({text:i,bold:a,italics:l,color:"000000",size:t}))}0===r.length&&r.push(new n.TextRun({text:"",color:"000000",size:t,bold:!0}));return r}(a,g);return{paragraph:new n.Paragraph({children:[new n.Bookmark({id:o,children:p})],heading:l,spacing:{before:1===t.level?2*r.headingSpacing:r.headingSpacing,after:r.headingSpacing/2},alignment:s,style:`Heading${l}`}),bookmarkId:o}},exports.processImage=function(t,r,i){return e.__awaiter(this,void 0,void 0,(function*(){try{console.log(`Starting image processing for URL: ${r}`);const e=yield fetch(r);if(console.log(`Fetch response status: ${e.status}`),!e.ok)throw new Error(`Failed to fetch image: ${e.status} ${e.statusText}`);const t=yield e.arrayBuffer();console.log(`ArrayBuffer size: ${t.byteLength} bytes`);const a=Buffer.from(t);return console.log(`Buffer size: ${a.length} bytes`),[new n.Paragraph({children:[new n.ImageRun({data:a,transformation:{width:200,height:200},type:"jpg"})],alignment:n.AlignmentType.CENTER,spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing}})]}catch(e){return console.error("Error in processImage:",e),console.error("Error stack:",e instanceof Error?e.stack:"No stack available"),[new n.Paragraph({children:[new n.TextRun({text:`[Image could not be displayed: ${t}]`,italics:!0,color:"FF0000"})],alignment:n.AlignmentType.CENTER})]}}))},exports.processInlineCode=r,exports.processLinkParagraph=function(e,t,r){const i=new n.ExternalHyperlink({children:[new n.TextRun({text:e,color:"0000FF",underline:{type:"single"}})],link:t});return new n.Paragraph({children:[i],spacing:{before:r.paragraphSpacing,after:r.paragraphSpacing}})},exports.processListItem=function(e,r){const i=t(e.text,r);if(e.boldText&&i.push(new n.TextRun({text:"\n",size:r.listItemSize||24}),new n.TextRun({text:e.boldText,bold:!0,color:"000000",size:r.listItemSize||24})),e.isNumbered){const t=`numbered-list-${e.sequenceId||1}`;return new n.Paragraph({children:i,numbering:{reference:t,level:0},spacing:{before:r.paragraphSpacing/2,after:r.paragraphSpacing/2}})}return new n.Paragraph({children:i,bullet:{level:0},spacing:{before:r.paragraphSpacing/2,after:r.paragraphSpacing/2}})},exports.processParagraph=function(e,r){const i=t(e,r),a=r.paragraphAlignment?"CENTER"===r.paragraphAlignment?n.AlignmentType.CENTER:"RIGHT"===r.paragraphAlignment?n.AlignmentType.RIGHT:"JUSTIFIED"===r.paragraphAlignment?n.AlignmentType.JUSTIFIED:n.AlignmentType.LEFT:n.AlignmentType.LEFT;console.log(`Paragraph alignment: ${a}, Style alignment: ${r.paragraphAlignment}`);const l="JUSTIFIED"===r.paragraphAlignment?{left:0,right:0}:void 0;return new n.Paragraph({children:i,spacing:{before:r.paragraphSpacing,after:r.paragraphSpacing,line:240*r.lineSpacing},alignment:a,indent:l})},exports.processTable=function(e,t){return new n.Table({width:{size:100,type:n.WidthType.PERCENTAGE},rows:[new n.TableRow({tableHeader:!0,children:e.headers.map((e=>new n.TableCell({children:[new n.Paragraph({alignment:n.AlignmentType.CENTER,style:"Strong",children:[new n.TextRun({text:e,bold:!0,color:"000000"})]})],shading:{fill:"report"===t?"DDDDDD":"F2F2F2"}})))}),...e.rows.map((e=>new n.TableRow({children:e.map((e=>new n.TableCell({children:[new n.Paragraph({children:[new n.TextRun({text:e,color:"000000"})]})]})))})))],layout:n.TableLayoutType.FIXED,margins:{top:100,bottom:100,left:100,right:100}})};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),n=require("docx"),t=require("file-saver"),r=require("./types.js"),o=require("./helpers.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=i(t);const s={titleSize:32,headingSpacing:240,paragraphSpacing:240,lineSpacing:1.15,paragraphAlignment:"LEFT"},l={documentType:"document",style:s};class c extends Error{constructor(e,n){super(e),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:n}),this.name="MarkdownConversionError"}}exports.MarkdownConversionError=c,exports.convertMarkdownToDocx=function(t,i=l){return e.__awaiter(this,void 0,void 0,(function*(){try{const{style:e=s,documentType:a="document"}=i,l=[],c=[],g=t.split("\n");let p,d=!1,h=[],u=1,m=!1,f=0,b=!1,w="",v=0;const T=o.collectTables(g);for(let t=0;t<g.length;t++)try{const i=g[t],s=i.trim();if(!s){b&&(w+="\n"),d&&(l.push(...h),h=[],d=!1,u=1,m=!1),l.push(new n.Paragraph({}));continue}if("\\pagebreak"===s){d&&(l.push(...h),h=[],d=!1,u=1,m=!1),l.push(new n.Paragraph({children:[new n.PageBreak]}));continue}if(/^\s*---\s*$/.test(s)){d&&(l.push(...h),h=[],d=!1,u=1,m=!1);continue}if("[TOC]"===s){d&&(l.push(...h),h=[],d=!1);const e=new n.Paragraph({});e.__isTocPlaceholder=!0,l.push(e);continue}if(s.startsWith("```")){b?(b=!1,l.push(o.processCodeBlock(w.trim(),p,e)),w="",p=void 0):(b=!0,p=s.slice(3).trim()||void 0,w="");continue}if(b){w+=(w?"\n":"")+i;continue}if(s.startsWith("#")){const n=s.match(/^#+/);if(n){const t=n[0].length;if(t>=1&&t<=5){d&&(l.push(...h),h=[],d=!1);const n=s.substring(t).trim(),i=Object.assign(Object.assign({},r.headingConfigs[t]),{alignment:r.headingConfigs[t].alignment||e.headingAlignment}),{paragraph:g,bookmarkId:p}=o.processHeading(s,i,e,a);c.push({text:n,level:t,bookmarkId:p}),l.push(g);continue}console.warn(`Warning: Heading level ${t} is not supported. Converting to regular paragraph.`)}}if(s.startsWith("|")&&s.endsWith("|")&&t+1<g.length&&(/^\s*\|(?:\s*-+\s*\|)+\s*$/.test(g[t+1])||t+2<g.length&&/^\s*\|(?:\s*-+\s*\|)+\s*$/.test(g[t+2]))&&(d&&(l.push(...h),h=[],d=!1),v<T.length))try{l.push(o.processTable(T[v],a));t+=2+T[v].rows.length-1,v++;continue}catch(e){console.warn(`Warning: Failed to process table at line ${t+1}. Converting to regular text.`),l.push(new n.Paragraph({children:[new n.TextRun({text:s.replace(/\|/g,"").trim(),color:"000000"})]}));continue}if(s.startsWith("- ")||s.startsWith("* ")){m&&(u=1,m=!1),d=!0;const n=s.replace(/^[\s-*]+/,"").trim();let r="";t+1<g.length&&g[t+1].trim().startsWith("**")&&g[t+1].trim().endsWith("**")&&(r=g[t+1].trim().slice(2,-2),t++),h.push(o.processListItem({text:n,boldText:r},e));continue}if(/^\s*\d+\.\s/.test(s)){m&&d||(f++,u=1,m=!0),d=!0;const n=s.replace(/^\s*\d+\.\s/,"").trim();let r="";t+1<g.length&&g[t+1].trim().startsWith("**")&&g[t+1].trim().endsWith("**")&&(r=g[t+1].trim().slice(2,-2),t++),h.push(o.processListItem({text:n,boldText:r,isNumbered:!0,listNumber:u,sequenceId:f},e)),u++;continue}if(s.startsWith("> ")){d&&(l.push(...h),h=[],d=!1);const n=s.replace(/^>\s*/,"").trim();l.push(o.processBlockquote(n,e));continue}if(s.startsWith("COMMENT:")){d&&(l.push(...h),h=[],d=!1);const n=s.replace(/^COMMENT:\s*/,"").trim();l.push(o.processComment(n,e));continue}const x=s.match(/!\[([^\]]*)\]\(([^)]+)\)/);if(x){const[t,r,i]=x;console.log(`Found image in markdown: ${i}`);try{console.log(`Starting image processing for: ${i}`);const n=yield o.processImage(r,i,e);console.log(`Successfully processed image, adding ${n.length} paragraphs`),l.push(...n)}catch(e){console.error(`Error in image processing: ${e instanceof Error?e.message:String(e)}`),l.push(new n.Paragraph({children:[new n.TextRun({text:`[Image could not be loaded: ${r}]`,italics:!0,color:"FF0000"})],alignment:n.AlignmentType.CENTER}))}continue}const S=s.match(/^(?!.*!\[).*\[([^\]]+)\]\(([^)]+)\)/);if(S){const[n,t,r]=S;l.push(o.processLinkParagraph(t,r,e));continue}if(!d){try{l.push(o.processParagraph(s,e))}catch(r){console.warn(`Warning: Failed to process text formatting at line ${t+1}: ${r instanceof Error?r.message:String(r)}. Using plain text.`),l.push(new n.Paragraph({children:[new n.TextRun({text:s,color:"000000",size:e.paragraphSize||24})],spacing:{before:e.paragraphSpacing,after:e.paragraphSpacing,line:240*e.lineSpacing},alignment:e.paragraphAlignment?n.AlignmentType[e.paragraphAlignment]:void 0}))}continue}}catch(e){console.warn(`Warning: Failed to process line ${t+1}: ${e instanceof Error?e.message:"Unknown error"}. Skipping line.`);continue}b&&w&&l.push(o.processCodeBlock(w.trim(),p,e)),d&&h.length>0&&l.push(...h);const x=[];c.length>0&&(x.push(new n.Paragraph({text:"Table of Contents",heading:"Heading1",alignment:n.AlignmentType.CENTER,spacing:{after:240}})),c.forEach((t=>{let r,o=!1,i=!1;switch(t.level){case 1:r=e.tocHeading1FontSize||e.tocFontSize,o=void 0===e.tocHeading1Bold||e.tocHeading1Bold,i=e.tocHeading1Italic||!1;break;case 2:r=e.tocHeading2FontSize||e.tocFontSize,o=void 0!==e.tocHeading2Bold&&e.tocHeading2Bold,i=e.tocHeading2Italic||!1;break;case 3:r=e.tocHeading3FontSize||e.tocFontSize,o=e.tocHeading3Bold||!1,i=e.tocHeading3Italic||!1;break;case 4:r=e.tocHeading4FontSize||e.tocFontSize,o=e.tocHeading4Bold||!1,i=e.tocHeading4Italic||!1;break;case 5:r=e.tocHeading5FontSize||e.tocFontSize,o=e.tocHeading5Bold||!1,i=e.tocHeading5Italic||!1;break;default:r=e.tocFontSize}r||(r=e.paragraphSize?e.paragraphSize-2*(t.level-1):24-2*(t.level-1)),x.push(new n.Paragraph({children:[new n.InternalHyperlink({anchor:t.bookmarkId,children:[new n.TextRun({text:t.text,size:r,bold:o,italics:i})]})],indent:{left:400*(t.level-1)},spacing:{after:120}}))})));const S=[];let k=!1;l.forEach((e=>{!0===e.__isTocPlaceholder?x.length>0&&!k?(S.push(...x),k=!0):console.warn("TOC placeholder found, but no headings collected or TOC already inserted."):S.push(e)}));const y=[];for(let e=1;e<=f;e++)y.push({reference:`numbered-list-${e}`,levels:[{level:0,format:n.LevelFormat.DECIMAL,text:"%1.",alignment:n.AlignmentType.LEFT,style:{paragraph:{indent:{left:720,hanging:260}}}}]});const H=new n.Document({numbering:{config:y},sections:[{properties:{page:{margin:{top:1440,right:1080,bottom:1440,left:1080},size:{orientation:n.PageOrientation.PORTRAIT}}},footers:{default:new n.Footer({children:[new n.Paragraph({alignment:n.AlignmentType.CENTER,children:[new n.TextRun({children:[n.PageNumber.CURRENT]})]})]})},children:S}],styles:{paragraphStyles:[{id:"Title",name:"Title",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize,bold:!0,color:"000000"},paragraph:{spacing:{after:240,line:240*e.lineSpacing},alignment:n.AlignmentType.CENTER}},{id:"Heading1",name:"Heading 1",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize,bold:!0,color:"000000"},paragraph:{spacing:{before:360,after:240},outlineLevel:1}},{id:"Heading2",name:"Heading 2",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-4,bold:!0,color:"000000"},paragraph:{spacing:{before:320,after:160},outlineLevel:2}},{id:"Heading3",name:"Heading 3",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-8,bold:!0,color:"000000"},paragraph:{spacing:{before:280,after:120},outlineLevel:3}},{id:"Heading4",name:"Heading 4",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-12,bold:!0,color:"000000"},paragraph:{spacing:{before:240,after:120},outlineLevel:4}},{id:"Heading5",name:"Heading 5",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-16,bold:!0,color:"000000"},paragraph:{spacing:{before:220,after:100},outlineLevel:5}},{id:"Strong",name:"Strong",run:{bold:!0}}]}});return yield n.Packer.toBlob(H)}catch(e){if(e instanceof c)throw e;throw new c(`Failed to convert markdown to docx: ${e instanceof Error?e.message:"Unknown error"}`,{originalError:e})}}))},exports.downloadDocx=function(e,n="document.docx"){if("undefined"==typeof window)throw new Error("This function can only be used in browser environments");if(!(e instanceof Blob))throw new Error("Invalid blob provided");if(!n||"string"!=typeof n)throw new Error("Invalid filename provided");try{a.default(e,n)}catch(e){throw console.error("Failed to save file:",e),new Error(`Failed to save file: ${e instanceof Error?e.message:"Unknown error"}`)}};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.headingConfigs={1:{level:1,size:0,style:"Title"},2:{level:2,size:0,style:"Heading2"},3:{level:3,size:0},4:{level:4,size:0},5:{level:5,size:0}};
@@ -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:o,onDownload:x,onSaveAsPDF: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:o.text}},{children:c})),e.jsx(l.default,Object.assign({width:"auto",className:"font-semibold p-1 text-sm",style:{backgroundColor:o.primary,color:o.text},border:`1px solid ${o.primary}`},{children:"text/markdown"===r.type?e.jsxs(e.Fragment,{children:[e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("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:d},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]}))]}):"text/html"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/html")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"HTML"]})):"text/csv"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/csv")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"CSV"]})):"image/svg+xml"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("image/svg+xml")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.code"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("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:()=>x("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:()=>x("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("../../../../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:o,onDownload:x,onSaveAsPDF:d,onSaveAsDOCX:p})=>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:o.text}},{children:c})),e.jsx(l.default,Object.assign({width:"auto",className:"font-semibold p-1 text-sm",style:{backgroundColor:o.primary,color:o.text},border:`1px solid ${o.primary}`},{children:"text/markdown"===r.type?e.jsxs(e.Fragment,{children:[e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("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:d},{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:p},{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:()=>x("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("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/html")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"HTML"]})):"text/csv"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/csv")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"CSV"]})):"image/svg+xml"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("image/svg+xml")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.code"===r.type?e.jsxs("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("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:()=>x("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:()=>x("application/vnd.pxe.react")},{children:[e.jsx(s.default,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TSX"]})):null}))]}));
@@ -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"),n=require("../hooks/useArtifactContext.js"),r=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../Scroll/hooks/useScroll.js"),i=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("../../Scroll/ScrollLockView.js"),u=require("../../../../Icons/x.svg.js"),m=require("../../../../Icons/save.svg.js"),x=require("../../../../Icons/expand.svg.js"),f=require("../../../../Icons/shrink.svg.js"),v=require("../../../common/PickaxeCopyButton.js"),y=require("../../../../Core/ScrollArea.js"),g=require("../../../../Core/TipContainer.js"),h=require("../MermaidRenderer.js"),b=require("./SaveMenu.js"),j=require("./ViewOptions.js"),w=require("csv-to-markdown-table"),C=require("../../../../../common/cn.js");function k(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var F=k(w);const T="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co";exports.default=w=>{var k,O,A,S;const{artifacts:E,currentPopupType:q,currentArtifact:D,setCurrentArtifact:N}=n.useArtifactContext(),{onLoadArtifact:M}=i.useArtifact(),{styles:R,colors:B,translations:L}=r.usePickaxeContext(),[P,z]=o.useState("code"),_=o.useRef(),$=o.useRef(null),W=o.useRef(null),H=l.useReactToPrint({contentRef:_}),{scrollContainerRef:I,scrollStartSession:U,scrollToBottom:V,scrollEndSession:X}=a.useScroll({auto:"code"===P}),G=null!==(O=null===(k=w.styling)||void 0===k?void 0:k.styles)&&void 0!==O?O:R,J=null!==(S=null===(A=w.styling)||void 0===A?void 0:A.colors)&&void 0!==S?S:B,K=o.useMemo((()=>{var e,t,o,n,r;if(!w.artifact&&!D)return null;const a=null!==(t=null===(e=w.artifact)||void 0===e?void 0:e.id)&&void 0!==t?t:null==D?void 0:D.id,i=null!==(n=null===(o=w.artifact)||void 0===o?void 0:o.version)&&void 0!==n?n:null==D?void 0:D.version;return null!==(r=E.find((e=>e.id===a&&e.version===i)))&&void 0!==r?r:null}),[D,E,w.artifact]),Q=o.useMemo((()=>K&&"text/csv"===K.type?F.default(K.content,",",!0):null),[K]),Y=o.useMemo((()=>(J.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==J?void 0:J.secondaryText]),Z=o.useMemo((()=>{const e=w.artifact&&(null==D?void 0:D.id)===w.artifact.id&&(null==D?void 0:D.version)===w.artifact.version;return"inline"===w.type&&("inline-form"===q?!!D:e)}),[D,q,w.type,w.artifact]);o.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){"inline"===w.type&&w.artifact&&(E.some((e=>w.artifact&&e.id===w.artifact.id&&e.version===w.artifact.version))||M({id:w.artifact.id,version:w.artifact.version}))}))}),[E,w.type,w.artifact]),o.useEffect((()=>{if("application/vnd.pxe.code"===(null==K?void 0:K.type)&&z("code"),"finished"!==(null==K?void 0:K.status))return z("code"),U(),void V();X(),"application/vnd.pxe.code"!==K.type&&z("render")}),[null==K?void 0:K.status,null==K?void 0:K.type]),o.useEffect((()=>{var e;!W.current||"text/html"!==(null==K?void 0:K.type)&&"application/vnd.pxe.react"!==(null==K?void 0:K.type)||null===(e=W.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===K.type?"HTML_CODE":"REACT_CODE",content:K.content},T)}),[null==K?void 0:K.content,null==K?void 0:K.type]);const ee=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!K)return;const e=P;"code"===e&&(z("render"),yield new Promise((e=>setTimeout(e,50)))),H(),"code"===e&&z(e)})),te=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!K)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"image/svg+xml":case"application/vnd.pxe.mermaid":o={mimeType:"image/svg+xml",extension:".svg"};break;case"application/vnd.pxe.code":o={mimeType:`application/${K.programmingLanguage||"text"};charset=utf-8`,extension:`.${K.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"===K.type){const t=P;"code"===t&&(z("render"),yield new Promise((e=>setTimeout(e,50))));const o=null===(e=$.current)||void 0===e?void 0:e.querySelector("svg");o&&(n=(new XMLSerializer).serializeToString(o)),"code"===t&&z(t)}const r=new Blob([null!=n?n:K.content],{type:o.mimeType}),a=URL.createObjectURL(r);try{const e=document.createElement("a");e.href=a,e.download=`${K.title}${o.extension}`,e.style.display="none",document.body.appendChild(e),e.click(),document.body.removeChild(e)}finally{URL.revokeObjectURL(a)}}));return K?t.jsxs("div",Object.assign({className:C.default("pxe-artifact-renderer flex flex-col","inline"===w.type&&!Z&&"min-h-[320px] mb-6",w.className),style:Object.assign(Object.assign({backgroundColor:J.secondary,color:J.secondaryText},"auto"!==q&&{borderRadius:G.cornerRadius}),w.style)},{children:[t.jsxs("div",Object.assign({className:"flex items-center gap-6 justify-between p-4 shadow-sm"},{children:[t.jsxs("div",Object.assign({className:"pxe-artifact-create-header flex items-center gap-4 truncate"},{children:[(Z||!q.startsWith("inline"))&&t.jsx(j.default,{type:K.type,view:P,colors:J,onChange:z}),t.jsx("p",Object.assign({className:"font-semilight truncate text-xl"},{children:K.title}))]})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[(Z||!q.startsWith("inline"))&&t.jsx(b.default,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:K,colors:J,onDownload:te,onSaveAsPDF:ee},{children:t.jsx("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==L?void 0:L["save-as"])||"Save as"}))})),t.jsx("button",Object.assign({style:{color:J.secondaryText},onClick:()=>{"inline"!==w.type||!w.artifact||Z?N(null):N({id:w.artifact.id,version:w.artifact.version})}},{children:"inline"===w.type?Z?t.jsx(f.default,{className:"w-6 h-6 shrink-0"}):t.jsx(x.default,{className:"w-6 h-6 shrink-0"}):t.jsx(u.default,{className:"w-6 h-6 shrink-0"})}))]}))]})),t.jsx("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:t.jsxs(y.default,Object.assign({ref:I,innerClassName:"flex-grow w-full"},{children:["render"===P&&"application/vnd.pxe.code"!==K.type?t.jsx("div",Object.assign({ref:_,className:C.default("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===K.type&&"p-0","text/html"===K.type&&"p-0","text/csv"===K.type&&"p-0")},{children:"text/markdown"===K.type||"text/csv"===K.type||"image/svg+xml"===K.type?t.jsx(s.PickaxeMarkdown,Object.assign({theme:G.theme,colors:J},{children:t.jsx(c.PickaxeMarkdownRenderer,{value:null!=Q?Q:K.content,className:C.default("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===K.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===K.type?t.jsx(h.default,{ref:$,id:`mermaid-${K.id}-${K.version}`,data:K.content}):"text/html"===K.type||"application/vnd.pxe.react"===K.type?t.jsx("iframe",Object.assign({ref:W,title:K.title,src:`${T}/${"text/html"===K.type?"html":"react"}?theme=${Y?"dark":"light"}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==J?void 0:J.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:"text/html"===K.type?"HTML_CODE":"REACT_CODE",content:K.content},T)}catch(e){console.error("Error sending message to iframe:",e)}}),100),V()}},{children:"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"===K.type?"markdown":"text/html"===K.type||"image/svg+xml"===K.type?"xml":"application/vnd.pxe.react"===K.type?"typescript":K.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==J?void 0:J.secondaryText},Y&&{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==J?void 0:J.secondaryText},Y&&{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==J?void 0:J.secondary}),':not(pre) > code[class*="language-"]':{background:null==J?void 0:J.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==J?void 0:J.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!Y&&{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==J?void 0:J.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:K.content})),t.jsx(p.default,{})]}))})),"inline"===w.type&&!Z&&t.jsxs("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t.jsx(g.default,Object.assign({id:`artifact-copy-${K.id}-${K.version}`,tip:(null==L?void 0:L.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:J.secondary,color:J.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(v.default,{color:J.secondaryText,text:K.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t.jsx(g.default,Object.assign({id:`artifact-save-${K.id}-${K.version}`,tip:(null==L?void 0:L.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:J.secondary,color:J.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(b.default,Object.assign({data:K,colors:J,onDownload:te,onSaveAsPDF:ee},{children:t.jsx("button",Object.assign({style:{color:J.secondaryText}},{children:t.jsx(m.default,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),o=require("react/jsx-runtime"),t=require("react"),n=require("../hooks/useArtifactContext.js"),r=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../Scroll/hooks/useScroll.js"),i=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"),m=require("../../Scroll/ScrollLockView.js"),x=require("../../../../Icons/x.svg.js"),f=require("../../../../Icons/save.svg.js"),v=require("../../../../Icons/expand.svg.js"),g=require("../../../../Icons/shrink.svg.js"),y=require("../../../common/PickaxeCopyButton.js"),h=require("../../../../Core/ScrollArea.js"),b=require("../../../../Core/TipContainer.js"),j=require("../MermaidRenderer.js"),w=require("./SaveMenu.js"),C=require("./ViewOptions.js"),k=require("csv-to-markdown-table"),F=require("../../../../../common/cn.js");function T(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var A=T(u),O=T(k);const S="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co";exports.default=u=>{var k,T,D,q;const{artifacts:E,currentPopupType:N,currentArtifact:M,setCurrentArtifact:B}=n.useArtifactContext(),{onLoadArtifact:_}=i.useArtifact(),{styles:P,colors:R,translations:z}=r.usePickaxeContext(),[$,L]=t.useState("code"),W=t.useRef(),H=t.useRef(null),I=t.useRef(null),V=l.useReactToPrint({contentRef:W}),{scrollContainerRef:X,scrollStartSession:G,scrollToBottom:J,scrollEndSession:K}=a.useScroll({auto:"code"===$}),Q=null!==(T=null===(k=u.styling)||void 0===k?void 0:k.styles)&&void 0!==T?T:P,U=null!==(q=null===(D=u.styling)||void 0===D?void 0:D.colors)&&void 0!==q?q:R,Y=t.useMemo((()=>{var e,o,t,n,r;if(!u.artifact&&!M)return null;const a=null!==(o=null===(e=u.artifact)||void 0===e?void 0:e.id)&&void 0!==o?o:null==M?void 0:M.id,i=null!==(n=null===(t=u.artifact)||void 0===t?void 0:t.version)&&void 0!==n?n:null==M?void 0:M.version;return null!==(r=E.find((e=>e.id===a&&e.version===i)))&&void 0!==r?r:null}),[M,E,u.artifact]),Z=t.useMemo((()=>Y&&"text/csv"===Y.type?O.default(Y.content,",",!0):null),[Y]),ee=t.useMemo((()=>(U.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==U?void 0:U.secondaryText]),oe=t.useMemo((()=>{const e=u.artifact&&(null==M?void 0:M.id)===u.artifact.id&&(null==M?void 0:M.version)===u.artifact.version;return"inline"===u.type&&("inline-form"===N?!!M:e)}),[M,N,u.type,u.artifact]);t.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){"inline"===u.type&&u.artifact&&(E.some((e=>u.artifact&&e.id===u.artifact.id&&e.version===u.artifact.version))||_({id:u.artifact.id,version:u.artifact.version}))}))}),[E,u.type,u.artifact]),t.useEffect((()=>{if("application/vnd.pxe.code"===(null==Y?void 0:Y.type)&&L("code"),"finished"!==(null==Y?void 0:Y.status))return L("code"),G(),void J();K(),"application/vnd.pxe.code"!==Y.type&&L("render")}),[null==Y?void 0:Y.status,null==Y?void 0:Y.type]),t.useEffect((()=>{var e;!I.current||"text/html"!==(null==Y?void 0:Y.type)&&"application/vnd.pxe.react"!==(null==Y?void 0:Y.type)||null===(e=I.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===Y.type?"HTML_CODE":"REACT_CODE",content:Y.content},S)}),[null==Y?void 0:Y.content,null==Y?void 0:Y.type]);const te=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!Y)return;const e=$;"code"===e&&(L("render"),yield new Promise((e=>setTimeout(e,50)))),V(),"code"===e&&L(e)})),ne=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!Y)return;const e=yield p.convertMarkdownToDocx(Y.content);p.downloadDocx(e,`${Y.title}.docx`)})),re=o=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!Y)return;let t={mimeType:"text/plain",extension:".txt"};switch(o){case"text/markdown":t={mimeType:"text/markdown",extension:".md"};break;case"text/html":t={mimeType:"text/html",extension:".html"};break;case"text/csv":t={mimeType:"text/csv",extension:".csv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":t={mimeType:"image/svg+xml",extension:".svg"};break;case"application/vnd.pxe.code":t={mimeType:`application/${Y.programmingLanguage||"text"};charset=utf-8`,extension:`.${Y.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":t={mimeType:"text/typescript",extension:".tsx"};break;default:t={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===Y.type){const o=$;"code"===o&&(L("render"),yield new Promise((e=>setTimeout(e,50))));const t=null===(e=H.current)||void 0===e?void 0:e.querySelector("svg");t&&(n=(new XMLSerializer).serializeToString(t)),"code"===o&&L(o)}const r=new Blob([null!=n?n:Y.content],{type:t.mimeType});A.default(r,`${Y.title}${t.extension}`)}));return Y?o.jsxs("div",Object.assign({className:F.default("pxe-artifact-renderer flex flex-col","inline"===u.type&&!oe&&"min-h-[320px] mb-6",u.className),style:Object.assign(Object.assign({backgroundColor:U.secondary,color:U.secondaryText},"auto"!==N&&{borderRadius:Q.cornerRadius}),u.style)},{children:[o.jsxs("div",Object.assign({className:"flex items-center gap-6 justify-between p-4 shadow-sm"},{children:[o.jsxs("div",Object.assign({className:"pxe-artifact-create-header flex items-center gap-4 truncate"},{children:[(oe||!N.startsWith("inline"))&&o.jsx(C.default,{type:Y.type,view:$,colors:U,onChange:L}),o.jsx("p",Object.assign({className:"font-semilight truncate text-xl"},{children:Y.title}))]})),o.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[(oe||!N.startsWith("inline"))&&o.jsx(w.default,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:Y,colors:U,onDownload:re,onSaveAsPDF:te,onSaveAsDOCX:ne},{children:o.jsx("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==z?void 0:z["save-as"])||"Save as"}))})),o.jsx("button",Object.assign({style:{color:U.secondaryText},onClick:()=>{"inline"!==u.type||!u.artifact||oe?B(null):B({id:u.artifact.id,version:u.artifact.version})}},{children:"inline"===u.type?oe?o.jsx(g.default,{className:"w-6 h-6 shrink-0"}):o.jsx(v.default,{className:"w-6 h-6 shrink-0"}):o.jsx(x.default,{className:"w-6 h-6 shrink-0"})}))]}))]})),o.jsx("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:o.jsxs(h.default,Object.assign({ref:X,innerClassName:"flex-grow w-full"},{children:["render"===$&&"application/vnd.pxe.code"!==Y.type?o.jsx("div",Object.assign({ref:W,className:F.default("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===Y.type&&"p-0","text/html"===Y.type&&"p-0","text/csv"===Y.type&&"p-0")},{children:"text/markdown"===Y.type||"text/csv"===Y.type||"image/svg+xml"===Y.type?o.jsx(s.PickaxeMarkdown,Object.assign({theme:Q.theme,colors:U},{children:o.jsx(c.PickaxeMarkdownRenderer,{value:null!=Z?Z:Y.content,className:F.default("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===Y.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===Y.type?o.jsx(j.default,{ref:H,id:`mermaid-${Y.id}-${Y.version}`,data:Y.content}):"text/html"===Y.type||"application/vnd.pxe.react"===Y.type?o.jsx("iframe",Object.assign({ref:I,title:Y.title,src:`${S}/${"text/html"===Y.type?"html":"react"}?theme=${ee?"dark":"light"}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==U?void 0:U.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 o=e.target;setTimeout((()=>{var e;try{null===(e=o.contentWindow)||void 0===e||e.postMessage({type:"text/html"===Y.type?"HTML_CODE":"REACT_CODE",content:Y.content},S)}catch(e){console.error("Error sending message to iframe:",e)}}),100),J()}},{children:"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):o.jsx(d.Prism,Object.assign({PreTag:"div",language:"text/markdown"===Y.type?"markdown":"text/html"===Y.type||"image/svg+xml"===Y.type?"xml":"application/vnd.pxe.react"===Y.type?"typescript":Y.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==U?void 0:U.secondaryText},ee&&{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==U?void 0:U.secondaryText},ee&&{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==U?void 0:U.secondary}),':not(pre) > code[class*="language-"]':{background:null==U?void 0:U.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==U?void 0:U.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!ee&&{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==U?void 0:U.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:Y.content})),o.jsx(m.default,{})]}))})),"inline"===u.type&&!oe&&o.jsxs("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[o.jsx(b.default,Object.assign({id:`artifact-copy-${Y.id}-${Y.version}`,tip:(null==z?void 0:z.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:U.secondary,color:U.secondaryText,fontSize:"12px"},align:"bottom"},{children:o.jsx(y.default,{color:U.secondaryText,text:Y.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),o.jsx(b.default,Object.assign({id:`artifact-save-${Y.id}-${Y.version}`,tip:(null==z?void 0:z.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:U.secondary,color:U.secondaryText,fontSize:"12px"},align:"bottom"},{children:o.jsx(w.default,Object.assign({data:Y,colors:U,onDownload:re,onSaveAsPDF:te,onSaveAsDOCX:ne},{children:o.jsx("button",Object.assign({style:{color:U.secondaryText}},{children:o.jsx(f.default,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};
@@ -0,0 +1,104 @@
1
+ import { Paragraph, TextRun, Table } from "docx";
2
+ import { Style, TableData, HeadingConfig, ListItemConfig } from "./types";
3
+ /**
4
+ * Processes a heading line and returns appropriate paragraph formatting and a bookmark ID
5
+ * @param line - The heading line to process
6
+ * @param config - The heading configuration
7
+ * @param style - The style configuration
8
+ * @param documentType - The document type
9
+ * @returns An object containing the processed paragraph and its bookmark ID
10
+ */
11
+ export declare function processHeading(line: string, config: HeadingConfig, style: Style, _: "document" | "report"): {
12
+ paragraph: Paragraph;
13
+ bookmarkId: string;
14
+ };
15
+ /**
16
+ * Processes a table and returns table formatting
17
+ * @param tableData - The table data
18
+ * @param documentType - The document type
19
+ * @returns The processed table
20
+ */
21
+ export declare function processTable(tableData: TableData, documentType: "document" | "report"): Table;
22
+ /**
23
+ * Processes a list item and returns appropriate paragraph formatting
24
+ * @param config - The list item configuration
25
+ * @param style - The style configuration
26
+ * @returns The processed paragraph
27
+ */
28
+ export declare function processListItem(config: ListItemConfig, style: Style): Paragraph;
29
+ /**
30
+ * Processes a blockquote and returns appropriate paragraph formatting
31
+ * @param text - The blockquote text
32
+ * @param style - The style configuration
33
+ * @returns The processed paragraph
34
+ */
35
+ export declare function processBlockquote(text: string, style: Style): Paragraph;
36
+ /**
37
+ * Processes a comment and returns appropriate paragraph formatting
38
+ * @param text - The comment text
39
+ * @param style - The style configuration
40
+ * @returns The processed paragraph
41
+ */
42
+ export declare function processComment(text: string, style: Style): Paragraph;
43
+ /**
44
+ * Processes formatted text (bold/italic/inline-code) and returns an array of TextRun objects
45
+ * @param line - The line to process
46
+ * @param style - The style configuration
47
+ * @returns An array of TextRun objects
48
+ */
49
+ export declare function processFormattedText(line: string, style?: Style): TextRun[];
50
+ /**
51
+ * Collects tables from markdown lines
52
+ * @param lines - The markdown lines
53
+ * @returns An array of table data
54
+ */
55
+ export declare function collectTables(lines: string[]): TableData[];
56
+ /**
57
+ * Processes inline code and returns a TextRun object
58
+ * @param code - The inline code text
59
+ * @param style - The style configuration
60
+ * @returns A TextRun object
61
+ */
62
+ export declare function processInlineCode(code: string, style?: Style): TextRun;
63
+ /**
64
+ * Processes a code block and returns appropriate paragraph formatting
65
+ * @param code - The code block text
66
+ * @param language - The programming language (optional)
67
+ * @param style - The style configuration
68
+ * @returns The processed paragraph
69
+ */
70
+ export declare function processCodeBlock(code: string, language: string | undefined, style: Style): Paragraph;
71
+ /**
72
+ * Processes a link and returns appropriate text run
73
+ */
74
+ export declare function processLink(text: string, _: string): TextRun;
75
+ /**
76
+ * Processes a link and returns a paragraph with hyperlink
77
+ * @param text - The link text
78
+ * @param url - The link URL
79
+ * @param style - The style configuration
80
+ * @returns The processed paragraph with hyperlink
81
+ */
82
+ export declare function processLinkParagraph(text: string, url: string, style: Style): Paragraph;
83
+ /**
84
+ * Creates a simple link paragraph
85
+ * @param text - The link text
86
+ * @param url - The URL to link to
87
+ * @returns A paragraph with a hyperlink
88
+ */
89
+ export declare function createLinkParagraph(text: string, url: string): Paragraph;
90
+ /**
91
+ * Processes an image and returns appropriate paragraph
92
+ * @param altText - The alt text
93
+ * @param imageUrl - The image URL
94
+ * @param style - The style configuration
95
+ * @returns The processed paragraph
96
+ */
97
+ export declare function processImage(altText: string, imageUrl: string, style: Style): Promise<Paragraph[]>;
98
+ /**
99
+ * Processes a paragraph and returns appropriate paragraph formatting
100
+ * @param text - The paragraph text
101
+ * @param style - The style configuration
102
+ * @returns The processed paragraph
103
+ */
104
+ export declare function processParagraph(text: string, style: Style): Paragraph;
@@ -0,0 +1,28 @@
1
+ import { Options } from "./types";
2
+ /**
3
+ * Custom error class for markdown conversion errors
4
+ * @extends Error
5
+ * @param message - The error message
6
+ * @param context - The context of the error
7
+ */
8
+ export declare class MarkdownConversionError extends Error {
9
+ context?: any;
10
+ constructor(message: string, context?: any);
11
+ }
12
+ /**
13
+ * Convert Markdown to Docx
14
+ * @param markdown - The Markdown string to convert
15
+ * @param options - The options for the conversion
16
+ * @returns A Promise that resolves to a Blob containing the Docx file
17
+ * @throws {MarkdownConversionError} If conversion fails
18
+ */
19
+ export declare function convertMarkdownToDocx(markdown: string, options?: Options): Promise<Blob>;
20
+ /**
21
+ * Downloads a DOCX file in the browser environment
22
+ * @param blob - The Blob containing the DOCX file data
23
+ * @param filename - The name to save the file as (defaults to "document.docx")
24
+ * @throws {Error} If the function is called outside browser environment
25
+ * @throws {Error} If invalid blob or filename is provided
26
+ * @throws {Error} If file save fails
27
+ */
28
+ export declare function downloadDocx(blob: Blob, filename?: string): void;
@@ -0,0 +1,66 @@
1
+ export interface Style {
2
+ titleSize: number;
3
+ headingSpacing: number;
4
+ paragraphSpacing: number;
5
+ lineSpacing: number;
6
+ heading1Size?: number;
7
+ heading2Size?: number;
8
+ heading3Size?: number;
9
+ heading4Size?: number;
10
+ heading5Size?: number;
11
+ paragraphSize?: number;
12
+ listItemSize?: number;
13
+ codeBlockSize?: number;
14
+ blockquoteSize?: number;
15
+ tocFontSize?: number;
16
+ tocHeading1FontSize?: number;
17
+ tocHeading2FontSize?: number;
18
+ tocHeading3FontSize?: number;
19
+ tocHeading4FontSize?: number;
20
+ tocHeading5FontSize?: number;
21
+ tocHeading1Bold?: boolean;
22
+ tocHeading2Bold?: boolean;
23
+ tocHeading3Bold?: boolean;
24
+ tocHeading4Bold?: boolean;
25
+ tocHeading5Bold?: boolean;
26
+ tocHeading1Italic?: boolean;
27
+ tocHeading2Italic?: boolean;
28
+ tocHeading3Italic?: boolean;
29
+ tocHeading4Italic?: boolean;
30
+ tocHeading5Italic?: boolean;
31
+ paragraphAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
32
+ headingAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
33
+ heading1Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
34
+ heading2Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
35
+ heading3Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
36
+ heading4Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
37
+ heading5Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
38
+ blockquoteAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
39
+ }
40
+ export interface Options {
41
+ documentType?: "document" | "report";
42
+ style?: Style;
43
+ }
44
+ export interface TableData {
45
+ headers: string[];
46
+ rows: string[][];
47
+ }
48
+ export interface ProcessedContent {
49
+ children: any[];
50
+ skipLines: number;
51
+ }
52
+ export interface HeadingConfig {
53
+ level: number;
54
+ size: number;
55
+ style?: string;
56
+ alignment?: any;
57
+ }
58
+ export interface ListItemConfig {
59
+ text: string;
60
+ boldText?: string;
61
+ isNumbered?: boolean;
62
+ listNumber?: number;
63
+ sequenceId?: number;
64
+ }
65
+ export declare const defaultStyle: Style;
66
+ export declare const headingConfigs: Record<number, HeadingConfig>;
@@ -7,8 +7,9 @@ interface ArtifactSaveMenuProps {
7
7
  children?: ReactNode;
8
8
  data: ArtifactData;
9
9
  colors: PickaxeProviderColors;
10
- onDownload: (type: ArtifactType) => void;
11
- onSaveAsPDF: () => void;
10
+ onDownload: (type: ArtifactType | "text/plain") => Promise<void>;
11
+ onSaveAsPDF: () => Promise<void>;
12
+ onSaveAsDOCX: () => Promise<void>;
12
13
  }
13
- declare const ArtifactSaveMenu: ({ variant, className, children, data, colors, onDownload, onSaveAsPDF, }: ArtifactSaveMenuProps) => import("react/jsx-runtime").JSX.Element;
14
+ declare const ArtifactSaveMenu: ({ variant, className, children, data, colors, onDownload, onSaveAsPDF, onSaveAsDOCX, }: ArtifactSaveMenuProps) => import("react/jsx-runtime").JSX.Element;
14
15
  export default ArtifactSaveMenu;
@@ -0,0 +1 @@
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{AlignmentType as n,Paragraph as t,Bookmark as i,TextRun as r,Table as a,WidthType as l,TableRow as o,TableCell as c,TableLayoutType as g,BorderStyle as s,ExternalHyperlink as p,ImageRun as h}from"docx";function d(e,a,l,o){const c=e.replace(new RegExp(`^#{${a.level}} `),""),g=a.level,s=`_Toc_${function(e){let n=e.replace(/[^a-zA-Z0-9_\s]/g,"").replace(/\s+/g,"_");return/^[a-zA-Z_]/.test(n)||(n="_"+n),n.substring(0,40)}(c.replace(/\*\*/g,"").replace(/\*/g,""))}_${Date.now()}`;let p,h=l.titleSize;1===g&&l.heading1Size?h=l.heading1Size:2===g&&l.heading2Size?h=l.heading2Size:3===g&&l.heading3Size?h=l.heading3Size:4===g&&l.heading4Size?h=l.heading4Size:5===g&&l.heading5Size?h=l.heading5Size:g>1&&(h=l.titleSize-4*(g-1)),1===g&&l.heading1Alignment?p=n[l.heading1Alignment]:2===g&&l.heading2Alignment?p=n[l.heading2Alignment]:3===g&&l.heading3Alignment?p=n[l.heading3Alignment]:4===g&&l.heading4Alignment?p=n[l.heading4Alignment]:5===g&&l.heading5Alignment?p=n[l.heading5Alignment]:l.headingAlignment&&(p=n[l.headingAlignment]);const d=function(e,n){const t=[];let i="",a=!1,l=!1,o=-1,c=-1;for(let g=0;g<e.length;g++)if("\\"===e[g]&&g+1<e.length){const n=e[g+1];if("*"===n||"\\"===n){i+=n,g++;continue}i+=e[g]}else g+1<e.length&&"*"===e[g]&&"*"===e[g+1]?(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:n})),i=""),o=a?-1:g,a=!a,g++):"*"!==e[g]||0!==g&&"*"===e[g-1]||g!==e.length-1&&"*"===e[g+1]?i+=e[g]:(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:n})),i=""),c=l?-1:g,l=!l);if(i){if(a&&o>=0){i="**"+i,a=!1}if(l&&c>=0){i="*"+i,l=!1}i.trim()&&t.push(new r({text:i,bold:a,italics:l,color:"000000",size:n}))}0===t.length&&t.push(new r({text:"",color:"000000",size:n,bold:!0}));return t}(c,h);return{paragraph:new t({children:[new i({id:s,children:d})],heading:g,spacing:{before:1===a.level?2*l.headingSpacing:l.headingSpacing,after:l.headingSpacing/2},alignment:p,style:`Heading${g}`}),bookmarkId:s}}function f(e,i){return new a({width:{size:100,type:l.PERCENTAGE},rows:[new o({tableHeader:!0,children:e.headers.map((e=>new c({children:[new t({alignment:n.CENTER,style:"Strong",children:[new r({text:e,bold:!0,color:"000000"})]})],shading:{fill:"report"===i?"DDDDDD":"F2F2F2"}})))}),...e.rows.map((e=>new o({children:e.map((e=>new c({children:[new t({children:[new r({text:e,color:"000000"})]})]})))})))],layout:g.FIXED,margins:{top:100,bottom:100,left:100,right:100}})}function u(e,n){const i=w(e.text,n);if(e.boldText&&i.push(new r({text:"\n",size:n.listItemSize||24}),new r({text:e.boldText,bold:!0,color:"000000",size:n.listItemSize||24})),e.isNumbered){const r=`numbered-list-${e.sequenceId||1}`;return new t({children:i,numbering:{reference:r,level:0},spacing:{before:n.paragraphSpacing/2,after:n.paragraphSpacing/2}})}return new t({children:i,bullet:{level:0},spacing:{before:n.paragraphSpacing/2,after:n.paragraphSpacing/2}})}function m(e,i){let a;if(i.blockquoteAlignment)switch(i.blockquoteAlignment){case"LEFT":a=n.LEFT;break;case"CENTER":a=n.CENTER;break;case"RIGHT":a=n.RIGHT;break;case"JUSTIFIED":a=n.JUSTIFIED;break;default:a=void 0}return new t({children:[new r({text:e,italics:!0,color:"000000",size:i.blockquoteSize||24})],indent:{left:720},spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing},border:{left:{style:s.SINGLE,size:3,color:"AAAAAA"}},alignment:a})}function S(e,n){return new t({children:[new r({text:"Comment: "+e,italics:!0,color:"666666"})],spacing:{before:n.paragraphSpacing,after:n.paragraphSpacing}})}function w(e,n){const t=[];let i="",a=!1,l=!1,o=!1,c=-1,g=-1;for(let s=0;s<e.length;s++)if("\\"===e[s]&&s+1<e.length){const n=e[s+1];if("*"===n||"`"===n||"\\"===n){i+=n,s++;continue}i+=e[s]}else"`"!==e[s]||o?"`"===e[s]&&o?(i&&(t.push(b(i,n)),i=""),o=!1):o?i+=e[s]:s+1<e.length&&"*"===e[s]&&"*"===e[s+1]?(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),i=""),c=a?-1:s,a=!a,s++):"*"!==e[s]||0!==s&&"*"===e[s-1]||s!==e.length-1&&"*"===e[s+1]?i+=e[s]:(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),i=""),g=l?-1:s,l=!l):(i&&(t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),i=""),o=!0);if(i){if(a&&c>=0){i="**"+i,a=!1}if(l&&g>=0){i="*"+i,l=!1}o&&(i="`"+i),i.trim()&&t.push(new r({text:i,bold:a,italics:l,color:"000000",size:(null==n?void 0:n.paragraphSize)||24}))}return 0===t.length&&t.push(new r({text:"",color:"000000",size:(null==n?void 0:n.paragraphSize)||24})),t}function z(e){const n=[];for(let t=0;t<e.length;t++){const i=e[t];if(i.trim().startsWith("|")&&t+1<e.length&&/^\s*\|(?:\s*:?-+:?\s*\|)+\s*$/.test(e[t+1])){const r=i.split("|").filter(Boolean).map((e=>e.trim())),a=[];let l=t+2;for(;l<e.length&&e[l].trim().startsWith("|");){const n=e[l].split("|").filter(Boolean).map((e=>e.trim()));a.push(n),l++}n.push({headers:r,rows:a})}}return n}function b(e,n){return new r({text:e,font:"Courier New",size:(null==n?void 0:n.paragraphSize)?n.paragraphSize-2:20,color:"444444",shading:{fill:"F5F5F5"}})}function E(e,n,i){const a=e.split("\n"),l=[];return n&&l.push(new r({text:n,font:"Courier New",size:i.codeBlockSize||18,color:"666666",bold:!0}),new r({text:"\n",font:"Courier New",size:i.codeBlockSize||18,break:1})),a.forEach(((e,n)=>{var t;const o=(null===(t=e.match(/^\s*/))||void 0===t?void 0:t[0].length)||0,c=" ".repeat(o)+e.slice(o);l.push(new r({text:c,font:"Courier New",size:i.codeBlockSize||20,color:"444444"})),n<a.length-1&&l.push(new r({text:"\n",font:"Courier New",size:i.codeBlockSize||20,break:1}))})),new t({children:l,spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing,line:360,lineRule:"exact"},shading:{fill:"F5F5F5"},border:{top:{style:s.SINGLE,size:1,color:"DDDDDD"},bottom:{style:s.SINGLE,size:1,color:"DDDDDD"},left:{style:s.SINGLE,size:1,color:"DDDDDD"},right:{style:s.SINGLE,size:1,color:"DDDDDD"}},indent:{left:360}})}function D(e,n,i){const a=new p({children:[new r({text:e,color:"0000FF",underline:{type:"single"}})],link:n});return new t({children:[a],spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing}})}function x(i,a,l){return e(this,void 0,void 0,(function*(){try{console.log(`Starting image processing for URL: ${a}`);const e=yield fetch(a);if(console.log(`Fetch response status: ${e.status}`),!e.ok)throw new Error(`Failed to fetch image: ${e.status} ${e.statusText}`);const i=yield e.arrayBuffer();console.log(`ArrayBuffer size: ${i.byteLength} bytes`);const r=Buffer.from(i);return console.log(`Buffer size: ${r.length} bytes`),[new t({children:[new h({data:r,transformation:{width:200,height:200},type:"jpg"})],alignment:n.CENTER,spacing:{before:l.paragraphSpacing,after:l.paragraphSpacing}})]}catch(e){return console.error("Error in processImage:",e),console.error("Error stack:",e instanceof Error?e.stack:"No stack available"),[new t({children:[new r({text:`[Image could not be displayed: ${i}]`,italics:!0,color:"FF0000"})],alignment:n.CENTER})]}}))}function A(e,i){const r=w(e,i),a=i.paragraphAlignment?"CENTER"===i.paragraphAlignment?n.CENTER:"RIGHT"===i.paragraphAlignment?n.RIGHT:"JUSTIFIED"===i.paragraphAlignment?n.JUSTIFIED:n.LEFT:n.LEFT;console.log(`Paragraph alignment: ${a}, Style alignment: ${i.paragraphAlignment}`);const l="JUSTIFIED"===i.paragraphAlignment?{left:0,right:0}:void 0;return new t({children:r,spacing:{before:i.paragraphSpacing,after:i.paragraphSpacing,line:240*i.lineSpacing},alignment:a,indent:l})}export{z as collectTables,m as processBlockquote,E as processCodeBlock,S as processComment,w as processFormattedText,d as processHeading,x as processImage,b as processInlineCode,D as processLinkParagraph,u as processListItem,A as processParagraph,f as processTable};
@@ -0,0 +1 @@
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{Paragraph as n,PageBreak as t,TextRun as i,AlignmentType as o,InternalHyperlink as r,LevelFormat as a,Document as s,PageOrientation as l,Footer as c,PageNumber as d,Packer as g}from"docx";import p from"file-saver";import{headingConfigs as h}from"./types.js";import{collectTables as u,processCodeBlock as m,processHeading as f,processTable as b,processListItem as w,processBlockquote as S,processComment as v,processImage as z,processLinkParagraph as E,processParagraph as H}from"./helpers.js";const F={titleSize:32,headingSpacing:240,paragraphSpacing:240,lineSpacing:1.15,paragraphAlignment:"LEFT"},x={documentType:"document",style:F};class k extends Error{constructor(e,n){super(e),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:n}),this.name="MarkdownConversionError"}}function T(p,T=x){return e(this,void 0,void 0,(function*(){try{const{style:e=F,documentType:x="document"}=T,k=[],y=[],N=p.split("\n");let $,W=!1,C=[],O=1,I=!1,B=0,L=!1,R="",q=0;const j=u(N);for(let r=0;r<N.length;r++)try{const a=N[r],s=a.trim();if(!s){L&&(R+="\n"),W&&(k.push(...C),C=[],W=!1,O=1,I=!1),k.push(new n({}));continue}if("\\pagebreak"===s){W&&(k.push(...C),C=[],W=!1,O=1,I=!1),k.push(new n({children:[new t]}));continue}if(/^\s*---\s*$/.test(s)){W&&(k.push(...C),C=[],W=!1,O=1,I=!1);continue}if("[TOC]"===s){W&&(k.push(...C),C=[],W=!1);const e=new n({});e.__isTocPlaceholder=!0,k.push(e);continue}if(s.startsWith("```")){L?(L=!1,k.push(m(R.trim(),$,e)),R="",$=void 0):(L=!0,$=s.slice(3).trim()||void 0,R="");continue}if(L){R+=(R?"\n":"")+a;continue}if(s.startsWith("#")){const n=s.match(/^#+/);if(n){const t=n[0].length;if(t>=1&&t<=5){W&&(k.push(...C),C=[],W=!1);const n=s.substring(t).trim(),i=Object.assign(Object.assign({},h[t]),{alignment:h[t].alignment||e.headingAlignment}),{paragraph:o,bookmarkId:r}=f(s,i,e,x);y.push({text:n,level:t,bookmarkId:r}),k.push(o);continue}console.warn(`Warning: Heading level ${t} is not supported. Converting to regular paragraph.`)}}if(s.startsWith("|")&&s.endsWith("|")&&r+1<N.length&&(/^\s*\|(?:\s*-+\s*\|)+\s*$/.test(N[r+1])||r+2<N.length&&/^\s*\|(?:\s*-+\s*\|)+\s*$/.test(N[r+2]))&&(W&&(k.push(...C),C=[],W=!1),q<j.length))try{k.push(b(j[q],x));r+=2+j[q].rows.length-1,q++;continue}catch(e){console.warn(`Warning: Failed to process table at line ${r+1}. Converting to regular text.`),k.push(new n({children:[new i({text:s.replace(/\|/g,"").trim(),color:"000000"})]}));continue}if(s.startsWith("- ")||s.startsWith("* ")){I&&(O=1,I=!1),W=!0;const n=s.replace(/^[\s-*]+/,"").trim();let t="";r+1<N.length&&N[r+1].trim().startsWith("**")&&N[r+1].trim().endsWith("**")&&(t=N[r+1].trim().slice(2,-2),r++),C.push(w({text:n,boldText:t},e));continue}if(/^\s*\d+\.\s/.test(s)){I&&W||(B++,O=1,I=!0),W=!0;const n=s.replace(/^\s*\d+\.\s/,"").trim();let t="";r+1<N.length&&N[r+1].trim().startsWith("**")&&N[r+1].trim().endsWith("**")&&(t=N[r+1].trim().slice(2,-2),r++),C.push(w({text:n,boldText:t,isNumbered:!0,listNumber:O,sequenceId:B},e)),O++;continue}if(s.startsWith("> ")){W&&(k.push(...C),C=[],W=!1);const n=s.replace(/^>\s*/,"").trim();k.push(S(n,e));continue}if(s.startsWith("COMMENT:")){W&&(k.push(...C),C=[],W=!1);const n=s.replace(/^COMMENT:\s*/,"").trim();k.push(v(n,e));continue}const l=s.match(/!\[([^\]]*)\]\(([^)]+)\)/);if(l){const[t,r,a]=l;console.log(`Found image in markdown: ${a}`);try{console.log(`Starting image processing for: ${a}`);const n=yield z(r,a,e);console.log(`Successfully processed image, adding ${n.length} paragraphs`),k.push(...n)}catch(e){console.error(`Error in image processing: ${e instanceof Error?e.message:String(e)}`),k.push(new n({children:[new i({text:`[Image could not be loaded: ${r}]`,italics:!0,color:"FF0000"})],alignment:o.CENTER}))}continue}const c=s.match(/^(?!.*!\[).*\[([^\]]+)\]\(([^)]+)\)/);if(c){const[n,t,i]=c;k.push(E(t,i,e));continue}if(!W){try{k.push(H(s,e))}catch(t){console.warn(`Warning: Failed to process text formatting at line ${r+1}: ${t instanceof Error?t.message:String(t)}. Using plain text.`),k.push(new n({children:[new i({text:s,color:"000000",size:e.paragraphSize||24})],spacing:{before:e.paragraphSpacing,after:e.paragraphSpacing,line:240*e.lineSpacing},alignment:e.paragraphAlignment?o[e.paragraphAlignment]:void 0}))}continue}}catch(e){console.warn(`Warning: Failed to process line ${r+1}: ${e instanceof Error?e.message:"Unknown error"}. Skipping line.`);continue}L&&R&&k.push(m(R.trim(),$,e)),W&&C.length>0&&k.push(...C);const A=[];y.length>0&&(A.push(new n({text:"Table of Contents",heading:"Heading1",alignment:o.CENTER,spacing:{after:240}})),y.forEach((t=>{let o,a=!1,s=!1;switch(t.level){case 1:o=e.tocHeading1FontSize||e.tocFontSize,a=void 0===e.tocHeading1Bold||e.tocHeading1Bold,s=e.tocHeading1Italic||!1;break;case 2:o=e.tocHeading2FontSize||e.tocFontSize,a=void 0!==e.tocHeading2Bold&&e.tocHeading2Bold,s=e.tocHeading2Italic||!1;break;case 3:o=e.tocHeading3FontSize||e.tocFontSize,a=e.tocHeading3Bold||!1,s=e.tocHeading3Italic||!1;break;case 4:o=e.tocHeading4FontSize||e.tocFontSize,a=e.tocHeading4Bold||!1,s=e.tocHeading4Italic||!1;break;case 5:o=e.tocHeading5FontSize||e.tocFontSize,a=e.tocHeading5Bold||!1,s=e.tocHeading5Italic||!1;break;default:o=e.tocFontSize}o||(o=e.paragraphSize?e.paragraphSize-2*(t.level-1):24-2*(t.level-1)),A.push(new n({children:[new r({anchor:t.bookmarkId,children:[new i({text:t.text,size:o,bold:a,italics:s})]})],indent:{left:400*(t.level-1)},spacing:{after:120}}))})));const M=[];let _=!1;k.forEach((e=>{!0===e.__isTocPlaceholder?A.length>0&&!_?(M.push(...A),_=!0):console.warn("TOC placeholder found, but no headings collected or TOC already inserted."):M.push(e)}));const U=[];for(let e=1;e<=B;e++)U.push({reference:`numbered-list-${e}`,levels:[{level:0,format:a.DECIMAL,text:"%1.",alignment:o.LEFT,style:{paragraph:{indent:{left:720,hanging:260}}}}]});const P=new s({numbering:{config:U},sections:[{properties:{page:{margin:{top:1440,right:1080,bottom:1440,left:1080},size:{orientation:l.PORTRAIT}}},footers:{default:new c({children:[new n({alignment:o.CENTER,children:[new i({children:[d.CURRENT]})]})]})},children:M}],styles:{paragraphStyles:[{id:"Title",name:"Title",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize,bold:!0,color:"000000"},paragraph:{spacing:{after:240,line:240*e.lineSpacing},alignment:o.CENTER}},{id:"Heading1",name:"Heading 1",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize,bold:!0,color:"000000"},paragraph:{spacing:{before:360,after:240},outlineLevel:1}},{id:"Heading2",name:"Heading 2",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-4,bold:!0,color:"000000"},paragraph:{spacing:{before:320,after:160},outlineLevel:2}},{id:"Heading3",name:"Heading 3",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-8,bold:!0,color:"000000"},paragraph:{spacing:{before:280,after:120},outlineLevel:3}},{id:"Heading4",name:"Heading 4",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-12,bold:!0,color:"000000"},paragraph:{spacing:{before:240,after:120},outlineLevel:4}},{id:"Heading5",name:"Heading 5",basedOn:"Normal",next:"Normal",quickFormat:!0,run:{size:e.titleSize-16,bold:!0,color:"000000"},paragraph:{spacing:{before:220,after:100},outlineLevel:5}},{id:"Strong",name:"Strong",run:{bold:!0}}]}});return yield g.toBlob(P)}catch(e){if(e instanceof k)throw e;throw new k(`Failed to convert markdown to docx: ${e instanceof Error?e.message:"Unknown error"}`,{originalError:e})}}))}function y(e,n="document.docx"){if("undefined"==typeof window)throw new Error("This function can only be used in browser environments");if(!(e instanceof Blob))throw new Error("Invalid blob provided");if(!n||"string"!=typeof n)throw new Error("Invalid filename provided");try{p(e,n)}catch(e){throw console.error("Failed to save file:",e),new Error(`Failed to save file: ${e instanceof Error?e.message:"Unknown error"}`)}}export{k as MarkdownConversionError,T as convertMarkdownToDocx,y as downloadDocx};
@@ -0,0 +1 @@
1
+ const e={1:{level:1,size:0,style:"Title"},2:{level:2,size:0,style:"Heading2"},3:{level:3,size:0},4:{level:4,size:0},5:{level:5,size:0}};export{e as headingConfigs};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import a from"../../../../Icons/save.svg.js";import i from"../../../../Core/Menu/index.js";import s from"../../../../Core/Menu/Button.js";import l from"../../../../Core/Menu/List.js";const c=({variant:c="default",className:o,children:r,data:m,colors:p,onDownload:d,onSaveAsPDF:x})=>e(i,Object.assign({id:`save-artifact-${m.id}-${m.version}`},{children:[t(s,Object.assign({variant:c,className:o,style:{color:p.text}},{children:r})),t(l,Object.assign({width:"auto",className:"font-semibold p-1 text-sm",style:{backgroundColor:p.primary,color:p.text},border:`1px solid ${p.primary}`},{children:"text/markdown"===m.type?e(n,{children:[e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>d("text/markdown")},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"Markdown"]})),e("button",Object.assign({className:"px-2 py-1 text-left",onClick:x},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]}))]}):"text/html"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>d("text/html")},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"HTML"]})):"text/csv"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>d("text/csv")},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"CSV"]})):"image/svg+xml"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>d("image/svg+xml")},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.code"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>d("application/vnd.pxe.code")},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),`${m.programmingLanguage||"Plain Text"}`]})):"application/vnd.pxe.mermaid"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>d("application/vnd.pxe.mermaid")},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.react"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>d("application/vnd.pxe.react")},{children:[t(a,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TSX"]})):null}))]}));export{c as default};
1
+ import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import s from"../../../../Icons/save.svg.js";import a from"../../../../Core/Menu/index.js";import i from"../../../../Core/Menu/Button.js";import l from"../../../../Core/Menu/List.js";const c=({variant:c="default",className:o,children:r,data:m,colors:p,onDownload:x,onSaveAsPDF:d,onSaveAsDOCX:h})=>e(a,Object.assign({id:`save-artifact-${m.id}-${m.version}`},{children:[t(i,Object.assign({variant:c,className:o,style:{color:p.text}},{children:r})),t(l,Object.assign({width:"auto",className:"font-semibold p-1 text-sm",style:{backgroundColor:p.primary,color:p.text},border:`1px solid ${p.primary}`},{children:"text/markdown"===m.type?e(n,{children:[e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/markdown")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"Markdown"]})),e("button",Object.assign({className:"px-2 py-1 text-left",onClick:d},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"PDF"]})),e("button",Object.assign({className:"px-2 py-1 text-left",onClick:h},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"DOCX"]})),e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/plain")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TXT"]}))]}):"text/html"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/html")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"HTML"]})):"text/csv"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("text/csv")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"CSV"]})):"image/svg+xml"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("image/svg+xml")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.code"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("application/vnd.pxe.code")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),`${m.programmingLanguage||"Plain Text"}`]})):"application/vnd.pxe.mermaid"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("application/vnd.pxe.mermaid")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"SVG"]})):"application/vnd.pxe.react"===m.type?e("button",Object.assign({className:"px-2 py-1 text-left",onClick:()=>x("application/vnd.pxe.react")},{children:[t(s,{className:"w-5 h-5 shrink-0 inline-block mr-2"}),"TSX"]})):null}))]}));export{c as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as r,useMemo as i,useEffect as a}from"react";import{useArtifactContext as l}from"../hooks/useArtifactContext.js";import{usePickaxeContext as c}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useScroll as s}from"../../Scroll/hooks/useScroll.js";import{useArtifact as d}from"../hooks/useArtifact.js";import{useReactToPrint as p}from"react-to-print";import{PickaxeMarkdown as m}from"../../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as u}from"../../../common/PickaxeMarkdown/Renderer.js";import{Prism as g}from"react-syntax-highlighter";import v from"../../Scroll/ScrollLockView.js";import y from"../../../../Icons/x.svg.js";import f from"../../../../Icons/save.svg.js";import x from"../../../../Icons/expand.svg.js";import h from"../../../../Icons/shrink.svg.js";import b from"../../../common/PickaxeCopyButton.js";import C from"../../../../Core/ScrollArea.js";import w from"../../../../Core/TipContainer.js";import k from"../MermaidRenderer.js";import j from"./SaveMenu.js";import F from"./ViewOptions.js";import T from"csv-to-markdown-table";import O from"../../../../../common/cn.js";const A="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",S=S=>{var D,E,N,B;const{artifacts:L,currentPopupType:z,currentArtifact:M,setCurrentArtifact:R}=l(),{onLoadArtifact:$}=d(),{styles:W,colors:H,translations:P}=c(),[I,_]=n("code"),U=r(),V=r(null),q=r(null),X=p({contentRef:U}),{scrollContainerRef:G,scrollStartSession:J,scrollToBottom:K,scrollEndSession:Q}=s({auto:"code"===I}),Y=null!==(E=null===(D=S.styling)||void 0===D?void 0:D.styles)&&void 0!==E?E:W,Z=null!==(B=null===(N=S.styling)||void 0===N?void 0:N.colors)&&void 0!==B?B:H,ee=i((()=>{var e,o,t,n,r;if(!S.artifact&&!M)return null;const i=null!==(o=null===(e=S.artifact)||void 0===e?void 0:e.id)&&void 0!==o?o:null==M?void 0:M.id,a=null!==(n=null===(t=S.artifact)||void 0===t?void 0:t.version)&&void 0!==n?n:null==M?void 0:M.version;return null!==(r=L.find((e=>e.id===i&&e.version===a)))&&void 0!==r?r:null}),[M,L,S.artifact]),oe=i((()=>ee&&"text/csv"===ee.type?T(ee.content,",",!0):null),[ee]),te=i((()=>(Z.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==Z?void 0:Z.secondaryText]),ne=i((()=>{const e=S.artifact&&(null==M?void 0:M.id)===S.artifact.id&&(null==M?void 0:M.version)===S.artifact.version;return"inline"===S.type&&("inline-form"===z?!!M:e)}),[M,z,S.type,S.artifact]);a((()=>{e(void 0,void 0,void 0,(function*(){"inline"===S.type&&S.artifact&&(L.some((e=>S.artifact&&e.id===S.artifact.id&&e.version===S.artifact.version))||$({id:S.artifact.id,version:S.artifact.version}))}))}),[L,S.type,S.artifact]),a((()=>{if("application/vnd.pxe.code"===(null==ee?void 0:ee.type)&&_("code"),"finished"!==(null==ee?void 0:ee.status))return _("code"),J(),void K();Q(),"application/vnd.pxe.code"!==ee.type&&_("render")}),[null==ee?void 0:ee.status,null==ee?void 0:ee.type]),a((()=>{var e;!q.current||"text/html"!==(null==ee?void 0:ee.type)&&"application/vnd.pxe.react"!==(null==ee?void 0:ee.type)||null===(e=q.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===ee.type?"HTML_CODE":"REACT_CODE",content:ee.content},A)}),[null==ee?void 0:ee.content,null==ee?void 0:ee.type]);const re=()=>e(void 0,void 0,void 0,(function*(){if(!ee)return;const e=I;"code"===e&&(_("render"),yield new Promise((e=>setTimeout(e,50)))),X(),"code"===e&&_(e)})),ie=o=>e(void 0,void 0,void 0,(function*(){var e;if(!ee)return;let t={mimeType:"text/plain",extension:".txt"};switch(o){case"text/markdown":t={mimeType:"text/markdown",extension:".md"};break;case"text/html":t={mimeType:"text/html",extension:".html"};break;case"text/csv":t={mimeType:"text/csv",extension:".csv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":t={mimeType:"image/svg+xml",extension:".svg"};break;case"application/vnd.pxe.code":t={mimeType:`application/${ee.programmingLanguage||"text"};charset=utf-8`,extension:`.${ee.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":t={mimeType:"text/typescript",extension:".tsx"};break;default:t={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===ee.type){const o=I;"code"===o&&(_("render"),yield new Promise((e=>setTimeout(e,50))));const t=null===(e=V.current)||void 0===e?void 0:e.querySelector("svg");t&&(n=(new XMLSerializer).serializeToString(t)),"code"===o&&_(o)}const r=new Blob([null!=n?n:ee.content],{type:t.mimeType}),i=URL.createObjectURL(r);try{const e=document.createElement("a");e.href=i,e.download=`${ee.title}${t.extension}`,e.style.display="none",document.body.appendChild(e),e.click(),document.body.removeChild(e)}finally{URL.revokeObjectURL(i)}}));return ee?o("div",Object.assign({className:O("pxe-artifact-renderer flex flex-col","inline"===S.type&&!ne&&"min-h-[320px] mb-6",S.className),style:Object.assign(Object.assign({backgroundColor:Z.secondary,color:Z.secondaryText},"auto"!==z&&{borderRadius:Y.cornerRadius}),S.style)},{children:[o("div",Object.assign({className:"flex items-center gap-6 justify-between p-4 shadow-sm"},{children:[o("div",Object.assign({className:"pxe-artifact-create-header flex items-center gap-4 truncate"},{children:[(ne||!z.startsWith("inline"))&&t(F,{type:ee.type,view:I,colors:Z,onChange:_}),t("p",Object.assign({className:"font-semilight truncate text-xl"},{children:ee.title}))]})),o("div",Object.assign({className:"flex items-center gap-3"},{children:[(ne||!z.startsWith("inline"))&&t(j,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:ee,colors:Z,onDownload:ie,onSaveAsPDF:re},{children:t("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==P?void 0:P["save-as"])||"Save as"}))})),t("button",Object.assign({style:{color:Z.secondaryText},onClick:()=>{"inline"!==S.type||!S.artifact||ne?R(null):R({id:S.artifact.id,version:S.artifact.version})}},{children:"inline"===S.type?t(ne?h:x,{className:"w-6 h-6 shrink-0"}):t(y,{className:"w-6 h-6 shrink-0"})}))]}))]})),t("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:o(C,Object.assign({ref:G,innerClassName:"flex-grow w-full"},{children:["render"===I&&"application/vnd.pxe.code"!==ee.type?t("div",Object.assign({ref:U,className:O("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===ee.type&&"p-0","text/html"===ee.type&&"p-0","text/csv"===ee.type&&"p-0")},{children:"text/markdown"===ee.type||"text/csv"===ee.type||"image/svg+xml"===ee.type?t(m,Object.assign({theme:Y.theme,colors:Z},{children:t(u,{value:null!=oe?oe:ee.content,className:O("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===ee.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===ee.type?t(k,{ref:V,id:`mermaid-${ee.id}-${ee.version}`,data:ee.content}):"text/html"===ee.type||"application/vnd.pxe.react"===ee.type?t("iframe",Object.assign({ref:q,title:ee.title,src:`${A}/${"text/html"===ee.type?"html":"react"}?theme=${te?"dark":"light"}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==Z?void 0:Z.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 o=e.target;setTimeout((()=>{var e;try{null===(e=o.contentWindow)||void 0===e||e.postMessage({type:"text/html"===ee.type?"HTML_CODE":"REACT_CODE",content:ee.content},A)}catch(e){console.error("Error sending message to iframe:",e)}}),100),K()}},{children:"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t(g,Object.assign({PreTag:"div",language:"text/markdown"===ee.type?"markdown":"text/html"===ee.type||"image/svg+xml"===ee.type?"xml":"application/vnd.pxe.react"===ee.type?"typescript":ee.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==Z?void 0:Z.secondaryText},te&&{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==Z?void 0:Z.secondaryText},te&&{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==Z?void 0:Z.secondary}),':not(pre) > code[class*="language-"]':{background:null==Z?void 0:Z.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==Z?void 0:Z.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!te&&{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==Z?void 0:Z.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:ee.content})),t(v,{})]}))})),"inline"===S.type&&!ne&&o("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t(w,Object.assign({id:`artifact-copy-${ee.id}-${ee.version}`,tip:(null==P?void 0:P.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:Z.secondary,color:Z.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(b,{color:Z.secondaryText,text:ee.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t(w,Object.assign({id:`artifact-save-${ee.id}-${ee.version}`,tip:(null==P?void 0:P.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:Z.secondary,color:Z.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(j,Object.assign({data:ee,colors:Z,onDownload:ie,onSaveAsPDF:re},{children:t("button",Object.assign({style:{color:Z.secondaryText}},{children:t(f,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};export{S as default};
1
+ import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as r,useMemo as i,useEffect as a}from"react";import{useArtifactContext as l}from"../hooks/useArtifactContext.js";import{usePickaxeContext as c}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useScroll as s}from"../../Scroll/hooks/useScroll.js";import{useArtifact as d}from"../hooks/useArtifact.js";import{useReactToPrint as p}from"react-to-print";import{PickaxeMarkdown as m}from"../../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as u}from"../../../common/PickaxeMarkdown/Renderer.js";import{Prism as v}from"react-syntax-highlighter";import{convertMarkdownToDocx as f,downloadDocx as g}from"../../../../../common/docx/index.js";import x from"file-saver";import y from"../../Scroll/ScrollLockView.js";import h from"../../../../Icons/x.svg.js";import b from"../../../../Icons/save.svg.js";import C from"../../../../Icons/expand.svg.js";import w from"../../../../Icons/shrink.svg.js";import k from"../../../common/PickaxeCopyButton.js";import j from"../../../../Core/ScrollArea.js";import F from"../../../../Core/TipContainer.js";import T from"../MermaidRenderer.js";import O from"./SaveMenu.js";import A from"./ViewOptions.js";import S from"csv-to-markdown-table";import D from"../../../../../common/cn.js";const E="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",N=N=>{var B,z,M,$;const{artifacts:L,currentPopupType:W,currentArtifact:R,setCurrentArtifact:H}=l(),{onLoadArtifact:P}=d(),{styles:I,colors:_,translations:V}=c(),[X,q]=n("code"),G=r(),J=r(null),K=r(null),Q=p({contentRef:G}),{scrollContainerRef:U,scrollStartSession:Y,scrollToBottom:Z,scrollEndSession:ee}=s({auto:"code"===X}),oe=null!==(z=null===(B=N.styling)||void 0===B?void 0:B.styles)&&void 0!==z?z:I,te=null!==($=null===(M=N.styling)||void 0===M?void 0:M.colors)&&void 0!==$?$:_,ne=i((()=>{var e,o,t,n,r;if(!N.artifact&&!R)return null;const i=null!==(o=null===(e=N.artifact)||void 0===e?void 0:e.id)&&void 0!==o?o:null==R?void 0:R.id,a=null!==(n=null===(t=N.artifact)||void 0===t?void 0:t.version)&&void 0!==n?n:null==R?void 0:R.version;return null!==(r=L.find((e=>e.id===i&&e.version===a)))&&void 0!==r?r:null}),[R,L,N.artifact]),re=i((()=>ne&&"text/csv"===ne.type?S(ne.content,",",!0):null),[ne]),ie=i((()=>(te.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==te?void 0:te.secondaryText]),ae=i((()=>{const e=N.artifact&&(null==R?void 0:R.id)===N.artifact.id&&(null==R?void 0:R.version)===N.artifact.version;return"inline"===N.type&&("inline-form"===W?!!R:e)}),[R,W,N.type,N.artifact]);a((()=>{e(void 0,void 0,void 0,(function*(){"inline"===N.type&&N.artifact&&(L.some((e=>N.artifact&&e.id===N.artifact.id&&e.version===N.artifact.version))||P({id:N.artifact.id,version:N.artifact.version}))}))}),[L,N.type,N.artifact]),a((()=>{if("application/vnd.pxe.code"===(null==ne?void 0:ne.type)&&q("code"),"finished"!==(null==ne?void 0:ne.status))return q("code"),Y(),void Z();ee(),"application/vnd.pxe.code"!==ne.type&&q("render")}),[null==ne?void 0:ne.status,null==ne?void 0:ne.type]),a((()=>{var e;!K.current||"text/html"!==(null==ne?void 0:ne.type)&&"application/vnd.pxe.react"!==(null==ne?void 0:ne.type)||null===(e=K.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===ne.type?"HTML_CODE":"REACT_CODE",content:ne.content},E)}),[null==ne?void 0:ne.content,null==ne?void 0:ne.type]);const le=()=>e(void 0,void 0,void 0,(function*(){if(!ne)return;const e=X;"code"===e&&(q("render"),yield new Promise((e=>setTimeout(e,50)))),Q(),"code"===e&&q(e)})),ce=()=>e(void 0,void 0,void 0,(function*(){if(!ne)return;const e=yield f(ne.content);g(e,`${ne.title}.docx`)})),se=o=>e(void 0,void 0,void 0,(function*(){var e;if(!ne)return;let t={mimeType:"text/plain",extension:".txt"};switch(o){case"text/markdown":t={mimeType:"text/markdown",extension:".md"};break;case"text/html":t={mimeType:"text/html",extension:".html"};break;case"text/csv":t={mimeType:"text/csv",extension:".csv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":t={mimeType:"image/svg+xml",extension:".svg"};break;case"application/vnd.pxe.code":t={mimeType:`application/${ne.programmingLanguage||"text"};charset=utf-8`,extension:`.${ne.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":t={mimeType:"text/typescript",extension:".tsx"};break;default:t={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===ne.type){const o=X;"code"===o&&(q("render"),yield new Promise((e=>setTimeout(e,50))));const t=null===(e=J.current)||void 0===e?void 0:e.querySelector("svg");t&&(n=(new XMLSerializer).serializeToString(t)),"code"===o&&q(o)}const r=new Blob([null!=n?n:ne.content],{type:t.mimeType});x(r,`${ne.title}${t.extension}`)}));return ne?o("div",Object.assign({className:D("pxe-artifact-renderer flex flex-col","inline"===N.type&&!ae&&"min-h-[320px] mb-6",N.className),style:Object.assign(Object.assign({backgroundColor:te.secondary,color:te.secondaryText},"auto"!==W&&{borderRadius:oe.cornerRadius}),N.style)},{children:[o("div",Object.assign({className:"flex items-center gap-6 justify-between p-4 shadow-sm"},{children:[o("div",Object.assign({className:"pxe-artifact-create-header flex items-center gap-4 truncate"},{children:[(ae||!W.startsWith("inline"))&&t(A,{type:ne.type,view:X,colors:te,onChange:q}),t("p",Object.assign({className:"font-semilight truncate text-xl"},{children:ne.title}))]})),o("div",Object.assign({className:"flex items-center gap-3"},{children:[(ae||!W.startsWith("inline"))&&t(O,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:ne,colors:te,onDownload:se,onSaveAsPDF:le,onSaveAsDOCX:ce},{children:t("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==V?void 0:V["save-as"])||"Save as"}))})),t("button",Object.assign({style:{color:te.secondaryText},onClick:()=>{"inline"!==N.type||!N.artifact||ae?H(null):H({id:N.artifact.id,version:N.artifact.version})}},{children:"inline"===N.type?t(ae?w:C,{className:"w-6 h-6 shrink-0"}):t(h,{className:"w-6 h-6 shrink-0"})}))]}))]})),t("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:o(j,Object.assign({ref:U,innerClassName:"flex-grow w-full"},{children:["render"===X&&"application/vnd.pxe.code"!==ne.type?t("div",Object.assign({ref:G,className:D("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===ne.type&&"p-0","text/html"===ne.type&&"p-0","text/csv"===ne.type&&"p-0")},{children:"text/markdown"===ne.type||"text/csv"===ne.type||"image/svg+xml"===ne.type?t(m,Object.assign({theme:oe.theme,colors:te},{children:t(u,{value:null!=re?re:ne.content,className:D("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===ne.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===ne.type?t(T,{ref:J,id:`mermaid-${ne.id}-${ne.version}`,data:ne.content}):"text/html"===ne.type||"application/vnd.pxe.react"===ne.type?t("iframe",Object.assign({ref:K,title:ne.title,src:`${E}/${"text/html"===ne.type?"html":"react"}?theme=${ie?"dark":"light"}`,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 o=e.target;setTimeout((()=>{var e;try{null===(e=o.contentWindow)||void 0===e||e.postMessage({type:"text/html"===ne.type?"HTML_CODE":"REACT_CODE",content:ne.content},E)}catch(e){console.error("Error sending message to iframe:",e)}}),100),Z()}},{children:"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t(v,Object.assign({PreTag:"div",language:"text/markdown"===ne.type?"markdown":"text/html"===ne.type||"image/svg+xml"===ne.type?"xml":"application/vnd.pxe.react"===ne.type?"typescript":ne.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},ie&&{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},ie&&{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"}},!ie&&{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:ne.content})),t(y,{})]}))})),"inline"===N.type&&!ae&&o("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t(F,Object.assign({id:`artifact-copy-${ne.id}-${ne.version}`,tip:(null==V?void 0:V.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:te.secondary,color:te.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(k,{color:te.secondaryText,text:ne.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t(F,Object.assign({id:`artifact-save-${ne.id}-${ne.version}`,tip:(null==V?void 0:V.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:te.secondary,color:te.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(O,Object.assign({data:ne,colors:te,onDownload:se,onSaveAsPDF:le,onSaveAsDOCX:ce},{children:t("button",Object.assign({style:{color:te.secondaryText}},{children:t(b,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};export{N as default};
@@ -0,0 +1,104 @@
1
+ import { Paragraph, TextRun, Table } from "docx";
2
+ import { Style, TableData, HeadingConfig, ListItemConfig } from "./types";
3
+ /**
4
+ * Processes a heading line and returns appropriate paragraph formatting and a bookmark ID
5
+ * @param line - The heading line to process
6
+ * @param config - The heading configuration
7
+ * @param style - The style configuration
8
+ * @param documentType - The document type
9
+ * @returns An object containing the processed paragraph and its bookmark ID
10
+ */
11
+ export declare function processHeading(line: string, config: HeadingConfig, style: Style, _: "document" | "report"): {
12
+ paragraph: Paragraph;
13
+ bookmarkId: string;
14
+ };
15
+ /**
16
+ * Processes a table and returns table formatting
17
+ * @param tableData - The table data
18
+ * @param documentType - The document type
19
+ * @returns The processed table
20
+ */
21
+ export declare function processTable(tableData: TableData, documentType: "document" | "report"): Table;
22
+ /**
23
+ * Processes a list item and returns appropriate paragraph formatting
24
+ * @param config - The list item configuration
25
+ * @param style - The style configuration
26
+ * @returns The processed paragraph
27
+ */
28
+ export declare function processListItem(config: ListItemConfig, style: Style): Paragraph;
29
+ /**
30
+ * Processes a blockquote and returns appropriate paragraph formatting
31
+ * @param text - The blockquote text
32
+ * @param style - The style configuration
33
+ * @returns The processed paragraph
34
+ */
35
+ export declare function processBlockquote(text: string, style: Style): Paragraph;
36
+ /**
37
+ * Processes a comment and returns appropriate paragraph formatting
38
+ * @param text - The comment text
39
+ * @param style - The style configuration
40
+ * @returns The processed paragraph
41
+ */
42
+ export declare function processComment(text: string, style: Style): Paragraph;
43
+ /**
44
+ * Processes formatted text (bold/italic/inline-code) and returns an array of TextRun objects
45
+ * @param line - The line to process
46
+ * @param style - The style configuration
47
+ * @returns An array of TextRun objects
48
+ */
49
+ export declare function processFormattedText(line: string, style?: Style): TextRun[];
50
+ /**
51
+ * Collects tables from markdown lines
52
+ * @param lines - The markdown lines
53
+ * @returns An array of table data
54
+ */
55
+ export declare function collectTables(lines: string[]): TableData[];
56
+ /**
57
+ * Processes inline code and returns a TextRun object
58
+ * @param code - The inline code text
59
+ * @param style - The style configuration
60
+ * @returns A TextRun object
61
+ */
62
+ export declare function processInlineCode(code: string, style?: Style): TextRun;
63
+ /**
64
+ * Processes a code block and returns appropriate paragraph formatting
65
+ * @param code - The code block text
66
+ * @param language - The programming language (optional)
67
+ * @param style - The style configuration
68
+ * @returns The processed paragraph
69
+ */
70
+ export declare function processCodeBlock(code: string, language: string | undefined, style: Style): Paragraph;
71
+ /**
72
+ * Processes a link and returns appropriate text run
73
+ */
74
+ export declare function processLink(text: string, _: string): TextRun;
75
+ /**
76
+ * Processes a link and returns a paragraph with hyperlink
77
+ * @param text - The link text
78
+ * @param url - The link URL
79
+ * @param style - The style configuration
80
+ * @returns The processed paragraph with hyperlink
81
+ */
82
+ export declare function processLinkParagraph(text: string, url: string, style: Style): Paragraph;
83
+ /**
84
+ * Creates a simple link paragraph
85
+ * @param text - The link text
86
+ * @param url - The URL to link to
87
+ * @returns A paragraph with a hyperlink
88
+ */
89
+ export declare function createLinkParagraph(text: string, url: string): Paragraph;
90
+ /**
91
+ * Processes an image and returns appropriate paragraph
92
+ * @param altText - The alt text
93
+ * @param imageUrl - The image URL
94
+ * @param style - The style configuration
95
+ * @returns The processed paragraph
96
+ */
97
+ export declare function processImage(altText: string, imageUrl: string, style: Style): Promise<Paragraph[]>;
98
+ /**
99
+ * Processes a paragraph and returns appropriate paragraph formatting
100
+ * @param text - The paragraph text
101
+ * @param style - The style configuration
102
+ * @returns The processed paragraph
103
+ */
104
+ export declare function processParagraph(text: string, style: Style): Paragraph;
@@ -0,0 +1,28 @@
1
+ import { Options } from "./types";
2
+ /**
3
+ * Custom error class for markdown conversion errors
4
+ * @extends Error
5
+ * @param message - The error message
6
+ * @param context - The context of the error
7
+ */
8
+ export declare class MarkdownConversionError extends Error {
9
+ context?: any;
10
+ constructor(message: string, context?: any);
11
+ }
12
+ /**
13
+ * Convert Markdown to Docx
14
+ * @param markdown - The Markdown string to convert
15
+ * @param options - The options for the conversion
16
+ * @returns A Promise that resolves to a Blob containing the Docx file
17
+ * @throws {MarkdownConversionError} If conversion fails
18
+ */
19
+ export declare function convertMarkdownToDocx(markdown: string, options?: Options): Promise<Blob>;
20
+ /**
21
+ * Downloads a DOCX file in the browser environment
22
+ * @param blob - The Blob containing the DOCX file data
23
+ * @param filename - The name to save the file as (defaults to "document.docx")
24
+ * @throws {Error} If the function is called outside browser environment
25
+ * @throws {Error} If invalid blob or filename is provided
26
+ * @throws {Error} If file save fails
27
+ */
28
+ export declare function downloadDocx(blob: Blob, filename?: string): void;
@@ -0,0 +1,66 @@
1
+ export interface Style {
2
+ titleSize: number;
3
+ headingSpacing: number;
4
+ paragraphSpacing: number;
5
+ lineSpacing: number;
6
+ heading1Size?: number;
7
+ heading2Size?: number;
8
+ heading3Size?: number;
9
+ heading4Size?: number;
10
+ heading5Size?: number;
11
+ paragraphSize?: number;
12
+ listItemSize?: number;
13
+ codeBlockSize?: number;
14
+ blockquoteSize?: number;
15
+ tocFontSize?: number;
16
+ tocHeading1FontSize?: number;
17
+ tocHeading2FontSize?: number;
18
+ tocHeading3FontSize?: number;
19
+ tocHeading4FontSize?: number;
20
+ tocHeading5FontSize?: number;
21
+ tocHeading1Bold?: boolean;
22
+ tocHeading2Bold?: boolean;
23
+ tocHeading3Bold?: boolean;
24
+ tocHeading4Bold?: boolean;
25
+ tocHeading5Bold?: boolean;
26
+ tocHeading1Italic?: boolean;
27
+ tocHeading2Italic?: boolean;
28
+ tocHeading3Italic?: boolean;
29
+ tocHeading4Italic?: boolean;
30
+ tocHeading5Italic?: boolean;
31
+ paragraphAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
32
+ headingAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
33
+ heading1Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
34
+ heading2Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
35
+ heading3Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
36
+ heading4Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
37
+ heading5Alignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
38
+ blockquoteAlignment?: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED";
39
+ }
40
+ export interface Options {
41
+ documentType?: "document" | "report";
42
+ style?: Style;
43
+ }
44
+ export interface TableData {
45
+ headers: string[];
46
+ rows: string[][];
47
+ }
48
+ export interface ProcessedContent {
49
+ children: any[];
50
+ skipLines: number;
51
+ }
52
+ export interface HeadingConfig {
53
+ level: number;
54
+ size: number;
55
+ style?: string;
56
+ alignment?: any;
57
+ }
58
+ export interface ListItemConfig {
59
+ text: string;
60
+ boldText?: string;
61
+ isNumbered?: boolean;
62
+ listNumber?: number;
63
+ sequenceId?: number;
64
+ }
65
+ export declare const defaultStyle: Style;
66
+ export declare const headingConfigs: Record<number, HeadingConfig>;
@@ -7,8 +7,9 @@ interface ArtifactSaveMenuProps {
7
7
  children?: ReactNode;
8
8
  data: ArtifactData;
9
9
  colors: PickaxeProviderColors;
10
- onDownload: (type: ArtifactType) => void;
11
- onSaveAsPDF: () => void;
10
+ onDownload: (type: ArtifactType | "text/plain") => Promise<void>;
11
+ onSaveAsPDF: () => Promise<void>;
12
+ onSaveAsDOCX: () => Promise<void>;
12
13
  }
13
- declare const ArtifactSaveMenu: ({ variant, className, children, data, colors, onDownload, onSaveAsPDF, }: ArtifactSaveMenuProps) => import("react/jsx-runtime").JSX.Element;
14
+ declare const ArtifactSaveMenu: ({ variant, className, children, data, colors, onDownload, onSaveAsPDF, onSaveAsDOCX, }: ArtifactSaveMenuProps) => import("react/jsx-runtime").JSX.Element;
14
15
  export default ArtifactSaveMenu;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "3.5.3",
3
+ "version": "3.6.1",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",
@@ -83,6 +83,7 @@
83
83
  "cross-env": "^7.0.3",
84
84
  "csv-to-markdown-table": "^1.5.0",
85
85
  "date-fns": "^3.6.0",
86
+ "docx": "^9.5.1",
86
87
  "eslint": "8.31.0",
87
88
  "eslint-config-prettier": "^8.6.0",
88
89
  "eslint-plugin-jsx-a11y": "^6.7.1",
@@ -91,6 +92,7 @@
91
92
  "eslint-plugin-react-hooks": "^4.6.0",
92
93
  "eslint-plugin-storybook": "^0.11.2",
93
94
  "eventsource-parser": "^3.0.2",
95
+ "file-saver": "^2.0.5",
94
96
  "framer-motion": "^11.17.0",
95
97
  "husky": "^8.0.3",
96
98
  "isomorphic-dompurify": "^2.20.0",
@@ -145,7 +147,9 @@
145
147
  "copy-to-clipboard": "^3.3.3",
146
148
  "csv-to-markdown-table": "^1.5.0",
147
149
  "date-fns": "^3.6.0",
150
+ "docx": "^9.5.1",
148
151
  "eventsource-parser": "^3.0.2",
152
+ "file-saver": "^2.0.5",
149
153
  "framer-motion": "^11.17.0",
150
154
  "isomorphic-dompurify": "^2.20.0",
151
155
  "katex": "^0.16.19",