From 2ae716f0c7e3e8168edb61b87b31da88a516c441 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 7 Nov 2024 09:21:56 +0800 Subject: [PATCH] chore: init converter module --- README.md | 142 ++----------------------------- web/converter/package.json | 38 +++++++++ web/converter/tsconfig.json | 30 +++++++ web/converter/tsconfig.node.json | 10 +++ web/converter/vite.config.mts | 32 +++++++ 5 files changed, 117 insertions(+), 135 deletions(-) create mode 100644 web/converter/package.json create mode 100644 web/converter/tsconfig.json create mode 100644 web/converter/tsconfig.node.json create mode 100644 web/converter/vite.config.mts diff --git a/README.md b/README.md index 6c956ff..368c197 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ Additionally, we aim to share insights from the article titled [Why Chatbots Are Not the Future](https://wattenberger.com/thoughts/boo-chatbots). Our vision includes delivering a writing experience akin to [Copilot for Docs](https://githubnext.com/projects/copilot-for-docs/) in documentation. -About name: In the documentary "10 Years with Hayao Miyazaki" the esteemed artist (宫崎骏, 宮﨑駿/みやざきはやお) chooses a 3B -pencil, -deeming conventional ones too inflexible for his creative process. Let us pay homage to his lofty ideals. +About name: In the documentary "10 Years with Hayao Miyazaki" the esteemed artist (宫崎骏, 宮﨑駿/みやざきはやお) +chooses a 3B +pencil, deeming conventional ones too inflexible for his creative process. Let us pay homage to his lofty ideals.

architecture diagram @@ -36,6 +36,10 @@ Online Demo: [https://editor.unitmesh.cc/](https://editor.unitmesh.cc/) Demo Videos: [开源 AI 原生编辑器 Studio B3](https://www.bilibili.com/video/BV1E64y1j7hJ/) +## Quick Start + +See in [web/core](web/core/README.md) + ## Features - Immersive generation. Provides an immersive content generation experience, supporting various formats to allow users @@ -70,138 +74,6 @@ Demo Videos: [开源 AI 原生编辑器 Studio B3](https://www.bilibili.com/vide * Change: The effect produced by extensions may depend on other aspects of the system state, or be explicitly reconfigured. -## Usage - -See in [web-core](./web/core/README.md) - -### Install - -```bash -npm install -g @studio-b3/web-core -``` - -Use - -```typescript jsx -import Head from 'next/head' - -import "../styles/editor-styles.css" -import { LiveEditor } from '@studio-b3/web-core' -import '@/i18n/i18n'; - -export default function Home() { - return ( -

- - Studio B3 - all you need is editor! - - - -
-
- -
-
-
- ); -} -``` - -### Custom Menu examples - -```typescript -const BubbleMenu: PromptAction[] = [ - { - name: 'Polish', - i18Name: true, - template: `You are an assistant helping to polish sentence. Output in markdown format. \n ###${DefinedVariable.SELECTION}###`, - facetType: FacetType.BUBBLE_MENU, - outputForm: OutputForm.STREAMING, - }, - { - name: 'Similar Chunk', - i18Name: true, - template: `You are an assistant helping to find similar content. Output in markdown format. \n ###${DefinedVariable.SELECTION}###`, - facetType: FacetType.BUBBLE_MENU, - outputForm: OutputForm.STREAMING, - }, - { - name: 'Simplify Content', - i18Name: true, - template: `You are an assistant helping to simplify content. Output in markdown format. \n ###${DefinedVariable.SELECTION}###`, - facetType: FacetType.BUBBLE_MENU, - outputForm: OutputForm.STREAMING, - changeForm: ChangeForm.DIFF, - }, -]; -``` - -Custom Samples: - - -```tsx -// custom api endpoint -const actionExecutor: AiActionExecutor = new AiActionExecutor(); -actionExecutor.setEndpointUrl("/api/chat"); - -// custom prompts -const instance = PromptsManager.getInstance(); -const map = customSlashActions?.map((action) => { - return { - name: action.name, - i18Name: false, - template: `123125`, - facetType: FacetType.SLASH_COMMAND, - outputForm: OutputForm.STREAMING, - action: async (editor: Editor) => { - if (action.action) { - await action.action(editor); - } - }, - }; -}) || []; - -// set prompts group to default article group -instance.updateActionsMap("article", ArticlePrompts.concat(map)); - -const editor = useEditor({ - extensions: setupExtensions(instance, actionExecutor).concat([ - /// configure for copy and paste - Markdown.configure({ - transformPastedText: true, - transformCopiedText: false, - }), - ]), - content: md.render(value), - immediatelyRender: false, - editorProps: { - attributes: { - class: "prose lg:prose-xl bb-editor-inner", - }, - }, - onUpdate: ({ editor }) => { - if (onChange) { - /// update markdown - const schema = editor.state.schema; - try { - const serializer = DOMSerializer.fromSchema(schema); - const serialized: HTMLElement | DocumentFragment = serializer.serializeFragment(editor.state.doc.content); - - const html: string = Array.from(serialized.childNodes) - .map((node: ChildNode) => (node as HTMLElement).outerHTML) - .join(""); - - const turndownService = new TurndownService(); - const markdown = turndownService.turndown(html); - onChange(markdown); - } catch (e) { - console.error(e); - } - } - }, -}); -``` - ## Refs ### Tiptap Editor extensions diff --git a/web/converter/package.json b/web/converter/package.json new file mode 100644 index 0000000..e6ad3cb --- /dev/null +++ b/web/converter/package.json @@ -0,0 +1,38 @@ +{ + "name": "@studio-b3/converter", + "version": "0.0.2", + "type": "module", + "main": "dist/index.mjs", + "types": "dist-types/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.mjs" + }, + "./package.json": "./package.json" + }, + "typesVersions": { + "*": { + "*": [ + "./dist-types/index.d.ts", + "./dist-types/*" + ] + } + }, + "sideEffects": false, + "files": [ + "dist", + "dist-types", + "src" + ], + "scripts": { + "watch": "vite build --watch", + "build": "vite build", + "lint": "eslint . --ext ts,tsx,.cjs --report-unused-disable-directives --max-warnings 0", + "lint:fix": "eslint . --ext .ts,.cjs --fix --fix-type [problem,suggestion]" + }, + "dependencies": { + + }, + "private": false, + "devDependencies": {} +} diff --git a/web/converter/tsconfig.json b/web/converter/tsconfig.json new file mode 100644 index 0000000..cd9a232 --- /dev/null +++ b/web/converter/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": [ + "ES2020" + ], + "module": "ESNext", + "skipLibCheck": true, + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + /* Linting */ + // "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": [ + "src" + ], + "references": [ + { + "path": "./tsconfig.node.json" + } + ] +} \ No newline at end of file diff --git a/web/converter/tsconfig.node.json b/web/converter/tsconfig.node.json new file mode 100644 index 0000000..a858353 --- /dev/null +++ b/web/converter/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.mts"] +} diff --git a/web/converter/vite.config.mts b/web/converter/vite.config.mts new file mode 100644 index 0000000..68f94ec --- /dev/null +++ b/web/converter/vite.config.mts @@ -0,0 +1,32 @@ +import { defineConfig } from 'vite'; +import checker from 'vite-plugin-checker'; +import dts from 'vite-plugin-dts'; +import { externalizeDeps } from 'vite-plugin-externalize-deps'; + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [ + checker({ + typescript: true, + }), + externalizeDeps(), + dts({ + outDir: './dist-types', + }), + ], + build: { + copyPublicDir: false, + lib: { + entry: 'src/index.ts', + formats: ['es'], + }, + rollupOptions: { + output: { + dir: 'dist', + exports: 'named', + entryFileNames: '[name].mjs', + chunkFileNames: '[name].mjs', + }, + }, + }, +});