@@ -5,13 +5,9 @@ import { isValidUrl } from "./lib/url";
55import MainPage from "./main-page.svelte" ;
66import DownloadTablePage from "./download-table-page.svelte" ;
77import HtmlTablePage from "./html-table-page.svelte" ;
8- import {
9- OutputFormat ,
10- type TransformConfig ,
11- TransformPreset ,
12- } from "./core" ;
8+ import { OutputFormat , type TransformConfig , TransformPreset } from "./core" ;
139import { compressor , appWorker } from "./init" ;
14- import { fetchAsText } from "./model" ;
10+ import { fetchAsText , type SharedData } from "./model" ;
1511import "./app.css" ;
1612
1713const target = document . getElementById ( "app" ) ! ;
@@ -24,48 +20,43 @@ function page() {
2420 format : OutputFormat . HTML ,
2521 paginate : false ,
2622 } ;
27- const searchParams = new URLSearchParams ( window . location . search ) ;
28- if ( searchParams . has ( "data" ) ) {
29- try {
30- initialData = compressor . decompress ( searchParams . get ( "data" ) ! ) || "" ;
31- } catch ( error ) {
32- console . error ( error ) ;
23+ const hash = location . hash . substring ( 1 ) ;
24+ if ( hash !== "" ) {
25+ const { data, options, createOnOpen } : SharedData = JSON . parse (
26+ compressor . decompress ( hash )
27+ ) ;
28+ if ( data ) {
29+ initialData = data ;
3330 }
34- }
35- if ( searchParams . has ( "options" ) ) {
36- try {
37- initialOptions = JSON . parse (
38- compressor . decompress ( searchParams . get ( "options" ) ! )
39- ) ;
40- } catch ( error ) {
41- console . error ( error ) ;
31+ if ( options ) {
32+ initialOptions = options ;
4233 }
43- }
44- if ( searchParams . get ( "createOnOpen" ) === "true" ) {
45- const table = isValidUrl ( initialData )
46- ? fetchAsText ( initialData ) . then ( ( data ) =>
47- appWorker . createTable ( { data , config : initialOptions } )
48- )
49- : appWorker . createTable ( {
50- data : initialData ,
51- config : initialOptions ,
52- } ) ;
53- switch ( initialOptions . format ) {
54- case OutputFormat . XLSX :
55- return mount ( DownloadTablePage , {
56- target ,
57- props : {
58- title : " table.xlsx" ,
59- content : table ,
60- } ,
61- } ) ;
62- default :
63- return mount ( HtmlTablePage , {
64- target ,
65- props : {
66- content : table ,
67- } ,
68- } ) ;
34+ if ( createOnOpen ) {
35+ const table = isValidUrl ( initialData )
36+ ? fetchAsText ( initialData ) . then ( ( data ) =>
37+ appWorker . createTable ( { data, config : initialOptions } )
38+ )
39+ : appWorker . createTable ( {
40+ data : initialData ,
41+ config : initialOptions ,
42+ } ) ;
43+ switch ( initialOptions . format ) {
44+ case OutputFormat . XLSX :
45+ return mount ( DownloadTablePage , {
46+ target ,
47+ props : {
48+ title : "table.xlsx" ,
49+ content : table ,
50+ } ,
51+ } ) ;
52+ default :
53+ return mount ( HtmlTablePage , {
54+ target ,
55+ props : {
56+ content : table ,
57+ } ,
58+ } ) ;
59+ }
6960 }
7061 }
7162 return mount ( MainPage , {
0 commit comments