Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling fix/default-font-2 into develop #977

Merged
merged 24 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ddf2092
feat(editor-toolbar): add Inter Variable font family option
ktun95 Feb 12, 2025
aa03d1e
feat(editor-toolbar): change default font family to Inter Variable
ktun95 Feb 13, 2025
4e6ed3b
feat(editor): initialize editor with empty text node
ktun95 Feb 13, 2025
5ff18ae
feat(editor-toolbar): create DictybaseToolbar component
ktun95 Feb 13, 2025
04a9045
feat: create editor-toolbar package with DictybaseToolbar
ktun95 Feb 13, 2025
ef09f5e
feat(editor-toolbar): add font selection to editor toolbar
ktun95 Feb 13, 2025
81bc9d2
fix(editor-toolbar): change main entrypoint from .tsx to .ts
ktun95 Feb 13, 2025
b9241db
fix(editor): use DEFAULT_FONT variable for initial editor state
ktun95 Feb 13, 2025
29b659e
feat(editor-toolbar): refactor FontFamilyDropdown to use fonts atom
ktun95 Feb 13, 2025
2d0670e
fix(atomConfigs.ts): reorder font list to place Inter Variable at the…
ktun95 Feb 13, 2025
d70a5f9
feat(editor): use fp-ts Option to handle initial editor state
ktun95 Feb 14, 2025
0c268f0
fix(useFontProperties.ts): change default font-family to DEFAULT_FONT
ktun95 Feb 14, 2025
33caaf0
feat(FontFamilyDropdown.tsx): add title attribute to Select component
ktun95 Feb 14, 2025
c39f398
fix(FontFamilyDropdown.tsx): use FontFamily type for event value
ktun95 Feb 14, 2025
7187cac
feat(editor): conditionally render toolbar based on props and remove …
ktun95 Feb 14, 2025
c73f769
feat(editor): render empty fragment if toolbar and editable are null
ktun95 Feb 17, 2025
aa91534
refactor: remove ButtonStates type definition
ktun95 Feb 18, 2025
57a1d83
refactor(editor-toolbar): encapsulate atom configs and expose them
ktun95 Feb 18, 2025
327f15d
refactor(resizable-image): move atoms export to the bottom of the file
ktun95 Feb 18, 2025
f6af4c5
feat(ui-dsc): add iconButton class to AuthorizedHeading
ktun95 Feb 18, 2025
3a63a21
feat(editor-toolbar): introduce DEFAULT_FONT_SIZE constant and remove…
ktun95 Feb 18, 2025
c6e5dda
refactor(FontSizeDropdown.tsx): change font size array generation to …
ktun95 Feb 18, 2025
0f54067
feat(editor): add default font size to initial state
ktun95 Feb 18, 2025
d667da4
feat(editor-toolbar): improve font size dropdown and atom configs
ktun95 Feb 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/editor-toolbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"version": "0.0.0",
"type": "module",
"main": "src/index.tsx",
"main": "./src/index.ts",
"scripts": {
"test": "vitest run",
"coverage": "vitest run --coverage",
Expand Down
31 changes: 7 additions & 24 deletions packages/editor-toolbar/src/components/FontFamilyDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,34 @@ import React from "react"
import { Select, MenuItem } from "@material-ui/core"
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext"
import { useAtom } from "jotai"
import { fontFamilyAtom } from "../context/atomConfigs"
import { fontFamilyAtom, fonts, FontFamily } from "../context/atomConfigs"
import { applyTextStyles } from "../utils/textStyles"
import { useToolbarItemStyles } from "../hooks/useToolbarItemStyles"

const defaultFontFamilyOptions = [
"Arial",
"Courier New",
"Georgia",
"Times New Roman",
"Trebuchet MS",
"Verdana",
]

type FontFamilySelectProperties = React.ChangeEvent<{
name?: string | undefined
value: unknown
}>

type FontFamilyDropdownProperties = {
fontOptions?: typeof defaultFontFamilyOptions
}

const title = "Font Family"

const FontFamilyDropdown = ({
fontOptions = defaultFontFamilyOptions,
}: FontFamilyDropdownProperties) => {
const FontFamilyDropdown = () => {
const [fontFamily] = useAtom(fontFamilyAtom)
const [editor] = useLexicalComposerContext()
const classes = useToolbarItemStyles()
const joinedClasses = `${classes.root} ${classes.spaced}`

const onFontFamilySelect = (event: FontFamilySelectProperties) => {
applyTextStyles(editor, { "font-family": event.target.value as string })
applyTextStyles(editor, { "font-family": event.target.value as FontFamily })
}

return (
<Select
title={title}
title="Font Family"
className={joinedClasses}
onChange={onFontFamilySelect}
value={fontFamily}>
{fontOptions.map((option) => (
<MenuItem key={option} value={option}>
{option}
{fonts.map((option) => (
<MenuItem key={option.name} value={option.value}>
{option.name}
</MenuItem>
))}
</Select>
Expand Down
8 changes: 4 additions & 4 deletions packages/editor-toolbar/src/components/FontSizeDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const title = "Font Size"
const genFontSize = (start: number, end: number) =>
[...new Array(end - start + 1).keys()]
.map((x) => x + start)
.map((x) => [`${x}px`, `${x}`])
.map((x) => ({ value: `${x}px`, label: `${x}` }))

const FontSizeDropdown = ({
start = 10,
Expand All @@ -41,9 +41,9 @@ const FontSizeDropdown = ({
className={joinedClasses}
onChange={onFontSizeSelect}
value={fontSize}>
{genFontSize(start, end).map(([option, size]) => (
<MenuItem key={option} value={option}>
{size}
{genFontSize(start, end).map(({ value, label }) => (
<MenuItem key={label} value={value}>
{label}
</MenuItem>
))}
</Select>
Expand Down
116 changes: 63 additions & 53 deletions packages/editor-toolbar/src/context/atomConfigs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { atom } from "jotai"
import { focusAtom } from "jotai-optics"

export type ButtonStates = "NORMAL" | "LOADING" | "DONE" | "ERROR"

export enum FontFamily {
enum FontFamily {
INTER_VARIABLE = "Inter Variable",
ARIAL = "Arial",
COURIER_NEW = "Courier New",
GEORGIA = "Georgia",
Expand All @@ -12,7 +11,20 @@ export enum FontFamily {
VERDANA = "Verdana",
}

export enum BlockTypes {
const DEFAULT_FONT = FontFamily.INTER_VARIABLE
const DEFAULT_FONT_SIZE = "15px"

const fonts = [
{ name: "Arial", value: FontFamily.ARIAL },
{ name: "Courier New", value: FontFamily.COURIER_NEW },
{ name: "Georgia", value: FontFamily.GEORGIA },
{ name: "Inter Variable", value: FontFamily.INTER_VARIABLE },
{ name: "Times New Roman", value: FontFamily.TIMES_NEW_ROMAN },
{ name: "Trebuchet MS", value: FontFamily.TREBUCHET_MS },
{ name: "Verdana", value: FontFamily.VERDANA },
]

enum BlockTypes {
PARAGRAPH = "flex-layout",
HEADING_ONE = "h1",
HEADING_TWO = "h2",
Expand All @@ -23,81 +35,79 @@ export enum BlockTypes {
QUOTE = "quote",
}

const FontSizes = [
"10px",
"11px",
"12px",
"13px",
"14px",
"15px",
"16px",
"17px",
"18px",
"19px",
"20px",
]

export const formatAtom = atom({
const formatAtom = atom({
isBold: false,
isItalic: false,
isUnderlined: false,
fontSize: FontSizes[5],
fontSize: DEFAULT_FONT_SIZE,
fontColor: "hsl(0, 0%, 0%)",
fontFamily: FontFamily.ARIAL,
fontFamily: DEFAULT_FONT,
blockType: BlockTypes.PARAGRAPH,
})
export const isBoldAtom = focusAtom(formatAtom, (optic) => optic.prop("isBold"))
export const isItalicAtom = focusAtom(formatAtom, (optic) =>
optic.prop("isItalic"),
)
export const isUnderlinedAtom = focusAtom(formatAtom, (optic) =>
optic.prop("isUnderlined"),
)
export const fontFamilyAtom = focusAtom(formatAtom, (optic) =>
optic.prop("fontFamily"),
)
export const fontSizeAtom = focusAtom(formatAtom, (optic) =>
optic.prop("fontSize"),
)
export const fontColorAtom = focusAtom(formatAtom, (optic) =>
optic.prop("fontColor"),
)

export const blockTypeAtom = focusAtom(formatAtom, (optic) =>
optic.prop("blockType"),
)

const historyAtom = atom({
canUndo: false,
canRedo: false,
})
export const canUndoAtom = focusAtom(historyAtom, (optic) =>
optic.prop("canUndo"),
)
export const canRedoAtom = focusAtom(historyAtom, (optic) =>
optic.prop("canRedo"),
)

export const openAtom = atom({
const openAtom = atom({
insertImage: false,
uploadFile: false,
insertTable: false,
tableActions: false,
colorPicker: false,
})

export const insertTableDialogOpenAtom = focusAtom(openAtom, (optic) =>
const isBoldAtom = focusAtom(formatAtom, (optic) => optic.prop("isBold"))
const isItalicAtom = focusAtom(formatAtom, (optic) => optic.prop("isItalic"))
const isUnderlinedAtom = focusAtom(formatAtom, (optic) =>
optic.prop("isUnderlined"),
)
const fontFamilyAtom = focusAtom(formatAtom, (optic) =>
optic.prop("fontFamily"),
)
const fontSizeAtom = focusAtom(formatAtom, (optic) => optic.prop("fontSize"))
const fontColorAtom = focusAtom(formatAtom, (optic) => optic.prop("fontColor"))

const blockTypeAtom = focusAtom(formatAtom, (optic) => optic.prop("blockType"))

const canUndoAtom = focusAtom(historyAtom, (optic) => optic.prop("canUndo"))
const canRedoAtom = focusAtom(historyAtom, (optic) => optic.prop("canRedo"))

const insertTableDialogOpenAtom = focusAtom(openAtom, (optic) =>
optic.prop("insertTable"),
)
export const insertImageDialogOpenAtom = focusAtom(openAtom, (optic) =>
const insertImageDialogOpenAtom = focusAtom(openAtom, (optic) =>
optic.prop("insertImage"),
)
export const uploadFileDialogOpenAtom = focusAtom(openAtom, (optic) =>
const uploadFileDialogOpenAtom = focusAtom(openAtom, (optic) =>
optic.prop("uploadFile"),
)
export const tableActionMenuOpenAtom = focusAtom(openAtom, (optic) =>
const tableActionMenuOpenAtom = focusAtom(openAtom, (optic) =>
optic.prop("tableActions"),
)
export const colorPickerOpenAtom = focusAtom(openAtom, (optic) =>
const colorPickerOpenAtom = focusAtom(openAtom, (optic) =>
optic.prop("colorPicker"),
)

export {
fonts,
DEFAULT_FONT,
DEFAULT_FONT_SIZE,
FontFamily,
BlockTypes,
isBoldAtom,
isItalicAtom,
isUnderlinedAtom,
fontFamilyAtom,
fontSizeAtom,
fontColorAtom,
blockTypeAtom,
canUndoAtom,
canRedoAtom,
insertTableDialogOpenAtom,
insertImageDialogOpenAtom,
uploadFileDialogOpenAtom,
tableActionMenuOpenAtom,
colorPickerOpenAtom,
}
3 changes: 2 additions & 1 deletion packages/editor-toolbar/src/hooks/useFontProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
fontSizeAtom,
fontFamilyAtom,
FontFamily,
DEFAULT_FONT,
} from "../context/atomConfigs"

const useFontProperties = () => {
Expand All @@ -30,7 +31,7 @@ const useFontProperties = () => {
$getSelectionStyleValueForProperty(
selection,
"font-family",
"Arial",
DEFAULT_FONT,
) as FontFamily,
)
}, [setIsBold, setIsItalic, setIsUnderlined, setFontSize, setFontFamily])
Expand Down
2 changes: 2 additions & 0 deletions packages/editor-toolbar/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./DictybaseToolbar"
export * from "./context/atomConfigs"
44 changes: 29 additions & 15 deletions packages/editor/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin"
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin"
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary"
import { Grid } from "@material-ui/core"
import { pipe } from "fp-ts/function"
import { match as Bmatch } from "fp-ts/boolean"
import {
getOrElse as OgetOrElse,
fromNullable as OfromNullable,
map as Omap,
} from "fp-ts/Option"
import { ImagePlugin } from "@dictybase/image-plugin"
import { WidthTablePlugin } from "@dictybase/width-table-plugin"
import { FlexLayoutPlugin } from "@dictybase/flex-layout-plugin"
Expand Down Expand Up @@ -40,9 +47,13 @@ const Editor = ({
plugins,
}: EditorProperties) => {
// eslint-disable-next-line unicorn/no-null
const initialEditorState = content?.editorState || initialStateString || null
const initialEditorState = pipe(
content,
OfromNullable,
Omap(({ editorState }) => editorState),
OgetOrElse(() => initialStateString as InitialEditorStateType),
)
const placeholderClasses = useEditorPlaceholderStyles()
// const persistencePluginStyles = usePersistencePluginStyles()
const editorAreaClasses = useEditorAreaStyles({ editable })

return (
Expand All @@ -60,20 +71,23 @@ const Editor = ({
<WidthTablePlugin />
<TableActionPlugin />
<HistoryPlugin />
{/* {content?.storageKey ? (
<LocalPersistencePlugin storageKey={content.storageKey} />
) : (
<></>
)} */}
<Grid container spacing={1} direction="column">
{/* <Grid item className={persistencePluginStyles.root}> */}
{toolbar ? <Grid item>{toolbar}</Grid> : <></>}
{editable ? (
<Grid item>
<DictybaseToolbar />
</Grid>
) : (
<></>
{pipe(
toolbar,
OfromNullable,
Omap((tb) => <Grid item>{tb}</Grid>),
OgetOrElse(() => <></>)
)}
{pipe(
editable,
Bmatch(
() => <></>,
() => (
<Grid item>
<DictybaseToolbar />
</Grid>
),
),
)}
<Grid item>
<div>
Expand Down
13 changes: 12 additions & 1 deletion packages/editor/src/initialState.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { DEFAULT_FONT, DEFAULT_FONT_SIZE } from "@dictybase/editor-toolbar"
/* eslint-disable unicorn/no-null */
const initialState = {
root: {
children: [
{
children: [
{
children: [],
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: `font-family: ${DEFAULT_FONT}; font-size: ${DEFAULT_FONT_SIZE}`,
text: "",
type: "text",
version: 1
}
],
direction: null,
format: "",
indent: 0,
Expand Down
9 changes: 4 additions & 5 deletions packages/resizable-image/src/state.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { atom } from "jotai"

export type ButtonStates = "NORMAL" | "LOADING" | "DONE" | "ERROR"
const ImageDimensionsAtom = atom({ width: 500, height: 500 })
const dialogOpenAtom = atom(false)
const isResizingAtom = atom(false)

export const ButtonStateAtom = atom<ButtonStates>("NORMAL")
export const ImageDimensionsAtom = atom({ width: 500, height: 500 })
export const dialogOpenAtom = atom(false)
export const isResizingAtom = atom(false)
export { ImageDimensionsAtom, dialogOpenAtom, isResizingAtom }
6 changes: 5 additions & 1 deletion packages/ui-dsc/src/home/AuthorizedHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ const AuthorizedHeading = () => {
<Grid item className={classes.header}>
<Typography variant="h1">
Welcome to Dicty Stock Center (DSC)
<IconButton aria-label="Edit DSC Intro" size="medium" onClick={onClick}>
<IconButton
aria-label="Edit DSC Intro"
size="medium"
onClick={onClick}
className={classes.iconButton}>
<EditIcon className={classes.icon} />
</IconButton>
</Typography>
Expand Down
Loading