SurfSense/surfsense_web/components/editor/plugins/fixed-toolbar-kit.tsx

34 lines
862 B
TypeScript
Raw Normal View History

2026-02-17 12:47:39 +05:30
"use client";
2026-02-17 12:47:39 +05:30
import { createPlatePlugin } from "platejs/react";
import { useEditorReadOnly } from "platejs/react";
import { useEditorSave } from "@/components/editor/editor-save-context";
2026-02-17 12:47:39 +05:30
import { FixedToolbar } from "@/components/ui/fixed-toolbar";
import { FixedToolbarButtons } from "@/components/ui/fixed-toolbar-buttons";
function ConditionalFixedToolbar() {
const readOnly = useEditorReadOnly();
const { onSave, hasUnsavedChanges, canToggleMode } = useEditorSave();
const hasVisibleControls =
!readOnly || canToggleMode || (!!onSave && hasUnsavedChanges && !readOnly);
if (!hasVisibleControls) return null;
return (
<FixedToolbar>
<FixedToolbarButtons />
</FixedToolbar>
);
}
export const FixedToolbarKit = [
2026-02-17 12:47:39 +05:30
createPlatePlugin({
key: "fixed-toolbar",
render: {
beforeEditable: () => <ConditionalFixedToolbar />,
2026-02-17 12:47:39 +05:30
},
}),
];