This commit is contained in:
Kristjan ESPERANTO 2024-12-06 08:46:15 +00:00 committed by GitHub
commit 49d84755f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1636 additions and 33 deletions

View file

@ -1,14 +0,0 @@
{
"extends": "airbnb-base",
"globals": {
"Module": true,
"Log": true,
"MM": true
},
"rules": {
"comma-dangle": "off",
"object-shorthand": "off",
"func-names": "off",
"space-before-function-paren": "off"
}
}

View file

@ -1,8 +1,5 @@
Module.register('MMM-pages', {
// We require the older style of function declaration for compatibility
// reasons.
/**
* By default, we have don't pseudo-paginate any modules. We also exclude
* the page indicator by default, in case people actually want to use the
@ -25,7 +22,7 @@ Module.register('MMM-pages', {
/**
* Apply any styles, if we have any.
*/
getStyles: function () {
getStyles () {
return ['pages.css'];
},
@ -36,15 +33,15 @@ Module.register('MMM-pages', {
* @param {number} x The dividend
* @param {number} n The divisor
*/
mod: function (x, n) {
return ((x % n) + n) % n;
mod (x, n) {
return (x % n + n) % n;
},
/**
* Pseudo-constructor for our module. Makes sure that values aren't negative,
* and sets the default current page to 0.
*/
start: function () {
start () {
// Clamp homePage value to [0, num pages).
if (this.config.homePage >= this.config.modules.length || this.config.homePage < 0) {
this.config.homePage = 0;
@ -91,7 +88,7 @@ Module.register('MMM-pages', {
* @param {string} notification the notification ID
* @param {number|string} payload the page to change to/by
*/
notificationReceived: function (notification, payload) {
notificationReceived (notification, payload) {
switch (notification) {
case 'PAGE_CHANGED':
Log.log(`[MMM-pages] received a notification to change to page ${payload} of type ${typeof payload}.`);
@ -153,7 +150,7 @@ Module.register('MMM-pages', {
* @param {number} fallback the fallback value to use. Accepts negative
* numbers.
*/
changePageBy: function (amt, fallback) {
changePageBy (amt, fallback) {
if (typeof amt !== 'number' && typeof fallback === 'undefined') {
Log.warn(`[MMM-pages] ${amt} is not a number!`);
}
@ -175,7 +172,7 @@ Module.register('MMM-pages', {
* Handles hiding the current page's elements and showing the next page's
* elements.
*/
updatePages: function () {
updatePages () {
// Update if there's at least one page.
if (this.config.modules.length !== 0) {
this.animatePageChange();
@ -194,8 +191,8 @@ Module.register('MMM-pages', {
* @param {string} [targetPageName] the name of the hiddenPage we want to show.
* Optional and only used when we want to switch to a hidden page
*/
animatePageChange: function (targetPageName) {
let lockStringObj = { lockString: this.identifier };
animatePageChange (targetPageName) {
let lockStringObj = {lockString: this.identifier};
if (!this.config.useLockString) {
// Passing in an undefined object is equivalent to not passing it in at
// all, effectively providing only one arg to the hide and show calls
@ -216,13 +213,13 @@ Module.register('MMM-pages', {
MM.getModules()
.exceptWithClass(modulesToShow)
.enumerate(module => module.hide(animationTime, lockStringObj));
.enumerate((module) => module.hide(animationTime, lockStringObj));
// Shows all modules meant to be on the current page, after a small delay.
setTimeout(() => {
MM.getModules()
.withClass(modulesToShow)
.enumerate(module => module.show(animationTime, lockStringObj));
.enumerate((module) => module.show(animationTime, lockStringObj));
}, animationTime);
},
@ -231,7 +228,7 @@ Module.register('MMM-pages', {
*
* @param {number} delay the delay, in milliseconds.
*/
resetTimerWithDelay: function (delay) {
resetTimerWithDelay (delay) {
if (this.config.rotationTime > 0) {
// This timer is the auto rotate function.
clearInterval(this.timer);
@ -275,8 +272,8 @@ Module.register('MMM-pages', {
*
* @param {boolean} isRotating the parameter, if you want to pause or resume.
*/
setRotation: function (isRotating) {
const stateBaseString = (isRotating) ? "resum" : "paus";
setRotation (isRotating) {
const stateBaseString = isRotating ? 'resum' : 'paus';
if (isRotating === this.rotationPaused) {
Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`);
} else {
@ -296,7 +293,7 @@ Module.register('MMM-pages', {
*
* @param {string} name the name of the hiddenPage we want to show
*/
showHiddenPage: function (name) {
showHiddenPage (name) {
// Only proceed if the named hidden page actually exists
if (name in this.config.hiddenPages) {
this.animatePageChange(name);

41
eslint.config.mjs Normal file
View file

@ -0,0 +1,41 @@
import eslintPluginJs from '@eslint/js';
import eslintPluginStylistic from '@stylistic/eslint-plugin';
import globals from 'globals';
const config = [
{
files: ['**/*.js', '**/*.mjs'],
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
Log: 'readonly',
MM: 'readonly',
Module: 'readonly',
},
},
plugins: {
...eslintPluginStylistic.configs['all-flat'].plugins,
},
rules: {
...eslintPluginJs.configs.recommended.rules,
...eslintPluginStylistic.configs['all-flat'].rules,
'@stylistic/array-element-newline': 'off',
'@stylistic/brace-style': ['error', '1tbs', {allowSingleLine: true}],
'@stylistic/comma-dangle': ['error', 'only-multiline'],
'@stylistic/dot-location': ['error', 'property'],
'@stylistic/function-call-argument-newline': 'off',
'@stylistic/indent': ['error', 2],
'@stylistic/padded-blocks': 'off',
'@stylistic/quote-props': ['error', 'consistent-as-needed'],
'@stylistic/quotes': ['error', 'single'],
'@stylistic/multiline-comment-style': 'off',
'@stylistic/multiline-ternary': 'off',
'object-shorthand': ['error', 'always']
},
}
];
export default config;

1560
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -17,5 +17,16 @@
"bugs": {
"url": "https://github.com/edward-shen/MMM-pages/issues"
},
"homepage": "https://github.com/edward-shen/MMM-pages#readme"
"homepage": "https://github.com/edward-shen/MMM-pages#readme",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "npm run lint"
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@stylistic/eslint-plugin": "^2.11.0",
"eslint": "^9.16.0",
"globals": "^15.13.0"
}
}

View file

@ -190,5 +190,13 @@ See also FAQ below.
Please make an issue. Thanks!
## Developer commands
If you want to contribute to this poject, pleases use the following commands to maintain code quality:
- `npm install` - Install development dependencies for linting.
- `npm run lint` - Run linting checks.
- `npm run lint:fix` - Fix linting issues. Please run this before committing.
[mm]: https://github.com/MagicMirrorOrg/MagicMirror
[page indicator]: https://github.com/edward-shen/MMM-page-indicator