diff --git a/package-lock.json b/package-lock.json index a928007..2752c90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "kri-ui-registry", - "version": "0.5.0", + "version": "0.10.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kri-ui-registry", - "version": "0.5.0", + "version": "0.10.0", "devDependencies": { "@tanstack/react-table": "^8.21.3", "@tiptap/extension-color": "^3.27.1", + "@tiptap/extension-font-family": "^3.27.1", "@tiptap/extension-highlight": "^3.27.1", "@tiptap/extension-image": "^3.27.1", "@tiptap/extension-link": "^3.27.1", @@ -1024,6 +1025,20 @@ "@tiptap/pm": "3.27.1" } }, + "node_modules/@tiptap/extension-font-family": { + "version": "3.27.1", + "resolved": "https://registry.npmjs.org/@tiptap/extension-font-family/-/extension-font-family-3.27.1.tgz", + "integrity": "sha512-sxPae35pbJSaF3IZRGDglB5z/7nzS9dmxLLjiQNWYmgUIs8+/EYcrsN/woYUS0nsgHswgBmg7DwBabunKLSGhQ==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-text-style": "3.27.1" + } + }, "node_modules/@tiptap/extension-gapcursor": { "version": "3.27.1", "resolved": "https://registry.npmjs.org/@tiptap/extension-gapcursor/-/extension-gapcursor-3.27.1.tgz", diff --git a/package.json b/package.json index c6633fa..c0f76e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kri-ui-registry", - "version": "0.10.0", + "version": "0.11.0", "private": true, "description": "KRI internal shadcn UI registry", "scripts": { @@ -12,6 +12,7 @@ "devDependencies": { "@tanstack/react-table": "^8.21.3", "@tiptap/extension-color": "^3.27.1", + "@tiptap/extension-font-family": "^3.27.1", "@tiptap/extension-highlight": "^3.27.1", "@tiptap/extension-image": "^3.27.1", "@tiptap/extension-link": "^3.27.1", diff --git a/registry/components/KriTimePicker.tsx b/registry/components/KriTimePicker.tsx index 7305c31..d73ca67 100644 --- a/registry/components/KriTimePicker.tsx +++ b/registry/components/KriTimePicker.tsx @@ -79,7 +79,7 @@ export function KriTimePicker({ return (
-
{hourLabel}
+
{hourLabel}
{hours.map((hour) => ( @@ -101,7 +101,7 @@ export function KriTimePicker({
-
{minuteLabel}
+
{minuteLabel}
{minutes.map((minute) => ( diff --git a/registry/components/kri-editor/KriEditorWysiwyg.tsx b/registry/components/kri-editor/KriEditorWysiwyg.tsx index edfa856..c7eda55 100644 --- a/registry/components/kri-editor/KriEditorWysiwyg.tsx +++ b/registry/components/kri-editor/KriEditorWysiwyg.tsx @@ -5,6 +5,7 @@ import { EditorContent, useEditor, type Editor } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; import Underline from "@tiptap/extension-underline"; import { TextStyle } from "@tiptap/extension-text-style"; +import FontFamily from "@tiptap/extension-font-family"; import Color from "@tiptap/extension-color"; import Highlight from "@tiptap/extension-highlight"; import TiptapImage from "@tiptap/extension-image"; @@ -27,6 +28,7 @@ import { Div } from "./extensions/div"; import { compressImage } from "./utils/imageCompression"; import { sanitizeHtml } from "./utils/sanitizeHtml"; import { preserveEmptyParagraphs } from "./utils/emptyParagraph"; +import { DEFAULT_FONT_FAMILY_OPTIONS } from "./utils/fontFamilyOptions"; import { applyLinkPreviewClass, KRI_EDITOR_LINK_CLASS } from "./utils/linkPreview"; import { Toolbar } from "./toolbar/Toolbar"; import { useDebouncedChange } from "./hooks/useDebouncedChange"; @@ -35,9 +37,10 @@ import { useTextareaInsert } from "./hooks/useTextareaInsert"; type ViewMode = "wysiwyg" | "html"; function getToolbarState(editor: Editor): ToolbarState { - const ts = editor.getAttributes("textStyle") as { fontSize?: string | null; color?: string | null }; + const ts = editor.getAttributes("textStyle") as { fontSize?: string | null; fontFamily?: string | null; color?: string | null }; const hl = editor.getAttributes("highlight") as { color?: string | null }; + const fontFamily = (ts?.fontFamily ?? null) as string | null; const fontSize = (ts?.fontSize ?? "16px") as string; const textColor = (ts?.color ?? null) as string | null; const highlightColor = (hl?.color ?? null) as string | null; @@ -48,6 +51,7 @@ function getToolbarState(editor: Editor): ToolbarState { "left"; return { + fontFamily, fontSize, textColor, highlightColor, @@ -89,6 +93,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) { allowBase64 = false, sanitizeHtml: sanitizeHtmlOpt = true, toolbar = {}, + fontFamilyOptions = DEFAULT_FONT_FAMILY_OPTIONS, editorExtensions = [], allowedCustomHtml, transformPreviewHtml, @@ -122,6 +127,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) { const selectionRef = useRef<{ from: number; to: number } | null>(null); const [tb, setTb] = useState({ + fontFamily: null, fontSize: "16px", textColor: null, highlightColor: null, @@ -150,6 +156,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) { Underline, TextStyle, FontSize, + FontFamily, Color, Highlight.configure({ multicolor: true }), Div, @@ -276,6 +283,19 @@ export function KriEditorWysiwyg(props: KriEditorProps) { [editor, restoreSelection] ); + const setFontFamily = useCallback( + (value: string) => { + if (!editor) return; + restoreSelection(); + if (!value) { + editor.chain().focus().unsetFontFamily().run(); + return; + } + editor.chain().focus().setFontFamily(value).run(); + }, + [editor, restoreSelection] + ); + const setTextColor = useCallback( (hex: string) => { if (!editor) return; @@ -595,6 +615,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) { showHtmlToggle={showHtmlToggle} isHtmlView={view === "html"} onToggleHtmlView={onToggleHtmlView} + fontFamilyOptions={fontFamilyOptions} + onSetFontFamily={setFontFamily} onSetFontSize={setFontSize} onSetTextColor={setTextColor} onUnsetTextColor={unsetTextColor} diff --git a/registry/components/kri-editor/index.ts b/registry/components/kri-editor/index.ts index 11bfa8f..6f684c7 100644 --- a/registry/components/kri-editor/index.ts +++ b/registry/components/kri-editor/index.ts @@ -3,9 +3,11 @@ export { KriEditorHtmlOnly } from './KriEditorHtmlOnly' export { KriEditorSms } from './KriEditorSms' export { KriEditorWysiwyg } from './KriEditorWysiwyg' export { ToolbarButton as KriEditorToolbarButton } from './toolbar/ToolbarButton' +export { DEFAULT_FONT_FAMILY_OPTIONS } from './utils/fontFamilyOptions' export type { KriEditorAllowedHtml, KriEditorCommand, + KriEditorFontFamilyOption, KriEditorMode, KriEditorProps, KriEditorToolbarConfig, diff --git a/registry/components/kri-editor/toolbar/Toolbar.tsx b/registry/components/kri-editor/toolbar/Toolbar.tsx index 0b87723..b313d5a 100644 --- a/registry/components/kri-editor/toolbar/Toolbar.tsx +++ b/registry/components/kri-editor/toolbar/Toolbar.tsx @@ -25,7 +25,7 @@ import { Input } from '@/components/ui/input' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { Separator } from '@/components/ui/separator' import { cn } from '@/lib/utils' -import type { KriEditorToolbarConfig, KriEditorToolbarFeature, ToolbarState } from '../types' +import type { KriEditorFontFamilyOption, KriEditorToolbarConfig, KriEditorToolbarFeature, ToolbarState } from '../types' import { ToolbarButton } from './ToolbarButton' interface ToolbarProps { @@ -38,6 +38,8 @@ interface ToolbarProps { showHtmlToggle: boolean isHtmlView: boolean onToggleHtmlView: () => void + fontFamilyOptions: KriEditorFontFamilyOption[] + onSetFontFamily: (value: string) => void onSetFontSize: (value: string) => void onSetTextColor: (value: string) => void onUnsetTextColor: () => void @@ -74,6 +76,8 @@ export function Toolbar({ showHtmlToggle, isHtmlView, onToggleHtmlView, + fontFamilyOptions, + onSetFontFamily, onSetFontSize, onSetTextColor, onUnsetTextColor, @@ -89,6 +93,7 @@ export function Toolbar({ customContent, }: ToolbarProps) { const enabled = (feature: KriEditorToolbarFeature) => config?.[feature] !== false + const showFontControls = enabled('fontFamily') || enabled('fontSize') const showTextStyle = enabled('bold') || enabled('italic') || enabled('underline') || enabled('strike') const showColors = enabled('textColor') || enabled('highlight') const showLists = enabled('bulletList') || enabled('orderedList') @@ -108,6 +113,19 @@ export function Toolbar({ return (
+ {enabled('fontFamily') ? ( + + ) : null} + {enabled('fontSize') ? (