@@ -3,10 +3,10 @@ import MonacoEditor from '../component/wrapper/MonacoEditor.mjs'
33import TabContainer from '../tab/Container.mjs' ;
44
55const
6- classDeclarationRegex = / c l a s s \s + ( [ a - z A - Z $ _ ] [ a - z A - Z 0 - 9 $ _ ] * ) \s * (?: e x t e n d s \s + [ a - z A - Z $ _ ] [ a - z A - Z 0 - 9 $ _ ] * ) ? \s * { [ \s \S ] * ? } / g,
7- classNameRegex = / c l a s s N a m e \s * : \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / g,
8- 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 ,
9- importRegex = / i m p o r t \s + ( [ \w - ] + ) \s + f r o m \s + [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / ;
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 ;
1010
1111/**
1212 * @class Neo.code.LivePreview
@@ -229,7 +229,7 @@ class LivePreview extends Container {
229229 { environment} = Neo . config ,
230230 container = me . getPreviewContainer ( ) ,
231231 source = me . editorValue || me . value ,
232- className = me . findLastClassName ( source ) ,
232+ className = me . findSetupClassName ( source ) ,
233233 cleanLines = [ ] ,
234234 moduleNameAndPath = [ ] ,
235235 params = [ ] ,
@@ -240,8 +240,9 @@ class LivePreview extends Container {
240240 let importMatch = line . match ( importRegex ) ;
241241
242242 if ( importMatch ) {
243- let moduleName = importMatch [ 1 ] ,
244- path = importMatch [ 2 ] ,
243+ let defaultImport = importMatch [ 1 ] ,
244+ namedImports = importMatch [ 2 ] ?. split ( ',' ) . map ( name => name . trim ( ) ) ,
245+ path = importMatch [ 3 ] ,
245246 index ;
246247
247248 // We want the non-minified version for code which can not get bundled.
@@ -266,7 +267,7 @@ class LivePreview extends Container {
266267 }
267268 }
268269
269- moduleNameAndPath . push ( { moduleName , path} )
270+ moduleNameAndPath . push ( { defaultImport , namedImports , path} )
270271 } else if ( line . match ( exportRegex ) ) {
271272 // Skip export statements
272273 } else {
@@ -289,9 +290,15 @@ class LivePreview extends Container {
289290 // });
290291 // Making the promise part of the eval seems weird, but it made it easier to
291292 // set up the import vars.
292- promises = moduleNameAndPath . map ( item => {
293- params . push ( `${ item . moduleName } Module` ) ;
294- vars . push ( ` const ${ item . moduleName } = ${ item . moduleName } Module.default;` ) ;
293+ promises = moduleNameAndPath . map ( ( item , i ) => {
294+ let moduleAlias = `Module${ i } ` ;
295+ params . push ( moduleAlias ) ;
296+ if ( item . defaultImport ) {
297+ vars . push ( ` const ${ item . defaultImport } = ${ moduleAlias } .default;` ) ;
298+ }
299+ if ( item . namedImports ) {
300+ vars . push ( ` const {${ item . namedImports . join ( ', ' ) } } = ${ moduleAlias } ;` ) ;
301+ }
295302 return `import('${ item . path } ')`
296303 } ) ;
297304
@@ -302,7 +309,10 @@ class LivePreview extends Container {
302309 `${ vars . join ( '\n' ) } ` ,
303310 ` ${ cleanLines . join ( '\n' ) } ` ,
304311 '' ,
305- ` if (${ className } && Neo.component.Base.isPrototypeOf(${ className } )) {` ,
312+ ` if (${ className } && (` ,
313+ ` Neo.component.Base.isPrototypeOf(${ className } ) ||` ,
314+ ` Neo.functional.component.Base.isPrototypeOf(${ className } )` ,
315+ ` )) {` ,
306316 ` container.add({module:${ className } })` ,
307317 ' }' ,
308318 '})' ,
@@ -352,11 +362,11 @@ class LivePreview extends Container {
352362 * @param {String } sourceCode
353363 * @returns {String|null }
354364 */
355- findLastClassName ( sourceCode ) {
365+ findSetupClassName ( sourceCode ) {
356366 let lastClassName = null ,
357367 match ;
358368
359- while ( ( match = classDeclarationRegex . exec ( sourceCode ) ) !== null ) {
369+ while ( ( match = setupClassRegex . exec ( sourceCode ) ) !== null ) {
360370 // Update the last class name found
361371 lastClassName = match [ 1 ]
362372 }
0 commit comments