mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
### TL;DR Moved editor components from BlockSuite presets to AFFiNE core and updated imports accordingly. ### What changed? - Relocated `EdgelessEditor` and `PageEditor` components from BlockSuite presets to AFFiNE core - Removed basic editor examples from playground - Updated import paths across the codebase to reference new component locations - Added editor effects registration in AFFiNE core - Removed editor exports from BlockSuite presets ### How to test? 1. Launch the application 2. Verify both page and edgeless editors load correctly 3. Confirm editor functionality remains intact including: - Document editing - Mode switching - Editor toolbars and controls - Multiple editor instances ### Why make this change? This change better aligns with AFFiNE's architecture by moving editor components closer to where they are used. It reduces coupling with BlockSuite presets and gives AFFiNE more direct control over editor customization and implementation.
115 lines
3.0 KiB
TypeScript
115 lines
3.0 KiB
TypeScript
import { cpus } from 'node:os';
|
|
import path, { resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
|
|
import type { Plugin } from 'vite';
|
|
import { defineConfig, loadEnv } from 'vite';
|
|
import istanbul from 'vite-plugin-istanbul';
|
|
import wasm from 'vite-plugin-wasm';
|
|
|
|
import { hmrPlugin } from './scripts/hmr-plugin';
|
|
|
|
const enableIstanbul = !!process.env.COVERAGE;
|
|
|
|
export function sourcemapExclude(): Plugin {
|
|
return {
|
|
name: 'sourcemap-exclude',
|
|
transform(code: string, id: string) {
|
|
if (id.includes('node_modules') && !id.includes('@blocksuite')) {
|
|
return {
|
|
code,
|
|
// https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
|
|
map: { mappings: '' },
|
|
};
|
|
}
|
|
|
|
return undefined;
|
|
},
|
|
};
|
|
}
|
|
|
|
const clearSiteDataPlugin = () =>
|
|
({
|
|
name: 'clear-site-data',
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
if (req.url === '/Clear-Site-Data') {
|
|
res.statusCode = 200;
|
|
res.setHeader('Clear-Site-Data', '"*"');
|
|
}
|
|
next();
|
|
});
|
|
},
|
|
}) as Plugin;
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
process.env = { ...process.env, ...loadEnv(mode, __dirname, '') };
|
|
|
|
return {
|
|
envDir: __dirname,
|
|
define: {
|
|
'import.meta.env.PLAYGROUND_SERVER': JSON.stringify(
|
|
process.env.PLAYGROUND_SERVER ?? 'http://localhost:8787'
|
|
),
|
|
'import.meta.env.PLAYGROUND_WS': JSON.stringify(
|
|
process.env.PLAYGROUND_WS ?? 'ws://localhost:8787'
|
|
),
|
|
},
|
|
plugins: [
|
|
hmrPlugin,
|
|
sourcemapExclude(),
|
|
enableIstanbul &&
|
|
istanbul({
|
|
cwd: fileURLToPath(new URL('../..', import.meta.url)),
|
|
include: ['packages/**/src/*'],
|
|
exclude: [
|
|
'node_modules',
|
|
'tests',
|
|
fileURLToPath(new URL('.', import.meta.url)),
|
|
],
|
|
forceBuildInstrument: true,
|
|
}),
|
|
wasm(),
|
|
vanillaExtractPlugin(),
|
|
clearSiteDataPlugin(),
|
|
],
|
|
esbuild: {
|
|
target: 'es2018',
|
|
},
|
|
resolve: {
|
|
extensions: ['.ts', '.js'],
|
|
},
|
|
build: {
|
|
target: 'es2022',
|
|
sourcemap: true,
|
|
rollupOptions: {
|
|
cache: false,
|
|
maxParallelFileOps: Math.max(1, cpus().length - 1),
|
|
onwarn(warning, defaultHandler) {
|
|
if (
|
|
warning.code &&
|
|
['EVAL', 'SOURCEMAP_ERROR'].includes(warning.code)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
defaultHandler(warning);
|
|
},
|
|
input: {
|
|
main: resolve(__dirname, 'index.html'),
|
|
'examples/inline': resolve(__dirname, 'examples/inline/index.html'),
|
|
},
|
|
treeshake: true,
|
|
output: {
|
|
sourcemapIgnoreList: relativeSourcePath => {
|
|
const normalizedPath = path.normalize(relativeSourcePath);
|
|
return normalizedPath.includes('node_modules');
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
});
|