@@ -40,41 +40,55 @@ export interface DecompressedData {
4040}
4141
4242async function loadMarkdownProcessingLibs ( ) {
43- const [ { ModelManager } , { TemplateMarkInterpreter } , { TemplateMarkTransformer } , { transform } ] =
44- await Promise . all ( [
45- import ( "@accordproject/concerto-core" ) ,
46- import ( "@accordproject/template-engine" ) ,
47- import ( "@accordproject/markdown-template" ) ,
48- import ( "@accordproject/markdown-transform" ) ,
49- ] ) ;
43+ try {
44+ const [ { ModelManager } , { TemplateMarkInterpreter } , { TemplateMarkTransformer } , { transform } ] =
45+ await Promise . all ( [
46+ import ( "@accordproject/concerto-core" ) ,
47+ import ( "@accordproject/template-engine" ) ,
48+ import ( "@accordproject/markdown-template" ) ,
49+ import ( "@accordproject/markdown-transform" ) ,
50+ ] ) ;
5051
51- return { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform } ;
52+ return { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform } ;
53+ } catch ( error ) {
54+ console . error ( "Failed to load Accord processing libraries:" , error ) ;
55+ throw new Error ( "Error loading Accord processing libraries" ) ;
56+ }
5257}
5358
5459const rebuild = debounce ( async ( template : string , model : string , dataString : string ) => {
55- const { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform } =
56- await loadMarkdownProcessingLibs ( ) ;
60+ try {
61+ const { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform } =
62+ await loadMarkdownProcessingLibs ( ) ;
63+
64+ const modelManager = new ModelManager ( { strict : true } ) ;
65+ modelManager . addCTOModel ( model , undefined , true ) ;
66+ await modelManager . updateExternalModels ( ) ;
67+
68+ const engine = new TemplateMarkInterpreter ( modelManager , { } ) ;
69+ const templateMarkTransformer = new TemplateMarkTransformer ( ) ;
5770
58- const modelManager = new ModelManager ( { strict : true } ) ;
59- modelManager . addCTOModel ( model , undefined , true ) ;
60- await modelManager . updateExternalModels ( ) ;
61- const engine = new TemplateMarkInterpreter ( modelManager , { } ) ;
62- const templateMarkTransformer = new TemplateMarkTransformer ( ) ;
63- const templateMarkDom = templateMarkTransformer . fromMarkdownTemplate (
64- { content : template } ,
65- modelManager ,
66- "contract" ,
67- { verbose : false }
68- ) ;
69- const data = JSON . parse ( dataString ) ;
70- const ciceroMark = await engine . generate ( templateMarkDom , data ) ;
71- return await transform (
72- ciceroMark . toJSON ( ) ,
73- "ciceromark_parsed" ,
74- [ "html" ] ,
75- { } ,
76- { verbose : false }
77- ) ;
71+ const templateMarkDom = templateMarkTransformer . fromMarkdownTemplate (
72+ { content : template } ,
73+ modelManager ,
74+ "contract" ,
75+ { verbose : false }
76+ ) ;
77+
78+ const data = JSON . parse ( dataString ) ;
79+
80+ const ciceroMark = await engine . generate ( templateMarkDom , data ) ;
81+ return await transform (
82+ ciceroMark . toJSON ( ) ,
83+ "ciceromark_parsed" ,
84+ [ "html" ] ,
85+ { } ,
86+ { verbose : false }
87+ ) ;
88+ } catch ( error ) {
89+ console . error ( "Error rebuilding the template:" , error ) ;
90+ throw new Error ( "Failed to process the template" ) ;
91+ }
7892} , 500 ) ;
7993
8094const useAppStore = create < AppState > ( ) (
0 commit comments