Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -15,20 +15,20 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as linkifyjs from 'linkifyjs';
|
||||
import { registerCustomProtocol, registerPlugin } from 'linkifyjs';
|
||||
import linkifyElement from 'linkify-element';
|
||||
import linkifyString from 'linkify-string';
|
||||
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
||||
import * as linkifyjs from "linkifyjs";
|
||||
import { registerCustomProtocol, registerPlugin } from "linkifyjs";
|
||||
import linkifyElement from "linkify-element";
|
||||
import linkifyString from "linkify-string";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
|
||||
import {
|
||||
parsePermalink,
|
||||
tryTransformEntityToPermalink,
|
||||
tryTransformPermalinkToLocalHref,
|
||||
} from "./utils/permalinks/Permalinks";
|
||||
import dis from './dispatcher/dispatcher';
|
||||
import { Action } from './dispatcher/actions';
|
||||
import { ViewUserPayload } from './dispatcher/payloads/ViewUserPayload';
|
||||
import dis from "./dispatcher/dispatcher";
|
||||
import { Action } from "./dispatcher/actions";
|
||||
import { ViewUserPayload } from "./dispatcher/payloads/ViewUserPayload";
|
||||
import { ViewRoomPayload } from "./dispatcher/payloads/ViewRoomPayload";
|
||||
|
||||
export enum Type {
|
||||
|
@ -48,7 +48,7 @@ function matrixOpaqueIdLinkifyParser({
|
|||
scanner: any;
|
||||
parser: any;
|
||||
utils: any;
|
||||
token: '#' | '+' | '@';
|
||||
token: "#" | "+" | "@";
|
||||
name: Type;
|
||||
}) {
|
||||
const {
|
||||
|
@ -106,7 +106,9 @@ function matrixOpaqueIdLinkifyParser({
|
|||
function onUserClick(event: MouseEvent, userId: string) {
|
||||
event.preventDefault();
|
||||
const member = new RoomMember(null, userId);
|
||||
if (!member) { return; }
|
||||
if (!member) {
|
||||
return;
|
||||
}
|
||||
dis.dispatch<ViewUserPayload>({
|
||||
action: Action.ViewUser,
|
||||
member: member,
|
||||
|
@ -123,7 +125,7 @@ function onAliasClick(event: MouseEvent, roomAlias: string) {
|
|||
});
|
||||
}
|
||||
|
||||
const escapeRegExp = function(s: string): string {
|
||||
const escapeRegExp = function (s: string): string {
|
||||
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
};
|
||||
|
||||
|
@ -131,13 +133,14 @@ const escapeRegExp = function(s: string): string {
|
|||
// Anyone else really should be using matrix.to. vector:// allowed to support Element Desktop relative links.
|
||||
export const ELEMENT_URL_PATTERN =
|
||||
"^(?:vector://|https?://)?(?:" +
|
||||
escapeRegExp(window.location.host + window.location.pathname) + "|" +
|
||||
"(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/|" +
|
||||
"(?:app|beta|staging|develop)\\.element\\.io/" +
|
||||
escapeRegExp(window.location.host + window.location.pathname) +
|
||||
"|" +
|
||||
"(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/|" +
|
||||
"(?:app|beta|staging|develop)\\.element\\.io/" +
|
||||
")(#.*)";
|
||||
|
||||
export const options = {
|
||||
events: function(href: string, type: Type | string): Partial<GlobalEventHandlers> {
|
||||
events: function (href: string, type: Type | string): Partial<GlobalEventHandlers> {
|
||||
switch (type) {
|
||||
case Type.URL: {
|
||||
// intercept local permalinks to users and show them like userids (in userinfo of current room)
|
||||
|
@ -146,7 +149,7 @@ export const options = {
|
|||
if (permalink?.userId) {
|
||||
return {
|
||||
// @ts-ignore see https://linkify.js.org/docs/options.html
|
||||
click: function(e: MouseEvent) {
|
||||
click: function (e: MouseEvent) {
|
||||
onUserClick(e, permalink.userId);
|
||||
},
|
||||
};
|
||||
|
@ -156,8 +159,8 @@ export const options = {
|
|||
if (localHref !== href) {
|
||||
// it could be converted to a localHref -> therefore handle locally
|
||||
return {
|
||||
// @ts-ignore see https://linkify.js.org/docs/options.html
|
||||
click: function(e: MouseEvent) {
|
||||
// @ts-ignore see https://linkify.js.org/docs/options.html
|
||||
click: function (e: MouseEvent) {
|
||||
e.preventDefault();
|
||||
window.location.hash = localHref;
|
||||
},
|
||||
|
@ -172,7 +175,7 @@ export const options = {
|
|||
case Type.UserId:
|
||||
return {
|
||||
// @ts-ignore see https://linkify.js.org/docs/options.html
|
||||
click: function(e: MouseEvent) {
|
||||
click: function (e: MouseEvent) {
|
||||
const userId = parsePermalink(href).userId;
|
||||
onUserClick(e, userId);
|
||||
},
|
||||
|
@ -180,7 +183,7 @@ export const options = {
|
|||
case Type.RoomAlias:
|
||||
return {
|
||||
// @ts-ignore see https://linkify.js.org/docs/options.html
|
||||
click: function(e: MouseEvent) {
|
||||
click: function (e: MouseEvent) {
|
||||
const alias = parsePermalink(href).roomIdOrAlias;
|
||||
onAliasClick(e, alias);
|
||||
},
|
||||
|
@ -188,7 +191,7 @@ export const options = {
|
|||
}
|
||||
},
|
||||
|
||||
formatHref: function(href: string, type: Type | string): string {
|
||||
formatHref: function (href: string, type: Type | string): string {
|
||||
switch (type) {
|
||||
case Type.RoomAlias:
|
||||
case Type.UserId:
|
||||
|
@ -199,14 +202,14 @@ export const options = {
|
|||
},
|
||||
|
||||
attributes: {
|
||||
rel: 'noreferrer noopener',
|
||||
rel: "noreferrer noopener",
|
||||
},
|
||||
|
||||
ignoreTags: ['pre', 'code'],
|
||||
ignoreTags: ["pre", "code"],
|
||||
|
||||
className: 'linkified',
|
||||
className: "linkified",
|
||||
|
||||
target: function(href: string, type: Type | string): string {
|
||||
target: function (href: string, type: Type | string): string {
|
||||
if (type === Type.URL) {
|
||||
try {
|
||||
const transformed = tryTransformPermalinkToLocalHref(href);
|
||||
|
@ -216,7 +219,7 @@ export const options = {
|
|||
) {
|
||||
return null;
|
||||
} else {
|
||||
return '_blank';
|
||||
return "_blank";
|
||||
}
|
||||
} catch (e) {
|
||||
// malformed URI
|
||||
|
@ -228,7 +231,7 @@ export const options = {
|
|||
|
||||
// Run the plugins
|
||||
registerPlugin(Type.RoomAlias, ({ scanner, parser, utils }) => {
|
||||
const token = scanner.tokens.POUND as '#';
|
||||
const token = scanner.tokens.POUND as "#";
|
||||
matrixOpaqueIdLinkifyParser({
|
||||
scanner,
|
||||
parser,
|
||||
|
@ -239,7 +242,7 @@ registerPlugin(Type.RoomAlias, ({ scanner, parser, utils }) => {
|
|||
});
|
||||
|
||||
registerPlugin(Type.UserId, ({ scanner, parser, utils }) => {
|
||||
const token = scanner.tokens.AT as '@';
|
||||
const token = scanner.tokens.AT as "@";
|
||||
matrixOpaqueIdLinkifyParser({
|
||||
scanner,
|
||||
parser,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue