1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-06-02 22:00:13 +02:00

first tauri build with new systems

deleted old/unused code
This commit is contained in:
Felix Kaspar 2024-05-18 00:09:46 +02:00
parent a484a804ad
commit 3eca56f8c6
13 changed files with 17 additions and 138 deletions

View File

@ -7,7 +7,9 @@
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"tauri": "tauri"
"tauri-dev (currently broken)": "tauri dev",
"tauri-build-debug": "tauri build --debug",
"tauri-build": "tauri build"
},
"dependencies": {
"@stirling-pdf/shared-operations": "^0.0.0",

View File

@ -5,8 +5,8 @@ import Home from "./pages/Home";
import About from "./pages/About";
import Dashboard from "./pages/Dashboard";
import Dynamic from "./pages/Dynamic";
import ToPdf from "./pages/convert/ToPdf";
import Impose from "./pages/page-operations/Impose";
// import ToPdf from "./pages/convert/ToPdf";
// import Impose from "./pages/page-operations/Impose";
import NoMatch from "./pages/NoMatch";
import NavBar from "./components/NavBar";
@ -53,11 +53,11 @@ export default function App() {
<Route path="*" element={<NoMatch />} />
</Route>
<Route path="/convert" element={<Layout />}>
<Route path="file-to-pdf" element={<ToPdf />} />
{/* <Route path="file-to-pdf" element={<ToPdf />} /> */}
<Route path="*" element={<NoMatch />} />
</Route>
<Route path="/page-operations" element={<Layout />}>
<Route path="impose" element={<Impose />} />
{/* <Route path="impose" element={<Impose />} /> */}
<Route path="*" element={<NoMatch />} />
</Route>
</Routes>

View File

@ -1,63 +0,0 @@
import Form from "react-bootstrap/Form";
import { useTranslation } from "react-i18next";
import { FieldConstraint, RecordConstraint } from "@stirling-pdf/shared-operations/src/dynamic-ui/OperatorConstraints";
interface DynamicParameterFieldsProps {
constraints: RecordConstraint;
parentKeyPath?: string[];
}
const DynamicParameterFields: React.FC<DynamicParameterFieldsProps> = ({constraints, parentKeyPath=["DPF"]}) => {
const { t } = useTranslation();
return (<>
{Object.entries(constraints.record).map(([fieldName, value]) => {
console.log(fieldName, value);
const globallyUniqueId = joinKeyPath([...parentKeyPath, fieldName]);
return <div className='mb-3' key={fieldName} >
<label htmlFor={globallyUniqueId}>{t(value.displayNameKey)}</label>
{fieldConstraintToElement(fieldName, parentKeyPath, globallyUniqueId, value)}
</div>;
})}
</>);
};
function joinKeyPath(keyPath: string[]) {
return keyPath.join(".");
}
function fieldConstraintToElement(fieldName: string, parentKeyPath: string[], globallyUniqueId: string, fieldConstraint: FieldConstraint) {
if (Array.isArray(fieldConstraint.type)) {
if (fieldConstraint.type.every(e => typeof e == "string" || typeof e == "number")) {
return (
<Form.Select id={globallyUniqueId} name={fieldName}>
<option value="" disabled>Select an option</option>
{fieldConstraint.type.map((option) => <option key={option} value={option}>{option}</option> )}
</Form.Select>
);
} else {
return <div key={fieldName}>Error: Field type '{fieldConstraint.type}' not supported</div>;
}
} else if (typeof fieldConstraint.type == "string") {
switch (fieldConstraint.type) {
case "file.pdf":
return <input id={globallyUniqueId} type="file" name={fieldName} required={fieldConstraint.required} className="form-control required" accept="application/pdf" multiple={false}/>;
case "files.pdf":
return <input id={globallyUniqueId} type="file" name={fieldName} required={fieldConstraint.required} className="form-control required" accept="application/pdf" multiple={true}/>;
case "string":
return <input id={globallyUniqueId} type="text" name={fieldName} required={fieldConstraint.required} />;
case "number":
return <input id={globallyUniqueId} type="number" name={fieldName} required={fieldConstraint.required} />;
default:
return <div key={fieldName}>Error: Field type '{fieldConstraint.type}' not supported</div>;
}
} else if (fieldConstraint.type instanceof RecordConstraint) {
//return <DynamicParameterFields constraints={fieldConstraint.type} parentKeyPath={[...parentKeyPath, fieldName]}/>
return <div key={fieldName}>Error: Field type 'RecordConstraint' not supported yet!</div>;
}
return <div key={fieldName}>Error: Field type '{fieldConstraint.type}' not supported</div>;
}
export default DynamicParameterFields;

View File

@ -20,7 +20,7 @@ export function BuildFields({ schemaDescription, onSubmit }: BuildFieldsProps) {
<hr />
<form onSubmit={(e) => { onSubmit(e); e.preventDefault(); }}>
{
values ? Object.keys(values).map((key, i) => {
values ? Object.keys(values).map((key) => {
return (<GenericField key={key} fieldName={key} joiDefinition={values[key]} />)
}) : undefined
}

View File

@ -1,12 +0,0 @@
interface StringFieldProps {
/** The text to display inside the button */
validValues: string[];
exampleValues: string;
}
export function StringField({ validValues, exampleValues }: StringFieldProps) {
return (
<button>{validValues}</button>
);
}

View File

@ -1,6 +1,6 @@
import { Link } from "react-router-dom";
import { BaseSyntheticEvent, createContext, useRef, useState } from "react";
import { BaseSyntheticEvent, useRef, useState } from "react";
import { Operator } from "@stirling-pdf/shared-operations/src/functions";
import i18next from "i18next";
import Joi from "@stirling-tools/joi";
@ -26,6 +26,7 @@ function Dynamic() {
console.log("Loading namespaces for", selectedValue);
await i18next.loadNamespaces(selectedValue, (err, t) => {
if (err) throw err;
console.log(t);
});
console.log("Loading namespaces done");
@ -110,7 +111,7 @@ function Dynamic() {
<br />
<select id="pdfOptions" onChange={selectionChanged}>
<option value="none">none</option>
{ operators.map((operator, i) => {
{ operators.map((operator) => {
return (<option key={operator} value={operator}>{operator}</option>)
}) }
</select>

View File

@ -1,16 +0,0 @@
import { isLibreOfficeInstalled } from "../../utils/libre-office-utils";
const hasLibreOffice = await isLibreOfficeInstalled();
console.log(hasLibreOffice);
function About() {
return (
<div>
<h2>Convert to PDF</h2>
{"hasLibreOffice: "+hasLibreOffice}
</div>
);
}
export default About;

View File

@ -1,18 +0,0 @@
import DynamicParameterFields from "../../components/DynamicParameterFields";
// import { ImposeParamConstraints } from "@stirling-pdf/shared-operations/src/functions/impose";
import { useTranslation } from "react-i18next";
function Impose() {
const { t } = useTranslation();
return (
<div>
<h2>{t("pageLayout.header")}</h2>
<form>
{/* <DynamicParameterFields constraints={ImposeParamConstraints}/> */}
</form>
</div>
);
}
export default Impose;

View File

@ -1,17 +0,0 @@
import SharedOperations, { OperationsType } from "@stirling-pdf/shared-operations/src";
import { ImposeParamsType } from "@stirling-pdf/shared-operations/src/functions/impose";
import { PdfFile } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile";
// Import injected libraries here!
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js";
async function impose(params: ImposeParamsType): Promise<PdfFile> {
return SharedOperations.impose(params, pdfcpuWrapper);
}
const toExport: OperationsType = {
...SharedOperations,
impose,
};
export default toExport;

View File

@ -22,7 +22,8 @@
},
"include": [
"src",
"declarations/*.d.ts"
"declarations/*.d.ts",
"../shared-operations/declarations/*.d.ts"
],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

@ -7,7 +7,7 @@ export async function getPages(file: PdfFile, pageIndexes: number[]): Promise<Pd
const subDocument = await PDFDocument.create();
// Check that array max number is not larger pdf pages number
if(Math.max(...pageIndexes) >= pdfLibDocument.getPageCount()) {
if(Math.max(...pageIndexes) > pdfLibDocument.getPageCount()) {
throw new Error(`The PDF document only has ${pdfLibDocument.getPageCount()} pages and you tried to extract page ${Math.max(...pageIndexes)}`);
}

View File

@ -35,7 +35,8 @@ export class Operator {
}
async run(input: PdfFile[] | any[], progressCallback: (progress: Progress) => void): Promise<PdfFile[] | any[]> {
return [];
progressCallback({ curFileProgress: 1, operationProgress: 1 })
return input;
}
}

View File

@ -7,7 +7,7 @@ export async function getOperatorByName(name: string): Promise<typeof Operator |
// Check if exists
if(!compileTimeOperatorList.includes(name)) return;
i18next.loadNamespaces(name, (err, t) => { if (err) throw err; });
i18next.loadNamespaces(name, (err, t) => { if (err) throw err; console.log(t) });
const loadedModule = await import("../functions/" + name + ".ts");
const operator = loadedModule[capitalizeFirstLetter(name)];
if(!operator) {