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;

View File

@@ -212,7 +212,6 @@
"Empty": "Empty",
"Go back": "Go back",
"Go forward": "Go forward",
"Starred documents could not be loaded": "Starred documents could not be loaded",
"Starred": "Starred",
"Show more": "Show more",
"Toggle sidebar": "Toggle sidebar",
@@ -314,6 +313,8 @@
"Integrations": "Integrations",
"Self Hosted": "Self Hosted",
"Google Analytics": "Google Analytics",
"Revoke token": "Revoke token",
"Revoke": "Revoke",
"Show path to document": "Show path to document",
"Path to document": "Path to document",
"Group member options": "Group member options",
@@ -688,9 +689,7 @@
"Date shared": "Date shared",
"Shared nested": "Shared nested",
"API token copied to clipboard": "API token copied to clipboard",
"Revoke token": "Revoke token",
"Copied": "Copied",
"Revoke": "Revoke",
"Revoking": "Revoking",
"Are you sure you want to revoke the {{ tokenName }} token?": "Are you sure you want to revoke the {{ tokenName }} token?",
"Active": "Active",
@@ -729,8 +728,8 @@
"Create a \"Web\" stream in your Google Analytics admin dashboard and copy the measurement ID from the generated code snippet to install.": "Create a \"Web\" stream in your Google Analytics admin dashboard and copy the measurement ID from the generated code snippet to install.",
"New group": "New group",
"Groups can be used to organize and manage the people on your team.": "Groups can be used to organize and manage the people on your team.",
"All groups": "All groups",
"No groups have been created yet": "No groups have been created yet",
"All": "All",
"Quickly transfer your existing documents, pages, and files from other tools and services into {{appName}}. You can also drag and drop any HTML, Markdown, and text documents directly into Collections in the app.": "Quickly transfer your existing documents, pages, and files from other tools and services into {{appName}}. You can also drag and drop any HTML, Markdown, and text documents directly into Collections in the app.",
"Import a zip file of Markdown documents (exported from version 0.67.0 or earlier)": "Import a zip file of Markdown documents (exported from version 0.67.0 or earlier)",
"Import data": "Import data",
@@ -811,7 +810,6 @@
"Documents that have been shared are listed below. Anyone that has the public link can access a read-only version of the document until the link has been revoked.": "Documents that have been shared are listed below. Anyone that has the public link can access a read-only version of the document until the link has been revoked.",
"New token": "New token",
"You can create an unlimited amount of personal tokens to authenticate\n with the API. Tokens have the same permissions as your user account.\n For more details see the <em>developer documentation</em>.": "You can create an unlimited amount of personal tokens to authenticate\n with the API. Tokens have the same permissions as your user account.\n For more details see the <em>developer documentation</em>.",
"Tokens": "Tokens",
"Create a token": "Create a token",
"Zapier is a platform that allows {{appName}} to easily integrate with thousands of other business tools. Automate your workflows, sync data, and more.": "Zapier is a platform that allows {{appName}} to easily integrate with thousands of other business tools. Automate your workflows, sync data, and more.",
"Your are creating a new workspace using your current account — <em>{{email}}</em>": "Your are creating a new workspace using your current account — <em>{{email}}</em>",
@@ -825,11 +823,6 @@
"<em>Note:</em> Signing back in will cause a new account to be automatically reprovisioned.": "<em>Note:</em> Signing back in will cause a new account to be automatically reprovisioned.",
"Are you sure? Deleting your account will destroy identifying data associated with your user and cannot be undone. You will be immediately logged out of {{appName}} and all your API tokens will be revoked.": "Are you sure? Deleting your account will destroy identifying data associated with your user and cannot be undone. You will be immediately logged out of {{appName}} and all your API tokens will be revoked.",
"Delete My Account": "Delete My Account",
"You joined": "You joined",
"Joined": "Joined",
"{{ time }} ago.": "{{ time }} ago.",
"Edit Profile": "Edit Profile",
"{{ userName }} hasnt updated any documents yet.": "{{ userName }} hasnt updated any documents yet.",
"Today": "Today",
"Yesterday": "Yesterday",
"Last week": "Last week",
@@ -872,6 +865,7 @@
"Webhooks": "Webhooks",
"New webhook": "New webhook",
"Webhooks can be used to notify your application when events happen in {{appName}}. Events are sent as a https request with a JSON payload in near real-time.": "Webhooks can be used to notify your application when events happen in {{appName}}. Events are sent as a https request with a JSON payload in near real-time.",
"Inactive": "Inactive",
"Create a webhook": "Create a webhook",
"Uploading": "Uploading"
}

View File

@@ -1,9 +1,6 @@
const randomInteger = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1) + min);
};
const randomInteger = (min: number, max: number) =>
Math.floor(Math.random() * (max - min + 1) + min);
const randomElement = <T>(arr: T[]): T => {
return arr[randomInteger(0, arr.length - 1)];
};
const randomElement = <T>(arr: T[]): T => arr[randomInteger(0, arr.length - 1)];
export { randomInteger, randomElement };

View File

@@ -22,9 +22,7 @@ export const ellipsis = () => `
*/
export const s = (key: keyof DefaultTheme) => (props: {
theme: DefaultTheme;
}) => {
return String(props.theme[key]);
};
}) => String(props.theme[key]);
/**
* Mixin to hide scrollbars.

View File

@@ -19,9 +19,8 @@ export const palette = [
darken(0.2, theme.brand.yellow),
];
export const validateColorHex = (color: string) => {
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
};
export const validateColorHex = (color: string) =>
/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
export const stringToColor = (input: string) => {
const inputAsNumber = parseInt(md5(input).toString(), 16);

View File

@@ -1,7 +1,4 @@
const unescape = (text: string) => {
return text
.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, "$1")
.replace(/\n\\\n/g, "\n\n");
};
const unescape = (text: string) =>
text.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, "$1").replace(/\n\\\n/g, "\n\n");
export default unescape;