mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor(electron): server side plugin (#3360)
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
# `@affine/bookmark-block`
|
||||
|
||||
> Moved to [@affine/bookmark-plugin](../bookmark)
|
||||
>
|
||||
> A block for bookmarking a website
|
||||
|
||||

|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB |
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "@affine/bookmark-block",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./server": "./src/server.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node ./scripts/build.mjs",
|
||||
"dev": "node ./scripts/dev.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@toeverything/plugin-infra": "workspace:*",
|
||||
"link-preview-js": "^3.0.4"
|
||||
},
|
||||
"version": "0.7.0-canary.52"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "@affine/bookmark-block",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "library",
|
||||
"root": "plugins/bookmark-block",
|
||||
"sourceRoot": "plugins/bookmark-block/src",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "nx:run-script",
|
||||
"dependsOn": ["^build"],
|
||||
"options": {
|
||||
"script": "build"
|
||||
},
|
||||
"outputs": ["{workspaceRoot}/apps/electron/dist/plugins/bookmark-block"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
import { build } from 'esbuild';
|
||||
|
||||
import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
await build({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: [
|
||||
// server.ts
|
||||
'link-preview-js',
|
||||
// ui.ts
|
||||
'@toeverything/plugin-infra',
|
||||
'@affine/component',
|
||||
'@blocksuite/store',
|
||||
'@blocksuite/blocks',
|
||||
'react',
|
||||
'react-dom',
|
||||
'foxact',
|
||||
],
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
import { context } from 'esbuild';
|
||||
|
||||
import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
const plugin = await context({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: [
|
||||
// server.ts
|
||||
'link-preview-js',
|
||||
// ui.ts
|
||||
'@toeverything/plugin-infra',
|
||||
'@affine/component',
|
||||
'@blocksuite/store',
|
||||
'@blocksuite/blocks',
|
||||
'react',
|
||||
'react-dom',
|
||||
'foxact',
|
||||
],
|
||||
});
|
||||
|
||||
await plugin.watch();
|
||||
@@ -1,34 +0,0 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
export const rootDir = fileURLToPath(new URL('../../..', import.meta.url));
|
||||
export const electronOutputDir = resolve(
|
||||
rootDir,
|
||||
'apps',
|
||||
'electron',
|
||||
'dist',
|
||||
'plugins'
|
||||
);
|
||||
export const pluginDir = resolve(rootDir, 'plugins');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pluginDirName {string}
|
||||
* @return {import('esbuild').BuildOptions}
|
||||
*/
|
||||
export function definePluginServerConfig(pluginDirName) {
|
||||
const pluginRootDir = resolve(pluginDir, pluginDirName);
|
||||
const mainEntryFile = resolve(pluginRootDir, 'src/index.ts');
|
||||
const serverOutputDir = resolve(electronOutputDir, pluginDirName);
|
||||
return {
|
||||
entryPoints: [mainEntryFile],
|
||||
platform: 'neutral',
|
||||
format: 'esm',
|
||||
outExtension: {
|
||||
'.js': '.mjs',
|
||||
},
|
||||
outdir: serverOutputDir,
|
||||
bundle: true,
|
||||
splitting: true,
|
||||
};
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { definePlugin } from '@toeverything/plugin-infra/manager';
|
||||
import { ReleaseStage } from '@toeverything/plugin-infra/type';
|
||||
|
||||
definePlugin(
|
||||
{
|
||||
id: 'com.blocksuite.bookmark-block',
|
||||
name: {
|
||||
fallback: 'BlockSuite Bookmark Block',
|
||||
i18nKey: 'com.blocksuite.bookmark.name',
|
||||
},
|
||||
description: {
|
||||
fallback: 'Bookmark block',
|
||||
},
|
||||
publisher: {
|
||||
name: {
|
||||
fallback: 'AFFiNE',
|
||||
},
|
||||
link: 'https://affine.pro',
|
||||
},
|
||||
stage: ReleaseStage.NIGHTLY,
|
||||
version: '0.0.1',
|
||||
commands: ['com.blocksuite.bookmark-block.get-bookmark-data-by-link'],
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
load: () => import('./server'),
|
||||
hotModuleReload: onHot => onHot(import('./server')),
|
||||
}
|
||||
);
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["./src"],
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "../../packages/component"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/plugin-infra"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,13 +4,15 @@
|
||||
"affinePlugin": {
|
||||
"release": true,
|
||||
"entry": {
|
||||
"core": "./src/index.ts"
|
||||
"core": "./src/index.ts",
|
||||
"server": "./src/server.ts"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine/component": "workspace:*",
|
||||
"@blocksuite/icons": "^2.1.27",
|
||||
"@toeverything/plugin-infra": "workspace:*",
|
||||
"foxact": "^0.2.17"
|
||||
"foxact": "^0.2.17",
|
||||
"link-preview-js": "^3.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ServerAdapter } from '@toeverything/plugin-infra/type';
|
||||
import type { ServerContext } from '@toeverything/plugin-infra/server';
|
||||
import { getLinkPreview } from 'link-preview-js';
|
||||
|
||||
type MetaData = {
|
||||
@@ -27,8 +27,8 @@ export interface PreviewType {
|
||||
favicons: string[];
|
||||
}
|
||||
|
||||
const adapter: ServerAdapter = affine => {
|
||||
affine.registerCommand(
|
||||
export const entry = (context: ServerContext) => {
|
||||
context.registerCommand(
|
||||
'com.blocksuite.bookmark-block.get-bookmark-data-by-link',
|
||||
async (url: string): Promise<MetaData> => {
|
||||
const previewData = (await getLinkPreview(url, {
|
||||
@@ -58,10 +58,8 @@ const adapter: ServerAdapter = affine => {
|
||||
}
|
||||
);
|
||||
return () => {
|
||||
affine.unregisterCommand(
|
||||
context.unregisterCommand(
|
||||
'com.blocksuite.bookmark-block.get-bookmark-data-by-link'
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default adapter;
|
||||
@@ -1,14 +1,13 @@
|
||||
import { Button, FlexWrapper, Input } from '@affine/component';
|
||||
import { SettingRow } from '@affine/component/setting-components';
|
||||
import { SettingWrapper } from '@affine/component/setting-components';
|
||||
import type { PluginUIAdapter } from '@toeverything/plugin-infra/type';
|
||||
import { useAtom } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
import { type ReactElement, useCallback } from 'react';
|
||||
|
||||
import { openAIApiKeyAtom } from '../core/hooks';
|
||||
import { conversationHistoryDBName } from '../core/langchain/message-history';
|
||||
|
||||
export const DebugContent: PluginUIAdapter['debugContent'] = () => {
|
||||
export const DebugContent = (): ReactElement => {
|
||||
const [key, setKey] = useAtom(openAIApiKeyAtom);
|
||||
const desc = (
|
||||
<>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { PluginUIAdapter } from '@toeverything/plugin-infra/type';
|
||||
import { createElement } from 'react';
|
||||
|
||||
import { DebugContent } from './debug-content';
|
||||
import { DetailContent } from './detail-content';
|
||||
import { HeaderItem } from './header-item';
|
||||
|
||||
export default {
|
||||
headerItem: props => createElement(HeaderItem, props),
|
||||
detailContent: props => createElement(DetailContent, props),
|
||||
debugContent: props => createElement(DebugContent, props),
|
||||
} satisfies Partial<PluginUIAdapter>;
|
||||
Reference in New Issue
Block a user