@json-to-office/core-docx 0.6.0 → 0.8.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/dist/components/columns.d.ts.map +1 -1
- package/dist/components/heading.d.ts.map +1 -1
- package/dist/components/highcharts.d.ts +2 -2
- package/dist/components/highcharts.d.ts.map +1 -1
- package/dist/components/image.d.ts.map +1 -1
- package/dist/components/list.d.ts.map +1 -1
- package/dist/components/paragraph.d.ts.map +1 -1
- package/dist/components/statistic.d.ts +1 -1
- package/dist/components/statistic.d.ts.map +1 -1
- package/dist/core/generator.d.ts +2 -0
- package/dist/core/generator.d.ts.map +1 -1
- package/dist/core/render.d.ts +2 -0
- package/dist/core/render.d.ts.map +1 -1
- package/dist/core/structure.d.ts.map +1 -1
- package/dist/index.js +248 -162
- package/dist/index.js.map +1 -1
- package/dist/plugin/createDocumentGenerator.d.ts +3 -0
- package/dist/plugin/createDocumentGenerator.d.ts.map +1 -1
- package/dist/plugin/example/index.js +243 -158
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/styles/utils/componentDefaults.d.ts +1 -6
- package/dist/styles/utils/componentDefaults.d.ts.map +1 -1
- package/dist/styles/utils/resolveComponentTree.d.ts +19 -0
- package/dist/styles/utils/resolveComponentTree.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1953,24 +1953,175 @@ var formatDate = (date, formatString = "MMMM d, yyyy") => {
|
|
|
1953
1953
|
return format(date, formatString);
|
|
1954
1954
|
};
|
|
1955
1955
|
|
|
1956
|
+
// src/styles/utils/componentDefaults.ts
|
|
1957
|
+
import { mergeWithDefaults } from "@json-to-office/shared";
|
|
1958
|
+
import { mergeWithDefaults as mergeWithDefaults2 } from "@json-to-office/shared";
|
|
1959
|
+
function getComponentDefaults(theme) {
|
|
1960
|
+
return theme.componentDefaults || {};
|
|
1961
|
+
}
|
|
1962
|
+
function getHeadingDefaults(theme) {
|
|
1963
|
+
const defaults = getComponentDefaults(theme);
|
|
1964
|
+
return defaults?.heading || {};
|
|
1965
|
+
}
|
|
1966
|
+
function getHeadingDefaultsForLevel(theme, level) {
|
|
1967
|
+
const defaults = {};
|
|
1968
|
+
if (theme.styles) {
|
|
1969
|
+
const styleKey = `heading${level}`;
|
|
1970
|
+
const headingStyle = theme.styles[styleKey];
|
|
1971
|
+
if (headingStyle?.alignment) {
|
|
1972
|
+
defaults.alignment = headingStyle.alignment;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
return defaults;
|
|
1976
|
+
}
|
|
1977
|
+
function getTextDefaults(theme) {
|
|
1978
|
+
const defaults = getComponentDefaults(theme);
|
|
1979
|
+
return defaults?.paragraph || {};
|
|
1980
|
+
}
|
|
1981
|
+
function getImageDefaults(theme) {
|
|
1982
|
+
const defaults = getComponentDefaults(theme);
|
|
1983
|
+
return defaults?.image || {};
|
|
1984
|
+
}
|
|
1985
|
+
function getStatisticDefaults(theme) {
|
|
1986
|
+
const defaults = getComponentDefaults(theme);
|
|
1987
|
+
return defaults?.statistic || {};
|
|
1988
|
+
}
|
|
1989
|
+
function getTableDefaults(theme) {
|
|
1990
|
+
const defaults = getComponentDefaults(theme);
|
|
1991
|
+
return defaults?.table || {};
|
|
1992
|
+
}
|
|
1993
|
+
function getSectionDefaults(theme) {
|
|
1994
|
+
const defaults = getComponentDefaults(theme);
|
|
1995
|
+
return defaults?.section || {};
|
|
1996
|
+
}
|
|
1997
|
+
function getColumnsDefaults(theme) {
|
|
1998
|
+
const defaults = getComponentDefaults(theme);
|
|
1999
|
+
return defaults?.columns || {};
|
|
2000
|
+
}
|
|
2001
|
+
function getListDefaults(theme) {
|
|
2002
|
+
const defaults = getComponentDefaults(theme);
|
|
2003
|
+
return defaults?.list || {};
|
|
2004
|
+
}
|
|
2005
|
+
function resolveHeadingProps(props, theme) {
|
|
2006
|
+
const defaults = getHeadingDefaults(theme);
|
|
2007
|
+
return mergeWithDefaults(props, defaults);
|
|
2008
|
+
}
|
|
2009
|
+
function resolveParagraphProps(props, theme) {
|
|
2010
|
+
const defaults = getTextDefaults(theme);
|
|
2011
|
+
return mergeWithDefaults(props, defaults);
|
|
2012
|
+
}
|
|
2013
|
+
function resolveImageProps(props, theme) {
|
|
2014
|
+
const defaults = getImageDefaults(theme);
|
|
2015
|
+
return mergeWithDefaults(props, defaults);
|
|
2016
|
+
}
|
|
2017
|
+
function resolveStatisticProps(props, theme) {
|
|
2018
|
+
const defaults = getStatisticDefaults(theme);
|
|
2019
|
+
return mergeWithDefaults(props, defaults);
|
|
2020
|
+
}
|
|
2021
|
+
function resolveTableProps(props, theme) {
|
|
2022
|
+
const defaults = getTableDefaults(theme);
|
|
2023
|
+
return mergeWithDefaults(props, defaults);
|
|
2024
|
+
}
|
|
2025
|
+
function resolveSectionProps(props, theme) {
|
|
2026
|
+
const defaults = getSectionDefaults(theme);
|
|
2027
|
+
return mergeWithDefaults(props, defaults);
|
|
2028
|
+
}
|
|
2029
|
+
function resolveColumnsProps(props, theme) {
|
|
2030
|
+
const defaults = getColumnsDefaults(theme);
|
|
2031
|
+
return mergeWithDefaults(props, defaults);
|
|
2032
|
+
}
|
|
2033
|
+
function resolveListProps(props, theme) {
|
|
2034
|
+
const defaults = getListDefaults(theme);
|
|
2035
|
+
return mergeWithDefaults(props, defaults);
|
|
2036
|
+
}
|
|
2037
|
+
function resolveHighchartsProps(props, _theme) {
|
|
2038
|
+
return props;
|
|
2039
|
+
}
|
|
2040
|
+
function getCustomComponentDefaults(theme, componentName) {
|
|
2041
|
+
const defaults = getComponentDefaults(theme);
|
|
2042
|
+
return defaults?.[componentName] || {};
|
|
2043
|
+
}
|
|
2044
|
+
function resolveCustomComponentProps(props, theme, componentName) {
|
|
2045
|
+
const defaults = getCustomComponentDefaults(theme, componentName);
|
|
2046
|
+
return mergeWithDefaults(props, defaults);
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
// src/styles/utils/resolveComponentTree.ts
|
|
2050
|
+
function resolveHeadingWithLevelDefaults(props, theme) {
|
|
2051
|
+
const resolved = resolveHeadingProps(props, theme);
|
|
2052
|
+
const level = resolved.level || 1;
|
|
2053
|
+
const levelDefaults = getHeadingDefaultsForLevel(theme, level);
|
|
2054
|
+
return {
|
|
2055
|
+
...resolved,
|
|
2056
|
+
// Only apply level-specific defaults if no explicit alignment in original props
|
|
2057
|
+
...props.alignment ? {} : levelDefaults
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
var RESOLVER_MAP = {
|
|
2061
|
+
heading: resolveHeadingWithLevelDefaults,
|
|
2062
|
+
paragraph: resolveParagraphProps,
|
|
2063
|
+
image: resolveImageProps,
|
|
2064
|
+
statistic: resolveStatisticProps,
|
|
2065
|
+
table: resolveTableProps,
|
|
2066
|
+
section: resolveSectionProps,
|
|
2067
|
+
columns: resolveColumnsProps,
|
|
2068
|
+
list: resolveListProps,
|
|
2069
|
+
highcharts: resolveHighchartsProps
|
|
2070
|
+
};
|
|
2071
|
+
function resolveComponentDefaults(component, theme) {
|
|
2072
|
+
if (!component.props) return component;
|
|
2073
|
+
const resolver = RESOLVER_MAP[component.name];
|
|
2074
|
+
const resolvedProps = resolver ? resolver(component.props, theme) : resolveCustomComponentProps(
|
|
2075
|
+
component.props,
|
|
2076
|
+
theme,
|
|
2077
|
+
component.name
|
|
2078
|
+
);
|
|
2079
|
+
return { ...component, props: resolvedProps };
|
|
2080
|
+
}
|
|
2081
|
+
function resolveComponentTree(components, theme) {
|
|
2082
|
+
return components.map((component) => {
|
|
2083
|
+
const resolved = resolveComponentDefaults(component, theme);
|
|
2084
|
+
const children = resolved.children;
|
|
2085
|
+
if (children && children.length > 0) {
|
|
2086
|
+
return {
|
|
2087
|
+
...resolved,
|
|
2088
|
+
children: resolveComponentTree(children, theme)
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
return resolved;
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
|
|
1956
2095
|
// src/core/structure.ts
|
|
1957
2096
|
async function processDocument(document, theme, themeName) {
|
|
1958
2097
|
const metadata = createDocumentMetadata(document.props);
|
|
2098
|
+
const docDefaults = document.props.componentDefaults;
|
|
2099
|
+
const effectiveTheme = docDefaults ? {
|
|
2100
|
+
...theme,
|
|
2101
|
+
componentDefaults: mergeWithDefaults2(
|
|
2102
|
+
docDefaults,
|
|
2103
|
+
theme.componentDefaults || {}
|
|
2104
|
+
)
|
|
2105
|
+
} : theme;
|
|
1959
2106
|
const context = createRenderContext(
|
|
1960
2107
|
{
|
|
1961
2108
|
metadata,
|
|
1962
2109
|
sections: [],
|
|
1963
|
-
theme,
|
|
2110
|
+
theme: effectiveTheme,
|
|
1964
2111
|
themeName
|
|
1965
2112
|
},
|
|
1966
|
-
|
|
2113
|
+
effectiveTheme,
|
|
1967
2114
|
themeName
|
|
1968
2115
|
);
|
|
1969
|
-
const
|
|
2116
|
+
const resolvedChildren = resolveComponentTree(
|
|
2117
|
+
document.children || [],
|
|
2118
|
+
effectiveTheme
|
|
2119
|
+
);
|
|
2120
|
+
const sections = await extractSections(resolvedChildren, context);
|
|
1970
2121
|
return {
|
|
1971
2122
|
metadata,
|
|
1972
2123
|
sections,
|
|
1973
|
-
theme,
|
|
2124
|
+
theme: effectiveTheme,
|
|
1974
2125
|
themeName
|
|
1975
2126
|
};
|
|
1976
2127
|
}
|
|
@@ -2000,19 +2151,24 @@ async function extractSections(components, context) {
|
|
|
2000
2151
|
Math.max(component.props.level || 1, 1),
|
|
2001
2152
|
6
|
|
2002
2153
|
);
|
|
2003
|
-
sectionComponents.unshift(
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2154
|
+
sectionComponents.unshift(
|
|
2155
|
+
resolveComponentDefaults(
|
|
2156
|
+
{
|
|
2157
|
+
name: "heading",
|
|
2158
|
+
props: {
|
|
2159
|
+
text: component.props.title,
|
|
2160
|
+
level: headingLevel,
|
|
2161
|
+
pageBreak: shouldPageBreak,
|
|
2162
|
+
// Apply zero-spacing to prevent unwanted initial line
|
|
2163
|
+
spacing: {
|
|
2164
|
+
before: 0,
|
|
2165
|
+
after: 0
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
},
|
|
2169
|
+
context.fullTheme
|
|
2170
|
+
)
|
|
2171
|
+
);
|
|
2016
2172
|
}
|
|
2017
2173
|
sections.push({
|
|
2018
2174
|
title: component.props?.title,
|
|
@@ -2052,18 +2208,23 @@ async function flattenComponents(components, context) {
|
|
|
2052
2208
|
Math.max(component.props.level || 1, 1),
|
|
2053
2209
|
6
|
|
2054
2210
|
);
|
|
2055
|
-
flattened.push(
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2211
|
+
flattened.push(
|
|
2212
|
+
resolveComponentDefaults(
|
|
2213
|
+
{
|
|
2214
|
+
name: "heading",
|
|
2215
|
+
props: {
|
|
2216
|
+
text: component.props.title,
|
|
2217
|
+
level: headingLevel,
|
|
2218
|
+
// Apply zero-spacing to prevent unwanted initial line
|
|
2219
|
+
spacing: {
|
|
2220
|
+
before: 0,
|
|
2221
|
+
after: 0
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
},
|
|
2225
|
+
context.fullTheme
|
|
2226
|
+
)
|
|
2227
|
+
);
|
|
2067
2228
|
}
|
|
2068
2229
|
flattened.push(...await flattenComponents(component.children, context));
|
|
2069
2230
|
} else {
|
|
@@ -3853,93 +4014,6 @@ function getComponentCacheStats() {
|
|
|
3853
4014
|
return componentCache.getStats();
|
|
3854
4015
|
}
|
|
3855
4016
|
|
|
3856
|
-
// src/styles/utils/componentDefaults.ts
|
|
3857
|
-
function getComponentDefaults(theme) {
|
|
3858
|
-
return theme.componentDefaults || {};
|
|
3859
|
-
}
|
|
3860
|
-
function getHeadingDefaults(theme) {
|
|
3861
|
-
const defaults = getComponentDefaults(theme);
|
|
3862
|
-
return defaults?.heading || {};
|
|
3863
|
-
}
|
|
3864
|
-
function getHeadingDefaultsForLevel(theme, level) {
|
|
3865
|
-
const defaults = {};
|
|
3866
|
-
if (theme.styles) {
|
|
3867
|
-
const styleKey = `heading${level}`;
|
|
3868
|
-
const headingStyle = theme.styles[styleKey];
|
|
3869
|
-
if (headingStyle?.alignment) {
|
|
3870
|
-
defaults.alignment = headingStyle.alignment;
|
|
3871
|
-
}
|
|
3872
|
-
}
|
|
3873
|
-
return defaults;
|
|
3874
|
-
}
|
|
3875
|
-
function getTextDefaults(theme) {
|
|
3876
|
-
const defaults = getComponentDefaults(theme);
|
|
3877
|
-
return defaults?.paragraph || {};
|
|
3878
|
-
}
|
|
3879
|
-
function getImageDefaults(theme) {
|
|
3880
|
-
const defaults = getComponentDefaults(theme);
|
|
3881
|
-
return defaults?.image || {};
|
|
3882
|
-
}
|
|
3883
|
-
function getStatisticDefaults(theme) {
|
|
3884
|
-
const defaults = getComponentDefaults(theme);
|
|
3885
|
-
return defaults?.statistic || {};
|
|
3886
|
-
}
|
|
3887
|
-
function getColumnsDefaults(theme) {
|
|
3888
|
-
const defaults = getComponentDefaults(theme);
|
|
3889
|
-
return defaults?.columns || {};
|
|
3890
|
-
}
|
|
3891
|
-
function getListDefaults(theme) {
|
|
3892
|
-
const defaults = getComponentDefaults(theme);
|
|
3893
|
-
return defaults?.list || {};
|
|
3894
|
-
}
|
|
3895
|
-
function deepMerge(target, source) {
|
|
3896
|
-
const output = { ...target };
|
|
3897
|
-
if (isObject(target) && isObject(source)) {
|
|
3898
|
-
Object.keys(source).forEach((key) => {
|
|
3899
|
-
if (isObject(source[key])) {
|
|
3900
|
-
if (!(key in target)) {
|
|
3901
|
-
output[key] = source[key];
|
|
3902
|
-
} else {
|
|
3903
|
-
output[key] = deepMerge(target[key], source[key]);
|
|
3904
|
-
}
|
|
3905
|
-
} else {
|
|
3906
|
-
output[key] = source[key];
|
|
3907
|
-
}
|
|
3908
|
-
});
|
|
3909
|
-
}
|
|
3910
|
-
return output;
|
|
3911
|
-
}
|
|
3912
|
-
function isObject(item) {
|
|
3913
|
-
return item !== null && typeof item === "object" && !Array.isArray(item);
|
|
3914
|
-
}
|
|
3915
|
-
function mergeWithDefaults(userConfig, themeDefaults) {
|
|
3916
|
-
return deepMerge(themeDefaults, userConfig);
|
|
3917
|
-
}
|
|
3918
|
-
function resolveHeadingProps(props, theme) {
|
|
3919
|
-
const defaults = getHeadingDefaults(theme);
|
|
3920
|
-
return mergeWithDefaults(props, defaults);
|
|
3921
|
-
}
|
|
3922
|
-
function resolveParagraphProps(props, theme) {
|
|
3923
|
-
const defaults = getTextDefaults(theme);
|
|
3924
|
-
return mergeWithDefaults(props, defaults);
|
|
3925
|
-
}
|
|
3926
|
-
function resolveImageProps(props, theme) {
|
|
3927
|
-
const defaults = getImageDefaults(theme);
|
|
3928
|
-
return mergeWithDefaults(props, defaults);
|
|
3929
|
-
}
|
|
3930
|
-
function resolveStatisticProps(props, theme) {
|
|
3931
|
-
const defaults = getStatisticDefaults(theme);
|
|
3932
|
-
return mergeWithDefaults(props, defaults);
|
|
3933
|
-
}
|
|
3934
|
-
function resolveColumnsProps(props, theme) {
|
|
3935
|
-
const defaults = getColumnsDefaults(theme);
|
|
3936
|
-
return mergeWithDefaults(props, defaults);
|
|
3937
|
-
}
|
|
3938
|
-
function resolveListProps(props, theme) {
|
|
3939
|
-
const defaults = getListDefaults(theme);
|
|
3940
|
-
return mergeWithDefaults(props, defaults);
|
|
3941
|
-
}
|
|
3942
|
-
|
|
3943
4017
|
// src/core/content.ts
|
|
3944
4018
|
import {
|
|
3945
4019
|
Paragraph,
|
|
@@ -5153,35 +5227,28 @@ function createFooterElement(children, _options) {
|
|
|
5153
5227
|
// src/components/heading.ts
|
|
5154
5228
|
function renderHeadingComponent(component, theme, themeName) {
|
|
5155
5229
|
if (!isHeadingComponent(component)) return [];
|
|
5156
|
-
const
|
|
5157
|
-
const
|
|
5158
|
-
const levelDefaults = getHeadingDefaultsForLevel(theme, level);
|
|
5159
|
-
const finalConfig = {
|
|
5160
|
-
...resolvedConfig,
|
|
5161
|
-
// Only apply level defaults if no explicit alignment was provided in the original props
|
|
5162
|
-
...component.props.alignment ? {} : levelDefaults
|
|
5163
|
-
};
|
|
5164
|
-
const bookmarkId = component.id || globalBookmarkRegistry.generateId(finalConfig.text, "heading");
|
|
5230
|
+
const config = component.props;
|
|
5231
|
+
const bookmarkId = component.id || globalBookmarkRegistry.generateId(config.text, "heading");
|
|
5165
5232
|
const header = createHeading(
|
|
5166
|
-
|
|
5167
|
-
|
|
5233
|
+
config.text,
|
|
5234
|
+
config.level || 1,
|
|
5168
5235
|
theme,
|
|
5169
5236
|
themeName,
|
|
5170
5237
|
{
|
|
5171
|
-
alignment:
|
|
5172
|
-
spacing:
|
|
5173
|
-
lineSpacing:
|
|
5174
|
-
columnBreak:
|
|
5238
|
+
alignment: config.alignment,
|
|
5239
|
+
spacing: config.spacing,
|
|
5240
|
+
lineSpacing: config.lineSpacing,
|
|
5241
|
+
columnBreak: config.columnBreak,
|
|
5175
5242
|
// Local font overrides
|
|
5176
|
-
fontFamily:
|
|
5177
|
-
fontSize:
|
|
5178
|
-
fontColor:
|
|
5179
|
-
bold:
|
|
5180
|
-
italic:
|
|
5181
|
-
underline:
|
|
5243
|
+
fontFamily: config.font?.family,
|
|
5244
|
+
fontSize: config.font?.size,
|
|
5245
|
+
fontColor: config.font?.color,
|
|
5246
|
+
bold: config.font?.bold,
|
|
5247
|
+
italic: config.font?.italic,
|
|
5248
|
+
underline: config.font?.underline,
|
|
5182
5249
|
// Pagination control
|
|
5183
|
-
keepNext:
|
|
5184
|
-
keepLines:
|
|
5250
|
+
keepNext: config.keepNext,
|
|
5251
|
+
keepLines: config.keepLines,
|
|
5185
5252
|
// Bookmark ID for internal linking
|
|
5186
5253
|
bookmarkId
|
|
5187
5254
|
}
|
|
@@ -5226,7 +5293,7 @@ function parseMarkdownList(text) {
|
|
|
5226
5293
|
}
|
|
5227
5294
|
function renderParagraphComponent(component, theme, themeName) {
|
|
5228
5295
|
if (!isParagraphComponent(component)) return [];
|
|
5229
|
-
const resolvedConfig =
|
|
5296
|
+
const resolvedConfig = component.props;
|
|
5230
5297
|
const listData = parseMarkdownList(resolvedConfig.text);
|
|
5231
5298
|
if (listData) {
|
|
5232
5299
|
const reference = globalNumberingRegistry.generateReference("markdown-list");
|
|
@@ -5411,7 +5478,7 @@ function fillMissingLevels(levels, maxLevel) {
|
|
|
5411
5478
|
}
|
|
5412
5479
|
function renderListComponent(component, theme, themeName) {
|
|
5413
5480
|
if (!isListComponent(component)) return [];
|
|
5414
|
-
const resolvedConfig =
|
|
5481
|
+
const resolvedConfig = component.props;
|
|
5415
5482
|
const maxLevel = getMaxLevelFromItems(resolvedConfig.items);
|
|
5416
5483
|
const reference = resolvedConfig.reference || globalNumberingRegistry.generateReference("list");
|
|
5417
5484
|
if (!globalNumberingRegistry.has(reference)) {
|
|
@@ -5442,7 +5509,7 @@ function renderListComponent(component, theme, themeName) {
|
|
|
5442
5509
|
// src/components/image.ts
|
|
5443
5510
|
async function renderImageComponent(component, theme, themeName) {
|
|
5444
5511
|
if (!isImageComponent(component)) return [];
|
|
5445
|
-
const resolvedConfig =
|
|
5512
|
+
const resolvedConfig = component.props;
|
|
5446
5513
|
const imageSource = resolvedConfig.base64 || resolvedConfig.path;
|
|
5447
5514
|
if (!imageSource) {
|
|
5448
5515
|
throw new Error(
|
|
@@ -5802,7 +5869,6 @@ async function renderColumnsComponent(component, theme, themeName, context) {
|
|
|
5802
5869
|
if (context.parent && isTextBoxComponent(context.parent)) {
|
|
5803
5870
|
return await renderColumnsAsTable(component, theme, themeName, context);
|
|
5804
5871
|
}
|
|
5805
|
-
resolveColumnsProps(component.props, theme);
|
|
5806
5872
|
const elements = [];
|
|
5807
5873
|
if (component.children) {
|
|
5808
5874
|
for (const child of component.children) {
|
|
@@ -5914,9 +5980,9 @@ async function renderColumnsAsTable(component, theme, themeName, context) {
|
|
|
5914
5980
|
}
|
|
5915
5981
|
|
|
5916
5982
|
// src/components/statistic.ts
|
|
5917
|
-
function renderStatisticComponent(component,
|
|
5983
|
+
function renderStatisticComponent(component, _theme) {
|
|
5918
5984
|
if (!isStatisticComponent(component)) return [];
|
|
5919
|
-
const resolvedConfig =
|
|
5985
|
+
const resolvedConfig = component.props;
|
|
5920
5986
|
return createStatistic(
|
|
5921
5987
|
{
|
|
5922
5988
|
number: resolvedConfig.number,
|
|
@@ -6078,27 +6144,33 @@ function hasNodeBuiltins() {
|
|
|
6078
6144
|
|
|
6079
6145
|
// src/components/highcharts.ts
|
|
6080
6146
|
var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
|
|
6081
|
-
function getExportServerUrl(propsUrl) {
|
|
6082
|
-
|
|
6147
|
+
function getExportServerUrl(propsUrl, servicesUrl) {
|
|
6148
|
+
const raw = propsUrl || servicesUrl || DEFAULT_EXPORT_SERVER_URL;
|
|
6149
|
+
return raw.startsWith("http") ? raw : `http://${raw}`;
|
|
6083
6150
|
}
|
|
6084
|
-
async function generateChart(config) {
|
|
6151
|
+
async function generateChart(config, servicesConfig) {
|
|
6085
6152
|
if (!isNodeEnvironment()) {
|
|
6086
6153
|
throw new Error(
|
|
6087
6154
|
"Highcharts export server requires a Node.js environment. Chart generation is not available in browser environments."
|
|
6088
6155
|
);
|
|
6089
6156
|
}
|
|
6090
|
-
const serverUrl = getExportServerUrl(
|
|
6157
|
+
const serverUrl = getExportServerUrl(
|
|
6158
|
+
config.serverUrl,
|
|
6159
|
+
servicesConfig?.serverUrl
|
|
6160
|
+
);
|
|
6091
6161
|
const requestBody = {
|
|
6092
6162
|
infile: config.options,
|
|
6093
6163
|
type: "png",
|
|
6094
6164
|
b64: true,
|
|
6095
6165
|
scale: config.scale
|
|
6096
6166
|
};
|
|
6167
|
+
const headers = {
|
|
6168
|
+
"Content-Type": "application/json",
|
|
6169
|
+
...servicesConfig?.headers
|
|
6170
|
+
};
|
|
6097
6171
|
const response = await fetch(`${serverUrl}/export`, {
|
|
6098
6172
|
method: "POST",
|
|
6099
|
-
headers
|
|
6100
|
-
"Content-Type": "application/json"
|
|
6101
|
-
},
|
|
6173
|
+
headers,
|
|
6102
6174
|
body: JSON.stringify(requestBody)
|
|
6103
6175
|
}).catch((error) => {
|
|
6104
6176
|
throw new Error(
|
|
@@ -6121,10 +6193,13 @@ Cause: ${error instanceof Error ? error.message : String(error)}`
|
|
|
6121
6193
|
height
|
|
6122
6194
|
};
|
|
6123
6195
|
}
|
|
6124
|
-
async function renderHighchartsComponent(component, theme, themeName) {
|
|
6196
|
+
async function renderHighchartsComponent(component, theme, themeName, context) {
|
|
6125
6197
|
if (!isHighchartsComponent(component)) return [];
|
|
6126
6198
|
const config = component.props;
|
|
6127
|
-
const chartResult = await generateChart(
|
|
6199
|
+
const chartResult = await generateChart(
|
|
6200
|
+
config,
|
|
6201
|
+
context?.services?.highcharts
|
|
6202
|
+
);
|
|
6128
6203
|
const hasConfigDimensions = config.width !== void 0 || config.height !== void 0;
|
|
6129
6204
|
const renderWidth = hasConfigDimensions ? config.width : chartResult.width;
|
|
6130
6205
|
const renderHeight = hasConfigDimensions ? config.height : chartResult.height;
|
|
@@ -6220,6 +6295,7 @@ async function renderDocument(structure, layout, options) {
|
|
|
6220
6295
|
structure.theme,
|
|
6221
6296
|
structure.themeName
|
|
6222
6297
|
);
|
|
6298
|
+
context.services = options?.services;
|
|
6223
6299
|
let sectionBookmarkCounter = 0;
|
|
6224
6300
|
let previousHeader = void 0;
|
|
6225
6301
|
let previousFooter = void 0;
|
|
@@ -6540,7 +6616,12 @@ async function renderComponent(component, theme, themeName, context) {
|
|
|
6540
6616
|
} else if (isTocComponent(component)) {
|
|
6541
6617
|
return renderTocComponent(component, theme, context);
|
|
6542
6618
|
} else if (isHighchartsComponent(component)) {
|
|
6543
|
-
return await renderHighchartsComponent(
|
|
6619
|
+
return await renderHighchartsComponent(
|
|
6620
|
+
component,
|
|
6621
|
+
theme,
|
|
6622
|
+
themeName,
|
|
6623
|
+
context
|
|
6624
|
+
);
|
|
6544
6625
|
} else if (isSectionComponent(component)) {
|
|
6545
6626
|
return await renderSectionComponent(component, theme, themeName, context);
|
|
6546
6627
|
}
|
|
@@ -6733,7 +6814,7 @@ async function generateFromConfig(props, components) {
|
|
|
6733
6814
|
};
|
|
6734
6815
|
return await generateDocument(reportComponent);
|
|
6735
6816
|
}
|
|
6736
|
-
async function generateDocumentWithCustomThemes(document, customThemes) {
|
|
6817
|
+
async function generateDocumentWithCustomThemes(document, customThemes, services) {
|
|
6737
6818
|
const themeName = document.props.theme || "minimal";
|
|
6738
6819
|
let theme;
|
|
6739
6820
|
if (customThemes) {
|
|
@@ -6756,8 +6837,8 @@ async function generateDocumentWithCustomThemes(document, customThemes) {
|
|
|
6756
6837
|
const structure = await processDocument(document, theme, themeName);
|
|
6757
6838
|
const layout = applyLayout(structure.sections, theme, themeName);
|
|
6758
6839
|
const renderedDocument = await renderDocument(structure, layout, {
|
|
6759
|
-
bypassCache: false
|
|
6760
|
-
|
|
6840
|
+
bypassCache: false,
|
|
6841
|
+
services
|
|
6761
6842
|
});
|
|
6762
6843
|
return renderedDocument;
|
|
6763
6844
|
}
|
|
@@ -6775,7 +6856,8 @@ async function generateDocumentFromJson(jsonConfig, options) {
|
|
|
6775
6856
|
const [reportComponent] = normalizeDocument(componentToConvert);
|
|
6776
6857
|
return await generateDocumentWithCustomThemes(
|
|
6777
6858
|
reportComponent,
|
|
6778
|
-
options?.customThemes
|
|
6859
|
+
options?.customThemes,
|
|
6860
|
+
options?.services
|
|
6779
6861
|
);
|
|
6780
6862
|
}
|
|
6781
6863
|
function validateJsonSchema(jsonConfig) {
|
|
@@ -7405,7 +7487,8 @@ function createBuilderImpl(state) {
|
|
|
7405
7487
|
theme: state.theme,
|
|
7406
7488
|
customThemes: state.customThemes,
|
|
7407
7489
|
debug: state.debug,
|
|
7408
|
-
enableCache: state.enableCache
|
|
7490
|
+
enableCache: state.enableCache,
|
|
7491
|
+
services: state.services
|
|
7409
7492
|
};
|
|
7410
7493
|
return createBuilderImpl(
|
|
7411
7494
|
newState
|
|
@@ -7437,7 +7520,9 @@ function createBuilderImpl(state) {
|
|
|
7437
7520
|
themeName
|
|
7438
7521
|
);
|
|
7439
7522
|
const layout = applyLayout(structure.sections, docTheme, themeName);
|
|
7440
|
-
const generatedDocument = await renderDocument(structure, layout
|
|
7523
|
+
const generatedDocument = await renderDocument(structure, layout, {
|
|
7524
|
+
services: state.services
|
|
7525
|
+
});
|
|
7441
7526
|
return {
|
|
7442
7527
|
document: generatedDocument,
|
|
7443
7528
|
warnings: warnings.length > 0 ? warnings : null
|
|
@@ -7552,7 +7637,8 @@ function createDocumentGenerator(options) {
|
|
|
7552
7637
|
theme: options.theme,
|
|
7553
7638
|
customThemes: options.customThemes,
|
|
7554
7639
|
debug: options.debug ?? false,
|
|
7555
|
-
enableCache: options.enableCache ?? false
|
|
7640
|
+
enableCache: options.enableCache ?? false,
|
|
7641
|
+
services: options.services
|
|
7556
7642
|
};
|
|
7557
7643
|
return createBuilderImpl(initialState);
|
|
7558
7644
|
}
|