mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-24 13:44:54 +00:00
Merge branch 'main' into codex/refactor-data-binding-resolution-in-componentrenderer
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { createElement, useMemo } from 'react'
|
||||
import { UIComponent, Binding, ComponentRendererProps } from '@/types/json-ui'
|
||||
import { getUIComponent } from './component-registry'
|
||||
import { getNestedValue } from './utils'
|
||||
import { transformData } from './utils'
|
||||
|
||||
function resolveBinding(binding: Binding, data: Record<string, unknown>): unknown {
|
||||
const sourceValue = binding.source.includes('.')
|
||||
@@ -14,7 +14,9 @@ function resolveBinding(binding: Binding, data: Record<string, unknown>): unknow
|
||||
}
|
||||
|
||||
if (binding.transform) {
|
||||
value = binding.transform(value)
|
||||
value = typeof binding.transform === 'string'
|
||||
? transformData(value, binding.transform)
|
||||
: binding.transform(value)
|
||||
}
|
||||
|
||||
return value
|
||||
|
||||
@@ -86,6 +86,12 @@ export function JSONUIRenderer({
|
||||
|
||||
const props: Record<string, any> = { ...component.props }
|
||||
|
||||
if (component.bindings) {
|
||||
Object.entries(component.bindings).forEach(([propName, binding]) => {
|
||||
props[propName] = resolveDataBinding(binding, dataMap, context)
|
||||
})
|
||||
}
|
||||
|
||||
if (component.dataBinding) {
|
||||
const boundData = resolveDataBinding(component.dataBinding, dataMap, context)
|
||||
if (boundData !== undefined) {
|
||||
|
||||
@@ -33,6 +33,7 @@ export const UIComponentSchema: any = z.object({
|
||||
props: z.record(z.string(), z.any()).optional(),
|
||||
className: z.string().optional(),
|
||||
style: z.record(z.string(), z.any()).optional(),
|
||||
bindings: z.record(z.string(), DataBindingSchema).optional(),
|
||||
children: z.union([
|
||||
z.string(),
|
||||
z.array(z.lazy(() => UIComponentSchema)),
|
||||
|
||||
@@ -48,7 +48,7 @@ export interface Action {
|
||||
export interface Binding {
|
||||
source: string
|
||||
path?: string
|
||||
transform?: (value: any) => any
|
||||
transform?: string | ((value: any) => any)
|
||||
}
|
||||
|
||||
export interface EventHandler {
|
||||
|
||||
Reference in New Issue
Block a user