diff --git a/client-tauri/src/App.tsx b/client-tauri/src/App.tsx index ffab325e6..cbab0b925 100644 --- a/client-tauri/src/App.tsx +++ b/client-tauri/src/App.tsx @@ -28,7 +28,7 @@ i18next.use(LanguageDetector).use(initReactI18next).use(resourcesToBackend((lang interpolation: { escapeValue: false, }, - initImmediate: true // Makes loading blocking but sync + initImmediate: false // Makes loading blocking but sync }); // TODO: use i18next.config.ts instead import "./general.css"; diff --git a/client-tauri/src/pages/Dynamic.tsx b/client-tauri/src/pages/Dynamic.tsx index 7bff1f7d3..93ff3ad7e 100644 --- a/client-tauri/src/pages/Dynamic.tsx +++ b/client-tauri/src/pages/Dynamic.tsx @@ -1,6 +1,8 @@ import { Link } from "react-router-dom"; import { BaseSyntheticEvent } from "react"; +import { Operator } from "@stirling-pdf/shared-operations/src/functions"; +import i18next from "i18next"; function Dynamic() { const operators = ["impose"]; // TODO: Make this dynamic @@ -8,8 +10,23 @@ function Dynamic() { function selectionChanged(s: BaseSyntheticEvent) { const selectedValue = s.target.value; if(selectedValue == "none") return; - const LoadedOperator = import(`@stirling-pdf/shared-operations/src/functions/${selectedValue}`); - LoadedOperator.then(console.log); + + i18next.loadNamespaces("impose", (err, t) => { + if (err) throw err; + + const LoadingModule = import(`@stirling-pdf/shared-operations/src/functions/${selectedValue}`) as Promise<{ [key: string]: typeof Operator }>; + LoadingModule.then((Module) => { + const Operator = Module[capitalizeFirstLetter(selectedValue)]; + const description = Operator.schema.describe(); // TODO: The browser build of joi does not include describe. + + console.log(description); + // TODO: use description to generate fields + }); + }); + } + + function capitalizeFirstLetter(string: String) { + return string.charAt(0).toUpperCase() + string.slice(1); } return ( diff --git a/package-lock.json b/package-lock.json index e3b869212..96bc634de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -896,11 +896,45 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@hapi/address": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@hapi/address/-/address-5.1.1.tgz", + "integrity": "sha512-A+po2d/dVoY7cYajycYI43ZbYMXukuopIsqCjh5QzsBCipDtdofHntljDlpccMjIfTy6UOkg+5KPriwYch2bXA==", + "dependencies": { + "@hapi/hoek": "^11.0.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@hapi/address/node_modules/@hapi/hoek": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-11.0.4.tgz", + "integrity": "sha512-PnsP5d4q7289pS2T2EgGz147BFJ2Jpb4yrEdkpz2IhgEUzos1S7HTl7ezWh1yfYzYlj89KzLdCRkqsP6SIryeQ==" + }, + "node_modules/@hapi/formula": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@hapi/formula/-/formula-3.0.2.tgz", + "integrity": "sha512-hY5YPNXzw1He7s0iqkRQi+uMGh383CGdyyIGYtB+W5N3KHPXoqychklvHhKCC9M3Xtv0OCs/IHw+r4dcHtBYWw==" + }, "node_modules/@hapi/hoek": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==" }, + "node_modules/@hapi/pinpoint": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@hapi/pinpoint/-/pinpoint-2.0.1.tgz", + "integrity": "sha512-EKQmr16tM8s16vTT3cA5L0kZZcTMU5DUOZTuvpnY738m+jyP3JIUj+Mm1xc1rsLkGBQ/gVnfKYPwOmPg1tUR4Q==" + }, + "node_modules/@hapi/tlds": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@hapi/tlds/-/tlds-1.0.2.tgz", + "integrity": "sha512-JHeIUwqHw3xk1fMJNU8YL2eYhRZxTMExTOnnqHp0y0NZJAGs2UypK2Dg+QT1NPnm29wj5n2zvg5Aoi9Dq/IZGg==", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/@hapi/topo": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", @@ -2818,6 +2852,32 @@ "vite": "^4.2.0 || ^5.0.0" } }, + "node_modules/@vizzly/joi": { + "version": "17.11.0", + "resolved": "https://registry.npmjs.org/@vizzly/joi/-/joi-17.11.0.tgz", + "integrity": "sha512-VpLziKclrc0ul9euaxhD0C+31CXwkmrKBxg7RKNEKnZi/iy4mQPERkxBHCaYksjoZKQEOAnB/IXY7PPbF/OiUw==", + "dependencies": { + "@hapi/address": "^5.1.1", + "@hapi/formula": "^3.0.2", + "@hapi/hoek": "^11.0.2", + "@hapi/pinpoint": "^2.0.1", + "@hapi/tlds": "^1.0.2", + "@hapi/topo": "^6.0.2" + } + }, + "node_modules/@vizzly/joi/node_modules/@hapi/hoek": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-11.0.4.tgz", + "integrity": "sha512-PnsP5d4q7289pS2T2EgGz147BFJ2Jpb4yrEdkpz2IhgEUzos1S7HTl7ezWh1yfYzYlj89KzLdCRkqsP6SIryeQ==" + }, + "node_modules/@vizzly/joi/node_modules/@hapi/topo": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-6.0.2.tgz", + "integrity": "sha512-KR3rD5inZbGMrHmgPxsJ9dbi6zEK+C3ZwUwTa+eMwWLz7oijWUTWD2pMSNNYJAU6Qq+65NkxXjqHr/7LM2Xkqg==", + "dependencies": { + "@hapi/hoek": "^11.0.2" + } + }, "node_modules/@wasmer/wasmfs": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/@wasmer/wasmfs/-/wasmfs-0.12.0.tgz", @@ -9320,6 +9380,7 @@ "version": "0.0.0", "license": "ISC", "dependencies": { + "@vizzly/joi": "^17.11.0", "i18next-resources-to-backend": "^1.2.0", "image-js": "^0.35.5", "next-i18next": "^15.1.1", diff --git a/shared-operations/package.json b/shared-operations/package.json index ea4c3e36c..e6e87e6fc 100644 --- a/shared-operations/package.json +++ b/shared-operations/package.json @@ -9,6 +9,7 @@ "author": "", "license": "ISC", "dependencies": { + "@vizzly/joi": "^17.11.0", "i18next-resources-to-backend": "^1.2.0", "image-js": "^0.35.5", "next-i18next": "^15.1.1", diff --git a/shared-operations/src/functions/impose.ts b/shared-operations/src/functions/impose.ts index 2d1340845..516f4ad18 100644 --- a/shared-operations/src/functions/impose.ts +++ b/shared-operations/src/functions/impose.ts @@ -8,7 +8,6 @@ import Joi from "joi"; import { JoiPDFFileSchema } from "../wrappers/PdfFileJoi"; import i18next from "i18next"; -i18next.loadNamespaces("impose", (err, t) => { if (err) throw err; }); export class Impose extends Operator { static type = "impose"; diff --git a/shared-operations/src/workflow/getOperatorByName.ts b/shared-operations/src/workflow/getOperatorByName.ts index b3890c2a1..99bd9e9cd 100644 --- a/shared-operations/src/workflow/getOperatorByName.ts +++ b/shared-operations/src/workflow/getOperatorByName.ts @@ -1,7 +1,10 @@ import { Operator } from "../functions"; +import i18next from "i18next"; -// TODO: Import other Operators (could make this dynamic) +// TODO: Import other Operators (should make this dynamic imports) +i18next.loadNamespaces("impose", (err, t) => { if (err) throw err; }); import { Impose } from "../functions/impose"; + export const Operators = { Impose: Impose };