Assorted cleanup, minor bug fixes, styling fixes, eslint rules (#5165

* fix: Logic error in toast
fix: Remove useless component

* fix: Logout not clearing all stores

* Add icons to notification settings

* Add eslint rule to enforce spaced comment

* Add eslint rule for arrow-body-style

* Add eslint rule to enforce self-closing components

* Add menu to api key settings
Fix: Deleting webhook subscription does not remove from UI
Split webhook subscriptions into active and inactive
Styling updates
This commit is contained in:
Tom Moor
2023-04-08 08:25:20 -04:00
committed by GitHub
parent 422bdc32d9
commit db73879918
116 changed files with 792 additions and 1088 deletions

View File

@@ -20,16 +20,11 @@ export interface GetScaleToWindow {
(data: { width: number; height: number; offset: number }): number;
}
export const getScaleToWindow: GetScaleToWindow = ({
height,
offset,
width,
}) => {
return Math.min(
export const getScaleToWindow: GetScaleToWindow = ({ height, offset, width }) =>
Math.min(
(window.innerWidth - offset * 2) / width, // scale X-axis
(window.innerHeight - offset * 2) / height // scale Y-axis
);
};
export interface GetScaleToWindowMax {
(data: {
@@ -80,8 +75,8 @@ export const getScale: GetScale = ({
offset,
targetHeight,
targetWidth,
}) => {
return !hasScalableSrc && targetHeight && targetWidth
}) =>
!hasScalableSrc && targetHeight && targetWidth
? getScaleToWindowMax({
containerHeight,
containerWidth,
@@ -94,7 +89,6 @@ export const getScale: GetScale = ({
offset,
width: containerWidth,
});
};
const URL_REGEX = /url(?:\(['"]?)(.*?)(?:['"]?\))/;

View File

@@ -10,9 +10,10 @@ export default function chainTransactions(
dispatch?.(tr);
};
const last = commands.pop();
const reduced = commands.reduce((result, command) => {
return result || command(state, dispatcher);
}, false);
const reduced = commands.reduce(
(result, command) => result || command(state, dispatcher),
false
);
return reduced && last !== undefined && last(state, dispatch);
};
}

View File

@@ -198,12 +198,9 @@ export default class Link extends Mark {
const plugin: Plugin = new Plugin({
state: {
init: (config, state) => {
return getLinkDecorations(state);
},
apply: (tr, decorationSet, _oldState, newState) => {
return tr.docChanged ? getLinkDecorations(newState) : decorationSet;
},
init: (config, state) => getLinkDecorations(state),
apply: (tr, decorationSet, _oldState, newState) =>
tr.docChanged ? getLinkDecorations(newState) : decorationSet,
},
props: {
decorations: (state: EditorState) => plugin.getState(state),

View File

@@ -43,29 +43,25 @@ export default class Attachment extends Node {
{
priority: 100,
tag: "a.attachment",
getAttrs: (dom: HTMLAnchorElement) => {
return {
id: dom.id,
title: dom.innerText,
href: dom.getAttribute("href"),
size: parseInt(dom.dataset.size || "0", 10),
};
},
getAttrs: (dom: HTMLAnchorElement) => ({
id: dom.id,
title: dom.innerText,
href: dom.getAttribute("href"),
size: parseInt(dom.dataset.size || "0", 10),
}),
},
],
toDOM: (node) => {
return [
"a",
{
class: `attachment`,
id: node.attrs.id,
href: sanitizeUrl(node.attrs.href),
download: node.attrs.title,
"data-size": node.attrs.size,
},
node.attrs.title,
];
},
toDOM: (node) => [
"a",
{
class: `attachment`,
id: node.attrs.id,
href: sanitizeUrl(node.attrs.href),
download: node.attrs.title,
"data-size": node.attrs.size,
},
node.attrs.title,
],
toPlainText: (node) => node.attrs.title,
};
}

View File

@@ -148,11 +148,9 @@ export default class CodeFence extends Node {
tag: ".code-block",
preserveWhitespace: "full",
contentElement: "code",
getAttrs: (dom: HTMLDivElement) => {
return {
language: dom.dataset.language,
};
},
getAttrs: (dom: HTMLDivElement) => ({
language: dom.dataset.language,
}),
},
],
toDOM: (node) => {

View File

@@ -101,10 +101,10 @@ export default class Emoji extends Node {
) {
const { pos } = view.state.selection.$from;
return run(view, pos, pos, OPEN_REGEX, (state, match) => {
return run(view, pos, pos, OPEN_REGEX, (state, match) =>
// just tell Prosemirror we handled it and not to do anything
return match ? true : null;
});
match ? true : null
);
}
return false;
@@ -189,9 +189,7 @@ export default class Emoji extends Node {
parseMarkdown() {
return {
node: "emoji",
getAttrs: (tok: Token) => {
return { "data-name": tok.markup.trim() };
},
getAttrs: (tok: Token) => ({ "data-name": tok.markup.trim() }),
};
}
}

View File

@@ -114,9 +114,8 @@ export default class Heading extends Node {
}
commands({ type, schema }: { type: NodeType; schema: Schema }) {
return (attrs: Record<string, any>) => {
return toggleBlockType(type, schema.nodes.paragraph, attrs);
};
return (attrs: Record<string, any>) =>
toggleBlockType(type, schema.nodes.paragraph, attrs);
}
handleFoldContent = (event: MouseEvent) => {
@@ -256,12 +255,9 @@ export default class Heading extends Node {
const plugin: Plugin = new Plugin({
state: {
init: (config, state) => {
return getAnchors(state.doc);
},
apply: (tr, oldState) => {
return tr.docChanged ? getAnchors(tr.doc) : oldState;
},
init: (config, state) => getAnchors(state.doc),
apply: (tr, oldState) =>
tr.docChanged ? getAnchors(tr.doc) : oldState,
},
props: {
decorations: (state) => plugin.getState(state),

View File

@@ -20,12 +20,10 @@ export default class HorizontalRule extends Node {
},
group: "block",
parseDOM: [{ tag: "hr" }],
toDOM: (node) => {
return [
"hr",
{ class: node.attrs.markup === "***" ? "page-break" : "" },
];
},
toDOM: (node) => [
"hr",
{ class: node.attrs.markup === "***" ? "page-break" : "" },
],
};
}

View File

@@ -219,30 +219,28 @@ export default class Image extends SimpleImage {
downloadImageNode(node);
};
component = (props: ComponentProps) => {
return (
<ImageComponent
{...props}
onClick={this.handleSelect(props)}
onDownload={this.handleDownload(props)}
onChangeSize={this.handleChangeSize(props)}
component = (props: ComponentProps) => (
<ImageComponent
{...props}
onClick={this.handleSelect(props)}
onDownload={this.handleDownload(props)}
onChangeSize={this.handleChangeSize(props)}
>
<Caption
onKeyDown={this.handleKeyDown(props)}
onBlur={this.handleBlur(props)}
onMouseDown={this.handleMouseDown}
className="caption"
tabIndex={-1}
role="textbox"
contentEditable
suppressContentEditableWarning
data-caption={this.options.dictionary.imageCaptionPlaceholder}
>
<Caption
onKeyDown={this.handleKeyDown(props)}
onBlur={this.handleBlur(props)}
onMouseDown={this.handleMouseDown}
className="caption"
tabIndex={-1}
role="textbox"
contentEditable
suppressContentEditableWarning
data-caption={this.options.dictionary.imageCaptionPlaceholder}
>
{props.node.attrs.alt}
</Caption>
</ImageComponent>
);
};
{props.node.attrs.alt}
</Caption>
</ImageComponent>
);
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
let markdown =
@@ -275,17 +273,13 @@ export default class Image extends SimpleImage {
parseMarkdown() {
return {
node: "image",
getAttrs: (token: Token) => {
return {
src: token.attrGet("src"),
alt:
(token?.children &&
token.children[0] &&
token.children[0].content) ||
null,
...parseTitleAttribute(token?.attrGet("title") || ""),
};
},
getAttrs: (token: Token) => ({
src: token.attrGet("src"),
alt:
(token?.children && token.children[0] && token.children[0].content) ||
null,
...parseTitleAttribute(token?.attrGet("title") || ""),
}),
};
}

View File

@@ -47,19 +47,17 @@ export default class Mention extends Node {
}),
},
],
toDOM: (node) => {
return [
"span",
{
class: `${node.type.name}`,
id: node.attrs.id,
"data-type": node.attrs.type,
"data-id": node.attrs.modelId,
"data-actorId": node.attrs.actorId,
},
node.attrs.label,
];
},
toDOM: (node) => [
"span",
{
class: `${node.type.name}`,
id: node.attrs.id,
"data-type": node.attrs.type,
"data-id": node.attrs.modelId,
"data-actorId": node.attrs.actorId,
},
node.attrs.label,
],
toPlainText: (node) => `@${node.attrs.label}`,
};
}
@@ -109,10 +107,10 @@ export default class Mention extends Node {
) {
const { pos } = view.state.selection.$from;
return run(view, pos, pos, OPEN_REGEX, (state, match) => {
return run(view, pos, pos, OPEN_REGEX, (state, match) =>
// just tell Prosemirror we handled it and not to do anything
return match ? true : null;
});
match ? true : null
);
}
return false;

View File

@@ -51,31 +51,27 @@ export default class SimpleImage extends Node {
},
{
tag: "img",
getAttrs: (dom: HTMLImageElement) => {
return {
src: dom.getAttribute("src"),
alt: dom.getAttribute("alt"),
title: dom.getAttribute("title"),
};
},
getAttrs: (dom: HTMLImageElement) => ({
src: dom.getAttribute("src"),
alt: dom.getAttribute("alt"),
title: dom.getAttribute("title"),
}),
},
],
toDOM: (node) => {
return [
"div",
toDOM: (node) => [
"div",
{
class: "image",
},
[
"img",
{
class: "image",
...node.attrs,
src: sanitizeUrl(node.attrs.src),
contentEditable: "false",
},
[
"img",
{
...node.attrs,
src: sanitizeUrl(node.attrs.src),
contentEditable: "false",
},
],
];
},
],
],
};
}
@@ -155,9 +151,9 @@ export default class SimpleImage extends Node {
}
};
component = (props: ComponentProps) => {
return <ImageComponent {...props} onClick={this.handleSelect(props)} />;
};
component = (props: ComponentProps) => (
<ImageComponent {...props} onClick={this.handleSelect(props)} />
);
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
state.write(
@@ -172,16 +168,12 @@ export default class SimpleImage extends Node {
parseMarkdown() {
return {
node: "image",
getAttrs: (token: Token) => {
return {
src: token.attrGet("src"),
alt:
(token?.children &&
token.children[0] &&
token.children[0].content) ||
null,
};
},
getAttrs: (token: Token) => ({
src: token.attrGet("src"),
alt:
(token?.children && token.children[0] && token.children[0].content) ||
null,
}),
};
}

View File

@@ -99,10 +99,10 @@ export default class BlockMenuTrigger extends Extension {
) {
const { pos } = view.state.selection.$from;
return run(view, pos, pos, OPEN_REGEX, (state, match) => {
return run(view, pos, pos, OPEN_REGEX, (state, match) =>
// just tell Prosemirror we handled it and not to do anything
return match ? true : null;
});
match ? true : null
);
}
return false;

View File

@@ -178,9 +178,7 @@ export default function Prism({
return new Plugin({
key: new PluginKey("prism"),
state: {
init: (_: Plugin, { doc }) => {
return DecorationSet.create(doc, []);
},
init: (_: Plugin, { doc }) => DecorationSet.create(doc, []),
apply: (transaction: Transaction, decorationSet, oldState, state) => {
const nodeName = state.selection.$head.parent.type.name;
const previousNodeName = oldState.selection.$head.parent.type.name;