mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
editor: fixes & refactoring for monorepo merge
This commit is contained in:
@@ -13,3 +13,6 @@ apps/web/public/an.js
|
||||
|
||||
# editor
|
||||
packages/editor/styles/
|
||||
|
||||
# editor mobile
|
||||
packages/editor-mobile/build.bundle
|
||||
@@ -5,7 +5,7 @@
|
||||
"dependencies": {
|
||||
"@flyerhq/react-native-link-preview": "^1.6.0",
|
||||
"@mdi/js": "^6.7.96",
|
||||
"@streetwriters/editor": "*",
|
||||
"@notesnook/editor": "*",
|
||||
"@notesnook/core": "*",
|
||||
"absolutify": "^0.1.0",
|
||||
"buffer": "^6.0.3",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type {
|
||||
Attachment,
|
||||
AttachmentProgress
|
||||
} from "@streetwriters/editor/dist/extensions/attachment/index";
|
||||
import type { ImageAttributes } from "@streetwriters/editor/dist/extensions/image/index";
|
||||
} from "@notesnook/editor/dist/extensions/attachment/index";
|
||||
import type { ImageAttributes } from "@notesnook/editor/dist/extensions/image/index";
|
||||
import { createRef, RefObject } from "react";
|
||||
import { Platform } from "react-native";
|
||||
import { EdgeInsets } from "react-native-safe-area-context";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEditor } from "./use-editor";
|
||||
import type { ToolbarGroupDefinition } from "@streetwriters/editor/dist/toolbar/types";
|
||||
import type { ToolbarGroupDefinition } from "@notesnook/editor/dist/toolbar/types";
|
||||
import { ThemeStore } from "../../../stores/use-theme-store";
|
||||
export type useEditorType = ReturnType<typeof useEditor>;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
import { getDefaultPresets } from "@streetwriters/editor/dist/toolbar/tool-definitions";
|
||||
import { getDefaultPresets } from "@notesnook/editor/dist/toolbar/tool-definitions";
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import {
|
||||
BackHandler,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ToolbarGroupDefinition } from "@streetwriters/editor/dist/toolbar/types";
|
||||
import type { ToolbarGroupDefinition } from "@notesnook/editor/dist/toolbar/types";
|
||||
import create, { State } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import { useNoteStore } from "../../../stores/use-notes-store";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ToolId } from "@streetwriters/editor/dist/toolbar";
|
||||
import { ToolId } from "@notesnook/editor/dist/toolbar";
|
||||
import React, { RefObject } from "react";
|
||||
import { View } from "react-native";
|
||||
import ActionSheet from "react-native-actions-sheet";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Icons } from "@streetwriters/editor/dist/toolbar/icons";
|
||||
import { Icons } from "@notesnook/editor/dist/toolbar/icons";
|
||||
import {
|
||||
getDefaultPresets,
|
||||
getAllTools
|
||||
} from "@streetwriters/editor/dist/toolbar/tool-definitions";
|
||||
import { ToolId } from "@streetwriters/editor/dist/toolbar/tools";
|
||||
import { ToolbarGroupDefinition } from "@streetwriters/editor/dist/toolbar/index";
|
||||
} from "@notesnook/editor/dist/toolbar/tool-definitions";
|
||||
import { ToolId } from "@notesnook/editor/dist/toolbar/tools";
|
||||
import { ToolbarGroupDefinition } from "@notesnook/editor/dist/toolbar/index";
|
||||
import { useThemeStore } from "../../../stores/use-theme-store";
|
||||
|
||||
export const tools = getAllTools();
|
||||
|
||||
@@ -83,7 +83,7 @@ module.exports = (env) => {
|
||||
//'react-native': reactNativePath,
|
||||
"react": path.join(__dirname, "../node_modules/react"),
|
||||
"react-dom": path.join(__dirname, "../node_modules/react-dom"),
|
||||
"@streetwriters/editor": path.join(__dirname, "../../../packages/editor"),
|
||||
"@notesnook/editor": path.join(__dirname, "../../../packages/editor"),
|
||||
},
|
||||
},
|
||||
/**
|
||||
|
||||
14
apps/mobile/package-lock.json
generated
14
apps/mobile/package-lock.json
generated
@@ -12,7 +12,7 @@
|
||||
"app/"
|
||||
],
|
||||
"dependencies": {
|
||||
"@streetwriters/editor": "*"
|
||||
"@notesnook/editor": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"patch-package": "^6.4.7",
|
||||
@@ -26,7 +26,7 @@
|
||||
"dependencies": {
|
||||
"@flyerhq/react-native-link-preview": "^1.6.0",
|
||||
"@mdi/js": "^6.7.96",
|
||||
"@streetwriters/editor": "*",
|
||||
"@notesnook/editor": "*",
|
||||
"@streetwriters/notesnook-core": "^7.3.5",
|
||||
"absolutify": "^0.1.0",
|
||||
"buffer": "^6.0.3",
|
||||
@@ -5823,9 +5823,9 @@
|
||||
"resolved": "https://registry.npmjs.org/@social-embed/lib/-/lib-0.0.1-next.12.tgz",
|
||||
"integrity": "sha512-CUqgq2PTmdmWhNPzth9JN1cFoaFsIWhgiuDVD23hjD+9HJVD+xs3GlbZF+YWYMKVhRa3hib4A7Ev8rOjz2QBwQ=="
|
||||
},
|
||||
"node_modules/@streetwriters/editor": {
|
||||
"node_modules/@notesnook/editor": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://npm.pkg.github.com/download/@streetwriters/editor/1.3.1/68b8d739d0b11e392b689b5bf7375318172de61a",
|
||||
"resolved": "https://npm.pkg.github.com/download/@notesnook/editor/1.3.1/68b8d739d0b11e392b689b5bf7375318172de61a",
|
||||
"integrity": "sha512-Pub5JXPabY4YdraMLi43HW+Y94ZiZRZA+PXJUmpSPa+KBr/36hTZG55EJUEqlY+bGDdec0ctSWFJ5Hu1cNPBqg==",
|
||||
"hasInstallScript": true,
|
||||
"license": "GPL-3.0",
|
||||
@@ -26147,7 +26147,7 @@
|
||||
"requires": {
|
||||
"@flyerhq/react-native-link-preview": "^1.6.0",
|
||||
"@mdi/js": "^6.7.96",
|
||||
"@streetwriters/editor": "*",
|
||||
"@notesnook/editor": "*",
|
||||
"@streetwriters/notesnook-core": "^7.3.5",
|
||||
"absolutify": "^0.1.0",
|
||||
"buffer": "^6.0.3",
|
||||
@@ -27440,9 +27440,9 @@
|
||||
"resolved": "https://registry.npmjs.org/@social-embed/lib/-/lib-0.0.1-next.12.tgz",
|
||||
"integrity": "sha512-CUqgq2PTmdmWhNPzth9JN1cFoaFsIWhgiuDVD23hjD+9HJVD+xs3GlbZF+YWYMKVhRa3hib4A7Ev8rOjz2QBwQ=="
|
||||
},
|
||||
"@streetwriters/editor": {
|
||||
"@notesnook/editor": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://npm.pkg.github.com/download/@streetwriters/editor/1.3.1/68b8d739d0b11e392b689b5bf7375318172de61a",
|
||||
"resolved": "https://npm.pkg.github.com/download/@notesnook/editor/1.3.1/68b8d739d0b11e392b689b5bf7375318172de61a",
|
||||
"integrity": "sha512-Pub5JXPabY4YdraMLi43HW+Y94ZiZRZA+PXJUmpSPa+KBr/36hTZG55EJUEqlY+bGDdec0ctSWFJ5Hu1cNPBqg==",
|
||||
"requires": {
|
||||
"@_ueberdosis/prosemirror-tables": "^1.1.3",
|
||||
|
||||
@@ -21,6 +21,6 @@
|
||||
"typescript": "^4.8.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@streetwriters/editor": "*"
|
||||
"@notesnook/editor": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,9 +104,6 @@
|
||||
"analyze": "source-map-explorer 'build/static/js/*.js'",
|
||||
"postinstall": "patch-package"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
|
||||
1
packages/editor-mobile/.env
Normal file
1
packages/editor-mobile/.env
Normal file
@@ -0,0 +1 @@
|
||||
SKIP_PREFLIGHT_CHECK=true
|
||||
1
packages/editor-mobile/.gitignore
vendored
1
packages/editor-mobile/.gitignore
vendored
@@ -10,6 +10,7 @@
|
||||
|
||||
# production
|
||||
/build
|
||||
/build.bundle
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
||||
|
||||
11495
packages/editor-mobile/package-lock.json
generated
11495
packages/editor-mobile/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,28 +1,24 @@
|
||||
{
|
||||
"name": "tiptap",
|
||||
"name": "@notesnook/editor-mobile",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@streetwriters/editor": "^1.3.1",
|
||||
"@streetwriters/theme": "^1.0.1",
|
||||
"@notesnook/editor": "*",
|
||||
"@notesnook/theme": "*",
|
||||
"framer-motion": "^4.1.17",
|
||||
"mdi-react": "^8.4.0",
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"zustand": "^3.6.8"
|
||||
},
|
||||
"resolutions": {
|
||||
"@types/react": "^17.0.39",
|
||||
"@types/react-dom": "^17.0.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.0",
|
||||
"@testing-library/react": "^11.2.7",
|
||||
"@testing-library/user-event": "^12.8.3",
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.11",
|
||||
"@types/react": "^17.0.39",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"@types/react": "^17.0.2",
|
||||
"@types/react-dom": "^17.0.2",
|
||||
"patch-package": "^6.4.7",
|
||||
"react-error-overlay": "6.0.9",
|
||||
"react-scripts": "^4.0.3",
|
||||
@@ -31,16 +27,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "BROWSER=none react-scripts start",
|
||||
"build": "GENERATE_SOURCEMAP=false react-scripts build && rm -rf ../clean/notesnook-mobile/web.bundle/ && mkdir ../clean/notesnook-mobile/web.bundle && cp -R ./build/* ../clean/notesnook-mobile/web.bundle/",
|
||||
"build": "GENERATE_SOURCEMAP=false react-scripts build && mv build build.bundle",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
"postinstall": "patch-package"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"homepage": ".",
|
||||
"browserslist": {
|
||||
@@ -54,5 +43,14 @@
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"nx": {
|
||||
"targets": {
|
||||
"build": {
|
||||
"outputs": [
|
||||
"{projectRoot}/build.bundle"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
diff --git a/node_modules/@tiptap/core/dist/tiptap-core.esm.js b/node_modules/@tiptap/core/dist/tiptap-core.esm.js
|
||||
index 3739b80..173171c 100644
|
||||
--- a/node_modules/@tiptap/core/dist/tiptap-core.esm.js
|
||||
+++ b/node_modules/@tiptap/core/dist/tiptap-core.esm.js
|
||||
@@ -2768,8 +2768,7 @@ const Keymap = Extension.create({
|
||||
new Plugin({
|
||||
key: new PluginKey('clearDocument'),
|
||||
appendTransaction: (transactions, oldState, newState) => {
|
||||
- const docChanges = transactions.some(transaction => transaction.docChanged)
|
||||
- && !oldState.doc.eq(newState.doc);
|
||||
+ const docChanges = transactions.some(transaction => transaction.docChanged);
|
||||
if (!docChanges) {
|
||||
return;
|
||||
}
|
||||
@@ -2777,10 +2776,11 @@ const Keymap = Extension.create({
|
||||
const allFrom = Selection.atStart(oldState.doc).from;
|
||||
const allEnd = Selection.atEnd(oldState.doc).to;
|
||||
const allWasSelected = from === allFrom && to === allEnd;
|
||||
- const isEmpty = newState.doc.textBetween(0, newState.doc.content.size, ' ', ' ').length === 0;
|
||||
- if (empty || !allWasSelected || !isEmpty) {
|
||||
+ if (empty || !allWasSelected) {
|
||||
return;
|
||||
}
|
||||
+ const isEmpty = newState.doc.textBetween(0, newState.doc.content.size, ' ', ' ').length === 0;
|
||||
+ if (!isEmpty) return;
|
||||
const tr = newState.tr;
|
||||
const state = createChainableState({
|
||||
state: newState,
|
||||
@@ -1,13 +0,0 @@
|
||||
diff --git a/node_modules/react-scripts/config/webpack.config.js b/node_modules/react-scripts/config/webpack.config.js
|
||||
index 26c2a65..c534178 100644
|
||||
--- a/node_modules/react-scripts/config/webpack.config.js
|
||||
+++ b/node_modules/react-scripts/config/webpack.config.js
|
||||
@@ -343,6 +343,8 @@ module.exports = function (webpackEnv) {
|
||||
'react-dom$': 'react-dom/profiling',
|
||||
'scheduler/tracing': 'scheduler/tracing-profiling',
|
||||
}),
|
||||
+ react: path.resolve(__dirname, '../../react'),
|
||||
+ 'react-dom': path.resolve(__dirname, '../../react-dom'),
|
||||
...(modules.webpackAliases || {}),
|
||||
},
|
||||
plugins: [
|
||||
@@ -1,7 +1,7 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import App from "./App";
|
||||
|
||||
test('renders learn react link', () => {
|
||||
test("renders learn react link", () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Editor } from "@streetwriters/editor";
|
||||
import { Editor } from "@notesnook/editor";
|
||||
|
||||
type ButtonType = {
|
||||
editor: Editor | null;
|
||||
@@ -13,7 +13,7 @@ export default function Button({
|
||||
title,
|
||||
onPress,
|
||||
marginRight = 10,
|
||||
activeKey,
|
||||
activeKey
|
||||
}: ButtonType) {
|
||||
const active = editor?.isActive(activeKey);
|
||||
|
||||
@@ -29,7 +29,7 @@ export default function Button({
|
||||
userSelect: "none",
|
||||
color: active ? "var(--nn_accent)" : "var(--nn_pri)",
|
||||
marginRight: marginRight,
|
||||
fontSize: 18,
|
||||
fontSize: 18
|
||||
}}
|
||||
onMouseUp={(e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -3,16 +3,16 @@ import {
|
||||
PortalProvider,
|
||||
Toolbar,
|
||||
usePermissionHandler,
|
||||
useTiptap,
|
||||
} from "@streetwriters/editor";
|
||||
import { Theme, useTheme } from "@streetwriters/theme";
|
||||
useTiptap
|
||||
} from "@notesnook/editor";
|
||||
import { Theme, useTheme } from "@notesnook/theme";
|
||||
import {
|
||||
forwardRef,
|
||||
memo,
|
||||
useCallback,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
useState
|
||||
} from "react";
|
||||
import { useEditorController } from "../hooks/useEditorController";
|
||||
import { useSettings } from "../hooks/useSettings";
|
||||
@@ -26,7 +26,7 @@ import Title from "./title";
|
||||
const Tiptap = ({
|
||||
editorTheme,
|
||||
toolbarTheme,
|
||||
settings,
|
||||
settings
|
||||
}: {
|
||||
editorTheme: Theme;
|
||||
toolbarTheme: Theme;
|
||||
@@ -38,11 +38,11 @@ const Tiptap = ({
|
||||
const [layout, setLayout] = useState(false);
|
||||
usePermissionHandler({
|
||||
claims: {
|
||||
premium: settings.premium,
|
||||
premium: settings.premium
|
||||
},
|
||||
onPermissionDenied: () => {
|
||||
post(EventTypes.pro);
|
||||
},
|
||||
}
|
||||
});
|
||||
const _editor = useTiptap(
|
||||
{
|
||||
@@ -64,12 +64,12 @@ const Tiptap = ({
|
||||
element: !layout ? undefined : contentRef.current || undefined,
|
||||
editable: !settings.readonly,
|
||||
editorProps: {
|
||||
editable: () => !settings.readonly,
|
||||
editable: () => !settings.readonly
|
||||
},
|
||||
content: global.editorController?.content?.current,
|
||||
isMobile: true,
|
||||
isKeyboardOpen: settings.keyboardShown,
|
||||
doubleSpacedLines: settings.doubleSpacedLines,
|
||||
doubleSpacedLines: settings.doubleSpacedLines
|
||||
},
|
||||
[layout, settings.readonly, tick]
|
||||
);
|
||||
@@ -97,7 +97,7 @@ const Tiptap = ({
|
||||
flex: 1,
|
||||
flexDirection: "column",
|
||||
maxWidth: "100vw",
|
||||
marginBottom: "5px",
|
||||
marginBottom: "5px"
|
||||
}}
|
||||
>
|
||||
<Header
|
||||
@@ -115,7 +115,7 @@ const Tiptap = ({
|
||||
height: "100%",
|
||||
flexGrow: 1,
|
||||
flexShrink: 1,
|
||||
display: "flex",
|
||||
display: "flex"
|
||||
}}
|
||||
>
|
||||
{settings.noHeader ? null : (
|
||||
@@ -143,7 +143,7 @@ const Tiptap = ({
|
||||
globalThis.editor
|
||||
?.chain()
|
||||
.insertContentAt(lastPosition - 1, "<p></p>", {
|
||||
updateSelection: true,
|
||||
updateSelection: true
|
||||
})
|
||||
.run();
|
||||
setTimeout(() => {
|
||||
@@ -153,7 +153,7 @@ const Tiptap = ({
|
||||
style={{
|
||||
flexShrink: 0,
|
||||
height: 150,
|
||||
width: "100%",
|
||||
width: "100%"
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
@@ -184,7 +184,7 @@ const ContentDiv = memo(
|
||||
flex: 1,
|
||||
color: theme.pri,
|
||||
marginTop: -12,
|
||||
caretColor: theme.accent,
|
||||
caretColor: theme.accent
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@@ -194,36 +194,35 @@ const ContentDiv = memo(
|
||||
|
||||
const modifyToolbarTheme = (toolbarTheme: Theme) => {
|
||||
toolbarTheme.space = [0, 10, 12, 18];
|
||||
//@ts-ignore
|
||||
toolbarTheme.space.small = "10px";
|
||||
|
||||
toolbarTheme.buttons.menuitem = {
|
||||
...toolbarTheme.buttons.menuitem,
|
||||
height: "50px",
|
||||
paddingX: "20px",
|
||||
borderBottomWidth: 0,
|
||||
borderBottomWidth: 0
|
||||
};
|
||||
|
||||
toolbarTheme.iconSizes = {
|
||||
big: 20,
|
||||
medium: 18,
|
||||
small: 18,
|
||||
small: 18
|
||||
};
|
||||
toolbarTheme.fontSizes = {
|
||||
...toolbarTheme.fontSizes,
|
||||
subBody: "0.8rem",
|
||||
body: "0.9rem",
|
||||
body: "0.9rem"
|
||||
};
|
||||
|
||||
toolbarTheme.radii = {
|
||||
...toolbarTheme.radii,
|
||||
small: 5,
|
||||
small: 5
|
||||
};
|
||||
|
||||
toolbarTheme.buttons.menuitem = {
|
||||
...toolbarTheme.buttons.menuitem,
|
||||
px: 5,
|
||||
height: "45px",
|
||||
height: "45px"
|
||||
};
|
||||
};
|
||||
|
||||
@@ -234,14 +233,14 @@ const TiptapProvider = () => {
|
||||
//todo
|
||||
accent: theme?.accent,
|
||||
scale: 1,
|
||||
theme: theme?.night ? "dark" : "light",
|
||||
theme: theme?.night ? "dark" : "light"
|
||||
});
|
||||
modifyToolbarTheme(toolbarTheme);
|
||||
const editorTheme = useTheme({
|
||||
//todo
|
||||
accent: theme?.accent,
|
||||
scale: 1,
|
||||
theme: theme?.night ? "dark" : "light",
|
||||
theme: theme?.night ? "dark" : "light"
|
||||
});
|
||||
editorTheme.colors.background = theme?.bg || "#f0f0f0";
|
||||
editorTheme.space = [0, 10, 12, 20];
|
||||
|
||||
@@ -3,7 +3,7 @@ import React, { RefObject, useEffect, useRef, useState } from "react";
|
||||
function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
|
||||
const [status, setStatus] = useState({
|
||||
date: "",
|
||||
saved: "",
|
||||
saved: ""
|
||||
});
|
||||
const [sticky, setSticky] = useState(false);
|
||||
const stickyRef = useRef(false);
|
||||
@@ -13,13 +13,11 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
|
||||
const currentWords = useRef(words);
|
||||
const interval = useRef(0);
|
||||
const statusBar = useRef({
|
||||
set: setStatus,
|
||||
set: setStatus
|
||||
});
|
||||
//@ts-ignore
|
||||
globalThis.statusBar = statusBar;
|
||||
|
||||
const onScroll = React.useCallback((event) => {
|
||||
//@ts-ignore
|
||||
const currentOffset = event.target.scrollTop;
|
||||
if (currentOffset < 200) {
|
||||
if (stickyRef.current) {
|
||||
@@ -48,12 +46,11 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
|
||||
|
||||
useEffect(() => {
|
||||
clearInterval(interval.current);
|
||||
//@ts-ignore
|
||||
interval.current = setInterval(() => {
|
||||
const words = editor?.storage?.characterCount?.words() + " words";
|
||||
if (currentWords.current === words) return;
|
||||
setWords(words);
|
||||
}, 3000);
|
||||
}, 3000) as unknown as number;
|
||||
return () => {
|
||||
clearInterval(interval.current);
|
||||
};
|
||||
@@ -73,7 +70,7 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
|
||||
fontSize: "12px",
|
||||
color: "var(--nn_icon)",
|
||||
marginRight: 8,
|
||||
paddingBottom: 0,
|
||||
paddingBottom: 0
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -89,7 +86,7 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
|
||||
zIndex: 1,
|
||||
justifyContent: sticky ? "center" : "flex-start",
|
||||
paddingTop: 2,
|
||||
paddingBottom: 2,
|
||||
paddingBottom: 2
|
||||
}}
|
||||
>
|
||||
<p style={paragraphStyle}>{words}</p>
|
||||
|
||||
@@ -5,7 +5,7 @@ import styles from "./styles.module.css";
|
||||
export default function Tags() {
|
||||
const [tags, setTags] = useState<{ title: string; alias: string }[]>([]);
|
||||
const editorTags = useRef({
|
||||
setTags: setTags,
|
||||
setTags: setTags
|
||||
});
|
||||
|
||||
global.editorTags = editorTags;
|
||||
@@ -24,7 +24,7 @@ export default function Tags() {
|
||||
padding: "0px 12px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
marginTop: 10,
|
||||
marginTop: 10
|
||||
}}
|
||||
>
|
||||
<button
|
||||
@@ -47,7 +47,7 @@ export default function Tags() {
|
||||
fontFamily: "Open Sans",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
height: "30px",
|
||||
height: "30px"
|
||||
}}
|
||||
>
|
||||
{tags.length === 0 ? (
|
||||
@@ -56,7 +56,7 @@ export default function Tags() {
|
||||
marginRight: 4,
|
||||
fontSize: 13,
|
||||
color: "var(--nn_icon)",
|
||||
userSelect: "none",
|
||||
userSelect: "none"
|
||||
}}
|
||||
>
|
||||
Add a tag
|
||||
@@ -78,6 +78,7 @@ export default function Tags() {
|
||||
|
||||
{tags.map((tag) => (
|
||||
<button
|
||||
key={tag.title}
|
||||
className={styles.btn}
|
||||
style={{
|
||||
borderWidth: 0,
|
||||
@@ -88,7 +89,7 @@ export default function Tags() {
|
||||
height: "30px",
|
||||
fontFamily: "Open Sans",
|
||||
fontSize: 13,
|
||||
color: "var(--nn_icon)",
|
||||
color: "var(--nn_icon)"
|
||||
}}
|
||||
onMouseUp={(e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Editor } from "@streetwriters/editor";
|
||||
import { Editor } from "@notesnook/editor";
|
||||
import {
|
||||
MutableRefObject,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
useState
|
||||
} from "react";
|
||||
import { useEditorThemeStore } from "../state/theme";
|
||||
import { EventTypes, isReactNative, post } from "../utils";
|
||||
@@ -20,7 +20,7 @@ export type Selection = {
|
||||
[name: string]: {
|
||||
text?: string;
|
||||
length?: number;
|
||||
attributes?: Record<string, any>;
|
||||
attributes?: Record<string, unknown>;
|
||||
type?: "mark" | "node";
|
||||
};
|
||||
};
|
||||
@@ -51,10 +51,10 @@ export function useEditorController(update: () => void): EditorController {
|
||||
const htmlContentRef = useRef<string | null>(null);
|
||||
const timers = useRef<Timers>({
|
||||
selectionChange: null,
|
||||
change: null,
|
||||
change: null
|
||||
});
|
||||
|
||||
const selectionChange = useCallback((editor: Editor) => {}, []);
|
||||
const selectionChange = useCallback((_editor: Editor) => {}, []);
|
||||
|
||||
const titleChange = useCallback((title: string) => {
|
||||
post(EventTypes.title, title);
|
||||
@@ -72,10 +72,7 @@ export function useEditorController(update: () => void): EditorController {
|
||||
}, []);
|
||||
|
||||
const scroll = useCallback(
|
||||
(event: React.UIEvent<HTMLDivElement, UIEvent>) => {
|
||||
//@ts-ignore
|
||||
//post(EventTypes.scroll, event.target.scrollTop);
|
||||
},
|
||||
(_event: React.UIEvent<HTMLDivElement, UIEvent>) => {},
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -84,13 +81,12 @@ export function useEditorController(update: () => void): EditorController {
|
||||
}, [update]);
|
||||
|
||||
const onMessage = useCallback(
|
||||
(data: Event) => {
|
||||
//@ts-ignore
|
||||
if (data?.data[0] !== "{") return;
|
||||
//@ts-ignore
|
||||
let message = JSON.parse(data.data);
|
||||
let type = message.type;
|
||||
let value = message.value;
|
||||
(event: Event & { data?: string }) => {
|
||||
if (event?.data?.[0] !== "{") return;
|
||||
|
||||
const message = JSON.parse(event.data);
|
||||
const type = message.type;
|
||||
const value = message.value;
|
||||
global.sessionId = message.sessionId;
|
||||
switch (type) {
|
||||
case "native:html":
|
||||
@@ -118,10 +114,9 @@ export function useEditorController(update: () => void): EditorController {
|
||||
|
||||
useEffect(() => {
|
||||
if (!isReactNative()) return; // Subscribe only in react native webview.
|
||||
let isSafari = navigator.vendor.match(/apple/i);
|
||||
let root = document;
|
||||
const isSafari = navigator.vendor.match(/apple/i);
|
||||
let root: Document | Window = document;
|
||||
if (isSafari) {
|
||||
//@ts-ignore
|
||||
root = window;
|
||||
}
|
||||
console.log("recreating messaging");
|
||||
@@ -152,6 +147,6 @@ export function useEditorController(update: () => void): EditorController {
|
||||
openFilePicker,
|
||||
downloadAttachment,
|
||||
content: htmlContentRef,
|
||||
onUpdate: onUpdate,
|
||||
onUpdate: onUpdate
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultPresets } from "@streetwriters/editor";
|
||||
import { getDefaultPresets } from "@notesnook/editor";
|
||||
import { useState } from "react";
|
||||
|
||||
const settingsJson = localStorage.getItem("editorSettings");
|
||||
@@ -10,7 +10,7 @@ const initialState = {
|
||||
noToolbar: globalThis.noToolbar,
|
||||
noHeader: globalThis.noHeader,
|
||||
readonly: globalThis.readonly,
|
||||
doubleSpacedLines: true,
|
||||
doubleSpacedLines: true
|
||||
};
|
||||
|
||||
global.settingsController = {
|
||||
@@ -19,7 +19,7 @@ global.settingsController = {
|
||||
...settings,
|
||||
noToolbar: globalThis.noToolbar || settings.noToolbar,
|
||||
noHeader: globalThis.noHeader || settings.noHeader,
|
||||
readonly: globalThis.readonly || settings.readonly,
|
||||
readonly: globalThis.readonly || settings.readonly
|
||||
};
|
||||
if (
|
||||
JSON.stringify(nextSettings) ===
|
||||
@@ -36,7 +36,7 @@ global.settingsController = {
|
||||
}
|
||||
settingsController.previous = { ...nextSettings };
|
||||
},
|
||||
previous: settingsJson ? JSON.parse(settingsJson) : { ...initialState },
|
||||
previous: settingsJson ? JSON.parse(settingsJson) : { ...initialState }
|
||||
};
|
||||
global.settingsController.previous.noHeader = globalThis.noHeader;
|
||||
global.settingsController.previous.noToolbar = globalThis.noToolbar;
|
||||
@@ -44,7 +44,7 @@ global.settingsController.previous.readonly = globalThis.readonly;
|
||||
|
||||
export const useSettings = () => {
|
||||
const [settings, setSettings] = useState({
|
||||
...global.settingsController.previous,
|
||||
...global.settingsController.previous
|
||||
});
|
||||
global.settingsController.set = setSettings;
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@ import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import "./index.css";
|
||||
import App from "./App";
|
||||
import reportWebVitals from "./reportWebVitals";
|
||||
import "@streetwriters/editor/styles/katex.min.css";
|
||||
import "@streetwriters/editor/styles/prism-theme.css";
|
||||
import "@streetwriters/editor/styles/fonts.mobile.css";
|
||||
import "@streetwriters/editor/styles/katexfonts.mobile.css";
|
||||
import "@streetwriters/editor/styles/styles.css";
|
||||
import "@notesnook/editor/styles/katex.min.css";
|
||||
import "@notesnook/editor/styles/prism-theme.css";
|
||||
import "@notesnook/editor/styles/fonts.mobile.css";
|
||||
import "@notesnook/editor/styles/katex-fonts.mobile.css";
|
||||
import "@notesnook/editor/styles/styles.css";
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
@@ -15,8 +14,3 @@ ReactDOM.render(
|
||||
</React.StrictMode>,
|
||||
document.getElementById("root")
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
const reportWebVitals = onPerfEntry => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
getLCP(onPerfEntry);
|
||||
getTTFB(onPerfEntry);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default reportWebVitals;
|
||||
@@ -2,4 +2,4 @@
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
||||
import "@testing-library/jest-dom";
|
||||
|
||||
@@ -63,7 +63,7 @@ const DefaultColors = {
|
||||
input: "transparent",
|
||||
heading: "#212121",
|
||||
border: "#E8E8E8",
|
||||
placeholder: "#a9a9a9",
|
||||
placeholder: "#a9a9a9"
|
||||
};
|
||||
|
||||
injectCss(transform(DefaultColors));
|
||||
@@ -72,10 +72,10 @@ interface ThemeState extends State {
|
||||
setColors: (colors: Colors) => void;
|
||||
}
|
||||
|
||||
export const useEditorThemeStore = create<ThemeState>((set, get) => ({
|
||||
export const useEditorThemeStore = create<ThemeState>((set) => ({
|
||||
colors: DefaultColors,
|
||||
setColors: (colors) => {
|
||||
injectCss(transform(colors));
|
||||
set({ colors: colors });
|
||||
},
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ToolbarGroupDefinition } from "@streetwriters/editor";
|
||||
import { Editor } from "@streetwriters/editor";
|
||||
import { ToolbarGroupDefinition } from "@notesnook/editor";
|
||||
import { Editor } from "@notesnook/editor";
|
||||
import { Dispatch, MutableRefObject, RefObject, SetStateAction } from "react";
|
||||
import { useEditorController } from "../hooks/useEditorController";
|
||||
|
||||
@@ -22,7 +22,16 @@ export type Settings = {
|
||||
doubleSpacedLines?: boolean;
|
||||
};
|
||||
|
||||
/* eslint-disable no-var */
|
||||
declare global {
|
||||
var statusBar: React.MutableRefObject<{
|
||||
set: React.Dispatch<
|
||||
React.SetStateAction<{
|
||||
date: string;
|
||||
saved: string;
|
||||
}>
|
||||
>;
|
||||
}>;
|
||||
var readonly: boolean;
|
||||
var noToolbar: boolean;
|
||||
var noHeader: boolean;
|
||||
@@ -76,14 +85,17 @@ declare global {
|
||||
>;
|
||||
}>;
|
||||
|
||||
function logger(type: "info" | "warn" | "error", ...logs: any[]): void;
|
||||
function logger(type: "info" | "warn" | "error", ...logs: never[]): void;
|
||||
/**
|
||||
* Function to post message to react native
|
||||
* @param type
|
||||
* @param value
|
||||
*/
|
||||
|
||||
function post(type: string, value?: unknown): void;
|
||||
function post<T extends keyof typeof EventTypes>(
|
||||
type: typeof EventTypes[T],
|
||||
value?: unknown
|
||||
): void;
|
||||
interface Window {
|
||||
/**
|
||||
* React Native WebView
|
||||
@@ -93,11 +105,7 @@ declare global {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const timerFn = (callback: () => void, duration: number) => {
|
||||
// timer = setTimeout(callback, duration);
|
||||
// return timer;
|
||||
};
|
||||
/* eslint-enable no-var */
|
||||
|
||||
export const EventTypes = {
|
||||
selection: "editor-event:selection",
|
||||
@@ -114,15 +122,15 @@ export const EventTypes = {
|
||||
pro: "editor-event:pro",
|
||||
monograph: "editor-event:monograph",
|
||||
properties: "editor-event:properties",
|
||||
fullscreen: "editor-event:fullscreen",
|
||||
};
|
||||
fullscreen: "editor-event:fullscreen"
|
||||
} as const;
|
||||
|
||||
export function isReactNative(): boolean {
|
||||
return !!window.ReactNativeWebView;
|
||||
}
|
||||
|
||||
export function logger(type: "info" | "warn" | "error", ...logs: any[]) {
|
||||
let logString = logs
|
||||
export function logger(type: "info" | "warn" | "error", ...logs: never[]) {
|
||||
const logString = logs
|
||||
.map((log) => {
|
||||
return typeof log !== "string" ? JSON.stringify(log) : log;
|
||||
})
|
||||
@@ -131,19 +139,22 @@ export function logger(type: "info" | "warn" | "error", ...logs: any[]) {
|
||||
post(EventTypes.logger, `[${type}]: ` + logString);
|
||||
}
|
||||
|
||||
export function post(type: string, value?: unknown) {
|
||||
export function post<T extends keyof typeof EventTypes>(
|
||||
type: typeof EventTypes[T],
|
||||
value?: unknown
|
||||
) {
|
||||
if (isReactNative()) {
|
||||
window.ReactNativeWebView.postMessage(
|
||||
JSON.stringify({
|
||||
//@ts-ignore
|
||||
type: EventTypes[type] || type,
|
||||
type,
|
||||
value: value,
|
||||
sessionId: global.sessionId,
|
||||
sessionId: globalThis.sessionId
|
||||
})
|
||||
);
|
||||
} else {
|
||||
console.log(type, value);
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.logger = logger;
|
||||
globalThis.post = post;
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"display": "tiptap editor",
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"module": "esnext",
|
||||
"target": "es5",
|
||||
"allowJs": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true,
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"jsx": "react-jsx",
|
||||
"moduleResolution": "node",
|
||||
"noEmit": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"outDir": "../notesnook-mobile/web.bundle",
|
||||
"downlevelIteration": true,
|
||||
"maxNodeModuleJsDepth": 5
|
||||
"maxNodeModuleJsDepth": 5,
|
||||
"allowJs": true
|
||||
},
|
||||
"include": ["src/"],
|
||||
"exclude": ["src/notesnook-editor/"]
|
||||
"include": [
|
||||
"src/"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ThemeConfig } from "./types";
|
||||
|
||||
export type Theme = {
|
||||
breakpoints: string[];
|
||||
space: number[] & { small?: number };
|
||||
space: number[] & { small?: number | string };
|
||||
sizes: { full: "100%"; half: "50%" };
|
||||
radii: {
|
||||
none: number;
|
||||
@@ -41,13 +41,13 @@ class ThemeFactory {
|
||||
shadows:
|
||||
config.theme === "dark"
|
||||
? {
|
||||
menu: "0px 0px 10px 0px #00000078",
|
||||
menu: "0px 0px 10px 0px #00000078"
|
||||
}
|
||||
: {
|
||||
menu: "0px 0px 10px 0px #00000022",
|
||||
menu: "0px 0px 10px 0px #00000022"
|
||||
},
|
||||
...getFontConfig(config.scale),
|
||||
...variants,
|
||||
...variants
|
||||
};
|
||||
theme.space.small = 3;
|
||||
return theme;
|
||||
|
||||
Reference in New Issue
Block a user