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: make cell properties functional
thecodrr3655f3c8616c
diff --git a/packages/editor/dist/toolbar/components/toolbutton.d.ts b/packages/editor/dist/toolbar/components/toolbutton.d.tsindex 2cde85f8c..87d56acaf 100644--- a/packages/editor/dist/toolbar/components/toolbutton.d.ts+++ b/packages/editor/dist/toolbar/components/toolbutton.d.ts@@ -14,8 +14,8 @@ export declare type ToolButtonProps = ButtonProps & {};export declare const ToolButton: React.NamedExoticComponent<ButtonProps & {icon: IconNames;- iconColor?: "background" | "border" | "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "icon" | "overlay" | "hover" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "fontSecondary" | "fontTertiary" | "secondary" | undefined;- iconSize?: number | "small" | "big" | "medium" | undefined;+ iconColor?: "icon" | "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "background" | "border" | "overlay" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "hover" | "fontSecondary" | "fontTertiary" | "secondary" | undefined;+ iconSize?: number | "big" | "small" | "medium" | undefined;toggled: boolean;buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined> | undefined;variant?: ToolButtonVariant | undefined;diff --git a/packages/editor/dist/toolbar/popups/cellproperties.d.ts b/packages/editor/dist/toolbar/popups/cellproperties.d.tsindex d116c136d..7c0de5a61 100644--- a/packages/editor/dist/toolbar/popups/cellproperties.d.ts+++ b/packages/editor/dist/toolbar/popups/cellproperties.d.ts@@ -1,5 +1,5 @@/// <reference types="react" />-import { Editor } from "@tiptap/core";+import { Editor } from "../../types";declare type CellPropertiesProps = {editor: Editor;onClose: () => void;diff --git a/packages/editor/dist/toolbar/popups/cellproperties.js b/packages/editor/dist/toolbar/popups/cellproperties.jsindex 9a81a6fb6..c585ad979 100644--- a/packages/editor/dist/toolbar/popups/cellproperties.js+++ b/packages/editor/dist/toolbar/popups/cellproperties.js@@ -9,54 +9,25 @@ var __assign = (this && this.__assign) || function () {};return __assign.apply(this, arguments);};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";-import { useRef, useState } from "react";-import { Box, Flex, Text } from "rebass";+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Box } from "rebass";import { Tab, Tabs } from "../../components/tabs";import { Icon } from "../components/icon";// import { MenuPresenter } from "../../components/menu/menu";import { Popup } from "../components/popup";-import { ToolButton } from "../components/tool-button";import { Icons } from "../icons";import { ColorPicker } from "./color-picker";export function CellProperties(props) {var editor = props.editor, onClose = props.onClose;var attributes = editor.getAttributes("tableCell");return (_jsx(Popup, __assign({ title: "Cell properties", onClose: onClose }, { children: _jsxs(Tabs, __assign({ activeIndex: 0 }, { children: [_jsxs(Tab, __assign({ title: _jsx(Icon, { title: "Cell background color", path: Icons.backgroundColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.backgroundColor, onChange: function (color) {- return editor.commands.setCellAttribute("backgroundColor", color);+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", color);}, onClear: function () {- return editor.commands.setCellAttribute("backgroundColor", undefined);- } })] })), _jsxs(Tab, __assign({ title: _jsx(Icon, { title: "Cell text color", path: Icons.textColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.color, onChange: function (color) {- return editor.commands.setCellAttribute("color", color);- }, onClear: function () { return editor.commands.setCellAttribute("color", undefined); } })] })), _jsxs(Tab, __assign({ title: _jsx(Icon, { title: "Cell border color", path: Icons.cellBorderColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.borderColor, onChange: function (color) {- return editor.commands.setCellAttribute("borderColor", color);- }, onClear: function () {- return editor.commands.setCellAttribute("borderColor", undefined);+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", undefined);+ } })] })), _jsxs(Tab, __assign({ title: _jsx(Icon, { title: "Cell text color", path: Icons.textColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.color, onChange: function (color) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", color); }, onClear: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", undefined); } })] })), _jsxs(Tab, __assign({ title: _jsx(Icon, { title: "Cell border color", path: Icons.cellBorderColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.borderColor, onChange: function (color) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", color); }, onClear: function () {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", undefined);} })] }))] })) })));}-function ColorPickerTool(props) {- var color = props.color, title = props.title, icon = props.icon, onColorChange = props.onColorChange;- var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var buttonRef = useRef(null);- return (_jsx(_Fragment, { children: _jsxs(Flex, __assign({ sx: { justifyContent: "space-between", alignItems: "center", mt: 1 } }, { children: [_jsx(Text, __assign({ variant: "body" }, { children: title })), _jsx(ToolButton, { buttonRef: buttonRef, toggled: isOpen, title: title, id: icon, icon: icon, variant: "small", sx: {- borderRadius: "small",- backgroundColor: color || "transparent",- ":hover": { bg: color, filter: "brightness(90%)" },- }, onClick: function () { return setIsOpen(true); } })] })) }));-}diff --git a/packages/editor/dist/toolbar/popups/colorpicker.js b/packages/editor/dist/toolbar/popups/colorpicker.jsindex 1108224c8..cad405dec 100644--- a/packages/editor/dist/toolbar/popups/colorpicker.js+++ b/packages/editor/dist/toolbar/popups/colorpicker.js@@ -30,10 +30,11 @@ import { Box, Flex, Text } from "rebass";import { Input } from "@rebass/forms";import { Icon } from "../components/icon";import { Icons } from "../icons";-import { useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import tinycolor from "tinycolor2";import { HexColorPicker } from "react-colorful";import { Button } from "../../components/button";+import { debounce } from "../../utils/debounce";export var DEFAULT_COLORS = ["#e91e63","#9c27b0",@@ -63,6 +64,9 @@ export function ColorPicker(props) {if (isPickerOpen)ref.current.focus({ preventScroll: true });}, [isPickerOpen]);+ var onColorChange = useCallback(debounce(function (color) {+ onChange(color);+ }, 500), [onChange]);return (_jsxs(Flex, __assign({ ref: ref, tabIndex: -1, sx: {bg: "background",flexDirection: "column",@@ -82,7 +86,10 @@ export function ColorPicker(props) {pb: isPickerOpen ? 2 : 0,//pb: 0,alignItems: "center",- }, onClick: onClose }, { children: [_jsx(Text, __assign({ variant: "title" }, { children: title })), _jsx(Button, __assign({ variant: "icon", sx: { p: 0 } }, { children: _jsx(Icon, { path: Icons.close, size: "big" }) }))] }))), isPickerOpen ? (_jsxs(_Fragment, { children: [_jsx(HexColorPicker, { onChange: function (color) { return setCurrentColor(color); }, onTouchEnd: function () { return onChange(currentColor); }, onMouseUp: function () { return onChange(currentColor); } }), _jsx(Input, { variant: "clean", placeholder: "#000000", spellCheck: false, sx: {+ }, onClick: onClose }, { children: [_jsx(Text, __assign({ variant: "title" }, { children: title })), _jsx(Button, __assign({ variant: "icon", sx: { p: 0 } }, { children: _jsx(Icon, { path: Icons.close, size: "big" }) }))] }))), isPickerOpen ? (_jsxs(_Fragment, { children: [_jsx(HexColorPicker, { onChange: function (color) {+ setCurrentColor(color);+ onColorChange(color);+ }, onTouchEnd: function () { return onChange(currentColor); }, onMouseUp: function () { return onChange(currentColor); } }), _jsx(Input, { variant: "clean", placeholder: "#000000", spellCheck: false, sx: {my: 2,p: 0,borderRadius: 0,diff --git a/packages/editor/dist/toolbar/tools/table.js b/packages/editor/dist/toolbar/tools/table.jsindex fd3dedd0d..fcf345de9 100644--- a/packages/editor/dist/toolbar/tools/table.js+++ b/packages/editor/dist/toolbar/tools/table.js@@ -153,10 +153,12 @@ export function CellBorderWidth(props) {return Math.min(10, borderWidth + 1);}, [borderWidth]);return (_jsxs(Flex, __assign({ sx: { justifyContent: "center", alignItems: "center" } }, { children: [_jsx(Text, __assign({ variant: "subBody", sx: { mx: 1 } }, { children: "Border width:" })), _jsx(Counter, { title: "cell border width", onDecrease: function () {- return editor.commands.setCellAttribute("borderWidth", decreaseBorderWidth());+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", decreaseBorderWidth());}, onIncrease: function () {- return editor.commands.setCellAttribute("borderWidth", increaseBorderWidth());- }, onReset: function () { return editor.commands.setCellAttribute("borderWidth", 1); }, value: borderWidth + "px" })] })));+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", increaseBorderWidth());+ }, onReset: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", 1); }, value: borderWidth + "px" })] })));}var insertColumnLeft = function (editor) { return (__assign(__assign({}, getToolDefinition("insertColumnLeft")), { key: "addColumnLeft", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnBefore().run(); } })); };var insertColumnRight = function (editor) { return (__assign(__assign({}, getToolDefinition("insertColumnRight")), { key: "addColumnRight", type: "button", title: "Add column right", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnAfter().run(); }, icon: "insertColumnRight" })); };diff --git a/packages/editor/src/toolbar/popups/cell-properties.tsx b/packages/editor/src/toolbar/popups/cell-properties.tsxindex bbe9fb5e6..b97b6e1de 100644--- a/packages/editor/src/toolbar/popups/cell-properties.tsx+++ b/packages/editor/src/toolbar/popups/cell-properties.tsx@@ -1,5 +1,5 @@import { Slider } from "@rebass/forms";-import { Editor } from "@tiptap/core";+import { Editor } from "../../types";import { useRef, useState } from "react";import { Box, Flex, Text } from "rebass";import { Tab, Tabs } from "../../components/tabs";@@ -32,10 +32,16 @@ export function CellProperties(props: CellPropertiesProps) {expanded={true}color={attributes.backgroundColor}onChange={(color) =>- editor.commands.setCellAttribute("backgroundColor", color)+ editor.current?.commands.setCellAttribute(+ "backgroundColor",+ color+ )}onClear={() =>- editor.commands.setCellAttribute("backgroundColor", undefined)+ editor.current?.commands.setCellAttribute(+ "backgroundColor",+ undefined+ )}/></Tab>@@ -49,9 +55,11 @@ export function CellProperties(props: CellPropertiesProps) {expanded={true}color={attributes.color}onChange={(color) =>- editor.commands.setCellAttribute("color", color)+ editor.current?.commands.setCellAttribute("color", color)+ }+ onClear={() =>+ editor.current?.commands.setCellAttribute("color", undefined)}- onClear={() => editor.commands.setCellAttribute("color", undefined)}/></Tab><Tab@@ -68,122 +76,17 @@ export function CellProperties(props: CellPropertiesProps) {expanded={true}color={attributes.borderColor}onChange={(color) =>- editor.commands.setCellAttribute("borderColor", color)+ editor.current?.commands.setCellAttribute("borderColor", color)}onClear={() =>- editor.commands.setCellAttribute("borderColor", undefined)+ editor.current?.commands.setCellAttribute(+ "borderColor",+ undefined+ )}/></Tab></Tabs>- {/* <Flex sx={{ flexDirection: "column", px: 1, mb: 2 }}>- <ColorPickerTool- color={attributes.backgroundColor}- title="Background color"- icon="backgroundColor"- onColorChange={(color) =>- editor.commands.setCellAttribute("backgroundColor", color)- }- />- <ColorPickerTool- color={attributes.color}- title="Text color"- icon="textColor"- onColorChange={(color) =>- editor.commands.setCellAttribute("color", color)- }- />- <ColorPickerTool- color={attributes.borderColor}- title="Border color"- icon="borderColor"- onColorChange={(color) =>- editor.commands.setCellAttribute("borderColor", color)- }- />- <Flex sx={{ flexDirection: "column" }}>- <Flex- sx={{- justifyContent: "space-between",- alignItems: "center",- mt: 1,- }}- >- <Text variant={"body"}>Border width</Text>- <Text variant={"body"}>{attributes.borderWidth || 1}px</Text>- </Flex>- </Flex>- </Flex> */}</Popup>);}-type ColorPickerToolProps = {- color: string;- title: string;- icon: IconNames;- onColorChange: (color?: string) => void;-};-function ColorPickerTool(props: ColorPickerToolProps) {- const { color, title, icon, onColorChange } = props;- const [isOpen, setIsOpen] = useState(false);- const buttonRef = useRef<HTMLButtonElement>(null);-- return (- <>- <Flex- sx={{ justifyContent: "space-between", alignItems: "center", mt: 1 }}- >- <Text variant={"body"}>{title}</Text>- <ToolButton- buttonRef={buttonRef}- toggled={isOpen}- title={title}- id={icon}- icon={icon}- variant="small"- sx={{- borderRadius: "small",- backgroundColor: color || "transparent",- ":hover": { bg: color, filter: "brightness(90%)" },- }}- onClick={() => setIsOpen(true)}- />- </Flex>-- {/* <MenuPresenter- isOpen={isOpen}- onClose={() => setIsOpen(false)}- items={[]}- options={{- type: "menu",- position: {- target: buttonRef.current || undefined,- location: "below",- align: "center",- isTargetAbsolute: true,- yOffset: 5,- },- }}- >- <Flex- sx={{- flexDirection: "column",- bg: "background",- boxShadow: "menu",- border: "1px solid var(--border)",- borderRadius: "default",- p: 1,- width: 160,- }}- >- {/* <ColorPicker- colors={DEFAULT_COLORS}- color={color}- onClear={() => onColorChange()}- onChange={(color) => onColorChange(color)}- />- </Flex>- </MenuPresenter> */}- </>- );-}diff --git a/packages/editor/src/toolbar/popups/color-picker.tsx b/packages/editor/src/toolbar/popups/color-picker.tsxindex 1ee46e01b..89e09b4bc 100644--- a/packages/editor/src/toolbar/popups/color-picker.tsx+++ b/packages/editor/src/toolbar/popups/color-picker.tsx@@ -2,7 +2,7 @@ import { Box, Flex, Text } from "rebass";import { Input } from "@rebass/forms";import { Icon } from "../components/icon";import { Icons } from "../icons";-import { useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import tinycolor from "tinycolor2";import { HexColorPicker } from "react-colorful";import { Button } from "../../components/button";@@ -56,6 +56,13 @@ export function ColorPicker(props: ColorPickerProps) {if (isPickerOpen) ref.current.focus({ preventScroll: true });}, [isPickerOpen]);+ const onColorChange = useCallback(+ debounce((color: string) => {+ onChange(color);+ }, 500),+ [onChange]+ );+return (<Flexref={ref}@@ -96,7 +103,10 @@ export function ColorPicker(props: ColorPickerProps) {{isPickerOpen ? (<><HexColorPicker- onChange={(color) => setCurrentColor(color)}+ onChange={(color) => {+ setCurrentColor(color);+ onColorChange(color);+ }}onTouchEnd={() => onChange(currentColor)}onMouseUp={() => onChange(currentColor)}/>diff --git a/packages/editor/src/toolbar/tools/table.tsx b/packages/editor/src/toolbar/tools/table.tsxindex 5b652607e..d735c71e4 100644--- a/packages/editor/src/toolbar/tools/table.tsx+++ b/packages/editor/src/toolbar/tools/table.tsx@@ -272,12 +272,20 @@ export function CellBorderWidth(props: ToolProps) {<Countertitle="cell border width"onDecrease={() =>- editor.commands.setCellAttribute("borderWidth", decreaseBorderWidth())+ editor.current?.commands.setCellAttribute(+ "borderWidth",+ decreaseBorderWidth()+ )}onIncrease={() =>- editor.commands.setCellAttribute("borderWidth", increaseBorderWidth())+ editor.current?.commands.setCellAttribute(+ "borderWidth",+ increaseBorderWidth()+ )+ }+ onReset={() =>+ editor.current?.commands.setCellAttribute("borderWidth", 1)}- onReset={() => editor.commands.setCellAttribute("borderWidth", 1)}value={borderWidth + "px"}/></Flex>