@json-render/core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # @json-render/core
2
+
3
+ Enterprise-grade JSON-driven UI library with conditional visibility, rich actions, and enhanced validation.
4
+
5
+ ## Features
6
+
7
+ - **Conditional Visibility**: Show/hide components based on data paths, auth state, or complex logic expressions
8
+ - **Rich Actions**: Actions with typed parameters, confirmation dialogs, and success/error callbacks
9
+ - **Enhanced Validation**: Built-in validation functions with custom catalog functions support
10
+ - **Type-Safe Catalog**: Define component schemas using Zod for full type safety
11
+ - **Framework Agnostic**: Core logic is independent of UI frameworks
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @json-render/core
17
+ # or
18
+ pnpm add @json-render/core
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### Create a Catalog
24
+
25
+ ```typescript
26
+ import { createCatalog } from '@json-render/core';
27
+ import { z } from 'zod';
28
+
29
+ const catalog = createCatalog({
30
+ name: 'My Dashboard',
31
+ components: {
32
+ Card: {
33
+ props: z.object({
34
+ title: z.string(),
35
+ description: z.string().nullable(),
36
+ }),
37
+ hasChildren: true,
38
+ description: 'A card container',
39
+ },
40
+ Button: {
41
+ props: z.object({
42
+ label: z.string(),
43
+ action: ActionSchema,
44
+ }),
45
+ description: 'A clickable button',
46
+ },
47
+ },
48
+ actions: {
49
+ submit: { description: 'Submit the form' },
50
+ export: {
51
+ params: z.object({ format: z.enum(['csv', 'pdf']) }),
52
+ description: 'Export data',
53
+ },
54
+ },
55
+ functions: {
56
+ customValidation: (value) => typeof value === 'string' && value.length > 0,
57
+ },
58
+ });
59
+ ```
60
+
61
+ ### Visibility Conditions
62
+
63
+ ```typescript
64
+ import { visibility, evaluateVisibility } from '@json-render/core';
65
+
66
+ // Simple path-based visibility
67
+ const element1 = {
68
+ key: 'error-banner',
69
+ type: 'Alert',
70
+ props: { message: 'Error!' },
71
+ visible: { path: '/form/hasError' },
72
+ };
73
+
74
+ // Auth-based visibility
75
+ const element2 = {
76
+ key: 'admin-panel',
77
+ type: 'Card',
78
+ props: { title: 'Admin' },
79
+ visible: { auth: 'signedIn' },
80
+ };
81
+
82
+ // Complex logic
83
+ const element3 = {
84
+ key: 'notification',
85
+ type: 'Alert',
86
+ props: { message: 'Warning' },
87
+ visible: {
88
+ and: [
89
+ { path: '/settings/notifications' },
90
+ { not: { path: '/user/dismissed' } },
91
+ { gt: [{ path: '/items/count' }, 10] },
92
+ ],
93
+ },
94
+ };
95
+
96
+ // Evaluate visibility
97
+ const isVisible = evaluateVisibility(element1.visible, {
98
+ dataModel: { form: { hasError: true } },
99
+ });
100
+ ```
101
+
102
+ ### Rich Actions
103
+
104
+ ```typescript
105
+ import { resolveAction, executeAction } from '@json-render/core';
106
+
107
+ const buttonAction = {
108
+ name: 'refund',
109
+ params: {
110
+ paymentId: { path: '/selected/id' },
111
+ amount: 100,
112
+ },
113
+ confirm: {
114
+ title: 'Confirm Refund',
115
+ message: 'Refund $100 to customer?',
116
+ variant: 'danger',
117
+ },
118
+ onSuccess: { navigate: '/payments' },
119
+ onError: { set: { '/ui/error': '$error.message' } },
120
+ };
121
+
122
+ // Resolve dynamic values
123
+ const resolved = resolveAction(buttonAction, dataModel);
124
+ ```
125
+
126
+ ### Validation
127
+
128
+ ```typescript
129
+ import { runValidation, check } from '@json-render/core';
130
+
131
+ const config = {
132
+ checks: [
133
+ check.required('Email is required'),
134
+ check.email('Invalid email'),
135
+ check.maxLength(100, 'Too long'),
136
+ ],
137
+ validateOn: 'blur',
138
+ };
139
+
140
+ const result = runValidation(config, {
141
+ value: 'user@example.com',
142
+ dataModel: {},
143
+ });
144
+
145
+ // result.valid = true
146
+ // result.errors = []
147
+ ```
148
+
149
+ ## API Reference
150
+
151
+ ### Visibility
152
+
153
+ - `evaluateVisibility(condition, context)` - Evaluate a visibility condition
154
+ - `evaluateLogicExpression(expr, context)` - Evaluate a logic expression
155
+ - `visibility.*` - Helper functions for creating visibility conditions
156
+
157
+ ### Actions
158
+
159
+ - `resolveAction(action, dataModel)` - Resolve dynamic values in an action
160
+ - `executeAction(context)` - Execute an action with callbacks
161
+ - `interpolateString(template, dataModel)` - Interpolate `${path}` in strings
162
+
163
+ ### Validation
164
+
165
+ - `runValidation(config, context)` - Run validation checks
166
+ - `runValidationCheck(check, context)` - Run a single validation check
167
+ - `builtInValidationFunctions` - Built-in validators (required, email, min, max, etc.)
168
+ - `check.*` - Helper functions for creating validation checks
169
+
170
+ ### Catalog
171
+
172
+ - `createCatalog(config)` - Create a catalog with components, actions, and functions
173
+ - `generateCatalogPrompt(catalog)` - Generate an AI prompt describing the catalog
174
+
175
+ ## Types
176
+
177
+ See `src/types.ts` for full type definitions:
178
+
179
+ - `UIElement` - Base element structure
180
+ - `UITree` - Flat tree structure
181
+ - `VisibilityCondition` - Visibility condition types
182
+ - `LogicExpression` - Logic expression types
183
+ - `Action` - Rich action definition
184
+ - `ValidationConfig` - Validation configuration