@pickaxeproject/react 3.6.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/docx/helpers.js +1 -0
- package/dist/cjs/common/docx/index.js +1 -0
- package/dist/cjs/common/docx/types.js +1 -0
- package/dist/cjs/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
- package/dist/cjs/components/Pickaxe/common/PickaxeBranding.js +1 -1
- package/dist/cjs/hooks/core/useAffiliate.js +1 -0
- package/dist/cjs/src/common/docx/helpers.d.ts +104 -0
- package/dist/cjs/src/common/docx/index.d.ts +28 -0
- package/dist/cjs/src/common/docx/types.d.ts +66 -0
- package/dist/cjs/src/hooks/core/useAffiliate.d.ts +12 -0
- package/dist/esm/common/docx/helpers.js +1 -0
- package/dist/esm/common/docx/index.js +1 -0
- package/dist/esm/common/docx/types.js +1 -0
- package/dist/esm/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
- package/dist/esm/components/Pickaxe/common/PickaxeBranding.js +1 -1
- package/dist/esm/hooks/core/useAffiliate.js +1 -0
- package/dist/esm/src/common/docx/helpers.d.ts +104 -0
- package/dist/esm/src/common/docx/index.d.ts +28 -0
- package/dist/esm/src/common/docx/types.d.ts +66 -0
- package/dist/esm/src/hooks/core/useAffiliate.d.ts +12 -0
- package/package.json +5 -3
|
@@ -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("../../../../../_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("@mohtasham/md-to-docx"),u=require("../../Scroll/ScrollLockView.js"),m=require("../../../../Icons/x.svg.js"),x=require("../../../../Icons/save.svg.js"),f=require("../../../../Icons/expand.svg.js"),v=require("../../../../Icons/shrink.svg.js"),y=require("../../../common/PickaxeCopyButton.js"),g=require("../../../../Core/ScrollArea.js"),h=require("../../../../Core/TipContainer.js"),b=require("../MermaidRenderer.js"),j=require("./SaveMenu.js"),w=require("./ViewOptions.js"),C=require("csv-to-markdown-table"),k=require("../../../../../common/cn.js");function F(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var O=F(C);const T="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co";exports.default=C=>{var F,A,S,D;const{artifacts:E,currentPopupType:q,currentArtifact:N,setCurrentArtifact:M}=n.useArtifactContext(),{onLoadArtifact:R}=i.useArtifact(),{styles:B,colors:_,translations:L}=r.usePickaxeContext(),[P,z]=t.useState("code"),$=t.useRef(),W=t.useRef(null),H=t.useRef(null),I=l.useReactToPrint({contentRef:$}),{scrollContainerRef:U,scrollStartSession:V,scrollToBottom:X,scrollEndSession:G}=a.useScroll({auto:"code"===P}),J=null!==(A=null===(F=C.styling)||void 0===F?void 0:F.styles)&&void 0!==A?A:B,K=null!==(D=null===(S=C.styling)||void 0===S?void 0:S.colors)&&void 0!==D?D:_,Q=t.useMemo((()=>{var e,o,t,n,r;if(!C.artifact&&!N)return null;const a=null!==(o=null===(e=C.artifact)||void 0===e?void 0:e.id)&&void 0!==o?o:null==N?void 0:N.id,i=null!==(n=null===(t=C.artifact)||void 0===t?void 0:t.version)&&void 0!==n?n:null==N?void 0:N.version;return null!==(r=E.find((e=>e.id===a&&e.version===i)))&&void 0!==r?r:null}),[N,E,C.artifact]),Y=t.useMemo((()=>Q&&"text/csv"===Q.type?O.default(Q.content,",",!0):null),[Q]),Z=t.useMemo((()=>(K.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==K?void 0:K.secondaryText]),ee=t.useMemo((()=>{const e=C.artifact&&(null==N?void 0:N.id)===C.artifact.id&&(null==N?void 0:N.version)===C.artifact.version;return"inline"===C.type&&("inline-form"===q?!!N:e)}),[N,q,C.type,C.artifact]);t.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){"inline"===C.type&&C.artifact&&(E.some((e=>C.artifact&&e.id===C.artifact.id&&e.version===C.artifact.version))||R({id:C.artifact.id,version:C.artifact.version}))}))}),[E,C.type,C.artifact]),t.useEffect((()=>{if("application/vnd.pxe.code"===(null==Q?void 0:Q.type)&&z("code"),"finished"!==(null==Q?void 0:Q.status))return z("code"),V(),void X();G(),"application/vnd.pxe.code"!==Q.type&&z("render")}),[null==Q?void 0:Q.status,null==Q?void 0:Q.type]),t.useEffect((()=>{var e;!H.current||"text/html"!==(null==Q?void 0:Q.type)&&"application/vnd.pxe.react"!==(null==Q?void 0:Q.type)||null===(e=H.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===Q.type?"HTML_CODE":"REACT_CODE",content:Q.content},T)}),[null==Q?void 0:Q.content,null==Q?void 0:Q.type]);const oe=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!Q)return;const e=P;"code"===e&&(z("render"),yield new Promise((e=>setTimeout(e,50)))),I(),"code"===e&&z(e)})),te=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!Q)return;const e=yield p.convertMarkdownToDocx(Q.content);p.downloadDocx(e,`${Q.title}.docx`)})),ne=o=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!Q)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/${Q.programmingLanguage||"text"};charset=utf-8`,extension:`.${Q.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"===Q.type){const o=P;"code"===o&&(z("render"),yield new Promise((e=>setTimeout(e,50))));const t=null===(e=W.current)||void 0===e?void 0:e.querySelector("svg");t&&(n=(new XMLSerializer).serializeToString(t)),"code"===o&&z(o)}const r=new Blob([null!=n?n:Q.content],{type:t.mimeType}),a=URL.createObjectURL(r);try{const e=document.createElement("a");e.href=a,e.download=`${Q.title}${t.extension}`,e.style.display="none",document.body.appendChild(e),e.click(),document.body.removeChild(e)}finally{URL.revokeObjectURL(a)}}));return Q?o.jsxs("div",Object.assign({className:k.default("pxe-artifact-renderer flex flex-col","inline"===C.type&&!ee&&"min-h-[320px] mb-6",C.className),style:Object.assign(Object.assign({backgroundColor:K.secondary,color:K.secondaryText},"auto"!==q&&{borderRadius:J.cornerRadius}),C.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:[(ee||!q.startsWith("inline"))&&o.jsx(w.default,{type:Q.type,view:P,colors:K,onChange:z}),o.jsx("p",Object.assign({className:"font-semilight truncate text-xl"},{children:Q.title}))]})),o.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[(ee||!q.startsWith("inline"))&&o.jsx(j.default,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:Q,colors:K,onDownload:ne,onSaveAsPDF:oe,onSaveAsDOCX:te},{children:o.jsx("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==L?void 0:L["save-as"])||"Save as"}))})),o.jsx("button",Object.assign({style:{color:K.secondaryText},onClick:()=>{"inline"!==C.type||!C.artifact||ee?M(null):M({id:C.artifact.id,version:C.artifact.version})}},{children:"inline"===C.type?ee?o.jsx(v.default,{className:"w-6 h-6 shrink-0"}):o.jsx(f.default,{className:"w-6 h-6 shrink-0"}):o.jsx(m.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(g.default,Object.assign({ref:U,innerClassName:"flex-grow w-full"},{children:["render"===P&&"application/vnd.pxe.code"!==Q.type?o.jsx("div",Object.assign({ref:$,className:k.default("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===Q.type&&"p-0","text/html"===Q.type&&"p-0","text/csv"===Q.type&&"p-0")},{children:"text/markdown"===Q.type||"text/csv"===Q.type||"image/svg+xml"===Q.type?o.jsx(s.PickaxeMarkdown,Object.assign({theme:J.theme,colors:K},{children:o.jsx(c.PickaxeMarkdownRenderer,{value:null!=Y?Y:Q.content,className:k.default("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===Q.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===Q.type?o.jsx(b.default,{ref:W,id:`mermaid-${Q.id}-${Q.version}`,data:Q.content}):"text/html"===Q.type||"application/vnd.pxe.react"===Q.type?o.jsx("iframe",Object.assign({ref:H,title:Q.title,src:`${T}/${"text/html"===Q.type?"html":"react"}?theme=${Z?"dark":"light"}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==K?void 0:K.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"===Q.type?"HTML_CODE":"REACT_CODE",content:Q.content},T)}catch(e){console.error("Error sending message to iframe:",e)}}),100),X()}},{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"===Q.type?"markdown":"text/html"===Q.type||"image/svg+xml"===Q.type?"xml":"application/vnd.pxe.react"===Q.type?"typescript":Q.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==K?void 0:K.secondaryText},Z&&{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==K?void 0:K.secondaryText},Z&&{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==K?void 0:K.secondary}),':not(pre) > code[class*="language-"]':{background:null==K?void 0:K.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==K?void 0:K.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!Z&&{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==K?void 0:K.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:Q.content})),o.jsx(u.default,{})]}))})),"inline"===C.type&&!ee&&o.jsxs("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[o.jsx(h.default,Object.assign({id:`artifact-copy-${Q.id}-${Q.version}`,tip:(null==L?void 0:L.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:K.secondary,color:K.secondaryText,fontSize:"12px"},align:"bottom"},{children:o.jsx(y.default,{color:K.secondaryText,text:Q.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),o.jsx(h.default,Object.assign({id:`artifact-save-${Q.id}-${Q.version}`,tip:(null==L?void 0:L.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:K.secondary,color:K.secondaryText,fontSize:"12px"},align:"bottom"},{children:o.jsx(j.default,Object.assign({data:Q,colors:K,onDownload:ne,onSaveAsPDF:oe,onSaveAsDOCX:te},{children:o.jsx("button",Object.assign({style:{color:K.secondaryText}},{children:o.jsx(x.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../hooks/pickaxe/usePickaxeContext.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/studio/useStyleFontSize.js"),t=require("../../../hooks/core/useAffiliate.js"),a=require("framer-motion"),o=require("../../Icons/pickaxe.svg.js"),r=require("../../../common/cn.js");exports.default=({className:l,animateHover:n=!0})=>{var c,u,d;const{formId:f,pickaxe:x,colors:p,misc:m,translations:h}=s.usePickaxeContext(),k=t.useAffiliate({formId:f}),v=i.useStyleFontSize();return!x||m.isWhiteLabel?null:e.jsxs(a.motion.a,Object.assign({href:null!==(u=null===(c=k.data)||void 0===c?void 0:c.link)&&void 0!==u?u:`https://${process.env.NEXT_PUBLIC_PICKAXE_DOMAIN}`,className:r.default("flex items-center gap-2 select-none overflow-hidden px-2 py-1 rounded",l,"#ffffff"===p.text.toLowerCase()?"text-white":"text-black")},n&&{initial:{scale:1},whileHover:{scale:1.05},whileTap:{scale:.95}},{children:[e.jsx(o.default,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",Object.assign({className:r.default(v.b4,"opacity-50")},{children:null!==(d=null==h?void 0:h["powered-by-pickaxe"])&&void 0!==d?d:"Powered by Pickaxe"}))]}))};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),t=require("@tanstack/react-query"),i=require("../../common/api/utils.js");exports.useAffiliate=r=>{const o=t.useQuery({queryKey:["affiliate",r],queryFn:()=>e.__awaiter(void 0,void 0,void 0,(function*(){return(({formId:t,studioId:r,deploymentId:o})=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!t&&!r&&!o)throw new Error("[_getAffiliate] No formId, studioId or deploymentId provided");const e={};t?e.formId=t:r?e.studioId=r:o&&(e.deploymentId=o);const d=new URLSearchParams(e).toString(),a=d?`/affiliate?${d}`:"/affiliate",f=yield i.default.get(a),u=f.data;if(200!==f.status)throw new Error("[_getAffiliate] Failed to fetch affiliate "+u);return u})))(r)})),enabled:!!r.formId||!!r.studioId||!!r.deploymentId});return o};
|
|
@@ -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>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface QueryResponse {
|
|
2
|
+
success: boolean;
|
|
3
|
+
link: string;
|
|
4
|
+
error?: string;
|
|
5
|
+
}
|
|
6
|
+
interface QueryParams {
|
|
7
|
+
formId?: string;
|
|
8
|
+
studioId?: string;
|
|
9
|
+
deploymentId?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const useAffiliate: (params: QueryParams) => import("@tanstack/react-query").UseQueryResult<QueryResponse, Error>;
|
|
12
|
+
export {};
|
|
@@ -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{__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 y}from"@mohtasham/md-to-docx";import g from"../../Scroll/ScrollLockView.js";import x from"../../../../Icons/x.svg.js";import h from"../../../../Icons/save.svg.js";import b from"../../../../Icons/expand.svg.js";import C from"../../../../Icons/shrink.svg.js";import w from"../../../common/PickaxeCopyButton.js";import k from"../../../../Core/ScrollArea.js";import j from"../../../../Core/TipContainer.js";import F from"../MermaidRenderer.js";import O from"./SaveMenu.js";import T from"./ViewOptions.js";import A from"csv-to-markdown-table";import S from"../../../../../common/cn.js";const D="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",E=E=>{var N,B,L,z;const{artifacts:M,currentPopupType:R,currentArtifact:$,setCurrentArtifact:W}=l(),{onLoadArtifact:H}=d(),{styles:P,colors:I,translations:_}=c(),[U,V]=n("code"),X=r(),q=r(null),G=r(null),J=p({contentRef:X}),{scrollContainerRef:K,scrollStartSession:Q,scrollToBottom:Y,scrollEndSession:Z}=s({auto:"code"===U}),ee=null!==(B=null===(N=E.styling)||void 0===N?void 0:N.styles)&&void 0!==B?B:P,oe=null!==(z=null===(L=E.styling)||void 0===L?void 0:L.colors)&&void 0!==z?z:I,te=i((()=>{var e,o,t,n,r;if(!E.artifact&&!$)return null;const i=null!==(o=null===(e=E.artifact)||void 0===e?void 0:e.id)&&void 0!==o?o:null==$?void 0:$.id,a=null!==(n=null===(t=E.artifact)||void 0===t?void 0:t.version)&&void 0!==n?n:null==$?void 0:$.version;return null!==(r=M.find((e=>e.id===i&&e.version===a)))&&void 0!==r?r:null}),[$,M,E.artifact]),ne=i((()=>te&&"text/csv"===te.type?A(te.content,",",!0):null),[te]),re=i((()=>(oe.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==oe?void 0:oe.secondaryText]),ie=i((()=>{const e=E.artifact&&(null==$?void 0:$.id)===E.artifact.id&&(null==$?void 0:$.version)===E.artifact.version;return"inline"===E.type&&("inline-form"===R?!!$:e)}),[$,R,E.type,E.artifact]);a((()=>{e(void 0,void 0,void 0,(function*(){"inline"===E.type&&E.artifact&&(M.some((e=>E.artifact&&e.id===E.artifact.id&&e.version===E.artifact.version))||H({id:E.artifact.id,version:E.artifact.version}))}))}),[M,E.type,E.artifact]),a((()=>{if("application/vnd.pxe.code"===(null==te?void 0:te.type)&&V("code"),"finished"!==(null==te?void 0:te.status))return V("code"),Q(),void Y();Z(),"application/vnd.pxe.code"!==te.type&&V("render")}),[null==te?void 0:te.status,null==te?void 0:te.type]),a((()=>{var e;!G.current||"text/html"!==(null==te?void 0:te.type)&&"application/vnd.pxe.react"!==(null==te?void 0:te.type)||null===(e=G.current.contentWindow)||void 0===e||e.postMessage({type:"text/html"===te.type?"HTML_CODE":"REACT_CODE",content:te.content},D)}),[null==te?void 0:te.content,null==te?void 0:te.type]);const ae=()=>e(void 0,void 0,void 0,(function*(){if(!te)return;const e=U;"code"===e&&(V("render"),yield new Promise((e=>setTimeout(e,50)))),J(),"code"===e&&V(e)})),le=()=>e(void 0,void 0,void 0,(function*(){if(!te)return;const e=yield f(te.content);y(e,`${te.title}.docx`)})),ce=o=>e(void 0,void 0,void 0,(function*(){var e;if(!te)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/${te.programmingLanguage||"text"};charset=utf-8`,extension:`.${te.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"===te.type){const o=U;"code"===o&&(V("render"),yield new Promise((e=>setTimeout(e,50))));const t=null===(e=q.current)||void 0===e?void 0:e.querySelector("svg");t&&(n=(new XMLSerializer).serializeToString(t)),"code"===o&&V(o)}const r=new Blob([null!=n?n:te.content],{type:t.mimeType}),i=URL.createObjectURL(r);try{const e=document.createElement("a");e.href=i,e.download=`${te.title}${t.extension}`,e.style.display="none",document.body.appendChild(e),e.click(),document.body.removeChild(e)}finally{URL.revokeObjectURL(i)}}));return te?o("div",Object.assign({className:S("pxe-artifact-renderer flex flex-col","inline"===E.type&&!ie&&"min-h-[320px] mb-6",E.className),style:Object.assign(Object.assign({backgroundColor:oe.secondary,color:oe.secondaryText},"auto"!==R&&{borderRadius:ee.cornerRadius}),E.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:[(ie||!R.startsWith("inline"))&&t(T,{type:te.type,view:U,colors:oe,onChange:V}),t("p",Object.assign({className:"font-semilight truncate text-xl"},{children:te.title}))]})),o("div",Object.assign({className:"flex items-center gap-3"},{children:[(ie||!R.startsWith("inline"))&&t(O,Object.assign({variant:"anchor",className:"px-3 py-1.5 shrink-0",data:te,colors:oe,onDownload:ce,onSaveAsPDF:ae,onSaveAsDOCX:le},{children:t("span",Object.assign({className:"shrink-0 font-semibold text-sm select-none"},{children:(null==_?void 0:_["save-as"])||"Save as"}))})),t("button",Object.assign({style:{color:oe.secondaryText},onClick:()=>{"inline"!==E.type||!E.artifact||ie?W(null):W({id:E.artifact.id,version:E.artifact.version})}},{children:"inline"===E.type?t(ie?C:b,{className:"w-6 h-6 shrink-0"}):t(x,{className:"w-6 h-6 shrink-0"})}))]}))]})),t("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:o(k,Object.assign({ref:K,innerClassName:"flex-grow w-full"},{children:["render"===U&&"application/vnd.pxe.code"!==te.type?t("div",Object.assign({ref:X,className:S("p-4 pb-6 flex-grow flex flex-col","application/vnd.pxe.react"===te.type&&"p-0","text/html"===te.type&&"p-0","text/csv"===te.type&&"p-0")},{children:"text/markdown"===te.type||"text/csv"===te.type||"image/svg+xml"===te.type?t(m,Object.assign({theme:ee.theme,colors:oe},{children:t(u,{value:null!=ne?ne:te.content,className:S("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full","text/csv"===te.type&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===te.type?t(F,{ref:q,id:`mermaid-${te.id}-${te.version}`,data:te.content}):"text/html"===te.type||"application/vnd.pxe.react"===te.type?t("iframe",Object.assign({ref:G,title:te.title,src:`${D}/${"text/html"===te.type?"html":"react"}?theme=${re?"dark":"light"}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==oe?void 0:oe.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"===te.type?"HTML_CODE":"REACT_CODE",content:te.content},D)}catch(e){console.error("Error sending message to iframe:",e)}}),100),Y()}},{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"===te.type?"markdown":"text/html"===te.type||"image/svg+xml"===te.type?"xml":"application/vnd.pxe.react"===te.type?"typescript":te.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==oe?void 0:oe.secondaryText},re&&{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==oe?void 0:oe.secondaryText},re&&{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==oe?void 0:oe.secondary}),':not(pre) > code[class*="language-"]':{background:null==oe?void 0:oe.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==oe?void 0:oe.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!re&&{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==oe?void 0:oe.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:te.content})),t(g,{})]}))})),"inline"===E.type&&!ie&&o("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t(j,Object.assign({id:`artifact-copy-${te.id}-${te.version}`,tip:(null==_?void 0:_.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:oe.secondary,color:oe.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(w,{color:oe.secondaryText,text:te.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t(j,Object.assign({id:`artifact-save-${te.id}-${te.version}`,tip:(null==_?void 0:_.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:oe.secondary,color:oe.secondaryText,fontSize:"12px"},align:"bottom"},{children:t(O,Object.assign({data:te,colors:oe,onDownload:ce,onSaveAsPDF:ae,onSaveAsDOCX:le},{children:t("button",Object.assign({style:{color:oe.secondaryText}},{children:t(h,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};export{E 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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as o}from"react/jsx-runtime";import{usePickaxeContext as s}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useStyleFontSize as
|
|
1
|
+
import{jsxs as e,jsx as o}from"react/jsx-runtime";import{usePickaxeContext as s}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useStyleFontSize as i}from"../../../hooks/studio/useStyleFontSize.js";import{useAffiliate as t}from"../../../hooks/core/useAffiliate.js";import{motion as a}from"framer-motion";import r from"../../Icons/pickaxe.svg.js";import l from"../../../common/cn.js";const n=({className:n,animateHover:c=!0})=>{var m,f,p;const{formId:d,pickaxe:h,colors:x,misc:u,translations:k}=s(),v=t({formId:d}),j=i();return!h||u.isWhiteLabel?null:e(a.a,Object.assign({href:null!==(f=null===(m=v.data)||void 0===m?void 0:m.link)&&void 0!==f?f:`https://${process.env.NEXT_PUBLIC_PICKAXE_DOMAIN}`,className:l("flex items-center gap-2 select-none overflow-hidden px-2 py-1 rounded",n,"#ffffff"===x.text.toLowerCase()?"text-white":"text-black")},c&&{initial:{scale:1},whileHover:{scale:1.05},whileTap:{scale:.95}},{children:[o(r,{className:"h-3.5 w-3.5 shrink-0"}),o("span",Object.assign({className:l(j.b4,"opacity-50")},{children:null!==(p=null==k?void 0:k["powered-by-pickaxe"])&&void 0!==p?p:"Powered by Pickaxe"}))]}))};export{n as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as t}from"../../_virtual/_tslib.js";import{useQuery as o}from"@tanstack/react-query";import i from"../../common/api/utils.js";const e=e=>{const r=o({queryKey:["affiliate",e],queryFn:()=>t(void 0,void 0,void 0,(function*(){return(({formId:o,studioId:e,deploymentId:r})=>t(void 0,void 0,void 0,(function*(){if(!o&&!e&&!r)throw new Error("[_getAffiliate] No formId, studioId or deploymentId provided");const t={};o?t.formId=o:e?t.studioId=e:r&&(t.deploymentId=r);const d=new URLSearchParams(t).toString(),f=d?`/affiliate?${d}`:"/affiliate",a=yield i.get(f),n=a.data;if(200!==a.status)throw new Error("[_getAffiliate] Failed to fetch affiliate "+n);return n})))(e)})),enabled:!!e.formId||!!e.studioId||!!e.deploymentId});return r};export{e as useAffiliate};
|
|
@@ -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>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface QueryResponse {
|
|
2
|
+
success: boolean;
|
|
3
|
+
link: string;
|
|
4
|
+
error?: string;
|
|
5
|
+
}
|
|
6
|
+
interface QueryParams {
|
|
7
|
+
formId?: string;
|
|
8
|
+
studioId?: string;
|
|
9
|
+
deploymentId?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const useAffiliate: (params: QueryParams) => import("@tanstack/react-query").UseQueryResult<QueryResponse, Error>;
|
|
12
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pickaxeproject/react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Client utility library for Pickaxe",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@changesets/cli": "^2.26.0",
|
|
44
44
|
"@chromatic-com/storybook": "3.2.3",
|
|
45
45
|
"@mdx-js/react": "^3.1.0",
|
|
46
|
-
"@mohtasham/md-to-docx": "^2.0.1",
|
|
47
46
|
"@nem035/gpt-3-encoder": "^1.1.7",
|
|
48
47
|
"@prettier/plugin-xml": "^3.4.1",
|
|
49
48
|
"@rollup/plugin-alias": "^5.1.1",
|
|
@@ -84,6 +83,7 @@
|
|
|
84
83
|
"cross-env": "^7.0.3",
|
|
85
84
|
"csv-to-markdown-table": "^1.5.0",
|
|
86
85
|
"date-fns": "^3.6.0",
|
|
86
|
+
"docx": "^9.5.1",
|
|
87
87
|
"eslint": "8.31.0",
|
|
88
88
|
"eslint-config-prettier": "^8.6.0",
|
|
89
89
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
93
93
|
"eslint-plugin-storybook": "^0.11.2",
|
|
94
94
|
"eventsource-parser": "^3.0.2",
|
|
95
|
+
"file-saver": "^2.0.5",
|
|
95
96
|
"framer-motion": "^11.17.0",
|
|
96
97
|
"husky": "^8.0.3",
|
|
97
98
|
"isomorphic-dompurify": "^2.20.0",
|
|
@@ -138,7 +139,6 @@
|
|
|
138
139
|
"webpack-cli": "^5.0.1"
|
|
139
140
|
},
|
|
140
141
|
"peerDependencies": {
|
|
141
|
-
"@mohtasham/md-to-docx": "^2.0.1",
|
|
142
142
|
"@nem035/gpt-3-encoder": "^1.1.7",
|
|
143
143
|
"@tailwindcss/container-queries": "^0.1.1",
|
|
144
144
|
"@tanstack/react-query": "^4.36.1",
|
|
@@ -147,7 +147,9 @@
|
|
|
147
147
|
"copy-to-clipboard": "^3.3.3",
|
|
148
148
|
"csv-to-markdown-table": "^1.5.0",
|
|
149
149
|
"date-fns": "^3.6.0",
|
|
150
|
+
"docx": "^9.5.1",
|
|
150
151
|
"eventsource-parser": "^3.0.2",
|
|
152
|
+
"file-saver": "^2.0.5",
|
|
151
153
|
"framer-motion": "^11.17.0",
|
|
152
154
|
"isomorphic-dompurify": "^2.20.0",
|
|
153
155
|
"katex": "^0.16.19",
|