[build] upgrade eslint to 9.37.0 (#88)
Co-authored-by: tobi <tobi.smethurst@protonmail.com> Reviewed-on: https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/88 Co-authored-by: Zoë Bijl <moiety@noreply.codeberg.org> Co-committed-by: Zoë Bijl <moiety@noreply.codeberg.org>
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { PureComponent } from 'react';
|
||||
import PropTypes from "prop-types";
|
||||
import { PureComponent } from "react";
|
||||
|
||||
import { FormattedMessage, injectIntl } from 'react-intl';
|
||||
import { FormattedMessage, injectIntl } from "react-intl";
|
||||
|
||||
import classnames from 'classnames';
|
||||
import classnames from "classnames";
|
||||
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { connect } from 'react-redux';
|
||||
import ImmutablePropTypes from "react-immutable-proptypes";
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import { Icon } from 'flavours/glitch/components/icon';
|
||||
import { autoPlayGif } from 'flavours/glitch/initial_state';
|
||||
import { decode as decodeIDNA } from 'flavours/glitch/utils/idna';
|
||||
import { Icon } from "flavours/glitch/components/icon";
|
||||
import { autoPlayGif } from "flavours/glitch/initial_state";
|
||||
import { decode as decodeIDNA } from "flavours/glitch/utils/idna";
|
||||
|
||||
import Permalink from './permalink';
|
||||
import Permalink from "./permalink";
|
||||
|
||||
const textMatchesTarget = (text, origin, host) => {
|
||||
return (text === origin || text === host
|
||||
|| text.startsWith(origin + '/') || text.startsWith(host + '/')
|
||||
|| 'www.' + text === host || ('www.' + text).startsWith(host + '/'));
|
||||
|| text.startsWith(origin + "/") || text.startsWith(host + "/")
|
||||
|| "www." + text === host || ("www." + text).startsWith(host + "/"));
|
||||
};
|
||||
|
||||
const isLinkMisleading = (link) => {
|
||||
@@ -29,30 +29,32 @@ const isLinkMisleading = (link) => {
|
||||
|
||||
const walk = (node) => {
|
||||
switch (node.nodeType) {
|
||||
case Node.TEXT_NODE:
|
||||
linkTextParts.push(node.textContent);
|
||||
break;
|
||||
case Node.ELEMENT_NODE:
|
||||
if (node.classList.contains('invisible')) return;
|
||||
const children = node.childNodes;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
walk(children[i]);
|
||||
}
|
||||
break;
|
||||
case Node.TEXT_NODE:
|
||||
linkTextParts.push(node.textContent);
|
||||
break;
|
||||
case Node.ELEMENT_NODE:
|
||||
if (node.classList.contains("invisible")) {
|
||||
return;
|
||||
}
|
||||
const children = node.childNodes;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
walk(children[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
walk(link);
|
||||
|
||||
const linkText = linkTextParts.join('');
|
||||
const linkText = linkTextParts.join("");
|
||||
const targetURL = new URL(link.href);
|
||||
|
||||
if (targetURL.protocol === 'magnet:') {
|
||||
return !linkText.startsWith('magnet:');
|
||||
if (targetURL.protocol === "magnet:") {
|
||||
return !linkText.startsWith("magnet:");
|
||||
}
|
||||
|
||||
if (targetURL.protocol === 'xmpp:') {
|
||||
return !(linkText === targetURL.href || 'xmpp:' + linkText === targetURL.href);
|
||||
if (targetURL.protocol === "xmpp:") {
|
||||
return !(linkText === targetURL.href || "xmpp:" + linkText === targetURL.href);
|
||||
}
|
||||
|
||||
// The following may not work with international domain names
|
||||
@@ -61,10 +63,10 @@ const isLinkMisleading = (link) => {
|
||||
}
|
||||
|
||||
// The link hasn't been recognized, maybe it features an international domain name
|
||||
const hostname = decodeIDNA(targetURL.hostname).normalize('NFKC');
|
||||
const hostname = decodeIDNA(targetURL.hostname).normalize("NFKC");
|
||||
const host = targetURL.host.replace(targetURL.hostname, hostname);
|
||||
const origin = targetURL.origin.replace(targetURL.host, host);
|
||||
const text = linkText.normalize('NFKC');
|
||||
const text = linkText.normalize("NFKC");
|
||||
return !(textMatchesTarget(text, origin, host) || textMatchesTarget(text.toLowerCase(), origin, host));
|
||||
};
|
||||
|
||||
@@ -93,7 +95,7 @@ class StatusContent extends PureComponent {
|
||||
|
||||
static defaultProps = {
|
||||
tagLinks: true,
|
||||
rewriteMentions: 'no',
|
||||
rewriteMentions: "no",
|
||||
};
|
||||
|
||||
state = {
|
||||
@@ -108,60 +110,64 @@ class StatusContent extends PureComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
const links = node.querySelectorAll('a');
|
||||
const links = node.querySelectorAll("a");
|
||||
|
||||
for (var i = 0; i < links.length; ++i) {
|
||||
let link = links[i];
|
||||
if (link.classList.contains('status-link')) {
|
||||
if (link.classList.contains("status-link")) {
|
||||
continue;
|
||||
}
|
||||
link.classList.add('status-link');
|
||||
link.classList.add("status-link");
|
||||
|
||||
let mention = this.props.status.get('mentions').find(item => link.href === item.get('url'));
|
||||
let mention = this.props.status.get("mentions").find(item => link.href === item.get("url"));
|
||||
|
||||
if (mention) {
|
||||
link.addEventListener('click', this.onMentionClick.bind(this, mention), false);
|
||||
link.setAttribute('title', `@${mention.get('acct')}`);
|
||||
if (rewriteMentions !== 'no') {
|
||||
while (link.firstChild) link.removeChild(link.firstChild);
|
||||
link.appendChild(document.createTextNode('@'));
|
||||
const acctSpan = document.createElement('span');
|
||||
acctSpan.textContent = rewriteMentions === 'acct' ? mention.get('acct') : mention.get('username');
|
||||
link.addEventListener("click", this.onMentionClick.bind(this, mention), false);
|
||||
link.setAttribute("title", `@${mention.get("acct")}`);
|
||||
if (rewriteMentions !== "no") {
|
||||
while (link.firstChild) {
|
||||
link.removeChild(link.firstChild);
|
||||
}
|
||||
link.appendChild(document.createTextNode("@"));
|
||||
const acctSpan = document.createElement("span");
|
||||
acctSpan.textContent = rewriteMentions === "acct" ? mention.get("acct") : mention.get("username");
|
||||
link.appendChild(acctSpan);
|
||||
}
|
||||
} else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
|
||||
link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
|
||||
} else if (link.textContent[0] === "#" || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === "#")) {
|
||||
link.addEventListener("click", this.onHashtagClick.bind(this, link.text), false);
|
||||
} else {
|
||||
link.addEventListener('click', this.onLinkClick.bind(this), false);
|
||||
link.setAttribute('title', link.href);
|
||||
link.classList.add('unhandled-link');
|
||||
link.addEventListener("click", this.onLinkClick.bind(this), false);
|
||||
link.setAttribute("title", link.href);
|
||||
link.classList.add("unhandled-link");
|
||||
|
||||
link.setAttribute('target', '_blank');
|
||||
link.setAttribute('rel', 'noopener nofollow noreferrer');
|
||||
link.setAttribute("target", "_blank");
|
||||
link.setAttribute("rel", "noopener nofollow noreferrer");
|
||||
|
||||
try {
|
||||
if (tagLinks && isLinkMisleading(link)) {
|
||||
// Add a tag besides the link to display its origin
|
||||
|
||||
const url = new URL(link.href);
|
||||
const tag = document.createElement('span');
|
||||
tag.classList.add('link-origin-tag');
|
||||
const tag = document.createElement("span");
|
||||
tag.classList.add("link-origin-tag");
|
||||
switch (url.protocol) {
|
||||
case 'xmpp:':
|
||||
tag.textContent = `[${url.href}]`;
|
||||
break;
|
||||
case 'magnet:':
|
||||
tag.textContent = '(magnet)';
|
||||
break;
|
||||
default:
|
||||
tag.textContent = `[${url.host}]`;
|
||||
case "xmpp:":
|
||||
tag.textContent = `[${url.href}]`;
|
||||
break;
|
||||
case "magnet:":
|
||||
tag.textContent = "(magnet)";
|
||||
break;
|
||||
default:
|
||||
tag.textContent = `[${url.host}]`;
|
||||
}
|
||||
link.insertAdjacentText('beforeend', ' ');
|
||||
link.insertAdjacentElement('beforeend', tag);
|
||||
link.insertAdjacentText("beforeend", " ");
|
||||
link.insertAdjacentElement("beforeend", tag);
|
||||
}
|
||||
} catch (e) {
|
||||
// The URL is invalid, remove the href just to be safe
|
||||
if (tagLinks && e instanceof TypeError) link.removeAttribute('href');
|
||||
if (tagLinks && e instanceof TypeError) {
|
||||
link.removeAttribute("href");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,11 +178,11 @@ class StatusContent extends PureComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
||||
const emojis = currentTarget.querySelectorAll(".custom-emoji");
|
||||
|
||||
for (var i = 0; i < emojis.length; i++) {
|
||||
let emoji = emojis[i];
|
||||
emoji.src = emoji.getAttribute('data-original');
|
||||
emoji.src = emoji.getAttribute("data-original");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -185,11 +191,11 @@ class StatusContent extends PureComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
||||
const emojis = currentTarget.querySelectorAll(".custom-emoji");
|
||||
|
||||
for (var i = 0; i < emojis.length; i++) {
|
||||
let emoji = emojis[i];
|
||||
emoji.src = emoji.getAttribute('data-static');
|
||||
emoji.src = emoji.getAttribute("data-static");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -199,23 +205,27 @@ class StatusContent extends PureComponent {
|
||||
|
||||
componentDidUpdate () {
|
||||
this._updateStatusLinks();
|
||||
if (this.props.onUpdate) this.props.onUpdate();
|
||||
if (this.props.onUpdate) {
|
||||
this.props.onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
onLinkClick = (e) => {
|
||||
if (this.props.collapsed) {
|
||||
if (this.props.parseClick) this.props.parseClick(e);
|
||||
if (this.props.parseClick) {
|
||||
this.props.parseClick(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onMentionClick = (mention, e) => {
|
||||
if (this.props.parseClick) {
|
||||
this.props.parseClick(e, `/@${mention.get('acct')}`);
|
||||
this.props.parseClick(e, `/@${mention.get("acct")}`);
|
||||
}
|
||||
};
|
||||
|
||||
onHashtagClick = (hashtag, e) => {
|
||||
hashtag = hashtag.replace(/^#/, '');
|
||||
hashtag = hashtag.replace(/^#/, "");
|
||||
|
||||
if (this.props.parseClick) {
|
||||
this.props.parseClick(e, `/tags/${hashtag}`);
|
||||
@@ -238,7 +248,7 @@ class StatusContent extends PureComponent {
|
||||
|
||||
let element = e.target;
|
||||
while (element !== e.currentTarget) {
|
||||
if (['button', 'video', 'a', 'label', 'canvas'].includes(element.localName) || element.getAttribute('role') === 'button') {
|
||||
if (["button", "video", "a", "label", "canvas"].includes(element.localName) || element.getAttribute("role") === "button") {
|
||||
return;
|
||||
}
|
||||
element = element.parentNode;
|
||||
@@ -283,28 +293,28 @@ class StatusContent extends PureComponent {
|
||||
|
||||
const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
|
||||
|
||||
const content = { __html: status.getIn(['translation', 'contentHtml']) || status.get('contentHtml') };
|
||||
const spoilerContent = { __html: status.getIn(['translation', 'spoilerHtml']) || status.get('spoilerHtml') };
|
||||
const language = status.getIn(['translation', 'language']) || status.get('language');
|
||||
const classNames = classnames('status__content', {
|
||||
'status__content--with-action': parseClick && !disabled,
|
||||
'status__content--with-spoiler': status.get('spoiler_text').length > 0,
|
||||
const content = { __html: status.getIn(["translation", "contentHtml"]) || status.get("contentHtml") };
|
||||
const spoilerContent = { __html: status.getIn(["translation", "spoilerHtml"]) || status.get("spoilerHtml") };
|
||||
const language = status.getIn(["translation", "language"]) || status.get("language");
|
||||
const classNames = classnames("status__content", {
|
||||
"status__content--with-action": parseClick && !disabled,
|
||||
"status__content--with-spoiler": status.get("spoiler_text").length > 0,
|
||||
});
|
||||
|
||||
|
||||
if (status.get('spoiler_text').length > 0) {
|
||||
let mentionsPlaceholder = '';
|
||||
if (status.get("spoiler_text").length > 0) {
|
||||
let mentionsPlaceholder = "";
|
||||
|
||||
const mentionLinks = status.get('mentions').map(item => (
|
||||
const mentionLinks = status.get("mentions").map(item => (
|
||||
<Permalink
|
||||
to={`/@${item.get('acct')}`}
|
||||
href={item.get('url')}
|
||||
key={item.get('id')}
|
||||
to={`/@${item.get("acct")}`}
|
||||
href={item.get("url")}
|
||||
key={item.get("id")}
|
||||
className='mention'
|
||||
>
|
||||
@<span>{item.get('username')}</span>
|
||||
@<span>{item.get("username")}</span>
|
||||
</Permalink>
|
||||
)).reduce((aggregate, item) => [...aggregate, item, ' '], []);
|
||||
)).reduce((aggregate, item) => [...aggregate, item, " "], []);
|
||||
|
||||
let toggleText = null;
|
||||
if (hidden) {
|
||||
@@ -345,10 +355,10 @@ class StatusContent extends PureComponent {
|
||||
return (
|
||||
<div className={classNames} tabIndex={0} onMouseDown={this.handleMouseDown} onMouseUp={this.handleMouseUp}>
|
||||
<p
|
||||
style={{ marginBottom: hidden && status.get('mentions').isEmpty() ? '0px' : null }}
|
||||
style={{ marginBottom: hidden && status.get("mentions").isEmpty() ? "0px" : null }}
|
||||
>
|
||||
<span dangerouslySetInnerHTML={spoilerContent} className='translate' lang={language} />
|
||||
{' '}
|
||||
{" "}
|
||||
<button type='button' className='status__content__spoiler-link' onClick={this.handleSpoilerClick} aria-expanded={!hidden}>
|
||||
{toggleText}
|
||||
</button>
|
||||
@@ -356,7 +366,7 @@ class StatusContent extends PureComponent {
|
||||
|
||||
{mentionsPlaceholder}
|
||||
|
||||
<div className={`status__content__spoiler ${!hidden ? 'status__content__spoiler--visible' : ''}`}>
|
||||
<div className={`status__content__spoiler ${!hidden ? "status__content__spoiler--visible" : ""}`}>
|
||||
<div
|
||||
ref={this.setContentsRef}
|
||||
key={`contents-${tagLinks}`}
|
||||
|
||||
Reference in New Issue
Block a user