@json-to-office/core-docx 0.12.0 → 0.13.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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -55
- package/dist/index.js.map +1 -1
- package/dist/plugin/createDocumentGenerator.d.ts.map +1 -1
- package/dist/plugin/example/index.js +92 -55
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/plugin/index.d.ts +2 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +59 -6
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/validation.d.ts +1 -1
- package/dist/plugin/validation.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -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,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9E,OAAO,KAAK,EAEV,wBAAwB,
|
|
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,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9E,OAAO,KAAK,EAEV,wBAAwB,EAOzB,MAAM,SAAS,CAAC;AAejB;;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;IAC1B,oFAAoF;IACpF,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB;AAiiBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAavC"}
|
|
@@ -1888,7 +1888,8 @@ import {
|
|
|
1888
1888
|
} from "@json-to-office/shared-docx/validation/unified";
|
|
1889
1889
|
import {
|
|
1890
1890
|
DuplicateComponentError,
|
|
1891
|
-
ComponentValidationError as ComponentValidationError2
|
|
1891
|
+
ComponentValidationError as ComponentValidationError2,
|
|
1892
|
+
UnknownPreservedComponentError
|
|
1892
1893
|
} from "@json-to-office/shared/plugin";
|
|
1893
1894
|
function validateComponentProps(schema, props, componentName) {
|
|
1894
1895
|
return validateCustomComponentProps(schema.propsSchema, props, {
|
|
@@ -1955,6 +1956,9 @@ function getValidatedProps(schema, props) {
|
|
|
1955
1956
|
}
|
|
1956
1957
|
var cleanComponentProps = getValidatedProps;
|
|
1957
1958
|
|
|
1959
|
+
// src/plugin/createDocumentGenerator.ts
|
|
1960
|
+
import { UnknownPreservedComponentError as UnknownPreservedComponentError2 } from "@json-to-office/shared/plugin";
|
|
1961
|
+
|
|
1958
1962
|
// src/plugin/schema.ts
|
|
1959
1963
|
import { Type } from "@sinclair/typebox";
|
|
1960
1964
|
import { latestVersion } from "@json-to-office/shared-docx";
|
|
@@ -6829,17 +6833,19 @@ function createBuilderImpl(state) {
|
|
|
6829
6833
|
}
|
|
6830
6834
|
return getThemeWithFallback(themeName);
|
|
6831
6835
|
}
|
|
6832
|
-
async function processDocumentComponents(components, warningsCollector, resolvedTheme, depth = 0) {
|
|
6836
|
+
async function processDocumentComponents(components, preserveSet, warningsCollector, resolvedTheme, depth = 0) {
|
|
6833
6837
|
if (depth > 20) {
|
|
6834
6838
|
throw new Error(
|
|
6835
6839
|
"Maximum component nesting depth exceeded (20). Check for circular component references."
|
|
6836
6840
|
);
|
|
6837
6841
|
}
|
|
6838
|
-
const
|
|
6842
|
+
const standardOut = [];
|
|
6843
|
+
const preservedOut = [];
|
|
6839
6844
|
for (const componentData of components) {
|
|
6840
6845
|
const componentName = componentData?.name;
|
|
6841
6846
|
if (!componentName) {
|
|
6842
|
-
|
|
6847
|
+
standardOut.push(componentData);
|
|
6848
|
+
preservedOut.push(componentData);
|
|
6843
6849
|
continue;
|
|
6844
6850
|
}
|
|
6845
6851
|
const customComponent = componentMap.get(componentName);
|
|
@@ -6862,12 +6868,14 @@ function createBuilderImpl(state) {
|
|
|
6862
6868
|
);
|
|
6863
6869
|
let nestedChildren;
|
|
6864
6870
|
if (componentWithName.children && Array.isArray(componentWithName.children)) {
|
|
6865
|
-
|
|
6871
|
+
const nested = await processDocumentComponents(
|
|
6866
6872
|
componentWithName.children,
|
|
6873
|
+
preserveSet,
|
|
6867
6874
|
warningsCollector,
|
|
6868
6875
|
resolvedTheme,
|
|
6869
6876
|
depth + 1
|
|
6870
6877
|
);
|
|
6878
|
+
nestedChildren = nested.standard;
|
|
6871
6879
|
}
|
|
6872
6880
|
const versionLabel = componentWithName.version ? `${customComponent.name}@${componentWithName.version}` : customComponent.name;
|
|
6873
6881
|
const addWarning = (message, context) => {
|
|
@@ -6887,15 +6895,21 @@ function createBuilderImpl(state) {
|
|
|
6887
6895
|
const resultComponents = Array.isArray(result) ? result : [result];
|
|
6888
6896
|
const processedResult = await processDocumentComponents(
|
|
6889
6897
|
resultComponents,
|
|
6898
|
+
preserveSet,
|
|
6890
6899
|
warningsCollector,
|
|
6891
6900
|
resolvedTheme,
|
|
6892
6901
|
depth + 1
|
|
6893
6902
|
);
|
|
6894
|
-
|
|
6903
|
+
standardOut.push(...processedResult.standard);
|
|
6904
|
+
if (preserveSet && preserveSet.has(componentName)) {
|
|
6905
|
+
preservedOut.push(componentData);
|
|
6906
|
+
} else {
|
|
6907
|
+
preservedOut.push(...processedResult.preserved);
|
|
6908
|
+
}
|
|
6895
6909
|
if (state.debug) {
|
|
6896
6910
|
console.log(
|
|
6897
6911
|
`Processed custom component '${versionLabel}':`,
|
|
6898
|
-
processedResult
|
|
6912
|
+
processedResult.standard
|
|
6899
6913
|
);
|
|
6900
6914
|
}
|
|
6901
6915
|
} catch (error) {
|
|
@@ -6910,20 +6924,26 @@ function createBuilderImpl(state) {
|
|
|
6910
6924
|
if ("children" in componentData && Array.isArray(componentData.children)) {
|
|
6911
6925
|
const processedNested = await processDocumentComponents(
|
|
6912
6926
|
componentData.children,
|
|
6927
|
+
preserveSet,
|
|
6913
6928
|
warningsCollector,
|
|
6914
6929
|
resolvedTheme,
|
|
6915
6930
|
depth + 1
|
|
6916
6931
|
);
|
|
6917
|
-
|
|
6932
|
+
standardOut.push({
|
|
6933
|
+
...componentData,
|
|
6934
|
+
children: processedNested.standard
|
|
6935
|
+
});
|
|
6936
|
+
preservedOut.push({
|
|
6918
6937
|
...componentData,
|
|
6919
|
-
children: processedNested
|
|
6938
|
+
children: processedNested.preserved
|
|
6920
6939
|
});
|
|
6921
6940
|
} else {
|
|
6922
|
-
|
|
6941
|
+
standardOut.push(componentData);
|
|
6942
|
+
preservedOut.push(componentData);
|
|
6923
6943
|
}
|
|
6924
6944
|
}
|
|
6925
6945
|
}
|
|
6926
|
-
return
|
|
6946
|
+
return { standard: standardOut, preserved: preservedOut };
|
|
6927
6947
|
}
|
|
6928
6948
|
function addComponent(component) {
|
|
6929
6949
|
if (!component.name) {
|
|
@@ -6948,8 +6968,24 @@ function createBuilderImpl(state) {
|
|
|
6948
6968
|
newState
|
|
6949
6969
|
);
|
|
6950
6970
|
}
|
|
6951
|
-
|
|
6971
|
+
function resolvePreserveSet(options) {
|
|
6972
|
+
const list = options?.preserveCustomComponents;
|
|
6973
|
+
if (!list || list.length === 0) {
|
|
6974
|
+
return void 0;
|
|
6975
|
+
}
|
|
6976
|
+
const registered = new Set(state.componentNames);
|
|
6977
|
+
const unknown = list.filter((n) => !registered.has(n));
|
|
6978
|
+
if (unknown.length > 0) {
|
|
6979
|
+
throw new UnknownPreservedComponentError2(
|
|
6980
|
+
unknown,
|
|
6981
|
+
Array.from(state.componentNames)
|
|
6982
|
+
);
|
|
6983
|
+
}
|
|
6984
|
+
return new Set(list);
|
|
6985
|
+
}
|
|
6986
|
+
async function generate(document, options) {
|
|
6952
6987
|
try {
|
|
6988
|
+
const preserveSet = resolvePreserveSet(options);
|
|
6953
6989
|
const internalDocument = document;
|
|
6954
6990
|
validateDocument(
|
|
6955
6991
|
internalDocument,
|
|
@@ -6973,14 +7009,15 @@ function createBuilderImpl(state) {
|
|
|
6973
7009
|
context: { code: w.code }
|
|
6974
7010
|
});
|
|
6975
7011
|
}
|
|
6976
|
-
const
|
|
7012
|
+
const processed = await processDocumentComponents(
|
|
6977
7013
|
mode.doc.children || [],
|
|
7014
|
+
preserveSet,
|
|
6978
7015
|
warnings,
|
|
6979
7016
|
modedTheme
|
|
6980
7017
|
);
|
|
6981
7018
|
const processedDocument = {
|
|
6982
7019
|
...mode.doc,
|
|
6983
|
-
children:
|
|
7020
|
+
children: processed.standard
|
|
6984
7021
|
};
|
|
6985
7022
|
const [modedDoc] = normalizeDocument(processedDocument);
|
|
6986
7023
|
await resolveDocumentFonts(modedDoc, modedTheme, state.fonts, warnings);
|
|
@@ -6989,9 +7026,15 @@ function createBuilderImpl(state) {
|
|
|
6989
7026
|
const generatedDocument = await renderDocument(structure, layout, {
|
|
6990
7027
|
services: state.services
|
|
6991
7028
|
});
|
|
7029
|
+
const preservedDefinition = preserveSet ? {
|
|
7030
|
+
...mode.doc,
|
|
7031
|
+
children: processed.preserved
|
|
7032
|
+
} : void 0;
|
|
6992
7033
|
return {
|
|
6993
7034
|
document: generatedDocument,
|
|
6994
|
-
warnings: warnings.length > 0 ? warnings : null
|
|
7035
|
+
warnings: warnings.length > 0 ? warnings : null,
|
|
7036
|
+
standardDefinition: modedDoc,
|
|
7037
|
+
preservedDefinition
|
|
6995
7038
|
};
|
|
6996
7039
|
} catch (error) {
|
|
6997
7040
|
if (state.debug) {
|
|
@@ -7000,16 +7043,40 @@ function createBuilderImpl(state) {
|
|
|
7000
7043
|
throw error;
|
|
7001
7044
|
}
|
|
7002
7045
|
}
|
|
7003
|
-
async function generateBuffer(document) {
|
|
7004
|
-
const {
|
|
7046
|
+
async function generateBuffer(document, options) {
|
|
7047
|
+
const {
|
|
7048
|
+
document: doc,
|
|
7049
|
+
warnings,
|
|
7050
|
+
standardDefinition,
|
|
7051
|
+
preservedDefinition
|
|
7052
|
+
} = await generate(document, options);
|
|
7005
7053
|
const buffer = await Packer.toBuffer(doc);
|
|
7006
|
-
return { buffer, warnings };
|
|
7054
|
+
return { buffer, warnings, standardDefinition, preservedDefinition };
|
|
7007
7055
|
}
|
|
7008
|
-
async function generateFile(document, outputPath) {
|
|
7009
|
-
const { buffer, warnings } = await generateBuffer(document);
|
|
7056
|
+
async function generateFile(document, outputPath, options) {
|
|
7057
|
+
const { buffer, warnings, standardDefinition, preservedDefinition } = await generateBuffer(document, options);
|
|
7010
7058
|
const fs4 = await import("fs/promises");
|
|
7011
7059
|
await fs4.writeFile(outputPath, new Uint8Array(buffer));
|
|
7012
|
-
|
|
7060
|
+
let preservedOutputPath;
|
|
7061
|
+
if (preservedDefinition !== void 0) {
|
|
7062
|
+
const path3 = await import("path");
|
|
7063
|
+
preservedOutputPath = options?.preservedOutputPath ?? (() => {
|
|
7064
|
+
const ext = path3.extname(outputPath);
|
|
7065
|
+
const base = ext ? outputPath.slice(0, -ext.length) : outputPath;
|
|
7066
|
+
return `${base}-preserved.json`;
|
|
7067
|
+
})();
|
|
7068
|
+
await fs4.writeFile(
|
|
7069
|
+
preservedOutputPath,
|
|
7070
|
+
JSON.stringify(preservedDefinition, null, 2),
|
|
7071
|
+
"utf8"
|
|
7072
|
+
);
|
|
7073
|
+
}
|
|
7074
|
+
return {
|
|
7075
|
+
warnings,
|
|
7076
|
+
standardDefinition,
|
|
7077
|
+
preservedDefinition,
|
|
7078
|
+
preservedOutputPath
|
|
7079
|
+
};
|
|
7013
7080
|
}
|
|
7014
7081
|
function getComponentNames() {
|
|
7015
7082
|
return Array.from(state.componentNames);
|
|
@@ -7043,6 +7110,10 @@ function createBuilderImpl(state) {
|
|
|
7043
7110
|
};
|
|
7044
7111
|
}
|
|
7045
7112
|
}
|
|
7113
|
+
async function getStandardComponentsDefinition(document) {
|
|
7114
|
+
const { standardDefinition } = await generate(document);
|
|
7115
|
+
return standardDefinition;
|
|
7116
|
+
}
|
|
7046
7117
|
function generateSchema(includeStandardComponents = true) {
|
|
7047
7118
|
return generatePluginDocumentSchema(
|
|
7048
7119
|
state.components,
|
|
@@ -7056,40 +7127,6 @@ function createBuilderImpl(state) {
|
|
|
7056
7127
|
options
|
|
7057
7128
|
);
|
|
7058
7129
|
}
|
|
7059
|
-
async function getStandardComponentsDefinition(document) {
|
|
7060
|
-
try {
|
|
7061
|
-
const internalDocument = document;
|
|
7062
|
-
validateDocument(
|
|
7063
|
-
internalDocument,
|
|
7064
|
-
state.components
|
|
7065
|
-
);
|
|
7066
|
-
const themeName = internalDocument.props.theme || "minimal";
|
|
7067
|
-
const docTheme = resolveDocumentTheme(themeName);
|
|
7068
|
-
const warnings = [];
|
|
7069
|
-
const mode = applyExportMode({
|
|
7070
|
-
doc: internalDocument,
|
|
7071
|
-
theme: docTheme,
|
|
7072
|
-
fonts: state.fonts
|
|
7073
|
-
});
|
|
7074
|
-
const modedTheme = mode.theme;
|
|
7075
|
-
const processedComponents = await processDocumentComponents(
|
|
7076
|
-
mode.doc.children || [],
|
|
7077
|
-
warnings,
|
|
7078
|
-
modedTheme
|
|
7079
|
-
);
|
|
7080
|
-
const processedDocument = {
|
|
7081
|
-
...mode.doc,
|
|
7082
|
-
children: processedComponents
|
|
7083
|
-
};
|
|
7084
|
-
const [finalReportComponent] = normalizeDocument(processedDocument);
|
|
7085
|
-
return finalReportComponent;
|
|
7086
|
-
} catch (error) {
|
|
7087
|
-
if (state.debug) {
|
|
7088
|
-
console.error("Error getting standard components definition:", error);
|
|
7089
|
-
}
|
|
7090
|
-
throw error;
|
|
7091
|
-
}
|
|
7092
|
-
}
|
|
7093
7130
|
return Object.freeze({
|
|
7094
7131
|
addComponent,
|
|
7095
7132
|
generate,
|