@@ -285,9 +285,11 @@ class LitAce extends LitElement {
285
285
this . editor . focus ( ) ;
286
286
}
287
287
288
+ this . _statusbarIndex = 1 ;
288
289
this . editor . statusbar = new this . statusBar (
289
290
this . editor ,
290
- this . editorStatusbarDiv
291
+ this . editorStatusbarDiv ,
292
+ this . _statusbarIndex
291
293
) ;
292
294
293
295
this . vScrollbarObserver = new IntersectionObserver (
@@ -1006,72 +1008,16 @@ class LitAce extends LitElement {
1006
1008
}
1007
1009
1008
1010
/** @private */
1009
- _generateHTML ( exportType ) {
1010
- if ( exportType . toLowerCase ( ) == "flat" ) {
1011
- let currentVal = this . editorValue ;
1011
+ async _generateHTML ( exportType ) {
1012
+ const content = await this . _generateExport ( exportType ) ;
1012
1013
1013
- currentVal = currentVal . replace ( / [ \u00A0 - \u9999 < > \& ] / g, function ( i ) {
1014
- return "&#" + i . charCodeAt ( 0 ) + ";" ;
1015
- } ) ;
1016
- currentVal = currentVal . replace ( new RegExp ( "\r?\n" , "g" ) , "<br/>" ) ;
1017
- currentVal = currentVal . replace ( / \s / g, " " ) ;
1018
-
1019
- var htmlContent = `<!DOCTYPE html>
1020
- <html>
1021
- <head>
1022
- <link rel="preconnect" href="https://fonts.gstatic.com">
1023
- <link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
1024
- <style>
1025
- #aceRaw {
1026
- font-family: 'Source Code Pro', monospace;
1027
- font-size: 12px;
1028
- }
1029
- </style>
1030
- </head>
1031
- <body>
1032
- <div id="aceRaw">${ currentVal } </div>
1033
- </body>
1034
- </html>` ;
1035
-
1036
- this . dispatchEvent (
1037
- new CustomEvent ( "html-generated" , {
1038
- detail : {
1039
- html : htmlContent ,
1040
- } ,
1041
- } )
1042
- ) ;
1043
- } else if ( exportType . toLowerCase ( ) == "rich" ) {
1044
- let self = this ;
1045
- ace
1046
- . require ( "ace/config" )
1047
- . loadModule ( "ace/ext/static_highlight" , function ( m ) {
1048
- var result = m . renderSync (
1049
- self . editor . getValue ( ) ,
1050
- self . editor . session . getMode ( ) ,
1051
- self . editor . renderer . theme
1052
- ) ;
1053
-
1054
- var htmlContent = `<!DOCTYPE html>
1055
- <html>
1056
- <head>
1057
- <style>
1058
- ${ result . css }
1059
- </style>
1060
- </head>
1061
- <body>
1062
- ${ result . html }
1063
- </body>
1064
- </html>` ;
1065
-
1066
- self . dispatchEvent (
1067
- new CustomEvent ( "html-generated" , {
1068
- detail : {
1069
- html : htmlContent ,
1070
- } ,
1071
- } )
1072
- ) ;
1073
- } ) ;
1074
- }
1014
+ this . dispatchEvent (
1015
+ new CustomEvent ( "html-generated" , {
1016
+ detail : {
1017
+ html : content ,
1018
+ } ,
1019
+ } )
1020
+ ) ;
1075
1021
}
1076
1022
1077
1023
unfold ( ) {
@@ -1237,82 +1183,42 @@ class LitAce extends LitElement {
1237
1183
}
1238
1184
1239
1185
/** @private */
1240
- _print ( exportType ) {
1241
- if ( exportType . toLowerCase ( ) == "flat" ) {
1242
- let currentVal = this . editorValue ;
1243
-
1244
- currentVal = currentVal . replace ( / [ \u00A0 - \u9999 < > \& ] / g, function ( i ) {
1245
- return "&#" + i . charCodeAt ( 0 ) + ";" ;
1246
- } ) ;
1247
- currentVal = currentVal . replace ( new RegExp ( "\r?\n" , "g" ) , "<br/>" ) ;
1248
- currentVal = currentVal . replace ( / \s / g, " " ) ;
1186
+ async _print ( exportType ) {
1187
+ const content = await this . _generateExport ( exportType ) ;
1188
+ this . _initializePrint ( content ) ;
1189
+ }
1249
1190
1250
- var htmlContent = `<!DOCTYPE html>
1251
- <html>
1252
- <head>
1253
- <title>Ace Export</title>
1254
- <link rel="preconnect" href="https://fonts.gstatic.com">
1255
- <link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
1256
- <style>
1257
- #aceRaw {
1258
- font-family: 'Source Code Pro', monospace;
1259
- font-size: 12px;
1260
- }
1261
- @media print {
1262
- @page {
1263
- margin-top: 0;
1264
- margin-bottom: 0;
1265
- }
1266
- body {
1267
- padding-top: 72px;
1268
- padding-bottom: 72px ;
1191
+ setStatusbarIndexing ( statusbarIndex ) {
1192
+ if ( this . editor == undefined ) {
1193
+ this . addEventListener (
1194
+ "editor-ready" ,
1195
+ ( ) => this . _setStatusbarIndexing ( statusbarIndex ) ,
1196
+ {
1197
+ once : true ,
1269
1198
}
1270
- }
1271
- </style>
1272
- </head>
1273
- <body>
1274
- <div id="aceRaw">${ currentVal } </div>
1275
- </body>
1276
- </html>` ;
1199
+ ) ;
1200
+ } else {
1201
+ this . _setStatusbarIndexing ( statusbarIndex ) ;
1202
+ }
1203
+ }
1277
1204
1278
- this . initializePrint ( htmlContent ) ;
1279
- } else if ( exportType . toLowerCase ( ) == "rich" ) {
1280
- let self = this ;
1281
- ace
1282
- . require ( "ace/config" )
1283
- . loadModule ( "ace/ext/static_highlight" , function ( m ) {
1284
- var result = m . renderSync (
1285
- self . editor . getValue ( ) ,
1286
- self . editor . session . getMode ( ) ,
1287
- self . editor . renderer . theme
1288
- ) ;
1205
+ /** @private */
1206
+ _setStatusbarIndexing ( statusbarIndex ) {
1207
+ if ( statusbarIndex == this . _statusbarIndex ) return ;
1289
1208
1290
- var htmlContent = `<!DOCTYPE html>
1291
- <html>
1292
- <head>
1293
- <title>Ace Export</title>
1294
- <style>
1295
- ${ result . css }
1296
- @media print {
1297
- @page {
1298
- margin-top: 0;
1299
- margin-bottom: 0;
1300
- }
1301
- body {
1302
- padding-top: 72px;
1303
- padding-bottom: 72px ;
1304
- }
1305
- }
1306
- </style>
1307
- </head>
1308
- <body>
1309
- ${ result . html }
1310
- </body>
1311
- </html>` ;
1209
+ this . _statusbarIndex = statusbarIndex ;
1312
1210
1313
- self . initializePrint ( htmlContent ) ;
1314
- } ) ;
1211
+ for ( const child of this . editorStatusbarDiv . childNodes ) {
1212
+ this . editorStatusbarDiv . removeChild ( child ) ;
1315
1213
}
1214
+
1215
+ this . editor . statusbar = new this . statusBar (
1216
+ this . editor ,
1217
+ this . editorStatusbarDiv ,
1218
+ this . _statusbarIndex
1219
+ ) ;
1220
+
1221
+ this . editor . statusbar . updateStatus ( this . editor , this . _statusbarIndex ) ;
1316
1222
}
1317
1223
1318
1224
/** @private */
@@ -1365,7 +1271,81 @@ class LitAce extends LitElement {
1365
1271
}
1366
1272
1367
1273
/** @private */
1368
- initializePrint ( content ) {
1274
+ _generateExport ( exportType ) {
1275
+ const printCSS = `@media print {
1276
+ @page {
1277
+ margin-top: 0;
1278
+ margin-bottom: 0;
1279
+ }
1280
+ body {
1281
+ padding-top: 72px;
1282
+ padding-bottom: 72px ;
1283
+ }
1284
+ }` ;
1285
+
1286
+ return new Promise ( ( resolve ) => {
1287
+ if ( exportType . toLowerCase ( ) == "flat" ) {
1288
+ let currentVal = this . editorValue ;
1289
+
1290
+ currentVal = currentVal . replace ( / [ \u00A0 - \u9999 < > \& ] / g, function ( i ) {
1291
+ return "&#" + i . charCodeAt ( 0 ) + ";" ;
1292
+ } ) ;
1293
+ currentVal = currentVal . replace ( new RegExp ( "\r?\n" , "g" ) , "<br/>" ) ;
1294
+ currentVal = currentVal . replace ( / \s / g, " " ) ;
1295
+
1296
+ var htmlContent = `<!DOCTYPE html>
1297
+ <html>
1298
+ <head>
1299
+ <title>Ace Export</title>
1300
+ <link rel="preconnect" href="https://fonts.gstatic.com">
1301
+ <link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
1302
+ <style>
1303
+ #aceRaw {
1304
+ font-family: 'Source Code Pro', monospace;
1305
+ font-size: 12px;
1306
+ }
1307
+ ${ printCSS }
1308
+ </style>
1309
+ </head>
1310
+ <body>
1311
+ <div id="aceRaw">${ currentVal } </div>
1312
+ </body>
1313
+ </html>` ;
1314
+
1315
+ resolve ( htmlContent ) ;
1316
+ } else if ( exportType . toLowerCase ( ) == "rich" ) {
1317
+ let self = this ;
1318
+ ace
1319
+ . require ( "ace/config" )
1320
+ . loadModule ( "ace/ext/static_highlight" , function ( m ) {
1321
+ var result = m . renderSync (
1322
+ self . editor . getValue ( ) ,
1323
+ self . editor . session . getMode ( ) ,
1324
+ self . editor . renderer . theme
1325
+ ) ;
1326
+
1327
+ var htmlContent = `<!DOCTYPE html>
1328
+ <html>
1329
+ <head>
1330
+ <title>Ace Export</title>
1331
+ <style>
1332
+ ${ result . css }
1333
+ ${ printCSS }
1334
+ </style>
1335
+ </head>
1336
+ <body>
1337
+ ${ result . html }
1338
+ </body>
1339
+ </html>` ;
1340
+
1341
+ resolve ( htmlContent ) ;
1342
+ } ) ;
1343
+ }
1344
+ } ) ;
1345
+ }
1346
+
1347
+ /** @private */
1348
+ _initializePrint ( content ) {
1369
1349
const popupWidth = 742 ;
1370
1350
const popupHeight = 600 ;
1371
1351
0 commit comments