Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add take photo using camera button for mobile

thecodrrb577f7385fb2
diff --git a/packages/editor/dist/components/actionsheet/index.js b/packages/editor/dist/components/actionsheet/index.js
index ee5e4f98e..ea4b031ae 100644
--- a/packages/editor/dist/components/actionsheet/index.js
+++ b/packages/editor/dist/components/actionsheet/index.js
@@ -177,6 +177,8 @@ function ContentContainer(props) {
return (_jsxs(Flex, __assign({ sx: { flexDirection: "column" } }, { children: [canGoBack || (current === null || current === void 0 ? void 0 : current.title) ? (_jsxs(Flex, __assign({ id: "header", sx: { alignItems: "center", mx: 0, mb: 1 } }, { children: [canGoBack && (_jsx(Button, __assign({ variant: "icon", sx: { p: 1, ml: 1 }, onClick: goBack }, { children: _jsx(Icon, { path: Icons.arrowLeft, size: "big" }) }))), (current === null || current === void 0 ? void 0 : current.title) && (_jsx(Text, __assign({ variant: "title", sx: { ml: 1, fontSize: "title" } }, { children: current === null || current === void 0 ? void 0 : current.title })))] }))) : null, children
? children
: (_a = current === null || current === void 0 ? void 0 : current.items) === null || _a === void 0 ? void 0 : _a.map(function (item) {
+ if (item.isHidden)
+ return null;
switch (item.type) {
case "separator":
return _jsx(MenuSeparator, {}, item.key);
diff --git a/packages/editor/dist/components/menu/index.js b/packages/editor/dist/components/menu/index.js
index 47d62bca8..9ab865fe3 100644
--- a/packages/editor/dist/components/menu/index.js
+++ b/packages/editor/dist/components/menu/index.js
@@ -67,6 +67,8 @@ export function Menu(props) {
subMenuRef.current.style.left = "".concat(left, "px");
}, [isSubmenuOpen, focusIndex, items]);
return (_jsxs(_Fragment, { children: [_jsx(MenuContainer, __assign({}, containerProps, { children: items.map(function (item, index) {
+ if (item.isHidden)
+ return null;
switch (item.type) {
case "separator":
return _jsx(MenuSeparator, {}, item.key);
diff --git a/packages/editor/dist/extensions/attachment/attachment.d.ts b/packages/editor/dist/extensions/attachment/attachment.d.ts
index 071d35323..cd34695f5 100644
--- a/packages/editor/dist/extensions/attachment/attachment.d.ts
+++ b/packages/editor/dist/extensions/attachment/attachment.d.ts
@@ -1,6 +1,6 @@
import { Node, Editor } from "@tiptap/core";
import { Attribute } from "@tiptap/core";
-export declare type AttachmentType = "image" | "file";
+export declare type AttachmentType = "image" | "file" | "camera";
export interface AttachmentOptions {
HTMLAttributes: Record<string, any>;
onDownloadAttachment: (editor: Editor, attachment: Attachment) => boolean;
diff --git a/packages/editor/dist/toolbar/components/toolbutton.d.ts b/packages/editor/dist/toolbar/components/toolbutton.d.ts
index debe4afa8..2cde85f8c 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?: "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "background" | "border" | "overlay" | "icon" | "hover" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "fontSecondary" | "fontTertiary" | "secondary" | undefined;
- iconSize?: number | "big" | "small" | "medium" | undefined;
+ 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;
toggled: boolean;
buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined> | undefined;
variant?: ToolButtonVariant | undefined;
diff --git a/packages/editor/dist/toolbar/icons.d.ts b/packages/editor/dist/toolbar/icons.d.ts
index f5147bf49..934932c6b 100644
--- a/packages/editor/dist/toolbar/icons.d.ts
+++ b/packages/editor/dist/toolbar/icons.d.ts
@@ -35,6 +35,7 @@ export declare const Icons: {
loading: string;
more: string;
upload: string;
+ camera: string;
attachment: string;
table: string;
rowProperties: string;
diff --git a/packages/editor/dist/toolbar/icons.js b/packages/editor/dist/toolbar/icons.js
index 7a9147fe4..6a8332195 100644
--- a/packages/editor/dist/toolbar/icons.js
+++ b/packages/editor/dist/toolbar/icons.js
@@ -1,4 +1,4 @@
-import { mdiAttachment, mdiBorderHorizontal, mdiCheck, mdiChevronDown, mdiCodeBraces, mdiCodeTags, mdiDotsVertical, mdiFormatAlignCenter, mdiFormatAlignJustify, mdiFormatAlignLeft, mdiFormatAlignRight, mdiFormatBold, mdiFormatClear, mdiFormatColorHighlight, mdiFormatColorText, mdiFormatItalic, mdiFormatListBulleted, mdiFormatListNumbered, mdiFormatQuoteClose, mdiFormatStrikethrough, mdiFormatSubscript, mdiFormatSuperscript, mdiFormatTextdirectionLToR, mdiFormatTextdirectionRToL, mdiFormatUnderline, mdiImage, mdiInvertColorsOff, mdiLinkPlus, mdiLoading, mdiTable, mdiTableBorder, mdiTableRowPlusAfter, mdiTableRowPlusBefore, mdiTableRowRemove, mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiFormatColorFill, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, mdiTableMergeCells, mdiTableSplitCell, mdiDeleteOutline, mdiDownloadOutline, mdiFormatListCheckbox, mdiDrag, mdiCheckboxMarkedOutline, mdiChevronUp, mdiArrowUp, mdiArrowDown, mdiRegex, mdiFormatLetterCase, mdiFormatLetterMatches, mdiMoviePlusOutline, mdiLink, mdiChevronRight, mdiTableColumnWidth, mdiTableRowHeight, mdiMinus, mdiPaletteOutline, mdiCircle, mdiChevronLeft, mdiTableCog, mdiTableOff, mdiRectangle, mdiImageEditOutline, mdiArrowLeft, mdiMovieCogOutline, mdiLinkOff, mdiOpenInNew, } from "@mdi/js";
+import { mdiAttachment, mdiBorderHorizontal, mdiCheck, mdiChevronDown, mdiCodeBraces, mdiCodeTags, mdiDotsVertical, mdiFormatAlignCenter, mdiFormatAlignJustify, mdiFormatAlignLeft, mdiFormatAlignRight, mdiFormatBold, mdiFormatClear, mdiFormatColorHighlight, mdiFormatColorText, mdiFormatItalic, mdiFormatListBulleted, mdiFormatListNumbered, mdiFormatQuoteClose, mdiFormatStrikethrough, mdiFormatSubscript, mdiFormatSuperscript, mdiFormatTextdirectionLToR, mdiFormatTextdirectionRToL, mdiFormatUnderline, mdiImage, mdiInvertColorsOff, mdiLinkPlus, mdiLoading, mdiTable, mdiTableBorder, mdiTableRowPlusAfter, mdiTableRowPlusBefore, mdiTableRowRemove, mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiFormatColorFill, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, mdiTableMergeCells, mdiTableSplitCell, mdiDeleteOutline, mdiDownloadOutline, mdiFormatListCheckbox, mdiDrag, mdiCheckboxMarkedOutline, mdiChevronUp, mdiArrowUp, mdiArrowDown, mdiRegex, mdiFormatLetterCase, mdiFormatLetterMatches, mdiMoviePlusOutline, mdiLink, mdiChevronRight, mdiTableColumnWidth, mdiTableRowHeight, mdiMinus, mdiPaletteOutline, mdiCircle, mdiChevronLeft, mdiTableCog, mdiTableOff, mdiRectangle, mdiImageEditOutline, mdiArrowLeft, mdiMovieCogOutline, mdiLinkOff, mdiOpenInNew, mdiCameraOutline, } from "@mdi/js";
export var Icons = {
bold: mdiFormatBold,
italic: mdiFormatItalic,
@@ -36,6 +36,7 @@ export var Icons = {
loading: mdiLoading,
more: mdiDotsVertical,
upload: mdiUploadOutline,
+ camera: mdiCameraOutline,
attachment: mdiAttachment,
table: mdiTable,
rowProperties: mdiTableRowHeight,
diff --git a/packages/editor/dist/toolbar/tools/block.js b/packages/editor/dist/toolbar/tools/block.js
index 202ac1b2b..04fa65cd6 100644
--- a/packages/editor/dist/toolbar/tools/block.js
+++ b/packages/editor/dist/toolbar/tools/block.js
@@ -111,6 +111,14 @@ var image = function (editor, isMobile) { return ({
icon: "upload",
onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("image").run(); },
},
+ {
+ key: "camera",
+ type: "button",
+ title: "Take a photo using camera",
+ icon: "camera",
+ isHidden: !isMobile,
+ onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("camera").run(); },
+ },
isMobile ? uploadImageFromURLMobile(editor) : uploadImageFromURL(editor),
],
},
diff --git a/packages/editor/src/components/action-sheet/index.tsx b/packages/editor/src/components/action-sheet/index.tsx
index e315e0e63..ec9f08071 100644
--- a/packages/editor/src/components/action-sheet/index.tsx
+++ b/packages/editor/src/components/action-sheet/index.tsx
@@ -295,6 +295,8 @@ function ContentContainer(props: PropsWithChildren<ContentContainerProps>) {
{children
? children
: current?.items?.map((item) => {
+ if (item.isHidden) return null;
+
switch (item.type) {
case "separator":
return <MenuSeparator key={item.key} />;
diff --git a/packages/editor/src/components/menu/index.tsx b/packages/editor/src/components/menu/index.tsx
index 69311a974..71bcd771e 100644
--- a/packages/editor/src/components/menu/index.tsx
+++ b/packages/editor/src/components/menu/index.tsx
@@ -74,6 +74,8 @@ export function Menu(props: MenuProps) {
<>
<MenuContainer {...containerProps}>
{items.map((item, index) => {
+ if (item.isHidden) return null;
+
switch (item.type) {
case "separator":
return <MenuSeparator key={item.key} />;
diff --git a/packages/editor/src/extensions/attachment/attachment.ts b/packages/editor/src/extensions/attachment/attachment.ts
index 6e65d5bd9..8f76d37e4 100644
--- a/packages/editor/src/extensions/attachment/attachment.ts
+++ b/packages/editor/src/extensions/attachment/attachment.ts
@@ -3,7 +3,7 @@ import { Attribute } from "@tiptap/core";
import { createNodeView, createSelectionBasedNodeView } from "../react";
import { AttachmentComponent } from "./component";
-export type AttachmentType = "image" | "file";
+export type AttachmentType = "image" | "file" | "camera";
export interface AttachmentOptions {
HTMLAttributes: Record<string, any>;
onDownloadAttachment: (editor: Editor, attachment: Attachment) => boolean;
diff --git a/packages/editor/src/toolbar/icons.ts b/packages/editor/src/toolbar/icons.ts
index bfe0e4b03..c87d18608 100644
--- a/packages/editor/src/toolbar/icons.ts
+++ b/packages/editor/src/toolbar/icons.ts
@@ -98,6 +98,7 @@ import {
mdiMovieCogOutline,
mdiLinkOff,
mdiOpenInNew,
+ mdiCameraOutline,
} from "@mdi/js";
export const Icons = {
@@ -140,6 +141,7 @@ export const Icons = {
loading: mdiLoading,
more: mdiDotsVertical,
upload: mdiUploadOutline,
+ camera: mdiCameraOutline,
attachment: mdiAttachment,
table: mdiTable,
rowProperties: mdiTableRowHeight,
diff --git a/packages/editor/src/toolbar/tools/block.tsx b/packages/editor/src/toolbar/tools/block.tsx
index c7862b041..1a4554e42 100644
--- a/packages/editor/src/toolbar/tools/block.tsx
+++ b/packages/editor/src/toolbar/tools/block.tsx
@@ -115,6 +115,15 @@ const image = (editor: Editor, isMobile: boolean): MenuItem => ({
onClick: () =>
editor.current?.chain().focus().openAttachmentPicker("image").run(),
},
+ {
+ key: "camera",
+ type: "button",
+ title: "Take a photo using camera",
+ icon: "camera",
+ isHidden: !isMobile,
+ onClick: () =>
+ editor.current?.chain().focus().openAttachmentPicker("camera").run(),
+ },
isMobile ? uploadImageFromURLMobile(editor) : uploadImageFromURL(editor),
],
},