@@ -3,10 +3,9 @@ import MonacoEditor from '../component/wrapper/MonacoEditor.mjs'
33import TabContainer from '../tab/Container.mjs' ;
44
55const
6- classNameRegex = / c l a s s N a m e \s * : \s * [ ' \" ] ( [ ^ ' \" ] + ) [ ' \" ] / g,
7- exportRegex = / e x p o r t \s + (?: d e f a u l t \s + ) ? (?: c o n s t | l e t | v a r | c l a s s | f u n c t i o n | a s y n c \s + f u n c t i o n | g e n e r a t o r \s + f u n c t i o n | a s y n c \s + g e n e r a t o r \s + f u n c t i o n | ( \{ [ \s \S ] * ?\} ) ) / g,
8- importRegex = / i m p o r t \s + (?: ( [ \w - ] + ) | \{ ( [ ^ } ] + ) \} ) \s + f r o m \s + [ ' \" ] ( [ ^ ' \" ] + ) [ ' \" ] / ,
9- setupClassRegex = / ( \w + ) \s * = \s * N e o \. s e t u p C l a s s / g;
6+ classNameRegex = / c l a s s N a m e \s * : \s * [ ' \" ] ( [ ^ ' \" ] + ) [ ' \" ] / g,
7+ exportRegex = / e x p o r t \s + (?: d e f a u l t \s + ) ? (?: c o n s t | l e t | v a r | c l a s s | f u n c t i o n | a s y n c \s + f u n c t i o n | g e n e r a t o r \s + f u n c t i o n | a s y n c \s + g e n e r a t o r \s + f u n c t i o n | ( \{ [ \s \S ] * ?\} ) ) / g,
8+ importRegex = / i m p o r t \s + (?: ( [ \w - ] + ) | \{ ( [ ^ } ] + ) \} ) \s + f r o m \s + [ ' \" ] ( [ ^ ' \" ] + ) [ ' \" ] / ;
109
1110/**
1211 * @class Neo.code.LivePreview
@@ -229,12 +228,12 @@ class LivePreview extends Container {
229228 { environment} = Neo . config ,
230229 container = me . getPreviewContainer ( ) ,
231230 source = me . editorValue || me . value ,
232- className = me . findSetupClassName ( source ) ,
231+ className = me . findMainClassName ( source ) ,
233232 cleanLines = [ ] ,
234233 moduleNameAndPath = [ ] ,
235234 params = [ ] ,
236235 vars = [ ] ,
237- codeString , promises ;
236+ codeString , module , promises ;
238237
239238 source . split ( '\n' ) . forEach ( line => {
240239 let importMatch = line . match ( importRegex ) ;
@@ -309,11 +308,13 @@ class LivePreview extends Container {
309308 `${ vars . join ( '\n' ) } ` ,
310309 ` ${ cleanLines . join ( '\n' ) } ` ,
311310 '' ,
312- ` if (${ className } && (` ,
313- ` Neo.component.Base.isPrototypeOf(${ className } ) ||` ,
314- ` Neo.functional.component.Base.isPrototypeOf(${ className } )` ,
311+ ` module = Neo.ns('${ className } ');` ,
312+ '' ,
313+ ` if (module && (` ,
314+ ` Neo.component.Base.isPrototypeOf(module) ||` ,
315+ ` Neo.functional.component.Base.isPrototypeOf(module)` ,
315316 ` )) {` ,
316- ` container.add({module: ${ className } })` ,
317+ ` container.add({module})` ,
317318 ' }' ,
318319 '})' ,
319320 '.catch(error => {' ,
@@ -337,7 +338,7 @@ class LivePreview extends Container {
337338 } ) ;
338339
339340 try {
340- new Function ( 'container' , codeString ) ( container ) ;
341+ new Function ( 'container' , 'module' , codeString ) ( container , module ) ;
341342 } catch ( error ) {
342343 container . add ( {
343344 ntype : 'component' ,
@@ -365,18 +366,29 @@ class LivePreview extends Container {
365366 * @param {String } sourceCode
366367 * @returns {String|null }
367368 */
368- findSetupClassName ( sourceCode ) {
369- let lastClassName = null ,
370- match ;
369+ findMainClassName ( sourceCode ) {
370+ let classNames = this . findClassNames ( sourceCode ) ,
371+ mainName = null ,
372+ prioNames = [ 'MainContainer' , 'MainComponent' , 'MainView' , 'Main' ] ;
373+
374+ if ( classNames . length > 0 ) {
375+ for ( const name of prioNames ) {
376+ mainName = classNames . find ( className => className . endsWith ( name ) ) ;
377+ if ( mainName ) {
378+ break
379+ }
380+ }
371381
372- while ( ( match = setupClassRegex . exec ( sourceCode ) ) !== null ) {
373- // Update the last class name found
374- lastClassName = match [ 1 ]
382+ if ( ! mainName ) {
383+ mainName = classNames [ classNames . length - 1 ]
384+ }
375385 }
376386
377- return lastClassName
387+ return mainName
378388 }
379389
390+
391+
380392 /**
381393 * @returns {Neo.component.Base|null }
382394 */
0 commit comments