import { ___JSE_XLSX___File , ___JSE_XLSX___FileContent , ___JSE_XLSX___Node } from "../api/xlsx" ; import { EXTENSION_RELS_SCHEMA , EXTENSION_XML_SCHEMA , PART_NAME_DOC_PROPS_APP , PART_NAME_DOC_PROPS_CORE , PART_NAME_DOC_PROPS_CUSTOM , PART_NAME_XL_SHARED_STRINGS , PART_NAME_XL_WORKSHEET , PART_NAME_XL_STYLES , PART_NAME_XL_THEME , PART_NAME_XL_WORKBOOK , XMLNS_CONTENT_TYPES , DEFAULT_XML_VERSION , ENCODING_UTF_8 , DEFAULT_STAND_ALONE } from "../api/Internals" ; import { JSESheet , JSExcel } from "../Types" ; import { DEFAULT_FILE_EXTENSION } from "../api/constants" ; import { cleanAlphaNumericString } from "../util/Helper" ; const fileProps = { name : "[Content_Types]" , extension : DEFAULT_FILE_EXTENSION , version : DEFAULT_XML_VERSION , encoding : ENCODING_UTF_8 , standalone : DEFAULT_STAND_ALONE , nodes : { Types : "Types" , Default : "Default" , Override : "Override" } , keys : { xmlns : "xmlns" , Extension : "Extension" , ContentType : "ContentType" , PartName : "PartName" } , values : { rels : "rels" , xml : "xml" , PartName_xml : "/xl/workbook.xml" } } ; export default ( excel ) : ___JSE_XLSX___File => ( { fileName : fileProps . name , fileExtension : fileProps . extension , fileContent : getContentTypeNodes ( excel ) } ) ; function getContentTypeNodes ( excel ) { return { xml : { version : fileProps . version , encoding : fileProps . encoding , standalone : fileProps . standalone } , content : { name : fileProps . nodes . Types , values : [ { key : fileProps . keys . xmlns , value : XMLNS_CONTENT_TYPES } ] , content : [ { name : fileProps . nodes . Default , values : [ { key : fileProps . keys . Extension , value : fileProps . values . rels } , { key : fileProps . keys . ContentType , value : EXTENSION_RELS_SCHEMA } ] } , { name : fileProps . nodes . Default , values : [ { key : fileProps . keys . Extension , value : fileProps . values . xml } , { key : fileProps . keys . ContentType , value : EXTENSION_XML_SCHEMA } ] } , { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : fileProps . values . PartName_xml } , { key : fileProps . keys . ContentType , value : PART_NAME_XL_WORKBOOK } ] } , ... getWorkSheetsOverrides ( excel ) , ... getThemesOverrides ( excel ) , ... getStylesOverrides ( excel ) , ... getSharedStringsOverrides ( excel ) , ... getPropsOverrides ( excel ) , ] } } ; } function getWorkSheetsOverrides ( excel ) { const partNameOverride = "/xl/worksheets/" ; return excel . sheets . map ( ( sheet ) => ( { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : `${ partNameOverride }${ cleanAlphaNumericString ( sheet . name ) }${ fileProps . extension }` } , { key : fileProps . keys . ContentType , value : PART_NAME_XL_WORKSHEET } ] } ) ) ; } function getThemesOverrides ( excel ) { const partNameOverride = "/xl/theme/" ; return [ { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : `${ partNameOverride }theme1${ fileProps . extension }` } , { key : fileProps . keys . ContentType , value : PART_NAME_XL_THEME } ] } ] ; } function getStylesOverrides ( excel ) { const partNameOverride = "/xl/styles" ; return [ { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : `${ partNameOverride }${ fileProps . extension }` } , { key : fileProps . keys . ContentType , value : PART_NAME_XL_STYLES } ] } ] ; } function getSharedStringsOverrides ( excel ) { const partNameOverride = "/xl/sharedStrings" ; return [ { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : `${ partNameOverride }${ fileProps . extension }` } , { key : fileProps . keys . ContentType , value : PART_NAME_XL_SHARED_STRINGS } ] } ] ; } function getPropsOverrides ( excel ) { const partNameOverride = "/docProps/" ; return [ { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : `${ partNameOverride }core${ fileProps . extension }` } , { key : fileProps . keys . ContentType , value : PART_NAME_DOC_PROPS_CORE } ] } , { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : `${ partNameOverride }app${ fileProps . extension }` } , { key : fileProps . keys . ContentType , value : PART_NAME_DOC_PROPS_APP } ] } , ] ; } function getCustomPropsOverrider ( excel ) { const partNameOverride = "/docProps/custom" ; return { name : fileProps . nodes . Override , values : [ { key : fileProps . keys . PartName , value : `${ partNameOverride }${ fileProps . extension }` } , { key : fileProps . keys . ContentType , value : PART_NAME_DOC_PROPS_CUSTOM } ] } ; }