feat(admin): reorganize housekeeping and strengthen shared workflows
This commit is contained in:
1 parent
35f66d879f
commit
a070004e7b
35 files changed
+1667
-462
No files matched your search
@@ -57,13 +57,17 @@ export function RichText({
|
||||
defaultValue = "",
|
||||
placeholder,
|
||||
rows = 10,
|
||||
onChange,
|
||||
}: {
|
||||
name: string;
|
||||
defaultValue?: string;
|
||||
placeholder?: string;
|
||||
rows?: number;
|
||||
onChange?: () => void;
|
||||
}) {
|
||||
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
|
||||
const changeCallback = useRef(onChange);
|
||||
changeCallback.current = onChange;
|
||||
const reactId = useId();
|
||||
// Stable, querySelector-safe id (useId() contains ':').
|
||||
const editorId = `rt-${reactId.replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
||||
@@ -94,11 +98,16 @@ export function RichText({
|
||||
on: (ev: string, cb: () => void) => void;
|
||||
getContent: () => string;
|
||||
}) => {
|
||||
const sync = () => {
|
||||
if (textareaRef.current)
|
||||
textareaRef.current.value = editor.getContent();
|
||||
const sync = (notify: boolean) => {
|
||||
const field = textareaRef.current;
|
||||
if (!field) return;
|
||||
const html = editor.getContent();
|
||||
const changed = field.value !== html;
|
||||
field.value = html;
|
||||
if (notify && changed) changeCallback.current?.();
|
||||
};
|
||||
editor.on("change keyup undo redo SetContent", sync);
|
||||
editor.on("SetContent", () => sync(false));
|
||||
editor.on("change keyup undo redo", () => sync(true));
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
Reference in new issue
Block a user