Skip to content

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

refactor: move isMobile prop to useTiptap hook

thecodrr5c581a7792dd
diff --git a/packages/editor/dist/cjs/extensions/codeblock/codeblock.js b/packages/editor/dist/cjs/extensions/codeblock/codeblock.js
index c7e83230e..0c295b51e 100644
--- a/packages/editor/dist/cjs/extensions/codeblock/codeblock.js
+++ b/packages/editor/dist/cjs/extensions/codeblock/codeblock.js
@@ -172,8 +172,8 @@ exports.CodeBlock = core_2.Node.create({
if (!codeblock)
return false;
return editor.commands.setTextSelection({
- from: codeblock.pos,
- to: codeblock.pos + codeblock.node.nodeSize,
+ from: codeblock.pos + 1,
+ to: codeblock.pos + codeblock.node.nodeSize - 1,
});
},
// remove code block when at start of document or code block is empty
diff --git a/packages/editor/dist/cjs/extensions/codeblock/highlighter.js b/packages/editor/dist/cjs/extensions/codeblock/highlighter.js
index bcaeb260d..ead12449e 100644
--- a/packages/editor/dist/cjs/extensions/codeblock/highlighter.js
+++ b/packages/editor/dist/cjs/extensions/codeblock/highlighter.js
@@ -42,28 +42,7 @@ function getLineDecoration(from, line, total, isActive) {
total,
from,
};
- // Prosemirror has a selection issue with the widget decoration
- // on the first line. To work around that we use inline decoration
- // for the first line.
- if (line === 1 ||
- // Android Composition API (aka the virtual keyboard) doesn't behave well
- // with Decoration widgets so we have to resort to inline line numbers.
- isAndroid()) {
- return prosemirror_view_1.Decoration.inline(from, from + 1, attributes, spec);
- }
- return prosemirror_view_1.Decoration.widget(from, () => {
- const element = document.createElement("span");
- element.classList.add("line-number-widget");
- if (isActive)
- element.classList.add("active");
- element.innerHTML = attributes["data-line"];
- return element;
- }, Object.assign(Object.assign({}, spec), {
- // should rerender when any of these change:
- // 1. line number
- // 2. line active state
- // 3. the max length of all lines
- key: `${line}-${isActive ? "active" : ""}-${maxLength}` }));
+ return prosemirror_view_1.Decoration.inline(from, from + 1, attributes, spec);
}
function getDecorations({ doc, name, defaultLanguage, caretPosition, }) {
const decorations = [];
@@ -102,8 +81,12 @@ function HighlighterPlugin({ name, defaultLanguage, }) {
return new prosemirror_state_1.Plugin({
key,
state: {
- init: () => {
- return prosemirror_view_1.DecorationSet.empty;
+ init: (config, state) => {
+ return getDecorations({
+ doc: state.doc,
+ name,
+ defaultLanguage,
+ });
},
apply: (transaction, decorationSet, oldState, newState) => {
const oldNodeName = oldState.selection.$head.parent.type.name;
@@ -157,9 +140,10 @@ function HighlighterPlugin({ name, defaultLanguage, }) {
prevState.selection.$from.parent.type.name === name) &&
prevState.selection.$from.pos !== nextState.selection.$from.pos;
(0, core_1.findChildren)(nextState.doc, (node) => node.type.name === name).forEach((block) => {
+ var _a;
const { node, pos } = block;
const attributes = Object.assign({}, node.attrs);
- if (docChanged) {
+ if (docChanged || !((_a = attributes.lines) === null || _a === void 0 ? void 0 : _a.length)) {
const lines = (0, codeblock_1.toCodeLines)(node.textContent, pos);
attributes.lines = lines.slice();
}
diff --git a/packages/editor/dist/cjs/extensions/image/component.js b/packages/editor/dist/cjs/extensions/image/component.js
index 1bf6973b1..172555938 100644
--- a/packages/editor/dist/cjs/extensions/image/component.js
+++ b/packages/editor/dist/cjs/extensions/image/component.js
@@ -15,6 +15,8 @@ const rebass_1 = require("rebass");
const re_resizable_1 = require("re-resizable");
const react_1 = require("react");
const responsive_1 = require("../../components/responsive");
+const icon_1 = require("../../toolbar/components/icon");
+const icons_1 = require("../../toolbar/icons");
const toolbargroup_1 = require("../../toolbar/components/toolbargroup");
function ImageComponent(props) {
const { editor, updateAttributes, node, selected } = props;
@@ -59,34 +61,27 @@ function ImageComponent(props) {
width: ref.clientWidth,
height: ref.clientHeight,
});
- }, lockAspectRatio: true }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ width: "100%", "data-drag-handle": true, draggable: true, sx: {
- position: "relative",
- justifyContent: "end",
- borderTop: editor.isEditable
- ? "20px solid var(--bgSecondary)"
- : "none",
- borderTopLeftRadius: "default",
- borderTopRightRadius: "default",
- borderColor: selected ? "border" : "bgSecondary",
- cursor: "pointer",
- ":hover": {
- borderColor: "border",
- },
- } }, { children: (0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: { position: "relative", justifyContent: "end" } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {
- position: "absolute",
- top: -40,
- mb: 2,
- alignItems: "end",
- } }, { children: (0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { editor: editor, tools: [
- "imageAlignLeft",
- "imageAlignCenter",
- "imageAlignRight",
- "imageProperties",
- ], sx: {
- boxShadow: "menu",
- borderRadius: "default",
- bg: "background",
- } }) })) }))) }) })), (0, jsx_runtime_1.jsx)(rebass_1.Image, Object.assign({ "data-drag-image": true, ref: imageRef, alt: alt, src: "/placeholder.svg", title: title, width: "100%", height: "100%", sx: {
+ }, lockAspectRatio: true }, { children: [(0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: { position: "relative", justifyContent: "end" } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {
+ position: "absolute",
+ top: -40,
+ mb: 2,
+ alignItems: "end",
+ } }, { children: (0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { editor: editor, tools: [
+ "imageAlignLeft",
+ "imageAlignCenter",
+ "imageAlignRight",
+ "imageProperties",
+ ], sx: {
+ boxShadow: "menu",
+ borderRadius: "default",
+ bg: "background",
+ } }) })) }))) }), selected && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { className: "drag-handle", "data-drag-handle": true, draggable: true, path: icons_1.Icons.dragHandle, sx: {
+ cursor: "grab",
+ position: "absolute",
+ top: 2,
+ left: 2,
+ zIndex: 999,
+ } })), (0, jsx_runtime_1.jsx)(rebass_1.Image, Object.assign({ "data-drag-image": true, ref: imageRef, alt: alt, src: "/placeholder.svg", title: title, width: "100%", height: "100%", sx: {
bg: "bgSecondary",
border: selected
? "2px solid var(--primary)"
diff --git a/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.js b/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.js
index 737c5dc40..e14e62aba 100644
--- a/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.js
+++ b/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.js
@@ -44,7 +44,7 @@ exports.OutlineListItem = core_1.Node.create({
Enter: ({ editor }) => {
const subList = findSublist(editor, this.type);
if (!subList)
- return false;
+ return this.editor.commands.splitListItem(this.name);
const { isCollapsed, subListPos } = subList;
if (isCollapsed) {
return this.editor.commands.toggleOutlineCollapse(subListPos, false);
diff --git a/packages/editor/dist/cjs/hooks/useEditor.d.ts b/packages/editor/dist/cjs/hooks/useEditor.d.ts
index 9c4401648..407df0f3f 100644
--- a/packages/editor/dist/cjs/hooks/useEditor.d.ts
+++ b/packages/editor/dist/cjs/hooks/useEditor.d.ts
@@ -1,4 +1,4 @@
import { EditorOptions } from "@tiptap/core";
import { DependencyList } from "react";
import { Editor as EditorType } from "../types";
-export declare const useEditor: (options?: Partial<EditorOptions>, deps?: DependencyList) => EditorType;
+export declare const useEditor: (options?: Partial<EditorOptions>, deps?: DependencyList) => EditorType | null;
diff --git a/packages/editor/dist/cjs/hooks/useEditor.js b/packages/editor/dist/cjs/hooks/useEditor.js
index df6995466..e6fd34c98 100644
--- a/packages/editor/dist/cjs/hooks/useEditor.js
+++ b/packages/editor/dist/cjs/hooks/useEditor.js
@@ -10,6 +10,7 @@ function useForceUpdate() {
const useEditor = (options = {}, deps = []) => {
const [editor, setEditor] = (0, react_1.useState)(null);
const forceUpdate = useForceUpdate();
+ const editorRef = (0, react_1.useRef)(editor);
(0, react_1.useEffect)(() => {
let isMounted = true;
const instance = new core_1.Editor(options);
@@ -28,6 +29,27 @@ const useEditor = (options = {}, deps = []) => {
isMounted = false;
};
}, deps);
+ (0, react_1.useEffect)(() => {
+ editorRef.current = editor;
+ if (editor && !editor.current)
+ Object.defineProperty(editor, "current", {
+ get: () => editorRef.current,
+ });
+ }, [editor]);
+ (0, react_1.useEffect)(() => {
+ // this is required for the drag/drop to work properly
+ // in the editor.
+ function onDragEnter(event) {
+ if (!!(editor === null || editor === void 0 ? void 0 : editor.view.dragging)) {
+ event.preventDefault();
+ return true;
+ }
+ }
+ editor === null || editor === void 0 ? void 0 : editor.view.dom.addEventListener("dragenter", onDragEnter);
+ return () => {
+ editor === null || editor === void 0 ? void 0 : editor.view.dom.removeEventListener("dragenter", onDragEnter);
+ };
+ }, [editor === null || editor === void 0 ? void 0 : editor.view.dom]);
return editor;
};
exports.useEditor = useEditor;
diff --git a/packages/editor/dist/cjs/index.d.ts b/packages/editor/dist/cjs/index.d.ts
index cd47cb2da..a9204a864 100644
--- a/packages/editor/dist/cjs/index.d.ts
+++ b/packages/editor/dist/cjs/index.d.ts
@@ -1,12 +1,13 @@
-/// <reference types="react" />
import "./extensions";
import Toolbar from "./toolbar";
import { Theme } from "@notesnook/theme";
import { AttachmentOptions } from "./extensions/attachment";
import { EditorOptions } from "@tiptap/core";
-declare const useTiptap: (options?: Partial<EditorOptions & AttachmentOptions & {
+declare type TiptapOptions = EditorOptions & AttachmentOptions & {
theme: Theme;
-}>, deps?: import("react").DependencyList) => import("./types").Editor;
+ isMobile?: boolean;
+};
+declare const useTiptap: (options?: Partial<TiptapOptions>, deps?: import("react").DependencyList) => import("./types").Editor | null;
export { useTiptap, Toolbar };
export * from "./types";
export * from "./extensions/react";
diff --git a/packages/editor/dist/cjs/index.js b/packages/editor/dist/cjs/index.js
index 98787115b..ca77cb930 100644
--- a/packages/editor/dist/cjs/index.js
+++ b/packages/editor/dist/cjs/index.js
@@ -76,9 +76,9 @@ prosemirror_view_1.EditorView.prototype.updateState = function updateState(state
this.updateStateInner(state, this.state.plugins != state.plugins);
};
const useTiptap = (options = {}, deps = []) => {
- const { theme, onDownloadAttachment, onOpenAttachmentPicker } = options, restOptions = __rest(options, ["theme", "onDownloadAttachment", "onOpenAttachmentPicker"]);
+ const { theme, isMobile, onDownloadAttachment, onOpenAttachmentPicker } = options, restOptions = __rest(options, ["theme", "isMobile", "onDownloadAttachment", "onOpenAttachmentPicker"]);
const PortalProviderAPI = (0, react_2.usePortalProvider)();
- const isMobile = (0, toolbarstore_1.useIsMobile)();
+ const setIsMobile = (0, toolbarstore_1.useToolbarStore)((store) => store.setIsMobile);
const defaultOptions = (0, react_1.useMemo)(() => ({
extensions: [
react_2.NodeViewSelectionNotifier,
@@ -159,26 +159,9 @@ const useTiptap = (options = {}, deps = []) => {
isMobile,
]);
const editor = (0, useEditor_1.useEditor)(Object.assign(Object.assign({}, defaultOptions), restOptions), deps);
- const editorRef = (0, react_1.useRef)(editor);
(0, react_1.useEffect)(() => {
- editorRef.current = editor;
- if (editor && !editor.current)
- Object.defineProperty(editor, "current", {
- get: () => editorRef.current,
- });
- }, [editor]);
- (0, react_1.useEffect)(() => {
- function onDragEnter(event) {
- if (!!(editor === null || editor === void 0 ? void 0 : editor.view.dragging)) {
- event.preventDefault();
- return true;
- }
- }
- editor === null || editor === void 0 ? void 0 : editor.view.dom.addEventListener("dragenter", onDragEnter);
- return () => {
- editor === null || editor === void 0 ? void 0 : editor.view.dom.removeEventListener("dragenter", onDragEnter);
- };
- }, [editor === null || editor === void 0 ? void 0 : editor.view.dom]);
+ setIsMobile(isMobile || false);
+ }, [isMobile]);
return editor;
};
exports.useTiptap = useTiptap;
diff --git a/packages/editor/dist/cjs/toolbar/toolbar.d.ts b/packages/editor/dist/cjs/toolbar/toolbar.d.ts
index 29e9038aa..b156254da 100644
--- a/packages/editor/dist/cjs/toolbar/toolbar.d.ts
+++ b/packages/editor/dist/cjs/toolbar/toolbar.d.ts
@@ -7,7 +7,6 @@ declare type ToolbarProps = {
theme: Theme;
editor: Editor | null;
location: ToolbarLocation;
- isMobile?: boolean;
tools?: ToolbarDefinition;
};
export declare function Toolbar(props: ToolbarProps): JSX.Element | null;
diff --git a/packages/editor/dist/cjs/toolbar/toolbar.js b/packages/editor/dist/cjs/toolbar/toolbar.js
index 84ab58adc..43bd8c505 100644
--- a/packages/editor/dist/cjs/toolbar/toolbar.js
+++ b/packages/editor/dist/cjs/toolbar/toolbar.js
@@ -11,13 +11,11 @@ const toolbarstore_1 = require("./stores/toolbarstore");
const toolbargroup_1 = require("./components/toolbargroup");
const popuprenderer_1 = require("../components/popup-presenter/popuprenderer");
function Toolbar(props) {
- const { editor, theme, location, isMobile, tools = tooldefinitions_1.DEFAULT_TOOLS } = props;
- const setIsMobile = (0, toolbarstore_1.useToolbarStore)((store) => store.setIsMobile);
+ const { editor, theme, location, tools = tooldefinitions_1.DEFAULT_TOOLS } = props;
const setToolbarLocation = (0, toolbarstore_1.useToolbarStore)((store) => store.setToolbarLocation);
(0, react_1.useEffect)(() => {
- setIsMobile(isMobile || false);
setToolbarLocation(location);
- }, [isMobile, location]);
+ }, [location]);
if (!editor)
return null;
return ((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, Object.assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(popuprenderer_1.EditorContext.Provider, Object.assign({ value: editor }, { children: (0, jsx_runtime_1.jsxs)(popuprenderer_1.PopupRenderer, Object.assign({ editor: editor }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ className: "editor-toolbar", sx: { flexWrap: ["nowrap", "wrap"], overflowX: ["auto", "hidden"] } }, { children: tools.map((tools) => {
diff --git a/packages/editor/dist/cjs/toolbar/tools/font.js b/packages/editor/dist/cjs/toolbar/tools/font.js
index 614856edb..08bd77906 100644
--- a/packages/editor/dist/cjs/toolbar/tools/font.js
+++ b/packages/editor/dist/cjs/toolbar/tools/font.js
@@ -27,7 +27,7 @@ function FontSize(props) {
}
exports.FontSize = FontSize;
const fontFamilies = {
- System: "Open Sans",
+ Default: "Open Sans",
Serif: "serif",
Monospace: "monospace",
};
@@ -35,7 +35,7 @@ function FontFamily(props) {
var _a, _b;
const { editor } = props;
const currentFontFamily = ((_b = (_a = Object.entries(fontFamilies)
- .find(([key, value]) => editor.isActive("textStyle", { fontFamily: value }))) === null || _a === void 0 ? void 0 : _a.map((a) => a)) === null || _b === void 0 ? void 0 : _b.at(0)) || "System";
+ .find(([key, value]) => editor.isActive("textStyle", { fontFamily: value }))) === null || _a === void 0 ? void 0 : _a.map((a) => a)) === null || _b === void 0 ? void 0 : _b.at(0)) || "Default";
const items = (0, react_1.useMemo)(() => toMenuItems(editor, currentFontFamily), [currentFontFamily]);
return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { selectedItem: currentFontFamily, items: items, menuWidth: 130 }));
}
diff --git a/packages/editor/dist/cjs/toolbar/tools/link.js b/packages/editor/dist/cjs/toolbar/tools/link.js
index 2d55544a6..94dee753f 100644
--- a/packages/editor/dist/cjs/toolbar/tools/link.js
+++ b/packages/editor/dist/cjs/toolbar/tools/link.js
@@ -1,4 +1,15 @@
"use strict";
+var __rest = (this && this.__rest) || function (s, e) {
+ var t = {};
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
+ t[p] = s[p];
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
+ t[p[i]] = s[p[i]];
+ }
+ return t;
+};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenLink = exports.RemoveLink = exports.EditLink = exports.AddLink = exports.LinkSettings = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
@@ -101,12 +112,12 @@ function OpenLink(props) {
}
exports.OpenLink = OpenLink;
function LinkTool(props) {
- const { isEditing, onClick, onDone } = props;
+ const { isEditing, onClick, onDone } = props, toolProps = __rest(props, ["isEditing", "onClick", "onDone"]);
const buttonRef = (0, react_1.useRef)(null);
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
const [href, setHref] = (0, react_1.useState)();
const [text, setText] = (0, react_1.useState)();
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { buttonRef: buttonRef, onClick: () => {
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolProps, { buttonRef: buttonRef, onClick: () => {
const result = onClick();
if (!result)
return;
diff --git a/packages/editor/dist/es/index.d.ts b/packages/editor/dist/es/index.d.ts
index 0be27387d..a9204a864 100644
--- a/packages/editor/dist/es/index.d.ts
+++ b/packages/editor/dist/es/index.d.ts
@@ -3,9 +3,11 @@ import Toolbar from "./toolbar";
import { Theme } from "@notesnook/theme";
import { AttachmentOptions } from "./extensions/attachment";
import { EditorOptions } from "@tiptap/core";
-declare const useTiptap: (options?: Partial<EditorOptions & AttachmentOptions & {
+declare type TiptapOptions = EditorOptions & AttachmentOptions & {
theme: Theme;
-}>, deps?: import("react").DependencyList) => import("./types").Editor | null;
+ isMobile?: boolean;
+};
+declare const useTiptap: (options?: Partial<TiptapOptions>, deps?: import("react").DependencyList) => import("./types").Editor | null;
export { useTiptap, Toolbar };
export * from "./types";
export * from "./extensions/react";
diff --git a/packages/editor/dist/es/index.js b/packages/editor/dist/es/index.js
index e810f1c2f..32ee99f12 100644
--- a/packages/editor/dist/es/index.js
+++ b/packages/editor/dist/es/index.js
@@ -59,6 +59,7 @@ const useTiptap = (options = {}, deps = []) => {
const PortalProviderAPI = usePortalProvider();
const isMobile = useIsMobile();
const defaultOptions = useMemo(() => ({
+ // enableInputRules: ,
extensions: [
NodeViewSelectionNotifier,
SearchReplace,
diff --git a/packages/editor/dist/es/toolbar/toolbar.d.ts b/packages/editor/dist/es/toolbar/toolbar.d.ts
index 29e9038aa..b156254da 100644
--- a/packages/editor/dist/es/toolbar/toolbar.d.ts
+++ b/packages/editor/dist/es/toolbar/toolbar.d.ts
@@ -7,7 +7,6 @@ declare type ToolbarProps = {
theme: Theme;
editor: Editor | null;
location: ToolbarLocation;
- isMobile?: boolean;
tools?: ToolbarDefinition;
};
export declare function Toolbar(props: ToolbarProps): JSX.Element | null;
diff --git a/packages/editor/dist/es/toolbar/toolbar.js b/packages/editor/dist/es/toolbar/toolbar.js
index 64e10bf69..90250891f 100644
--- a/packages/editor/dist/es/toolbar/toolbar.js
+++ b/packages/editor/dist/es/toolbar/toolbar.js
@@ -8,13 +8,11 @@ import { useToolbarStore, } from "./stores/toolbar-store";
import { ToolbarGroup } from "./components/toolbar-group";
import { EditorContext, PopupRenderer, } from "../components/popup-presenter/popuprenderer";
export function Toolbar(props) {
- const { editor, theme, location, isMobile, tools = DEFAULT_TOOLS } = props;
- const setIsMobile = useToolbarStore((store) => store.setIsMobile);
+ const { editor, theme, location, tools = DEFAULT_TOOLS } = props;
const setToolbarLocation = useToolbarStore((store) => store.setToolbarLocation);
useEffect(() => {
- setIsMobile(isMobile || false);
setToolbarLocation(location);
- }, [isMobile, location]);
+ }, [location]);
if (!editor)
return null;
return (_jsx(ThemeProvider, Object.assign({ theme: theme }, { children: _jsx(EditorContext.Provider, Object.assign({ value: editor }, { children: _jsxs(PopupRenderer, Object.assign({ editor: editor }, { children: [_jsx(Flex, Object.assign({ className: "editor-toolbar", sx: { flexWrap: ["nowrap", "wrap"], overflowX: ["auto", "hidden"] } }, { children: tools.map((tools) => {
diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts
index dc12da397..35d516159 100644
--- a/packages/editor/src/index.ts
+++ b/packages/editor/src/index.ts
@@ -40,7 +40,7 @@ import {
import { OutlineList } from "./extensions/outline-list";
import { OutlineListItem } from "./extensions/outline-list-item";
import { Table } from "./extensions/table";
-import { useIsMobile } from "./toolbar/stores/toolbar-store";
+import { useIsMobile, useToolbarStore } from "./toolbar/stores/toolbar-store";
import { useEditor } from "./hooks/use-editor";
import { EditorOptions } from "@tiptap/core";
@@ -49,18 +49,22 @@ EditorView.prototype.updateState = function updateState(state) {
(this as any).updateStateInner(state, this.state.plugins != state.plugins);
};
+type TiptapOptions = EditorOptions &
+ AttachmentOptions & { theme: Theme; isMobile?: boolean };
+
const useTiptap = (
- options: Partial<EditorOptions & AttachmentOptions & { theme: Theme }> = {},
+ options: Partial<TiptapOptions> = {},
deps: React.DependencyList = []
) => {
const {
theme,
+ isMobile,
onDownloadAttachment,
onOpenAttachmentPicker,
...restOptions
} = options;
const PortalProviderAPI = usePortalProvider();
- const isMobile = useIsMobile();
+ const setIsMobile = useToolbarStore((store) => store.setIsMobile);
const defaultOptions = useMemo<Partial<EditorOptions>>(
() => ({
@@ -154,6 +158,10 @@ const useTiptap = (
deps
);
+ useEffect(() => {
+ setIsMobile(isMobile || false);
+ }, [isMobile]);
+
return editor;
};
diff --git a/packages/editor/src/toolbar/toolbar.tsx b/packages/editor/src/toolbar/toolbar.tsx
index 9f7c7d210..ec3706b7e 100644
--- a/packages/editor/src/toolbar/toolbar.tsx
+++ b/packages/editor/src/toolbar/toolbar.tsx
@@ -28,21 +28,18 @@ type ToolbarProps = {
theme: Theme;
editor: Editor | null;
location: ToolbarLocation;
- isMobile?: boolean;
tools?: ToolbarDefinition;
};
export function Toolbar(props: ToolbarProps) {
- const { editor, theme, location, isMobile, tools = DEFAULT_TOOLS } = props;
- const setIsMobile = useToolbarStore((store) => store.setIsMobile);
+ const { editor, theme, location, tools = DEFAULT_TOOLS } = props;
const setToolbarLocation = useToolbarStore(
(store) => store.setToolbarLocation
);
useEffect(() => {
- setIsMobile(isMobile || false);
setToolbarLocation(location);
- }, [isMobile, location]);
+ }, [location]);
if (!editor) return null;
return (
diff --git a/packages/editor/tsconfig.json b/packages/editor/tsconfig.json
index 5379960d7..17459804c 100644
--- a/packages/editor/tsconfig.json
+++ b/packages/editor/tsconfig.json
@@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
- "target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
+ "target": "ES2015" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"DOM",
"DOM.Iterable",
@@ -28,7 +28,7 @@
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
- "module": "esnext" /* Specify what module code is generated. */,
+ "module": "commonjs" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@@ -51,7 +51,7 @@
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
- "outDir": "./dist/es" /* Specify an output folder for all emitted files. */,
+ "outDir": "./dist/cjs" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */