mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 02:20:19 +08:00
init: the first public commit for AFFiNE
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"@nrwl/react/babel",
|
||||
{
|
||||
"runtime": "automatic",
|
||||
"useBuiltIns": "usage"
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": []
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.ts", "*.tsx"],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.js", "*.jsx"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
displayName: 'components-affine-editor',
|
||||
preset: '../../../jest.preset.js',
|
||||
transform: {
|
||||
'^.+\\.[tj]sx?$': 'babel-jest',
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||
coverageDirectory: '../../../coverage/libs/components/affine-editor',
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@toeverything/components/affine-editor",
|
||||
"version": "0.0.1",
|
||||
"license": "MIT"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"sourceRoot": "libs/components/affine-editor/src",
|
||||
"projectType": "library",
|
||||
"tags": ["components:affine-editor"],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/web:rollup",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/libs/components/affine-editor",
|
||||
"tsConfig": "libs/components/affine-editor/tsconfig.lib.json",
|
||||
"project": "libs/components/affine-editor/package.json",
|
||||
"entryFile": "libs/components/affine-editor/src/index.ts",
|
||||
"external": ["react/jsx-runtime"],
|
||||
"rollupConfig": "libs/rollup.config.cjs",
|
||||
"compiler": "babel",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "libs/components/affine-editor/README.md",
|
||||
"input": ".",
|
||||
"output": "."
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nrwl/linter:eslint",
|
||||
"outputs": ["{options.outputFile}"],
|
||||
"options": {
|
||||
"lintFilePatterns": [
|
||||
"libs/components/affine-editor/**/*.{ts,tsx,js,jsx}"
|
||||
]
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["coverage/libs/components/affine-editor"],
|
||||
"options": {
|
||||
"jestConfig": "libs/components/affine-editor/jest.config.js",
|
||||
"passWithNoTests": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
import { RenderRoot, RenderBlock } from '@toeverything/components/editor-core';
|
||||
import { useCurrentEditors } from '@toeverything/datasource/state';
|
||||
|
||||
import { createEditor } from './create-editor';
|
||||
|
||||
interface AffineEditorProps {
|
||||
workspace: string;
|
||||
rootBlockId: string;
|
||||
/**
|
||||
* Whether to show the visual blank at the bottom of the article
|
||||
*/
|
||||
scrollBlank?: boolean;
|
||||
|
||||
isWhiteboard?: boolean;
|
||||
}
|
||||
|
||||
function useConstant<T>(init: () => T): T {
|
||||
const ref = useRef<T>(null);
|
||||
ref.current ??= init();
|
||||
|
||||
return ref.current;
|
||||
}
|
||||
|
||||
export const AffineEditor = ({
|
||||
workspace,
|
||||
rootBlockId,
|
||||
scrollBlank = true,
|
||||
isWhiteboard,
|
||||
}: AffineEditorProps) => {
|
||||
const { setCurrentEditors } = useCurrentEditors();
|
||||
const editor = useConstant(() => {
|
||||
const editor = createEditor(workspace, isWhiteboard);
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.virgo = editor;
|
||||
return editor;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (rootBlockId) {
|
||||
editor.setRootBlockId(rootBlockId);
|
||||
} else {
|
||||
console.error('rootBlockId for page is required. ');
|
||||
}
|
||||
}, [editor, rootBlockId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!rootBlockId) return;
|
||||
setCurrentEditors(prev => ({ ...prev, [rootBlockId]: editor }));
|
||||
}, [editor, rootBlockId, setCurrentEditors]);
|
||||
|
||||
return (
|
||||
<RenderRoot
|
||||
editor={editor}
|
||||
editorElement={AffineEditor as any}
|
||||
scrollBlank={scrollBlank}
|
||||
>
|
||||
<RenderBlock blockId={rootBlockId} />
|
||||
</RenderRoot>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
import { BlockEditor } from '@toeverything/framework/virgo';
|
||||
import {
|
||||
PageBlock,
|
||||
RefLinkBlock,
|
||||
TextBlock,
|
||||
Heading1Block,
|
||||
Heading2Block,
|
||||
Heading3Block,
|
||||
QuoteBlock,
|
||||
TodoBlock,
|
||||
CodeBlock,
|
||||
// TocBlock,
|
||||
FileBlock,
|
||||
ImageBlock,
|
||||
DividerBlock,
|
||||
CalloutBlock,
|
||||
YoutubeBlock,
|
||||
FigmaBlock,
|
||||
GroupBlock,
|
||||
EmbedLinkBlock,
|
||||
BulletBlock,
|
||||
NumberedBlock,
|
||||
GridBlock,
|
||||
GridItemBlock,
|
||||
GroupDividerBlock,
|
||||
} from '@toeverything/components/editor-blocks';
|
||||
import { Protocol } from '@toeverything/datasource/db-service';
|
||||
import { plugins } from '@toeverything/components/editor-plugins';
|
||||
|
||||
export const createEditor = (workspace: string, isWhiteboard?: boolean) => {
|
||||
const blockEditor = new BlockEditor({
|
||||
workspace,
|
||||
views: {
|
||||
[Protocol.Block.Type.page]: new PageBlock(),
|
||||
[Protocol.Block.Type.reference]: new RefLinkBlock(),
|
||||
[Protocol.Block.Type.text]: new TextBlock(),
|
||||
[Protocol.Block.Type.heading1]: new Heading1Block(),
|
||||
[Protocol.Block.Type.heading2]: new Heading2Block(),
|
||||
[Protocol.Block.Type.heading3]: new Heading3Block(),
|
||||
[Protocol.Block.Type.quote]: new QuoteBlock(),
|
||||
[Protocol.Block.Type.todo]: new TodoBlock(),
|
||||
[Protocol.Block.Type.code]: new CodeBlock(),
|
||||
// [Protocol.Block.Type.toc]: new TocBlock(),
|
||||
[Protocol.Block.Type.file]: new FileBlock(),
|
||||
[Protocol.Block.Type.image]: new ImageBlock(),
|
||||
[Protocol.Block.Type.divider]: new DividerBlock(),
|
||||
[Protocol.Block.Type.callout]: new CalloutBlock(),
|
||||
[Protocol.Block.Type.youtube]: new YoutubeBlock(),
|
||||
[Protocol.Block.Type.figma]: new FigmaBlock(),
|
||||
[Protocol.Block.Type.group]: new GroupBlock(),
|
||||
[Protocol.Block.Type.embedLink]: new EmbedLinkBlock(),
|
||||
[Protocol.Block.Type.numbered]: new NumberedBlock(),
|
||||
[Protocol.Block.Type.bullet]: new BulletBlock(),
|
||||
[Protocol.Block.Type.grid]: new GridBlock(),
|
||||
[Protocol.Block.Type.gridItem]: new GridItemBlock(),
|
||||
[Protocol.Block.Type.groupDivider]: new GroupDividerBlock(),
|
||||
},
|
||||
plugins,
|
||||
isWhiteboard,
|
||||
});
|
||||
|
||||
return blockEditor;
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export { AffineEditor } from './Editor';
|
||||
export { createEditor } from './create-editor';
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"types": ["node"]
|
||||
},
|
||||
"files": [
|
||||
"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts",
|
||||
"../../../node_modules/@nrwl/react/typings/image.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*.spec.ts",
|
||||
"**/*.test.ts",
|
||||
"**/*.spec.tsx",
|
||||
"**/*.test.tsx",
|
||||
"**/*.spec.js",
|
||||
"**/*.test.js",
|
||||
"**/*.spec.jsx",
|
||||
"**/*.test.jsx"
|
||||
],
|
||||
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": [
|
||||
"**/*.test.ts",
|
||||
"**/*.spec.ts",
|
||||
"**/*.test.tsx",
|
||||
"**/*.spec.tsx",
|
||||
"**/*.test.js",
|
||||
"**/*.spec.js",
|
||||
"**/*.test.jsx",
|
||||
"**/*.spec.jsx",
|
||||
"**/*.d.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user