2024-02-29 01:23:56 +03:00
|
|
|
import { type ClassValue, clsx } from "clsx";
|
|
|
|
|
import { twMerge } from "tailwind-merge";
|
2026-02-27 18:55:36 +03:00
|
|
|
import { UiSchema } from "@rjsf/utils";
|
|
|
|
|
import { JsonObject } from "@/types/configForm";
|
2023-12-08 16:33:22 +03:00
|
|
|
|
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
2024-02-29 01:23:56 +03:00
|
|
|
return twMerge(clsx(inputs));
|
2023-12-08 16:33:22 +03:00
|
|
|
}
|
2026-02-27 18:55:36 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deep merges uiSchema objects, preserving nested properties from the base schema
|
|
|
|
|
* when overrides don't explicitly replace them.
|
|
|
|
|
*
|
|
|
|
|
* Special handling for ui:options - merges nested options rather than replacing them.
|
|
|
|
|
*/
|
|
|
|
|
export function mergeUiSchema(
|
|
|
|
|
base: UiSchema = {},
|
|
|
|
|
overrides: UiSchema = {},
|
|
|
|
|
): UiSchema {
|
|
|
|
|
const result: UiSchema = { ...base };
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(overrides)) {
|
|
|
|
|
if (
|
|
|
|
|
key === "ui:options" &&
|
|
|
|
|
base[key] &&
|
|
|
|
|
typeof value === "object" &&
|
|
|
|
|
value !== null
|
|
|
|
|
) {
|
|
|
|
|
// Merge ui:options objects instead of replacing
|
|
|
|
|
result[key] = {
|
|
|
|
|
...(typeof base[key] === "object" && base[key] !== null
|
|
|
|
|
? base[key]
|
|
|
|
|
: {}),
|
|
|
|
|
...value,
|
|
|
|
|
};
|
|
|
|
|
} else if (
|
|
|
|
|
typeof value === "object" &&
|
|
|
|
|
value !== null &&
|
|
|
|
|
!Array.isArray(value)
|
|
|
|
|
) {
|
|
|
|
|
// Recursively merge nested objects (field configurations)
|
|
|
|
|
result[key] = mergeUiSchema(base[key] as UiSchema, value as UiSchema);
|
|
|
|
|
} else {
|
|
|
|
|
// Replace primitive values and arrays
|
|
|
|
|
result[key] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Type guard to check if a value is a JsonObject (non-array object)
|
|
|
|
|
*/
|
|
|
|
|
export function isJsonObject(value: unknown): value is JsonObject {
|
|
|
|
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
|
|
|
}
|