abstract-sheet 0.0.3 → 0.0.4
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/README.md +1 -1
- package/lib/abstract-sheet/abstract-sheet-xsd.d.ts +1 -1
- package/lib/abstract-sheet/abstract-sheet-xsd.d.ts.map +1 -1
- package/lib/abstract-sheet/abstract-sheet-xsd.js +41 -45
- package/lib/abstract-sheet/abstract-sheet-xsd.js.map +1 -1
- package/lib/abstract-sheet/abstract-sheet.d.ts +22 -9
- package/lib/abstract-sheet/abstract-sheet.d.ts.map +1 -1
- package/lib/abstract-sheet/abstract-sheet.js.map +1 -1
- package/lib/abstract-sheet-exporters/_style.d.ts +3 -0
- package/lib/abstract-sheet-exporters/_style.d.ts.map +1 -0
- package/lib/abstract-sheet-exporters/_style.js +113 -0
- package/lib/abstract-sheet-exporters/_style.js.map +1 -0
- package/lib/abstract-sheet-exporters/_xlsx-sheet.d.ts +2 -3
- package/lib/abstract-sheet-exporters/_xlsx-sheet.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/_xlsx-sheet.js +14 -116
- package/lib/abstract-sheet-exporters/_xlsx-sheet.js.map +1 -1
- package/lib/abstract-sheet-exporters/csv.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/csv.js +2 -1
- package/lib/abstract-sheet-exporters/csv.js.map +1 -1
- package/lib/abstract-sheet-exporters/index.d.ts +1 -0
- package/lib/abstract-sheet-exporters/index.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/index.js +1 -0
- package/lib/abstract-sheet-exporters/index.js.map +1 -1
- package/lib/abstract-sheet-exporters/react.d.ts +5 -0
- package/lib/abstract-sheet-exporters/react.d.ts.map +1 -0
- package/lib/abstract-sheet-exporters/react.js +135 -0
- package/lib/abstract-sheet-exporters/react.js.map +1 -0
- package/lib/abstract-sheet-exporters/xlsx.d.ts.map +1 -1
- package/lib/abstract-sheet-exporters/xlsx.js +2 -1
- package/lib/abstract-sheet-exporters/xlsx.js.map +1 -1
- package/lib/abstract-sheet-xml/abstract-sheet-xml.d.ts +3 -1
- package/lib/abstract-sheet-xml/abstract-sheet-xml.d.ts.map +1 -1
- package/lib/abstract-sheet-xml/abstract-sheet-xml.js +33 -22
- package/lib/abstract-sheet-xml/abstract-sheet-xml.js.map +1 -1
- package/package.json +6 -2
- package/src/abstract-sheet/abstract-sheet-xsd.ts +41 -45
- package/src/abstract-sheet/abstract-sheet-xsd.xml +41 -45
- package/src/abstract-sheet/abstract-sheet.ts +10 -12
- package/src/abstract-sheet-exporters/_style.ts +113 -0
- package/src/abstract-sheet-exporters/_xlsx-sheet.ts +19 -121
- package/src/abstract-sheet-exporters/csv.ts +2 -1
- package/src/abstract-sheet-exporters/index.ts +1 -0
- package/src/abstract-sheet-exporters/react.tsx +185 -0
- package/src/abstract-sheet-exporters/xlsx.ts +2 -1
- package/src/abstract-sheet-xml/abstract-sheet-xml.ts +31 -22
|
@@ -3,43 +3,44 @@ import {
|
|
|
3
3
|
Cell,
|
|
4
4
|
ColInfo,
|
|
5
5
|
ColInfos,
|
|
6
|
-
|
|
6
|
+
Cells,
|
|
7
7
|
RowInfo,
|
|
8
8
|
RowInfos,
|
|
9
|
-
Rows,
|
|
10
9
|
Sheet,
|
|
11
|
-
Sheets,
|
|
12
10
|
Style,
|
|
13
11
|
Styles,
|
|
12
|
+
AbstractSheet,
|
|
14
13
|
} from "../abstract-sheet/abstract-sheet";
|
|
15
14
|
import { xsd } from "../abstract-sheet/abstract-sheet-xsd";
|
|
16
|
-
import {
|
|
15
|
+
import { parseMustacheXml, parseXsd, XmlElement } from "./mustache-xml";
|
|
17
16
|
|
|
18
|
-
export
|
|
17
|
+
export const abstractSheetXml = (template: string, data: any, partials: Record<string, string>): AbstractSheet =>
|
|
18
|
+
abstractSheetOfXml(parseMustacheXml(template, data, partials)[0]!) as AbstractSheet;
|
|
19
|
+
|
|
20
|
+
export function abstractSheetOfXml(el: XmlElement): unknown {
|
|
19
21
|
const children = Array<unknown>();
|
|
20
22
|
const childElements = Array<XmlElement>();
|
|
21
23
|
for (const child of el.children ?? []) {
|
|
22
24
|
if (child.tagName !== undefined) {
|
|
23
|
-
children.push(
|
|
25
|
+
children.push(abstractSheetOfXml(child));
|
|
24
26
|
childElements.push(child);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
29
|
+
|
|
27
30
|
switch (el.tagName) {
|
|
28
31
|
case "AbstractSheet":
|
|
29
32
|
let styles: Styles | undefined = undefined;
|
|
30
|
-
|
|
33
|
+
const sheets: Array<Sheet> = [];
|
|
31
34
|
childElements.forEach((childEl, i) => {
|
|
32
|
-
if (childEl.tagName === "
|
|
33
|
-
sheets
|
|
35
|
+
if (childEl.tagName === "Sheet") {
|
|
36
|
+
sheets.push(children[i] as Sheet);
|
|
34
37
|
} else if (childEl.tagName === "Styles") {
|
|
35
38
|
styles = children[i] as Styles;
|
|
36
39
|
}
|
|
37
40
|
});
|
|
38
|
-
return { styles, sheets };
|
|
39
|
-
case "Sheets":
|
|
40
|
-
return children as Sheets;
|
|
41
|
+
return { styles, sheets } satisfies AbstractSheet;
|
|
41
42
|
case "Sheet": {
|
|
42
|
-
|
|
43
|
+
const cells: Array<Cells> = [];
|
|
43
44
|
let colInfo: ColInfos | undefined = undefined;
|
|
44
45
|
let rowInfo: RowInfos | undefined = undefined;
|
|
45
46
|
childElements.forEach((childEl, i) => {
|
|
@@ -47,16 +48,17 @@ export function abstractSheetXml(el: XmlElement): unknown {
|
|
|
47
48
|
colInfo = children[i] as ColInfos;
|
|
48
49
|
} else if (childEl.tagName === "RowInfos") {
|
|
49
50
|
rowInfo = children[i] as RowInfos;
|
|
50
|
-
} else if (childEl.tagName === "
|
|
51
|
-
|
|
51
|
+
} else if (childEl.tagName === "Cells") {
|
|
52
|
+
cells.push(children[i] as Cells);
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
return {
|
|
55
56
|
name: ((el.attributes as Partial<Record<keyof Sheet, unknown>>)?.name ?? "") as string,
|
|
56
|
-
|
|
57
|
+
cells,
|
|
57
58
|
colInfo,
|
|
58
59
|
rowInfo,
|
|
59
|
-
|
|
60
|
+
direction: ((el.attributes as Partial<Record<keyof Sheet, unknown>>)?.direction ?? "") as Sheet["direction"],
|
|
61
|
+
} satisfies Sheet;
|
|
60
62
|
}
|
|
61
63
|
case "ColInfos":
|
|
62
64
|
return children as ColInfos;
|
|
@@ -66,12 +68,19 @@ export function abstractSheetXml(el: XmlElement): unknown {
|
|
|
66
68
|
return children as RowInfos;
|
|
67
69
|
case "RowInfo":
|
|
68
70
|
return el.attributes as RowInfo;
|
|
69
|
-
case "
|
|
70
|
-
return children as
|
|
71
|
-
case "Row":
|
|
72
|
-
return children as Row;
|
|
71
|
+
case "Cells":
|
|
72
|
+
return children as Cells;
|
|
73
73
|
case "Cell": {
|
|
74
|
-
|
|
74
|
+
const styles = el.attributes.styles?.split(",");
|
|
75
|
+
if (el.attributes.number !== undefined) {
|
|
76
|
+
return { ...el.attributes, type: "number", value: el.attributes.number, styles } as Cell;
|
|
77
|
+
} else if (el.attributes.bool !== undefined) {
|
|
78
|
+
return { ...el.attributes, type: "boolean", value: el.attributes.boolean, styles } as Cell;
|
|
79
|
+
} else if (el.attributes.date !== undefined) {
|
|
80
|
+
return { ...el.attributes, type: "date", value: el.attributes.date, styles } as Cell;
|
|
81
|
+
} else {
|
|
82
|
+
return { ...el.attributes, type: "string", value: el.attributes.text, styles } as Cell;
|
|
83
|
+
}
|
|
75
84
|
}
|
|
76
85
|
case "Styles":
|
|
77
86
|
return children as Styles;
|