Skip to content

Commit

Permalink
chore: init converter module
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 7, 2024
1 parent c26cd2c commit 2ae716f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 135 deletions.
142 changes: 7 additions & 135 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<p align="center">
<img src="docs/architecture.svg" alt="architecture diagram" />
Expand All @@ -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
Expand Down Expand Up @@ -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 (
<div className={styles.container}>
<Head>
<title>Studio B3 - all you need is editor!</title>
<link rel="icon" href="/favicon.ico" />
</Head>

<main>
<div>
<LiveEditor />
</div>
</main>
</div>
);
}
```

### 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
Expand Down
38 changes: 38 additions & 0 deletions web/converter/package.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
30 changes: 30 additions & 0 deletions web/converter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
10 changes: 10 additions & 0 deletions web/converter/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.mts"]
}
32 changes: 32 additions & 0 deletions web/converter/vite.config.mts
Original file line number Diff line number Diff line change
@@ -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',
},
},
},
});

0 comments on commit 2ae716f

Please sign in to comment.