page.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { Code } from "@/components/code";
  2. export const metadata = {
  3. title: "@json-render/core API | json-render",
  4. };
  5. export default function CoreApiPage() {
  6. return (
  7. <article>
  8. <h1 className="text-3xl font-bold mb-4">@json-render/core</h1>
  9. <p className="text-muted-foreground mb-8">
  10. Core types, schemas, and utilities.
  11. </p>
  12. <h2 className="text-xl font-semibold mt-12 mb-4">createCatalog</h2>
  13. <p className="text-sm text-muted-foreground mb-4">
  14. Creates a catalog definition.
  15. </p>
  16. <Code lang="typescript">{`function createCatalog(config: CatalogConfig): Catalog
  17. interface CatalogConfig {
  18. components: Record<string, ComponentDefinition>;
  19. actions?: Record<string, ActionDefinition>;
  20. validationFunctions?: Record<string, ValidationFunctionDef>;
  21. }
  22. interface ComponentDefinition {
  23. props: ZodObject;
  24. hasChildren?: boolean;
  25. description?: string;
  26. }
  27. interface ActionDefinition {
  28. params?: ZodObject;
  29. description?: string;
  30. }`}</Code>
  31. <h2 className="text-xl font-semibold mt-12 mb-4">
  32. generateCatalogPrompt
  33. </h2>
  34. <p className="text-sm text-muted-foreground mb-4">
  35. Generates a system prompt for AI models.
  36. </p>
  37. <Code lang="typescript">{`function generateCatalogPrompt(catalog: Catalog): string`}</Code>
  38. <h2 className="text-xl font-semibold mt-12 mb-4">evaluateVisibility</h2>
  39. <p className="text-sm text-muted-foreground mb-4">
  40. Evaluates a visibility condition against data and auth state.
  41. </p>
  42. <Code lang="typescript">{`function evaluateVisibility(
  43. condition: VisibilityCondition | undefined,
  44. data: Record<string, unknown>,
  45. auth?: AuthState
  46. ): boolean
  47. type VisibilityCondition =
  48. | { path: string }
  49. | { auth: 'signedIn' | 'signedOut' | string }
  50. | { and: VisibilityCondition[] }
  51. | { or: VisibilityCondition[] }
  52. | { not: VisibilityCondition }
  53. | { eq: [DynamicValue, DynamicValue] }
  54. | { gt: [DynamicValue, DynamicValue] }
  55. | { gte: [DynamicValue, DynamicValue] }
  56. | { lt: [DynamicValue, DynamicValue] }
  57. | { lte: [DynamicValue, DynamicValue] };`}</Code>
  58. <h2 className="text-xl font-semibold mt-12 mb-4">Types</h2>
  59. <h3 className="text-lg font-semibold mt-8 mb-4">UIElement</h3>
  60. <Code lang="typescript">{`interface UIElement {
  61. key: string;
  62. type: string;
  63. props: Record<string, unknown>;
  64. children?: UIElement[];
  65. visible?: VisibilityCondition;
  66. validation?: ValidationSchema;
  67. }`}</Code>
  68. <h3 className="text-lg font-semibold mt-8 mb-4">UITree</h3>
  69. <Code lang="typescript">{`interface UITree {
  70. root: UIElement | null;
  71. elements: Record<string, UIElement>;
  72. }`}</Code>
  73. <h3 className="text-lg font-semibold mt-8 mb-4">Action</h3>
  74. <Code lang="typescript">{`interface Action {
  75. name: string;
  76. params?: Record<string, unknown>;
  77. confirm?: {
  78. title: string;
  79. message: string;
  80. variant?: 'default' | 'danger';
  81. };
  82. onSuccess?: { set: Record<string, unknown> };
  83. onError?: { set: Record<string, unknown> };
  84. }`}</Code>
  85. <h3 className="text-lg font-semibold mt-8 mb-4">ValidationSchema</h3>
  86. <Code lang="typescript">{`interface ValidationSchema {
  87. checks: ValidationCheck[];
  88. validateOn?: 'change' | 'blur' | 'submit';
  89. }
  90. interface ValidationCheck {
  91. fn: string;
  92. args?: Record<string, unknown>;
  93. message: string;
  94. }`}</Code>
  95. </article>
  96. );
  97. }