Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: local command

DarkSky9361ad8e61e7
diff --git a/.env.local b/.env.local
new file mode 100644
index 0000000000..7471e5ffd4
--- /dev/null
+++ b/.env.local
@@ -0,0 +1 @@
+NX_LOCAL=true
diff --git a/.free.env b/.free.env
deleted file mode 100644
index 24b1b20ec4..0000000000
--- a/.free.env
+++ /dev/null
@@ -1 +0,0 @@
-NX_FREE_LOGIN=true
diff --git a/libs/components/common/src/lib/block-preview/StyledBlockPreview.tsx b/libs/components/common/src/lib/block-preview/StyledBlockPreview.tsx
index afe859eb53..f811ac3211 100644
--- a/libs/components/common/src/lib/block-preview/StyledBlockPreview.tsx
+++ b/libs/components/common/src/lib/block-preview/StyledBlockPreview.tsx
@@ -84,9 +84,9 @@ const Title = styled('div')<{ size: PreviewSize }>(({ size }) => {
const ScopedEditorWrapper = styled('div')<{ size: PreviewSize }>(({ size }) => {
return {
- width: '750px',
+ width: '940px',
height: '750px',
- transform: 'scale(32%) translate(-102%, -104%)',
+ transform: 'scale(25%) translate(-145%, -145%)',
// eslint-disable-next-line @typescript-eslint/naming-convention
'&>:first-child': {
margin: 'auto',
diff --git a/libs/components/editor-blocks/src/components/source-view/SourceView.tsx b/libs/components/editor-blocks/src/components/source-view/SourceView.tsx
index 99673d221a..c044c117a0 100644
--- a/libs/components/editor-blocks/src/components/source-view/SourceView.tsx
+++ b/libs/components/editor-blocks/src/components/source-view/SourceView.tsx
@@ -136,7 +136,6 @@ const SourceViewContainer = styled('div')<{
borderRadius: theme.affine.shape.borderRadius,
background: isSelected ? 'rgba(152, 172, 189, 0.1)' : 'transparent',
padding: '8px',
- // border:
iframe: {
width: '100%',
height: '100%',
@@ -171,6 +170,7 @@ export const SourceView: FC<Props> = props => {
<SourceViewContainer
isSelected={isSelected}
scene={SCENE_CONFIG.REFLINK}
+ style={{ padding: '0' }}
>
<MemoBlockPreview
block={block}
diff --git a/libs/components/editor-blocks/src/components/source-view/format-url/affine.ts b/libs/components/editor-blocks/src/components/source-view/format-url/affine.ts
index 2ddb814634..e31e1759cc 100644
--- a/libs/components/editor-blocks/src/components/source-view/format-url/affine.ts
+++ b/libs/components/editor-blocks/src/components/source-view/format-url/affine.ts
@@ -1,5 +1,5 @@
const _regex =
- /^(https?:\/\/(localhost:4200|(nightly|app)\.affine\.pro|.*?\.ligo-virgo\.pages\.dev)\/\w{28}\/)?(affine\w{16})$/;
+ /^(https?:\/\/(localhost:4200|(nightly|app)\.affine\.pro|.*?\.ligo-virgo\.pages\.dev)\/\w{28}\/)?(affine\w{16})(\/whiteboard)?$/;
export const isAffineUrl = (url?: string) => {
if (!url) return false;
diff --git a/libs/datasource/db-service/src/services/database/index.ts b/libs/datasource/db-service/src/services/database/index.ts
index a7cfe952bb..c8422502b2 100644
--- a/libs/datasource/db-service/src/services/database/index.ts
+++ b/libs/datasource/db-service/src/services/database/index.ts
@@ -24,16 +24,16 @@ const waitLoading = async (key: string) => {
};
async function _getCurrentToken() {
- if (process.env['NX_FREE_LOGIN']) {
- return 'NX_FREE_LOGIN';
- }
- const token = await getAuth().currentUser?.getIdToken();
- if (token) return token;
- return new Promise<string>(resolve => {
- getAuth().onIdTokenChanged((user: User | null) => {
- if (user) resolve(user.getIdToken());
+ if (!process.env['NX_LOCAL']) {
+ const token = await getAuth().currentUser?.getIdToken();
+ if (token) return token;
+ return new Promise<string>(resolve => {
+ getAuth().onIdTokenChanged((user: User | null) => {
+ if (user) resolve(user.getIdToken());
+ });
});
- });
+ }
+ return undefined;
}
async function _getBlockDatabase(
diff --git a/libs/datasource/jwt/src/adapter/yjs/index.ts b/libs/datasource/jwt/src/adapter/yjs/index.ts
index 81ab0adc2c..ca4d3904e2 100644
--- a/libs/datasource/jwt/src/adapter/yjs/index.ts
+++ b/libs/datasource/jwt/src/adapter/yjs/index.ts
@@ -16,6 +16,7 @@ import {
transact,
encodeStateAsUpdate,
applyUpdate,
+ snapshot,
} from 'yjs';
import { WebsocketProvider } from '@toeverything/datasource/jwt-rpc';
@@ -62,7 +63,7 @@ async function _initWebsocketProvider(
params?: YjsInitOptions['params']
): Promise<[Awareness, WebsocketProvider | undefined]> {
const awareness = new Awareness(doc);
- if (token && !process.env['NX_FREE_LOGIN']) {
+ if (token) {
const ws = new WebsocketProvider(token, url, room, doc, {
awareness,
params,
@@ -129,10 +130,13 @@ async function _initYjsDatabase(
binaries
).whenSynced;
+ const gateKeeperData = doc.getMap<YMap<string>>('gatekeeper');
+
const gatekeeper = new GateKeeper(
userId,
- doc.getMap('creators'),
- doc.getMap('common')
+ gateKeeperData.get('creators') ||
+ gateKeeperData.set('creators', new YMap()),
+ gateKeeperData.get('common') || gateKeeperData.set('common', new YMap())
);
_yjsDatabaseInstance.set(workspace, {
@@ -206,8 +210,11 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
this.#awareness = providers.awareness;
this.#gatekeeper = providers.gatekeeper;
- this.#blocks = this.#doc.getMap('blocks');
- this.#block_updated = this.#doc.getMap('block_updated');
+ const blocks = this.#doc.getMap<YMap<any>>('blocks');
+ this.#blocks =
+ blocks.get('content') || blocks.set('content', new YMap());
+ this.#block_updated =
+ blocks.get('updated') || blocks.set('updated', new YMap());
this.#block_caches = new LRUCache({ max: 1024, ttl: 1000 * 60 * 10 });
this.#binaries = new YjsRemoteBinaries(
providers.binariesIdb.doc.getMap(),
@@ -381,6 +388,18 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
this.#blocks.clear();
this.#block_updated.clear();
this.#gatekeeper.clear();
+ this.#doc.getMap('blocks').clear();
+ this.#doc.getMap('gatekeeper').clear();
+ },
+ // eslint-disable-next-line @typescript-eslint/naming-convention
+ clear_old: () => {
+ this.#doc.getMap('block_updated').clear();
+ this.#doc.getMap('blocks').clear();
+ this.#doc.getMap('common').clear();
+ this.#doc.getMap('creators').clear();
+ },
+ snapshot: () => {
+ return snapshot(this.#doc);
},
};
}
diff --git a/libs/datasource/state/src/user.ts b/libs/datasource/state/src/user.ts
index ce362cc72c..16aa62bc1c 100644
--- a/libs/datasource/state/src/user.ts
+++ b/libs/datasource/state/src/user.ts
@@ -63,7 +63,7 @@ const _useUserAndSpace = () => {
};
const _useUserAndSpacesForFreeLogin = () => {
- const [loading] = useAtom(_loadingAtom);
+ const [loading, setLoading] = useAtom(_loadingAtom);
useEffect(() => setLoading(false), []);
const BRAND_ID = 'AFFiNE';
@@ -78,6 +78,6 @@ const _useUserAndSpacesForFreeLogin = () => {
loading,
};
};
-export const useUserAndSpaces = process.env['NX_FREE_LOGIN']
+export const useUserAndSpaces = process.env['NX_LOCAL']
? _useUserAndSpacesForFreeLogin
: _useUserAndSpace;
diff --git a/package.json b/package.json
index 651bd68e94..49393c41c4 100644
--- a/package.json
+++ b/package.json
@@ -4,10 +4,11 @@
"license": "MIT",
"author": "AFFiNE <[email protected]>",
"scripts": {
- "start": "nx serve ligo-virgo",
- "start:free": "env-cmd -f .free.env nx serve ligo-virgo",
+ "start": "env-cmd -f .env.local nx serve ligo-virgo",
+ "start:affine": "nx serve ligo-virgo",
"start:keck": "nx serve keck",
"build": "nx build ligo-virgo",
+ "build:local": "env-cmd -f .env.local nx build ligo-virgo",
"build:keck": "nx build keck",
"build:analytic": "cross-env BUNDLE_ANALYZER=true nx build --skip-nx-cache",
"test": "nx run-many --target test --all",