Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { useControlField, useField } from "@carbon/form";
import { FormControl, FormErrorMessage } from "@carbon/react";
import { RichText as RichTextBase, useRichText } from "@carbon/react/RichText";
import type { ComponentProps } from "react";
import { useEffect } from "react";
type RichTextProps = Omit<ComponentProps<typeof RichTextBase>, "editor"> & {
name: string;
output?: "html" | "json" | "text";
};
const RichText = ({ name, output = "html", ...props }: RichTextProps) => {
const { getInputProps, error, defaultValue } = useField(name);
const [value, setValue] = useControlField<string>(name);
const richText = useRichText(defaultValue);
useEffect(() => {
if (!value) {
richText?.commands.clearContent(true);
}
}, [value, richText]);
useEffect(() => {
if (richText) {
richText.on("update", () => {
switch (output) {
case "html":
setValue(richText.getHTML());
break;
case "json":
setValue(JSON.stringify(richText.getJSON()));
break;
case "text":
setValue(richText.getText());
break;
default:
setValue(richText.getHTML());
break;
}
});
}
return () => {
if (richText) {
richText.off("update");
}
};
}, [richText, output, setValue]);
return (
<FormControl isInvalid={!!error}>
<RichTextBase {...props} editor={richText} />
<input
{...getInputProps({
id: name
})}
value={value}
type="hidden"
/>
{error && <FormErrorMessage>{error}</FormErrorMessage>}
</FormControl>
);
};
export default RichText;