Files
outline/app/editor/menus/formatting.tsx
Tom Moor fc8c20149f feat: Comments (#4911)
* Comment model

* Framework, model, policy, presenter, api endpoint etc

* Iteration, first pass of UI

* fixes, refactors

* Comment commands

* comment socket support

* typing indicators

* comment component, styling

* wip

* right sidebar resize

* fix: CMD+Enter submit

* Add usePersistedState
fix: Main page scrolling on comment highlight

* drafts

* Typing indicator

* refactor

* policies

* Click thread to highlight
Improve comment timestamps

* padding

* Comment menu v1

* Change comments to use editor

* Basic comment editing

* fix: Hide commenting button when disabled at team level

* Enable opening sidebar without mark

* Move selected comment to location state

* Add comment delete confirmation

* Add comment count to document meta

* fix: Comment sidebar togglable
Add copy link to comment

* stash

* Restore History changes

* Refactor right sidebar to allow for comment animation

* Update to new router best practices

* stash

* Various improvements

* stash

* Handle click outside

* Fix incorrect placeholder in input
fix: Input box appearing on other sessions erroneously

* stash

* fix: Don't leave orphaned child comments

* styling

* stash

* Enable comment toggling again

* Edit styling, merge conflicts

* fix: Cannot navigate from insights to comments

* Remove draft comment mark on click outside

* Fix: Empty comment sidebar, tsc

* Remove public toggle

* fix: All comments are recessed
fix: Comments should not be printed

* fix: Associated mark should be removed on comment delete

* Revert unused changes

* Empty state, basic RTL support

* Create dont toggle comment mark

* Make it feel more snappy

* Highlight active comment in text

* fix animation

* RTL support

* Add reply CTA

* Translations
2023-02-25 12:03:05 -08:00

159 lines
4.1 KiB
TypeScript

import {
BoldIcon,
CodeIcon,
Heading1Icon,
Heading2Icon,
BlockQuoteIcon,
LinkIcon,
StrikethroughIcon,
OrderedListIcon,
BulletedListIcon,
TodoListIcon,
InputIcon,
HighlightIcon,
CommentIcon,
ItalicIcon,
} from "outline-icons";
import { EditorState } from "prosemirror-state";
import { isInTable } from "prosemirror-tables";
import * as React from "react";
import isInCode from "@shared/editor/queries/isInCode";
import isInList from "@shared/editor/queries/isInList";
import isMarkActive from "@shared/editor/queries/isMarkActive";
import isNodeActive from "@shared/editor/queries/isNodeActive";
import { MenuItem } from "@shared/editor/types";
import { Dictionary } from "~/hooks/useDictionary";
export default function formattingMenuItems(
state: EditorState,
isTemplate: boolean,
dictionary: Dictionary
): MenuItem[] {
const { schema } = state;
const isTable = isInTable(state);
const isList = isInList(state);
const isCode = isInCode(state);
const allowBlocks = !isTable && !isList;
return [
{
name: "placeholder",
tooltip: dictionary.placeholder,
icon: <InputIcon />,
active: isMarkActive(schema.marks.placeholder),
visible: isTemplate,
},
{
name: "separator",
visible: isTemplate,
},
{
name: "strong",
tooltip: dictionary.strong,
icon: <BoldIcon />,
active: isMarkActive(schema.marks.strong),
visible: !isCode,
},
{
name: "em",
tooltip: dictionary.em,
icon: <ItalicIcon />,
active: isMarkActive(schema.marks.em),
visible: !isCode,
},
{
name: "strikethrough",
tooltip: dictionary.strikethrough,
icon: <StrikethroughIcon />,
active: isMarkActive(schema.marks.strikethrough),
visible: !isCode,
},
{
name: "highlight",
tooltip: dictionary.mark,
icon: <HighlightIcon />,
active: isMarkActive(schema.marks.highlight),
visible: !isTemplate && !isCode,
},
{
name: "code_inline",
tooltip: dictionary.codeInline,
icon: <CodeIcon />,
active: isMarkActive(schema.marks.code_inline),
},
{
name: "separator",
visible: allowBlocks && !isCode,
},
{
name: "heading",
tooltip: dictionary.heading,
icon: <Heading1Icon />,
active: isNodeActive(schema.nodes.heading, { level: 1 }),
attrs: { level: 1 },
visible: allowBlocks && !isCode,
},
{
name: "heading",
tooltip: dictionary.subheading,
icon: <Heading2Icon />,
active: isNodeActive(schema.nodes.heading, { level: 2 }),
attrs: { level: 2 },
visible: allowBlocks && !isCode,
},
{
name: "blockquote",
tooltip: dictionary.quote,
icon: <BlockQuoteIcon />,
active: isNodeActive(schema.nodes.blockquote),
attrs: { level: 2 },
visible: allowBlocks && !isCode,
},
{
name: "separator",
visible: (allowBlocks || isList) && !isCode,
},
{
name: "checkbox_list",
tooltip: dictionary.checkboxList,
icon: <TodoListIcon />,
keywords: "checklist checkbox task",
active: isNodeActive(schema.nodes.checkbox_list),
visible: (allowBlocks || isList) && !isCode,
},
{
name: "bullet_list",
tooltip: dictionary.bulletList,
icon: <BulletedListIcon />,
active: isNodeActive(schema.nodes.bullet_list),
visible: (allowBlocks || isList) && !isCode,
},
{
name: "ordered_list",
tooltip: dictionary.orderedList,
icon: <OrderedListIcon />,
active: isNodeActive(schema.nodes.ordered_list),
visible: (allowBlocks || isList) && !isCode,
},
{
name: "separator",
visible: !isCode,
},
{
name: "link",
tooltip: dictionary.createLink,
icon: <LinkIcon />,
active: isMarkActive(schema.marks.link),
attrs: { href: "" },
visible: !isCode,
},
{
name: "comment",
tooltip: dictionary.comment,
icon: <CommentIcon />,
active: isMarkActive(schema.marks.comment),
visible: !isCode,
},
];
}