@@ -45,7 +45,12 @@ class Markdown extends Component {
4545 * @member {String|null} value_=null
4646 * @reactive
4747 */
48- value_ : null
48+ value_ : null ,
49+ /**
50+ * Optional windowUrl to pass to nested code.LivePreviews.
51+ * @member {String|null} windowUrl=null
52+ */
53+ windowUrl : null
4954 }
5055
5156 /**
@@ -86,20 +91,24 @@ class Markdown extends Component {
8691 // Clean up previous instances
8792 me . destroyComponents ( ) ;
8893
89- await me . render ( {
90- code : value ,
91- container : me ,
92- context : {
93- appName : me . appName ,
94- windowId : me . windowId ,
95- parentComponent : me
96- }
97- } ) ;
94+ await me . render ( { code : value } )
9895 }
9996 }
10097
98+ /**
99+ * Triggered after the windowId config got changed
100+ * @param {String|null } value
101+ * @param {String|null } oldValue
102+ * @protected
103+ */
104+ async afterSetWindowId ( value , oldValue ) {
105+ super . afterSetWindowId ( value , oldValue ) ;
106+ this . activeComponents . forEach ( component => component . windowId = value )
107+ }
108+
101109 /**
102110 * Destroy all created child instances
111+ * @param {...* } args
103112 */
104113 destroy ( ...args ) {
105114 this . destroyComponents ( ) ;
@@ -113,7 +122,7 @@ class Markdown extends Component {
113122 let me = this ;
114123
115124 me . activeComponents . forEach ( component => component . destroy ( ) ) ;
116- me . activeComponents = [ ] ;
125+ me . activeComponents = [ ]
117126 }
118127
119128 /**
@@ -247,22 +256,19 @@ class Markdown extends Component {
247256 * the actual Neo.mjs components, rendering them into the placeholder DIVs within the generated HTML.
248257 * @param {Object } data
249258 * @param {String } data.code
250- * @param {Neo.component.Base } data.container
251- * @param {Object } [data.context]
252259 * @returns {Promise<Object> }
253260 */
254- async render ( { code, container, context= { } } ) {
255- let me = this ,
256- content = code ,
257- neoComponents = { } ,
258- neoDivs = { } ,
259- parentComponent = context . parentComponent || container ,
260- baseConfigs = {
261- appName : context . appName ,
262- autoInitVnode : true ,
263- autoMount : true ,
264- parentComponent,
265- windowId : context . windowId || parentComponent . windowId
261+ async render ( { code} ) {
262+ let me = this ,
263+ content = code ,
264+ neoComponents = { } ,
265+ neoDivs = { } ,
266+ baseConfigs = {
267+ appName : me . appName ,
268+ autoInitVnode : true ,
269+ autoMount : true ,
270+ parentComponent : me . parentComponent ,
271+ windowId : me . windowId
266272 } ,
267273 html , instance ;
268274
@@ -285,9 +291,7 @@ class Markdown extends Component {
285291 html = marked . parse ( content ) ;
286292
287293 // Insert lab divs (these are markdown comments, so process on the final HTML)
288- html = me . insertLabDivs ( html ) ;
289-
290- container . html = html ;
294+ me . html = me . insertLabDivs ( html ) ;
291295
292296 await new Promise ( resolve => setTimeout ( resolve , Neo . config . environment === 'development' ? 100 : 150 ) ) ;
293297
@@ -299,9 +303,7 @@ class Markdown extends Component {
299303 parentId : key ,
300304 ...neoComponents [ key ]
301305 } ) ;
302- me . activeComponents . push ( instance ) ;
303-
304- console . log ( me . activeComponents ) ;
306+ me . activeComponents . push ( instance )
305307 } ) ;
306308 }
307309
@@ -310,12 +312,18 @@ class Markdown extends Component {
310312 const LivePreviewClass = LivePreviewModule . default ;
311313
312314 Object . keys ( neoDivs ) . forEach ( key => {
313- instance = Neo . create ( {
315+ const config = {
314316 ...baseConfigs ,
315317 module : LivePreviewClass ,
316318 parentId : key ,
317319 value : neoDivs [ key ] . code
318- } ) ;
320+ }
321+
322+ if ( me . windowUrl ) {
323+ config . windowUrl = me . windowUrl
324+ }
325+
326+ instance = Neo . create ( config ) ;
319327 me . activeComponents . push ( instance ) ;
320328 } ) ;
321329 }
@@ -329,7 +337,7 @@ class Markdown extends Component {
329337 */
330338 updateComponentState ( mounted ) {
331339 this . activeComponents . forEach ( component => {
332- if ( mounted ) { console . log ( 'remount cmp' , component . id ) ;
340+ if ( mounted ) {
333341 component . initVnode ( true )
334342 } else {
335343 component . mounted = false
0 commit comments