Merge branch 'main' into block

This commit is contained in:
Daniel Waxweiler 2022-06-03 23:32:23 +02:00
commit c042851184
20 changed files with 4894 additions and 8730 deletions

View File

@ -22,6 +22,9 @@
"jsx" "jsx"
], ],
"rules": { "rules": {
"import/no-unresolved": [
"off"
],
"indent": [ "indent": [
"error", "error",
2 2

5
.gulp.json Normal file
View File

@ -0,0 +1,5 @@
{
"flags": {
"gulpfile": "gulpfile.cjs"
}
}

View File

@ -4,6 +4,8 @@ Connector for Mobilizon allows you to display the upcoming events of [Mobilizon]
More details can be found in the [WordPress Plugin Directory](https://wordpress.org/plugins/connector-mobilizon/). More details can be found in the [WordPress Plugin Directory](https://wordpress.org/plugins/connector-mobilizon/).
The current changelog can be under [source/changelog.txt](source/changelog.txt).
## Development ## Development
### Setup ### Setup

13372
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,9 @@
{ {
"name": "connector-mobilizon", "name": "connector-mobilizon",
"version": "0.6.2", "version": "0.9.1",
"description": "Display Mobilizon events in WordPress.", "description": "Display Mobilizon events in WordPress.",
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"build-dev": "webpack --mode=development && gulp inject", "build-dev": "webpack --mode=development && gulp inject",
"build-prod": "ava && webpack --mode=production && gulp inject", "build-prod": "ava && webpack --mode=production && gulp inject",
@ -23,49 +24,46 @@
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"graphql": "^16.1.0", "graphql": "16.5.0",
"graphql-request": "^3.7.0", "graphql-request": "4.2.0",
"luxon": "^2.1.1", "luxon": "2.4.0",
"object-hash": "^2.2.0" "object-hash": "3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.16.5", "@babel/core": "7.17.12",
"@babel/eslint-parser": "^7.16.5", "@babel/eslint-parser": "^7.16.5",
"@babel/preset-env": "^7.15.8", "@babel/preset-env": "7.17.12",
"@babel/preset-react": "^7.16.5", "@babel/preset-react": "^7.16.5",
"@wordpress/eslint-plugin": "^9.2.0", "@wordpress/eslint-plugin": "12.4.0",
"ava": "^3.15.0", "ava": "4.2.0",
"babel-loader": "^8.2.3", "babel-loader": "8.2.5",
"c8": "^7.10.0", "c8": "7.11.3",
"copy-webpack-plugin": "^10.0.0", "copy-webpack-plugin": "11.0.0",
"eslint": "^7.32.0", "eslint": "8.15.0",
"eslint-plugin-ava": "^13.1.0", "eslint-plugin-ava": "13.2.0",
"eslint-plugin-jsx": "^0.1.0", "eslint-plugin-jsx": "^0.1.0",
"eslint-plugin-react": "^7.27.1", "eslint-plugin-react": "^7.27.1",
"esm": "^3.2.25", "esm": "3.2.25",
"gulp": "^4.0.2", "gulp": "4.0.2",
"gulp-replace": "^1.1.3", "gulp-replace": "1.1.3",
"husky": "^7.0.4", "husky": "8.0.1",
"jsdom": "^19.0.0", "jsdom": "19.0.0",
"lint-staged": "^12.1.2", "lint-staged": "12.4.1",
"prettier": "2.5.1", "prettier": "2.6.2",
"rimraf": "^3.0.2", "rimraf": "3.0.2",
"webpack": "^5.65.0", "webpack": "5.72.1",
"webpack-cli": "^4.9.1" "webpack-cli": "4.9.2"
}, },
"ava": { "ava": {
"files": [ "files": [
"./source/**/*test.js" "./source/**/*test.js"
],
"require": [
"esm"
] ]
}, },
"additionalDetails": { "additionalDetails": {
"niceName": "Connector for Mobilizon", "niceName": "Connector for Mobilizon",
"phpMinimumVersion": 7.4, "phpMinimumVersion": 7.4,
"wordpressMinimumVersion": 5.6, "wordpressMinimumVersion": 5.6,
"wordpressTestedUpToVersion": 5.8 "wordpressTestedUpToVersion": "6.0"
}, },
"lint-staged": { "lint-staged": {
"source/**/*.js": "eslint", "source/**/*.js": "eslint",

View File

@ -1,16 +1,46 @@
### [Unreleased] ### [Unreleased]
#### Added #### Added
- Add specific error message for the case the group is not found
- Add code formatter prettier
#### Changed #### Changed
- Set minimum PHP version to oldest officially supported 7.4
- Update dependencies
- Simplify build process
#### Deprecated #### Deprecated
#### Removed #### Removed
#### Fixed #### Fixed
#### Security #### Security
### [0.9.1] - 2020-05-19
#### Fixed
- Fix WordPress compatibility version number
### [0.9.0] - 2020-05-19
#### Added
- Improve explanation of group name filter
#### Changed
- Update dependencies
- Confirm compatibility with WordPress 6.0
#### Fixed
- Fix displaying error message for the case the group is not found
### [0.8.0] - 2022-01-09
#### Added
- Add support for older browsers using babel
#### Changed
- Confirm compatibility with WordPress 5.9
- Update dependencies
#### Fixed
- Use ES modules correctly
- Trim events' location
### [0.7.0] - 2021-12-23
#### Added
- Add specific error message for the case the group is not found
- Add code formatter prettier
#### Changed
- Update dependencies
- Simplify build process
#### Fixed
- Fix Invalid DateTime on event end time being null
#### Security
- Set minimum PHP version to oldest stable 7.4
### [0.6.2] - 2021-08-24 ### [0.6.2] - 2021-08-24
#### Changed #### Changed
- Update dependencies - Update dependencies

View File

@ -1,5 +1,5 @@
import test from 'ava' import test from 'ava'
import DateTimeWrapper from './date-time-wrapper' import DateTimeWrapper from './date-time-wrapper.js'
test('#getShortDate usual date', (t) => { test('#getShortDate usual date', (t) => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })

View File

@ -1,7 +1,7 @@
import test from 'ava' import test from 'ava'
import { JSDOM } from 'jsdom' import { JSDOM } from 'jsdom'
import { displayEvents, displayErrorMessage } from './events-displayer' import { displayEvents, displayErrorMessage } from './events-displayer.js'
let document let document

View File

@ -1,5 +1,5 @@
import Formatter from './formatter' import Formatter from './formatter.js'
import { createAnchorElement } from './html-creator' import { createAnchorElement } from './html-creator.js'
export function displayEvents({ data, document, list }) { export function displayEvents({ data, document, list }) {
const locale = list.getAttribute('data-locale') const locale = list.getAttribute('data-locale')

View File

@ -1,5 +1,5 @@
import { displayEvents, displayErrorMessage } from './events-displayer' import { displayEvents, displayErrorMessage } from './events-displayer.js'
import * as GraphqlWrapper from './graphql-wrapper' import * as GraphqlWrapper from './graphql-wrapper.js'
const NAME = '<wordpress-name>' const NAME = '<wordpress-name>'

View File

@ -1,5 +1,5 @@
import test from 'ava' import test from 'ava'
import Formatter from './formatter' import Formatter from './formatter.js'
test('#formatDate one date', (t) => { test('#formatDate one date', (t) => {
const date = Formatter.formatDate({ const date = Formatter.formatDate({
@ -32,20 +32,42 @@ test('#formatDate two dates with short offset name', (t) => {
end: '2021-04-16T15:30:00Z', end: '2021-04-16T15:30:00Z',
isShortOffsetNameShown: true, isShortOffsetNameShown: true,
}) })
t.is(date, '15/04/2021 10:30 (UTC) - 16/04/2021 15:30 (UTC)') t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30 (UTC)')
})
test('#formatDate second date is null', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: null,
})
t.is(date, '15/04/2021 10:30')
})
test('#formatDate second date is null with short offset name', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: null,
isShortOffsetNameShown: true,
})
t.is(date, '15/04/2021 10:30 (UTC)')
}) })
test('#formatLocation both parameters', (t) => { test('#formatLocation both parameters', (t) => {
const date = Formatter.formatLocation({ description: 'a', locality: 'b' }) const location = Formatter.formatLocation({ description: 'a', locality: 'b' })
t.is(date, 'a, b') t.is(location, 'a, b')
}) })
test('#formatLocation description only', (t) => { test('#formatLocation description only', (t) => {
const date = Formatter.formatLocation({ description: 'a' }) const location = Formatter.formatLocation({ description: 'a' })
t.is(date, 'a') t.is(location, 'a')
})
test('#formatLocation description with space only', (t) => {
const location = Formatter.formatLocation({ description: ' ' })
t.is(location, '')
}) })
test('#formatLocation locality only', (t) => { test('#formatLocation locality only', (t) => {
const date = Formatter.formatLocation({ locality: 'a' }) const location = Formatter.formatLocation({ locality: 'a' })
t.is(date, 'a') t.is(location, 'a')
}) })

View File

@ -1,4 +1,4 @@
import DateTimeWrapper from './date-time-wrapper' import DateTimeWrapper from './date-time-wrapper.js'
export default class Formatter { export default class Formatter {
static formatDate({ locale, timeZone, start, end, isShortOffsetNameShown }) { static formatDate({ locale, timeZone, start, end, isShortOffsetNameShown }) {
@ -7,29 +7,32 @@ export default class Formatter {
text: start, text: start,
timeZone, timeZone,
}) })
const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone })
let dateText = startDateTime.getShortDate() let dateText = startDateTime.getShortDate()
dateText += ' ' + startDateTime.get24Time() dateText += ' ' + startDateTime.get24Time()
if (!startDateTime.equalsDate(endDateTime)) { if (!end && isShortOffsetNameShown) {
if (isShortOffsetNameShown) { dateText += ' (' + startDateTime.getShortOffsetName() + ')'
dateText += ' (' + startDateTime.getShortOffsetName() + ')'
}
dateText += ' - '
dateText += endDateTime.getShortDate() + ' '
} else {
dateText += ' - '
} }
dateText += endDateTime.get24Time()
if (isShortOffsetNameShown) { if (end) {
dateText += ' (' + endDateTime.getShortOffsetName() + ')' const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone })
if (!startDateTime.equalsDate(endDateTime)) {
dateText += ' - '
dateText += endDateTime.getShortDate() + ' '
} else {
dateText += ' - '
}
dateText += endDateTime.get24Time()
if (isShortOffsetNameShown) {
dateText += ' (' + endDateTime.getShortOffsetName() + ')'
}
} }
return dateText return dateText
} }
static formatLocation({ description, locality }) { static formatLocation({ description, locality }) {
let location = '' let location = ''
if (description) { if (description && description.trim()) {
location += description location += description.trim()
} }
if (location && locality) { if (location && locality) {
location += ', ' location += ', '

View File

@ -1,6 +1,6 @@
import SessionCache from './session-cache' import SessionCache from './session-cache.js'
import { request } from 'graphql-request' import { request } from 'graphql-request'
import DateTimeWrapper from './date-time-wrapper' import DateTimeWrapper from './date-time-wrapper.js'
export function getUpcomingEvents({ url, limit }) { export function getUpcomingEvents({ url, limit }) {
const query = ` const query = `
@ -37,7 +37,7 @@ export function getUpcomingEvents({ url, limit }) {
export function getUpcomingEventsByGroupName({ url, limit, groupName }) { export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
const query = ` const query = `
query ($afterDatetime: DateTime, $groupName: String, $limit: Int) { query ($afterDatetime: DateTime, $groupName: String!, $limit: Int) {
group(preferredUsername: $groupName) { group(preferredUsername: $groupName) {
organizedEvents(afterDatetime: $afterDatetime, limit: $limit) { organizedEvents(afterDatetime: $afterDatetime, limit: $limit) {
elements { elements {

View File

@ -1,7 +1,7 @@
import test from 'ava' import test from 'ava'
import { JSDOM } from 'jsdom' import { JSDOM } from 'jsdom'
import { createAnchorElement } from './html-creator' import { createAnchorElement } from './html-creator.js'
let document let document

View File

@ -1,5 +1,5 @@
import test from 'ava' import test from 'ava'
import hash from './object-hash-wrapper' import hash from './object-hash-wrapper.js'
test('#hash object', (t) => { test('#hash object', (t) => {
t.is(hash({ foo: 'bar' }), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b') t.is(hash({ foo: 'bar' }), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b')

View File

@ -1,5 +1,5 @@
import test from 'ava' import test from 'ava'
import SessionCache from './session-cache' import SessionCache from './session-cache.js'
const fakeStorage = { const fakeStorage = {
elements: {}, elements: {},

View File

@ -1,4 +1,4 @@
import hash from './object-hash-wrapper' import hash from './object-hash-wrapper.js'
const MAX_AGE_IN_MS = 120000 const MAX_AGE_IN_MS = 120000

View File

@ -24,7 +24,9 @@ Features
- Toggle adding named offset in brackets after the time in the settings - Toggle adding named offset in brackets after the time in the settings
Shortcut format with limiting the number of events to show to 3 for example: `[<wordpress-name>-events-list events-count=3]` Shortcut format with limiting the number of events to show to 3 for example: `[<wordpress-name>-events-list events-count=3]`
Optionally, you can only show the events of a specific group by indicatings its name: `[<wordpress-name>-events-list events-count=3 group-name="mygroup"]` Optionally, you can only show the events of a specific group by indicatings its name: `[<wordpress-name>-events-list events-count=3 group-name="mygroup"]`
You have to use their username, e.g. `@nosliensvivants`, and append the name of their instance if they use a different one, e.g. `@yaam_berlin@mobilize.berlin`.
The source code is available on [Github](https://github.com/dwaxweiler/connector-mobilizon). The source code is available on [Github](https://github.com/dwaxweiler/connector-mobilizon).
@ -36,6 +38,41 @@ The source code is available on [Github](https://github.com/dwaxweiler/connector
## Changelog ## Changelog
### [0.9.1] - 2020-05-19
#### Fixed
- Fix WordPress compatibility version number
### [0.9.0] - 2020-05-19
#### Added
- Improve explanation of group name filter
#### Changed
- Update dependencies
- Confirm compatibility with WordPress 6.0
#### Fixed
- Fix displaying error message for the case the group is not found
### [0.8.0] - 2022-01-09
#### Added
- Add support for older browsers using babel
#### Changed
- Confirm compatibility with WordPress 5.9
- Update dependencies
#### Fixed
- Use ES modules correctly
- Trim events' location
### [0.7.0] - 2021-12-23
#### Added
- Add specific error message for the case the group is not found
- Add code formatter prettier
#### Changed
- Update dependencies
- Simplify build process
#### Fixed
- Fix Invalid DateTime on event end time being null
#### Security
- Set minimum PHP version to oldest stable 7.4
### [0.6.2] - 2021-08-24 ### [0.6.2] - 2021-08-24
#### Changed #### Changed
- Update dependencies - Update dependencies

View File

@ -25,6 +25,20 @@ module.exports = {
}, },
], ],
}, },
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { targets: 'defaults' }]],
},
},
},
],
},
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
patterns: [ patterns: [