Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kguzek committed Jan 5, 2025
1 parent 882ab51 commit 93bd71a
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 181 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@types/next": "^8.0.7",
"@types/node": "^22.10.2",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@types/tailwindcss": "^3.0.11",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.49",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
import { DropdownButton, DropdownCategoryTitle } from '@/components/ui/Dropdown'
import { Icon } from '@/components/ui/Icon'
import { Surface } from '@/components/ui/Surface'
import { Toolbar } from '@/components/ui/Toolbar'
import * as Dropdown from '@radix-ui/react-dropdown-menu'
import { useCallback } from 'react'
import { DropdownButton } from "@/components/ui/Dropdown";
import { Icon } from "@/components/ui/Icon";
import { Surface } from "@/components/ui/Surface";
import { Toolbar } from "@/components/ui/Toolbar";
import * as Dropdown from "@radix-ui/react-dropdown-menu";
import { useCallback } from "react";

const FONT_SIZES = [
{ label: 'Smaller', value: '12px' },
{ label: 'Small', value: '14px' },
{ label: 'Medium', value: '' },
{ label: 'Large', value: '18px' },
{ label: 'Extra Large', value: '24px' },
]
{ label: "Smaller", value: "12px" },
{ label: "Small", value: "14px" },
{ label: "Medium", value: "" },
{ label: "Large", value: "18px" },
{ label: "Extra Large", value: "24px" },
];

export type FontSizePickerProps = {
onChange: (value: string) => void // eslint-disable-line no-unused-vars
value: string
}
onChange: (value: string) => void; // eslint-disable-line no-unused-vars
value: string;
};

