@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.
@@ -1,4 +1,5 @@
1
1
  import { type ThemeConfig } from '../styles';
2
+ import type { ServicesConfig } from '@json-to-office/shared';
2
3
  import type { DocumentGeneratorBuilder } from './types';
3
4
  /**
4
5
  * Options for creating a document generator
@@ -12,6 +13,8 @@ export interface DocumentGeneratorOptions {
12
13
  enableCache?: boolean;
13
14
  /** Enable debug logging */
14
15
  debug?: boolean;
16
+ /** External service configuration (e.g. Highcharts export server) */
17
+ services?: ServicesConfig;
15
18
  }
16
19
  /**
17
20
  * Create a document generator with chainable component registration.
@@ -1 +1 @@
1
- {"version":3,"file":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAwB,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EAEV,wBAAwB,EAKzB,MAAM,SAAS,CAAC;AAcjB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3C,4CAA4C;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA8bD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAWvC"}
1
+ {"version":3,"file":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAwB,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAEV,wBAAwB,EAKzB,MAAM,SAAS,CAAC;AAcjB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3C,4CAA4C;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAkcD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAYvC"}
@@ -6062,27 +6062,33 @@ function isNodeEnvironment() {
6062
6062
 
6063
6063
  // src/components/highcharts.ts
6064
6064
  var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
6065
- function getExportServerUrl(propsUrl) {
6066
- return propsUrl || process.env.HIGHCHARTS_SERVER_URL || DEFAULT_EXPORT_SERVER_URL;
6065
+ function getExportServerUrl(propsUrl, servicesUrl) {
6066
+ const raw = propsUrl || servicesUrl || DEFAULT_EXPORT_SERVER_URL;
6067
+ return raw.startsWith("http") ? raw : `http://${raw}`;
6067
6068
  }
6068
- async function generateChart(config) {
6069
+ async function generateChart(config, servicesConfig) {
6069
6070
  if (!isNodeEnvironment()) {
6070
6071
  throw new Error(
6071
6072
  "Highcharts export server requires a Node.js environment. Chart generation is not available in browser environments."
6072
6073
  );
6073
6074
  }
6074
- const serverUrl = getExportServerUrl(config.serverUrl);
6075
+ const serverUrl = getExportServerUrl(
6076
+ config.serverUrl,
6077
+ servicesConfig?.serverUrl
6078
+ );
6075
6079
  const requestBody = {
6076
6080
  infile: config.options,
6077
6081
  type: "png",
6078
6082
  b64: true,
6079
6083
  scale: config.scale
6080
6084
  };
6085
+ const headers = {
6086
+ "Content-Type": "application/json",
6087
+ ...servicesConfig?.headers
6088
+ };
6081
6089
  const response = await fetch(`${serverUrl}/export`, {
6082
6090
  method: "POST",
6083
- headers: {
6084
- "Content-Type": "application/json"
6085
- },
6091
+ headers,
6086
6092
  body: JSON.stringify(requestBody)
6087
6093
  }).catch((error) => {
6088
6094
  throw new Error(
@@ -6105,10 +6111,13 @@ Cause: ${error instanceof Error ? error.message : String(error)}`
6105
6111
  height
6106
6112
  };
6107
6113
  }
6108
- async function renderHighchartsComponent(component, theme, themeName) {
6114
+ async function renderHighchartsComponent(component, theme, themeName, context) {
6109
6115
  if (!isHighchartsComponent(component)) return [];
6110
6116
  const config = component.props;
6111
- const chartResult = await generateChart(config);
6117
+ const chartResult = await generateChart(
6118
+ config,
6119
+ context?.services?.highcharts
6120
+ );
6112
6121
  const hasConfigDimensions = config.width !== void 0 || config.height !== void 0;
6113
6122
  const renderWidth = hasConfigDimensions ? config.width : chartResult.width;
6114
6123
  const renderHeight = hasConfigDimensions ? config.height : chartResult.height;
@@ -6204,6 +6213,7 @@ async function renderDocument(structure, layout, options) {
6204
6213
  structure.theme,
6205
6214
  structure.themeName
6206
6215
  );
6216
+ context.services = options?.services;
6207
6217
  let sectionBookmarkCounter = 0;
6208
6218
  let previousHeader = void 0;
6209
6219
  let previousFooter = void 0;
@@ -6524,7 +6534,12 @@ async function renderComponent(component, theme, themeName, context) {
6524
6534
  } else if (isTocComponent(component)) {
6525
6535
  return renderTocComponent(component, theme, context);
6526
6536
  } else if (isHighchartsComponent(component)) {
6527
- return await renderHighchartsComponent(component, theme, themeName);
6537
+ return await renderHighchartsComponent(
6538
+ component,
6539
+ theme,
6540
+ themeName,
6541
+ context
6542
+ );
6528
6543
  } else if (isSectionComponent(component)) {
6529
6544
  return await renderSectionComponent(component, theme, themeName, context);
6530
6545
  }
@@ -6746,7 +6761,8 @@ function createBuilderImpl(state) {
6746
6761
  theme: state.theme,
6747
6762
  customThemes: state.customThemes,
6748
6763
  debug: state.debug,
6749
- enableCache: state.enableCache
6764
+ enableCache: state.enableCache,
6765
+ services: state.services
6750
6766
  };
6751
6767
  return createBuilderImpl(
6752
6768
  newState
@@ -6778,7 +6794,9 @@ function createBuilderImpl(state) {
6778
6794
  themeName
6779
6795
  );
6780
6796
  const layout = applyLayout(structure.sections, docTheme, themeName);
6781
- const generatedDocument = await renderDocument(structure, layout);
6797
+ const generatedDocument = await renderDocument(structure, layout, {
6798
+ services: state.services
6799
+ });
6782
6800
  return {
6783
6801
  document: generatedDocument,
6784
6802
  warnings: warnings.length > 0 ? warnings : null
@@ -6893,7 +6911,8 @@ function createDocumentGenerator(options) {
6893
6911
  theme: options.theme,
6894
6912
  customThemes: options.customThemes,
6895
6913
  debug: options.debug ?? false,
6896
- enableCache: options.enableCache ?? false
6914
+ enableCache: options.enableCache ?? false,
6915
+ services: options.services
6897
6916
  };
6898
6917
  return createBuilderImpl(initialState);
6899
6918
  }