Skip to content

Commit

Permalink
Fix Editor Build + Styling Tweaks (#742)
Browse files Browse the repository at this point in the history
Co-authored-by: Alder Whiteford <[email protected]>
  • Loading branch information
alderwhiteford and Alder Whiteford authored May 6, 2024
1 parent e406871 commit 2a7cfa2
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 81 deletions.
13 changes: 10 additions & 3 deletions frontend/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@generatesac/lib",
"version": "1.0.52",
"version": "1.0.53",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand All @@ -15,7 +15,8 @@
"test": "echo \"Woah there, we have no frontend tests as of right now. Let's just say we're passing.\" && exit 0",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
"format": "prettier --write .",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"build": "yarn clean && tsc",
"watch": "tsc --watch"
},
"dependencies": {
Expand All @@ -27,17 +28,23 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.1.0",
"react-redux": "^9.1.2",
"rollup-plugin-typescript2": "^0.36.0",
"zod": "^3.23.4"
},
"devDependencies": {
"@babel/core": "^7.24.5",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/react": "^18",
"eslint-plugin-prettier": "^5.1.3",
"postcss": "^8.4.38",
"prettier": "^3.2.4",
"rimraf": "^5.0.5",
"tslib": "^2.6.2",
"typescript": "^5.4.5"
},
"peerDependencies": {
"react": "^18.3.1"
},
"publishConfig": {
"@generatesac:registry": "https://npm.pkg.github.com"
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/lib/src/components/RichTextEditor/BlockNote.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use client';

import { Dispatch, SetStateAction } from 'react';

import { PartialBlock } from '@blocknote/core';
Expand All @@ -8,7 +6,8 @@ import { BlockNoteView, useCreateBlockNote } from '@blocknote/react';
import { EditorFonts, editorFonts, schema } from './config/config';
import SideBarMenu from './elements/SideBarMenu';
import SuggestionMenu from './elements/SuggestionMenu';
import './styles/BlockNote.styles.css';
import "@blocknote/react/style.css";
import FormattingToolbar from './elements/FormattingToolbar';

type EditorProps = {
description: PartialBlock[];
Expand Down Expand Up @@ -39,7 +38,6 @@ export default function Editor({

// Save the content to state on any change:
function onChange() {
console.log(editor.document);
const content: any = editor.document;
setDescription(content as Record<string, string>);
}
Expand All @@ -59,9 +57,11 @@ export default function Editor({
theme={editorFonts[fontFamily]}
slashMenu={false}
sideMenu={false}
formattingToolbar={false}
>
<SuggestionMenu editor={editor} />
<SideBarMenu />
<FormattingToolbar />
</BlockNoteView>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
BasicTextStyleButton,
BlockTypeSelect,
CreateLinkButton,
FormattingToolbar as Toolbar,
FormattingToolbarController,
ImageCaptionButton,
ReplaceImageButton,
blockTypeSelectItems,
} from "@blocknote/react";
import { LuHeading } from "react-icons/lu";

export default function FormattingToolbar() {
const suggestionItems = () => {
const itemsToRemove = [
'Image',
'Heading 1',
'Heading 2',
'Table'
];
const filteredSlashMenuItems = blockTypeSelectItems.filter((item) => {
if (item.name === 'Heading 3') {
item.name = 'Heading';
item.icon = LuHeading;
}

return !itemsToRemove.includes(item.name);
});

return filteredSlashMenuItems;
};

return (
<FormattingToolbarController
formattingToolbar={() => (
<Toolbar>
<BlockTypeSelect key={"blockTypeSelect"} items={suggestionItems()} />

<ImageCaptionButton key={"imageCaptionButton"} />
<ReplaceImageButton key={"replaceImageButton"} />

<BasicTextStyleButton
basicTextStyle={"bold"}
key={"boldStyleButton"}
/>
<BasicTextStyleButton
basicTextStyle={"italic"}
key={"italicStyleButton"}
/>
<BasicTextStyleButton
basicTextStyle={"underline"}
key={"underlineStyleButton"}
/>
<BasicTextStyleButton
basicTextStyle={"strike"}
key={"strikeStyleButton"}
/>
{/* Extra button to toggle code styles */}
<BasicTextStyleButton
key={"codeStyleButton"}
basicTextStyle={"code"}
/>

<CreateLinkButton key={"createLinkButton"} />
</Toolbar>
)}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@blocknote/react';

// Custom Side Menu button to remove the hovered block.
export function RemoveBlockButton(props: SideMenuProps) {
export default function RemoveBlockButton(props: SideMenuProps) {
const editor = useBlockNoteEditor();

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
SideMenu,
SideMenuController
} from '@blocknote/react';
import RemoveBlockButton from './RemoveBlockButton';

import { RemoveBlockButton } from './RemoveBlockButton';

export default function SideBarMenu() {
return (
Expand Down

This file was deleted.

Loading

0 comments on commit 2a7cfa2

Please sign in to comment.