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
fix: highlights not being respected from old editor
thecodrr9b497491270a
diff --git a/packages/editor/package-lock.json b/packages/editor/package-lock.jsonindex 02499771e..a6a4aa484 100644--- a/packages/editor/package-lock.json+++ b/packages/editor/package-lock.json@@ -18,7 +18,6 @@"@tiptap/extension-character-count": "^2.0.0-beta.31","@tiptap/extension-color": "^2.0.0-beta.12","@tiptap/extension-font-family": "^2.0.0-beta.24",- "@tiptap/extension-highlight": "^2.0.0-beta.35","@tiptap/extension-history": "^2.0.0-beta.26","@tiptap/extension-horizontal-rule": "^2.0.0-beta.36","@tiptap/extension-link": "^2.0.0-beta.43",@@ -4013,18 +4012,6 @@"@tiptap/core": "^2.0.0-beta.1"}},- "node_modules/@tiptap/extension-highlight": {- "version": "2.0.0-beta.35",- "resolved": "https://registry.npmjs.org/@tiptap/extension-highlight/-/extension-highlight-2.0.0-beta.35.tgz",- "integrity": "sha512-xvEKOyuTj4mhQ8GIOItaSymJhGkWt2gGuCvmFWnTVZAaJJQOlgUTdkmayLCtwoDDP7biiuDhRJokTukGGmhUZw==",- "funding": {- "type": "github",- "url": "https://github.com/sponsors/ueberdosis"- },- "peerDependencies": {- "@tiptap/core": "^2.0.0-beta.1"- }- },"node_modules/@tiptap/extension-history": {"version": "2.0.0-beta.26","resolved": "https://registry.npmjs.org/@tiptap/extension-history/-/extension-history-2.0.0-beta.26.tgz",@@ -28225,12 +28212,6 @@"integrity": "sha512-q92jYcsT5bPhvuQaB0h44Z9r+Ii22tDYo082KMVnR4+tknHT/3xx+p4JC8KHjh+/5W8Quyafqy6mS8L8VX0zsQ==","requires": {}},- "@tiptap/extension-highlight": {- "version": "2.0.0-beta.35",- "resolved": "https://registry.npmjs.org/@tiptap/extension-highlight/-/extension-highlight-2.0.0-beta.35.tgz",- "integrity": "sha512-xvEKOyuTj4mhQ8GIOItaSymJhGkWt2gGuCvmFWnTVZAaJJQOlgUTdkmayLCtwoDDP7biiuDhRJokTukGGmhUZw==",- "requires": {}- },"@tiptap/extension-history": {"version": "2.0.0-beta.26","resolved": "https://registry.npmjs.org/@tiptap/extension-history/-/extension-history-2.0.0-beta.26.tgz",diff --git a/packages/editor/package.json b/packages/editor/package.jsonindex 8bc0c0194..6052068b2 100644--- a/packages/editor/package.json+++ b/packages/editor/package.json@@ -17,7 +17,6 @@"@tiptap/extension-character-count": "^2.0.0-beta.31","@tiptap/extension-color": "^2.0.0-beta.12","@tiptap/extension-font-family": "^2.0.0-beta.24",- "@tiptap/extension-highlight": "^2.0.0-beta.35","@tiptap/extension-history": "^2.0.0-beta.26","@tiptap/extension-horizontal-rule": "^2.0.0-beta.36","@tiptap/extension-link": "^2.0.0-beta.43",@@ -52,6 +51,7 @@"zustand": "^3.7.2"},"devDependencies": {+ "@streetwriters/theme": "1.0.0","@types/katex": "^0.14.0","@types/prismjs": "^1.26.0","@types/react": "^17.0.37",@@ -68,8 +68,7 @@"ts-node": "^10.8.1","typescript": "^4.7.4","typescript-plugin-css-modules": "^3.4.0",- "web-vitals": "^2.1.4",- "@streetwriters/theme": "1.0.0"+ "web-vitals": "^2.1.4"},"peerDependencies": {"framer-motion": "^4.1.17"diff --git a/packages/editor/src/extensions/highlight/highlight.ts b/packages/editor/src/extensions/highlight/highlight.tsnew file mode 100644index 000000000..71fcf1da0--- /dev/null+++ b/packages/editor/src/extensions/highlight/highlight.ts@@ -0,0 +1,90 @@+import "@tiptap/extension-text-style";+import { Extension } from "@tiptap/core";++export interface HighlightOptions {+ types: string[];+ HTMLAttributes: Record<string, any>;+}++declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ highlight: {+ /**+ * Set a highlight mark+ */+ setHighlight: (backgroundColor: string) => ReturnType;+ /**+ * Toggle a highlight mark+ */+ toggleHighlight: (backgroundColor: string) => ReturnType;+ /**+ * Unset a highlight mark+ */+ unsetHighlight: () => ReturnType;+ };+ }+}++export const Highlight = Extension.create<HighlightOptions>({+ name: "highlight",++ addOptions() {+ return {+ types: ["textStyle"],+ HTMLAttributes: {},+ };+ },++ addGlobalAttributes() {+ return [+ {+ types: this.options.types,+ attributes: {+ backgroundColor: {+ default: null,+ parseHTML: (element) =>+ element.style.backgroundColor?.replace(/['"]+/g, ""),+ renderHTML: (attributes) => {+ if (!attributes.backgroundColor) {+ return {};+ }++ return {+ style: `background-color: ${attributes.backgroundColor}`,+ };+ },+ },+ },+ },+ ];+ },++ addCommands() {+ return {+ setHighlight:+ (backgroundColor) =>+ ({ commands }) => {+ return commands.setMark("textStyle", { backgroundColor });+ },+ toggleHighlight:+ (backgroundColor) =>+ ({ commands }) => {+ return commands.toggleMark("textStyle", { backgroundColor });+ },+ unsetHighlight:+ () =>+ ({ chain }) => {+ return chain()+ .setMark("textStyle", { backgroundColor: null })+ .removeEmptyTextStyle()+ .run();+ },+ };+ },++ // addKeyboardShortcuts() {+ // return {+ // "Mod-Shift-h": () => this.editor.commands.toggleHighlight(),+ // };+ // },+});diff --git a/packages/editor/src/extensions/highlight/index.ts b/packages/editor/src/extensions/highlight/index.tsnew file mode 100644index 000000000..d90b37cc0--- /dev/null+++ b/packages/editor/src/extensions/highlight/index.ts@@ -0,0 +1 @@+export * from "./highlight";diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.tsindex a167da614..fbc608233 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -15,7 +15,6 @@ import TextStyle from "@tiptap/extension-text-style";import FontFamily from "@tiptap/extension-font-family";import BulletList from "./extensions/bullet-list";import OrderedList from "./extensions/ordered-list";-import Highlight from "@tiptap/extension-highlight";import Color from "@tiptap/extension-color";import TableRow from "@tiptap/extension-table-row";import TableCell from "./extensions/table-cell";@@ -46,6 +45,7 @@ import { useToolbarStore } from "./toolbar/stores/toolbar-store";import { useEditor } from "./hooks/use-editor";import { EditorOptions } from "@tiptap/core";import { usePermissionHandler } from "./hooks/use-permission-handler";+import { Highlight } from "./extensions/highlight";EditorView.prototype.updateState = function updateState(state) {if (!(this as any).docView) return; // This prevents the matchesNode error on hot reloads@@ -119,9 +119,7 @@ const useTiptap = (TableRow,TableCell,TableHeader,- Highlight.configure({- multicolor: true,- }),+ Highlight,CodeBlock,Color,TextAlign.configure({diff --git a/packages/editor/src/toolbar/components/split-button.tsx b/packages/editor/src/toolbar/components/split-button.tsxindex 889770fb2..19de10207 100644--- a/packages/editor/src/toolbar/components/split-button.tsx+++ b/packages/editor/src/toolbar/components/split-button.tsx@@ -14,7 +14,7 @@ import React from "react";export type SplitButtonProps = ToolButtonProps & { onOpen: () => void };function _SplitButton(props: PropsWithChildren<SplitButtonProps>) {- const { children, toggled, onOpen, ...toolButtonProps } = props;+ const { children, toggled, onOpen, sx, ...toolButtonProps } = props;const ref = useRef<HTMLDivElement>(null);const toolbarLocation = useToolbarLocation();@@ -29,7 +29,7 @@ function _SplitButton(props: PropsWithChildren<SplitButtonProps>) {><ToolButton{...toolButtonProps}- sx={{ mr: 0, ":hover": { bg: "hover" } }}+ sx={{ mr: 0, ":hover": { bg: "hover" }, ...sx }}toggled={false}/><Buttondiff --git a/packages/editor/src/toolbar/tools/colors.tsx b/packages/editor/src/toolbar/tools/colors.tsxindex 68de52fa0..5fabc3713 100644--- a/packages/editor/src/toolbar/tools/colors.tsx+++ b/packages/editor/src/toolbar/tools/colors.tsx@@ -10,7 +10,7 @@ import { getToolbarElement } from "../utils/dom";type ColorToolProps = ToolProps & {onColorChange: (color?: string) => void;- getActiveColor: () => string;+ activeColor: string;title: string;cacheKey: string;};@@ -19,12 +19,12 @@ export function ColorTool(props: ColorToolProps) {const {editor,onColorChange,- getActiveColor,+ activeColor: _activeColor,title,cacheKey,...toolProps} = props;- const activeColor = getActiveColor() || config.get(cacheKey);+ const activeColor = _activeColor || config.get(cacheKey);const tColor = tinycolor(activeColor);const isBottom = useToolbarLocation() === "bottom";const [isOpen, setIsOpen] = useState<boolean>(false);@@ -79,16 +79,15 @@ export function ColorTool(props: ColorToolProps) {export function Highlight(props: ToolProps) {const { editor } = props;-return (<ColorTool{...props}cacheKey="highlight"- getActiveColor={() => editor.current?.getAttributes("highlight").color}+ activeColor={editor.getAttributes("textStyle").backgroundColor}title={"Background color"}onColorChange={(color) =>color- ? editor.current?.chain().focus().toggleHighlight({ color }).run()+ ? editor.current?.chain().focus().setHighlight(color).run(): editor.current?.chain().focus().unsetHighlight().run()}/>@@ -101,7 +100,7 @@ export function TextColor(props: ToolProps) {<ColorTool{...props}cacheKey={"textColor"}- getActiveColor={() => editor.current?.getAttributes("textStyle").color}+ activeColor={editor.getAttributes("textStyle").color}title="Text color"onColorChange={(color) =>colordiff --git a/packages/editor/src/toolbar/tools/table.tsx b/packages/editor/src/toolbar/tools/table.tsxindex 0d4e9a94b..0aeacd8dd 100644--- a/packages/editor/src/toolbar/tools/table.tsx+++ b/packages/editor/src/toolbar/tools/table.tsx@@ -202,9 +202,7 @@ export function CellBackgroundColor(props: ToolProps) {<ColorTool{...props}cacheKey="cellBackgroundColor"- getActiveColor={() =>- editor.current?.getAttributes("tableCell").backgroundColor- }+ activeColor={editor.current?.getAttributes("tableCell").backgroundColor}title={"Cell background color"}onColorChange={(color) =>editor.current?.chain().setCellAttribute("backgroundColor", color).run()@@ -220,7 +218,7 @@ export function CellTextColor(props: ToolProps) {<ColorTool{...props}cacheKey="cellTextColor"- getActiveColor={() => editor.current?.getAttributes("tableCell").color}+ activeColor={editor.current?.getAttributes("tableCell").color}title={"Cell text color"}onColorChange={(color) =>editor.current?.chain().focus().setCellAttribute("color", color).run()@@ -236,9 +234,7 @@ export function CellBorderColor(props: ToolProps) {<ColorTool{...props}cacheKey="cellBorderColor"- getActiveColor={() =>- editor.current?.getAttributes("tableCell").borderColor- }+ activeColor={editor.current?.getAttributes("tableCell").borderColor}title={"Cell border color"}onColorChange={(color) =>editor.current