refactor!: next generation AFFiNE code structure (#1176)

This commit is contained in:
Himself65
2023-03-01 01:40:01 -06:00
committed by GitHub
parent 2dcccc772c
commit e0481d29ad
270 changed files with 8308 additions and 6829 deletions

View File

@@ -1,13 +0,0 @@
import { expect, test } from '@playwright/test';
import { isMobile } from '../get-is-mobile';
test.describe('get-is-mobile', () => {
test('get-is-mobile', () => {
expect(
isMobile(
'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
)
).toBe(true);
});
});

View File

@@ -1,20 +0,0 @@
export function stringToColour(str: string) {
str = str || 'affine';
let colour = '#';
let hash = 0;
// str to hash
for (
let i = 0;
i < str.length;
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
);
// int/hash to hex
for (
let i = 0;
i < 3;
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
);
return colour;
}

View File

@@ -1 +0,0 @@
export const isDev = process.env['NODE_ENV'] === 'development';

View File

@@ -16,5 +16,3 @@ export const getIsMobile = function () {
navigator?.userAgent || navigator?.vendor || (window as any)?.opera
);
};
export default getIsMobile;

View File

@@ -1,4 +1,37 @@
export * from './colors';
export { isDev } from './env';
export * from './tools';
export * from './useragent';
import { __unstableSchemas, builtInSchemas } from '@blocksuite/blocks/models';
import type { BlobOptionsGetter } from '@blocksuite/store';
import { BlockSuiteWorkspace } from '../shared';
export function stringToColour(str: string) {
str = str || 'affine';
let colour = '#';
let hash = 0;
// str to hash
for (
let i = 0;
i < str.length;
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
);
// int/hash to hex
for (
let i = 0;
i < 3;
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
);
return colour;
}
export const createEmptyBlockSuiteWorkspace = (
room: string,
blobOptionsGetter?: BlobOptionsGetter
) => {
return new BlockSuiteWorkspace({
room,
blobOptionsGetter,
})
.register(builtInSchemas)
.register(__unstableSchemas);
};

View File

@@ -1,60 +0,0 @@
import getConfig from 'next/config';
import { isDev } from './env';
type Config = {
BUILD_DATE: string;
NODE_ENV: string;
PROJECT_NAME: string;
EDITOR_VERSION: string;
VERSION: string;
CI?: string;
COMMIT_HASH: string;
};
const nextConfig = getConfig();
const publicRuntimeConfig: Config = nextConfig.publicRuntimeConfig;
const printBuildInfo = () => {
if (isDev) {
return;
}
console.group('Build info');
console.log('Project:', publicRuntimeConfig.PROJECT_NAME);
console.log(
'Build date:',
publicRuntimeConfig.BUILD_DATE
? new Date(publicRuntimeConfig.BUILD_DATE).toLocaleString()
: 'Unknown'
);
console.log(
'Environment:',
`${publicRuntimeConfig.NODE_ENV}${publicRuntimeConfig.CI ? '(ci)' : ''}`
);
console.log('Editor Version:', publicRuntimeConfig.EDITOR_VERSION);
console.log('Version:', publicRuntimeConfig.VERSION);
console.log(
'AFFiNE is an open source project, you can view its source code on GitHub!'
);
console.log(
`https://github.com/toeverything/AFFiNE/tree/${publicRuntimeConfig.COMMIT_HASH}`
);
console.groupEnd();
};
function setWindowEditorVersion() {
globalThis.__editoVersion = publicRuntimeConfig.EDITOR_VERSION;
}
declare global {
// eslint-disable-next-line no-var
var __affineSetupEnv: boolean | undefined;
}
if (!globalThis.__affineSetupEnv) {
printBuildInfo();
setWindowEditorVersion();
globalThis.__affineSetupEnv = true;
}
export {};

View File

@@ -1,10 +0,0 @@
// eslint-disable-next-line @typescript-eslint/ban-types
export function debounce(fn: Function, timeout: number) {
let timeoutId: any;
return function (this: any) {
clearTimeout(timeoutId);
// eslint-disable-next-line prefer-rest-params
timeoutId = setTimeout(() => fn.apply(this, arguments), timeout);
};
}

View File

@@ -1,4 +1,4 @@
function getUaHelper() {
export function getUaHelper() {
let uaHelper = null;
(function (navigator) {
const getUa = () => {
@@ -78,5 +78,3 @@ function getUaHelper() {
return uaHelper;
}
export { getUaHelper };