From dd16d4e228997a96ac5765c6bbd33eada2cacdd3 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Mon, 11 Mar 2024 19:42:49 -0400 Subject: [PATCH 1/3] Make URLs slightly cleaner --- src/models/configuration.js | 15 +++++++++++++++ src/utils/formUtils.js | 21 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/models/configuration.js b/src/models/configuration.js index 27f370c..1ba5950 100644 --- a/src/models/configuration.js +++ b/src/models/configuration.js @@ -99,3 +99,18 @@ export const schema = z.object({ }); /** @typedef {z.infer} Configuration */ + +export const defaultConfig = { + rotatePage: false, + paperRotation90: false, + cropMarks: false, + cutMarks: false, + pdfEdgeMarks: false, + mainForeEdgePaddingPt: 0, + bindingEdgePaddingPt: 0, + topEdgePaddingPt: 0, + bottomEdgePaddingPt: 0, + sigLength: 4, // Specific to standard + foreEdgePaddingPt: 0, // specific to wacky small + flyleafs: 1, +}; diff --git a/src/utils/formUtils.js b/src/utils/formUtils.js index a477b5b..dcdbbb4 100644 --- a/src/utils/formUtils.js +++ b/src/utils/formUtils.js @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -import { schema } from '../models/configuration'; +import { defaultConfig, schema } from '../models/configuration'; import { clearLocalSettings, getLocalSettings, setLocalSettings } from './localStorageUtils'; import { renderFormFromSettings, renderInfoBox, renderPageCount, renderWacky } from './renderUtils'; import { clearUrlParams, setUrlParams, toUrlParams, updateWindowLocation } from './uri'; @@ -47,7 +47,8 @@ const fromFormToConfiguration = (form) => * @param { import("../models/configuration").Configuration } configuration The configuration to set */ const setConfigurationToUrl = (configuration) => { - updateWindowLocation(setUrlParams(window.location.href, configuration)); + const cleanedConfig = removeDefaults(configuration); + updateWindowLocation(setUrlParams(window.location.href, cleanedConfig)); }; /** @@ -108,3 +109,19 @@ export const resetForm = () => { updateWindowLocation(clearUrlParams(window.location.href)); return loadForm(); }; + +/** + * Returns a version of the configuration with any items set to default values removed + * to keep url strings a little cleaner. + * @param { import("../models/configuration").Configuration } configuration The form to save + * @returns { import("../models/configuration").Configuration } The updated configuration set + */ +function removeDefaults(configuration) { + const cleaned = {}; + Object.keys(configuration).forEach((key) => { + if (defaultConfig[key] != configuration[key]) { + cleaned[key] = configuration[key]; + } + }); + return cleaned; +} From 421a617a38830574d62346f630b2fa66170c8376 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Tue, 12 Mar 2024 13:42:59 -0400 Subject: [PATCH 2/3] Add more defaults and move handling to a more logical location --- src/models/configuration.js | 19 +++---------------- src/utils/formUtils.js | 21 ++------------------- src/utils/uri.js | 7 +++++++ 3 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/models/configuration.js b/src/models/configuration.js index 1ba5950..ab3c71a 100644 --- a/src/models/configuration.js +++ b/src/models/configuration.js @@ -94,23 +94,10 @@ export const schema = z.object({ foreEdgePaddingPt: urlSafe(z.coerce.number()).default(0), // specific to wacky small wackySpacing, // specific to wacky small flyleafs: urlSafe(z.coerce.number()).default(1), - paperSizeCustomWidth: urlSafe(z.coerce.number()), - paperSizeCustomHeight: urlSafe(z.coerce.number()), + paperSizeCustomWidth: urlSafe(z.coerce.number()).default(0), + paperSizeCustomHeight: urlSafe(z.coerce.number()).default(0), }); /** @typedef {z.infer} Configuration */ -export const defaultConfig = { - rotatePage: false, - paperRotation90: false, - cropMarks: false, - cutMarks: false, - pdfEdgeMarks: false, - mainForeEdgePaddingPt: 0, - bindingEdgePaddingPt: 0, - topEdgePaddingPt: 0, - bottomEdgePaddingPt: 0, - sigLength: 4, // Specific to standard - foreEdgePaddingPt: 0, // specific to wacky small - flyleafs: 1, -}; +export const defaultConfig = schema.parse({}); diff --git a/src/utils/formUtils.js b/src/utils/formUtils.js index dcdbbb4..a477b5b 100644 --- a/src/utils/formUtils.js +++ b/src/utils/formUtils.js @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -import { defaultConfig, schema } from '../models/configuration'; +import { schema } from '../models/configuration'; import { clearLocalSettings, getLocalSettings, setLocalSettings } from './localStorageUtils'; import { renderFormFromSettings, renderInfoBox, renderPageCount, renderWacky } from './renderUtils'; import { clearUrlParams, setUrlParams, toUrlParams, updateWindowLocation } from './uri'; @@ -47,8 +47,7 @@ const fromFormToConfiguration = (form) => * @param { import("../models/configuration").Configuration } configuration The configuration to set */ const setConfigurationToUrl = (configuration) => { - const cleanedConfig = removeDefaults(configuration); - updateWindowLocation(setUrlParams(window.location.href, cleanedConfig)); + updateWindowLocation(setUrlParams(window.location.href, configuration)); }; /** @@ -109,19 +108,3 @@ export const resetForm = () => { updateWindowLocation(clearUrlParams(window.location.href)); return loadForm(); }; - -/** - * Returns a version of the configuration with any items set to default values removed - * to keep url strings a little cleaner. - * @param { import("../models/configuration").Configuration } configuration The form to save - * @returns { import("../models/configuration").Configuration } The updated configuration set - */ -function removeDefaults(configuration) { - const cleaned = {}; - Object.keys(configuration).forEach((key) => { - if (defaultConfig[key] != configuration[key]) { - cleaned[key] = configuration[key]; - } - }); - return cleaned; -} diff --git a/src/utils/uri.js b/src/utils/uri.js index 51092f6..33849ce 100644 --- a/src/utils/uri.js +++ b/src/utils/uri.js @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +import { defaultConfig } from '../models/configuration'; + /** * Gets parameters from a URL. * @param { string } url The URL to get the params from @@ -26,6 +28,11 @@ export const setUrlParams = (url, params) => { continue; } + if (value === defaultConfig[key]) { + urlRepresentation.searchParams.delete(key); + continue; + } + urlRepresentation.searchParams.set(key, String(value)); } From e83899285a6657d566177d10c9986fad883a1476 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Tue, 12 Mar 2024 22:11:12 -0400 Subject: [PATCH 3/3] Fix customSig param and bump version number --- package.json | 2 +- src/models/configuration.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fd3fccc..b4f5596 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bookbinder", - "version": "1.3.7", + "version": "1.4.0", "description": "An app to rearrange PDF pages for printing for bookbinding", "type": "module", "scripts": { diff --git a/src/models/configuration.js b/src/models/configuration.js index ab3c71a..07a1fc0 100644 --- a/src/models/configuration.js +++ b/src/models/configuration.js @@ -90,7 +90,7 @@ export const schema = z.object({ bottomEdgePaddingPt: urlSafe(z.coerce.number()).default(0), sigFormat, sigLength: urlSafe(z.coerce.number()).default(4), // Specific to standard - customSigLength: urlSafe(commaSeparatedNumberList).default([]), // Specific to custom. + customSigLength: urlSafe(commaSeparatedNumberList).default(null), // Specific to custom. foreEdgePaddingPt: urlSafe(z.coerce.number()).default(0), // specific to wacky small wackySpacing, // specific to wacky small flyleafs: urlSafe(z.coerce.number()).default(1),