@trebco/treb 32.14.0 → 36.1.3
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/api-generator/api-generator-types.ts +3 -0
- package/api-generator/api-generator.ts +15 -1
- package/bun.lock +145 -99
- package/dist/chunk-43DLP2OX.mjs +11 -0
- package/dist/chunk-4CKS56PE.mjs +11 -0
- package/dist/chunk-75PARUQE.mjs +11 -0
- package/dist/chunk-7QD63AZS.mjs +24601 -0
- package/dist/chunk-A55ARVRD.mjs +11 -0
- package/dist/chunk-DESAKYW4.mjs +11 -0
- package/dist/chunk-EQ2R5W6P.mjs +24565 -0
- package/dist/chunk-IYJU2J6D.mjs +24601 -0
- package/dist/chunk-KSJFPGXT.mjs +11 -0
- package/dist/chunk-ORQFKLXM.mjs +24601 -0
- package/dist/chunk-SFDNNDHY.mjs +11 -0
- package/dist/chunk-T47DX5MI.mjs +11 -0
- package/dist/chunk-T6ILBVEX.mjs +11 -0
- package/dist/chunk-TPRCDYYG.mjs +11 -0
- package/dist/chunk-YAHNOOHO.mjs +11 -0
- package/dist/chunk-YLCFKX2G.mjs +24601 -0
- package/dist/treb-export-worker.mjs +9 -2
- package/dist/treb-spreadsheet.mjs +7 -19
- package/dist/treb.d.ts +144 -117
- package/esbuild-composite.mjs +18 -6
- package/esbuild-utils.mjs +62 -3
- package/i18n/languages/treb-i18n-da.mjs +1 -1
- package/i18n/languages/treb-i18n-de.mjs +1 -1
- package/i18n/languages/treb-i18n-es.mjs +1 -1
- package/i18n/languages/treb-i18n-fr.mjs +1 -1
- package/i18n/languages/treb-i18n-it.mjs +1 -1
- package/i18n/languages/treb-i18n-nl.mjs +1 -1
- package/i18n/languages/treb-i18n-no.mjs +1 -1
- package/i18n/languages/treb-i18n-pl.mjs +1 -1
- package/i18n/languages/treb-i18n-pt.mjs +1 -1
- package/i18n/languages/treb-i18n-sv.mjs +1 -1
- package/ooxml-types/README.md +141 -0
- package/ooxml-types/package.json +5 -0
- package/ooxml-types/src/types/drawingml/chart.ts +327 -0
- package/ooxml-types/src/types/drawingml/index.ts +63 -0
- package/ooxml-types/src/types/drawingml/spreadsheetDrawing.ts +105 -0
- package/ooxml-types/src/types/drawingml/theme.ts +104 -0
- package/ooxml-types/src/types/index.ts +3 -0
- package/ooxml-types/src/types/package/contentTypes.ts +49 -0
- package/ooxml-types/src/types/package/docProps.ts +46 -0
- package/ooxml-types/src/types/package/index.ts +17 -0
- package/ooxml-types/src/types/package/relationships.ts +37 -0
- package/ooxml-types/src/types/spreadsheetml/columns.ts +20 -0
- package/ooxml-types/src/types/spreadsheetml/comments.ts +30 -0
- package/ooxml-types/src/types/spreadsheetml/dataFeatures.ts +261 -0
- package/ooxml-types/src/types/spreadsheetml/enums.ts +175 -0
- package/ooxml-types/src/types/spreadsheetml/index.ts +186 -0
- package/ooxml-types/src/types/spreadsheetml/metadata.ts +90 -0
- package/ooxml-types/src/types/spreadsheetml/misc.ts +35 -0
- package/ooxml-types/src/types/spreadsheetml/pageLayout.ts +83 -0
- package/ooxml-types/src/types/spreadsheetml/sharedStrings.ts +33 -0
- package/ooxml-types/src/types/spreadsheetml/sheetData.ts +70 -0
- package/ooxml-types/src/types/spreadsheetml/sheetProperties.ts +86 -0
- package/ooxml-types/src/types/spreadsheetml/sheetViews.ts +51 -0
- package/ooxml-types/src/types/spreadsheetml/sparkline.ts +46 -0
- package/ooxml-types/src/types/spreadsheetml/styles.ts +274 -0
- package/ooxml-types/src/types/spreadsheetml/table.ts +106 -0
- package/ooxml-types/src/types/spreadsheetml/util.ts +15 -0
- package/ooxml-types/src/types/spreadsheetml/workbook.ts +165 -0
- package/ooxml-types/src/types/spreadsheetml/worksheet.ts +60 -0
- package/package.json +13 -11
- package/treb-base-types/src/api_types.ts +1 -1
- package/treb-base-types/src/area-utils.ts +1 -1
- package/treb-base-types/src/area.ts +1 -1
- package/treb-base-types/src/basic_types.ts +1 -1
- package/treb-base-types/src/cell.ts +1 -1
- package/treb-base-types/src/cells.ts +1 -1
- package/treb-base-types/src/color.ts +1 -1
- package/treb-base-types/src/dom-utilities.ts +1 -1
- package/treb-base-types/src/evaluate-options.ts +1 -1
- package/treb-base-types/src/font-stack.ts +1 -1
- package/treb-base-types/src/gradient.ts +1 -1
- package/treb-base-types/src/import.ts +1 -1
- package/treb-base-types/src/index-standalone.ts +1 -1
- package/treb-base-types/src/index.ts +2 -1
- package/treb-base-types/src/layout.ts +1 -1
- package/treb-base-types/src/localization.ts +1 -1
- package/treb-base-types/src/rectangle.ts +1 -1
- package/treb-base-types/src/render_text.ts +7 -1
- package/treb-base-types/src/style.ts +1 -1
- package/treb-base-types/src/table.ts +1 -1
- package/treb-base-types/src/text_part.ts +1 -1
- package/treb-base-types/src/theme.ts +1 -1
- package/treb-base-types/src/union.ts +4 -1
- package/treb-base-types/src/value-type.ts +1 -1
- package/treb-base-types/src/worker-proxy.ts +294 -0
- package/treb-base-types/style/resizable.css +1 -1
- package/treb-calculator/src/calculator.ts +133 -14
- package/treb-calculator/src/complex-math.ts +1 -1
- package/treb-calculator/src/dag/array-vertex.ts +1 -1
- package/treb-calculator/src/dag/calculation_leaf_vertex.ts +1 -1
- package/treb-calculator/src/dag/graph.ts +1 -1
- package/treb-calculator/src/dag/spreadsheet_vertex.ts +1 -1
- package/treb-calculator/src/dag/spreadsheet_vertex_base.ts +1 -1
- package/treb-calculator/src/dag/state_leaf_vertex.ts +1 -1
- package/treb-calculator/src/dag/vertex.ts +1 -1
- package/treb-calculator/src/descriptors.ts +9 -1
- package/treb-calculator/src/expression-calculator.ts +1 -1
- package/treb-calculator/src/function-error.ts +1 -1
- package/treb-calculator/src/function-library.ts +1 -1
- package/treb-calculator/src/functions/base-functions.ts +8 -4
- package/treb-calculator/src/functions/beta.ts +1 -1
- package/treb-calculator/src/functions/checkbox.ts +1 -1
- package/treb-calculator/src/functions/complex-functions.ts +1 -1
- package/treb-calculator/src/functions/date-utils.ts +1 -1
- package/treb-calculator/src/functions/finance-functions.ts +2 -4
- package/treb-calculator/src/functions/fp.ts +1 -1
- package/treb-calculator/src/functions/function-utilities.ts +1 -1
- package/treb-calculator/src/functions/gamma.ts +1 -1
- package/treb-calculator/src/functions/information-functions.ts +1 -1
- package/treb-calculator/src/functions/lambda-functions.ts +4 -1
- package/treb-calculator/src/functions/matrix-functions.ts +1 -1
- package/treb-calculator/src/functions/normal.ts +1 -1
- package/treb-calculator/src/functions/regex-functions.ts +13 -4
- package/treb-calculator/src/functions/sparkline.ts +1 -1
- package/treb-calculator/src/functions/statistics-functions.ts +1 -1
- package/treb-calculator/src/functions/students-t.ts +1 -1
- package/treb-calculator/src/functions/text-functions.ts +5 -1
- package/treb-calculator/src/index.ts +1 -1
- package/treb-calculator/src/notifier-types.ts +1 -1
- package/treb-calculator/src/primitives.ts +1 -1
- package/treb-calculator/src/utilities.ts +1 -1
- package/treb-charts/src/chart-functions.ts +1 -1
- package/treb-charts/src/chart-types.ts +1 -1
- package/treb-charts/src/chart-utils.ts +1 -1
- package/treb-charts/src/chart.ts +1 -1
- package/treb-charts/src/default-chart-renderer.ts +1 -1
- package/treb-charts/src/index.ts +1 -1
- package/treb-charts/src/main.ts +1 -1
- package/treb-charts/src/quicksort.ts +1 -1
- package/treb-charts/src/rectangle.ts +1 -1
- package/treb-charts/src/renderer-type.ts +1 -1
- package/treb-charts/src/renderer.ts +1 -1
- package/treb-charts/src/util.ts +1 -1
- package/treb-charts/style/charts.scss +1 -1
- package/treb-data-model/src/annotation.ts +1 -1
- package/treb-data-model/src/conditional_format.ts +1 -1
- package/treb-data-model/src/data-validation.ts +1 -1
- package/treb-data-model/src/data_model.ts +32 -5
- package/treb-data-model/src/index.ts +1 -1
- package/treb-data-model/src/language-model.ts +1 -1
- package/treb-data-model/src/named.ts +1 -1
- package/treb-data-model/src/serialize_options.ts +1 -1
- package/treb-data-model/src/sheet.ts +1 -1
- package/treb-data-model/src/sheet_collection.ts +1 -1
- package/treb-data-model/src/sheet_selection.ts +1 -1
- package/treb-data-model/src/sheet_types.ts +1 -1
- package/treb-data-model/src/types.ts +1 -1
- package/treb-embed/src/content-types.d.ts +1 -1
- package/treb-embed/src/custom-element/global.d.ts +1 -1
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +1 -1
- package/treb-embed/src/custom-element/treb-global.ts +1 -1
- package/treb-embed/src/custom-element/treb-spreadsheet-element.ts +1 -1
- package/treb-embed/src/embedded-spreadsheet.ts +357 -154
- package/treb-embed/src/index.ts +1 -1
- package/treb-embed/src/options.ts +4 -2
- package/treb-embed/src/plugin.ts +1 -1
- package/treb-embed/src/progress-dialog.ts +1 -1
- package/treb-embed/src/selection-state.ts +1 -1
- package/treb-embed/src/spinner.ts +1 -1
- package/treb-embed/src/toolbar-message.ts +6 -1
- package/treb-embed/src/types.ts +13 -1
- package/treb-embed/style/autocomplete.scss +1 -1
- package/treb-embed/style/dark-theme.scss +1 -1
- package/treb-embed/style/defaults.scss +1 -1
- package/treb-embed/style/dialog.scss +1 -1
- package/treb-embed/style/dropdown-select.scss +1 -1
- package/treb-embed/style/font-stacks.scss +1 -1
- package/treb-embed/style/formula-bar.scss +1 -1
- package/treb-embed/style/grid.scss +1 -1
- package/treb-embed/style/layout.scss +1 -1
- package/treb-embed/style/mouse-mask.scss +1 -1
- package/treb-embed/style/note.scss +1 -1
- package/treb-embed/style/overlay-editor.scss +1 -1
- package/treb-embed/style/spinner.scss +1 -1
- package/treb-embed/style/tab-bar.scss +1 -1
- package/treb-embed/style/table.scss +1 -1
- package/treb-embed/style/theme-defaults.scss +1 -1
- package/treb-embed/style/toolbar.scss +1 -1
- package/treb-embed/style/tooltip.scss +1 -1
- package/treb-embed/style/treb-icons.scss +1 -1
- package/treb-embed/style/treb-spreadsheet-element.scss +1 -1
- package/treb-embed/style/z-index.scss +1 -1
- package/treb-export/src/address-type.ts +1 -1
- package/treb-export/src/base-template.ts +1 -1
- package/treb-export/src/column-width.ts +1 -1
- package/treb-export/src/drawing/bubble-chart-template.ts +1 -1
- package/treb-export/src/drawing/chart-template-components2.ts +1 -1
- package/treb-export/src/drawing/chart.ts +1 -1
- package/treb-export/src/drawing/column-chart-template2.ts +1 -1
- package/treb-export/src/drawing/donut-chart-template2.ts +1 -1
- package/treb-export/src/drawing/drawing.ts +1 -1
- package/treb-export/src/drawing/embedded-image.ts +1 -1
- package/treb-export/src/drawing/scatter-chart-template2.ts +1 -1
- package/treb-export/src/export.ts +10 -6
- package/treb-export/src/import-export-messages.ts +61 -0
- package/treb-export/src/import.ts +318 -301
- package/treb-export/src/index.worker.ts +85 -53
- package/treb-export/src/metadata.ts +71 -3
- package/treb-export/src/ooxml.ts +47 -0
- package/treb-export/src/relationship.ts +1 -1
- package/treb-export/src/shared-strings.ts +19 -15
- package/treb-export/src/template-2.ts +1 -1
- package/treb-export/src/unescape_xml.ts +1 -1
- package/treb-export/src/workbook-sheet.ts +11 -6
- package/treb-export/src/workbook-style.ts +137 -25
- package/treb-export/src/workbook-theme.ts +20 -4
- package/treb-export/src/workbook.ts +85 -88
- package/treb-export/src/xml-test.ts +1 -1
- package/treb-export/src/xml-utils.ts +1 -1
- package/treb-export/src/zip-wrapper.ts +1 -1
- package/treb-export/tsconfig.json +2 -1
- package/treb-format/src/format.test.ts +1 -1
- package/treb-format/src/format.ts +12 -5
- package/treb-format/src/format_cache.ts +3 -3
- package/treb-format/src/format_parser.ts +1 -1
- package/treb-format/src/index.ts +1 -1
- package/treb-format/src/number_format_section.ts +1 -1
- package/treb-format/src/value_parser.ts +1 -1
- package/treb-grid/src/editors/autocomplete.ts +1 -1
- package/treb-grid/src/editors/autocomplete_matcher.ts +1 -1
- package/treb-grid/src/editors/editor.ts +15 -6
- package/treb-grid/src/editors/external_editor.ts +33 -8
- package/treb-grid/src/editors/formula_bar.ts +12 -1
- package/treb-grid/src/editors/overlay_editor.ts +4 -1
- package/treb-grid/src/index.ts +1 -1
- package/treb-grid/src/layout/base_layout.ts +1 -1
- package/treb-grid/src/layout/grid_layout.ts +1 -1
- package/treb-grid/src/layout/mock-layout.ts +1 -1
- package/treb-grid/src/render/selection-renderer.ts +1 -1
- package/treb-grid/src/render/svg_header_overlay.ts +1 -1
- package/treb-grid/src/render/svg_selection_block.ts +1 -1
- package/treb-grid/src/render/tile_renderer.ts +36 -7
- package/treb-grid/src/types/border_constants.ts +1 -1
- package/treb-grid/src/types/clipboard_data.ts +1 -1
- package/treb-grid/src/types/clipboard_data2.ts +1 -1
- package/treb-grid/src/types/drag_mask.ts +1 -1
- package/treb-grid/src/types/external_editor_config.ts +1 -1
- package/treb-grid/src/types/grid.ts +181 -40
- package/treb-grid/src/types/grid_base.ts +7 -4
- package/treb-grid/src/types/grid_command.ts +7 -1
- package/treb-grid/src/types/grid_events.ts +2 -1
- package/treb-grid/src/types/grid_options.ts +1 -1
- package/treb-grid/src/types/scale-control.ts +1 -1
- package/treb-grid/src/types/set_range_options.ts +1 -1
- package/treb-grid/src/types/tab_bar.ts +1 -1
- package/treb-grid/src/types/tile.ts +1 -1
- package/treb-grid/src/types/update_flags.ts +1 -1
- package/treb-grid/src/util/fontmetrics.ts +1 -1
- package/treb-grid/src/util/ua.ts +1 -1
- package/treb-parser/src/csv-parser.ts +1 -1
- package/treb-parser/src/index.ts +1 -1
- package/treb-parser/src/md-parser.ts +1 -1
- package/treb-parser/src/parser-types.ts +1 -1
- package/treb-parser/src/parser.ts +1 -1
- package/treb-utils/src/event_source.ts +1 -1
- package/treb-utils/src/ievent_source.ts +1 -1
- package/treb-utils/src/index.ts +1 -1
- package/treb-utils/src/measurement.ts +1 -1
- package/treb-utils/src/scale.ts +1 -1
- package/treb-utils/src/serialize_html.ts +1 -1
- package/treb-utils/src/validate_uri.ts +1 -1
- package/tsproject.json +2 -3
- package/treb-embed/src/export-worker.ts +0 -44
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* You should have received a copy of the GNU General Public License along
|
|
15
15
|
* with TREB. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
*
|
|
17
|
-
* Copyright 2022-
|
|
17
|
+
* Copyright 2022-2026 trebco, llc.
|
|
18
18
|
* info@treb.app
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
@@ -22,74 +22,106 @@
|
|
|
22
22
|
import type { ImportedSheetData } from 'treb-base-types';
|
|
23
23
|
import type { SerializedModel } from 'treb-data-model';
|
|
24
24
|
|
|
25
|
+
import * as Messages from './import-export-messages';
|
|
26
|
+
|
|
25
27
|
import { Exporter } from './export';
|
|
26
28
|
import { Importer } from './import';
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
import { GetWorkerContext } from 'treb-base-types';
|
|
31
|
+
|
|
32
|
+
export function AttachInProcess() {
|
|
33
|
+
console.info("AOP");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// avoid top-level await so we can support older js engines
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
sheet: SerializedModel,
|
|
33
|
-
decorated: Record<string, string>,
|
|
34
|
-
}) => {
|
|
38
|
+
GetWorkerContext().then(ctx => {
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
exporter.Init(data.decorated || []);
|
|
38
|
-
exporter.Export(data.sheet);
|
|
39
|
-
ctx.postMessage({ status: 'complete', blob: exporter.Blob() });
|
|
40
|
-
}
|
|
40
|
+
const exporter = new Exporter();
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
const ExportSheets = (data: {
|
|
43
|
+
sheet: SerializedModel,
|
|
44
|
+
decorated: Record<string, string>,
|
|
45
|
+
}) => {
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
if (data.sheet) {
|
|
48
|
+
exporter.Init(data.decorated || []);
|
|
49
|
+
exporter.Export(data.sheet);
|
|
50
|
+
|
|
51
|
+
const message: Messages.ExportCompleteMessage = {
|
|
52
|
+
type: 'export-complete',
|
|
53
|
+
blob: exporter.Blob(),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
ctx.postMessage(message);
|
|
57
|
+
|
|
58
|
+
}
|
|
45
59
|
|
|
46
|
-
|
|
60
|
+
};
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
importer.Init(data.data);
|
|
62
|
+
const ImportSheet = (data: { data: ArrayBuffer }) => {
|
|
50
63
|
|
|
51
|
-
const
|
|
64
|
+
const importer = new Importer();
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
sheets: [] as ImportedSheetData[],
|
|
56
|
-
named,
|
|
57
|
-
active_tab: importer.workbook?.active_tab,
|
|
58
|
-
};
|
|
66
|
+
try {
|
|
67
|
+
importer.Init(data.data);
|
|
59
68
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
const named = importer.workbook?.GetNamedRanges();
|
|
70
|
+
|
|
71
|
+
const count = importer.SheetCount();
|
|
72
|
+
const results = {
|
|
73
|
+
sheets: [] as ImportedSheetData[],
|
|
74
|
+
named,
|
|
75
|
+
active_tab: importer.workbook?.active_tab,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < count; i++) {
|
|
79
|
+
const result = importer.GetSheet(i);
|
|
80
|
+
if (result) {
|
|
81
|
+
results.sheets.push(result);
|
|
82
|
+
}
|
|
64
83
|
}
|
|
65
|
-
}
|
|
66
84
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
for (const entry of named || []) {
|
|
86
|
+
if (typeof entry.local_scope === 'number') {
|
|
87
|
+
const sheet = results.sheets[entry.local_scope];
|
|
88
|
+
if (sheet) {
|
|
89
|
+
entry.scope = sheet.name;
|
|
90
|
+
}
|
|
72
91
|
}
|
|
73
92
|
}
|
|
93
|
+
|
|
94
|
+
const message: Messages.ImportCompleteMessage = {
|
|
95
|
+
type: 'import-complete',
|
|
96
|
+
results,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ctx.postMessage(message);
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
console.warn('error importing xlsx file');
|
|
104
|
+
console.info(err);
|
|
105
|
+
|
|
106
|
+
const message: Messages.ImportErrorMessage = {
|
|
107
|
+
type: 'import-error',
|
|
108
|
+
error: err,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
ctx.postMessage(message);
|
|
74
112
|
}
|
|
75
113
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
ctx.addEventListener('message', (event) => {
|
|
89
|
-
if (event.data && event.data.command === 'export'){
|
|
90
|
-
ExportSheets(event.data as { sheet: SerializedModel, decorated: Record<string, string>});
|
|
91
|
-
}
|
|
92
|
-
else if (event.data && event.data.command === 'import'){
|
|
93
|
-
ImportSheet(event.data as { data: ArrayBuffer });
|
|
94
|
-
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// initialize message handler
|
|
117
|
+
ctx.addEventListener('message', (event: MessageEvent<Messages.ImportMessage|Messages.ExportMessage>) => {
|
|
118
|
+
if (event.data && event.data.type === 'export'){
|
|
119
|
+
ExportSheets(event.data as Messages.ExportMessage);
|
|
120
|
+
}
|
|
121
|
+
else if (event.data && event.data.type === 'import'){
|
|
122
|
+
ImportSheet(event.data as Messages.ImportMessage);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
95
126
|
});
|
|
127
|
+
|
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of TREB.
|
|
3
|
+
*
|
|
4
|
+
* TREB is free software: you can redistribute it and/or modify it under the
|
|
5
|
+
* terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
* Foundation, either version 3 of the License, or (at your option) any
|
|
7
|
+
* later version.
|
|
8
|
+
*
|
|
9
|
+
* TREB is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
10
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
11
|
+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
12
|
+
* details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU General Public License along
|
|
15
|
+
* with TREB. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*
|
|
17
|
+
* Copyright 2022-2026 trebco, llc.
|
|
18
|
+
* info@treb.app
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import * as OOXML from 'ooxml-types';
|
|
23
|
+
import { IterateTags } from './ooxml';
|
|
24
|
+
|
|
25
|
+
// import { XMLUtils } from './xml-utils';
|
|
2
26
|
|
|
3
27
|
/**
|
|
4
28
|
* https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.metadatarecord?view=openxml-3.0.1
|
|
@@ -118,8 +142,7 @@ export const LookupMetadata = (source: Metadata, type: 'cell'|'value', index: nu
|
|
|
118
142
|
|
|
119
143
|
};
|
|
120
144
|
|
|
121
|
-
|
|
122
|
-
export const ParseMetadataXML = (xml: any): Metadata => {
|
|
145
|
+
export const ParseMetadataXML = (root: OOXML.Metadata): Metadata => {
|
|
123
146
|
|
|
124
147
|
const metadata: Metadata = {
|
|
125
148
|
metadata_types: [],
|
|
@@ -127,6 +150,17 @@ export const ParseMetadataXML = (xml: any): Metadata => {
|
|
|
127
150
|
future_metadata: {},
|
|
128
151
|
};
|
|
129
152
|
|
|
153
|
+
IterateTags(root.metadataTypes, metadataTypes => {
|
|
154
|
+
IterateTags(metadataTypes.metadataType, entry => {
|
|
155
|
+
const name: string = entry.$attributes?.name || '';
|
|
156
|
+
const cell_meta = !!entry.$attributes?.cellMeta;
|
|
157
|
+
metadata.metadata_types.push({
|
|
158
|
+
name, cell_meta
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
/*
|
|
130
164
|
const metadata_types = XMLUtils.FindAll(xml, 'metadata/metadataTypes/metadataType');
|
|
131
165
|
for (const entry of metadata_types) {
|
|
132
166
|
|
|
@@ -139,7 +173,26 @@ export const ParseMetadataXML = (xml: any): Metadata => {
|
|
|
139
173
|
});
|
|
140
174
|
|
|
141
175
|
}
|
|
176
|
+
*/
|
|
142
177
|
|
|
178
|
+
IterateTags(root.futureMetadata, entry => {
|
|
179
|
+
const name = entry.$attributes?.name;
|
|
180
|
+
if (name) {
|
|
181
|
+
const future_metadata_list: FutureMetadata[] = [];
|
|
182
|
+
IterateTags(entry.bk, bk => {
|
|
183
|
+
const future_metadata: FutureMetadata = { flags: {} };
|
|
184
|
+
IterateTags(bk.extLst?.ext, ext => {
|
|
185
|
+
if (ext.dynamicArrayProperties?.$attributes?.fDynamic) {
|
|
186
|
+
future_metadata.flags['dynamic-array'] = true;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
future_metadata_list.push(future_metadata);
|
|
190
|
+
});
|
|
191
|
+
metadata.future_metadata[name] = future_metadata_list;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
/*
|
|
143
196
|
const future_metadata_blocks = XMLUtils.FindAll(xml, 'metadata/futureMetadata');
|
|
144
197
|
for (const entry of future_metadata_blocks) {
|
|
145
198
|
|
|
@@ -172,13 +225,28 @@ export const ParseMetadataXML = (xml: any): Metadata => {
|
|
|
172
225
|
|
|
173
226
|
}
|
|
174
227
|
}
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
IterateTags(root.cellMetadata, cellMetadata => {
|
|
231
|
+
IterateTags(cellMetadata.bk, bk => {
|
|
232
|
+
IterateTags(bk.rc, rc => {
|
|
233
|
+
if (rc.$attributes) {
|
|
234
|
+
metadata.cell_metadata.push({
|
|
235
|
+
...rc.$attributes
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
175
241
|
|
|
242
|
+
/*
|
|
176
243
|
for (const entry of XMLUtils.FindAll(xml, 'metadata/cellMetadata/bk/rc')) {
|
|
177
244
|
metadata.cell_metadata.push({
|
|
178
245
|
t: Number(entry.a$?.t || -1),
|
|
179
246
|
v: Number(entry.a$?.v || -1),
|
|
180
247
|
});
|
|
181
248
|
}
|
|
249
|
+
*/
|
|
182
250
|
|
|
183
251
|
// console.info({metadata});
|
|
184
252
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
5
|
+
import * as OOXML from 'ooxml-types';
|
|
6
|
+
|
|
7
|
+
export const ooxml_parser = new XMLParser({
|
|
8
|
+
attributesGroupName: '$attributes',
|
|
9
|
+
ignoreAttributes: false,
|
|
10
|
+
parseAttributeValue: true,
|
|
11
|
+
attributeNamePrefix: '',
|
|
12
|
+
removeNSPrefix: true,
|
|
13
|
+
textNodeName: '$text',
|
|
14
|
+
cdataPropName: '$cdata',
|
|
15
|
+
parseTagValue: false,
|
|
16
|
+
alwaysCreateTextNode: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function EnsureArray<T>(tag?: OOXML.OneOrMany<T>) {
|
|
20
|
+
if (Array.isArray(tag)) {
|
|
21
|
+
return tag;
|
|
22
|
+
}
|
|
23
|
+
if (tag === undefined ) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
return [tag];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function IterateTags<T>(root: OOXML.OneOrMany<T>|undefined, fn: (tag: T) => false|void) {
|
|
30
|
+
for (const element of EnsureArray(root)) {
|
|
31
|
+
const test = fn(element);
|
|
32
|
+
if (test === false) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function MapTags<K, T>(root: OOXML.OneOrMany<T>|undefined, fn: (tag: T) => K) {
|
|
39
|
+
const arr: K[] = [];
|
|
40
|
+
for (const element of EnsureArray(root)) { arr.push(fn(element)); }
|
|
41
|
+
return arr;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function FirstTag<T>(root: OOXML.OneOrMany<T>) {
|
|
45
|
+
return EnsureArray(root)[0];
|
|
46
|
+
}
|
|
47
|
+
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
* You should have received a copy of the GNU General Public License along
|
|
15
15
|
* with TREB. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
*
|
|
17
|
-
* Copyright 2022-
|
|
17
|
+
* Copyright 2022-2026 trebco, llc.
|
|
18
18
|
* info@treb.app
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import
|
|
22
|
+
import * as OOXML from 'ooxml-types';
|
|
23
|
+
import { EnsureArray, IterateTags } from './ooxml';
|
|
23
24
|
|
|
24
25
|
export class SharedStrings {
|
|
25
26
|
|
|
@@ -27,7 +28,7 @@ export class SharedStrings {
|
|
|
27
28
|
public reverse: Record<string, number> = {};
|
|
28
29
|
|
|
29
30
|
/** read strings table from (pre-parsed) xml; removes any existing strings */
|
|
30
|
-
public FromXML(
|
|
31
|
+
public FromXML(sst: OOXML.SharedStringTable) {
|
|
31
32
|
|
|
32
33
|
// clear
|
|
33
34
|
|
|
@@ -36,7 +37,7 @@ export class SharedStrings {
|
|
|
36
37
|
|
|
37
38
|
let index = 0;
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
IterateTags(sst.si, si => {
|
|
40
41
|
|
|
41
42
|
// simple string looks like
|
|
42
43
|
//
|
|
@@ -57,8 +58,8 @@ export class SharedStrings {
|
|
|
57
58
|
|
|
58
59
|
let base = '';
|
|
59
60
|
if (typeof si.t === 'string') { base = si.t; }
|
|
60
|
-
else if (si.t
|
|
61
|
-
base = si.t
|
|
61
|
+
else if (si.t.$text) {
|
|
62
|
+
base = si.t.$text;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
this.strings[index] = base;
|
|
@@ -80,14 +81,17 @@ export class SharedStrings {
|
|
|
80
81
|
// collect text.
|
|
81
82
|
|
|
82
83
|
else if (si.r) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
|
|
85
|
+
// not sure what happens if there are multiple <r/> tags
|
|
86
|
+
|
|
87
|
+
const r = EnsureArray(si.r)[0];
|
|
88
|
+
if (r) {
|
|
89
|
+
const parts = EnsureArray(r.t);
|
|
90
|
+
const composite = parts.map(part => part.$text || '').join('');
|
|
91
|
+
this.strings[index] = composite;
|
|
92
|
+
this.reverse[composite] = index;
|
|
93
|
+
}
|
|
94
|
+
|
|
91
95
|
}
|
|
92
96
|
else {
|
|
93
97
|
console.warn(` ** unexpected shared string @ ${index}`);
|
|
@@ -96,7 +100,7 @@ export class SharedStrings {
|
|
|
96
100
|
|
|
97
101
|
index++;
|
|
98
102
|
|
|
99
|
-
}
|
|
103
|
+
});
|
|
100
104
|
|
|
101
105
|
}
|
|
102
106
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* You should have received a copy of the GNU General Public License along
|
|
15
15
|
* with TREB. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
*
|
|
17
|
-
* Copyright 2022-
|
|
17
|
+
* Copyright 2022-2026 trebco, llc.
|
|
18
18
|
* info@treb.app
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
@@ -47,10 +47,12 @@ import type { SharedStrings } from './shared-strings';
|
|
|
47
47
|
import type { Drawing } from './drawing/drawing';
|
|
48
48
|
import type { RelationshipMap } from './relationship';
|
|
49
49
|
|
|
50
|
+
import * as OOXML from 'ooxml-types';
|
|
51
|
+
|
|
50
52
|
export interface SheetOptions {
|
|
51
53
|
name?: string;
|
|
52
54
|
id?: number;
|
|
53
|
-
rid?:
|
|
55
|
+
rid?: string;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
export interface RangeOptions {
|
|
@@ -74,7 +76,7 @@ export class Sheet {
|
|
|
74
76
|
public rels_path?: string;
|
|
75
77
|
public rels: RelationshipMap = {};
|
|
76
78
|
|
|
77
|
-
public sheet_data: any = {};
|
|
79
|
+
// public sheet_data: any = {};
|
|
78
80
|
|
|
79
81
|
public shared_strings?: SharedStrings;
|
|
80
82
|
public extent?: RangeType;
|
|
@@ -86,8 +88,9 @@ export class Sheet {
|
|
|
86
88
|
|
|
87
89
|
public drawings: Drawing[] = [];
|
|
88
90
|
|
|
89
|
-
constructor(
|
|
90
|
-
|
|
91
|
+
constructor(
|
|
92
|
+
public options: SheetOptions,
|
|
93
|
+
public root: OOXML.Worksheet) {}
|
|
91
94
|
|
|
92
95
|
/**
|
|
93
96
|
* A1 -> {row: 1, col: 1} etc.
|
|
@@ -165,8 +168,10 @@ export class Sheet {
|
|
|
165
168
|
// we can read column/row sizes in here, or anything else we need to do
|
|
166
169
|
// atm just extent
|
|
167
170
|
|
|
168
|
-
const dim = this.sheet_data.worksheet?.dimension?.a$?.ref;
|
|
171
|
+
// const dim = this.sheet_data.worksheet?.dimension?.a$?.ref;
|
|
172
|
+
const dim = this.root.dimension?.$attributes?.ref;
|
|
169
173
|
|
|
174
|
+
// what's up with the copies?
|
|
170
175
|
const extent = this.TranslateAddress(dim || '');
|
|
171
176
|
if (is_range(extent)) {
|
|
172
177
|
this.extent = JSON.parse(JSON.stringify(extent));
|