Skip to content

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.

Merge origin/main into fix/bop-step-editor

Raulc6f00e0d89e4
diff --cc apps/erp/app/components/SlidesEditor.tsx
index 76208c21cb,d3d47f2bb4..9807259ea9
--- a/apps/erp/app/components/SlidesEditor.tsx
+++ b/apps/erp/app/components/SlidesEditor.tsx
@@@ -196,33 -197,12 +197,36 @@@ export function SlidesEditor(
const { t } = useLingui();
const [annotatingIndex, setAnnotatingIndex] = useState<number | null>(null);
const annotating = annotatingIndex == null ? null : slides[annotatingIndex];
+ // The image slide open full size. A model slide has no image to enlarge.
+ const [viewingIndex, setViewingIndex] = useState<number | null>(null);
+ const viewing = viewingIndex == null ? null : slides[viewingIndex];
const models = useSlideModels(slides);
+ const containerRef = useRef<HTMLDivElement>(null);
+ const isHidden = isDisabled && slides.length === 0;
- if (isDisabled && slides.length === 0) return null;
+ // A caption saves on blur. Submitting the surrounding form from inside a
+ // caption (⌘/Ctrl+Enter, or Enter) never blurs it, and the step form closes
+ // with the edit unsaved. So a submit first blurs a focused caption of this
+ // editor, which runs its own save.
+ useEffect(() => {
+ if (isHidden) return;
+ const form = containerRef.current?.closest("form");
+ if (!form) return;
+ const saveFocusedCaption = () => {
+ const active = document.activeElement;
+ if (
+ active instanceof HTMLInputElement &&
+ active.dataset.slideCaption !== undefined &&
+ containerRef.current?.contains(active)
+ ) {
+ active.blur();
+ }
+ };
+ form.addEventListener("submit", saveFocusedCaption);
+ return () => form.removeEventListener("submit", saveFocusedCaption);
+ }, [isHidden]);
+
+ if (isHidden) return null;
const withModels = !!modelInputRef && !!onModelFileChange;
diff --cc apps/erp/app/modules/shared/shared.models.test.ts
index d603add29f,6a980ccd41..7b902ba0d0
--- a/apps/erp/app/modules/shared/shared.models.test.ts
+++ b/apps/erp/app/modules/shared/shared.models.test.ts
@@@ -5,7 -6,7 +6,8 @@@ import { TiptapText } from "@carbon/fil
import { describe, expect, it } from "vitest";
import {
normalizeOperationSourceIds,
+ operationStepValidator,
+ optionalPlainTextDoc,
optionalTiptapDoc,
toTiptapDoc
} from "./shared.models";
diff --cc apps/erp/app/modules/shared/shared.models.ts
index 42d336b407,07029b44ff..19ccccd64f
--- a/apps/erp/app/modules/shared/shared.models.ts
+++ b/apps/erp/app/modules/shared/shared.models.ts
@@@ -269,24 -257,48 +257,58 @@@ export function toTiptapDoc
* INPUT schema) tells a caller both shapes are accepted, instead of the bare
* `{}` a `z.any()` produced.
*/
- export const optionalTiptapDoc = z
- .union([z.string(), z.record(z.string(), z.unknown())])
- .transform((value): any => (value === "" ? undefined : toTiptapDoc(value)))
- // `.optional()` LAST so the inferred key is optional (`notes?:`) — placing it
- // before the transform makes zod infer a required key and every caller that
- // omits `notes` stops compiling.
- .optional();
+ // A node's `content` must be a list of nodes, at every depth: a document
+ // whose content was a string reached the editor and RichTextView, which walk
+ // it as an array.
+ type TiptapNodeInput = { type: string; content?: TiptapNodeInput[] };
+ const tiptapNodeInput: z.ZodType<TiptapNodeInput> = z.lazy(() =>
+ z.looseObject({
+ type: z.string().min(1),
+ text: z.string().optional(),
+ content: z.array(tiptapNodeInput).optional()
+ })
+ );
+ const tiptapDocumentInput = z.looseObject({
+ type: z.literal("doc"),
+ content: z.array(tiptapNodeInput).optional()
+ });
+
+ const tiptapDocInput = (format?: "markdown" | "text") =>
+ z
+ .union([
+ z.string(),
+ // A Tiptap document, or `{}` to clear; any other object is refused.
+ tiptapDocumentInput,
+ z.strictObject({})
+ ])
+ .transform((value): any =>
+ value === "" ? undefined : toTiptapDoc(value, format)
+ )
+ // `.optional()` LAST so the inferred key is optional (`notes?:`) — placing
+ // it before the transform makes zod infer a required key and every caller
+ // that omits `notes` stops compiling.
+ .optional();
+
+ /** Text read as Markdown. */
+ export const optionalTiptapDoc = tiptapDocInput();
+
+ /**
+ * Text stored as typed, for a field edited in a plain textarea that reads it
+ * back with `TiptapText(…).toString()`: Markdown markers would not survive that
+ * round trip (`1. Ship` would come back as `Ship`).
+ */
+ export const optionalPlainTextDoc = tiptapDocInput("text");
+/**
+ * A List step's options. Blank rows (the empty row "Add option" leaves) are
+ * dropped before the step's refine runs, so a trailing empty row never blocks a
+ * save and is never stored.
+ */
+export const stepListValues = z
+ .array(z.string())
+ .transform((values) => values.filter((value) => value.trim() !== ""))
+ .optional();
+
export const operationStepValidator = z
.object({
id: zfd.text(z.string().optional()),