From 5047be9898d4c1579ccdbdec3535e0c54b24b5d5 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 22 Mar 2022 22:58:29 -0700 Subject: [PATCH 01/12] fix: Attachments on public share links broken when using AWS Accelerate fix: Attachments broken when using non-collab and AWS bucket on the same host (https://github.com/outline/outline/discussions/3274\) --- server/presenters/env.ts | 1 + shared/editor/rules/attachments.ts | 8 ++++++-- shared/types.ts | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/presenters/env.ts b/server/presenters/env.ts index 98e6aa9ea1..270683fd30 100644 --- a/server/presenters/env.ts +++ b/server/presenters/env.ts @@ -6,6 +6,7 @@ export default function present(env: Record): PublicEnv { return { URL: env.URL.replace(/\/$/, ""), AWS_S3_UPLOAD_BUCKET_URL: env.AWS_S3_UPLOAD_BUCKET_URL, + AWS_S3_ACCELERATE_URL: env.AWS_S3_ACCELERATE_URL, CDN_URL: (env.CDN_URL || "").replace(/\/$/, ""), COLLABORATION_URL: (env.COLLABORATION_URL || env.URL) .replace(/\/$/, "") diff --git a/shared/editor/rules/attachments.ts b/shared/editor/rules/attachments.ts index 328c96d01a..5ea0385dde 100644 --- a/shared/editor/rules/attachments.ts +++ b/shared/editor/rules/attachments.ts @@ -21,8 +21,12 @@ function isLinkClose(token: Token) { function isAttachment(token: Token) { const href = token.attrGet("href"); return ( - href?.includes("attachments.redirect") || - href?.startsWith(env.AWS_S3_UPLOAD_BUCKET_URL) + // internal + href?.startsWith("/api/attachments.redirect") || + // external (public share are pre-signed and this is a reasonable way of detecting them) + ((href?.startsWith(env.AWS_S3_UPLOAD_BUCKET_URL) || + href?.startsWith(env.AWS_S3_ACCELERATE_URL)) && + href?.includes("X-Amz-Signature")) ); } diff --git a/shared/types.ts b/shared/types.ts index 76d45f8a90..8587840c32 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -7,6 +7,7 @@ export type PublicEnv = { CDN_URL: string; COLLABORATION_URL: string; AWS_S3_UPLOAD_BUCKET_URL: string; + AWS_S3_ACCELERATE_URL: string; DEPLOYMENT: "hosted" | ""; ENVIRONMENT: "production" | "development"; SENTRY_DSN: string | undefined; From 7f15eb287debce76529a50625901ee1933498968 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 22 Mar 2022 23:20:53 -0700 Subject: [PATCH 02/12] fix: Redundant quotes closes #3272 --- .env.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 154f991bf5..439c66d9f9 100644 --- a/.env.sample +++ b/.env.sample @@ -92,7 +92,7 @@ OIDC_USERNAME_CLAIM=preferred_username OIDC_DISPLAY_NAME=OpenID # Space separated auth scopes. -OIDC_SCOPES="openid profile email" +OIDC_SCOPES=openid profile email # –––––––––––––––– OPTIONAL –––––––––––––––– From 8aa25fd7d6c8f830ef2fdb8bec3399735db21441 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 23 Mar 2022 00:27:22 -0700 Subject: [PATCH 03/12] fix: Add ability to convert between checklist and other types of list --- .../editor/commands/backspaceToParagraph.ts | 5 +- shared/editor/commands/clearNodes.ts | 49 +++++++++++++++++++ shared/editor/commands/moveLeft.ts | 10 ++-- shared/editor/commands/moveRight.ts | 5 +- shared/editor/commands/splitHeading.ts | 5 +- shared/editor/commands/toggleBlockType.ts | 5 +- shared/editor/commands/toggleList.ts | 20 ++++++-- shared/editor/commands/toggleWrap.ts | 5 +- shared/editor/lib/Extension.ts | 14 ++---- shared/editor/lib/chainTransactions.ts | 18 +++++++ shared/editor/marks/Link.tsx | 5 +- shared/editor/nodes/Blockquote.ts | 8 ++- shared/editor/nodes/CodeFence.ts | 9 ++-- shared/editor/nodes/Embed.tsx | 6 +-- shared/editor/nodes/Emoji.tsx | 5 +- shared/editor/nodes/HardBreak.ts | 10 ++-- shared/editor/nodes/HorizontalRule.ts | 7 +-- shared/editor/nodes/Image.tsx | 25 +++------- shared/editor/nodes/ListItem.ts | 16 ++---- shared/editor/nodes/Table.ts | 16 +++--- shared/editor/types/index.ts | 4 +- 21 files changed, 147 insertions(+), 100 deletions(-) create mode 100644 shared/editor/commands/clearNodes.ts create mode 100644 shared/editor/lib/chainTransactions.ts diff --git a/shared/editor/commands/backspaceToParagraph.ts b/shared/editor/commands/backspaceToParagraph.ts index b6c35fe28e..be9bf9e416 100644 --- a/shared/editor/commands/backspaceToParagraph.ts +++ b/shared/editor/commands/backspaceToParagraph.ts @@ -1,8 +1,9 @@ import { NodeType } from "prosemirror-model"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; +import { Dispatch } from "../types"; export default function backspaceToParagraph(type: NodeType) { - return (state: EditorState, dispatch: (tr: Transaction) => void) => { + return (state: EditorState, dispatch: Dispatch) => { const { $from, from, to, empty } = state.selection; // if the selection has anything in it then use standard delete behavior diff --git a/shared/editor/commands/clearNodes.ts b/shared/editor/commands/clearNodes.ts new file mode 100644 index 0000000000..55a30b92c9 --- /dev/null +++ b/shared/editor/commands/clearNodes.ts @@ -0,0 +1,49 @@ +import { EditorState } from "prosemirror-state"; +import { liftTarget } from "prosemirror-transform"; +import { Dispatch } from "../types"; + +const clearNodes = () => (state: EditorState, dispatch?: Dispatch) => { + const { tr } = state; + const { selection } = tr; + const { ranges } = selection; + + if (!dispatch) { + return true; + } + + ranges.forEach(({ $from, $to }) => { + state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => { + if (node.type.isText) { + return; + } + + const { doc, mapping } = tr; + const $mappedFrom = doc.resolve(mapping.map(pos)); + const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize)); + const nodeRange = $mappedFrom.blockRange($mappedTo); + + if (!nodeRange) { + return; + } + + const targetLiftDepth = liftTarget(nodeRange); + + if (node.type.isTextblock) { + const { defaultType } = $mappedFrom.parent.contentMatchAt( + $mappedFrom.index() + ); + + tr.setNodeMarkup(nodeRange.start, defaultType); + } + + if (targetLiftDepth || targetLiftDepth === 0) { + tr.lift(nodeRange, targetLiftDepth); + } + }); + }); + + dispatch(tr); + return true; +}; + +export default clearNodes; diff --git a/shared/editor/commands/moveLeft.ts b/shared/editor/commands/moveLeft.ts index b9c2440c61..82c3c4b65f 100644 --- a/shared/editor/commands/moveLeft.ts +++ b/shared/editor/commands/moveLeft.ts @@ -17,13 +17,9 @@ limitations under the License. // This file is based on the implementation found here: // https://bitbucket.org/atlassian/design-system-mirror/src/master/editor/editor-core/src/plugins/text-formatting/commands/text-formatting.ts -import { - Selection, - EditorState, - Transaction, - TextSelection, -} from "prosemirror-state"; +import { Selection, EditorState, TextSelection } from "prosemirror-state"; import isMarkActive from "../queries/isMarkActive"; +import { Dispatch } from "../types"; function hasCode(state: EditorState, pos: number) { const { code_inline } = state.schema.marks; @@ -35,7 +31,7 @@ function hasCode(state: EditorState, pos: number) { } export default function moveLeft() { - return (state: EditorState, dispatch: (tr: Transaction) => void): boolean => { + return (state: EditorState, dispatch: Dispatch): boolean => { const { code_inline } = state.schema.marks; const { empty, $cursor } = state.selection as TextSelection; if (!empty || !$cursor) { diff --git a/shared/editor/commands/moveRight.ts b/shared/editor/commands/moveRight.ts index 519f955275..5c2c0ccd91 100644 --- a/shared/editor/commands/moveRight.ts +++ b/shared/editor/commands/moveRight.ts @@ -17,11 +17,12 @@ limitations under the License. // This file is based on the implementation found here: // https://bitbucket.org/atlassian/design-system-mirror/src/master/editor/editor-core/src/plugins/text-formatting/commands/text-formatting.ts -import { EditorState, Transaction, TextSelection } from "prosemirror-state"; +import { EditorState, TextSelection } from "prosemirror-state"; import isMarkActive from "../queries/isMarkActive"; +import { Dispatch } from "../types"; export default function moveRight() { - return (state: EditorState, dispatch: (tr: Transaction) => void): boolean => { + return (state: EditorState, dispatch: Dispatch): boolean => { const { code_inline } = state.schema.marks; const { empty, $cursor } = state.selection as TextSelection; if (!empty || !$cursor) { diff --git a/shared/editor/commands/splitHeading.ts b/shared/editor/commands/splitHeading.ts index 59f52bff64..0a156a59d5 100644 --- a/shared/editor/commands/splitHeading.ts +++ b/shared/editor/commands/splitHeading.ts @@ -1,10 +1,11 @@ import { NodeType } from "prosemirror-model"; -import { EditorState, TextSelection, Transaction } from "prosemirror-state"; +import { EditorState, TextSelection } from "prosemirror-state"; import { findBlockNodes } from "prosemirror-utils"; import findCollapsedNodes from "../queries/findCollapsedNodes"; +import { Dispatch } from "../types"; export default function splitHeading(type: NodeType) { - return (state: EditorState, dispatch: (tr: Transaction) => void): boolean => { + return (state: EditorState, dispatch: Dispatch): boolean => { const { $from, from, $to, to } = state.selection; // check we're in a matching heading node diff --git a/shared/editor/commands/toggleBlockType.ts b/shared/editor/commands/toggleBlockType.ts index 162ef1562a..e7ed7c32ae 100644 --- a/shared/editor/commands/toggleBlockType.ts +++ b/shared/editor/commands/toggleBlockType.ts @@ -1,14 +1,15 @@ import { setBlockType } from "prosemirror-commands"; import { NodeType } from "prosemirror-model"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; import isNodeActive from "../queries/isNodeActive"; +import { Dispatch } from "../types"; export default function toggleBlockType( type: NodeType, toggleType: NodeType, attrs = {} ) { - return (state: EditorState, dispatch: (tr: Transaction) => void) => { + return (state: EditorState, dispatch?: Dispatch) => { const isActive = isNodeActive(type, attrs)(state); if (isActive) { diff --git a/shared/editor/commands/toggleList.ts b/shared/editor/commands/toggleList.ts index d7e3d35023..f0019a4080 100644 --- a/shared/editor/commands/toggleList.ts +++ b/shared/editor/commands/toggleList.ts @@ -1,14 +1,18 @@ import { NodeType } from "prosemirror-model"; import { wrapInList, liftListItem } from "prosemirror-schema-list"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; import { findParentNode } from "prosemirror-utils"; +import chainTransactions from "../lib/chainTransactions"; import isList from "../queries/isList"; +import { Dispatch } from "../types"; +import clearNodes from "./clearNodes"; export default function toggleList(listType: NodeType, itemType: NodeType) { - return (state: EditorState, dispatch: (tr: Transaction) => void) => { + return (state: EditorState, dispatch?: Dispatch) => { const { schema, selection } = state; const { $from, $to } = selection; const range = $from.blockRange($to); + const { tr } = state; if (!range) { return false; @@ -27,7 +31,6 @@ export default function toggleList(listType: NodeType, itemType: NodeType) { isList(parentList.node, schema) && listType.validContent(parentList.node.content) ) { - const { tr } = state; tr.setNodeMarkup(parentList.pos, listType); if (dispatch) { @@ -38,6 +41,15 @@ export default function toggleList(listType: NodeType, itemType: NodeType) { } } - return wrapInList(listType)(state, dispatch); + const canWrapInList = wrapInList(listType)(state); + + if (canWrapInList) { + return wrapInList(listType)(state, dispatch); + } + + return chainTransactions(clearNodes(), wrapInList(listType))( + state, + dispatch + ); }; } diff --git a/shared/editor/commands/toggleWrap.ts b/shared/editor/commands/toggleWrap.ts index bfd6b51680..ede336adc4 100644 --- a/shared/editor/commands/toggleWrap.ts +++ b/shared/editor/commands/toggleWrap.ts @@ -1,13 +1,14 @@ import { wrapIn, lift } from "prosemirror-commands"; import { NodeType } from "prosemirror-model"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; import isNodeActive from "../queries/isNodeActive"; +import { Dispatch } from "../types"; export default function toggleWrap( type: NodeType, attrs?: Record ) { - return (state: EditorState, dispatch: (tr: Transaction) => void) => { + return (state: EditorState, dispatch?: Dispatch) => { const isActive = isNodeActive(type)(state); if (isActive) { diff --git a/shared/editor/lib/Extension.ts b/shared/editor/lib/Extension.ts index 34f92985a7..ade3fb44fb 100644 --- a/shared/editor/lib/Extension.ts +++ b/shared/editor/lib/Extension.ts @@ -1,22 +1,16 @@ import { PluginSimple } from "markdown-it"; import { InputRule } from "prosemirror-inputrules"; import { NodeType, MarkType, Schema } from "prosemirror-model"; -import { EditorState, Plugin, Transaction } from "prosemirror-state"; +import { EditorState, Plugin } from "prosemirror-state"; import { EditorView } from "prosemirror-view"; import { Editor } from "../../../app/editor"; +import { Dispatch } from "../types"; -export type Command = ( - state: EditorState, - dispatch: (tr: Transaction) => void -) => boolean; +export type Command = (state: EditorState, dispatch: Dispatch) => boolean; export type CommandFactory = ( attrs?: Record -) => ( - state: EditorState, - dispatch: (tr: Transaction) => void, - view: EditorView -) => boolean; +) => (state: EditorState, dispatch: Dispatch, view: EditorView) => boolean; export default class Extension { options: any; diff --git a/shared/editor/lib/chainTransactions.ts b/shared/editor/lib/chainTransactions.ts new file mode 100644 index 0000000000..c328174ade --- /dev/null +++ b/shared/editor/lib/chainTransactions.ts @@ -0,0 +1,18 @@ +import { EditorState, Transaction } from "prosemirror-state"; +import { Dispatch } from "../types"; + +export default function chainTransactions( + ...commands: ((state: EditorState, dispatch?: Dispatch) => boolean)[] +) { + return (state: EditorState, dispatch?: Dispatch): boolean => { + const dispatcher = (tr: Transaction): void => { + state = state.apply(tr); + dispatch?.(tr); + }; + const last = commands.pop(); + const reduced = commands.reduce((result, command) => { + return result || command(state, dispatcher); + }, false); + return reduced && last !== undefined && last(state, dispatch); + }; +} diff --git a/shared/editor/marks/Link.tsx b/shared/editor/marks/Link.tsx index efea8bcdbc..f08cc0cc3d 100644 --- a/shared/editor/marks/Link.tsx +++ b/shared/editor/marks/Link.tsx @@ -9,12 +9,13 @@ import { Node, Mark as ProsemirrorMark, } from "prosemirror-model"; -import { Transaction, EditorState, Plugin } from "prosemirror-state"; +import { EditorState, Plugin } from "prosemirror-state"; import { Decoration, DecorationSet } from "prosemirror-view"; import * as React from "react"; import ReactDOM from "react-dom"; import { isInternalUrl } from "../../utils/urls"; import findLinkNodes from "../queries/findLinkNodes"; +import { Dispatch } from "../types"; import Mark from "./Mark"; const LINK_INPUT_REGEX = /\[([^[]+)]\((\S+)\)$/; @@ -103,7 +104,7 @@ export default class Link extends Mark { keys({ type }: { type: MarkType }) { return { - "Mod-k": (state: EditorState, dispatch: (tr: Transaction) => void) => { + "Mod-k": (state: EditorState, dispatch: Dispatch) => { if (state.selection.empty) { this.options.onKeyboardShortcut(); return true; diff --git a/shared/editor/nodes/Blockquote.ts b/shared/editor/nodes/Blockquote.ts index 3787ee6566..0dde3cedda 100644 --- a/shared/editor/nodes/Blockquote.ts +++ b/shared/editor/nodes/Blockquote.ts @@ -1,9 +1,10 @@ import { wrappingInputRule } from "prosemirror-inputrules"; import { NodeSpec, Node as ProsemirrorNode, NodeType } from "prosemirror-model"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; import toggleWrap from "../commands/toggleWrap"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; import isNodeActive from "../queries/isNodeActive"; +import { Dispatch } from "../types"; import Node from "./Node"; export default class Blockquote extends Node { @@ -37,10 +38,7 @@ export default class Blockquote extends Node { return { "Ctrl->": toggleWrap(type), "Mod-]": toggleWrap(type), - "Shift-Enter": ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + "Shift-Enter": (state: EditorState, dispatch: Dispatch) => { if (!isNodeActive(type)(state)) { return false; } diff --git a/shared/editor/nodes/CodeFence.ts b/shared/editor/nodes/CodeFence.ts index 392e4103fe..bc89cc287b 100644 --- a/shared/editor/nodes/CodeFence.ts +++ b/shared/editor/nodes/CodeFence.ts @@ -38,7 +38,7 @@ import toggleBlockType from "../commands/toggleBlockType"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; import Prism, { LANGUAGES } from "../plugins/Prism"; import isInCode from "../queries/isInCode"; -import { ToastType } from "../types"; +import { Dispatch, ToastType } from "../types"; import Node from "./Node"; const PERSISTENCE_KEY = "rme-code-language"; @@ -146,10 +146,7 @@ export default class CodeFence extends Node { keys({ type, schema }: { type: NodeType; schema: Schema }) { return { "Shift-Ctrl-\\": toggleBlockType(type, schema.nodes.paragraph), - "Shift-Enter": ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + "Shift-Enter": (state: EditorState, dispatch: Dispatch) => { if (!isInCode(state)) { return false; } @@ -172,7 +169,7 @@ export default class CodeFence extends Node { dispatch(tr.insertText(newText, selection.from, selection.to)); return true; }, - Tab: (state: EditorState, dispatch: (tr: Transaction) => void) => { + Tab: (state: EditorState, dispatch: Dispatch) => { if (!isInCode(state)) { return false; } diff --git a/shared/editor/nodes/Embed.tsx b/shared/editor/nodes/Embed.tsx index bdda25f138..8109786f60 100644 --- a/shared/editor/nodes/Embed.tsx +++ b/shared/editor/nodes/Embed.tsx @@ -1,11 +1,11 @@ import Token from "markdown-it/lib/token"; import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; import * as React from "react"; import DisabledEmbed from "../components/DisabledEmbed"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; import embedsRule from "../rules/embeds"; -import { ComponentProps } from "../types"; +import { ComponentProps, Dispatch } from "../types"; import Node from "./Node"; const cache = {}; @@ -117,7 +117,7 @@ export default class Embed extends Node { commands({ type }: { type: NodeType }) { return (attrs: Record) => ( state: EditorState, - dispatch: (tr: Transaction) => void + dispatch: Dispatch ) => { dispatch( state.tr.replaceSelectionWith(type.create(attrs)).scrollIntoView() diff --git a/shared/editor/nodes/Emoji.tsx b/shared/editor/nodes/Emoji.tsx index cce3bca07a..5c13da6db6 100644 --- a/shared/editor/nodes/Emoji.tsx +++ b/shared/editor/nodes/Emoji.tsx @@ -2,9 +2,10 @@ import nameToEmoji from "gemoji/name-to-emoji.json"; import Token from "markdown-it/lib/token"; import { InputRule } from "prosemirror-inputrules"; import { NodeSpec, Node as ProsemirrorNode, NodeType } from "prosemirror-model"; -import { EditorState, TextSelection, Transaction } from "prosemirror-state"; +import { EditorState, TextSelection } from "prosemirror-state"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; import emojiRule from "../rules/emoji"; +import { Dispatch } from "../types"; import Node from "./Node"; export default class Emoji extends Node { @@ -63,7 +64,7 @@ export default class Emoji extends Node { commands({ type }: { type: NodeType }) { return (attrs: Record) => ( state: EditorState, - dispatch: (tr: Transaction) => void + dispatch: Dispatch ) => { const { selection } = state; const position = diff --git a/shared/editor/nodes/HardBreak.ts b/shared/editor/nodes/HardBreak.ts index 4a25f3b76e..3ad7297e0b 100644 --- a/shared/editor/nodes/HardBreak.ts +++ b/shared/editor/nodes/HardBreak.ts @@ -1,8 +1,9 @@ import { NodeSpec, NodeType } from "prosemirror-model"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; import { isInTable } from "prosemirror-tables"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; import breakRule from "../rules/breaks"; +import { Dispatch } from "../types"; import Node from "./Node"; export default class HardBreak extends Node { @@ -27,7 +28,7 @@ export default class HardBreak extends Node { } commands({ type }: { type: NodeType }) { - return () => (state: EditorState, dispatch: (tr: Transaction) => void) => { + return () => (state: EditorState, dispatch: Dispatch) => { dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView()); return true; }; @@ -35,10 +36,7 @@ export default class HardBreak extends Node { keys({ type }: { type: NodeType }) { return { - "Shift-Enter": ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + "Shift-Enter": (state: EditorState, dispatch: Dispatch) => { if (!isInTable(state)) { return false; } diff --git a/shared/editor/nodes/HorizontalRule.ts b/shared/editor/nodes/HorizontalRule.ts index 02abcb2335..9bcba3dcd9 100644 --- a/shared/editor/nodes/HorizontalRule.ts +++ b/shared/editor/nodes/HorizontalRule.ts @@ -1,8 +1,9 @@ import Token from "markdown-it/lib/token"; import { InputRule } from "prosemirror-inputrules"; import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model"; -import { EditorState, Transaction } from "prosemirror-state"; +import { EditorState } from "prosemirror-state"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; +import { Dispatch } from "../types"; import Node from "./Node"; export default class HorizontalRule extends Node { @@ -31,7 +32,7 @@ export default class HorizontalRule extends Node { commands({ type }: { type: NodeType }) { return (attrs: Record) => ( state: EditorState, - dispatch: (tr: Transaction) => void + dispatch: Dispatch ) => { dispatch( state.tr.replaceSelectionWith(type.create(attrs)).scrollIntoView() @@ -42,7 +43,7 @@ export default class HorizontalRule extends Node { keys({ type }: { type: NodeType }) { return { - "Mod-_": (state: EditorState, dispatch: (tr: Transaction) => void) => { + "Mod-_": (state: EditorState, dispatch: Dispatch) => { dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView()); return true; }, diff --git a/shared/editor/nodes/Image.tsx b/shared/editor/nodes/Image.tsx index 17c1ec9ae1..5102cde12a 100644 --- a/shared/editor/nodes/Image.tsx +++ b/shared/editor/nodes/Image.tsx @@ -7,7 +7,6 @@ import { TextSelection, NodeSelection, EditorState, - Transaction, } from "prosemirror-state"; import * as React from "react"; import ImageZoom from "react-medium-image-zoom"; @@ -16,7 +15,7 @@ import getDataTransferFiles from "../../utils/getDataTransferFiles"; import insertFiles, { Options } from "../commands/insertFiles"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; import uploadPlaceholderPlugin from "../lib/uploadPlaceholder"; -import { ComponentProps } from "../types"; +import { ComponentProps, Dispatch } from "../types"; import Node from "./Node"; /** @@ -366,17 +365,11 @@ export default class Image extends Node { return true; }, - deleteImage: () => ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + deleteImage: () => (state: EditorState, dispatch: Dispatch) => { dispatch(state.tr.deleteSelection()); return true; }, - alignRight: () => ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + alignRight: () => (state: EditorState, dispatch: Dispatch) => { if (!(state.selection instanceof NodeSelection)) { return false; } @@ -389,10 +382,7 @@ export default class Image extends Node { dispatch(state.tr.setNodeMarkup(selection.from, undefined, attrs)); return true; }, - alignLeft: () => ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + alignLeft: () => (state: EditorState, dispatch: Dispatch) => { if (!(state.selection instanceof NodeSelection)) { return false; } @@ -436,10 +426,7 @@ export default class Image extends Node { inputElement.click(); return true; }, - alignCenter: () => ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + alignCenter: () => (state: EditorState, dispatch: Dispatch) => { if (!(state.selection instanceof NodeSelection)) { return false; } @@ -450,7 +437,7 @@ export default class Image extends Node { }, createImage: (attrs: Record) => ( state: EditorState, - dispatch: (tr: Transaction) => void + dispatch: Dispatch ) => { const { selection } = state; const position = diff --git a/shared/editor/nodes/ListItem.ts b/shared/editor/nodes/ListItem.ts index 9070657a9b..02aece86c8 100644 --- a/shared/editor/nodes/ListItem.ts +++ b/shared/editor/nodes/ListItem.ts @@ -16,6 +16,7 @@ import { MarkdownSerializerState } from "../lib/markdown/serializer"; import getParentListItem from "../queries/getParentListItem"; import isInList from "../queries/isInList"; import isList from "../queries/isList"; +import { Dispatch } from "../types"; import Node from "./Node"; export default class ListItem extends Node { @@ -199,10 +200,7 @@ export default class ListItem extends Node { "Shift-Tab": liftListItem(type), "Mod-]": sinkListItem(type), "Mod-[": liftListItem(type), - "Shift-Enter": ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + "Shift-Enter": (state: EditorState, dispatch: Dispatch) => { if (!isInList(state)) { return false; } @@ -214,10 +212,7 @@ export default class ListItem extends Node { dispatch(tr.split(selection.to)); return true; }, - "Alt-ArrowUp": ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + "Alt-ArrowUp": (state: EditorState, dispatch: Dispatch) => { if (!state.selection.empty) { return false; } @@ -248,10 +243,7 @@ export default class ListItem extends Node { ); return true; }, - "Alt-ArrowDown": ( - state: EditorState, - dispatch: (tr: Transaction) => void - ) => { + "Alt-ArrowDown": (state: EditorState, dispatch: Dispatch) => { if (!state.selection.empty) { return false; } diff --git a/shared/editor/nodes/Table.ts b/shared/editor/nodes/Table.ts index d2be72656c..973f818162 100644 --- a/shared/editor/nodes/Table.ts +++ b/shared/editor/nodes/Table.ts @@ -1,10 +1,5 @@ import { NodeSpec, Node as ProsemirrorNode, Schema } from "prosemirror-model"; -import { - EditorState, - Plugin, - TextSelection, - Transaction, -} from "prosemirror-state"; +import { EditorState, Plugin, TextSelection } from "prosemirror-state"; import { addColumnAfter, addColumnBefore, @@ -27,6 +22,7 @@ import { import { Decoration, DecorationSet } from "prosemirror-view"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; import tablesRule from "../rules/tables"; +import { Dispatch } from "../types"; import Node from "./Node"; export default class Table extends Node { @@ -67,7 +63,7 @@ export default class Table extends Node { }: { rowsCount: number; colsCount: number; - }) => (state: EditorState, dispatch: (tr: Transaction) => void) => { + }) => (state: EditorState, dispatch: Dispatch) => { const offset = state.tr.selection.anchor + 1; const nodes = createTable(schema, rowsCount, colsCount); const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView(); @@ -83,7 +79,7 @@ export default class Table extends Node { }: { index: number; alignment: string; - }) => (state: EditorState, dispatch: (tr: Transaction) => void) => { + }) => (state: EditorState, dispatch: Dispatch) => { const cells = getCellsInColumn(index)(state.selection) || []; let transaction = state.tr; cells.forEach(({ pos }) => { @@ -99,7 +95,7 @@ export default class Table extends Node { deleteColumn: () => deleteColumn, addRowAfter: ({ index }: { index: number }) => ( state: EditorState, - dispatch: (tr: Transaction) => void + dispatch: Dispatch ) => { if (index === 0) { // A little hack to avoid cloning the heading row by cloning the row @@ -123,7 +119,7 @@ export default class Table extends Node { return { Tab: goToNextCell(1), "Shift-Tab": goToNextCell(-1), - Enter: (state: EditorState, dispatch: (tr: Transaction) => void) => { + Enter: (state: EditorState, dispatch: Dispatch) => { if (!isInTable(state)) { return false; } diff --git a/shared/editor/types/index.ts b/shared/editor/types/index.ts index 62867698ed..9a1ff1427e 100644 --- a/shared/editor/types/index.ts +++ b/shared/editor/types/index.ts @@ -1,5 +1,5 @@ import { Node as ProsemirrorNode } from "prosemirror-model"; -import { EditorState } from "prosemirror-state"; +import { EditorState, Transaction } from "prosemirror-state"; import * as React from "react"; import { DefaultTheme } from "styled-components"; @@ -34,3 +34,5 @@ export type ComponentProps = { isEditable: boolean; getPos: () => number; }; + +export type Dispatch = (tr: Transaction) => void; From 53d96d2cb33aa3f5aa488efba3d79cb7504cabf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=BD=E5=A6=82=E5=AF=84?= <594613537@qq.com> Date: Fri, 25 Mar 2022 06:57:11 +0800 Subject: [PATCH 04/12] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Flex=20t?= =?UTF-8?q?ype=20(#3282)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: ♻️ Flex type Change-Id: I9043fa71a94c6d691e075b983c263be39b5a4b9b * fix: 💄 eslint Change-Id: I2c41ea588b8152a354998ec69ae85798cd6f3ff4 * fix: 💄 lint Change-Id: I9467ca89b3a3c83dbfa0422869528e86db8d4fab --- app/components/Flex.tsx | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/app/components/Flex.tsx b/app/components/Flex.tsx index f61e01b52d..ba3afef955 100644 --- a/app/components/Flex.tsx +++ b/app/components/Flex.tsx @@ -1,18 +1,9 @@ +import { CSSProperties } from "react"; import styled from "styled-components"; -type JustifyValues = - | "center" - | "space-around" - | "space-between" - | "flex-start" - | "flex-end"; +type JustifyValues = CSSProperties["justifyContent"]; -type AlignValues = - | "stretch" - | "center" - | "baseline" - | "flex-start" - | "flex-end"; +type AlignValues = CSSProperties["alignItems"]; const Flex = styled.div<{ auto?: boolean; From 6af9246f26c128ca551897b9b80a6a647442765f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 24 Mar 2022 16:02:50 -0700 Subject: [PATCH 05/12] feat: Allow disabling collection creation for members (#3270) --- .../Sidebar/components/SidebarAction.tsx | 4 ++++ app/models/Team.ts | 4 ++++ app/scenes/Settings/Security.tsx | 14 ++++++++++++++ server/commands/teamUpdater.ts | 4 ++++ ...20220319060408-collection-create-permission.js | 15 +++++++++++++++ server/models/Team.ts | 4 ++++ server/policies/collection.ts | 5 ++++- server/presenters/team.ts | 1 + server/routes/api/team.ts | 2 ++ shared/i18n/locales/en_US/translation.json | 2 ++ 10 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 server/migrations/20220319060408-collection-create-permission.js diff --git a/app/components/Sidebar/components/SidebarAction.tsx b/app/components/Sidebar/components/SidebarAction.tsx index 82ecd7c56c..334d42e445 100644 --- a/app/components/Sidebar/components/SidebarAction.tsx +++ b/app/components/Sidebar/components/SidebarAction.tsx @@ -21,6 +21,10 @@ function SidebarAction({ action, ...rest }: Props) { const menuItem = actionToMenuItem(action, context); invariant(menuItem.type === "button", "passed action must be a button"); + if (!menuItem.visible) { + return null; + } + return ( + + + { sharing, guestSignin, documentEmbeds, + memberCollectionCreate, collaborativeEditing, defaultCollectionId, defaultUserRole, @@ -41,6 +42,9 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => { if (avatarUrl !== undefined) { team.avatarUrl = avatarUrl; } + if (memberCollectionCreate !== undefined) { + team.memberCollectionCreate = memberCollectionCreate; + } if (defaultCollectionId !== undefined) { team.defaultCollectionId = defaultCollectionId; } diff --git a/server/migrations/20220319060408-collection-create-permission.js b/server/migrations/20220319060408-collection-create-permission.js new file mode 100644 index 0000000000..797e477c11 --- /dev/null +++ b/server/migrations/20220319060408-collection-create-permission.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.addColumn("teams", "memberCollectionCreate", { + type: Sequelize.BOOLEAN, + defaultValue: true, + allowNull: false, + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.removeColumn("teams", "memberCollectionCreate"); + } +}; diff --git a/server/models/Team.ts b/server/models/Team.ts index 8ffead4e68..962e682b60 100644 --- a/server/models/Team.ts +++ b/server/models/Team.ts @@ -89,6 +89,10 @@ class Team extends ParanoidModel { @Column documentEmbeds: boolean; + @Default(true) + @Column + memberCollectionCreate: boolean; + @Default(false) @Column collaborativeEditing: boolean; diff --git a/server/policies/collection.ts b/server/policies/collection.ts index fe3695ffd0..7d96c56e6b 100644 --- a/server/policies/collection.ts +++ b/server/policies/collection.ts @@ -8,7 +8,10 @@ allow(User, "createCollection", Team, (user, team) => { if (!team || user.isViewer || user.teamId !== team.id) { return false; } - return true; + if (user.isAdmin || team.memberCollectionCreate) { + return true; + } + return false; }); allow(User, "importCollection", Team, (actor, team) => { diff --git a/server/presenters/team.ts b/server/presenters/team.ts index 7025a7dfe2..60fab2cf4a 100644 --- a/server/presenters/team.ts +++ b/server/presenters/team.ts @@ -6,6 +6,7 @@ export default function present(team: Team) { name: team.name, avatarUrl: team.logoUrl, sharing: team.sharing, + memberCollectionCreate: team.memberCollectionCreate, collaborativeEditing: team.collaborativeEditing, defaultCollectionId: team.defaultCollectionId, documentEmbeds: team.documentEmbeds, diff --git a/server/routes/api/team.ts b/server/routes/api/team.ts index 83cbd79f7a..0890ad384b 100644 --- a/server/routes/api/team.ts +++ b/server/routes/api/team.ts @@ -16,6 +16,7 @@ router.post("team.update", auth(), async (ctx) => { sharing, guestSignin, documentEmbeds, + memberCollectionCreate, collaborativeEditing, defaultCollectionId, defaultUserRole, @@ -37,6 +38,7 @@ router.post("team.update", auth(), async (ctx) => { sharing, guestSignin, documentEmbeds, + memberCollectionCreate, collaborativeEditing, defaultCollectionId, defaultUserRole, diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index cf3a49cc55..f78d40d43f 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -616,6 +616,8 @@ "When enabled, documents can be shared publicly on the internet by any team member": "When enabled, documents can be shared publicly on the internet by any team member", "Rich service embeds": "Rich service embeds", "Links to supported services are shown as rich embeds within your documents": "Links to supported services are shown as rich embeds within your documents", + "Collection creation": "Collection creation", + "Allow members to create new collections within the knowledge base": "Allow members to create new collections within the knowledge base", "Default role": "Default role", "The default user role for new accounts. Changing this setting does not affect existing user accounts.": "The default user role for new accounts. Changing this setting does not affect existing user accounts.", "Sharing is currently disabled.": "Sharing is currently disabled.", From 396836deddae750f7cb8de7b464fdac1a47feb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=BD=E5=A6=82=E5=AF=84?= Date: Fri, 25 Mar 2022 08:45:36 +0800 Subject: [PATCH 06/12] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20del=20ch?= =?UTF-8?q?ildren=20type=20(#3283)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 🔧 del unnecessary children type Change-Id: I3dea5e07f5401bdbdd168eb959fe361c57784167 * feat: 💄 eslint Change-Id: Ie173adeca9e3112d8cdfc1f85964332105dcb424 * feat: 🔧 add css type Change-Id: I8850c4d09b152f4d9c4d98e6eebca58bd9eecd37 * fix: 💄 ci lint Change-Id: I69ff89c7a30e2bdcd26475ec83f3f5ec143121b6 --- app/components/Analytics.ts | 6 +--- app/components/AuthenticatedLayout.tsx | 5 +-- app/components/Breadcrumb.tsx | 8 +++-- app/components/ButtonLink.tsx | 3 +- app/components/CenteredContent.tsx | 3 +- app/components/DocumentBreadcrumb.tsx | 7 ++-- app/components/ErrorBoundary.tsx | 1 - app/components/EventBoundary.tsx | 7 ++-- app/components/Guide.tsx | 5 ++- app/components/Labeled.tsx | 3 +- app/components/Layout.tsx | 5 ++- app/components/Modal.tsx | 5 ++- app/scenes/Settings/components/SettingRow.tsx | 25 +++++++++----- server/emails/components/Body.tsx | 32 ++++++++--------- server/emails/components/Button.tsx | 34 +++++++++---------- server/emails/components/EmailLayout.tsx | 10 +++--- server/emails/components/Heading.tsx | 7 ++-- 17 files changed, 80 insertions(+), 86 deletions(-) diff --git a/app/components/Analytics.ts b/app/components/Analytics.ts index 1bf1e5d94c..044c6718f5 100644 --- a/app/components/Analytics.ts +++ b/app/components/Analytics.ts @@ -2,11 +2,7 @@ import * as React from "react"; import env from "~/env"; -type Props = { - children?: React.ReactNode; -}; - -export default class Analytics extends React.Component { +export default class Analytics extends React.Component { componentDidMount() { if (!env.GOOGLE_ANALYTICS_ID) { return; diff --git a/app/components/AuthenticatedLayout.tsx b/app/components/AuthenticatedLayout.tsx index 11ad15b113..50d9c1c96d 100644 --- a/app/components/AuthenticatedLayout.tsx +++ b/app/components/AuthenticatedLayout.tsx @@ -34,10 +34,7 @@ const CommandBar = React.lazy( ) ); -type Props = WithTranslation & - RootStore & { - children?: React.ReactNode; - }; +type Props = WithTranslation & RootStore; @observer class AuthenticatedLayout extends React.Component { diff --git a/app/components/Breadcrumb.tsx b/app/components/Breadcrumb.tsx index 7ad14c4824..b0c3d205e2 100644 --- a/app/components/Breadcrumb.tsx +++ b/app/components/Breadcrumb.tsx @@ -9,11 +9,15 @@ import { MenuInternalLink } from "~/types"; type Props = { items: MenuInternalLink[]; max?: number; - children?: React.ReactNode; highlightFirstItem?: boolean; }; -function Breadcrumb({ items, highlightFirstItem, children, max = 2 }: Props) { +function Breadcrumb({ + items, + highlightFirstItem, + children, + max = 2, +}: React.PropsWithChildren) { const totalItems = items.length; const topLevelItems: MenuInternalLink[] = [...items]; let overflowItems; diff --git a/app/components/ButtonLink.tsx b/app/components/ButtonLink.tsx index 4c14c1664e..4d3463928f 100644 --- a/app/components/ButtonLink.tsx +++ b/app/components/ButtonLink.tsx @@ -3,10 +3,9 @@ import styled from "styled-components"; type Props = { onClick?: React.MouseEventHandler; - children: React.ReactNode; }; -const ButtonLink = React.forwardRef( +const ButtonLink: React.FC = React.forwardRef( (props: Props, ref: React.Ref) => { return ); -} +}; const Button = styled.button` display: inline-flex; diff --git a/app/components/Sidebar/components/NavLink.tsx b/app/components/Sidebar/components/NavLink.tsx index 7ba8010ece..2295e4c66d 100644 --- a/app/components/Sidebar/components/NavLink.tsx +++ b/app/components/Sidebar/components/NavLink.tsx @@ -70,7 +70,7 @@ const NavLink = ({ const { pathname: path } = toLocation; // Regex taken from: https://github.com/pillarjs/path-to-regexp/blob/master/index.js#L202 - const escapedPath = path && path.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1"); + const escapedPath = path?.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1"); const match = escapedPath ? matchPath(currentLocation.pathname, { path: escapedPath, diff --git a/app/components/Sidebar/components/SidebarButton.tsx b/app/components/Sidebar/components/SidebarButton.tsx index fc3378f985..a23e0e87c3 100644 --- a/app/components/Sidebar/components/SidebarButton.tsx +++ b/app/components/Sidebar/components/SidebarButton.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import styled from "styled-components"; import Flex from "~/components/Flex"; -type Props = { +export type SidebarButtonProps = { title: React.ReactNode; image: React.ReactNode; minHeight?: number; @@ -13,7 +13,7 @@ type Props = { onClick: React.MouseEventHandler; }; -const SidebarButton = React.forwardRef( +const SidebarButton = React.forwardRef( ( { showDisclosure, @@ -22,7 +22,7 @@ const SidebarButton = React.forwardRef( title, minHeight = 0, ...rest - }: Props, + }: SidebarButtonProps, ref ) => ( { @@ -46,7 +44,7 @@ class SocketProvider extends React.Component { } checkConnection = () => { - if (this.socket && this.socket.disconnected && getPageVisible()) { + if (this.socket?.disconnected && getPageVisible()) { // null-ifying this reference is important, do not remove. Without it // references to old sockets are potentially held in context this.socket.close(); @@ -102,10 +100,9 @@ class SocketProvider extends React.Component { // connection may have failed (caused by proxy, firewall, browser, ...) this.socket.on("reconnect_attempt", () => { if (this.socket) { - this.socket.io.opts.transports = - auth.team && auth.team.domain - ? ["websocket"] - : ["websocket", "polling"]; + this.socket.io.opts.transports = auth?.team?.domain + ? ["websocket"] + : ["websocket", "polling"]; } }); @@ -210,10 +207,7 @@ class SocketProvider extends React.Component { // if we already have the latest version (it was us that performed // the change) then we don't need to update anything either. - if ( - collection && - collection.updatedAt === collectionDescriptor.updatedAt - ) { + if (collection?.updatedAt === collectionDescriptor.updatedAt) { continue; } diff --git a/app/components/Subheading.tsx b/app/components/Subheading.tsx index 85bd5e767b..d165fc6f8d 100644 --- a/app/components/Subheading.tsx +++ b/app/components/Subheading.tsx @@ -2,7 +2,6 @@ import * as React from "react"; import styled from "styled-components"; type Props = { - children: React.ReactNode; sticky?: boolean; }; @@ -34,7 +33,7 @@ const Background = styled.div<{ sticky?: boolean }>` z-index: 1; `; -const Subheading = ({ children, sticky, ...rest }: Props) => { +const Subheading: React.FC = ({ children, sticky, ...rest }) => { return (

diff --git a/app/components/Tab.tsx b/app/components/Tab.tsx index 8f8dac6f82..4d12f6a496 100644 --- a/app/components/Tab.tsx +++ b/app/components/Tab.tsx @@ -9,7 +9,6 @@ type Props = Omit< > & { to: string; exact?: boolean; - children: React.ReactNode; }; const TabLink = styled(NavLinkWithChildrenFunc)` @@ -45,7 +44,7 @@ const transition = { damping: 30, }; -export default function Tab({ children, ...rest }: Props) { +const Tab: React.FC = ({ children, ...rest }) => { const theme = useTheme(); const activeStyle = { color: theme.textSecondary, @@ -67,4 +66,6 @@ export default function Tab({ children, ...rest }: Props) { )} ); -} +}; + +export default Tab; diff --git a/app/components/Tabs.tsx b/app/components/Tabs.tsx index 0805d12d6a..e4939e58ed 100644 --- a/app/components/Tabs.tsx +++ b/app/components/Tabs.tsx @@ -56,7 +56,7 @@ export const Separator = styled.span` margin-top: 6px; `; -const Tabs = ({ children }: { children: React.ReactNode }) => { +const Tabs: React.FC = ({ children }) => { const ref = React.useRef(); const [shadowVisible, setShadow] = React.useState(false); const { width } = useWindowSize(); diff --git a/app/components/Theme.tsx b/app/components/Theme.tsx index eb85af31bf..c434e1ee57 100644 --- a/app/components/Theme.tsx +++ b/app/components/Theme.tsx @@ -6,11 +6,7 @@ import useMediaQuery from "~/hooks/useMediaQuery"; import useStores from "~/hooks/useStores"; import GlobalStyles from "~/styles/globals"; -type Props = { - children: React.ReactNode; -}; - -function Theme({ children }: Props) { +const Theme: React.FC = ({ children }) => { const { ui } = useStores(); const resolvedTheme = ui.resolvedTheme === "dark" ? dark : light; const resolvedMobileTheme = @@ -37,6 +33,6 @@ function Theme({ children }: Props) { ); -} +}; export default observer(Theme); diff --git a/app/editor/components/CommandMenu.tsx b/app/editor/components/CommandMenu.tsx index 0d87a0b898..2ace5b25e4 100644 --- a/app/editor/components/CommandMenu.tsx +++ b/app/editor/components/CommandMenu.tsx @@ -139,7 +139,7 @@ class CommandMenu extends React.Component, State> { this.setState({ selectedIndex: Math.max( 0, - prev && prev.name === "separator" ? prevIndex - 1 : prevIndex + prev?.name === "separator" ? prevIndex - 1 : prevIndex ), }); } else { @@ -162,7 +162,7 @@ class CommandMenu extends React.Component, State> { this.setState({ selectedIndex: Math.min( - next && next.name === "separator" ? nextIndex + 1 : nextIndex, + next?.name === "separator" ? nextIndex + 1 : nextIndex, total ), }); diff --git a/app/editor/components/SelectionToolbar.tsx b/app/editor/components/SelectionToolbar.tsx index f71f14a092..55e1ec598c 100644 --- a/app/editor/components/SelectionToolbar.tsx +++ b/app/editor/components/SelectionToolbar.tsx @@ -191,8 +191,7 @@ export default class SelectionToolbar extends React.Component { const isTableSelection = colIndex !== undefined && rowIndex !== undefined; const link = isMarkActive(state.schema.marks.link)(state); const range = getMarkRange(selection.$from, state.schema.marks.link); - const isImageSelection = - selection.node && selection.node.type.name === "image"; + const isImageSelection = selection.node?.type?.name === "image"; let isTextSelection = false; let items: MenuItem[] = []; diff --git a/app/editor/components/Tooltip.tsx b/app/editor/components/Tooltip.tsx index 6dc9fc3080..670a8eabe2 100644 --- a/app/editor/components/Tooltip.tsx +++ b/app/editor/components/Tooltip.tsx @@ -3,11 +3,10 @@ import styled from "styled-components"; import Tooltip from "~/components/Tooltip"; type Props = { - children: React.ReactNode; tooltip?: string; }; -const WrappedTooltip = ({ children, tooltip }: Props) => ( +const WrappedTooltip: React.FC = ({ children, tooltip }) => ( {children} diff --git a/app/hooks/useAuthorizedSettingsConfig.ts b/app/hooks/useAuthorizedSettingsConfig.ts index fe96f56481..016af6ff94 100644 --- a/app/hooks/useAuthorizedSettingsConfig.ts +++ b/app/hooks/useAuthorizedSettingsConfig.ts @@ -29,6 +29,7 @@ import Zapier from "~/scenes/Settings/Zapier"; import SlackIcon from "~/components/SlackIcon"; import ZapierIcon from "~/components/ZapierIcon"; import env from "~/env"; +import isHosted from "~/utils/isHosted"; import useCurrentTeam from "./useCurrentTeam"; import usePolicy from "./usePolicy"; @@ -61,8 +62,6 @@ type ConfigType = { [key in SettingsPage]: ConfigItem; }; -const isHosted = env.DEPLOYMENT === "hosted"; - const useAuthorizedSettingsConfig = () => { const team = useCurrentTeam(); const can = usePolicy(team.id); diff --git a/app/index.tsx b/app/index.tsx index cdf525f266..9a65d2d409 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -37,7 +37,7 @@ if ("serviceWorker" in window.navigator) { } ); - if (maybePromise && maybePromise.then) { + if (maybePromise?.then) { maybePromise .then((registration) => { console.log("SW registered: ", registration); diff --git a/app/menus/AccountMenu.tsx b/app/menus/AccountMenu.tsx index 2c6eb30c90..1c63b5aa3d 100644 --- a/app/menus/AccountMenu.tsx +++ b/app/menus/AccountMenu.tsx @@ -18,11 +18,7 @@ import usePrevious from "~/hooks/usePrevious"; import useStores from "~/hooks/useStores"; import separator from "~/menus/separator"; -type Props = { - children: (props: any) => React.ReactNode; -}; - -function AccountMenu(props: Props) { +const AccountMenu: React.FC = ({ children }) => { const menu = useMenuState({ placement: "bottom-end", modal: true, @@ -55,12 +51,12 @@ function AccountMenu(props: Props) { return ( <> - {props.children} + {children}