|
| 1 | +import {JSExcel} from "./Types"; |
| 2 | +import {___JSE_XLSX___Directory, ___JSE_XLSX___File, ___JSE_XLSX___FileContent, ___JSE_XLSX___Node} from "./xlsx"; |
| 3 | +import { |
| 4 | + Relationship_Target_App, |
| 5 | + Relationship_Target_Core, |
| 6 | + Relationship_Target_Custom, |
| 7 | + Relationship_Target_Workbook, |
| 8 | + Relationship_Type_App, |
| 9 | + Relationship_Type_Core, |
| 10 | + Relationship_Type_Custom, |
| 11 | + Relationship_Type_Workbook, |
| 12 | + Xmlns_RelationShips |
| 13 | +} from "./Internals"; |
| 14 | + |
| 15 | +const fileProps: any = { |
| 16 | + name: null, |
| 17 | + extension: ".rels", |
| 18 | + version: "1.0", |
| 19 | + encoding: "UTF-8", |
| 20 | + standalone: true, |
| 21 | + nodes: { |
| 22 | + Relationships: "Relationships", |
| 23 | + Relationship: "Relationship" |
| 24 | + }, |
| 25 | + keys: { |
| 26 | + xmlns: "xmlns", |
| 27 | + Id: "Id", |
| 28 | + Type: "Type", |
| 29 | + Target: "Target" |
| 30 | + }, |
| 31 | + values: { |
| 32 | + Id_rId3: "rId3", |
| 33 | + Id_rId2: "rId2", |
| 34 | + Id_rId1: "rId1", |
| 35 | + Id_rId4: "rId4" |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +const directorProps: any = { |
| 40 | + name: "_rels", |
| 41 | + files: {rels: {...fileProps}} |
| 42 | +}; |
| 43 | + |
| 44 | +export default (excel: JSExcel): ___JSE_XLSX___Directory => ({ |
| 45 | + directoryName: directorProps.name, |
| 46 | + content: getRelDirectoryFiles(excel) |
| 47 | +}); |
| 48 | + |
| 49 | +function getRelDirectoryFiles(excel: JSExcel): ___JSE_XLSX___File { |
| 50 | + return { |
| 51 | + fileName: fileProps.name, |
| 52 | + fileExtension: fileProps.extension, |
| 53 | + fileContent: getRelsNodes(excel) |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +function getRelsNodes(excel: JSExcel): ___JSE_XLSX___FileContent { |
| 58 | + return { |
| 59 | + xml: { |
| 60 | + version: fileProps.version, |
| 61 | + encoding: fileProps.encoding, |
| 62 | + standalone: fileProps.standalone |
| 63 | + }, |
| 64 | + content: { |
| 65 | + name: fileProps.nodes.Relationships, |
| 66 | + values: [{key: fileProps.keys.xmlns, value: Xmlns_RelationShips}], |
| 67 | + content: [ |
| 68 | + { |
| 69 | + name: fileProps.nodes.Relationship, |
| 70 | + values: [ |
| 71 | + {key: fileProps.keys.Id, value: fileProps.values.Id_rId3}, |
| 72 | + {key: fileProps.keys.Type, value: Relationship_Type_App}, |
| 73 | + {key: fileProps.keys.Target, value: Relationship_Target_App} |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + name: fileProps.nodes.Relationship, |
| 78 | + values: [ |
| 79 | + {key: fileProps.keys.Id, value: fileProps.values.Id_rId2}, |
| 80 | + {key: fileProps.keys.Type, value: Relationship_Type_Core}, |
| 81 | + {key: fileProps.keys.Target, value: Relationship_Target_Core} |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + name: fileProps.nodes.Relationship, |
| 86 | + values: [ |
| 87 | + {key: fileProps.keys.Id, value: fileProps.values.Id_rId1}, |
| 88 | + {key: fileProps.keys.Type, value: Relationship_Type_Workbook}, |
| 89 | + {key: fileProps.keys.Target, value: Relationship_Target_Workbook} |
| 90 | + ] |
| 91 | + }, |
| 92 | + // ...getCustomRelationshipNode(excel) TODO: finish when file custom props are implemented |
| 93 | + ] |
| 94 | + } |
| 95 | + }; |
| 96 | +} |
| 97 | + |
| 98 | +function getCustomRelationshipNode(excel: JSExcel): ___JSE_XLSX___Node { |
| 99 | + //TODO: return if custom values are provided |
| 100 | + return { |
| 101 | + name: fileProps.nodes.Relationship, |
| 102 | + values: [ |
| 103 | + {key: fileProps.keys.Id, value: fileProps.values.Id_rId4}, |
| 104 | + {key: fileProps.keys.Type, value: Relationship_Type_Custom}, |
| 105 | + {key: fileProps.keys.Target, value: Relationship_Target_Custom} |
| 106 | + ] |
| 107 | + }; |
| 108 | +} |
0 commit comments