@woodylab/payload 0.0.122 → 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.
@@ -0,0 +1,4 @@
1
+ export declare function resolveInlineComponent(block: any): {
2
+ Component: any;
3
+ props: any;
4
+ } | null;
@@ -0,0 +1,35 @@
1
+ // uims/resolveInlineComponent.ts
2
+ import { componentRegistry } from '../../react';
3
+ export function resolveInlineComponent(block) {
4
+ const { definition, viewMode } = block;
5
+ if (!definition)
6
+ return null;
7
+ const Component = componentRegistry[definition.componentName];
8
+ if (!Component)
9
+ return null;
10
+ /* Caso CTA (inline typed) */
11
+ if (block.blockType === 'cta-block') {
12
+ return {
13
+ Component,
14
+ props: {
15
+ title: block.title,
16
+ description: block.description,
17
+ action: block.actionLabel
18
+ ? {
19
+ label: block.actionLabel,
20
+ href: block.actionHref,
21
+ }
22
+ : undefined,
23
+ className: viewMode?.css.className ?? definition.defaultStyle,
24
+ },
25
+ };
26
+ }
27
+ /* Caso component-instance generico */
28
+ return {
29
+ Component,
30
+ props: {
31
+ ...(block.props ?? {}),
32
+ className: viewMode?.css.className ?? definition.defaultStyle,
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,4 @@
1
+ export declare function resolveViewRow({ item, rowComponent, rowViewMode, rowPropsMapping }: any): {
2
+ Row: any;
3
+ props: Record<string, any>;
4
+ } | null;
@@ -0,0 +1,15 @@
1
+ // uims/resolveViewRow.ts
2
+ import { componentRegistry } from '../../react';
3
+ export function resolveViewRow({ item, rowComponent, rowViewMode, rowPropsMapping }) {
4
+ const Row = componentRegistry[rowComponent.componentName];
5
+ console.log(rowComponent);
6
+ if (!Row)
7
+ return null;
8
+ const props = {};
9
+ for (const prop in rowPropsMapping) {
10
+ const path = rowPropsMapping[prop];
11
+ props[prop] = path.split('.').reduce((acc, key) => acc?.[key], item);
12
+ }
13
+ props.className = rowViewMode?.css.className ?? rowComponent.defaultStyle;
14
+ return { Row, props };
15
+ }
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ type CardProps = {
3
+ children?: ReactNode;
4
+ };
5
+ export declare const Card: ({ children }: CardProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const Card = ({ children }) => {
3
+ return _jsx("div", { children: children ?? 'Card works' });
4
+ };
@@ -0,0 +1 @@
1
+ export declare function ComponentRenderer({ type, view, data }: any): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,29 @@
1
+ // components/ComponentRenderer.tsx
2
+ 'use client';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import { componentRegistry } from './registry';
5
+ function getValueByPath(obj, path) {
6
+ return path.split('.').reduce((acc, key) => acc?.[key], obj);
7
+ }
8
+ export function ComponentRenderer({ type, view, data }) {
9
+ if (type !== 'view')
10
+ return null;
11
+ const rows = data[view.dataSet];
12
+ const Container = componentRegistry[view.component.componentName];
13
+ const Row = componentRegistry[view.rowComponent.componentName];
14
+ if (!Container || !Row)
15
+ return null;
16
+ const containerClassNames = Array.isArray(view.viewMode)
17
+ ? view.viewMode.map((mode) => mode?.className || '').join(' ')
18
+ : '';
19
+ return (_jsx(Container, { className: containerClassNames, children: rows.map((item, i) => {
20
+ const props = {};
21
+ for (const [k, v] of Object.entries(view.rowPropsMapping ?? {})) {
22
+ props[k] = getValueByPath(item, v);
23
+ }
24
+ const rowClassNames = Array.isArray(view.rowViewMode)
25
+ ? view.rowViewMode.map((mode) => mode?.className || '').join(' ')
26
+ : '';
27
+ return _jsx(Row, { ...props, className: rowClassNames }, i);
28
+ }) }));
29
+ }
@@ -0,0 +1,4 @@
1
+ export declare function PageRenderer({ layout, serverData, }: {
2
+ layout: any[];
3
+ serverData: Record<number, any[]>;
4
+ }): Promise<import("react/jsx-runtime").JSX.Element>;
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // #TODO Gestire doppio caricamento dati:
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 '../config/utils/resolveInlineComponent';
5
+ import { ViewBlock } from './ViewBlock';
6
+ // 2 recupero dati sempre lato server chiamando un EP in maniera asincrona e gestendo il corretto binding
7
+ export async function PageRenderer({ layout, serverData, }) {
8
+ const resolvedLayout = layout.map((block, index) => {
9
+ if (block.blockType !== 'view')
10
+ return block;
11
+ console.log(block);
12
+ console.log(serverData);
13
+ return {
14
+ blockType: block.blockType,
15
+ component: block.component,
16
+ viewMode: block.viewMode,
17
+ containerProps: block.containerProps,
18
+ rowComponent: block.rowComponent,
19
+ rowViewMode: block.rowViewMode,
20
+ rowPropsMapping: block.rowPropsMapping,
21
+ rowChildren: block.rowChildren,
22
+ _resolvedData: serverData[index] ?? [],
23
+ _resolvedOk: true,
24
+ };
25
+ });
26
+ return (_jsx(_Fragment, { children: resolvedLayout.map((block, i) => {
27
+ if (block.blockType === 'view') {
28
+ return _jsx(ViewBlock, { ...block }, i);
29
+ }
30
+ const resolved = resolveInlineComponent(block);
31
+ if (!resolved)
32
+ return null;
33
+ const { Component, props } = resolved;
34
+ return _jsx(Component, { ...props }, i);
35
+ }) }));
36
+ }
@@ -0,0 +1 @@
1
+ export declare function ViewBlock(block: any): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,62 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { componentRegistry } from './registry';
4
+ function resolveClassName(viewMode) {
5
+ if (Array.isArray(viewMode) && viewMode.length > 0) {
6
+ return viewMode
7
+ .map((vm) => vm?.css.className)
8
+ .filter(Boolean)
9
+ .join(' ');
10
+ }
11
+ return viewMode?.css.className ?? '';
12
+ }
13
+ export function ViewBlock(block) {
14
+ const { component, viewMode, rowComponent, rowViewMode, containerProps = {}, rowPropsMapping = {}, rowChildren = [], _resolvedData = [], _resolvedOk = true, } = block;
15
+ const Container = componentRegistry[component.componentName];
16
+ const Row = componentRegistry[rowComponent.componentName];
17
+ if (!Container || !Row)
18
+ return null;
19
+ if (!_resolvedOk) {
20
+ return (_jsx(Container, { className: resolveClassName(viewMode), children: _jsx("div", { className: "text-red-600", children: "Impossibile caricare i dati" }) }));
21
+ }
22
+ //#TODO gestire rendering di molteplici rowChildren al mometno stampa solo il primo elemento dell'array
23
+ // --- helper per render figli di riga (con sourceProps mapping) ---
24
+ const renderRowChildren = (children, item) => {
25
+ return children.map((child, idx) => {
26
+ const ChildComp = componentRegistry[child.definition?.componentName];
27
+ if (!ChildComp)
28
+ return null;
29
+ const childVM = Array.isArray(child.viewMode) ? child.viewMode[0] : child.viewMode;
30
+ const hasSourceProps = child.sourceProps &&
31
+ typeof child.sourceProps === 'object' &&
32
+ Object.keys(child.sourceProps).length > 0;
33
+ let finalProps = {};
34
+ if (hasSourceProps) {
35
+ for (const [key, path] of Object.entries(child.sourceProps)) {
36
+ // @ts-ignore
37
+ finalProps[key] = path
38
+ .toString()
39
+ .split('.')
40
+ .reduce((acc, k) => acc?.[k], item);
41
+ }
42
+ }
43
+ else {
44
+ // fallback ai props statici
45
+ finalProps = child.staticProps || {};
46
+ }
47
+ return _jsx(ChildComp, { ...finalProps, className: resolveClassName(childVM) }, idx);
48
+ });
49
+ };
50
+ return (_jsx(Container, { className: resolveClassName(viewMode), ...containerProps, children: _resolvedData.map((item, i) => {
51
+ const props = {};
52
+ // mapping valori verso props della card
53
+ for (const [key, path] of Object.entries(rowPropsMapping)) {
54
+ // @ts-ignore
55
+ props[key] = path
56
+ .toString()
57
+ .split('.')
58
+ .reduce((acc, k) => acc?.[k], item);
59
+ }
60
+ return (_jsx(Row, { ...props, className: resolveClassName(rowViewMode), children: rowChildren?.length > 0 ? renderRowChildren(rowChildren, item) : null }, i));
61
+ }) }));
62
+ }
@@ -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,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,EAAAA,IAACwB,GAAUd,UAAWR,EAAiBC,GAASJ,S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,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,5 @@
1
+ export { Card } from './Card';
2
+ export { ViewBlock } from './ViewBlock';
3
+ export { ComponentRenderer } from './ComponentRenderer';
4
+ export { PageRenderer } from './PageRenderer';
5
+ export * from './registry';
@@ -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,KAEvB,MAAME,EAAU7B,MAAMC,QAAQwB,EAAM1B,UAAY0B,EAAM1B,SAAS,GAAK0B,EAAM1B,SAO1E,IAAI+B,EAAkB,CAAA,EAEtB,GANEL,EAAMM,aACuB,iBAA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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"}
@@ -0,0 +1,5 @@
1
+ export { Card } from './Card';
2
+ export { ViewBlock } from './ViewBlock';
3
+ export { ComponentRenderer } from './ComponentRenderer';
4
+ export { PageRenderer } from './PageRenderer';
5
+ export * from './registry';
@@ -0,0 +1 @@
1
+ export declare const componentRegistry: Record<string, any>;
@@ -0,0 +1,5 @@
1
+ // components/registry.ts
2
+ import { Card } from './Card';
3
+ export const componentRegistry = {
4
+ Card,
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woodylab/payload",
3
- "version": "0.0.122",
3
+ "version": "0.0.125",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",