Skip to content

Commit

Permalink
chore(deps): update floating-ui and remove handlebars
Browse files Browse the repository at this point in the history
Update dependencies for floating-ui packages to the latest versions. Additionally, remove the Handlebars dependency and replace it with a custom render function for templates.
  • Loading branch information
phodal committed Oct 9, 2024
1 parent f7f43bc commit 9b03d2c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 50 deletions.
59 changes: 23 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions web/core/lib/editor/menu/menu-bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { newAdvice } from '@/editor/extensions/advice/advice';
import { ToolbarMenu } from '@/editor/menu/toolbar-menu';
import { BounceLoader } from 'react-spinners';

export const MenuBubble = ({ editor }: {
export const MenuBubble = ({ editor } : {
editor: Editor
}) => {
const [loading, setLoading] = React.useState(false);
Expand All @@ -28,15 +28,15 @@ export const MenuBubble = ({ editor }: {

innerSmartMenus.push({
name: '扩写',
template: `根据如下的内容扩写,只返回三句,限 100 字以内。###{{${DefinedVariable.SELECTION}}}###。`,
template: `根据如下的内容扩写,只返回三句,限 100 字以内。###\${${DefinedVariable.SELECTION}}###。`,
facetType: FacetType.BUBBLE_MENU,
changeForm: ChangeForm.DIFF,
outputForm: OutputForm.TEXT
});

innerSmartMenus.push({
name: '润色',
template: `请润色并重写如下的内容:###{{${DefinedVariable.SELECTION}}}###`,
template: `请润色并重写如下的内容:###\${${DefinedVariable.SELECTION}}###`,
facetType: FacetType.BUBBLE_MENU,
changeForm: ChangeForm.DIFF,
outputForm: OutputForm.TEXT
Expand Down
14 changes: 7 additions & 7 deletions web/core/lib/editor/prompts/article-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ export const ToolbarMenuPrompts: PromptAction[] = [
{
name: 'Generate Outline',
i18Name: true,
template: `You are an assistant helping a user to generate an outline. Output in markdown format. ###{{${DefinedVariable.BEFORE_CURSOR}}}###`,
template: `You are an assistant helping a user to generate an outline. Output in markdown format. ###\${${DefinedVariable.BEFORE_CURSOR}}###`,
facetType: FacetType.TOOLBAR_MENU,
outputForm: OutputForm.STREAMING,
},
{
name: 'Continue writing',
i18Name: true,
template: `You are an assistant helping a user write a document. Output how the document continues, no more than 3 sentences. ###{{${DefinedVariable.BEFORE_CURSOR}}}###`,
template: `You are an assistant helping a user write a document. Output how the document continues, no more than 3 sentences. ###\${${DefinedVariable.BEFORE_CURSOR}}###`,
facetType: FacetType.TOOLBAR_MENU,
outputForm: OutputForm.STREAMING,
},
{
name: 'Help Me Write',
i18Name: true,
template: ` You are an assistant helping a user write more content in a document based on a prompt. Output in markdown format. ###{{${DefinedVariable.BEFORE_CURSOR}}}###`,
template: ` You are an assistant helping a user write more content in a document based on a prompt. Output in markdown format. ###\${${DefinedVariable.BEFORE_CURSOR}}###`,
facetType: FacetType.TOOLBAR_MENU,
outputForm: OutputForm.STREAMING,
},
{
name: 'Spelling and Grammar',
i18Name: true,
template: `You are an assistant helping a user to check spelling and grammar. Output in markdown format. ###{{${DefinedVariable.BEFORE_CURSOR}}}###`,
template: `You are an assistant helping a user to check spelling and grammar. Output in markdown format. ###\${${DefinedVariable.BEFORE_CURSOR}}###`,
facetType: FacetType.TOOLBAR_MENU,
outputForm: OutputForm.STREAMING,
},
Expand All @@ -40,7 +40,7 @@ export const BubbleMenuPrompts: PromptAction[] = [
{
name: 'Translate',
i18Name: true,
template: `You are an assistant helping to translate a sentence. Output in markdown format. \n ###{{${DefinedVariable.SELECTION}}}###`,
template: `You are an assistant helping to translate a sentence. Output in markdown format. \n ###\${${DefinedVariable.SELECTION}}###`,
facetType: FacetType.BUBBLE_MENU,
outputForm: OutputForm.STREAMING,
}
Expand All @@ -50,14 +50,14 @@ export const SlashCommandsPrompts: PromptAction[] = [
{
name: 'Summarize',
i18Name: true,
template: `You are an assistant helping to summarize a article. Output in markdown format. \n ###{{${DefinedVariable.BEFORE_CURSOR}}}###`,
template: `You are an assistant helping to summarize a article. Output in markdown format. \n ###\${${DefinedVariable.BEFORE_CURSOR}}###`,
facetType: FacetType.SLASH_COMMAND,
outputForm: OutputForm.STREAMING
},
{
name: 'Continue writing',
i18Name: true,
template: `You are an assistant helping a user write a document. Output how the document continues, no more than 3 sentences. ###{{${DefinedVariable.BEFORE_CURSOR}}}###`,
template: `You are an assistant helping a user write a document. Output how the document continues, no more than 3 sentences. ###\${${DefinedVariable.BEFORE_CURSOR}}###`,
facetType: FacetType.SLASH_COMMAND,
outputForm: OutputForm.STREAMING,
}
Expand Down
22 changes: 19 additions & 3 deletions web/core/lib/editor/prompts/prompts-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Handlebars from 'handlebars'
import i18next from "i18next";
import { DefinedVariable, FacetType, PromptAction } from "@/editor/defs/custom-action.type";
import ArticlePrompts from "@/editor/prompts/article-prompts";
Expand Down Expand Up @@ -50,11 +49,28 @@ export class PromptsManager {
}

compile(string: string, data: object) {
const template = Handlebars.compile(string)
return template(data)
const template = render(string, data)
console.log(template)
return template
}

saveBackgroundContext(context: string) {
(this as any).backgroundContext = context
}
}

function render(template: string, data: object) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
return template.replace(/\$\{([\s\S]+?)\}/g, (match, p1) => {
const keys = p1.trim().split('.');
let value = data;
for (const key of keys) {
value = value[key];
if (value === undefined) {
return '';
}
}
return value;
});
}
1 change: 0 additions & 1 deletion web/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"@tiptap/starter-kit": "^2.1.12",
"@tiptap/suggestion": "^2.1.12",
"clsx": "^2.0.0",
"handlebars": "^4.7.8",
"i18next": "^23.7.6",
"i18next-browser-languagedetector": "^7.2.0",
"markdown-it": "^13.0.2",
Expand Down

0 comments on commit 9b03d2c

Please sign in to comment.