@woodylab/payload 0.0.123 → 0.0.125
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/dist/config/utils/resolveInlineComponent.js +1 -1
- package/dist/config/utils/resolveViewRow.js +1 -1
- package/dist/{config/react → react}/PageRenderer.js +1 -1
- package/dist/react/index.cjs.js +2 -0
- package/dist/react/index.cjs.js.map +1 -0
- package/dist/react/index.esm.js +2 -0
- package/dist/react/index.esm.js.map +1 -0
- package/package.json +1 -1
- /package/dist/{config/react → react}/Card.d.ts +0 -0
- /package/dist/{config/react → react}/Card.js +0 -0
- /package/dist/{config/react → react}/ComponentRenderer.d.ts +0 -0
- /package/dist/{config/react → react}/ComponentRenderer.js +0 -0
- /package/dist/{config/react → react}/PageRenderer.d.ts +0 -0
- /package/dist/{config/react → react}/ViewBlock.d.ts +0 -0
- /package/dist/{config/react → react}/ViewBlock.js +0 -0
- /package/dist/{config/react → react}/index.d.ts +0 -0
- /package/dist/{config/react → react}/index.js +0 -0
- /package/dist/{config/react → react}/registry.d.ts +0 -0
- /package/dist/{config/react → react}/registry.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// uims/resolveViewRow.ts
|
|
2
|
-
import { componentRegistry } from '
|
|
2
|
+
import { componentRegistry } from '../../react';
|
|
3
3
|
export function resolveViewRow({ item, rowComponent, rowViewMode, rowPropsMapping }) {
|
|
4
4
|
const Row = componentRegistry[rowComponent.componentName];
|
|
5
5
|
console.log(rowComponent);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// #TODO Gestire doppio caricamento dati:
|
|
3
3
|
// 1 lato payload usando come già fatto api interne di payload mappando i campi in un blocco di tipo view dedicato
|
|
4
|
-
import { resolveInlineComponent } from '../utils/resolveInlineComponent';
|
|
4
|
+
import { resolveInlineComponent } from '../config/utils/resolveInlineComponent';
|
|
5
5
|
import { ViewBlock } from './ViewBlock';
|
|
6
6
|
// 2 recupero dati sempre lato server chiamando un EP in maniera asincrona e gestendo il corretto binding
|
|
7
7
|
export async function PageRenderer({ layout, serverData, }) {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime");const o=({children:o})=>e.jsx("div",{children:o??"Card works"}),r={Card:o};function n(e){return Array.isArray(e)&&e.length>0?e.map(e=>e?.css.className).filter(Boolean).join(" "):e?.css.className??""}function t(o){const{component:t,viewMode:s,rowComponent:c,rowViewMode:i,containerProps:a={},rowPropsMapping:l={},rowChildren:p=[],_resolvedData:m=[],_resolvedOk:d=!0}=o,u=r[t.componentName],w=r[c.componentName];if(!u||!w)return null;if(!d)return e.jsx(u,{className:n(s),children:e.jsx("div",{className:"text-red-600",children:"Impossibile caricare i dati"})});const f=(o,t)=>o.map((o,s)=>{const c=r[o.definition?.componentName];if(!c)return null;const i=Array.isArray(o.viewMode)?o.viewMode[0]:o.viewMode;let a={};if(o.sourceProps&&"object"==typeof o.sourceProps&&Object.keys(o.sourceProps).length>0)for(const[e,r]of Object.entries(o.sourceProps))a[e]=r.toString().split(".").reduce((e,o)=>e?.[o],t);else a=o.staticProps||{};return e.jsx(c,{...a,className:n(i)},s)});return e.jsx(u,{className:n(s),...a,children:m.map((o,r)=>{const t={};for(const[e,r]of Object.entries(l))t[e]=r.toString().split(".").reduce((e,o)=>e?.[o],o);return e.jsx(w,{...t,className:n(i),children:p?.length>0?f(p,o):null},r)})})}function s(e,o){return o.split(".").reduce((e,o)=>e?.[o],e)}exports.Card=o,exports.ComponentRenderer=function({type:o,view:n,data:t}){if("view"!==o)return null;const c=t[n.dataSet],i=r[n.component.componentName],a=r[n.rowComponent.componentName];if(!i||!a)return null;const l=Array.isArray(n.viewMode)?n.viewMode.map(e=>e?.className||"").join(" "):"";return e.jsx(i,{className:l,children:c.map((o,r)=>{const t={};for(const[e,r]of Object.entries(n.rowPropsMapping??{}))t[e]=s(o,r);const c=Array.isArray(n.rowViewMode)?n.rowViewMode.map(e=>e?.className||"").join(" "):"";return e.jsx(a,{...t,className:c},r)})})},exports.PageRenderer=async function({layout:o,serverData:n}){const s=o.map((e,o)=>"view"!==e.blockType?e:(console.log(e),console.log(n),{blockType:e.blockType,component:e.component,viewMode:e.viewMode,containerProps:e.containerProps,rowComponent:e.rowComponent,rowViewMode:e.rowViewMode,rowPropsMapping:e.rowPropsMapping,rowChildren:e.rowChildren,_resolvedData:n[o]??[],_resolvedOk:!0}));return e.jsx(e.Fragment,{children:s.map((o,n)=>{if("view"===o.blockType)return e.jsx(t,{...o},n);const s=function(e){const{definition:o,viewMode:n}=e;if(!o)return null;const t=r[o.componentName];return t?"cta-block"===e.blockType?{Component:t,props:{title:e.title,description:e.description,action:e.actionLabel?{label:e.actionLabel,href:e.actionHref}:void 0,className:n?.css.className??o.defaultStyle}}:{Component:t,props:{...e.props??{},className:n?.css.className??o.defaultStyle}}:null}(o);if(!s)return null;const{Component:c,props:i}=s;return e.jsx(c,{...i},n)})})},exports.ViewBlock=t,exports.componentRegistry=r;
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/react/Card.tsx","../../src/react/registry.ts","../../src/react/ViewBlock.tsx","../../src/react/ComponentRenderer.tsx","../../src/react/PageRenderer.tsx","../../src/config/utils/resolveInlineComponent.ts"],"sourcesContent":["import type { ReactNode } from 'react'\n\ntype CardProps = {\n children?: ReactNode\n}\n\nexport const Card = ({ children }: CardProps) => {\n return <div>{children ?? 'Card works'}</div>\n}\n","// components/registry.ts\nimport { Card } from './Card'\n\nexport const componentRegistry: Record<string, any> = {\n Card,\n}\n","'use client'\n\nimport { componentRegistry } from './registry'\n\nfunction resolveClassName(viewMode: any[] | any | undefined) {\n if (Array.isArray(viewMode) && viewMode.length > 0) {\n return viewMode\n .map((vm) => vm?.css.className)\n .filter(Boolean)\n .join(' ')\n }\n return viewMode?.css.className ?? ''\n}\n\nexport function ViewBlock(block: any) {\n const {\n component,\n viewMode,\n rowComponent,\n rowViewMode,\n containerProps = {},\n rowPropsMapping = {},\n rowChildren = [],\n _resolvedData = [],\n _resolvedOk = true,\n } = block\n const Container = componentRegistry[component.componentName]\n const Row = componentRegistry[rowComponent.componentName]\n if (!Container || !Row) return null\n\n if (!_resolvedOk) {\n return (\n <Container className={resolveClassName(viewMode)}>\n <div className=\"text-red-600\">Impossibile caricare i dati</div>\n </Container>\n )\n }\n\n //#TODO gestire rendering di molteplici rowChildren al mometno stampa solo il primo elemento dell'array\n // --- helper per render figli di riga (con sourceProps mapping) ---\n const renderRowChildren = (children: any[], item: any) => {\n return children.map((child, idx) => {\n const ChildComp = componentRegistry[child.definition?.componentName]\n\n if (!ChildComp) return null\n\n const childVM = Array.isArray(child.viewMode) ? child.viewMode[0] : child.viewMode\n\n const hasSourceProps =\n child.sourceProps &&\n typeof child.sourceProps === 'object' &&\n Object.keys(child.sourceProps).length > 0\n\n let finalProps: any = {}\n\n if (hasSourceProps) {\n for (const [key, path] of Object.entries(child.sourceProps)) {\n // @ts-ignore\n finalProps[key] = path\n .toString()\n .split('.')\n .reduce((acc: any, k: string) => acc?.[k], item)\n }\n } else {\n // fallback ai props statici\n finalProps = child.staticProps || {}\n }\n\n return <ChildComp key={idx} {...finalProps} className={resolveClassName(childVM)} />\n })\n }\n\n return (\n <Container className={resolveClassName(viewMode)} {...containerProps}>\n {_resolvedData.map((item: any, i: number) => {\n const props: any = {}\n\n // mapping valori verso props della card\n for (const [key, path] of Object.entries(rowPropsMapping)) {\n // @ts-ignore\n props[key] = path\n .toString()\n .split('.')\n .reduce((acc: { [x: string]: any }, k: string | number) => acc?.[k], item)\n }\n\n return (\n <Row key={i} {...props} className={resolveClassName(rowViewMode)}>\n {rowChildren?.length > 0 ? renderRowChildren(rowChildren, item) : null}\n </Row>\n )\n })}\n </Container>\n )\n}\n","// components/ComponentRenderer.tsx\n'use client'\nimport { componentRegistry } from './registry'\n\nfunction getValueByPath(obj: any, path: string) {\n return path.split('.').reduce((acc, key) => acc?.[key], obj)\n}\n\nexport function ComponentRenderer({ type, view, data }: any) {\n if (type !== 'view') return null\n const rows = data[view.dataSet]\n const Container = componentRegistry[view.component.componentName]\n\n const Row = componentRegistry[view.rowComponent.componentName]\n if (!Container || !Row) return null\n\n const containerClassNames = Array.isArray(view.viewMode)\n ? view.viewMode.map((mode: { className: string }) => mode?.className || '').join(' ')\n : ''\n\n return (\n <Container className={containerClassNames}>\n {rows.map((item: any, i: number) => {\n const props: any = {}\n\n for (const [k, v] of Object.entries(view.rowPropsMapping ?? {})) {\n props[k] = getValueByPath(item, v as string)\n }\n const rowClassNames = Array.isArray(view.rowViewMode)\n ? view.rowViewMode.map((mode: { className: string }) => mode?.className || '').join(' ')\n : ''\n\n return <Row key={i} {...props} className={rowClassNames} />\n })}\n </Container>\n )\n}\n","// #TODO Gestire doppio caricamento dati:\n// 1 lato payload usando come già fatto api interne di payload mappando i campi in un blocco di tipo view dedicato\n\nimport { resolveInlineComponent } from '../config/utils/resolveInlineComponent'\nimport { ViewBlock } from './ViewBlock'\n\n// 2 recupero dati sempre lato server chiamando un EP in maniera asincrona e gestendo il corretto binding\nexport async function PageRenderer({\n layout,\n serverData,\n}: {\n layout: any[]\n serverData: Record<number, any[]>\n}) {\n const resolvedLayout = layout.map((block, index) => {\n if (block.blockType !== 'view') return block\n console.log(block)\n console.log(serverData)\n return {\n blockType: block.blockType,\n component: block.component,\n viewMode: block.viewMode,\n containerProps: block.containerProps,\n rowComponent: block.rowComponent,\n rowViewMode: block.rowViewMode,\n rowPropsMapping: block.rowPropsMapping,\n rowChildren: block.rowChildren,\n _resolvedData: serverData[index] ?? [],\n _resolvedOk: true,\n }\n })\n\n return (\n <>\n {resolvedLayout.map((block, i) => {\n if (block.blockType === 'view') {\n return <ViewBlock key={i} {...block} />\n }\n\n const resolved = resolveInlineComponent(block)\n if (!resolved) return null\n\n const { Component, props } = resolved\n return <Component key={i} {...props} />\n })}\n </>\n )\n}\n","// uims/resolveInlineComponent.ts\n\nimport { componentRegistry } from '../../react'\n\nexport function resolveInlineComponent(block: any) {\n const { definition, viewMode } = block\n\n if (!definition) return null\n\n const Component = componentRegistry[definition.componentName]\n if (!Component) return null\n\n /* Caso CTA (inline typed) */\n if (block.blockType === 'cta-block') {\n return {\n Component,\n props: {\n title: block.title,\n description: block.description,\n action: block.actionLabel\n ? {\n label: block.actionLabel,\n href: block.actionHref,\n }\n : undefined,\n className: viewMode?.css.className ?? definition.defaultStyle,\n },\n }\n }\n\n /* Caso component-instance generico */\n return {\n Component,\n props: {\n ...(block.props ?? {}),\n className: viewMode?.css.className ?? definition.defaultStyle,\n },\n }\n}\n"],"names":["Card","children","_jsx","componentRegistry","resolveClassName","viewMode","Array","isArray","length","map","vm","css","className","filter","Boolean","join","ViewBlock","block","component","rowComponent","rowViewMode","containerProps","rowPropsMapping","rowChildren","_resolvedData","_resolvedOk","Container","componentName","Row","renderRowChildren","item","child","idx","ChildComp","definition","childVM","finalProps","sourceProps","Object","keys","key","path","entries","toString","split","reduce","acc","k","staticProps","i","props","getValueByPath","obj","type","view","data","rows","dataSet","containerClassNames","mode","v","rowClassNames","async","layout","serverData","resolvedLayout","index","blockType","console","log","_Fragment","resolved","Component","title","description","action","actionLabel","label","href","actionHref","undefined","defaultStyle","resolveInlineComponent"],"mappings":"sDAMaA,EAAO,EAAGC,cACdC,EAAAA,IAAA,MAAA,CAAAD,SAAMA,GAAY,eCJdE,EAAyC,CACpDH,QCAF,SAASI,EAAiBC,GACxB,OAAIC,MAAMC,QAAQF,IAAaA,EAASG,OAAS,EACxCH,EACJI,IAAKC,GAAOA,GAAIC,IAAIC,WACpBC,OAAOC,SACPC,KAAK,KAEHV,GAAUM,IAAIC,WAAa,EACpC,CAEM,SAAUI,EAAUC,GACxB,MAAMC,UACJA,EAASb,SACTA,EAAQc,aACRA,EAAYC,YACZA,EAAWC,eACXA,EAAiB,GAAEC,gBACnBA,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EAAMZ,SAChBgB,eAAgBJ,EAAMI,eACtBF,aAAcF,EAAME,aACpBC,YAAaH,EAAMG,YACnBE,gBAAiBL,EAAMK,gBACvBC,YAAaN,EAAMM,YACnBC,cAAewC,EAAWE,IAAU,GACpCzC,aAAa,KAIjB,OACEvB,EAAAA,IAAAoE,EAAAA,SAAA,CAAArE,SACGgE,EAAexD,IAAI,CAACQ,EAAOgC,KAC1B,GAAwB,SAApBhC,EAAMkD,UACR,OAAOjE,EAAAA,IAACc,EAAS,IAAaC,GAAPgC,GAGzB,MAAMsB,ECnCR,SAAiCtD,GACrC,MAAMiB,WAAEA,EAAU7B,SAAEA,GAAaY,EAEjC,IAAKiB,EAAY,OAAO,KAExB,MAAMsC,EAAYrE,EAAkB+B,EAAWP,eAC/C,OAAK6C,EAGmB,cAApBvD,EAAMkD,UACD,CACLK,YACAtB,MAAO,CACLuB,MAAOxD,EAAMwD,MACbC,YAAazD,EAAMyD,YACnBC,OAAQ1D,EAAM2D,YACV,CACEC,MAAO5D,EAAM2D,YACbE,KAAM7D,EAAM8D,iBAEdC,EACJpE,UAAWP,GAAUM,IAAIC,WAAasB,EAAW+C,eAMhD,CACLT,YACAtB,MAAO,IACDjC,EAAMiC,OAAS,GACnBtC,UAAWP,GAAUM,IAAIC,WAAasB,EAAW+C,eAzB9B,IA4BzB,CDCyBC,CAAuBjE,GACxC,IAAKsD,EAAU,OAAO,KAEtB,MAAMC,UAAEA,EAAStB,MAAEA,GAAUqB,EAC7B,OAAOrE,EAAAA,IAACsE,EAAS,IAAatB,GAAPD,MAI/B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as e,Fragment as o}from"react/jsx-runtime";const n=({children:o})=>e("div",{children:o??"Card works"}),r={Card:n};function t(e){return Array.isArray(e)&&e.length>0?e.map(e=>e?.css.className).filter(Boolean).join(" "):e?.css.className??""}function s(o){const{component:n,viewMode:s,rowComponent:c,rowViewMode:i,containerProps:a={},rowPropsMapping:l={},rowChildren:p=[],_resolvedData:m=[],_resolvedOk:d=!0}=o,u=r[n.componentName],w=r[c.componentName];if(!u||!w)return null;if(!d)return e(u,{className:t(s),children:e("div",{className:"text-red-600",children:"Impossibile caricare i dati"})});const f=(o,n)=>o.map((o,s)=>{const c=r[o.definition?.componentName];if(!c)return null;const i=Array.isArray(o.viewMode)?o.viewMode[0]:o.viewMode;let a={};if(o.sourceProps&&"object"==typeof o.sourceProps&&Object.keys(o.sourceProps).length>0)for(const[e,r]of Object.entries(o.sourceProps))a[e]=r.toString().split(".").reduce((e,o)=>e?.[o],n);else a=o.staticProps||{};return e(c,{...a,className:t(i)},s)});return e(u,{className:t(s),...a,children:m.map((o,n)=>{const r={};for(const[e,n]of Object.entries(l))r[e]=n.toString().split(".").reduce((e,o)=>e?.[o],o);return e(w,{...r,className:t(i),children:p?.length>0?f(p,o):null},n)})})}function c(e,o){return o.split(".").reduce((e,o)=>e?.[o],e)}function i({type:o,view:n,data:t}){if("view"!==o)return null;const s=t[n.dataSet],i=r[n.component.componentName],a=r[n.rowComponent.componentName];if(!i||!a)return null;const l=Array.isArray(n.viewMode)?n.viewMode.map(e=>e?.className||"").join(" "):"";return e(i,{className:l,children:s.map((o,r)=>{const t={};for(const[e,r]of Object.entries(n.rowPropsMapping??{}))t[e]=c(o,r);const s=Array.isArray(n.rowViewMode)?n.rowViewMode.map(e=>e?.className||"").join(" "):"";return e(a,{...t,className:s},r)})})}async function a({layout:n,serverData:t}){const c=n.map((e,o)=>"view"!==e.blockType?e:(console.log(e),console.log(t),{blockType:e.blockType,component:e.component,viewMode:e.viewMode,containerProps:e.containerProps,rowComponent:e.rowComponent,rowViewMode:e.rowViewMode,rowPropsMapping:e.rowPropsMapping,rowChildren:e.rowChildren,_resolvedData:t[o]??[],_resolvedOk:!0}));return e(o,{children:c.map((o,n)=>{if("view"===o.blockType)return e(s,{...o},n);const t=function(e){const{definition:o,viewMode:n}=e;if(!o)return null;const t=r[o.componentName];return t?"cta-block"===e.blockType?{Component:t,props:{title:e.title,description:e.description,action:e.actionLabel?{label:e.actionLabel,href:e.actionHref}:void 0,className:n?.css.className??o.defaultStyle}}:{Component:t,props:{...e.props??{},className:n?.css.className??o.defaultStyle}}:null}(o);if(!t)return null;const{Component:c,props:i}=t;return e(c,{...i},n)})})}export{n as Card,i as ComponentRenderer,a as PageRenderer,s as ViewBlock,r as componentRegistry};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/react/Card.tsx","../../src/react/registry.ts","../../src/react/ViewBlock.tsx","../../src/react/ComponentRenderer.tsx","../../src/react/PageRenderer.tsx","../../src/config/utils/resolveInlineComponent.ts"],"sourcesContent":["import type { ReactNode } from 'react'\n\ntype CardProps = {\n children?: ReactNode\n}\n\nexport const Card = ({ children }: CardProps) => {\n return <div>{children ?? 'Card works'}</div>\n}\n","// components/registry.ts\nimport { Card } from './Card'\n\nexport const componentRegistry: Record<string, any> = {\n Card,\n}\n","'use client'\n\nimport { componentRegistry } from './registry'\n\nfunction resolveClassName(viewMode: any[] | any | undefined) {\n if (Array.isArray(viewMode) && viewMode.length > 0) {\n return viewMode\n .map((vm) => vm?.css.className)\n .filter(Boolean)\n .join(' ')\n }\n return viewMode?.css.className ?? ''\n}\n\nexport function ViewBlock(block: any) {\n const {\n component,\n viewMode,\n rowComponent,\n rowViewMode,\n containerProps = {},\n rowPropsMapping = {},\n rowChildren = [],\n _resolvedData = [],\n _resolvedOk = true,\n } = block\n const Container = componentRegistry[component.componentName]\n const Row = componentRegistry[rowComponent.componentName]\n if (!Container || !Row) return null\n\n if (!_resolvedOk) {\n return (\n <Container className={resolveClassName(viewMode)}>\n <div className=\"text-red-600\">Impossibile caricare i dati</div>\n </Container>\n )\n }\n\n //#TODO gestire rendering di molteplici rowChildren al mometno stampa solo il primo elemento dell'array\n // --- helper per render figli di riga (con sourceProps mapping) ---\n const renderRowChildren = (children: any[], item: any) => {\n return children.map((child, idx) => {\n const ChildComp = componentRegistry[child.definition?.componentName]\n\n if (!ChildComp) return null\n\n const childVM = Array.isArray(child.viewMode) ? child.viewMode[0] : child.viewMode\n\n const hasSourceProps =\n child.sourceProps &&\n typeof child.sourceProps === 'object' &&\n Object.keys(child.sourceProps).length > 0\n\n let finalProps: any = {}\n\n if (hasSourceProps) {\n for (const [key, path] of Object.entries(child.sourceProps)) {\n // @ts-ignore\n finalProps[key] = path\n .toString()\n .split('.')\n .reduce((acc: any, k: string) => acc?.[k], item)\n }\n } else {\n // fallback ai props statici\n finalProps = child.staticProps || {}\n }\n\n return <ChildComp key={idx} {...finalProps} className={resolveClassName(childVM)} />\n })\n }\n\n return (\n <Container className={resolveClassName(viewMode)} {...containerProps}>\n {_resolvedData.map((item: any, i: number) => {\n const props: any = {}\n\n // mapping valori verso props della card\n for (const [key, path] of Object.entries(rowPropsMapping)) {\n // @ts-ignore\n props[key] = path\n .toString()\n .split('.')\n .reduce((acc: { [x: string]: any }, k: string | number) => acc?.[k], item)\n }\n\n return (\n <Row key={i} {...props} className={resolveClassName(rowViewMode)}>\n {rowChildren?.length > 0 ? renderRowChildren(rowChildren, item) : null}\n </Row>\n )\n })}\n </Container>\n )\n}\n","// components/ComponentRenderer.tsx\n'use client'\nimport { componentRegistry } from './registry'\n\nfunction getValueByPath(obj: any, path: string) {\n return path.split('.').reduce((acc, key) => acc?.[key], obj)\n}\n\nexport function ComponentRenderer({ type, view, data }: any) {\n if (type !== 'view') return null\n const rows = data[view.dataSet]\n const Container = componentRegistry[view.component.componentName]\n\n const Row = componentRegistry[view.rowComponent.componentName]\n if (!Container || !Row) return null\n\n const containerClassNames = Array.isArray(view.viewMode)\n ? view.viewMode.map((mode: { className: string }) => mode?.className || '').join(' ')\n : ''\n\n return (\n <Container className={containerClassNames}>\n {rows.map((item: any, i: number) => {\n const props: any = {}\n\n for (const [k, v] of Object.entries(view.rowPropsMapping ?? {})) {\n props[k] = getValueByPath(item, v as string)\n }\n const rowClassNames = Array.isArray(view.rowViewMode)\n ? view.rowViewMode.map((mode: { className: string }) => mode?.className || '').join(' ')\n : ''\n\n return <Row key={i} {...props} className={rowClassNames} />\n })}\n </Container>\n )\n}\n","// #TODO Gestire doppio caricamento dati:\n// 1 lato payload usando come già fatto api interne di payload mappando i campi in un blocco di tipo view dedicato\n\nimport { resolveInlineComponent } from '../config/utils/resolveInlineComponent'\nimport { ViewBlock } from './ViewBlock'\n\n// 2 recupero dati sempre lato server chiamando un EP in maniera asincrona e gestendo il corretto binding\nexport async function PageRenderer({\n layout,\n serverData,\n}: {\n layout: any[]\n serverData: Record<number, any[]>\n}) {\n const resolvedLayout = layout.map((block, index) => {\n if (block.blockType !== 'view') return block\n console.log(block)\n console.log(serverData)\n return {\n blockType: block.blockType,\n component: block.component,\n viewMode: block.viewMode,\n containerProps: block.containerProps,\n rowComponent: block.rowComponent,\n rowViewMode: block.rowViewMode,\n rowPropsMapping: block.rowPropsMapping,\n rowChildren: block.rowChildren,\n _resolvedData: serverData[index] ?? [],\n _resolvedOk: true,\n }\n })\n\n return (\n <>\n {resolvedLayout.map((block, i) => {\n if (block.blockType === 'view') {\n return <ViewBlock key={i} {...block} />\n }\n\n const resolved = resolveInlineComponent(block)\n if (!resolved) return null\n\n const { Component, props } = resolved\n return <Component key={i} {...props} />\n })}\n </>\n )\n}\n","// uims/resolveInlineComponent.ts\n\nimport { componentRegistry } from '../../react'\n\nexport function resolveInlineComponent(block: any) {\n const { definition, viewMode } = block\n\n if (!definition) return null\n\n const Component = componentRegistry[definition.componentName]\n if (!Component) return null\n\n /* Caso CTA (inline typed) */\n if (block.blockType === 'cta-block') {\n return {\n Component,\n props: {\n title: block.title,\n description: block.description,\n action: block.actionLabel\n ? {\n label: block.actionLabel,\n href: block.actionHref,\n }\n : undefined,\n className: viewMode?.css.className ?? definition.defaultStyle,\n },\n }\n }\n\n /* Caso component-instance generico */\n return {\n Component,\n props: {\n ...(block.props ?? {}),\n className: viewMode?.css.className ?? definition.defaultStyle,\n },\n }\n}\n"],"names":["Card","children","_jsx","componentRegistry","resolveClassName","viewMode","Array","isArray","length","map","vm","css","className","filter","Boolean","join","ViewBlock","block","component","rowComponent","rowViewMode","containerProps","rowPropsMapping","rowChildren","_resolvedData","_resolvedOk","Container","componentName","Row","renderRowChildren","item","child","idx","ChildComp","definition","childVM","finalProps","sourceProps","Object","keys","key","path","entries","toString","split","reduce","acc","k","staticProps","i","props","getValueByPath","obj","ComponentRenderer","type","view","data","rows","dataSet","containerClassNames","mode","v","rowClassNames","async","PageRenderer","layout","serverData","resolvedLayout","index","blockType","console","log","_Fragment","resolved","Component","title","description","action","actionLabel","label","href","actionHref","undefined","defaultStyle","resolveInlineComponent"],"mappings":"4DAMaA,EAAO,EAAGC,cACdC,EAAA,MAAA,CAAAD,SAAMA,GAAY,eCJdE,EAAyC,CACpDH,QCAF,SAASI,EAAiBC,GACxB,OAAIC,MAAMC,QAAQF,IAAaA,EAASG,OAAS,EACxCH,EACJI,IAAKC,GAAOA,GAAIC,IAAIC,WACpBC,OAAOC,SACPC,KAAK,KAEHV,GAAUM,IAAIC,WAAa,EACpC,CAEM,SAAUI,EAAUC,GACxB,MAAMC,UACJA,EAASb,SACTA,EAAQc,aACRA,EAAYC,YACZA,EAAWC,eACXA,EAAiB,GAAEC,gBACnBA,EAAkB,CAAA,EAAEC,YACpBA,EAAc,GAAEC,cAChBA,EAAgB,GAAEC,YAClBA,GAAc,GACZR,EACES,EAAYvB,EAAkBe,EAAUS,eACxCC,EAAMzB,EAAkBgB,EAAaQ,eAC3C,IAAKD,IAAcE,EAAK,OAAO,KAE/B,IAAKH,EACH,OACEvB,EAACwB,GAAUd,UAAWR,EAAiBC,GAASJ,SAC9CC,SAAKU,UAAU,eAAcX,SAAA,kCAOnC,MAAM4B,EAAoB,CAAC5B,EAAiB6B,IACnC7B,EAASQ,IAAI,CAACsB,EAAOC,KAC1B,MAAMC,EAAY9B,EAAkB4B,EAAMG,YAAYP,eAEtD,IAAKM,EAAW,OAAO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AAK+C,EAGmB,cAApBzD,EAAMoD,UACD,CACLK,YACAxB,MAAO,CACLyB,MAAO1D,EAAM0D,MACbC,YAAa3D,EAAM2D,YACnBC,OAAQ5D,EAAM6D,YACV,CACEC,MAAO9D,EAAM6D,YACbE,KAAM/D,EAAMgE,iBAEdC,EACJtE,UAAWP,GAAUM,IAAIC,WAAasB,EAAWiD,eAMhD,CACLT,YACAxB,MAAO,IACDjC,EAAMiC,OAAS,GACnBtC,UAAWP,GAAUM,IAAIC,WAAasB,EAAWiD,eAzB9B,IA4BzB,CDCyBC,CAAuBnE,GACxC,IAAKwD,EAAU,OAAO,KAEtB,MAAMC,UAAEA,EAASxB,MAAEA,GAAUuB,EAC7B,OAAOvE,EAACwE,EAAS,IAAaxB,GAAPD,MAI/B"}
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|