A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
refactoring [WIP]
thecodrr827a8f7e17f0
diff --git a/packages/editor/dist/extensions/attachment/attachment.d.ts b/packages/editor/dist/extensions/attachment/attachment.d.tsindex 5fd736538..66f655cae 100644--- a/packages/editor/dist/extensions/attachment/attachment.d.ts+++ b/packages/editor/dist/extensions/attachment/attachment.d.ts@@ -1,6 +1,7 @@import { Node } from "@tiptap/core";export interface AttachmentOptions {onDownloadAttachment: (attachment: Attachment) => boolean;+ onOpenAttachmentPicker: () => boolean;}export declare type Attachment = AttachmentProgress & {hash: string;@@ -16,6 +17,7 @@ export declare type AttachmentProgress = {declare module "@tiptap/core" {interface Commands<ReturnType> {attachment: {+ openAttachmentPicker: () => ReturnType;insertAttachment: (attachment: Attachment) => ReturnType;downloadAttachment: (attachment: Attachment) => ReturnType;setProgress: (progress: AttachmentProgress) => ReturnType;diff --git a/packages/editor/dist/extensions/attachment/attachment.js b/packages/editor/dist/extensions/attachment/attachment.jsindex af3599596..bad96e0da 100644--- a/packages/editor/dist/extensions/attachment/attachment.js+++ b/packages/editor/dist/extensions/attachment/attachment.js@@ -22,6 +22,7 @@ export var AttachmentNode = Node.create({return {// HTMLAttributes: {},onDownloadAttachment: function () { return false; },+ onOpenAttachmentPicker: function () { return false; },};},group: function () {@@ -67,6 +68,11 @@ export var AttachmentNode = Node.create({return _this.options.onDownloadAttachment(attachment);};},+ openAttachmentPicker: function () {+ return function (_a) {+ return _this.options.onOpenAttachmentPicker();+ };+ },setProgress: function (options) {return function (_a) {var e_1, _b;diff --git a/packages/editor/dist/toolbar/toolbar.js b/packages/editor/dist/toolbar/toolbar.jsindex f8a88c10f..5ca0bfa46 100644--- a/packages/editor/dist/toolbar/toolbar.js+++ b/packages/editor/dist/toolbar/toolbar.js@@ -20,14 +20,14 @@ export function Toolbar(props) {var themeProperties = useTheme({ accent: accent, theme: theme, scale: scale });var tools = [["bold", "italic", "underline", "strikethrough", "code"],- ["fontSize", "fontFamily", "headings"],- ["alignLeft", "alignCenter", "alignRight", "alignJustify"],- ["subscript", "superscript", "horizontalRule"],- ["codeblock", "blockquote"],- ["formatClear", "ltr", "rtl"],- ["numberedList", "bulletList", "checklist"],- ["link", "image", "attachment", "table", "embed"],- ["textColor", "highlight"],+ // ["fontSize", "fontFamily", "headings"],+ // ["alignLeft", "alignCenter", "alignRight", "alignJustify"],+ // ["subscript", "superscript", "horizontalRule"],+ // ["codeblock", "blockquote"],+ // ["formatClear", "ltr", "rtl"],+ // ["numberedList", "bulletList", "checklist"],+ // ["link", "image", "attachment", "table", "embed"],+ // ["textColor", "highlight"],];if (!editor)return null;@@ -38,8 +38,8 @@ export function Toolbar(props) {borderRight: "1px solid var(--border)",":last-of-type": { mr: 0, pr: 0, borderRight: "none" },} }, { children: tools.map(function (toolId) {- var Component = findToolById(toolId).render;- return _jsx(Component, { editor: editor });+ var Component = findToolById(toolId);+ return _jsx(Component, { editor: editor, id: toolId });}) })));}) })), _jsx(EditorFloatingMenus, { editor: editor })] })));}diff --git a/packages/editor/dist/toolbar/tools/index.d.ts b/packages/editor/dist/toolbar/tools/index.d.tsindex e8c050ef8..cdf12181b 100644--- a/packages/editor/dist/toolbar/tools/index.d.ts+++ b/packages/editor/dist/toolbar/tools/index.d.ts@@ -1,44 +1,18 @@-import { ITool } from "../types";+import React from "react";+import { ToolProps } from "../types";import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, Link, Attachment } from "./inline";-import { FontSize, FontFamily } from "./font";-import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";-import { Blockquote, CodeBlock, HorizontalRule, Image, Table, Embed } from "./block";-import { Headings } from "./headings";-import { NumberedList, BulletList, Checklist } from "./lists";-import { LeftToRight, RightToLeft } from "./text-direction";-import { Highlight, TextColor } from "./colors";declare const tools: {- bold: Bold;- italic: Italic;- underline: Underline;- strikethrough: Strikethrough;- code: Code;- formatClear: ClearFormatting;- alignCenter: AlignCenter;- alignRight: AlignRight;- alignLeft: AlignLeft;- alignJustify: AlignJustify;- subscript: Subscript;- superscript: Superscript;- fontSize: FontSize;- fontFamily: FontFamily;- horizontalRule: HorizontalRule;- codeblock: CodeBlock;- blockquote: Blockquote;- headings: Headings;- ltr: LeftToRight;- rtl: RightToLeft;- numberedList: NumberedList;- bulletList: BulletList;- checklist: Checklist;- textColor: TextColor;- highlight: Highlight;- link: Link;- image: Image;- attachment: Attachment;- table: Table;- embed: Embed;+ bold: typeof Bold;+ italic: typeof Italic;+ underline: typeof Underline;+ strikethrough: typeof Strikethrough;+ code: typeof Code;+ subscript: typeof Subscript;+ superscript: typeof Superscript;+ clearformatting: typeof ClearFormatting;+ link: typeof Link;+ attachment: typeof Attachment;};export declare type ToolId = keyof typeof tools;-export declare function findToolById(id: ToolId): ITool;+export declare function findToolById(id: ToolId): React.FunctionComponent<ToolProps>;export {};diff --git a/packages/editor/dist/toolbar/tools/index.js b/packages/editor/dist/toolbar/tools/index.jsindex 4fbe4578f..c32a6f056 100644--- a/packages/editor/dist/toolbar/tools/index.js+++ b/packages/editor/dist/toolbar/tools/index.js@@ -1,42 +1,61 @@import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, Link, Attachment, } from "./inline";-import { FontSize, FontFamily } from "./font";-import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";-import { Blockquote, CodeBlock, HorizontalRule, Image, Table, Embed, } from "./block";-import { Headings } from "./headings";-import { NumberedList, BulletList, Checklist } from "./lists";-import { LeftToRight, RightToLeft } from "./text-direction";-import { Highlight, TextColor } from "./colors";+// import { FontSize, FontFamily } from "./font";+// import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+// import {+// Blockquote,+// CodeBlock,+// HorizontalRule,+// Image,+// Table,+// Embed,+// } from "./block";+// import { Headings } from "./headings";+// import { NumberedList, BulletList, Checklist } from "./lists";+// import { LeftToRight, RightToLeft } from "./text-direction";+// import { Highlight, TextColor } from "./colors";+// const tools = {+// bold: new Bold(),+// italic: new Italic(),+// underline: new Underline(),+// strikethrough: new Strikethrough(),+// code: new Code(),+// formatClear: new ClearFormatting(),+// alignCenter: new AlignCenter(),+// alignRight: new AlignRight(),+// alignLeft: new AlignLeft(),+// alignJustify: new AlignJustify(),+// subscript: new Subscript(),+// superscript: new Superscript(),+// fontSize: new FontSize(),+// fontFamily: new FontFamily(),+// horizontalRule: new HorizontalRule(),+// codeblock: new CodeBlock(),+// blockquote: new Blockquote(),+// headings: new Headings(),+// ltr: new LeftToRight(),+// rtl: new RightToLeft(),+// numberedList: new NumberedList(),+// bulletList: new BulletList(),+// checklist: new Checklist(),+// textColor: new TextColor(),+// highlight: new Highlight(),+// link: new Link(),+// image: new Image(),+// attachment: new Attachment(),+// table: new Table(),+// embed: new Embed(),+// };var tools = {- bold: new Bold(),- italic: new Italic(),- underline: new Underline(),- strikethrough: new Strikethrough(),- code: new Code(),- formatClear: new ClearFormatting(),- alignCenter: new AlignCenter(),- alignRight: new AlignRight(),- alignLeft: new AlignLeft(),- alignJustify: new AlignJustify(),- subscript: new Subscript(),- superscript: new Superscript(),- fontSize: new FontSize(),- fontFamily: new FontFamily(),- horizontalRule: new HorizontalRule(),- codeblock: new CodeBlock(),- blockquote: new Blockquote(),- headings: new Headings(),- ltr: new LeftToRight(),- rtl: new RightToLeft(),- numberedList: new NumberedList(),- bulletList: new BulletList(),- checklist: new Checklist(),- textColor: new TextColor(),- highlight: new Highlight(),- link: new Link(),- image: new Image(),- attachment: new Attachment(),- table: new Table(),- embed: new Embed(),+ bold: Bold,+ italic: Italic,+ underline: Underline,+ strikethrough: Strikethrough,+ code: Code,+ subscript: Subscript,+ superscript: Superscript,+ clearformatting: ClearFormatting,+ link: Link,+ attachment: Attachment,};export function findToolById(id) {return tools[id];diff --git a/packages/editor/dist/toolbar/tools/inline.d.ts b/packages/editor/dist/toolbar/tools/inline.d.tsindex 90c680b7b..c27d47cc0 100644--- a/packages/editor/dist/toolbar/tools/inline.d.ts+++ b/packages/editor/dist/toolbar/tools/inline.d.ts@@ -1,48 +1,12 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { ToolId } from ".";-import { IconNames } from "../icons";-declare class InlineTool<TId extends ToolId> implements ITool {- readonly id: TId;- readonly title: string;- private readonly icon;- constructor(id: TId, title: string, icon: IconNames);- render: (props: ToolProps) => JSX.Element;-}-export declare class Italic extends InlineTool<ToolId> {- constructor();-}-export declare class Strikethrough extends InlineTool<ToolId> {- constructor();-}-export declare class Underline extends InlineTool<ToolId> {- constructor();-}-export declare class Code extends InlineTool<ToolId> {- constructor();-}-export declare class Bold extends InlineTool<ToolId> {- constructor();-}-export declare class Subscript extends InlineTool<ToolId> {- constructor();-}-export declare class Superscript extends InlineTool<ToolId> {- constructor();-}-export declare class ClearFormatting implements ITool {- id: ToolId;- title: string;- render: (props: ToolProps) => JSX.Element;-}-export declare class Link implements ITool {- id: ToolId;- title: string;- render: (props: ToolProps) => JSX.Element;-}-export declare class Attachment implements ITool {- id: ToolId;- title: string;- render: (props: ToolProps) => JSX.Element;-}-export {};+import { ToolProps } from "../types";+export declare function Italic(props: ToolProps): JSX.Element;+export declare function Strikethrough(props: ToolProps): JSX.Element;+export declare function Underline(props: ToolProps): JSX.Element;+export declare function Code(props: ToolProps): JSX.Element;+export declare function Bold(props: ToolProps): JSX.Element;+export declare function Subscript(props: ToolProps): JSX.Element;+export declare function Superscript(props: ToolProps): JSX.Element;+export declare function ClearFormatting(props: ToolProps): JSX.Element;+export declare function Link(props: ToolProps): JSX.Element;+export declare function Attachment(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/inline.js b/packages/editor/dist/toolbar/tools/inline.jsindex 79180d7ea..32cd63437 100644--- a/packages/editor/dist/toolbar/tools/inline.js+++ b/packages/editor/dist/toolbar/tools/inline.js@@ -1,18 +1,3 @@-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();var __assign = (this && this.__assign) || function () {__assign = Object.assign || function(t) {for (var s, i = 1, n = arguments.length; i < n; i++) {@@ -47,159 +32,87 @@ import { useRef, useState } from "react";import { Flex } from "rebass";import { Input } from "@rebass/forms";import { Popup } from "../components/popup";-var InlineTool = /** @class */ (function () {- function InlineTool(id, title, icon) {- var _this = this;- this.id = id;- this.title = title;- this.icon = icon;- this.render = function (props) {- var editor = props.editor;- return (_jsx(ToolButton, { title: _this.title, id: _this.id, icon: _this.icon, onClick: function () { return editor.chain().focus().toggleMark(_this.id).run(); }, toggled: editor.isActive(_this.id) }));- };- }- return InlineTool;-}());-var Italic = /** @class */ (function (_super) {- __extends(Italic, _super);- function Italic() {- return _super.call(this, "italic", "Italic", "italic") || this;- }- return Italic;-}(InlineTool));-export { Italic };-var Strikethrough = /** @class */ (function (_super) {- __extends(Strikethrough, _super);- function Strikethrough() {- return _super.call(this, "strikethrough", "Strikethrough", "strikethrough") || this;- }- return Strikethrough;-}(InlineTool));-export { Strikethrough };-var Underline = /** @class */ (function (_super) {- __extends(Underline, _super);- function Underline() {- return _super.call(this, "underline", "Underline", "underline") || this;- }- return Underline;-}(InlineTool));-export { Underline };-var Code = /** @class */ (function (_super) {- __extends(Code, _super);- function Code() {- return _super.call(this, "code", "Code", "code") || this;- }- return Code;-}(InlineTool));-export { Code };-var Bold = /** @class */ (function (_super) {- __extends(Bold, _super);- function Bold() {- return _super.call(this, "bold", "Bold", "bold") || this;- }- return Bold;-}(InlineTool));-export { Bold };-var Subscript = /** @class */ (function (_super) {- __extends(Subscript, _super);- function Subscript() {- return _super.call(this, "subscript", "Subscript", "subscript") || this;- }- return Subscript;-}(InlineTool));-export { Subscript };-var Superscript = /** @class */ (function (_super) {- __extends(Superscript, _super);- function Superscript() {- return _super.call(this, "superscript", "Superscript", "superscript") || this;- }- return Superscript;-}(InlineTool));-export { Superscript };-var ClearFormatting = /** @class */ (function () {- function ClearFormatting() {- var _this = this;- this.id = "formatClear";- this.title = "Clear all formatting";- this.render = function (props) {- var editor = props.editor;- return (_jsx(ToolButton, { title: _this.title, id: _this.id, icon: "formatClear", onClick: function () {- return editor.chain().focus().clearNodes().unsetAllMarks().run();- }, toggled: false }));- };- }- return ClearFormatting;-}());-export { ClearFormatting };-var Link = /** @class */ (function () {- function Link() {- var _this = this;- this.id = "link";- this.title = "Link";- this.render = function (props) {- var editor = props.editor;- var buttonRef = useRef(null);- var targetRef = useRef();- var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var _b = __read(useState(), 2), href = _b[0], setHref = _b[1];- var _c = __read(useState(), 2), text = _c[0], setText = _c[1];- var currentUrl = editor.getAttributes("link").href;- var isEditing = !!currentUrl;- return (_jsxs(_Fragment, { children: [_jsx(ToolButton, { ref: buttonRef, title: _this.title, id: _this.id, icon: "link", onClick: function () {- if (isEditing)- setHref(currentUrl);- var _a = editor.state.selection, from = _a.from, to = _a.to, $from = _a.$from;- var selectedNode = $from.node();- var pos = selectedNode.isTextblock ? $from.before() : $from.pos;- var domNode = editor.view.nodeDOM(pos);- targetRef.current = domNode;- var selectedText = isEditing- ? selectedNode.textContent- : editor.state.doc.textBetween(from, to);- setText(selectedText);- setIsOpen(true);- }, toggled: isOpen || !!isEditing }), _jsx(MenuPresenter, __assign({ options: {- type: "menu",- position: {- target: targetRef.current || buttonRef.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- },- }, isOpen: isOpen, items: [], onClose: function () {- editor.commands.focus();+function InlineTool(props) {+ var editor = props.editor, title = props.title, id = props.id, icon = props.icon, isToggled = props.isToggled, onClick = props.onClick;+ return (_jsx(ToolButton, { title: title, id: id, icon: icon, onClick: function () { return onClick(editor); }, toggled: isToggled(editor) }));+}+export function Italic(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function (editor) { return editor.isActive("italic"); }, onClick: function (editor) { return editor.chain().focus().toggleItalic().run(); } })));+}+export function Strikethrough(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function (editor) { return editor.isActive("strikethrough"); }, onClick: function (editor) { return editor.chain().focus().toggleStrike().run(); } })));+}+export function Underline(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function (editor) { return editor.isActive("underline"); }, onClick: function (editor) { return editor.chain().focus().toggleUnderline().run(); } })));+}+export function Code(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function (editor) { return editor.isActive("code"); }, onClick: function (editor) { return editor.chain().focus().toggleCode().run(); } })));+}+export function Bold(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function (editor) { return editor.isActive("bold"); }, onClick: function (editor) { return editor.chain().focus().toggleBold().run(); } })));+}+export function Subscript(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function (editor) { return editor.isActive("subscript"); }, onClick: function (editor) { return editor.chain().focus().toggleSubscript().run(); } })));+}+export function Superscript(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function (editor) { return editor.isActive("superscript"); }, onClick: function (editor) { return editor.chain().focus().toggleSuperscript().run(); } })));+}+export function ClearFormatting(props) {+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function () { return false; }, onClick: function (editor) {+ return editor.chain().focus().clearNodes().unsetAllMarks().run();+ } })));+}+export function Link(props) {+ var editor = props.editor, id = props.id, title = props.title, icon = props.icon;+ var buttonRef = useRef(null);+ var targetRef = useRef();+ var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];+ var _b = __read(useState(), 2), href = _b[0], setHref = _b[1];+ var _c = __read(useState(), 2), text = _c[0], setText = _c[1];+ var currentUrl = editor.getAttributes("link").href;+ var isEditing = !!currentUrl;+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, { ref: buttonRef, title: title, id: id, icon: icon, onClick: function () {+ if (isEditing)+ setHref(currentUrl);+ var _a = editor.state.selection, from = _a.from, to = _a.to, $from = _a.$from;+ var selectedNode = $from.node();+ var pos = selectedNode.isTextblock ? $from.before() : $from.pos;+ var domNode = editor.view.nodeDOM(pos);+ targetRef.current = domNode;+ var selectedText = isEditing+ ? selectedNode.textContent+ : editor.state.doc.textBetween(from, to);+ setText(selectedText);+ setIsOpen(true);+ }, toggled: isOpen || !!isEditing }), _jsx(MenuPresenter, __assign({ options: {+ type: "menu",+ position: {+ target: targetRef.current || buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ },+ }, isOpen: isOpen, items: [], onClose: function () {+ editor.commands.focus();+ setIsOpen(false);+ } }, { children: _jsx(Popup, __assign({ title: isEditing ? "Edit link" : "Insert link", action: {+ text: isEditing ? "Edit" : "Insert",+ onClick: function () {+ if (!href)+ return;+ var commandChain = editor+ .chain()+ .focus()+ .extendMarkRange("link")+ .setLink({ href: href, target: "_blank" });+ if (text)+ commandChain = commandChain.insertContent(text).focus();+ commandChain.run();setIsOpen(false);- } }, { children: _jsx(Popup, __assign({ title: isEditing ? "Edit link" : "Insert link", action: {- text: isEditing ? "Edit" : "Insert",- onClick: function () {- if (!href)- return;- var commandChain = editor- .chain()- .focus()- .extendMarkRange("link")- .setLink({ href: href, target: "_blank" });- if (text)- commandChain = commandChain.insertContent(text).focus();- commandChain.run();- setIsOpen(false);- },- } }, { children: _jsxs(Flex, __assign({ sx: { p: 1, width: 300, flexDirection: "column" } }, { children: [_jsx(Input, { type: "text", placeholder: "Link text", value: text, onChange: function (e) { return setText(e.target.value); } }), _jsx(Input, { type: "url", sx: { mt: 1 }, autoFocus: true, placeholder: "https://example.com/", value: href, onChange: function (e) { return setHref(e.target.value); } })] })) })) }))] }));- };- }- return Link;-}());-export { Link };-var Attachment = /** @class */ (function () {- function Attachment() {- var _this = this;- this.id = "attachment";- this.title = "Attachment";- this.render = function (props) {- var editor = props.editor;- return (_jsx(ToolButton, { title: _this.title, id: _this.id, icon: "attachment", onClick: function () { }, toggled: false }));- };- }- return Attachment;-}());-export { Attachment };+ },+ } }, { children: _jsxs(Flex, __assign({ sx: { p: 1, width: 300, flexDirection: "column" } }, { children: [_jsx(Input, { type: "text", placeholder: "Link text", value: text, onChange: function (e) { return setText(e.target.value); } }), _jsx(Input, { type: "url", sx: { mt: 1 }, autoFocus: true, placeholder: "https://example.com/", value: href, onChange: function (e) { return setHref(e.target.value); } })] })) })) }))] }));+}+export function Attachment(props) {+ var editor = props.editor;+ return (_jsx(InlineTool, __assign({}, props, { isToggled: function () { return false; }, onClick: function () { return editor.chain().focus().openAttachmentPicker().run(); } })));+}diff --git a/packages/editor/dist/toolbar/tools/lists.d.ts b/packages/editor/dist/toolbar/tools/lists.d.tsindex 1f72b9bda..fe8d31586 100644--- a/packages/editor/dist/toolbar/tools/lists.d.ts+++ b/packages/editor/dist/toolbar/tools/lists.d.ts@@ -1,3 +1,4 @@+/// <reference types="react" />import { ITool, ToolProps } from "../types";import { Editor } from "@tiptap/core";import { ToolId } from ".";diff --git a/packages/editor/dist/toolbar/types.d.ts b/packages/editor/dist/toolbar/types.d.tsindex 8c3282031..02b6fd643 100644--- a/packages/editor/dist/toolbar/types.d.ts+++ b/packages/editor/dist/toolbar/types.d.ts@@ -1,12 +1,12 @@-/// <reference types="react" />import { Editor } from "@tiptap/core";+import { IconNames } from "./icons";import { ToolId } from "./tools";-export declare type ToolProps = {+export declare type ToolProps = ToolDefinition & {editor: Editor;-};-export interface ITool {id: ToolId;+};+export declare type ToolDefinition = {+ icon: IconNames;title: string;description?: string;- render(props: ToolProps): JSX.Element;-}+};diff --git a/packages/editor/dist/toolbar/types.js b/packages/editor/dist/toolbar/types.jsindex 9e6994e55..cb0ff5c3b 100644--- a/packages/editor/dist/toolbar/types.js+++ b/packages/editor/dist/toolbar/types.js@@ -1,4 +1 @@export {};-// export interface ToolConstructor {-// new (editor: Editor): ITool;-// }diff --git a/packages/editor/src/extensions/attachment/attachment.ts b/packages/editor/src/extensions/attachment/attachment.tsindex 00c8b8e22..c712adeaf 100644--- a/packages/editor/src/extensions/attachment/attachment.ts+++ b/packages/editor/src/extensions/attachment/attachment.ts@@ -6,6 +6,7 @@ import { AttachmentComponent } from "./component";export interface AttachmentOptions {// HTMLAttributes: Record<string, any>;onDownloadAttachment: (attachment: Attachment) => boolean;+ onOpenAttachmentPicker: () => boolean;}export type Attachment = AttachmentProgress & {@@ -24,6 +25,7 @@ export type AttachmentProgress = {declare module "@tiptap/core" {interface Commands<ReturnType> {attachment: {+ openAttachmentPicker: () => ReturnType;insertAttachment: (attachment: Attachment) => ReturnType;downloadAttachment: (attachment: Attachment) => ReturnType;setProgress: (progress: AttachmentProgress) => ReturnType;@@ -42,6 +44,7 @@ export const AttachmentNode = Node.create<AttachmentOptions>({return {// HTMLAttributes: {},onDownloadAttachment: () => false,+ onOpenAttachmentPicker: () => false,};},@@ -91,6 +94,11 @@ export const AttachmentNode = Node.create<AttachmentOptions>({({}) => {return this.options.onDownloadAttachment(attachment);},+ openAttachmentPicker:+ () =>+ ({}) => {+ return this.options.onOpenAttachmentPicker();+ },setProgress:(options) =>({ state, tr, dispatch }) => {diff --git a/packages/editor/src/toolbar/tool-definitions.ts b/packages/editor/src/toolbar/tool-definitions.tsnew file mode 100644index 000000000..ba44b6c46--- /dev/null+++ b/packages/editor/src/toolbar/tool-definitions.ts@@ -0,0 +1,45 @@+import { ToolDefinition } from "./types";+import { ToolId } from "./tools";++const InlineTools: Record<ToolId, ToolDefinition> = {+ attachment: {+ icon: "attachment",+ title: "Attachment",+ },+ bold: {+ icon: "bold",+ title: "Bold",+ },+ italic: {+ icon: "attachment",+ title: "Attachment",+ },+ underline: {+ icon: "attachment",+ title: "Attachment",+ },+ strikethrough: {+ icon: "attachment",+ title: "Attachment",+ },+ link: {+ icon: "attachment",+ title: "Attachment",+ },+ code: {+ icon: "attachment",+ title: "Attachment",+ },+ clearformatting: {+ icon: "attachment",+ title: "Attachment",+ },+ subscript: {+ icon: "attachment",+ title: "Attachment",+ },+ superscript: {+ icon: "attachment",+ title: "Attachment",+ },+};diff --git a/packages/editor/src/toolbar/toolbar.tsx b/packages/editor/src/toolbar/toolbar.tsxindex 5560e562f..7d5d31847 100644--- a/packages/editor/src/toolbar/toolbar.tsx+++ b/packages/editor/src/toolbar/toolbar.tsx@@ -28,14 +28,14 @@ export function Toolbar(props: ToolbarProps) {const tools: ToolbarDefinition = [["bold", "italic", "underline", "strikethrough", "code"],- ["fontSize", "fontFamily", "headings"],- ["alignLeft", "alignCenter", "alignRight", "alignJustify"],- ["subscript", "superscript", "horizontalRule"],- ["codeblock", "blockquote"],- ["formatClear", "ltr", "rtl"],- ["numberedList", "bulletList", "checklist"],- ["link", "image", "attachment", "table", "embed"],- ["textColor", "highlight"],+ // ["fontSize", "fontFamily", "headings"],+ // ["alignLeft", "alignCenter", "alignRight", "alignJustify"],+ // ["subscript", "superscript", "horizontalRule"],+ // ["codeblock", "blockquote"],+ // ["formatClear", "ltr", "rtl"],+ // ["numberedList", "bulletList", "checklist"],+ // ["link", "image", "attachment", "table", "embed"],+ // ["textColor", "highlight"],];if (!editor) return null;@@ -54,8 +54,8 @@ export function Toolbar(props: ToolbarProps) {}}>{tools.map((toolId) => {- const { render: Component } = findToolById(toolId);- return <Component editor={editor} />;+ const Component = findToolById(toolId);+ return <Component editor={editor} id={toolId} />;})}</Flex>);diff --git a/packages/editor/src/toolbar/tools/index.ts b/packages/editor/src/toolbar/tools/index.tsindex a735eaae5..0a21a7980 100644--- a/packages/editor/src/toolbar/tools/index.ts+++ b/packages/editor/src/toolbar/tools/index.ts@@ -1,4 +1,5 @@-import { ITool } from "../types";+import React from "react";+import { ToolProps } from "../types";import {Bold,Italic,@@ -11,54 +12,66 @@ import {Link,Attachment,} from "./inline";-import { FontSize, FontFamily } from "./font";-import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";-import {- Blockquote,- CodeBlock,- HorizontalRule,- Image,- Table,- Embed,-} from "./block";-import { Headings } from "./headings";-import { NumberedList, BulletList, Checklist } from "./lists";-import { LeftToRight, RightToLeft } from "./text-direction";-import { Highlight, TextColor } from "./colors";+// import { FontSize, FontFamily } from "./font";+// import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+// import {+// Blockquote,+// CodeBlock,+// HorizontalRule,+// Image,+// Table,+// Embed,+// } from "./block";+// import { Headings } from "./headings";+// import { NumberedList, BulletList, Checklist } from "./lists";+// import { LeftToRight, RightToLeft } from "./text-direction";+// import { Highlight, TextColor } from "./colors";+// const tools = {+// bold: new Bold(),+// italic: new Italic(),+// underline: new Underline(),+// strikethrough: new Strikethrough(),+// code: new Code(),+// formatClear: new ClearFormatting(),+// alignCenter: new AlignCenter(),+// alignRight: new AlignRight(),+// alignLeft: new AlignLeft(),+// alignJustify: new AlignJustify(),+// subscript: new Subscript(),+// superscript: new Superscript(),+// fontSize: new FontSize(),+// fontFamily: new FontFamily(),+// horizontalRule: new HorizontalRule(),+// codeblock: new CodeBlock(),+// blockquote: new Blockquote(),+// headings: new Headings(),+// ltr: new LeftToRight(),+// rtl: new RightToLeft(),+// numberedList: new NumberedList(),+// bulletList: new BulletList(),+// checklist: new Checklist(),+// textColor: new TextColor(),+// highlight: new Highlight(),+// link: new Link(),+// image: new Image(),+// attachment: new Attachment(),+// table: new Table(),+// embed: new Embed(),+// };const tools = {- bold: new Bold(),- italic: new Italic(),- underline: new Underline(),- strikethrough: new Strikethrough(),- code: new Code(),- formatClear: new ClearFormatting(),- alignCenter: new AlignCenter(),- alignRight: new AlignRight(),- alignLeft: new AlignLeft(),- alignJustify: new AlignJustify(),- subscript: new Subscript(),- superscript: new Superscript(),- fontSize: new FontSize(),- fontFamily: new FontFamily(),- horizontalRule: new HorizontalRule(),- codeblock: new CodeBlock(),- blockquote: new Blockquote(),- headings: new Headings(),- ltr: new LeftToRight(),- rtl: new RightToLeft(),- numberedList: new NumberedList(),- bulletList: new BulletList(),- checklist: new Checklist(),- textColor: new TextColor(),- highlight: new Highlight(),- link: new Link(),- image: new Image(),- attachment: new Attachment(),- table: new Table(),- embed: new Embed(),+ bold: Bold,+ italic: Italic,+ underline: Underline,+ strikethrough: Strikethrough,+ code: Code,+ subscript: Subscript,+ superscript: Superscript,+ clearformatting: ClearFormatting,+ link: Link,+ attachment: Attachment,};export type ToolId = keyof typeof tools;-export function findToolById(id: ToolId): ITool {+export function findToolById(id: ToolId): React.FunctionComponent<ToolProps> {return tools[id];}diff --git a/packages/editor/src/toolbar/tools/inline.tsx b/packages/editor/src/toolbar/tools/inline.tsxindex a78a60903..ddf5a2a9f 100644--- a/packages/editor/src/toolbar/tools/inline.tsx+++ b/packages/editor/src/toolbar/tools/inline.tsx@@ -1,216 +1,215 @@-import { ITool, ToolProps } from "../types";+import { ToolProps } from "../types";import { Editor } from "@tiptap/core";import { ToolButton } from "../components/tool-button";-import { ToolId } from ".";import { MenuPresenter } from "../../components/menu/menu";import { useRef, useState } from "react";-import { Flex, Text } from "rebass";+import { Flex } from "rebass";import { Input } from "@rebass/forms";import { Popup } from "../components/popup";-import { FloatingMenu } from "@tiptap/react";-import { IconNames } from "../icons";--class InlineTool<TId extends ToolId> implements ITool {- constructor(- readonly id: TId,- readonly title: string,- private readonly icon: IconNames- ) {}-- render = (props: ToolProps) => {- const { editor } = props;- return (- <ToolButton- title={this.title}- id={this.id}- icon={this.icon}- onClick={() => editor.chain().focus().toggleMark(this.id).run()}- toggled={editor.isActive(this.id)}- />- );- };-}-export class Italic extends InlineTool<ToolId> {- constructor() {- super("italic", "Italic", "italic");- }+type InlineToolProps = ToolProps & {+ isToggled: (editor: Editor) => boolean;+ onClick: (editor: Editor) => boolean;+};+function InlineTool(props: InlineToolProps) {+ const { editor, title, id, icon, isToggled, onClick } = props;+ return (+ <ToolButton+ title={title}+ id={id}+ icon={icon}+ onClick={() => onClick(editor)}+ toggled={isToggled(editor)}+ />+ );}-export class Strikethrough extends InlineTool<ToolId> {- constructor() {- super("strikethrough", "Strikethrough", "strikethrough");- }+export function Italic(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={(editor) => editor.isActive("italic")}+ onClick={(editor) => editor.chain().focus().toggleItalic().run()}+ />+ );}-export class Underline extends InlineTool<ToolId> {- constructor() {- super("underline", "Underline", "underline");- }+export function Strikethrough(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={(editor) => editor.isActive("strikethrough")}+ onClick={(editor) => editor.chain().focus().toggleStrike().run()}+ />+ );}-export class Code extends InlineTool<ToolId> {- constructor() {- super("code", "Code", "code");- }+export function Underline(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={(editor) => editor.isActive("underline")}+ onClick={(editor) => editor.chain().focus().toggleUnderline().run()}+ />+ );}-export class Bold extends InlineTool<ToolId> {- constructor() {- super("bold", "Bold", "bold");- }+export function Code(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={(editor) => editor.isActive("code")}+ onClick={(editor) => editor.chain().focus().toggleCode().run()}+ />+ );}-export class Subscript extends InlineTool<ToolId> {- constructor() {- super("subscript", "Subscript", "subscript");- }+export function Bold(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={(editor) => editor.isActive("bold")}+ onClick={(editor) => editor.chain().focus().toggleBold().run()}+ />+ );}-export class Superscript extends InlineTool<ToolId> {- constructor() {- super("superscript", "Superscript", "superscript");- }+export function Subscript(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={(editor) => editor.isActive("subscript")}+ onClick={(editor) => editor.chain().focus().toggleSubscript().run()}+ />+ );}-export class ClearFormatting implements ITool {- id: ToolId = "formatClear";- title = "Clear all formatting";+export function Superscript(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={(editor) => editor.isActive("superscript")}+ onClick={(editor) => editor.chain().focus().toggleSuperscript().run()}+ />+ );+}- render = (props: ToolProps) => {- const { editor } = props;+export function ClearFormatting(props: ToolProps) {+ return (+ <InlineTool+ {...props}+ isToggled={() => false}+ onClick={(editor) =>+ editor.chain().focus().clearNodes().unsetAllMarks().run()+ }+ />+ );+}- return (+export function Link(props: ToolProps) {+ const { editor, id, title, icon } = props;+ const buttonRef = useRef<HTMLButtonElement>(null);+ const targetRef = useRef<HTMLElement>();+ const [isOpen, setIsOpen] = useState(false);+ const [href, setHref] = useState<string>();+ const [text, setText] = useState<string>();+ const currentUrl = editor.getAttributes("link").href;+ const isEditing = !!currentUrl;++ return (+ <><ToolButton- title={this.title}- id={this.id}- icon="formatClear"- onClick={() =>- editor.chain().focus().clearNodes().unsetAllMarks().run()- }- toggled={false}- />- );- };-}+ ref={buttonRef}+ title={title}+ id={id}+ icon={icon}+ onClick={() => {+ if (isEditing) setHref(currentUrl);-export class Link implements ITool {- id: ToolId = "link";- title = "Link";-- render = (props: ToolProps) => {- const { editor } = props;- const buttonRef = useRef<HTMLButtonElement>(null);- const targetRef = useRef<HTMLElement>();- const [isOpen, setIsOpen] = useState(false);- const [href, setHref] = useState<string>();- const [text, setText] = useState<string>();- const currentUrl = editor.getAttributes("link").href;- const isEditing = !!currentUrl;-- return (- <>- <ToolButton- ref={buttonRef}- title={this.title}- id={this.id}- icon={"link"}- onClick={() => {- if (isEditing) setHref(currentUrl);-- let { from, to, $from } = editor.state.selection;-- const selectedNode = $from.node();- const pos = selectedNode.isTextblock ? $from.before() : $from.pos;-- const domNode = editor.view.nodeDOM(pos) as HTMLElement;- targetRef.current = domNode;-- const selectedText = isEditing- ? selectedNode.textContent- : editor.state.doc.textBetween(from, to);-- setText(selectedText);- setIsOpen(true);- }}- toggled={isOpen || !!isEditing}- />- <MenuPresenter- options={{- type: "menu",- position: {- target: targetRef.current || buttonRef.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 5,+ let { from, to, $from } = editor.state.selection;++ const selectedNode = $from.node();+ const pos = selectedNode.isTextblock ? $from.before() : $from.pos;++ const domNode = editor.view.nodeDOM(pos) as HTMLElement;+ targetRef.current = domNode;++ const selectedText = isEditing+ ? selectedNode.textContent+ : editor.state.doc.textBetween(from, to);++ setText(selectedText);+ setIsOpen(true);+ }}+ toggled={isOpen || !!isEditing}+ />+ <MenuPresenter+ options={{+ type: "menu",+ position: {+ target: targetRef.current || buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ },+ }}+ isOpen={isOpen}+ items={[]}+ onClose={() => {+ editor.commands.focus();+ setIsOpen(false);+ }}+ >+ <Popup+ title={isEditing ? "Edit link" : "Insert link"}+ action={{+ text: isEditing ? "Edit" : "Insert",+ onClick: () => {+ if (!href) return;++ let commandChain = editor+ .chain()+ .focus()+ .extendMarkRange("link")+ .setLink({ href, target: "_blank" });+ if (text) commandChain = commandChain.insertContent(text).focus();++ commandChain.run();+ setIsOpen(false);},}}- isOpen={isOpen}- items={[]}- onClose={() => {- editor.commands.focus();- setIsOpen(false);- }}+ // negativeButton={{ text: "Cancel", onClick: () => setIsOpen(false) }}>- <Popup- title={isEditing ? "Edit link" : "Insert link"}- action={{- text: isEditing ? "Edit" : "Insert",- onClick: () => {- if (!href) return;-- let commandChain = editor- .chain()- .focus()- .extendMarkRange("link")- .setLink({ href, target: "_blank" });- if (text)- commandChain = commandChain.insertContent(text).focus();-- commandChain.run();- setIsOpen(false);- },- }}- // negativeButton={{ text: "Cancel", onClick: () => setIsOpen(false) }}- >- <Flex sx={{ p: 1, width: 300, flexDirection: "column" }}>- <Input- type="text"- placeholder="Link text"- value={text}- onChange={(e) => setText(e.target.value)}- />- <Input- type="url"- sx={{ mt: 1 }}- autoFocus- placeholder="https://example.com/"- value={href}- onChange={(e) => setHref(e.target.value)}- />- </Flex>- </Popup>- </MenuPresenter>- </>- );- };+ <Flex sx={{ p: 1, width: 300, flexDirection: "column" }}>+ <Input+ type="text"+ placeholder="Link text"+ value={text}+ onChange={(e) => setText(e.target.value)}+ />+ <Input+ type="url"+ sx={{ mt: 1 }}+ autoFocus+ placeholder="https://example.com/"+ value={href}+ onChange={(e) => setHref(e.target.value)}+ />+ </Flex>+ </Popup>+ </MenuPresenter>+ </>+ );}-export class Attachment implements ITool {- id: ToolId = "attachment";- title = "Attachment";-- render = (props: ToolProps) => {- const { editor } = props;+export function Attachment(props: ToolProps) {+ const { editor } = props;- return (- <ToolButton- title={this.title}- id={this.id}- icon="attachment"- onClick={() => {}}- toggled={false}- />- );- };+ return (+ <InlineTool+ {...props}+ isToggled={() => false}+ onClick={() => editor.chain().focus().openAttachmentPicker().run()}+ />+ );}diff --git a/packages/editor/src/toolbar/types.ts b/packages/editor/src/toolbar/types.tsindex a5145277a..8ff936ac6 100644--- a/packages/editor/src/toolbar/types.ts+++ b/packages/editor/src/toolbar/types.ts@@ -1,14 +1,14 @@import { Editor } from "@tiptap/core";+import { IconNames } from "./icons";import { ToolId } from "./tools";-export type ToolProps = { editor: Editor };-export interface ITool {+export type ToolProps = ToolDefinition & {+ editor: Editor;id: ToolId;+};++export type ToolDefinition = {+ icon: IconNames;title: string;description?: string;- render(props: ToolProps): JSX.Element;-}--// export interface ToolConstructor {-// new (editor: Editor): ITool;-// }+};diff --git a/packages/editor/toolbar.md b/packages/editor/toolbar.mdindex 3e0eea3c3..e2c3e0486 100644--- a/packages/editor/toolbar.md+++ b/packages/editor/toolbar.md@@ -70,3 +70,27 @@ Total Tools:- [x] table- [x] ltr rtl- [x] searchreplace++What's next:++- [ ] Port codeblock extension from tinymce to tiptap+- [ ] Optimize toolbar & editor UI for mobile+- [ ] Refactor & finalize UI + styling+- [ ] Write tests++## Optimize toolbar & editor UI for mobile++1. Refactor tools to be more easily configurable+2. Implement sub groups in toolbar+3. Move all popups to /popups directory+4. Implement mobile positioning logic in menu/popup presenter+5. Add support for repositioning toolbar (top/bottom)+6. Move all popups to be shown as bottom sheets on mobile++### Refactor tools++1. A tool defines it's own UI+ - This gives it maximum flexibility to do whatever it wants.+2. Some factors of a tool's UI can be defined externally+ - For example, a tool's icon + title + description?+3.