odf.js 1.13.2 → 2.0.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/README.md +15 -3
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +6 -3
- package/dist/ns.cjs +2 -1
- package/dist/ns.d.cts +1 -0
- package/dist/ns.d.ts +1 -0
- package/dist/ns.js +2 -1
- package/dist/typed/draw/shapes.cjs +71 -27
- package/dist/typed/draw/shapes.d.cts +4 -1
- package/dist/typed/draw/shapes.d.ts +4 -1
- package/dist/typed/draw/shapes.js +71 -27
- package/dist/typed/formula/read.cjs +14 -0
- package/dist/typed/formula/read.d.cts +3 -2
- package/dist/typed/formula/read.d.ts +3 -2
- package/dist/typed/formula/read.js +14 -1
- package/dist/typed/odb/form.cjs +85 -0
- package/dist/typed/odb/form.d.cts +31 -0
- package/dist/typed/odb/form.d.ts +31 -0
- package/dist/typed/odb/form.js +84 -0
- package/dist/typed/odb/read.cjs +60 -23
- package/dist/typed/odb/read.d.cts +15 -4
- package/dist/typed/odb/read.d.ts +15 -4
- package/dist/typed/odb/read.js +60 -24
- package/dist/typed/odb/report.cjs +161 -0
- package/dist/typed/odb/report.d.cts +48 -0
- package/dist/typed/odb/report.d.ts +48 -0
- package/dist/typed/odb/report.js +160 -0
- package/dist/typed/odb/subdocument.cjs +16 -0
- package/dist/typed/odb/subdocument.d.cts +8 -0
- package/dist/typed/odb/subdocument.d.ts +8 -0
- package/dist/typed/odb/subdocument.js +15 -0
- package/dist/typed/ods/read.cjs +8 -0
- package/dist/typed/ods/read.js +9 -1
- package/dist/typed/shared/table.cjs +94 -7
- package/dist/typed/shared/table.d.cts +9 -2
- package/dist/typed/shared/table.d.ts +9 -2
- package/dist/typed/shared/table.js +94 -8
- package/package.json +1 -1
|
@@ -79,16 +79,20 @@ function readOwnTransformFunctions(element) {
|
|
|
79
79
|
const value = attrValue(element, "draw:transform");
|
|
80
80
|
return value === void 0 ? [] : parseOdfTransform(value);
|
|
81
81
|
}
|
|
82
|
-
function walkDrawShapes(children, groupFunctions, pkg, out) {
|
|
82
|
+
function walkDrawShapes(children, groupFunctions, pkg, out, indexState = { next: 0 }) {
|
|
83
83
|
for (const node of children) {
|
|
84
84
|
if (node.type !== "element") continue;
|
|
85
85
|
if (node.tag === "draw:frame") {
|
|
86
|
+
const zIndex = paintOrderKey(node, indexState);
|
|
86
87
|
const shape = readDrawFrame(node, groupFunctions, pkg);
|
|
87
|
-
if (shape !== void 0) out.push(
|
|
88
|
+
if (shape !== void 0) out.push({
|
|
89
|
+
...shape,
|
|
90
|
+
paintOrder: zIndex
|
|
91
|
+
});
|
|
88
92
|
} else if (node.tag === "draw:g") {
|
|
89
93
|
const ownFunctions = readOwnTransformFunctions(node);
|
|
90
94
|
const nested = ownFunctions.length === 0 ? groupFunctions : [...ownFunctions, ...groupFunctions];
|
|
91
|
-
walkDrawShapes(node.children, nested, pkg, out);
|
|
95
|
+
walkDrawShapes(node.children, nested, pkg, out, indexState);
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
}
|
|
@@ -96,7 +100,9 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
96
100
|
const styleName = attrValue(element, "draw:style-name");
|
|
97
101
|
const { elements } = resolveStyleElementChain(styleName, "graphic", pkg);
|
|
98
102
|
let fill;
|
|
103
|
+
let fillRule;
|
|
99
104
|
let stroke;
|
|
105
|
+
let strokeStyle;
|
|
100
106
|
for (const styleElement of elements) {
|
|
101
107
|
const props = childrenWithTag(styleElement, "style:graphic-properties")[0];
|
|
102
108
|
if (props === void 0) continue;
|
|
@@ -106,8 +112,15 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
106
112
|
const parsedFill = fillColorValue === void 0 ? void 0 : parseOdfColor(fillColorValue);
|
|
107
113
|
if (parsedFill !== void 0) fill = parsedFill;
|
|
108
114
|
}
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
const fillRuleValue = attrValue(props, "svg:fill-rule");
|
|
116
|
+
if (fillRuleValue === "nonzero" || fillRuleValue === "evenodd") fillRule = fillRuleValue;
|
|
117
|
+
const strokeMode = attrValue(props, "draw:stroke");
|
|
118
|
+
if (strokeMode === "none") {
|
|
119
|
+
stroke = void 0;
|
|
120
|
+
strokeStyle = void 0;
|
|
121
|
+
} else {
|
|
122
|
+
if (strokeMode === "dash") strokeStyle = "dashed";
|
|
123
|
+
else if (strokeMode === "solid") strokeStyle = "solid";
|
|
111
124
|
const strokeColorValue = attrValue(props, "svg:stroke-color");
|
|
112
125
|
const strokeWidthValue = attrValue(props, "svg:stroke-width");
|
|
113
126
|
const strokeColor = strokeColorValue === void 0 ? void 0 : parseOdfColor(strokeColorValue);
|
|
@@ -120,32 +133,38 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
120
133
|
}
|
|
121
134
|
return {
|
|
122
135
|
fill,
|
|
123
|
-
|
|
136
|
+
fillRule,
|
|
137
|
+
stroke: stroke === void 0 || strokeStyle === void 0 ? stroke : {
|
|
138
|
+
...stroke,
|
|
139
|
+
style: strokeStyle
|
|
140
|
+
}
|
|
124
141
|
};
|
|
125
142
|
}
|
|
126
|
-
function
|
|
143
|
+
function resolveVectorGeometry(element, groupFunctions) {
|
|
127
144
|
const geometry = resolveOdfShapeGeometry(element);
|
|
128
145
|
if (geometry === void 0) return;
|
|
129
|
-
return composeOdfGroupTransform(groupFunctions, geometry)
|
|
146
|
+
return composeOdfGroupTransform(groupFunctions, geometry);
|
|
130
147
|
}
|
|
131
148
|
function readDrawRectVector(element, groupFunctions, pkg) {
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
149
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
150
|
+
if (geometry === void 0) return;
|
|
134
151
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
135
152
|
return {
|
|
136
153
|
kind: "rect",
|
|
137
|
-
frame,
|
|
154
|
+
frame: geometry.frame,
|
|
155
|
+
rotationDeg: geometry.rotationDeg,
|
|
138
156
|
fill,
|
|
139
157
|
stroke
|
|
140
158
|
};
|
|
141
159
|
}
|
|
142
160
|
function readDrawEllipseVector(element, groupFunctions, pkg) {
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
161
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
162
|
+
if (geometry === void 0) return;
|
|
145
163
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
146
164
|
return {
|
|
147
165
|
kind: "ellipse",
|
|
148
|
-
frame,
|
|
166
|
+
frame: geometry.frame,
|
|
167
|
+
rotationDeg: geometry.rotationDeg,
|
|
149
168
|
fill,
|
|
150
169
|
stroke
|
|
151
170
|
};
|
|
@@ -165,8 +184,9 @@ function readDrawLineVector(element, groupFunctions, pkg) {
|
|
|
165
184
|
};
|
|
166
185
|
}
|
|
167
186
|
function readDrawPathVector(element, groupFunctions, pkg) {
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
187
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
188
|
+
if (geometry === void 0) return;
|
|
189
|
+
const frame = geometry.frame;
|
|
170
190
|
const viewBoxValue = attrValue(element, "svg:viewBox");
|
|
171
191
|
const viewBox = viewBoxValue === void 0 ? void 0 : parseOdfViewBox(viewBoxValue);
|
|
172
192
|
if (viewBox === void 0) return;
|
|
@@ -182,12 +202,14 @@ function readDrawPathVector(element, groupFunctions, pkg) {
|
|
|
182
202
|
}
|
|
183
203
|
if (rawSubpaths.length === 0) return;
|
|
184
204
|
const subpaths = buildOdfSubpaths(rawSubpaths, viewBox, frame);
|
|
185
|
-
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
205
|
+
const { fill, fillRule, stroke } = readOdfFillAndStroke(element, pkg);
|
|
186
206
|
return {
|
|
187
207
|
kind: "path",
|
|
188
208
|
frame,
|
|
209
|
+
rotationDeg: geometry.rotationDeg,
|
|
189
210
|
subpaths,
|
|
190
211
|
fill,
|
|
212
|
+
fillRule,
|
|
191
213
|
stroke
|
|
192
214
|
};
|
|
193
215
|
}
|
|
@@ -200,12 +222,13 @@ function readCustomShapeVector(element, groupFunctions, pkg) {
|
|
|
200
222
|
const geometryElement = childrenWithTag(element, "draw:enhanced-geometry")[0];
|
|
201
223
|
const type = geometryElement === void 0 ? void 0 : attrValue(geometryElement, "draw:type");
|
|
202
224
|
if (type === void 0 || !RECOGNIZED_CUSTOM_SHAPE_PRESETS.has(type)) return;
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
225
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
226
|
+
if (geometry === void 0) return;
|
|
205
227
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
206
228
|
return {
|
|
207
229
|
kind: type === "ellipse" ? "ellipse" : "rect",
|
|
208
|
-
frame,
|
|
230
|
+
frame: geometry.frame,
|
|
231
|
+
rotationDeg: geometry.rotationDeg,
|
|
209
232
|
fill,
|
|
210
233
|
stroke
|
|
211
234
|
};
|
|
@@ -246,7 +269,10 @@ function walkDrawPageContent(children, groupFunctions, pkg, indexState, shapesOu
|
|
|
246
269
|
const zIndex = paintOrderKey(node, indexState);
|
|
247
270
|
const shape = readDrawFrame(node, groupFunctions, pkg);
|
|
248
271
|
if (shape !== void 0) shapesOut.push({
|
|
249
|
-
value:
|
|
272
|
+
value: {
|
|
273
|
+
...shape,
|
|
274
|
+
paintOrder: zIndex
|
|
275
|
+
},
|
|
250
276
|
zIndex
|
|
251
277
|
});
|
|
252
278
|
} else if (node.tag === "draw:g") {
|
|
@@ -257,41 +283,59 @@ function walkDrawPageContent(children, groupFunctions, pkg, indexState, shapesOu
|
|
|
257
283
|
const zIndex = paintOrderKey(node, indexState);
|
|
258
284
|
const vector = readDrawRectVector(node, groupFunctions, pkg);
|
|
259
285
|
if (vector !== void 0) vectorsOut.push({
|
|
260
|
-
value:
|
|
286
|
+
value: {
|
|
287
|
+
...vector,
|
|
288
|
+
paintOrder: zIndex
|
|
289
|
+
},
|
|
261
290
|
zIndex
|
|
262
291
|
});
|
|
263
292
|
} else if (node.tag === "draw:ellipse" || node.tag === "draw:circle") {
|
|
264
293
|
const zIndex = paintOrderKey(node, indexState);
|
|
265
294
|
const vector = readDrawEllipseVector(node, groupFunctions, pkg);
|
|
266
295
|
if (vector !== void 0) vectorsOut.push({
|
|
267
|
-
value:
|
|
296
|
+
value: {
|
|
297
|
+
...vector,
|
|
298
|
+
paintOrder: zIndex
|
|
299
|
+
},
|
|
268
300
|
zIndex
|
|
269
301
|
});
|
|
270
302
|
} else if (node.tag === "draw:line") {
|
|
271
303
|
const zIndex = paintOrderKey(node, indexState);
|
|
272
304
|
const vector = readDrawLineVector(node, groupFunctions, pkg);
|
|
273
305
|
if (vector !== void 0) vectorsOut.push({
|
|
274
|
-
value:
|
|
306
|
+
value: {
|
|
307
|
+
...vector,
|
|
308
|
+
paintOrder: zIndex
|
|
309
|
+
},
|
|
275
310
|
zIndex
|
|
276
311
|
});
|
|
277
312
|
} else if (node.tag === "draw:path" || node.tag === "draw:polygon" || node.tag === "draw:polyline") {
|
|
278
313
|
const zIndex = paintOrderKey(node, indexState);
|
|
279
314
|
const vector = readDrawPathVector(node, groupFunctions, pkg);
|
|
280
315
|
if (vector !== void 0) vectorsOut.push({
|
|
281
|
-
value:
|
|
316
|
+
value: {
|
|
317
|
+
...vector,
|
|
318
|
+
paintOrder: zIndex
|
|
319
|
+
},
|
|
282
320
|
zIndex
|
|
283
321
|
});
|
|
284
322
|
} else if (node.tag === "draw:custom-shape") {
|
|
285
323
|
const zIndex = paintOrderKey(node, indexState);
|
|
286
324
|
const vector = readCustomShapeVector(node, groupFunctions, pkg);
|
|
287
325
|
if (vector !== void 0) vectorsOut.push({
|
|
288
|
-
value:
|
|
326
|
+
value: {
|
|
327
|
+
...vector,
|
|
328
|
+
paintOrder: zIndex
|
|
329
|
+
},
|
|
289
330
|
zIndex
|
|
290
331
|
});
|
|
291
332
|
else {
|
|
292
333
|
const shape = readCustomShapeAsTextShape(node, groupFunctions, pkg);
|
|
293
334
|
if (shape !== void 0) shapesOut.push({
|
|
294
|
-
value:
|
|
335
|
+
value: {
|
|
336
|
+
...shape,
|
|
337
|
+
paintOrder: zIndex
|
|
338
|
+
},
|
|
295
339
|
zIndex
|
|
296
340
|
});
|
|
297
341
|
}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_xml_entities = require("../../xml/entities.cjs");
|
|
3
3
|
const require_xml_query = require("../../xml/query.cjs");
|
|
4
4
|
const require_typed_shared_metadata = require("../shared/metadata.cjs");
|
|
5
|
+
let document_schema_js = require("document-schema.js");
|
|
5
6
|
//#region src/typed/formula/read.ts
|
|
6
7
|
const CONTENT_PART = "content.xml";
|
|
7
8
|
const MATH_ROOT_TAGS = ["math", "math:math"];
|
|
@@ -44,5 +45,18 @@ function readOdfFormula(pkg) {
|
|
|
44
45
|
metadata
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
function readOdfFormulaDocument(pkg) {
|
|
49
|
+
const { mathml, starMath, metadata } = readOdfFormula(pkg);
|
|
50
|
+
return {
|
|
51
|
+
kind: "formula",
|
|
52
|
+
formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
|
|
53
|
+
metadata,
|
|
54
|
+
formula: starMath === void 0 ? { mathml } : {
|
|
55
|
+
mathml,
|
|
56
|
+
starMath
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
47
60
|
//#endregion
|
|
48
61
|
exports.readOdfFormula = readOdfFormula;
|
|
62
|
+
exports.readOdfFormulaDocument = readOdfFormulaDocument;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as XmlNode } from "../../node-CkBWRjNR.cjs";
|
|
2
2
|
import { Package } from "../../model/package.cjs";
|
|
3
|
-
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
import { ContentDocument, LayoutMetadata } from "document-schema.js";
|
|
4
4
|
//#region src/typed/formula/read.d.ts
|
|
5
5
|
interface OdfFormulaDocument {
|
|
6
6
|
starMath?: string;
|
|
@@ -8,5 +8,6 @@ interface OdfFormulaDocument {
|
|
|
8
8
|
metadata: LayoutMetadata;
|
|
9
9
|
}
|
|
10
10
|
declare function readOdfFormula(pkg: Package): OdfFormulaDocument;
|
|
11
|
+
declare function readOdfFormulaDocument(pkg: Package): ContentDocument;
|
|
11
12
|
//#endregion
|
|
12
|
-
export { OdfFormulaDocument, readOdfFormula };
|
|
13
|
+
export { OdfFormulaDocument, readOdfFormula, readOdfFormulaDocument };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as XmlNode } from "../../node-CkBWRjNR.js";
|
|
2
2
|
import { Package } from "../../model/package.js";
|
|
3
|
-
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
import { ContentDocument, LayoutMetadata } from "document-schema.js";
|
|
4
4
|
//#region src/typed/formula/read.d.ts
|
|
5
5
|
interface OdfFormulaDocument {
|
|
6
6
|
starMath?: string;
|
|
@@ -8,5 +8,6 @@ interface OdfFormulaDocument {
|
|
|
8
8
|
metadata: LayoutMetadata;
|
|
9
9
|
}
|
|
10
10
|
declare function readOdfFormula(pkg: Package): OdfFormulaDocument;
|
|
11
|
+
declare function readOdfFormulaDocument(pkg: Package): ContentDocument;
|
|
11
12
|
//#endregion
|
|
12
|
-
export { OdfFormulaDocument, readOdfFormula };
|
|
13
|
+
export { OdfFormulaDocument, readOdfFormula, readOdfFormulaDocument };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { decodeXmlText } from "../../xml/entities.js";
|
|
2
2
|
import { attrValue, elementsWithTag, rootElement } from "../../xml/query.js";
|
|
3
3
|
import { readOdfMetadata } from "../shared/metadata.js";
|
|
4
|
+
import { CONTENT_FORMAT_VERSION } from "document-schema.js";
|
|
4
5
|
//#region src/typed/formula/read.ts
|
|
5
6
|
const CONTENT_PART = "content.xml";
|
|
6
7
|
const MATH_ROOT_TAGS = ["math", "math:math"];
|
|
@@ -43,5 +44,17 @@ function readOdfFormula(pkg) {
|
|
|
43
44
|
metadata
|
|
44
45
|
};
|
|
45
46
|
}
|
|
47
|
+
function readOdfFormulaDocument(pkg) {
|
|
48
|
+
const { mathml, starMath, metadata } = readOdfFormula(pkg);
|
|
49
|
+
return {
|
|
50
|
+
kind: "formula",
|
|
51
|
+
formatVersion: CONTENT_FORMAT_VERSION,
|
|
52
|
+
metadata,
|
|
53
|
+
formula: starMath === void 0 ? { mathml } : {
|
|
54
|
+
mathml,
|
|
55
|
+
starMath
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
46
59
|
//#endregion
|
|
47
|
-
export { readOdfFormula };
|
|
60
|
+
export { readOdfFormula, readOdfFormulaDocument };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_entities = require("../../xml/entities.cjs");
|
|
3
|
+
const require_xml_query = require("../../xml/query.cjs");
|
|
4
|
+
const require_typed_odt_read = require("../odt/read.cjs");
|
|
5
|
+
const require_typed_odb_read = require("./read.cjs");
|
|
6
|
+
const require_typed_odb_subdocument = require("./subdocument.cjs");
|
|
7
|
+
//#region src/typed/odb/form.ts
|
|
8
|
+
const CONTENT_PART = "content.xml";
|
|
9
|
+
const FORM_ELEMENT_TAG = "form:form";
|
|
10
|
+
const FORM_PROPERTIES_TAG = "form:properties";
|
|
11
|
+
const FORM_TAG_PREFIX = "form:";
|
|
12
|
+
function formAttr(element, name) {
|
|
13
|
+
const raw = require_xml_query.attrValue(element, name);
|
|
14
|
+
return raw === void 0 ? void 0 : require_xml_entities.decodeXmlText(raw);
|
|
15
|
+
}
|
|
16
|
+
function readControl(element) {
|
|
17
|
+
const control = {
|
|
18
|
+
tag: element.tag,
|
|
19
|
+
controls: readControls(element)
|
|
20
|
+
};
|
|
21
|
+
const name = formAttr(element, "form:name");
|
|
22
|
+
if (name !== void 0) control.name = name;
|
|
23
|
+
const controlImplementation = formAttr(element, "form:control-implementation");
|
|
24
|
+
if (controlImplementation !== void 0) control.controlImplementation = controlImplementation;
|
|
25
|
+
const dataField = formAttr(element, "form:data-field");
|
|
26
|
+
if (dataField !== void 0) control.dataField = dataField;
|
|
27
|
+
const id = formAttr(element, "form:id");
|
|
28
|
+
if (id !== void 0) control.id = id;
|
|
29
|
+
const label = formAttr(element, "form:label");
|
|
30
|
+
if (label !== void 0) control.label = label;
|
|
31
|
+
return control;
|
|
32
|
+
}
|
|
33
|
+
function readControls(container) {
|
|
34
|
+
const controls = [];
|
|
35
|
+
for (const child of container.children) {
|
|
36
|
+
if (child.type !== "element" || !child.tag.startsWith(FORM_TAG_PREFIX)) continue;
|
|
37
|
+
if (child.tag === FORM_ELEMENT_TAG || child.tag === FORM_PROPERTIES_TAG) continue;
|
|
38
|
+
controls.push(readControl(child));
|
|
39
|
+
}
|
|
40
|
+
return controls;
|
|
41
|
+
}
|
|
42
|
+
function readFormDefinition(element) {
|
|
43
|
+
const subForms = [];
|
|
44
|
+
for (const child of element.children) if (child.type === "element" && child.tag === FORM_ELEMENT_TAG) subForms.push(readFormDefinition(child));
|
|
45
|
+
const definition = {
|
|
46
|
+
controls: readControls(element),
|
|
47
|
+
subForms
|
|
48
|
+
};
|
|
49
|
+
const name = formAttr(element, "form:name");
|
|
50
|
+
if (name !== void 0) definition.name = name;
|
|
51
|
+
const command = formAttr(element, "form:command");
|
|
52
|
+
if (command !== void 0) definition.command = command;
|
|
53
|
+
const commandType = formAttr(element, "form:command-type");
|
|
54
|
+
if (commandType !== void 0) definition.commandType = commandType;
|
|
55
|
+
const datasource = formAttr(element, "form:datasource");
|
|
56
|
+
if (datasource !== void 0) definition.datasource = datasource;
|
|
57
|
+
const filter = formAttr(element, "form:filter");
|
|
58
|
+
if (filter !== void 0) definition.filter = filter;
|
|
59
|
+
const order = formAttr(element, "form:order");
|
|
60
|
+
if (order !== void 0) definition.order = order;
|
|
61
|
+
return definition;
|
|
62
|
+
}
|
|
63
|
+
function readFormDefinitions(contentRoot) {
|
|
64
|
+
const body = contentRoot === void 0 ? void 0 : require_xml_query.findChildElement(contentRoot.children, "office:body");
|
|
65
|
+
const text = body === void 0 ? void 0 : require_xml_query.findChildElement(body.children, "office:text");
|
|
66
|
+
const forms = text === void 0 ? void 0 : require_xml_query.findChildElement(text.children, "office:forms");
|
|
67
|
+
if (forms === void 0) return [];
|
|
68
|
+
const definitions = [];
|
|
69
|
+
for (const child of forms.children) if (child.type === "element" && child.tag === FORM_ELEMENT_TAG) definitions.push(readFormDefinition(child));
|
|
70
|
+
return definitions;
|
|
71
|
+
}
|
|
72
|
+
function readOdbForm(pkg, formName) {
|
|
73
|
+
const component = require_typed_odb_read.resolveOdbComponent(pkg, "form", formName);
|
|
74
|
+
const subPackage = require_typed_odb_subdocument.subDocumentPackage(pkg, component.href);
|
|
75
|
+
const contentPart = subPackage.parts[CONTENT_PART];
|
|
76
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdbForm: form "${formName}" sub-document ${component.href}/${CONTENT_PART} is not an XML part`);
|
|
77
|
+
return {
|
|
78
|
+
name: component.name,
|
|
79
|
+
href: component.href,
|
|
80
|
+
document: require_typed_odt_read.readOdt(subPackage),
|
|
81
|
+
forms: readFormDefinitions(require_xml_query.rootElement(contentPart.nodes))
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.readOdbForm = readOdbForm;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Package } from "../../model/package.cjs";
|
|
2
|
+
import { OdtDocument } from "../odt/read.cjs";
|
|
3
|
+
//#region src/typed/odb/form.d.ts
|
|
4
|
+
interface OdbFormControl {
|
|
5
|
+
tag: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
controlImplementation?: string;
|
|
8
|
+
dataField?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
controls: OdbFormControl[];
|
|
12
|
+
}
|
|
13
|
+
interface OdbFormDefinition {
|
|
14
|
+
name?: string;
|
|
15
|
+
command?: string;
|
|
16
|
+
commandType?: string;
|
|
17
|
+
datasource?: string;
|
|
18
|
+
filter?: string;
|
|
19
|
+
order?: string;
|
|
20
|
+
controls: OdbFormControl[];
|
|
21
|
+
subForms: OdbFormDefinition[];
|
|
22
|
+
}
|
|
23
|
+
interface OdbForm {
|
|
24
|
+
name: string;
|
|
25
|
+
href: string;
|
|
26
|
+
document: OdtDocument;
|
|
27
|
+
forms: OdbFormDefinition[];
|
|
28
|
+
}
|
|
29
|
+
declare function readOdbForm(pkg: Package, formName: string): OdbForm;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { OdbForm, OdbFormControl, OdbFormDefinition, readOdbForm };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Package } from "../../model/package.js";
|
|
2
|
+
import { OdtDocument } from "../odt/read.js";
|
|
3
|
+
//#region src/typed/odb/form.d.ts
|
|
4
|
+
interface OdbFormControl {
|
|
5
|
+
tag: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
controlImplementation?: string;
|
|
8
|
+
dataField?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
controls: OdbFormControl[];
|
|
12
|
+
}
|
|
13
|
+
interface OdbFormDefinition {
|
|
14
|
+
name?: string;
|
|
15
|
+
command?: string;
|
|
16
|
+
commandType?: string;
|
|
17
|
+
datasource?: string;
|
|
18
|
+
filter?: string;
|
|
19
|
+
order?: string;
|
|
20
|
+
controls: OdbFormControl[];
|
|
21
|
+
subForms: OdbFormDefinition[];
|
|
22
|
+
}
|
|
23
|
+
interface OdbForm {
|
|
24
|
+
name: string;
|
|
25
|
+
href: string;
|
|
26
|
+
document: OdtDocument;
|
|
27
|
+
forms: OdbFormDefinition[];
|
|
28
|
+
}
|
|
29
|
+
declare function readOdbForm(pkg: Package, formName: string): OdbForm;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { OdbForm, OdbFormControl, OdbFormDefinition, readOdbForm };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { decodeXmlText } from "../../xml/entities.js";
|
|
2
|
+
import { attrValue, findChildElement, rootElement } from "../../xml/query.js";
|
|
3
|
+
import { readOdt } from "../odt/read.js";
|
|
4
|
+
import { resolveOdbComponent } from "./read.js";
|
|
5
|
+
import { subDocumentPackage } from "./subdocument.js";
|
|
6
|
+
//#region src/typed/odb/form.ts
|
|
7
|
+
const CONTENT_PART = "content.xml";
|
|
8
|
+
const FORM_ELEMENT_TAG = "form:form";
|
|
9
|
+
const FORM_PROPERTIES_TAG = "form:properties";
|
|
10
|
+
const FORM_TAG_PREFIX = "form:";
|
|
11
|
+
function formAttr(element, name) {
|
|
12
|
+
const raw = attrValue(element, name);
|
|
13
|
+
return raw === void 0 ? void 0 : decodeXmlText(raw);
|
|
14
|
+
}
|
|
15
|
+
function readControl(element) {
|
|
16
|
+
const control = {
|
|
17
|
+
tag: element.tag,
|
|
18
|
+
controls: readControls(element)
|
|
19
|
+
};
|
|
20
|
+
const name = formAttr(element, "form:name");
|
|
21
|
+
if (name !== void 0) control.name = name;
|
|
22
|
+
const controlImplementation = formAttr(element, "form:control-implementation");
|
|
23
|
+
if (controlImplementation !== void 0) control.controlImplementation = controlImplementation;
|
|
24
|
+
const dataField = formAttr(element, "form:data-field");
|
|
25
|
+
if (dataField !== void 0) control.dataField = dataField;
|
|
26
|
+
const id = formAttr(element, "form:id");
|
|
27
|
+
if (id !== void 0) control.id = id;
|
|
28
|
+
const label = formAttr(element, "form:label");
|
|
29
|
+
if (label !== void 0) control.label = label;
|
|
30
|
+
return control;
|
|
31
|
+
}
|
|
32
|
+
function readControls(container) {
|
|
33
|
+
const controls = [];
|
|
34
|
+
for (const child of container.children) {
|
|
35
|
+
if (child.type !== "element" || !child.tag.startsWith(FORM_TAG_PREFIX)) continue;
|
|
36
|
+
if (child.tag === FORM_ELEMENT_TAG || child.tag === FORM_PROPERTIES_TAG) continue;
|
|
37
|
+
controls.push(readControl(child));
|
|
38
|
+
}
|
|
39
|
+
return controls;
|
|
40
|
+
}
|
|
41
|
+
function readFormDefinition(element) {
|
|
42
|
+
const subForms = [];
|
|
43
|
+
for (const child of element.children) if (child.type === "element" && child.tag === FORM_ELEMENT_TAG) subForms.push(readFormDefinition(child));
|
|
44
|
+
const definition = {
|
|
45
|
+
controls: readControls(element),
|
|
46
|
+
subForms
|
|
47
|
+
};
|
|
48
|
+
const name = formAttr(element, "form:name");
|
|
49
|
+
if (name !== void 0) definition.name = name;
|
|
50
|
+
const command = formAttr(element, "form:command");
|
|
51
|
+
if (command !== void 0) definition.command = command;
|
|
52
|
+
const commandType = formAttr(element, "form:command-type");
|
|
53
|
+
if (commandType !== void 0) definition.commandType = commandType;
|
|
54
|
+
const datasource = formAttr(element, "form:datasource");
|
|
55
|
+
if (datasource !== void 0) definition.datasource = datasource;
|
|
56
|
+
const filter = formAttr(element, "form:filter");
|
|
57
|
+
if (filter !== void 0) definition.filter = filter;
|
|
58
|
+
const order = formAttr(element, "form:order");
|
|
59
|
+
if (order !== void 0) definition.order = order;
|
|
60
|
+
return definition;
|
|
61
|
+
}
|
|
62
|
+
function readFormDefinitions(contentRoot) {
|
|
63
|
+
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
64
|
+
const text = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
65
|
+
const forms = text === void 0 ? void 0 : findChildElement(text.children, "office:forms");
|
|
66
|
+
if (forms === void 0) return [];
|
|
67
|
+
const definitions = [];
|
|
68
|
+
for (const child of forms.children) if (child.type === "element" && child.tag === FORM_ELEMENT_TAG) definitions.push(readFormDefinition(child));
|
|
69
|
+
return definitions;
|
|
70
|
+
}
|
|
71
|
+
function readOdbForm(pkg, formName) {
|
|
72
|
+
const component = resolveOdbComponent(pkg, "form", formName);
|
|
73
|
+
const subPackage = subDocumentPackage(pkg, component.href);
|
|
74
|
+
const contentPart = subPackage.parts[CONTENT_PART];
|
|
75
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdbForm: form "${formName}" sub-document ${component.href}/${CONTENT_PART} is not an XML part`);
|
|
76
|
+
return {
|
|
77
|
+
name: component.name,
|
|
78
|
+
href: component.href,
|
|
79
|
+
document: readOdt(subPackage),
|
|
80
|
+
forms: readFormDefinitions(rootElement(contentPart.nodes))
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { readOdbForm };
|
package/dist/typed/odb/read.cjs
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_xml_entities = require("../../xml/entities.cjs");
|
|
3
3
|
const require_xml_query = require("../../xml/query.cjs");
|
|
4
4
|
//#region src/typed/odb/read.ts
|
|
5
5
|
const CONTENT_PART = "content.xml";
|
|
6
6
|
const EMBEDDED_URL_PREFIX = "sdbc:embedded:";
|
|
7
|
-
const SUBDOCUMENT_CONTENT_SUFFIX = "/content.xml";
|
|
8
|
-
function isXmlMediaType(mediaType) {
|
|
9
|
-
return mediaType === "text/xml" || mediaType === "application/xml" || mediaType.endsWith("+xml");
|
|
10
|
-
}
|
|
11
7
|
function formatServerDatabaseUrl(serverDatabase) {
|
|
12
8
|
const dbType = require_xml_query.attrValue(serverDatabase, "db:type");
|
|
13
9
|
if (dbType === void 0) return;
|
|
@@ -51,13 +47,24 @@ function readConnectionInfo(databaseElement) {
|
|
|
51
47
|
};
|
|
52
48
|
}
|
|
53
49
|
}
|
|
54
|
-
function
|
|
50
|
+
function collectQueryDefinitions(container, definitions) {
|
|
55
51
|
for (const child of container.children) {
|
|
56
52
|
if (child.type !== "element") continue;
|
|
57
53
|
if (child.tag === "db:query") {
|
|
58
54
|
const name = require_xml_query.attrValue(child, "db:name");
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const command = require_xml_query.attrValue(child, "db:command");
|
|
56
|
+
if (name === void 0 || command === void 0) continue;
|
|
57
|
+
const decodedCommand = require_xml_entities.decodeXmlText(command);
|
|
58
|
+
const escapeProcessingRaw = require_xml_query.attrValue(child, "db:escape-processing");
|
|
59
|
+
definitions.push(escapeProcessingRaw === void 0 ? {
|
|
60
|
+
name,
|
|
61
|
+
command: decodedCommand
|
|
62
|
+
} : {
|
|
63
|
+
name,
|
|
64
|
+
command: decodedCommand,
|
|
65
|
+
escapeProcessing: escapeProcessingRaw === "true"
|
|
66
|
+
});
|
|
67
|
+
} else if (child.tag === "db:query-collection") collectQueryDefinitions(child, definitions);
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
function collectTableNames(databaseElement) {
|
|
@@ -76,16 +83,47 @@ function collectTableNames(databaseElement) {
|
|
|
76
83
|
if (tableDefinitions !== void 0) for (const definition of require_xml_query.childrenWithTag(tableDefinitions, "db:table-definition")) pushName(require_xml_query.attrValue(definition, "db:name"));
|
|
77
84
|
return names;
|
|
78
85
|
}
|
|
79
|
-
function
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (
|
|
86
|
+
function collectComponents(container, components) {
|
|
87
|
+
for (const child of container.children) {
|
|
88
|
+
if (child.type !== "element") continue;
|
|
89
|
+
if (child.tag === "db:component-collection") {
|
|
90
|
+
collectComponents(child, components);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (child.tag !== "db:component") continue;
|
|
94
|
+
const name = require_xml_query.attrValue(child, "db:name");
|
|
95
|
+
const rawHref = require_xml_query.attrValue(child, "xlink:href");
|
|
96
|
+
if (name === void 0 || rawHref === void 0) continue;
|
|
97
|
+
const decodedHref = require_xml_entities.decodeXmlText(rawHref);
|
|
98
|
+
const href = decodedHref.endsWith("/") ? decodedHref.slice(0, -1) : decodedHref;
|
|
99
|
+
if (href.length === 0) continue;
|
|
100
|
+
const asTemplateRaw = require_xml_query.attrValue(child, "db:as-template");
|
|
101
|
+
components.push(asTemplateRaw === void 0 ? {
|
|
102
|
+
name: require_xml_entities.decodeXmlText(name),
|
|
103
|
+
href
|
|
104
|
+
} : {
|
|
105
|
+
name: require_xml_entities.decodeXmlText(name),
|
|
106
|
+
href,
|
|
107
|
+
asTemplate: asTemplateRaw === "true"
|
|
108
|
+
});
|
|
87
109
|
}
|
|
88
|
-
|
|
110
|
+
}
|
|
111
|
+
function readComponents(databaseElement, tag) {
|
|
112
|
+
const container = require_xml_query.findChildElement(databaseElement.children, tag);
|
|
113
|
+
if (container === void 0) return [];
|
|
114
|
+
const components = [];
|
|
115
|
+
collectComponents(container, components);
|
|
116
|
+
return components;
|
|
117
|
+
}
|
|
118
|
+
function resolveOdbComponent(pkg, kind, name) {
|
|
119
|
+
const inventory = readOdbInventory(pkg);
|
|
120
|
+
const components = kind === "form" ? inventory.forms : inventory.reports;
|
|
121
|
+
const match = components.find((component) => component.name === name);
|
|
122
|
+
if (match === void 0) {
|
|
123
|
+
const available = components.map((component) => component.name).join(", ");
|
|
124
|
+
throw new Error(`resolveOdbComponent: no ${kind} named "${name}" -- available: ${available === "" ? "(none)" : available}`);
|
|
125
|
+
}
|
|
126
|
+
return match;
|
|
89
127
|
}
|
|
90
128
|
function readOdbInventory(pkg) {
|
|
91
129
|
const contentPart = pkg.parts[CONTENT_PART];
|
|
@@ -97,16 +135,15 @@ function readOdbInventory(pkg) {
|
|
|
97
135
|
const connection = readConnectionInfo(databaseElement);
|
|
98
136
|
const queries = [];
|
|
99
137
|
const queriesElement = require_xml_query.findChildElement(databaseElement.children, "db:queries");
|
|
100
|
-
if (queriesElement !== void 0)
|
|
101
|
-
const tables = collectTableNames(databaseElement);
|
|
102
|
-
const manifest = require_manifest.readManifest(pkg);
|
|
138
|
+
if (queriesElement !== void 0) collectQueryDefinitions(queriesElement, queries);
|
|
103
139
|
return {
|
|
104
140
|
connection,
|
|
105
|
-
tables,
|
|
141
|
+
tables: collectTableNames(databaseElement),
|
|
106
142
|
queries,
|
|
107
|
-
forms:
|
|
108
|
-
reports:
|
|
143
|
+
forms: readComponents(databaseElement, "db:forms"),
|
|
144
|
+
reports: readComponents(databaseElement, "db:reports")
|
|
109
145
|
};
|
|
110
146
|
}
|
|
111
147
|
//#endregion
|
|
112
148
|
exports.readOdbInventory = readOdbInventory;
|
|
149
|
+
exports.resolveOdbComponent = resolveOdbComponent;
|