diff --git a/esbuild.config.mjs b/esbuild.config.mjs index f9fd6088..eef54b86 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -45,7 +45,6 @@ esbuild.context({ }, entryPoints: ['plugin/main.ts', 'plugin/styles.css'], bundle: true, - sourcemap: true, external: ['obsidian', 'electron', ...builtins], format: 'cjs', outdir: './', diff --git a/package-lock.json b/package-lock.json index 9a1bdf60..49a729e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -307,9 +307,9 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.21.0.tgz", - "integrity": "sha512-eD/JQ21IG2i1FraJnTMbUarAUkA7G988ofehG5MDCRXaUU91rEBJuCeSoou2Sk1y4RbLYXzqEg1QLwEmRU4qcQ==", + "version": "7.21.2", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.21.2.tgz", + "integrity": "sha512-79yj2AR4U/Oqq/WOV7Lx6hUjau1Zfo4cI+JLAVYeMV5XIlbOhmjEk5ulbTc9fMpmlojzZHkUUxAiK+UKn+hNQQ==", "dev": true, "dependencies": { "@babel/helper-environment-visitor": "^7.18.9", @@ -318,8 +318,8 @@ "@babel/helper-split-export-declaration": "^7.18.6", "@babel/helper-validator-identifier": "^7.19.1", "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.0", - "@babel/types": "^7.21.0" + "@babel/traverse": "^7.21.2", + "@babel/types": "^7.21.2" }, "engines": { "node": ">=6.9.0" @@ -486,9 +486,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.21.1", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.1.tgz", - "integrity": "sha512-JzhBFpkuhBNYUY7qs+wTzNmyCWUHEaAFpQQD2YfU1rPL38/L43Wvid0fFkiOCnHvsGncRZgEPyGnltABLcVDTg==", + "version": "7.21.2", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.2.tgz", + "integrity": "sha512-URpaIJQwEkEC2T9Kn+Ai6Xe/02iNaVCuT/PtoRz3GPVJVDpPd7mLo+VddTbhCRU9TXqW5mSrQfXZyi8kDKOVpQ==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -1266,12 +1266,12 @@ } }, "node_modules/@babel/plugin-transform-modules-commonjs": { - "version": "7.20.11", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.20.11.tgz", - "integrity": "sha512-S8e1f7WQ7cimJQ51JkAaDrEtohVEitXjgCGAS2N8S31Y42E+kWwfSz83LYz57QdBm7q9diARVqanIaH2oVgQnw==", + "version": "7.21.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.21.2.tgz", + "integrity": "sha512-Cln+Yy04Gxua7iPdj6nOV96smLGjpElir5YwzF0LBPKoPlLDNJePNlrGGaybAJkd0zKRnOVXOgizSqPYMNYkzA==", "dev": true, "dependencies": { - "@babel/helper-module-transforms": "^7.20.11", + "@babel/helper-module-transforms": "^7.21.2", "@babel/helper-plugin-utils": "^7.20.2", "@babel/helper-simple-access": "^7.20.2" }, @@ -1702,19 +1702,19 @@ } }, "node_modules/@babel/traverse": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.21.0.tgz", - "integrity": "sha512-Xdt2P1H4LKTO8ApPfnO1KmzYMFpp7D/EinoXzLYN/cHcBNrVCAkAtGUcXnHXrl/VGktureU6fkQrHSBE2URfoA==", + "version": "7.21.2", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.21.2.tgz", + "integrity": "sha512-ts5FFU/dSUPS13tv8XiEObDu9K+iagEKME9kAbaP7r0Y9KtZJZ+NGndDvWoRAYNpeWafbpFeki3q9QoMD6gxyw==", "dev": true, "dependencies": { "@babel/code-frame": "^7.18.6", - "@babel/generator": "^7.21.0", + "@babel/generator": "^7.21.1", "@babel/helper-environment-visitor": "^7.18.9", "@babel/helper-function-name": "^7.21.0", "@babel/helper-hoist-variables": "^7.18.6", "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.21.0", - "@babel/types": "^7.21.0", + "@babel/parser": "^7.21.2", + "@babel/types": "^7.21.2", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -1723,9 +1723,9 @@ } }, "node_modules/@babel/types": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.0.tgz", - "integrity": "sha512-uR7NWq2VNFnDi7EYqiRz2Jv/VQIu38tu64Zy8TX2nQFQ6etJ9V/Rr2msW8BS132mum2rL645qpDrLtAJtVpuow==", + "version": "7.21.2", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.2.tgz", + "integrity": "sha512-3wRZSs7jiFaB8AjxiiD+VqN5DTG2iRvJGQ+qYFrs/654lg6kGTQWIOFjlBo5RaXuAZjBmP3+OQH4dmhqiiyYxw==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.19.4", @@ -2135,9 +2135,9 @@ } }, "node_modules/@eslint/eslintrc": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.4.1.tgz", - "integrity": "sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.0.tgz", + "integrity": "sha512-fluIaaV+GyV24CCu/ggiHdV+j4RNh85yQnAYS/G2mZODZgGmmlrgCydjUcV3YvxCm9x8nMAfThsqTni4KiXT4A==", "dev": true, "dependencies": { "ajv": "^6.12.4", @@ -2202,6 +2202,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@eslint/js": { + "version": "8.35.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.35.0.tgz", + "integrity": "sha512-JXdzbRiWclLVoD8sNUjR443VVlYqiYmDVT6rGUEIEHU5YJW0gaVZwV2xgM7D4arkvASqD0IlLUVjHiFuxaftRw==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/@google-automations/git-file-utils": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@google-automations/git-file-utils/-/git-file-utils-1.2.6.tgz", @@ -3452,9 +3461,9 @@ } }, "node_modules/@sinclair/typebox": { - "version": "0.25.23", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.25.23.tgz", - "integrity": "sha512-VEB8ygeP42CFLWyAJhN5OklpxUliqdNEUcXb4xZ/CINqtYGTjL5ukluKdKzQ0iWdUxyQ7B0539PAUhHKrCNWSQ==", + "version": "0.25.24", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.25.24.tgz", + "integrity": "sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ==", "dev": true }, "node_modules/@sinonjs/commons": { @@ -3590,9 +3599,9 @@ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==" }, "node_modules/@types/node": { - "version": "18.14.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.0.tgz", - "integrity": "sha512-5EWrvLmglK+imbCJY0+INViFWUHg1AHel1sq4ZVSfdcNqGy9Edv3UB9IIzzg+xPaUcAgZYcfVs2fBcwDeZzU0A==", + "version": "18.14.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.2.tgz", + "integrity": "sha512-1uEQxww3DaghA0RxqHx0O0ppVlo43pJhepY51OxuQIKHpjbnYLA7vcdwioNPzIqmC2u3I/dmylcqjlh0e7AyUA==", "dev": true }, "node_modules/@types/normalize-package-data": { @@ -4564,9 +4573,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001457", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001457.tgz", - "integrity": "sha512-SDIV6bgE1aVbK6XyxdURbUE89zY7+k1BBBaOwYwkNCglXlel/E7mELiHC64HQ+W0xSKlqWhV9Wh7iHxUjMs4fA==", + "version": "1.0.30001458", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001458.tgz", + "integrity": "sha512-lQ1VlUUq5q9ro9X+5gOEyH7i3vm+AYVT1WDCVB69XOZ17KZRhnZ9J0Sqz7wTHQaLBJccNCHq8/Ww5LlOIZbB0w==", "dev": true, "funding": [ { @@ -5131,9 +5140,9 @@ "dev": true }, "node_modules/core-js-compat": { - "version": "3.28.0", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.28.0.tgz", - "integrity": "sha512-myzPgE7QodMg4nnd3K1TDoES/nADRStM8Gpz0D6nhkwbmwEnE0ZGJgoWsvQ722FR8D7xS0n0LV556RcEicjTyg==", + "version": "3.29.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.29.0.tgz", + "integrity": "sha512-ScMn3uZNAFhK2DGoEfErguoiAHhV2Ju+oJo/jK08p7B3f3UhocUrCCkTvnZaiS+edl5nlIoiBXKcwMc6elv4KQ==", "dev": true, "dependencies": { "browserslist": "^4.21.5" @@ -5492,9 +5501,9 @@ "integrity": "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==" }, "node_modules/electron-to-chromium": { - "version": "1.4.308", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.308.tgz", - "integrity": "sha512-qyTx2aDFjEni4UnRWEME9ubd2Xc9c0zerTUl/ZinvD4QPsF0S7kJTV/Es/lPCTkNX6smyYar+z/n8Cl6pFr8yQ==", + "version": "1.4.311", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.311.tgz", + "integrity": "sha512-RoDlZufvrtr2Nx3Yx5MB8jX3aHIxm8nRWPJm3yVvyHmyKaRvn90RjzB6hNnt0AkhS3IInJdyRfQb4mWhPvUjVw==", "dev": true }, "node_modules/emittery": { @@ -5743,12 +5752,13 @@ } }, "node_modules/eslint": { - "version": "8.34.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.34.0.tgz", - "integrity": "sha512-1Z8iFsucw+7kSqXNZVslXS8Ioa4u2KM7GPwuKtkTFAqZ/cHMcEaR+1+Br0wLlot49cNxIiZk5wp8EAbPcYZxTg==", + "version": "8.35.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.35.0.tgz", + "integrity": "sha512-BxAf1fVL7w+JLRQhWl2pzGeSiGqbWumV4WNvc9Rhp6tiCtm4oHnyPBSEtMGZwrQgudFQ+otqzWoPB7x+hxoWsw==", "dev": true, "dependencies": { - "@eslint/eslintrc": "^1.4.1", + "@eslint/eslintrc": "^2.0.0", + "@eslint/js": "8.35.0", "@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", @@ -5762,7 +5772,7 @@ "eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.3.0", "espree": "^9.4.0", - "esquery": "^1.4.0", + "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^6.0.1", @@ -6797,9 +6807,9 @@ } }, "node_modules/get-pkg-repo/node_modules/readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -10514,9 +10524,9 @@ } }, "node_modules/preact": { - "version": "10.12.1", - "resolved": "https://registry.npmjs.org/preact/-/preact-10.12.1.tgz", - "integrity": "sha512-l8386ixSsBdbreOAkqtrwqHwdvR35ID8c3rKPa8lCWuO86dBi32QWHV4vfsZK1utLLFMvw+Z5Ad4XLkZzchscg==", + "version": "10.13.0", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.13.0.tgz", + "integrity": "sha512-ERdIdUpR6doqdaSIh80hvzebHB7O6JxycOhyzAeLEchqOq/4yueslQbfnPwXaNhAYacFTyCclhwkEbOumT0tHw==", "dev": true, "funding": { "type": "opencollective", @@ -10773,9 +10783,9 @@ } }, "node_modules/readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.1.tgz", + "integrity": "sha512-+rQmrWMYGA90yenhTYsLWAsLsqVC8osOw6PKE1HDYiO0gdPeKe/xDHNzIAIn4C91YQ6oenEhfYqqc1883qHbjQ==", "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -11057,9 +11067,9 @@ } }, "node_modules/release-please/node_modules/type-fest": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.6.0.tgz", - "integrity": "sha512-RqTRtKTzvPpNdDUp1dVkKQRunlPITk4mXeqFlAZoJsS+fLRn8AdPK0TcQDumGayhU7fjlBfiBjsq3pe3rIfXZQ==", + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.6.1.tgz", + "integrity": "sha512-htXWckxlT6U4+ilVgweNliPqlsVSSucbxVexRYllyMVJDtf5rTjv6kF/s+qAd4QSL1BZcnJPEJavYBPQiWuZDA==", "engines": { "node": ">=14.16" }, @@ -11890,13 +11900,13 @@ } }, "node_modules/tsconfig-paths": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz", - "integrity": "sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==", + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", + "integrity": "sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==", "dev": true, "dependencies": { "@types/json5": "^0.0.29", - "json5": "^1.0.1", + "json5": "^1.0.2", "minimist": "^1.2.6", "strip-bom": "^3.0.0" } diff --git a/plugin/i18n/i18next.d.ts b/plugin/@types/i18next.d.ts similarity index 76% rename from plugin/i18n/i18next.d.ts rename to plugin/@types/i18next.d.ts index a3e63bdc..969ad47b 100644 --- a/plugin/i18n/i18next.d.ts +++ b/plugin/@types/i18next.d.ts @@ -1,8 +1,8 @@ -import { ressources } from "./i18next"; - -declare module "i18next" { - interface CustomTypeOptions { - readonly resources: typeof ressources["en"]; - readonly returnNull: false - } -} +import { ressources } from "../i18n/i18next"; + +declare module "i18next" { + interface CustomTypeOptions { + readonly resources: typeof ressources["en"]; + readonly returnNull: false + } +} diff --git a/plugin/i18n/locales/en.json b/plugin/i18n/locales/en.json index f49de8b7..27a7cb31 100644 --- a/plugin/i18n/locales/en.json +++ b/plugin/i18n/locales/en.json @@ -349,8 +349,6 @@ "title": "Default Folder" }, "filepathRegex": { - "desc": "The replacement won't be applied to the filename. Use the same settings than the filename replacement.", - "placeholder": "Filepath edit" }, "folderBehavior": { "desc": "Choose the file tree in the repository, with using a frontmatter key, a fixed folder or your Obsidian file tree.", @@ -364,9 +362,12 @@ "placeholder": "category", "title": "Frontmatter key" }, - "frontmatterRegex": { + "regexFilePathTitle": { "desc": "If the text is between \"//\", it will be used as a regex. Otherwise, it will be used as a string.", - "placeholder": "Filename edit" + "title": { + "FolderPathTitle": "Apply edit on the folder path or the filename (automatically)", + "titleOnly": "Apply edit on the filename (automatically)" + } }, "rootFolder": { "desc": "Append this path to the folder set by the frontmatter key", diff --git a/plugin/i18n/locales/fr.json b/plugin/i18n/locales/fr.json index 4c470b8a..afa3db07 100644 --- a/plugin/i18n/locales/fr.json +++ b/plugin/i18n/locales/fr.json @@ -131,7 +131,7 @@ "desc": "Replace des textes (ou des regex) dans le fichier par la valeur donnée.", "title": "Remplacement de texte" }, - "title": "Remplacer le {{- what}}", + "title": "Remplacer les nom du fichier ou son chemin", "warningPath": "Attention ! Utiliser le caractère \"/\" modifiera le chemin du fichier. Veuillez faire attention avec cette option." }, "dataview": { @@ -349,8 +349,6 @@ "title": "Dossier par défaut" }, "filepathRegex": { - "desc": "Le remplacement ne sera pas appliqué sur le nom du fichier. Utilise les mêmes options que pour le nom du fichier", - "placeholder": "Modification du chemin" }, "folderBehavior": { "desc": "Choisir la hierarchie des dossiers dans le dépôt, en se basant sur une clé frontmatter, un dossier fixe ou la hierarchie des dossiers dans Obsidian.", @@ -364,9 +362,12 @@ "placeholder": "category", "title": "Clé frontmatter" }, - "frontmatterRegex": { + "regexFilePathTitle": { "desc": "Si le texte est entre \"//\", il sera interprété comme une expression régulière. Sinon, il sera interprété comme du texte brut.", - "placeholder": "Modification du titre" + "title": { + "FolderPathTitle": "Éditer le titre et le chemin du dossier (automatiquement)", + "titleOnly": "Éditer le titre (automatiquement)" + } }, "rootFolder": { "desc": "Ajouter ce chemin au dossier définit par la clé frontmatter.", diff --git a/plugin/main.ts b/plugin/main.ts index 163bbcc2..c7d8e58c 100644 --- a/plugin/main.ts +++ b/plugin/main.ts @@ -79,6 +79,7 @@ export default class GithubPublisher extends Plugin { lng: translationLanguage, fallbackLng: "en", resources: ressources, + returnNull: false, }); await this.loadSettings(); diff --git a/plugin/settings.ts b/plugin/settings.ts index 50e48e9d..f1a1142d 100644 --- a/plugin/settings.ts +++ b/plugin/settings.ts @@ -399,42 +399,33 @@ export class GithubPublisherSettings extends PluginSettingTab { }); }); } + + let desc = i18next.t("settings.upload.regexFilePathTitle.title.FolderPathTitle") ; + if (uploadSettings.behavior === FolderSettings.fixed) { + desc = i18next.t("settings.upload.regexFilePathTitle.title.titleOnly"); + } + new Setting(this.settingsPage) - .setName( - i18next.t( - "settings.upload.frontmatterRegex.placeholder" - ) - ) + .setName(desc) .setDesc( - i18next.t("settings.upload.frontmatterRegex.desc") + i18next.t("settings.upload.regexFilePathTitle.desc") ) .addButton((button) => { button .setIcon("pencil") .onClick(async () => { - new ModalRegexFilePathName(this.app, this.plugin.settings, "file", (result => { - this.plugin.settings.upload.replaceTitle = result.upload.replaceTitle; + let allRegex = uploadSettings.replaceTitle; + if (uploadSettings.behavior !== FolderSettings.fixed) { + allRegex = allRegex.concat(uploadSettings.replacePath); + } + new ModalRegexFilePathName(this.app, this.plugin.settings, allRegex, (result => { + uploadSettings.replacePath = result.filter(title => {return title.type === "path";}); + uploadSettings.replaceTitle = result.filter(title => {return title.type === "title";}); this.plugin.saveSettings(); })).open(); }); }); - - if (uploadSettings.behavior !== FolderSettings.fixed) { - new Setting(this.settingsPage) - .setName(i18next.t("settings.upload.filepathRegex.placeholder") ) - .setDesc(i18next.t("settings.upload.filepathRegex.desc") ) - .addButton((button) => { - button - .setIcon("pencil") - .onClick(async () => { - new ModalRegexFilePathName(this.app, this.plugin.settings, "path", (result => { - this.plugin.settings.upload.replacePath = result.upload.replacePath; - this.plugin.saveSettings(); - })).open(); - }); - }); - } - + const folderNoteSettings = new Setting(this.settingsPage) .setName(i18next.t("settings.conversion.links.folderNote.title") ) .setClass("github-publisher-folderNote") diff --git a/plugin/settings/interface.ts b/plugin/settings/interface.ts index 9dc3cf65..dfa596ca 100644 --- a/plugin/settings/interface.ts +++ b/plugin/settings/interface.ts @@ -1,8 +1,14 @@ import { TFile } from "obsidian"; +export enum TypeOfEditRegex { + path = "path", + title = "title", +} + export interface RegexReplace { regex: string; replacement: string; + type: TypeOfEditRegex; } export interface GitHubPublisherSettings { diff --git a/plugin/settings/modal_regex_edition.ts b/plugin/settings/modal_regex_edition.ts index 4e046cbb..e742a6e4 100644 --- a/plugin/settings/modal_regex_edition.ts +++ b/plugin/settings/modal_regex_edition.ts @@ -1,23 +1,35 @@ import {App, Notice, Modal, Setting} from "obsidian"; -import { GitHubPublisherSettings, TextCleaner, RegexReplace } from "./interface"; +import { FolderSettings, GitHubPublisherSettings, RegexReplace, TextCleaner, TypeOfEditRegex } from "./interface"; import i18next from "i18next"; export class ModalRegexFilePathName extends Modal { settings: GitHubPublisherSettings; - type: string; - onSubmit: (settings: GitHubPublisherSettings) => void; + allRegex: RegexReplace[]; + onSubmit: (result: RegexReplace[]) => void; constructor( app: App, settings: GitHubPublisherSettings, - type: string, - onSubmit: (settings: GitHubPublisherSettings) => void) { + allRegex : RegexReplace[], + onSubmit: (result: RegexReplace[]) => void) { super(app); - this.type = type; + this.allRegex = allRegex; this.settings = settings; this.onSubmit = onSubmit; } - forbiddenValue(value: string, onWhat: string): (string|boolean)[] { + classValue(allRegex: RegexReplace[]) { + this.settings.upload.replacePath = allRegex.filter((regex) => { + return regex.type === TypeOfEditRegex.path; + }); + this.settings.upload.replaceTitle = allRegex.filter((regex) => { + return regex.type === TypeOfEditRegex.title; + } + ); + } + + forbiddenValue(value: string, type: TypeOfEditRegex): (string|boolean)[] { + let onWhat = type === TypeOfEditRegex.path ? i18next.t("common.path.folder") : i18next.t("common.path.file"); + onWhat = onWhat.toLowerCase(); let isForbidden = false; if (value == "/") { new Notice(i18next.t("settings.conversion.censor.forbiddenValue", {what: onWhat, forbiddenChar: value})); @@ -25,12 +37,12 @@ export class ModalRegexFilePathName extends Modal { isForbidden = true; } else if ( - (value.match(/[><:"|?*]|(\\\/)|(^\w+\/\w+)|(\\)/)) && (this.type === "file") + (value.match(/[><:"|?*]|(\\\/)|(^\w+\/\w+)|(\\)/)) && (type === TypeOfEditRegex.title) ) { new Notice(i18next.t("settings.conversion.censor.forbiddenValue", {what: onWhat, forbiddenChar: value.match(/[><:"|?*]|(\\\/)|(^\w+\/\w+)|(\\)/)[0]})); value = ""; isForbidden = true; - } else if (this.type === "path") { + } else if (type === TypeOfEditRegex.path) { if (value.match(/[\\><:"|?*]/)){ new Notice(i18next.t("settings.conversion.censor.forbiddenValue", { what: onWhat, forbiddenChar: value.match(/[\\><:"|?*]/)[0]})); value = ""; @@ -45,19 +57,26 @@ export class ModalRegexFilePathName extends Modal { onOpen() { const {contentEl} = this; contentEl.empty(); - let onWhat = this.type === "path" ? i18next.t("common.path.folder") : i18next.t("common.path.file"); - onWhat = onWhat.toLowerCase(); - contentEl.createEl("h2", {text: i18next.t("settings.conversion.censor.title", {what: onWhat})}); - if (this.type === "path" && !this.settings.upload.replacePath) { + contentEl.createEl("h2", {text: i18next.t("settings.conversion.censor.title")}); + if (!this.settings.upload.replacePath) { this.settings.upload.replacePath = []; } else if (!this.settings.upload.replaceTitle) { this.settings.upload.replaceTitle = []; } - const what: RegexReplace[] = this.type === "path" ? this.settings.upload.replacePath : this.settings.upload.replaceTitle; + this.settings.upload.replacePath.forEach((title) => { + if (!title.type) { + title.type = TypeOfEditRegex.path; + } + }); + this.settings.upload.replaceTitle.forEach((title) => { + if (!title.type) { + title.type = TypeOfEditRegex.title; + } + }); - for (const title of what) { - new Setting(contentEl) + for (const title of this.allRegex) { + const sett = new Setting(contentEl) .setClass("github-publisher-censor-entry") .addText((text) => { text.inputEl.style.width = "100%"; @@ -74,30 +93,47 @@ export class ModalRegexFilePathName extends Modal { .onChange((value) => { title.replacement = value; }); - }) - .addExtraButton((button) => { - button - .setIcon("trash") - .onClick(() => { - if (this.type === "path") { - this.settings.upload.replacePath = this.settings.upload.replacePath.filter((t) => t !== title); - } else { - this.settings.upload.replaceTitle = this.settings.upload.replaceTitle.filter((t) => t !== title); - } - this.onOpen(); + }); + + if (this.settings.upload.behavior !== FolderSettings.fixed) { + sett.addDropdown((dropdown) => { + dropdown + .addOption("path", i18next.t("common.path.folder")) + .addOption("title", i18next.t("common.path.file")) + .setValue(title.type) + .onChange((value) => { + title.type = value as TypeOfEditRegex; + }); }); + } else { + sett + .addButton((button) => { + button.buttonEl.classList.add("github-publisher-disabled-button"); + button.setButtonText(i18next.t("common.path.file")); + }); + } + sett.addExtraButton((button) => { + button + .setIcon("trash") + .onClick(() => { + //remove replace + this.allRegex.splice(this.allRegex.indexOf(title), 1); + this.onOpen(); + }); + }); } new Setting(contentEl) + .setClass("github-publisher-modals") .addButton((button) => { button .setIcon("plus") .onClick(() => { - if (this.type === "path") { - this.settings.upload.replacePath.push({regex: "", replacement: ""}); - } else { - this.settings.upload.replaceTitle.push({regex: "", replacement: ""}); - } + this.allRegex.push({ + regex: "", + replacement: "", + type: TypeOfEditRegex.title + }); this.onOpen(); }); }) @@ -106,9 +142,9 @@ export class ModalRegexFilePathName extends Modal { .setButtonText(i18next.t("common.save")) .onClick(() => { const canBeValidated: boolean[] = []; - what.forEach((title) => { - const isForbiddenEntry = this.forbiddenValue(title.regex, onWhat); - const isForbiddenReplace = this.forbiddenValue(title.replacement, onWhat); + this.allRegex.forEach((title) => { + const isForbiddenEntry = this.forbiddenValue(title.regex, title.type); + const isForbiddenReplace = this.forbiddenValue(title.replacement, title.type); canBeValidated.push(isForbiddenEntry[1] as boolean); canBeValidated.push(isForbiddenReplace[1] as boolean); if (isForbiddenEntry[1] || isForbiddenReplace[1]) { @@ -117,7 +153,7 @@ export class ModalRegexFilePathName extends Modal { } }); if (!canBeValidated.includes(true)) { - this.onSubmit(this.settings); + this.onSubmit(this.allRegex); this.close(); } }); diff --git a/plugin/styles.css b/plugin/styles.css index 5b692225..b99d96f6 100644 --- a/plugin/styles.css +++ b/plugin/styles.css @@ -12,8 +12,9 @@ summary.github-publisher-summary { } .setting-item.github-publisher-censor-entry { border: 0 !important; - padding: 0 !important; + padding: 5px !important; } + hr.github-publisher-hr { margin: 1px !important; padding-bottom: 1px; @@ -228,3 +229,19 @@ a.github-publisher-download:hover{ font-size: 14px; } +.github-publisher-disabled-button { + pointer-events: none; + opacity: 0.5; + font-style: italic; + color: var(--text-muted); + cursor: default; + box-shadow: none !important; + border: none !important; + background-color: transparent !important; + font-family: var(--font-monospace); + +} + +.github-publisher-modals { + border-top: 0 !important; +} \ No newline at end of file