mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
feat: isolated plugin system (#2742)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
"./server": "./src/server.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine/component": "workspace:*",
|
||||
"@toeverything/plugin-infra": "workspace:*",
|
||||
"foxact": "^0.2.7",
|
||||
"link-preview-js": "^3.0.4"
|
||||
|
||||
@@ -19,6 +19,7 @@ definePlugin(
|
||||
},
|
||||
stage: ReleaseStage.NIGHTLY,
|
||||
version: '0.0.1',
|
||||
commands: ['com.blocksuite.bookmark-block.get-bookmark-data-by-link'],
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
@@ -28,5 +29,19 @@ definePlugin(
|
||||
import.meta.webpackHot.accept('./blocksuite', () =>
|
||||
onHot(import('./blocksuite/index'))
|
||||
),
|
||||
},
|
||||
{
|
||||
load: () =>
|
||||
import(
|
||||
/* webpackIgnore: true */
|
||||
'./server'
|
||||
),
|
||||
hotModuleReload: onHot =>
|
||||
onHot(
|
||||
import(
|
||||
/* webpackIgnore: true */
|
||||
'./server'
|
||||
)
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ServerAdapter } from '@toeverything/plugin-infra/type';
|
||||
import { getLinkPreview } from 'link-preview-js';
|
||||
|
||||
type MetaData = {
|
||||
@@ -26,31 +27,41 @@ export interface PreviewType {
|
||||
favicons: string[];
|
||||
}
|
||||
|
||||
export default {
|
||||
getBookmarkDataByLink: async (_: unknown, url: string): Promise<MetaData> => {
|
||||
const previewData = (await getLinkPreview(url, {
|
||||
timeout: 6000,
|
||||
headers: {
|
||||
'user-agent': 'googlebot',
|
||||
},
|
||||
followRedirects: 'follow',
|
||||
}).catch(() => {
|
||||
return {
|
||||
title: '',
|
||||
siteName: '',
|
||||
description: '',
|
||||
images: [],
|
||||
videos: [],
|
||||
contentType: `text/html`,
|
||||
favicons: [],
|
||||
};
|
||||
})) as PreviewType;
|
||||
const adapter: ServerAdapter = affine => {
|
||||
affine.registerCommand(
|
||||
'com.blocksuite.bookmark-block.get-bookmark-data-by-link',
|
||||
async (url: string): Promise<MetaData> => {
|
||||
const previewData = (await getLinkPreview(url, {
|
||||
timeout: 6000,
|
||||
headers: {
|
||||
'user-agent': 'googlebot',
|
||||
},
|
||||
followRedirects: 'follow',
|
||||
}).catch(() => {
|
||||
return {
|
||||
title: '',
|
||||
siteName: '',
|
||||
description: '',
|
||||
images: [],
|
||||
videos: [],
|
||||
contentType: `text/html`,
|
||||
favicons: [],
|
||||
};
|
||||
})) as PreviewType;
|
||||
|
||||
return {
|
||||
title: previewData.title,
|
||||
description: previewData.description,
|
||||
icon: previewData.favicons[0],
|
||||
image: previewData.images[0],
|
||||
};
|
||||
},
|
||||
return {
|
||||
title: previewData.title,
|
||||
description: previewData.description,
|
||||
icon: previewData.favicons[0],
|
||||
image: previewData.images[0],
|
||||
};
|
||||
}
|
||||
);
|
||||
return () => {
|
||||
affine.unregisterCommand(
|
||||
'com.blocksuite.bookmark-block.get-bookmark-data-by-link'
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default adapter;
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
},
|
||||
{
|
||||
"path": "../../packages/plugin-infra"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/env"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine/component": "workspace:*",
|
||||
"@toeverything/plugin-infra": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Button, Input } from '@affine/component';
|
||||
import { rootStore } from '@affine/workspace/atom';
|
||||
import { rootStore } from '@toeverything/plugin-infra/manager';
|
||||
import type { PluginUIAdapter } from '@toeverything/plugin-infra/type';
|
||||
import { Provider, useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import type { ReactElement } from 'react';
|
||||
@@ -10,7 +10,7 @@ import { Conversation } from '../core/components/conversation';
|
||||
import { Divider } from '../core/components/divider';
|
||||
import { openAIApiKeyAtom, useChatAtoms } from '../core/hooks';
|
||||
|
||||
if (!environment.isServer) {
|
||||
if (typeof window === 'undefined') {
|
||||
import('@blocksuite/blocks').then(({ FormatQuickBar }) => {
|
||||
FormatQuickBar.customElements.push((_page, getSelection) => {
|
||||
const div = document.createElement('div');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import '@affine/env/config';
|
||||
|
||||
import { definePlugin } from '@toeverything/plugin-infra/manager';
|
||||
import { ReleaseStage } from '@toeverything/plugin-infra/type';
|
||||
|
||||
@@ -22,6 +20,7 @@ definePlugin(
|
||||
},
|
||||
stage: ReleaseStage.NIGHTLY,
|
||||
version: '0.0.1',
|
||||
commands: [],
|
||||
},
|
||||
{
|
||||
load: () => import('./UI/index'),
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
"include": ["./src"],
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"composite": true,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"references": [
|
||||
|
||||
Reference in New Issue
Block a user