From 862e35aa68b87c55952464fa4474248fcc7ce3a1 Mon Sep 17 00:00:00 2001 From: Michael Heuberger Date: Fri, 13 Sep 2024 09:36:03 +1200 Subject: [PATCH] repair various configurations --- .eslintrc.js | 22 ++--- .vscode/extensions.json | 6 ++ .vscode/settings.json | 6 ++ gulpfile.js | 15 +--- package-lock.json | 82 +++++++++---------- package.json | 8 +- .prettierrc.config.cjs => prettier.config.cjs | 6 +- src/js/main.js | 69 ++++++---------- 8 files changed, 99 insertions(+), 115 deletions(-) create mode 100644 .vscode/extensions.json rename .prettierrc.config.cjs => prettier.config.cjs (52%) diff --git a/.eslintrc.js b/.eslintrc.js index 6b57c85..665e772 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,16 +1,16 @@ module.exports = { - parser: '@babel/eslint-parser', - plugins: [], + parser: "@babel/eslint-parser", extends: [ - 'eslint:recommended', - 'standard', - 'standard-jsx', - 'plugin:import/errors', - 'plugin:import/warnings' + "eslint:recommended", + "standard", + "standard-jsx", + "plugin:import/errors", + "plugin:import/warnings", + "prettier", ], env: { browser: true, - es6: true + es6: true, }, rules: {}, globals: { @@ -18,6 +18,6 @@ module.exports = { Backbone: false, jQuery: false, VideomailClient: false, - nfRadio: false - } -} + nfRadio: false, + }, +}; diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..c99c624 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index ca1c649..0634df9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,17 @@ { + "editor.tabSize": 2, + "files.trimTrailingWhitespace": true, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "prettier.configPath": "./prettier.config.cjs", "cSpell.words": [ "apachectl", "binarykitchen", "bytediff", "corejs", + "cssnano", "gulpfile", "kbjohnson", + "styl", "Videomail" ] } diff --git a/gulpfile.js b/gulpfile.js index 7e0873e..d36e432 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -121,23 +121,16 @@ function watch() { function todo() { return gulp - .src([ - "videomail-for-ninja-forms.php", - "src/**/*.{php,js,styl}", - "gulpfile.js", - ]) + .src(["videomail-for-ninja-forms.php", "src/**/*.{php,js,styl}", "gulpfile.js"]) .pipe(plugins.todo()) .pipe(gulp.dest("./")); } function zip() { return gulp - .src( - ["index.php", "readme.txt", "videomail-for-ninja-forms.php", "target/**"], - { - base: "./", - }, - ) + .src(["index.php", "readme.txt", "videomail-for-ninja-forms.php", "target/**"], { + base: "./", + }) .pipe(plugins.zip("videomail-for-ninja-forms.zip")) .pipe(gulp.dest("dist")); } diff --git a/package-lock.json b/package-lock.json index 7c893ab..e2a8bc1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "browser-sync": "3.0.2", "del": "6.1.1", "eslint": "8.57.0", + "eslint-config-prettier": "9.1.0", "eslint-config-standard": "17.1.0", "eslint-plugin-import": "2.30.0", "eslint-plugin-node": "11.1.0", @@ -42,7 +43,7 @@ "minimist": "1.2.8", "nib": "1.2.0", "prettier": "3.3.3", - "standard": "17.1.0", + "standard": "17.1.1", "yargs": "17.7.2" }, "engines": { @@ -2750,18 +2751,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/array.prototype.toreversed": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/array.prototype.toreversed/-/array.prototype.toreversed-1.1.2.tgz", - "integrity": "sha512-wwDCoT4Ck4Cz7sLtgUmzR5UV3YF5mFHUlbChCzZBQZ+0m2cl/DH3tKgvphv1nKgFsJ48oCSg6p91q2Vm0I/ZMA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.2.0", - "es-abstract": "^1.22.1", - "es-shim-unscopables": "^1.0.0" - } - }, "node_modules/array.prototype.tosorted": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/array.prototype.tosorted/-/array.prototype.tosorted-1.1.4.tgz", @@ -5366,6 +5355,19 @@ "node": ">=10" } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-config-standard": { "version": "17.1.0", "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.1.0.tgz", @@ -5668,35 +5670,36 @@ } }, "node_modules/eslint-plugin-react": { - "version": "7.34.3", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.34.3.tgz", - "integrity": "sha512-aoW4MV891jkUulwDApQbPYTVZmeuSyFrudpbTAQuj5Fv8VL+o6df2xIGpw8B0hPjAaih1/Fb0om9grCdyFYemA==", + "version": "7.35.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.35.2.tgz", + "integrity": "sha512-Rbj2R9zwP2GYNcIak4xoAMV57hrBh3hTaR0k7hVjwCQgryE/pw5px4b13EYjduOI0hfXyZhwBxaGpOTbWSGzKQ==", "dev": true, + "license": "MIT", "dependencies": { "array-includes": "^3.1.8", "array.prototype.findlast": "^1.2.5", "array.prototype.flatmap": "^1.3.2", - "array.prototype.toreversed": "^1.1.2", "array.prototype.tosorted": "^1.1.4", "doctrine": "^2.1.0", "es-iterator-helpers": "^1.0.19", "estraverse": "^5.3.0", + "hasown": "^2.0.2", "jsx-ast-utils": "^2.4.1 || ^3.0.0", "minimatch": "^3.1.2", "object.entries": "^1.1.8", "object.fromentries": "^2.0.8", - "object.hasown": "^1.1.4", "object.values": "^1.2.0", "prop-types": "^15.8.1", "resolve": "^2.0.0-next.5", "semver": "^6.3.1", - "string.prototype.matchall": "^4.0.11" + "string.prototype.matchall": "^4.0.11", + "string.prototype.repeat": "^1.0.0" }, "engines": { "node": ">=4" }, "peerDependencies": { - "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7" } }, "node_modules/eslint-plugin-react/node_modules/doctrine": { @@ -12159,23 +12162,6 @@ "node": ">= 0.4" } }, - "node_modules/object.hasown": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/object.hasown/-/object.hasown-1.1.4.tgz", - "integrity": "sha512-FZ9LZt9/RHzGySlBARE3VF+gE26TxR38SdmqOqliuTnl9wrKulaQs+4dee1V+Io8VfxqzAfHu6YuRgUy8OHoTg==", - "dev": true, - "dependencies": { - "define-properties": "^1.2.1", - "es-abstract": "^1.23.2", - "es-object-atoms": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/object.map": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/object.map/-/object.map-1.0.1.tgz", @@ -17254,9 +17240,9 @@ } }, "node_modules/standard": { - "version": "17.1.0", - "resolved": "https://registry.npmjs.org/standard/-/standard-17.1.0.tgz", - "integrity": "sha512-jaDqlNSzLtWYW4lvQmU0EnxWMUGQiwHasZl5ZEIwx3S/ijZDjZOzs1y1QqKwKs5vqnFpGtizo4NOYX2s0Voq/g==", + "version": "17.1.1", + "resolved": "https://registry.npmjs.org/standard/-/standard-17.1.1.tgz", + "integrity": "sha512-GuqFtDMmpcIMX3R/kLaq+Cm18Pjx6IOpR9KhOYKetmkR5ryCxFtus4rC3JNvSE3l9GarlOZLZpBRHqDA9wY8zw==", "dev": true, "funding": [ { @@ -17272,6 +17258,7 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "eslint": "^8.41.0", "eslint-config-standard": "17.1.0", @@ -17279,8 +17266,8 @@ "eslint-plugin-import": "^2.27.5", "eslint-plugin-n": "^15.7.0", "eslint-plugin-promise": "^6.1.1", - "eslint-plugin-react": "^7.32.2", - "standard-engine": "^15.0.0", + "eslint-plugin-react": "7.35.2", + "standard-engine": "^15.1.0", "version-guard": "^1.1.1" }, "bin": { @@ -17540,6 +17527,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/string.prototype.repeat": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/string.prototype.repeat/-/string.prototype.repeat-1.0.0.tgz", + "integrity": "sha512-0u/TldDbKD8bFCQ/4f5+mNRrXwZ8hg2w7ZR8wa16e8z9XpePWl3eGEcUD0OXpEH/VJH/2G3gjUtR3ZOiBe2S/w==", + "dev": true, + "license": "MIT", + "dependencies": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5" + } + }, "node_modules/string.prototype.trim": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.9.tgz", diff --git a/package.json b/package.json index 89be814..1592e0d 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,12 @@ "build": "gulp build", "lint": "eslint ./src gulpfile.js", "lint:fix": "npm --silent run lint -- --fix; exit 0", - "prettier": "prettier --check ./src gulpfile.js", - "prettier:fix": "prettier --write ./src gulpfile.js", + "prettier": "prettier --check ./src gulpfile.js .eslintrc.js", + "prettier:fix": "prettier --write ./src gulpfile.js .eslintrc.js", "clean": "rm -rf node_modules && rm -rf target && rm -rf package-lock.json", "release": "./env/dev/release.sh" }, + "prettier": "./prettier.config.cjs", "babel": { "presets": [ [ @@ -78,6 +79,7 @@ "browser-sync": "3.0.2", "del": "6.1.1", "eslint": "8.57.0", + "eslint-config-prettier": "9.1.0", "eslint-config-standard": "17.1.0", "eslint-plugin-import": "2.30.0", "eslint-plugin-node": "11.1.0", @@ -99,7 +101,7 @@ "minimist": "1.2.8", "nib": "1.2.0", "prettier": "3.3.3", - "standard": "17.1.0", + "standard": "17.1.1", "yargs": "17.7.2" } } diff --git a/.prettierrc.config.cjs b/prettier.config.cjs similarity index 52% rename from .prettierrc.config.cjs rename to prettier.config.cjs index 1421c77..7171164 100644 --- a/.prettierrc.config.cjs +++ b/prettier.config.cjs @@ -1,8 +1,8 @@ -//@ts-check +// @ts-check /** @type {import('prettier').Config} */ const config = { - "printWidth": 90, + printWidth: 90, }; -module.exports = config; \ No newline at end of file +module.exports = config; diff --git a/src/js/main.js b/src/js/main.js index bfee55b..450d22f 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -23,37 +23,28 @@ const VideomailFieldController = Marionette.Object.extend({ // because the conditional plugin is resetting event handlers. // without the above, we'd be registering too early and the // conditional plugin overrides. - this.listenToOnce( - this.channel, - "init:model", - this.registerVideomailField, - ); + this.listenToOnce(this.channel, "init:model", this.registerVideomailField); // must be coming back from a multi-step where // videomail has already been initialised. so just resume it. - this.listenTo( - nfRadio.channel("nfMP"), - "change:part", - function (params) { - DEBUG && - console.log("nfMP channel event triggered:", "change:part"); - - const currentModels = - params.currentElement?.attributes?.formContentData?.models || []; - - const currentCid = this.fieldModel.cid; - - const currentModel = currentModels.find(function (model) { - return model.cid === currentCid; - }); - - if (currentModel) { - this.loadVideomailClient(); - } else { - this.videomailClient.unload(); - } - }, - ); + this.listenTo(nfRadio.channel("nfMP"), "change:part", function (params) { + DEBUG && console.log("nfMP channel event triggered:", "change:part"); + + const currentModels = + params.currentElement?.attributes?.formContentData?.models || []; + + const currentCid = this.fieldModel.cid; + + const currentModel = currentModels.find(function (model) { + return model.cid === currentCid; + }); + + if (currentModel) { + this.loadVideomailClient(); + } else { + this.videomailClient.unload(); + } + }); } }); }, @@ -170,10 +161,7 @@ const VideomailFieldController = Marionette.Object.extend({ }, onSubmitted: function (videomail) { - let formModel = Backbone.Radio.channel("app").request( - "get:form", - this.getFormId(), - ); + let formModel = Backbone.Radio.channel("app").request("get:form", this.getFormId()); if (!formModel) { // fallback for older versions @@ -188,10 +176,7 @@ const VideomailFieldController = Marionette.Object.extend({ ); // restart submission again, this time to the real wp site - Backbone.Radio.channel("form-" + this.getFormId()).request( - "submit", - formModel, - ); + Backbone.Radio.channel("form-" + this.getFormId()).request("submit", formModel); }, onGoingBack: function () { @@ -284,19 +269,13 @@ const VideomailFieldController = Marionette.Object.extend({ // } getFormValues: function () { let collection; - const formModel = Backbone.Radio.channel("app").request( - "get:form", - this.getFormId(), - ); + const formModel = Backbone.Radio.channel("app").request("get:form", this.getFormId()); if (formModel) { collection = formModel.get("fields"); // fallback for older versions - } else if ( - this.fieldModel.collection.options.formModel.get("fields").models - ) { - collection = - this.fieldModel.collection.options.formModel.get("fields").models; + } else if (this.fieldModel.collection.options.formModel.get("fields").models) { + collection = this.fieldModel.collection.options.formModel.get("fields").models; } return collection.reduce(function (memo, field) {