diff --git a/app/src/routes/edit/share-options/exports/export-modal.tsx b/app/src/routes/edit/share-options/exports/export-modal.tsx index 67ece0ad..90af95f7 100644 --- a/app/src/routes/edit/share-options/exports/export-modal.tsx +++ b/app/src/routes/edit/share-options/exports/export-modal.tsx @@ -14,7 +14,7 @@ import { TreeView, InlineNotification } from '@carbon/react'; -import { Copy } from '@carbon/react/icons'; +import { Copy, Download } from '@carbon/react/icons'; import { css } from 'emotion'; import Editor, { useMonaco } from '@monaco-editor/react'; @@ -30,6 +30,7 @@ import { GlobalStateContext } from '../../../../context'; import { ExportImageComponent } from './export-image-component'; import { filenameToLanguage, getFragmentJsonExportString } from '@carbon-builder/sdk-react'; import JSONCrush from 'jsoncrush'; +import JSZip from 'jszip'; const exportCodeModalStyle = css` .cds--tab-content { @@ -88,6 +89,17 @@ const versionDropdownStyle = css` right: 1rem; `; +const addToZip = (parent: JSZip, items: any[]) => { + items.forEach(item => { + if (item.items && item.items.length) { + const folder = parent.folder(item.name); + addToZip(folder as JSZip, item.items); + } else { + parent.file(item.name, item.code); + } + }); +}; + const renderCodeTree = (nodes: any, path = '') => { if (!nodes) { return; @@ -109,7 +121,26 @@ const renderCodeTree = (nodes: any, path = '') => { renderIcon={icon} isExpanded={isExpanded} value={code} - label={name} + className={css`.cds--tree-node__icon { align-self: center; }`} + label={<> + {name} + { + items && items.length > 0 && +