import { ActivityDefinition, ActivityPropertyDefinition, ActivityTypeDefinition } from "@vertesia/common";
import clsx from "clsx";
import { AnimatePresence, motion } from "motion/react";
import React, { useMemo, useState } from "react";
function Badge({ children, secondary = false }: { children: React.ReactNode, secondary?: boolean }) {
const className = secondary ? "bg-secondary text-primary" : "text-foreground bg-muted";
return {children}
}
/**
* Resolve nested array inner type
* @param innerType
*/
function resolveInnerType(innerType: ActivityTypeDefinition | undefined) {
if (!innerType) {
return undefined;
} else if (innerType.name === "array") {
return resolveInnerType(innerType.innerType);
} else {
return innerType;
}
}
interface PropertySignatureProps {
property: ActivityPropertyDefinition;
}
function PropertySignature({ property }: PropertySignatureProps) {
return (
{property.name}
{property.optional &&
optional}
{property.type.value}
)
}
interface ActivitiesDocProps {
activities: ActivityDefinition[];
}
export function ActivitiesDoc({ activities }: ActivitiesDocProps) {
return (
{activities.map(activity =>
)}
)
}
interface ActivitySectionTitleProps {
children: React.ReactNode;
code?: string;
}
function ActivitySectionTitle({ code, children }: ActivitySectionTitleProps) {
return (
{children}
{code &&
{code}
}
)
}
interface ActivityDocProps {
activity: ActivityDefinition;
headingRef?: React.RefObject;
headingClass?: string;
}
export function ActivityDoc({ activity, headingClass, headingRef }: ActivityDocProps) {
return (
{activity.title}
{activity.name}
{
activity.doc &&
{activity.doc}
}
Parameters
{activity.params.map(prop =>
)}
Returns
{activity.returnType ? activity.returnType.value : "void"}
)
}
function PropertyDetails({ property, className }: { className?: string, property: ActivityPropertyDefinition }) {
const expandable = useMemo(() => {
const type = resolveInnerType(property.type.innerType) ?? property.type;
if (type.name === "object" && type.members) {
return
} else if (type.name === 'enum' && type.enum) {
return
} else {
return null;
}
}, [property.type.innerType]);
return (
{property.doc &&
{property.doc}
}
{expandable &&
{expandable}
}
)
}
interface EnumValuesPanelProps {
values: string[] | number[];
}
function EnumValuesPanel({ values }: EnumValuesPanelProps) {
return {
values.map((v, i) => {v})
}
}
function ObjectMembersPanel({ members }: { members: ActivityPropertyDefinition[] }) {
return (
{
isOn ?
Hide child properties
:
Show child properties
}
)}
body={} />
}
function NestedPropertiesDetails({ properties }: { properties: ActivityPropertyDefinition[] }) {
return (
{properties.map(prop =>
)}
)
}
interface ExpandablePanelProps {
isInitiallyOpen?: boolean;
className?: string;
button: (isOn: boolean) => React.ReactNode;
body: React.ReactNode | React.ReactNode[];
}
function ExpandablePanel({ button, body, className, isInitiallyOpen }: ExpandablePanelProps) {
const [isExpanded, setExpanded] = useState(isInitiallyOpen || false);
return (
{
isExpanded &&
{body}
}
)
}
interface ExpandIconProps {
isOpen: boolean;
}
function ExpandIcon({ isOpen }: ExpandIconProps) {
return (
+
)
}