export const FontSizePicker = ({ onChange, value }: FontSizePickerProps) => {
const currentValue = FONT_SIZES.find(size => size.value === value)
const currentSizeLabel = currentValue?.label.split(' ')[0] || 'Medium'
const currentValue = FONT_SIZES.find((size) => size.value === value);
const currentSizeLabel = currentValue?.label.split(" ")[0] || "Medium";

const selectSize = useCallback((size: string) => () => onChange(size), [onChange])
const selectSize = useCallback(
(size: string) => () => onChange(size),
[onChange],
);

return (
<Dropdown.Root>
<Dropdown.Trigger asChild>
<Toolbar.Button active={!!currentValue?.value}>
{currentSizeLabel}
<Icon name="ChevronDown" className="w-2 h-2" />
<Icon name="ChevronDown" className="h-2 w-2" />
</Toolbar.Button>
</Dropdown.Trigger>
<Dropdown.Content asChild>
<Surface className="flex flex-col gap-1 px-2 py-4">
{FONT_SIZES.map(size => (
{FONT_SIZES.map((size) => (
<DropdownButton
isActive={value === size.value}
onClick={selectSize(size.value)}
Expand All @@ -46,5 +49,5 @@ export const FontSizePicker = ({ onChange, value }: FontSizePickerProps) => {
</Surface>
</Dropdown.Content>
</Dropdown.Root>
)
}
);
};
Original file line number Diff line number Diff line change
@@ -1,90 +1,104 @@
import type { Language } from '@/extensions/Ai'
import { Editor } from '@tiptap/react'
import { useCallback } from 'react'
import { Editor } from "@tiptap/react";
import { useCallback } from "react";

export const useTextmenuCommands = (editor: Editor) => {
const onBold = useCallback(() => editor.chain().focus().toggleBold().run(), [editor])
const onItalic = useCallback(() => editor.chain().focus().toggleItalic().run(), [editor])
const onStrike = useCallback(() => editor.chain().focus().toggleStrike().run(), [editor])
const onUnderline = useCallback(() => editor.chain().focus().toggleUnderline().run(), [editor])
const onCode = useCallback(() => editor.chain().focus().toggleCode().run(), [editor])
const onCodeBlock = useCallback(() => editor.chain().focus().toggleCodeBlock().run(), [editor])

const onSubscript = useCallback(() => editor.chain().focus().toggleSubscript().run(), [editor])
const onSuperscript = useCallback(() => editor.chain().focus().toggleSuperscript().run(), [editor])
const onAlignLeft = useCallback(() => editor.chain().focus().setTextAlign('left').run(), [editor])
const onAlignCenter = useCallback(() => editor.chain().focus().setTextAlign('center').run(), [editor])
const onAlignRight = useCallback(() => editor.chain().focus().setTextAlign('right').run(), [editor])
const onAlignJustify = useCallback(() => editor.chain().focus().setTextAlign('justify').run(), [editor])

const onChangeColor = useCallback((color: string) => editor.chain().setColor(color).run(), [editor])
const onClearColor = useCallback(() => editor.chain().focus().unsetColor().run(), [editor])

const onChangeHighlight = useCallback((color: string) => editor.chain().setHighlight({ color }).run(), [editor])
const onClearHighlight = useCallback(() => editor.chain().focus().unsetHighlight().run(), [editor])
const onBold = useCallback(
() => editor.chain().focus().toggleBold().run(),
[editor],
);
const onItalic = useCallback(
() => editor.chain().focus().toggleItalic().run(),
[editor],
);
const onStrike = useCallback(
() => editor.chain().focus().toggleStrike().run(),
[editor],
);
const onUnderline = useCallback(
() => editor.chain().focus().toggleUnderline().run(),
[editor],
);
const onCode = useCallback(
() => editor.chain().focus().toggleCode().run(),
[editor],
);
const onCodeBlock = useCallback(
() => editor.chain().focus().toggleCodeBlock().run(),
[editor],
);

const onSimplify = useCallback(
() => editor.chain().focus().aiSimplify({ stream: true, format: 'rich-text' }).run(),
const onSubscript = useCallback(
() => editor.chain().focus().toggleSubscript().run(),
[editor],
)
const onEmojify = useCallback(
() => editor.chain().focus().aiEmojify({ stream: true, format: 'rich-text' }).run(),
);
const onSuperscript = useCallback(
() => editor.chain().focus().toggleSuperscript().run(),
[editor],
)
const onCompleteSentence = useCallback(
() => editor.chain().focus().aiComplete({ stream: true, format: 'rich-text' }).run(),
);
const onAlignLeft = useCallback(
() => editor.chain().focus().setTextAlign("left").run(),
[editor],
)
const onFixSpelling = useCallback(
() => editor.chain().focus().aiFixSpellingAndGrammar({ stream: true, format: 'rich-text' }).run(),
);
const onAlignCenter = useCallback(
() => editor.chain().focus().setTextAlign("center").run(),
[editor],
)
const onMakeLonger = useCallback(
() => editor.chain().focus().aiExtend({ stream: true, format: 'rich-text' }).run(),
);
const onAlignRight = useCallback(
() => editor.chain().focus().setTextAlign("right").run(),
[editor],
)
const onMakeShorter = useCallback(
() => editor.chain().focus().aiShorten({ stream: true, format: 'rich-text' }).run(),
);
const onAlignJustify = useCallback(
() => editor.chain().focus().setTextAlign("justify").run(),
[editor],
)
const onTldr = useCallback(() => editor.chain().focus().aiTldr({ stream: true, format: 'rich-text' }).run(), [editor])
const onTone = useCallback(
(tone: string) => editor.chain().focus().aiAdjustTone(tone, { stream: true, format: 'rich-text' }).run(),
);

const onChangeColor = useCallback(
(color: string) => editor.chain().setColor(color).run(),
[editor],
)
const onTranslate = useCallback(
(language: Language) => editor.chain().focus().aiTranslate(language, { stream: true, format: 'rich-text' }).run(),
);
const onClearColor = useCallback(
() => editor.chain().focus().unsetColor().run(),
[editor],
)
);

const onChangeHighlight = useCallback(
(color: string) => editor.chain().setHighlight({ color }).run(),
[editor],
);
const onClearHighlight = useCallback(
() => editor.chain().focus().unsetHighlight().run(),
[editor],
);

const onLink = useCallback(
(url: string, inNewTab?: boolean) =>
editor
.chain()
.focus()
.setLink({ href: url, target: inNewTab ? '_blank' : '' })
.setLink({ href: url, target: inNewTab ? "_blank" : "" })
.run(),
[editor],
)
);

const onSetFont = useCallback(
(font: string) => {
if (!font || font.length === 0) {
return editor.chain().focus().unsetFontFamily().run()
return editor.chain().focus().unsetFontFamily().run();
}
return editor.chain().focus().setFontFamily(font).run()
return editor.chain().focus().setFontFamily(font).run();
},
[editor],
)
);

const onSetFontSize = useCallback(
(fontSize: string) => {
if (!fontSize || fontSize.length === 0) {
return editor.chain().focus().unsetFontSize().run()
return editor.chain().focus().unsetFontSize().run();
}
return editor.chain().focus().setFontSize(fontSize).run()
return editor.chain().focus().setFontSize(fontSize).run();
},
[editor],
)
);

return {
onBold,
Expand All @@ -105,15 +119,6 @@ export const useTextmenuCommands = (editor: Editor) => {
onClearHighlight,
onSetFont,
onSetFontSize,
onSimplify,
onEmojify,
onCompleteSentence,
onFixSpelling,
onMakeLonger,
onMakeShorter,
onTldr,
onTone,
onTranslate,
onLink,
}
}
};
};
Original file line number Diff line number Diff line change
@@ -1,53 +1,56 @@
import { Editor, useEditorState } from '@tiptap/react'
import { useCallback, useMemo } from 'react'
import { ShouldShowProps } from '../../types'
import { isCustomNodeSelected, isTextSelected } from '@/lib/utils'
import { Editor, useEditorState } from "@tiptap/react";
import { useCallback } from "react";
import { ShouldShowProps } from "../../types";
import { isCustomNodeSelected, isTextSelected } from "@/lib/utils";

export const useTextmenuStates = (editor: Editor) => {
const states = useEditorState({
editor,
selector: ctx => {
selector: (ctx) => {
return {
isBold: ctx.editor.isActive('bold'),
isItalic: ctx.editor.isActive('italic'),
isStrike: ctx.editor.isActive('strike'),
isUnderline: ctx.editor.isActive('underline'),
isCode: ctx.editor.isActive('code'),
isSubscript: ctx.editor.isActive('subscript'),
isSuperscript: ctx.editor.isActive('superscript'),
isAlignLeft: ctx.editor.isActive({ textAlign: 'left' }),
isAlignCenter: ctx.editor.isActive({ textAlign: 'center' }),
isAlignRight: ctx.editor.isActive({ textAlign: 'right' }),
isAlignJustify: ctx.editor.isActive({ textAlign: 'justify' }),
currentColor: ctx.editor.getAttributes('textStyle')?.color || undefined,
currentHighlight: ctx.editor.getAttributes('highlight')?.color || undefined,
currentFont: ctx.editor.getAttributes('textStyle')?.fontFamily || undefined,
currentSize: ctx.editor.getAttributes('textStyle')?.fontSize || undefined,
}
isBold: ctx.editor.isActive("bold"),
isItalic: ctx.editor.isActive("italic"),
isStrike: ctx.editor.isActive("strike"),
isUnderline: ctx.editor.isActive("underline"),
isCode: ctx.editor.isActive("code"),
isSubscript: ctx.editor.isActive("subscript"),
isSuperscript: ctx.editor.isActive("superscript"),
isAlignLeft: ctx.editor.isActive({ textAlign: "left" }),
isAlignCenter: ctx.editor.isActive({ textAlign: "center" }),
isAlignRight: ctx.editor.isActive({ textAlign: "right" }),
isAlignJustify: ctx.editor.isActive({ textAlign: "justify" }),
currentColor: ctx.editor.getAttributes("textStyle")?.color || undefined,
currentHighlight:
ctx.editor.getAttributes("highlight")?.color || undefined,
currentFont:
ctx.editor.getAttributes("textStyle")?.fontFamily || undefined,
currentSize:
ctx.editor.getAttributes("textStyle")?.fontSize || undefined,
};
},
})
});

const shouldShow = useCallback(
({ view, from }: ShouldShowProps) => {
if (!view || editor.view.dragging) {
return false
return false;
}

const domAtPos = view.domAtPos(from || 0).node as HTMLElement
const nodeDOM = view.nodeDOM(from || 0) as HTMLElement
const node = nodeDOM || domAtPos
const domAtPos = view.domAtPos(from || 0).node as HTMLElement;
const nodeDOM = view.nodeDOM(from || 0) as HTMLElement;
const node = nodeDOM || domAtPos;

if (isCustomNodeSelected(editor, node)) {
return false
return false;
}

return isTextSelected({ editor })
return isTextSelected({ editor });
},
[editor],
)
);

return {
shouldShow,
...states,
}
}
};
};
Loading

0 comments on commit 93bd71a

Please sign in to comment.