@json-to-office/core-docx 0.6.0 → 0.7.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/highcharts.d.ts +2 -2
- package/dist/components/highcharts.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/index.js +37 -17
- 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 +32 -13
- package/dist/plugin/example/index.js.map +1 -1
- 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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Standard component for generating charts using Highcharts Export Server
|
|
4
4
|
*/
|
|
5
5
|
import { Paragraph, Table } from 'docx';
|
|
6
|
-
import { ComponentDefinition } from '../types';
|
|
6
|
+
import { ComponentDefinition, RenderContext } from '../types';
|
|
7
7
|
import { ThemeConfig } from '../styles';
|
|
8
8
|
export type { HighchartsProps } from '@json-to-office/shared-docx';
|
|
9
9
|
/**
|
|
@@ -17,5 +17,5 @@ export interface ChartGenerationResult {
|
|
|
17
17
|
/**
|
|
18
18
|
* Render highcharts component
|
|
19
19
|
*/
|
|
20
|
-
export declare function renderHighchartsComponent(component: ComponentDefinition, theme: ThemeConfig, themeName: string): Promise<(Paragraph | Table)[]>;
|
|
20
|
+
export declare function renderHighchartsComponent(component: ComponentDefinition, theme: ThemeConfig, themeName: string, context?: RenderContext): Promise<(Paragraph | Table)[]>;
|
|
21
21
|
//# sourceMappingURL=highcharts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highcharts.d.ts","sourceRoot":"","sources":["../../src/components/highcharts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"highcharts.d.ts","sourceRoot":"","sources":["../../src/components/highcharts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,aAAa,EAEd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AASxC,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAuED;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CA+BhC"}
|
package/dist/core/generator.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { Document } from 'docx';
|
|
7
7
|
import { ComponentDefinition, ReportProps, ReportComponentDefinition } from '../types';
|
|
8
8
|
import { ThemeConfig } from '../styles';
|
|
9
|
+
import type { ServicesConfig } from '@json-to-office/shared';
|
|
9
10
|
import { DocumentValidationResult } from '@json-to-office/shared-docx';
|
|
10
11
|
export interface JsonGenerationOptions {
|
|
11
12
|
outputPath?: string;
|
|
@@ -16,6 +17,7 @@ export interface JsonGenerationOptions {
|
|
|
16
17
|
customThemes?: {
|
|
17
18
|
[key: string]: ThemeConfig;
|
|
18
19
|
};
|
|
20
|
+
services?: ServicesConfig;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Type guard to check if input is a report component definition
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EAAE,QAAQ,EAAU,MAAM,MAAM,CAAC;AAExC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,yBAAyB,EAE1B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAwB,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EAAE,QAAQ,EAAU,MAAM,MAAM,CAAC;AAExC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,yBAAyB,EAE1B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAwB,WAAW,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAMvE,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE;QACX,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,CAAC;IACF,YAAY,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,CAAC;IAC9C,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,OAAO,GAClB,UAAU,IAAI,yBAAyB,CASzC;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,yBAAyB,GAClC,OAAO,CAAC,QAAQ,CAAC,CAuBnB;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,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,CACnC,QAAQ,EAAE,yBAAyB,EACnC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAGf;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAErE;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAa7B,CAAC"}
|
package/dist/core/render.d.ts
CHANGED
|
@@ -8,12 +8,14 @@ import { ThemeConfig } from '../styles';
|
|
|
8
8
|
import { ProcessedDocument } from './structure';
|
|
9
9
|
import { LayoutPlan, SectionLayout } from './layout';
|
|
10
10
|
import { MemoryCache } from '../cache';
|
|
11
|
+
import type { ServicesConfig } from '@json-to-office/shared';
|
|
11
12
|
/**
|
|
12
13
|
* Render a complete document from structure and layout
|
|
13
14
|
*/
|
|
14
15
|
export declare function renderDocument(structure: ProcessedDocument, layout: LayoutPlan, options?: {
|
|
15
16
|
cache?: MemoryCache;
|
|
16
17
|
bypassCache?: boolean;
|
|
18
|
+
services?: ServicesConfig;
|
|
17
19
|
}): Promise<Document>;
|
|
18
20
|
/**
|
|
19
21
|
* Render a section with layout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/core/render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,QAAQ,EACR,SAAS,EACT,KAAK,EACL,eAAe,EACf,eAAe,EAKf,OAAO,EACR,MAAM,MAAM,CAAC;AAad,OAAO,EACL,mBAAmB,EACnB,aAAa,EAcd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAMxC,OAAO,EAAE,iBAAiB,EAAuB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU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AAG,KAAK,GAAG,eAAe,GAAG,OAAO,CAAC,EAAE,CAAC,CAiC5D"}
|
package/dist/index.js
CHANGED
|
@@ -6078,27 +6078,33 @@ function hasNodeBuiltins() {
|
|
|
6078
6078
|
|
|
6079
6079
|
// src/components/highcharts.ts
|
|
6080
6080
|
var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
|
|
6081
|
-
function getExportServerUrl(propsUrl) {
|
|
6082
|
-
|
|
6081
|
+
function getExportServerUrl(propsUrl, servicesUrl) {
|
|
6082
|
+
const raw = propsUrl || servicesUrl || DEFAULT_EXPORT_SERVER_URL;
|
|
6083
|
+
return raw.startsWith("http") ? raw : `http://${raw}`;
|
|
6083
6084
|
}
|
|
6084
|
-
async function generateChart(config) {
|
|
6085
|
+
async function generateChart(config, servicesConfig) {
|
|
6085
6086
|
if (!isNodeEnvironment()) {
|
|
6086
6087
|
throw new Error(
|
|
6087
6088
|
"Highcharts export server requires a Node.js environment. Chart generation is not available in browser environments."
|
|
6088
6089
|
);
|
|
6089
6090
|
}
|
|
6090
|
-
const serverUrl = getExportServerUrl(
|
|
6091
|
+
const serverUrl = getExportServerUrl(
|
|
6092
|
+
config.serverUrl,
|
|
6093
|
+
servicesConfig?.serverUrl
|
|
6094
|
+
);
|
|
6091
6095
|
const requestBody = {
|
|
6092
6096
|
infile: config.options,
|
|
6093
6097
|
type: "png",
|
|
6094
6098
|
b64: true,
|
|
6095
6099
|
scale: config.scale
|
|
6096
6100
|
};
|
|
6101
|
+
const headers = {
|
|
6102
|
+
"Content-Type": "application/json",
|
|
6103
|
+
...servicesConfig?.headers
|
|
6104
|
+
};
|
|
6097
6105
|
const response = await fetch(`${serverUrl}/export`, {
|
|
6098
6106
|
method: "POST",
|
|
6099
|
-
headers
|
|
6100
|
-
"Content-Type": "application/json"
|
|
6101
|
-
},
|
|
6107
|
+
headers,
|
|
6102
6108
|
body: JSON.stringify(requestBody)
|
|
6103
6109
|
}).catch((error) => {
|
|
6104
6110
|
throw new Error(
|
|
@@ -6121,10 +6127,13 @@ Cause: ${error instanceof Error ? error.message : String(error)}`
|
|
|
6121
6127
|
height
|
|
6122
6128
|
};
|
|
6123
6129
|
}
|
|
6124
|
-
async function renderHighchartsComponent(component, theme, themeName) {
|
|
6130
|
+
async function renderHighchartsComponent(component, theme, themeName, context) {
|
|
6125
6131
|
if (!isHighchartsComponent(component)) return [];
|
|
6126
6132
|
const config = component.props;
|
|
6127
|
-
const chartResult = await generateChart(
|
|
6133
|
+
const chartResult = await generateChart(
|
|
6134
|
+
config,
|
|
6135
|
+
context?.services?.highcharts
|
|
6136
|
+
);
|
|
6128
6137
|
const hasConfigDimensions = config.width !== void 0 || config.height !== void 0;
|
|
6129
6138
|
const renderWidth = hasConfigDimensions ? config.width : chartResult.width;
|
|
6130
6139
|
const renderHeight = hasConfigDimensions ? config.height : chartResult.height;
|
|
@@ -6220,6 +6229,7 @@ async function renderDocument(structure, layout, options) {
|
|
|
6220
6229
|
structure.theme,
|
|
6221
6230
|
structure.themeName
|
|
6222
6231
|
);
|
|
6232
|
+
context.services = options?.services;
|
|
6223
6233
|
let sectionBookmarkCounter = 0;
|
|
6224
6234
|
let previousHeader = void 0;
|
|
6225
6235
|
let previousFooter = void 0;
|
|
@@ -6540,7 +6550,12 @@ async function renderComponent(component, theme, themeName, context) {
|
|
|
6540
6550
|
} else if (isTocComponent(component)) {
|
|
6541
6551
|
return renderTocComponent(component, theme, context);
|
|
6542
6552
|
} else if (isHighchartsComponent(component)) {
|
|
6543
|
-
return await renderHighchartsComponent(
|
|
6553
|
+
return await renderHighchartsComponent(
|
|
6554
|
+
component,
|
|
6555
|
+
theme,
|
|
6556
|
+
themeName,
|
|
6557
|
+
context
|
|
6558
|
+
);
|
|
6544
6559
|
} else if (isSectionComponent(component)) {
|
|
6545
6560
|
return await renderSectionComponent(component, theme, themeName, context);
|
|
6546
6561
|
}
|
|
@@ -6733,7 +6748,7 @@ async function generateFromConfig(props, components) {
|
|
|
6733
6748
|
};
|
|
6734
6749
|
return await generateDocument(reportComponent);
|
|
6735
6750
|
}
|
|
6736
|
-
async function generateDocumentWithCustomThemes(document, customThemes) {
|
|
6751
|
+
async function generateDocumentWithCustomThemes(document, customThemes, services) {
|
|
6737
6752
|
const themeName = document.props.theme || "minimal";
|
|
6738
6753
|
let theme;
|
|
6739
6754
|
if (customThemes) {
|
|
@@ -6756,8 +6771,8 @@ async function generateDocumentWithCustomThemes(document, customThemes) {
|
|
|
6756
6771
|
const structure = await processDocument(document, theme, themeName);
|
|
6757
6772
|
const layout = applyLayout(structure.sections, theme, themeName);
|
|
6758
6773
|
const renderedDocument = await renderDocument(structure, layout, {
|
|
6759
|
-
bypassCache: false
|
|
6760
|
-
|
|
6774
|
+
bypassCache: false,
|
|
6775
|
+
services
|
|
6761
6776
|
});
|
|
6762
6777
|
return renderedDocument;
|
|
6763
6778
|
}
|
|
@@ -6775,7 +6790,8 @@ async function generateDocumentFromJson(jsonConfig, options) {
|
|
|
6775
6790
|
const [reportComponent] = normalizeDocument(componentToConvert);
|
|
6776
6791
|
return await generateDocumentWithCustomThemes(
|
|
6777
6792
|
reportComponent,
|
|
6778
|
-
options?.customThemes
|
|
6793
|
+
options?.customThemes,
|
|
6794
|
+
options?.services
|
|
6779
6795
|
);
|
|
6780
6796
|
}
|
|
6781
6797
|
function validateJsonSchema(jsonConfig) {
|
|
@@ -7405,7 +7421,8 @@ function createBuilderImpl(state) {
|
|
|
7405
7421
|
theme: state.theme,
|
|
7406
7422
|
customThemes: state.customThemes,
|
|
7407
7423
|
debug: state.debug,
|
|
7408
|
-
enableCache: state.enableCache
|
|
7424
|
+
enableCache: state.enableCache,
|
|
7425
|
+
services: state.services
|
|
7409
7426
|
};
|
|
7410
7427
|
return createBuilderImpl(
|
|
7411
7428
|
newState
|
|
@@ -7437,7 +7454,9 @@ function createBuilderImpl(state) {
|
|
|
7437
7454
|
themeName
|
|
7438
7455
|
);
|
|
7439
7456
|
const layout = applyLayout(structure.sections, docTheme, themeName);
|
|
7440
|
-
const generatedDocument = await renderDocument(structure, layout
|
|
7457
|
+
const generatedDocument = await renderDocument(structure, layout, {
|
|
7458
|
+
services: state.services
|
|
7459
|
+
});
|
|
7441
7460
|
return {
|
|
7442
7461
|
document: generatedDocument,
|
|
7443
7462
|
warnings: warnings.length > 0 ? warnings : null
|
|
@@ -7552,7 +7571,8 @@ function createDocumentGenerator(options) {
|
|
|
7552
7571
|
theme: options.theme,
|
|
7553
7572
|
customThemes: options.customThemes,
|
|
7554
7573
|
debug: options.debug ?? false,
|
|
7555
|
-
enableCache: options.enableCache ?? false
|
|
7574
|
+
enableCache: options.enableCache ?? false,
|
|
7575
|
+
services: options.services
|
|
7556
7576
|
};
|
|
7557
7577
|
return createBuilderImpl(initialState);
|
|
7558
7578
|
}
|