File tree Expand file tree Collapse file tree 3 files changed +29
-10
lines changed
Expand file tree Collapse file tree 3 files changed +29
-10
lines changed Original file line number Diff line number Diff line change 4141 "worker-loader" : " ^2.0.0"
4242 },
4343 "dependencies" : {
44+ "@types/lz-string" : " ^1.3.33" ,
4445 "@types/webpack-env" : " ^1.15.1" ,
4546 "fengari-web" : " ^0.1.4" ,
4647 "highlight.js" : " ^9.18.0" ,
4748 "lua-types" : " ^2.7.0" ,
49+ "lz-string" : " ^1.4.4" ,
4850 "monaco-editor" : " ^0.19.3" ,
4951 "renderjson" : " ^1.4.0" ,
5052 "typescript-to-lua" : " ^0.31.0"
Original file line number Diff line number Diff line change 1+ import lzstring from "lz-string" ;
2+
13const example = `// Declare exposed API
24type Vector = [number, number, number];
35
@@ -25,18 +27,15 @@ export function getInitialCode() {
2527 return decodeURIComponent ( code ) ;
2628 }
2729
30+ if ( window . location . hash . startsWith ( "#code/" ) ) {
31+ const code = window . location . hash . replace ( "#code/" , "" ) . trim ( ) ;
32+ return lzstring . decompressFromEncodedURIComponent ( code ) ;
33+ }
34+
2835 return example ;
2936}
3037
31- let ignoreHashChange = false ;
32- window . onhashchange = ( ) => {
33- if ( ignoreHashChange ) {
34- ignoreHashChange = false ;
35- return ;
36- }
37- } ;
38-
3938export function updateCodeHistory ( code : string ) {
40- window . location . replace ( "#src=" + encodeURIComponent ( code ) ) ;
41- ignoreHashChange = true ;
39+ const hash = `code/ ${ lzstring . compressToEncodedURIComponent ( code ) } ` ;
40+ window . history . replaceState ( { } , "" , `# ${ hash } ` ) ;
4241}
Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ __metadata:
2929 languageName : node
3030 linkType : hard
3131
32+ " @types/lz-string@npm:^1.3.33 " :
33+ version : 1.3.33
34+ resolution : " @types/lz-string@npm:1.3.33"
35+ checksum : 5cd0a49ed57ae8387c19a273b8fcf652ba4523fbc7fd3bd39bd9cc1a97c3cd37967a12dd6e0fe6135913ce9b08f2ee576975ec0adbf43953521b661a485d092b
36+ languageName : node
37+ linkType : hard
38+
3239" @types/minimatch@npm:* " :
3340 version : 3.0.3
3441 resolution : " @types/minimatch@npm:3.0.3"
@@ -3675,6 +3682,15 @@ fsevents@~2.1.2:
36753682 languageName : node
36763683 linkType : hard
36773684
3685+ " lz-string@npm:^1.4.4 " :
3686+ version : 1.4.4
3687+ resolution : " lz-string@npm:1.4.4"
3688+ bin :
3689+ lz-string : bin/bin.js
3690+ checksum : db16acfb00972da3907ce5c2186e208c64cccce69a4fc8ecb16c1e84c44b44480a4f153958ac180f977a27303a4b0642cbe14856d2dd89b14f4a7ea5e28ad93c
3691+ languageName : node
3692+ linkType : hard
3693+
36783694" make-dir@npm:^2.0.0 " :
36793695 version : 2.1.0
36803696 resolution : " make-dir@npm:2.1.0"
@@ -6345,6 +6361,7 @@ resolve@^1.13.1:
63456361 resolution : " typescripttolua.github.io@workspace:."
63466362 dependencies :
63476363 " @types/highlight.js " : ^9.12.3
6364+ " @types/lz-string " : ^1.3.33
63486365 " @types/node " : ^13.5.0
63496366 " @types/webpack-env " : ^1.15.1
63506367 css-loader : ^3.4.2
@@ -6355,6 +6372,7 @@ resolve@^1.13.1:
63556372 html-loader : ^0.5.5
63566373 html-webpack-plugin : ^3.2.0
63576374 lua-types : ^2.7.0
6375+ lz-string : ^1.4.4
63586376 monaco-editor : ^0.19.3
63596377 pnp-webpack-plugin : ^1.5.0
63606378 prettier : ^1.19.1
You can’t perform that action at this time.
0 commit comments