From e6ce7132ceb9743f47125c777744588acc9a54dc Mon Sep 17 00:00:00 2001 From: Johannes Zillmann Date: Sun, 3 Jan 2021 20:09:35 +0100 Subject: [PATCH] Show parse results --- ui/package.json | 2 +- ui/src/App.svelte | 9 +++++++- ui/src/Result.svelte | 15 +++++++++++++ ui/src/Table.svelte | 52 ++++++++++++++++++++++++++++++++++++++++++++ ui/src/Upload.svelte | 7 +++++- ui/src/store.ts | 17 +++++++++++---- ui/tsconfig.json | 48 ++++++++++++++++++++++------------------ 7 files changed, 122 insertions(+), 28 deletions(-) create mode 100644 ui/src/Result.svelte create mode 100644 ui/src/Table.svelte diff --git a/ui/package.json b/ui/package.json index 2740357..d3f02e3 100644 --- a/ui/package.json +++ b/ui/package.json @@ -2,7 +2,7 @@ "name": "pdf-to-markdown", "version": "0.2.0", "description": "A PDF to Markdown Converter", - "keywords": [ + "keywords": [ "PDF", "Markdown", "Converter" diff --git a/ui/src/App.svelte b/ui/src/App.svelte index 8598e82..f251674 100644 --- a/ui/src/App.svelte +++ b/ui/src/App.svelte @@ -1,10 +1,17 @@
PDF to Markdown Converter
- + {#if $parseResult} + + {:else} + + {/if}
diff --git a/ui/src/Upload.svelte b/ui/src/Upload.svelte index 745c279..5965d70 100644 --- a/ui/src/Upload.svelte +++ b/ui/src/Upload.svelte @@ -32,7 +32,9 @@ noClick={false} disableDefaultStyles={true}>
- + + +
Drop your PDF file here...
Or click the box to select one...
@@ -63,4 +65,7 @@ .dragover { @apply border-purple-600; } + .dragoverItem { + @apply text-purple-600; + } diff --git a/ui/src/store.ts b/ui/src/store.ts index e57f5ae..0d7cf55 100644 --- a/ui/src/store.ts +++ b/ui/src/store.ts @@ -2,6 +2,10 @@ import { pdfParser } from 'pdf-to-markdown-core'; import type ParseResult from 'pdf-to-markdown-core/lib/src/ParseResult'; import * as pdfjs from 'pdfjs-dist/es5/build/pdf'; +import { Writable, writable } from 'svelte/store'; + +export let parseResult: Writable = writable(undefined); + // TODO this will setup fake worker cause getMainThreadWorkerMessageHandler isn't null import pdfjsWorker from 'pdfjs-dist//es5/build/pdf.worker.entry'; pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker; @@ -16,8 +20,13 @@ export function processUpload(file: File): Promise { resolve(reader.result as ArrayBuffer); }; reader.readAsArrayBuffer(file); - }).then((buffer) => { - const uintArray = new Uint8Array(buffer as ArrayBuffer); - return parser.parse(uintArray); - }); + }) + .then((buffer) => { + const uintArray = new Uint8Array(buffer as ArrayBuffer); + return parser.parse(uintArray); + }) + .then((result) => { + parseResult.set(result); + return result; + }); } diff --git a/ui/tsconfig.json b/ui/tsconfig.json index 1b89b72..be02eac 100644 --- a/ui/tsconfig.json +++ b/ui/tsconfig.json @@ -1,23 +1,29 @@ { - "include": ["src", "types"], - "compilerOptions": { - "module": "esnext", - "target": "esnext", - "moduleResolution": "node", - "jsx": "preserve", - "baseUrl": "./", - /* paths - If you configure Snowpack import aliases, add them here. */ - "paths": {}, - /* noEmit - Snowpack builds (emits) files, not tsc. */ - "noEmit": true, - /* Additional Options */ - "strict": true, - "noImplicitAny": false, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "useDefineForClassFields": true, - "allowSyntheticDefaultImports": true, - "importsNotUsedAsValues": "error" - } + "include": ["src", "types"], + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "moduleResolution": "node", + "jsx": "preserve", + "baseUrl": "./", + /* paths - If you configure Snowpack import aliases, add them here. */ + "paths": {}, + /* noEmit - Snowpack builds (emits) files, not tsc. */ + "noEmit": true, + /* Additional Options */ + "strict": true, + "noImplicitAny": false, + // "noImplicitThis": false, + // "alwaysStrict": false, + // "strictBindCallApply": false, + "strictNullChecks": false, + // "strictFunctionTypes": false, + // "strictPropertyInitialization": false, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "useDefineForClassFields": true, + "allowSyntheticDefaultImports": true, + "importsNotUsedAsValues": "error" + } }