@woodylab/payload 0.0.133 → 0.0.134

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.
Files changed (43) hide show
  1. package/dist/LayoutRenderer-B9mdu_LN.js +2 -0
  2. package/dist/LayoutRenderer-B9mdu_LN.js.map +1 -0
  3. package/dist/LayoutRenderer-DHEQyk3K.js +2 -0
  4. package/dist/LayoutRenderer-DHEQyk3K.js.map +1 -0
  5. package/dist/config/blocks/blockCard.js +159 -84
  6. package/dist/config/blocks/blockView.js +37 -6
  7. package/dist/config/index.cjs.js +1 -1
  8. package/dist/config/index.cjs.js.map +1 -1
  9. package/dist/config/index.esm.js +1 -1
  10. package/dist/config/index.esm.js.map +1 -1
  11. package/dist/index.cjs.js +1 -1
  12. package/dist/index.esm.js +1 -1
  13. package/dist/react/LayoutRenderer.js +6 -7
  14. package/dist/react/componentRegistry.js +6 -2
  15. package/dist/react/components/Card.d.ts +1 -1
  16. package/dist/react/components/Card.js +2 -1
  17. package/dist/react/components/Section.d.ts +5 -0
  18. package/dist/react/components/Section.js +4 -0
  19. package/dist/react/components/View.d.ts +1 -1
  20. package/dist/react/components/View.js +4 -6
  21. package/dist/react/index.cjs.js +1 -1
  22. package/dist/react/index.esm.js +1 -1
  23. package/dist/resolveLayout-C5t_MveG.js +2 -0
  24. package/dist/resolveLayout-C5t_MveG.js.map +1 -0
  25. package/dist/resolveLayout-DGll1vY2.js +2 -0
  26. package/dist/resolveLayout-DGll1vY2.js.map +1 -0
  27. package/dist/uims/index.cjs.js +1 -1
  28. package/dist/uims/index.esm.js +1 -1
  29. package/dist/uims/resolver/resolveInlineBlock.d.ts +10 -3
  30. package/dist/uims/resolver/resolveInlineBlock.js +23 -12
  31. package/dist/uims/resolver/resolveViewBlock.d.ts +13 -5
  32. package/dist/uims/resolver/resolveViewBlock.js +27 -18
  33. package/package.json +1 -1
  34. package/dist/LayoutRenderer-B1IoWb16.js +0 -2
  35. package/dist/LayoutRenderer-B1IoWb16.js.map +0 -1
  36. package/dist/LayoutRenderer-Ba6ITI7O.js +0 -2
  37. package/dist/LayoutRenderer-Ba6ITI7O.js.map +0 -1
  38. package/dist/react/ComponentRenderer.d.ts +0 -1
  39. package/dist/react/ComponentRenderer.js +0 -29
  40. package/dist/resolveLayout-DlRnQBn8.js +0 -2
  41. package/dist/resolveLayout-DlRnQBn8.js.map +0 -1
  42. package/dist/resolveLayout-DryOXHEy.js +0 -2
  43. package/dist/resolveLayout-DryOXHEy.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("./resolveLayout-DlRnQBn8.js"),o=require("./config/index.cjs.js"),t=require("./utils/index.cjs.js"),s=require("./LayoutRenderer-B1IoWb16.js");require("react/jsx-runtime"),exports.Card=e.Card,exports.Container=e.Container,exports.applyStylesToProps=e.applyStylesToProps,exports.componentRegistry=e.componentRegistry,exports.getValueByPath=e.getValueByPath,exports.mapDataToProps=e.mapDataToProps,exports.resolveLayout=e.resolveLayout,exports.resolveViewData=e.resolveViewData,exports.blockCard=o.blockCard,exports.blockReference=o.blockReference,exports.blockView=o.blockView,exports.collectionBlocks=o.collectionBlocks,exports.collectionComponentDefinitions=o.collectionComponentDefinitions,exports.collectionMenus=o.collectionMenus,exports.collectionStyles=o.collectionStyles,exports.collectionViewModes=o.collectionViewModes,exports.concatCssFields=o.concatCssFields,exports.configFooter=o.configFooter,exports.configHeader=o.configHeader,exports.configSettings=o.configSettings,exports.fieldCss=o.fieldCss,exports.fieldRoles=o.fieldRoles,exports.tailwindField=o.tailwindField,exports.tailwindFieldsSelectors=o.tailwindFieldsSelectors,exports.tailwindSelectorVariants=o.tailwindSelectorVariants,exports.generateCssVars=t.generateCssVars,exports.iconsList=t.iconsList,exports.LayoutRenderer=s.LayoutRenderer,exports.View=s.View;
1
+ "use strict";var e=require("./resolveLayout-C5t_MveG.js"),o=require("./config/index.cjs.js"),t=require("./utils/index.cjs.js"),s=require("./LayoutRenderer-B9mdu_LN.js");require("react/jsx-runtime"),exports.Card=e.Card,exports.Container=e.Container,exports.View=e.View,exports.applyStylesToProps=e.applyStylesToProps,exports.componentRegistry=e.componentRegistry,exports.getValueByPath=e.getValueByPath,exports.mapDataToProps=e.mapDataToProps,exports.resolveLayout=e.resolveLayout,exports.resolveViewData=e.resolveViewData,exports.blockCard=o.blockCard,exports.blockReference=o.blockReference,exports.blockView=o.blockView,exports.collectionBlocks=o.collectionBlocks,exports.collectionComponentDefinitions=o.collectionComponentDefinitions,exports.collectionMenus=o.collectionMenus,exports.collectionStyles=o.collectionStyles,exports.collectionViewModes=o.collectionViewModes,exports.concatCssFields=o.concatCssFields,exports.configFooter=o.configFooter,exports.configHeader=o.configHeader,exports.configSettings=o.configSettings,exports.fieldCss=o.fieldCss,exports.fieldRoles=o.fieldRoles,exports.tailwindField=o.tailwindField,exports.tailwindFieldsSelectors=o.tailwindFieldsSelectors,exports.tailwindSelectorVariants=o.tailwindSelectorVariants,exports.generateCssVars=t.generateCssVars,exports.iconsList=t.iconsList,exports.LayoutRenderer=s.LayoutRenderer;
2
2
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- export{C as Card,c as Container,b as applyStylesToProps,d as componentRegistry,g as getValueByPath,m as mapDataToProps,a as resolveLayout,r as resolveViewData}from"./resolveLayout-DryOXHEy.js";export{blockCard,blockReference,blockView,collectionBlocks,collectionComponentDefinitions,collectionMenus,collectionStyles,collectionViewModes,concatCssFields,configFooter,configHeader,configSettings,fieldCss,fieldRoles,tailwindField,tailwindFieldsSelectors,tailwindSelectorVariants}from"./config/index.esm.js";export{generateCssVars,iconsList}from"./utils/index.esm.js";export{L as LayoutRenderer,V as View}from"./LayoutRenderer-Ba6ITI7O.js";import"react/jsx-runtime";
1
+ export{C as Card,c as Container,V as View,b as applyStylesToProps,d as componentRegistry,g as getValueByPath,m as mapDataToProps,a as resolveLayout,r as resolveViewData}from"./resolveLayout-DGll1vY2.js";export{blockCard,blockReference,blockView,collectionBlocks,collectionComponentDefinitions,collectionMenus,collectionStyles,collectionViewModes,concatCssFields,configFooter,configHeader,configSettings,fieldCss,fieldRoles,tailwindField,tailwindFieldsSelectors,tailwindSelectorVariants}from"./config/index.esm.js";export{generateCssVars,iconsList}from"./utils/index.esm.js";export{L as LayoutRenderer}from"./LayoutRenderer-DHEQyk3K.js";import"react/jsx-runtime";
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -1,5 +1,4 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { View } from './components/View';
3
2
  import { resolveLayout } from '../uims';
4
3
  import { createUIMSContext } from '../uims/resolver/createUIMSContext';
5
4
  //#TODO Ricordarsi di introdurre il concetto di PageRenderer, sarebbe carino se riuscissimo a delegarle la stampa anche dei meta dati e info accessorie oltre al layout.
@@ -9,11 +8,11 @@ export async function LayoutRenderer({ layout, payload }) {
9
8
  return (_jsx(_Fragment, { children: resolvedLayout.map((block, i) => {
10
9
  if (!block)
11
10
  return null;
12
- if (block.rows) {
13
- return _jsx(View, { ...block }, i);
14
- }
15
- const { Component, props } = block;
16
- return _jsx(Component, { ...props }, i);
17
- return null;
11
+ const { section, container, content } = block;
12
+ const { SectionComponent, SectionStylesBySlot } = section;
13
+ const { ContainerComponent, ContainerStylesBySlot } = container;
14
+ const { ContentComponent } = content;
15
+ // #TODO sarebbe carino rimuovere la stampa condizionale e includere invece un blocco View come componente per la stampa generica
16
+ return (_jsx(SectionComponent, { className: SectionStylesBySlot.root, children: _jsx(ContainerComponent, { className: ContainerStylesBySlot.root, children: _jsx(ContentComponent, { ...content }) }) }, i));
18
17
  }) }));
19
18
  }
@@ -1,7 +1,11 @@
1
1
  // components/registry.ts
2
- import { Container } from '.';
3
2
  import { Card } from './components/Card';
3
+ import { Section } from './components/Section';
4
+ import { Container } from './components/Container';
5
+ import { View } from './components/View';
4
6
  export const componentRegistry = {
5
- Card,
7
+ Section,
6
8
  Container,
9
+ View,
10
+ Card,
7
11
  };
@@ -15,5 +15,5 @@ export type CardProps = {
15
15
  descriptionProps?: CardTextProps;
16
16
  children?: ReactNode;
17
17
  };
18
- export declare const Card: ({ className, imageProps, titleProps, descriptionProps, children, }: CardProps) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const Card: (args: any) => import("react/jsx-runtime").JSX.Element;
19
19
  export {};
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- export const Card = ({ className, imageProps, titleProps, descriptionProps, children, }) => {
2
+ export const Card = (args) => {
3
+ const { className, imageProps, titleProps, descriptionProps, children } = args;
3
4
  // # TODO sarebbe da aggiungere un componente specifico per la stampa dei valori non stilati. Ossia se non viene selezionato alcun componente in fase di editing e per esempio le proprietà di una card arrivano a un DIV
4
5
  // Questo non è in grado di stampare i valori simil JSON, discorso diverso invece si presenta se a ricevere tutte le proprietà è invece un componente dedicato (comodo anche per debug)
5
6
  return (_jsxs("div", { className: className, children: [imageProps?.src && (_jsx("img", { src: imageProps.src, alt: imageProps.alt ?? '', className: imageProps.className })), titleProps?.text && _jsx("h3", { className: titleProps.className, children: titleProps.text }), descriptionProps?.text && (_jsx("p", { className: descriptionProps.className, children: descriptionProps.text })), children] }));
@@ -0,0 +1,5 @@
1
+ export type SectionProps = {
2
+ className?: string;
3
+ children?: [];
4
+ };
5
+ export declare const Section: ({ className, children }: SectionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const Section = ({ className, children }) => {
3
+ return _jsx("section", { className: className, children: children });
4
+ };
@@ -1 +1 @@
1
- export declare function View({ className, rows, viewMode, rowViewMode }: any): import("react/jsx-runtime").JSX.Element;
1
+ export declare function View(args: any): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,7 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { componentRegistry } from '../componentRegistry';
3
- export function View({ className = '', rows = [], viewMode, rowViewMode }) {
4
- const ContainerComponent = componentRegistry[viewMode?.component] ?? 'div';
5
- const RowComponent = componentRegistry[rowViewMode?.component] ?? 'div';
6
- return (_jsx(ContainerComponent, { className: className, children: rows.map((rowProps, i) => {
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ export function View(args) {
3
+ const { RowComponent, rows } = args;
4
+ return (_jsx(_Fragment, { children: rows.map((rowProps, i) => {
7
5
  return _jsx(RowComponent, { ...rowProps }, i);
8
6
  }) }));
9
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("../resolveLayout-DlRnQBn8.js"),r=require("../LayoutRenderer-B1IoWb16.js");require("react/jsx-runtime"),exports.Card=e.Card,exports.Container=e.Container,exports.componentRegistry=e.componentRegistry,exports.LayoutRenderer=r.LayoutRenderer,exports.View=r.View;
1
+ "use strict";var e=require("../resolveLayout-C5t_MveG.js"),r=require("../LayoutRenderer-B9mdu_LN.js");require("react/jsx-runtime"),exports.Card=e.Card,exports.Container=e.Container,exports.View=e.View,exports.componentRegistry=e.componentRegistry,exports.LayoutRenderer=r.LayoutRenderer;
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1,2 +1,2 @@
1
- export{C as Card,c as Container,d as componentRegistry}from"../resolveLayout-DryOXHEy.js";export{L as LayoutRenderer,V as View}from"../LayoutRenderer-Ba6ITI7O.js";import"react/jsx-runtime";
1
+ export{C as Card,c as Container,V as View,d as componentRegistry}from"../resolveLayout-DGll1vY2.js";export{L as LayoutRenderer}from"../LayoutRenderer-DHEQyk3K.js";import"react/jsx-runtime";
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime");async function t(e,t){const s={};for(let r=0;r<t.length;r++){const a=t[r];if(!o(a))continue;const c=await n({payload:e,block:a});s[r]=Array.isArray(c)?c:[]}return s}function o(e){return"view"===e.blockType}async function n({payload:e,block:t}){return t.useInternalSource?async function({payload:e,block:t}){const o=await e.find({collection:t.internalCollection,sort:t.internalSort||void 0,depth:t.internalDepth??1});return o?.docs??[]}({payload:e,block:t}):t.dataSource?async function({payload:e,block:t}){try{const e=await fetch(t.dataSource),o=await e.json();return Array.isArray(o?.[t.dataSet])?o[t.dataSet]:[]}catch{return[]}}({payload:e,block:t}):[]}const s=t=>{const{className:o,imageProps:n,titleProps:s,descriptionProps:r,children:a}=t;return e.jsxs("div",{className:o,children:[n?.src&&e.jsx("img",{src:n.src,alt:n.alt??"",className:n.className}),s?.text&&e.jsx("h3",{className:s.className,children:s.text}),r?.text&&e.jsx("p",{className:r.className,children:r.text}),a]})},r=({className:t,children:o})=>e.jsx("div",{className:t,children:o});function a(t){const{RowComponent:o,rows:n}=t;return e.jsx(e.Fragment,{children:n.map((t,n)=>e.jsx(o,{...t},n))})}const c={Section:({className:t,children:o})=>e.jsx("section",{className:t,children:o}),Container:r,View:a,Card:s};function i(e){const t={};if(!e?.styles)return t;for(const o of e.styles){const e=o.style;e&&(t[o.slot]=e)}return t}function l(e,t){if(!t)return e;const o={...e};for(const[e,n]of Object.entries(t))"root"!==e?o[e]&&"object"==typeof o[e]&&(o[e]={...o[e],className:[o[e].className,n].filter(Boolean).join(" ")}):o.className=[o.className,n].filter(Boolean).join(" ");return o}function p(e,t){return t.split(".").reduce((e,t)=>e?e[t]:void 0,e)}function u({data:e,mapper:t}){const o={};if(!t)return o;for(const n of Object.keys(t)){const s=t[n];"string"==typeof s&&s.startsWith("__static:")?o[n]=s.replace("__static:",""):o[n]="string"!=typeof s?"object"!=typeof s||null===s?void 0:u({data:e,mapper:s}):p(e,s)}return o}function y({block:e,context:t}){const o=t.registries.viewMode.byName[e.viewMode],n=t.registries.viewMode.byName[e.sectionViewMode],s=t.registries.viewMode.byName[e.containerViewMode],r=c[n?.component],a=c[s?.component],p=c[o.component],y=i(n),d=i(s),m=i(o);return{section:{SectionComponent:r,SectionStylesBySlot:y},container:{ContainerComponent:a,ContainerStylesBySlot:d},content:{ContentComponent:p,...l(u({data:e,mapper:o.blockPropsMapping}),m)}}}function d({block:e,rows:t,context:o}){const n=o.registries.viewMode.byName[e.sectionViewMode],s=o.registries.viewMode.byName[e.containerViewMode],r=o.registries.viewMode.byName[e.rowViewMode],a=c[n?.component],p=c[s?.component],y=c.View,d=c[r?.component],m=i(n),f=i(s),w=i(r);return{section:{SectionComponent:a,SectionStylesBySlot:m},container:{ContainerComponent:p,ContainerStylesBySlot:f},content:{ContentComponent:y,RowComponent:d,rows:t.map(t=>l(u({data:t,mapper:e.rowPropsMapping}),w))}}}exports.Card=s,exports.Container=r,exports.View=a,exports.applyStylesToProps=l,exports.componentRegistry=c,exports.getValueByPath=p,exports.mapDataToProps=u,exports.resolveLayout=async function e({layout:o,context:n}){const s=[],r=await t(n.payload,o);for(const[t,a]of o.entries())if("view"===a.blockType)s.push(d({block:a,rows:r[t]??[],context:n}));else if("reference"===a.blockType){const t=await e({layout:a.block.value.layout,context:n});s.push(...t)}else s.push(y({block:a,context:n}));return s},exports.resolveViewData=t;
2
+ //# sourceMappingURL=resolveLayout-C5t_MveG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLayout-C5t_MveG.js","sources":["../src/uims/resolver/resolveViewData.ts","../src/react/components/Card.tsx","../src/react/components/Container.tsx","../src/react/components/View.tsx","../src/react/componentRegistry.ts","../src/react/components/Section.tsx","../src/uims/resolver/resolveStylesBySlot.ts","../src/uims/mapper/applyStylesToProps.ts","../src/uims/mapper/getValueByPath.ts","../src/uims/mapper/mapDataToProps.ts","../src/uims/resolver/resolveInlineBlock.ts","../src/uims/resolver/resolveViewBlock.ts","../src/uims/resolver/resolveLayout.ts"],"sourcesContent":["import { BasePayload } from 'payload'\n\ntype ResolveViewDataParams = {\n payload: BasePayload\n layout: any[]\n}\n\ntype ViewDataResult = Record<number, any[]>\n\nexport async function resolveViewData(\n payload: BasePayload,\n layout: any[],\n): Promise<ViewDataResult> {\n const results: ViewDataResult = {}\n\n for (let index = 0; index < layout.length; index++) {\n const block = layout[index]\n\n if (!isViewBlock(block)) {\n continue\n }\n\n const data = await fetchViewBlockData({\n payload,\n block,\n })\n\n results[index] = Array.isArray(data) ? data : []\n }\n\n return results\n}\n\n// ──────────────────────────────────────────────\n// Helpers locali\n// ──────────────────────────────────────────────\n\nfunction isViewBlock(block: any): boolean {\n return block.blockType === 'view'\n}\n\nasync function fetchViewBlockData({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n // Sorgente interna (Payload)\n if (block.useInternalSource) {\n return fetchInternalCollection({\n payload,\n block,\n })\n }\n\n // Sorgente esterna (REST)\n if (block.dataSource) {\n return fetchExternalSource({\n payload,\n block,\n })\n }\n\n return []\n}\n\nasync function fetchInternalCollection({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n const result = await payload.find({\n collection: block.internalCollection,\n sort: block.internalSort || undefined,\n depth: block.internalDepth ?? 1,\n })\n\n return result?.docs ?? []\n}\n\nasync function fetchExternalSource({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n try {\n const res = await fetch(block.dataSource)\n const json = await res.json()\n\n return Array.isArray(json?.[block.dataSet]) ? json[block.dataSet] : []\n } catch {\n return []\n }\n}\n","import type { ReactNode } from 'react'\n\ntype CardTextProps = {\n text?: string\n className?: string\n}\n\ntype CardImageProps = {\n src?: string\n alt?: string\n className?: string\n}\n\nexport type CardProps = {\n className?: string\n imageProps?: CardImageProps\n titleProps?: CardTextProps\n descriptionProps?: CardTextProps\n children?: ReactNode\n}\n\nexport const Card = (args: any) => {\n const { className, imageProps, titleProps, descriptionProps, children } = args\n // # TODO sarebbe da aggiungere un componente specifico per la stampa dei valori non stilati. Ossia se non viene selezionato alcun componente in fase di editing e per esempio le proprietà di una card arrivano a un DIV\n // Questo non è in grado di stampare i valori simil JSON, discorso diverso invece si presenta se a ricevere tutte le proprietà è invece un componente dedicato (comodo anche per debug)\n return (\n <div className={className}>\n {imageProps?.src && (\n <img src={imageProps.src} alt={imageProps.alt ?? ''} className={imageProps.className} />\n )}\n\n {titleProps?.text && <h3 className={titleProps.className}>{titleProps.text}</h3>}\n\n {descriptionProps?.text && (\n <p className={descriptionProps.className}>{descriptionProps.text}</p>\n )}\n\n {children}\n </div>\n )\n}\n","export type ContainerProps = {\n className?: string\n children?: []\n}\n\nexport const Container = ({ className, children }: ContainerProps) => {\n return <div className={className}>{children}</div>\n}\n","export function View(args: any) {\n const { RowComponent, rows } = args\n \n return (\n <>\n {rows.map((rowProps: any, i: number) => {\n return <RowComponent key={i} {...rowProps} />\n })}\n </>\n )\n}\n","// components/registry.ts\nimport { Card } from './components/Card'\nimport { Section } from './components/Section'\nimport { Container } from './components/Container'\nimport { View } from './components/View'\n\nexport const componentRegistry: Record<string, any> = {\n Section,\n Container,\n View,\n Card,\n}\n","export type SectionProps = {\n className?: string\n children?: []\n}\n\nexport const Section = ({ className, children }: SectionProps) => {\n return <section className={className}>{children}</section>\n}\n","type ViewMode = {\n css?: {\n className?: string\n }\n styles?: Array<{\n slot: string\n style: string\n }>\n}\n\nexport function resolveStylesBySlot(viewMode: ViewMode): Record<string, string> {\n const result: Record<string, string> = {}\n\n if (!viewMode?.styles) return result\n\n for (const entry of viewMode.styles) {\n const classNames = entry.style\n\n if (classNames) {\n result[entry.slot] = classNames\n }\n }\n\n return result\n}\n","type StylesBySlot = Record<string, string>\ntype AnyProps = Record<string, any>\n\nexport function applyStylesToProps<T extends AnyProps>(props: T, stylesBySlot?: StylesBySlot): T {\n if (!stylesBySlot) return props\n const nextProps = { ...props } as AnyProps\n\n for (const [slot, className] of Object.entries(stylesBySlot)) {\n if (slot === 'root') {\n nextProps['className'] = [nextProps['className'], className].filter(Boolean).join(' ')\n continue\n }\n if (nextProps[slot] && typeof nextProps[slot] === 'object') {\n nextProps[slot] = {\n ...nextProps[slot],\n className: [nextProps[slot].className, className].filter(Boolean).join(' '),\n }\n }\n }\n\n return nextProps as T\n}\n","export function getValueByPath(obj: any, path: string): any {\n return path.split('.').reduce((acc, key) => (acc ? acc[key] : undefined), obj)\n}\n","import { getValueByPath } from './getValueByPath'\n\ntype Mapper = Record<string, any>\n\nexport function mapDataToProps<T = any>({ data, mapper }: { data: any; mapper: Mapper }): T {\n const result: any = {}\n if (!mapper) return result\n for (const key of Object.keys(mapper)) {\n const rule = mapper[key]\n if (typeof rule === 'string' && rule.startsWith('__static:')) {\n result[key] = rule.replace('__static:', '')\n continue\n }\n\n if (typeof rule === 'string') {\n result[key] = getValueByPath(data, rule)\n continue\n }\n\n if (typeof rule === 'object' && rule !== null) {\n result[key] = mapDataToProps({\n data,\n mapper: rule,\n })\n continue\n }\n\n result[key] = undefined\n }\n\n return result\n}\n","import { componentRegistry } from '../../react/componentRegistry'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { mapDataToProps } from '../mapper/mapDataToProps'\n\nexport function resolveInlineBlock({ block, context }: { block: any; context: UIMSContext }) {\n const viewMode = context.registries.viewMode.byName[block.viewMode]\n const sectionViewMode = context.registries.viewMode.byName[block.sectionViewMode]\n const containerViewMode = context.registries.viewMode.byName[block.containerViewMode]\n const SectionComponent = componentRegistry[sectionViewMode?.component]\n const ContainerComponent = componentRegistry[containerViewMode?.component]\n const ContentComponent = componentRegistry[viewMode.component]\n const SectionStylesBySlot = resolveStylesBySlot(sectionViewMode)\n const ContainerStylesBySlot = resolveStylesBySlot(containerViewMode)\n const ContentStyleBySlot = resolveStylesBySlot(viewMode)\n const content = applyStylesToProps(\n mapDataToProps({\n data: block,\n mapper: viewMode.blockPropsMapping,\n }),\n ContentStyleBySlot,\n )\n\n return {\n section: {\n SectionComponent,\n SectionStylesBySlot,\n },\n container: {\n ContainerComponent,\n ContainerStylesBySlot,\n },\n content: {\n ContentComponent,\n ...content,\n },\n }\n}\n","import { mapDataToProps } from '../mapper/mapDataToProps'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { componentRegistry } from '../../react'\n\nexport function resolveViewBlock({\n block,\n rows,\n context,\n}: {\n block: any\n rows: any[]\n context: UIMSContext\n}) {\n const sectionViewMode = context.registries.viewMode.byName[block.sectionViewMode]\n const containerViewMode = context.registries.viewMode.byName[block.containerViewMode]\n const rowViewMode = context.registries.viewMode.byName[block.rowViewMode]\n\n const SectionComponent = componentRegistry[sectionViewMode?.component]\n const ContainerComponent = componentRegistry[containerViewMode?.component]\n const ContentComponent = componentRegistry['View']\n const RowComponent = componentRegistry[rowViewMode?.component]\n\n const SectionStylesBySlot = resolveStylesBySlot(sectionViewMode)\n const ContainerStylesBySlot = resolveStylesBySlot(containerViewMode)\n const RowStylesBySlot = resolveStylesBySlot(rowViewMode)\n\n const viewRows = rows.map((row) =>\n applyStylesToProps(\n mapDataToProps({\n data: row,\n mapper: block.rowPropsMapping,\n }),\n RowStylesBySlot,\n ),\n )\n\n return {\n section: {\n SectionComponent,\n SectionStylesBySlot,\n },\n container: {\n ContainerComponent,\n ContainerStylesBySlot,\n },\n content: {\n ContentComponent,\n RowComponent,\n rows: viewRows,\n },\n }\n}\n","import { resolveInlineBlock } from './resolveInlineBlock'\nimport { resolveViewBlock } from './resolveViewBlock'\nimport { resolveViewData } from './resolveViewData'\nimport { UIMSContext } from '../types/UIMSContext'\n\nexport async function resolveLayout({\n layout,\n context,\n}: {\n layout: Array<any>\n context: UIMSContext\n}) {\n const resolved: any[] = []\n const viewData = await resolveViewData(context.payload, layout)\n for (const [index, block] of layout.entries()) {\n if (block.blockType === 'view') {\n resolved.push(\n resolveViewBlock({\n block,\n rows: viewData[index] ?? [],\n context,\n }),\n )\n } else if (block.blockType === 'reference') {\n const nestedResolved = await resolveLayout({ layout: block.block.value.layout, context })\n resolved.push(...nestedResolved)\n } else {\n resolved.push(resolveInlineBlock({ block, context }))\n }\n }\n return resolved\n}\n"],"names":["async","resolveViewData","payload","layout","results","index","length","block","isViewBlock","data","fetchViewBlockData","Array","isArray","blockType","useInternalSource","result","find","collection","internalCollection","sort","internalSort","undefined","depth","internalDepth","docs","fetchInternalCollection","dataSource","res","fetch","json","dataSet","fetchExternalSource","Card","args","className","imageProps","titleProps","descriptionProps","children","_jsxs","src","_jsx","alt","text","Container","View","RowComponent","rows","_Fragment","map","rowProps","i","componentRegistry","Section","resolveStylesBySlot","viewMode","styles","entry","classNames","style","slot","applyStylesToProps","props","stylesBySlot","nextProps","Object","entries","filter","Boolean","join","getValueByPath","obj","path","split","reduce","acc","key","mapDataToProps","mapper","keys","rule","startsWith","replace","resolveInlineBlock","context","registries","byName","sectionViewMode","containerViewMode","SectionComponent","component","ContainerComponent","ContentComponent","SectionStylesBySlot","ContainerStylesBySlot","ContentStyleBySlot","section","container","content","blockPropsMapping","resolveViewBlock","rowViewMode","RowStylesBySlot","row","rowPropsMapping","resolveLayout","resolved","viewData","push","nestedResolved","value"],"mappings":"gDASOA,eAAeC,EACpBC,EACAC,GAEA,MAAMC,EAA0B,CAAA,EAEhC,IAAK,IAAIC,EAAQ,EAAGA,EAAQF,EAAOG,OAAQD,IAAS,CAClD,MAAME,EAAQJ,EAAOE,GAErB,IAAKG,EAAYD,GACf,SAGF,MAAME,QAAaC,EAAmB,CACpCR,UACAK,UAGFH,EAAQC,GAASM,MAAMC,QAAQH,GAAQA,EAAO,EAChD,CAEA,OAAOL,CACT,CAMA,SAASI,EAAYD,GACnB,MAA2B,SAApBA,EAAMM,SACf,CAEAb,eAAeU,GAAmBR,QAChCA,EAAOK,MACPA,IAMA,OAAIA,EAAMO,kBAkBZd,gBAAuCE,QACrCA,EAAOK,MACPA,IAKA,MAAMQ,QAAeb,EAAQc,KAAK,CAChCC,WAAYV,EAAMW,mBAClBC,KAAMZ,EAAMa,mBAAgBC,EAC5BC,MAAOf,EAAMgB,eAAiB,IAGhC,OAAOR,GAAQS,MAAQ,EACzB,CA/BWC,CAAwB,CAC7B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CACf7F,QACAwC,KAAM4D,EAAStG,IAAU,GACzB+E,kBAGC,GAAwB,cAApB7E,EAAMM,UAA2B,CAC1C,MAAMgG,QAAuBJ,EAAc,CAAEtG,OAAQI,EAAMA,MAAMuG,MAAM3G,OAAQiF,YAC/EsB,EAASE,QAAQC,EACnB,MACEH,EAASE,KAAKzB,EAAmB,CAAE5E,QAAO6E,aAG9C,OAAOsB,CACT"}
@@ -0,0 +1,2 @@
1
+ import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";async function n(e,t){const o={};for(let n=0;n<t.length;n++){const s=t[n];if(!a(s))continue;const r=await c({payload:e,block:s});o[n]=Array.isArray(r)?r:[]}return o}function a(e){return"view"===e.blockType}async function c({payload:e,block:t}){return t.useInternalSource?async function({payload:e,block:t}){const o=await e.find({collection:t.internalCollection,sort:t.internalSort||void 0,depth:t.internalDepth??1});return o?.docs??[]}({payload:e,block:t}):t.dataSource?async function({payload:e,block:t}){try{const e=await fetch(t.dataSource),o=await e.json();return Array.isArray(o?.[t.dataSet])?o[t.dataSet]:[]}catch{return[]}}({payload:e,block:t}):[]}const s=o=>{const{className:n,imageProps:a,titleProps:c,descriptionProps:s,children:r}=o;return e("div",{className:n,children:[a?.src&&t("img",{src:a.src,alt:a.alt??"",className:a.className}),c?.text&&t("h3",{className:c.className,children:c.text}),s?.text&&t("p",{className:s.className,children:s.text}),r]})},r=({className:e,children:o})=>t("div",{className:e,children:o});function i(e){const{RowComponent:n,rows:a}=e;return t(o,{children:a.map((e,o)=>t(n,{...e},o))})}const l={Section:({className:e,children:o})=>t("section",{className:e,children:o}),Container:r,View:i,Card:s};function p(e){const t={};if(!e?.styles)return t;for(const o of e.styles){const e=o.style;e&&(t[o.slot]=e)}return t}function d(e,t){if(!t)return e;const o={...e};for(const[e,n]of Object.entries(t))"root"!==e?o[e]&&"object"==typeof o[e]&&(o[e]={...o[e],className:[o[e].className,n].filter(Boolean).join(" ")}):o.className=[o.className,n].filter(Boolean).join(" ");return o}function m(e,t){return t.split(".").reduce((e,t)=>e?e[t]:void 0,e)}function u({data:e,mapper:t}){const o={};if(!t)return o;for(const n of Object.keys(t)){const a=t[n];"string"==typeof a&&a.startsWith("__static:")?o[n]=a.replace("__static:",""):o[n]="string"!=typeof a?"object"!=typeof a||null===a?void 0:u({data:e,mapper:a}):m(e,a)}return o}function y({block:e,context:t}){const o=t.registries.viewMode.byName[e.viewMode],n=t.registries.viewMode.byName[e.sectionViewMode],a=t.registries.viewMode.byName[e.containerViewMode],c=l[n?.component],s=l[a?.component],r=l[o.component],i=p(n),m=p(a),y=p(o);return{section:{SectionComponent:c,SectionStylesBySlot:i},container:{ContainerComponent:s,ContainerStylesBySlot:m},content:{ContentComponent:r,...d(u({data:e,mapper:o.blockPropsMapping}),y)}}}function f({block:e,rows:t,context:o}){const n=o.registries.viewMode.byName[e.sectionViewMode],a=o.registries.viewMode.byName[e.containerViewMode],c=o.registries.viewMode.byName[e.rowViewMode],s=l[n?.component],r=l[a?.component],i=l.View,m=l[c?.component],y=p(n),f=p(a),w=p(c);return{section:{SectionComponent:s,SectionStylesBySlot:y},container:{ContainerComponent:r,ContainerStylesBySlot:f},content:{ContentComponent:i,RowComponent:m,rows:t.map(t=>d(u({data:t,mapper:e.rowPropsMapping}),w))}}}async function w({layout:e,context:t}){const o=[],a=await n(t.payload,e);for(const[n,c]of e.entries())if("view"===c.blockType)o.push(f({block:c,rows:a[n]??[],context:t}));else if("reference"===c.blockType){const e=await w({layout:c.block.value.layout,context:t});o.push(...e)}else o.push(y({block:c,context:t}));return o}export{s as C,i as V,w as a,d as b,r as c,l as d,m as g,u as m,n as r};
2
+ //# sourceMappingURL=resolveLayout-DGll1vY2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLayout-DGll1vY2.js","sources":["../src/uims/resolver/resolveViewData.ts","../src/react/components/Card.tsx","../src/react/components/Container.tsx","../src/react/components/View.tsx","../src/react/componentRegistry.ts","../src/react/components/Section.tsx","../src/uims/resolver/resolveStylesBySlot.ts","../src/uims/mapper/applyStylesToProps.ts","../src/uims/mapper/getValueByPath.ts","../src/uims/mapper/mapDataToProps.ts","../src/uims/resolver/resolveInlineBlock.ts","../src/uims/resolver/resolveViewBlock.ts","../src/uims/resolver/resolveLayout.ts"],"sourcesContent":["import { BasePayload } from 'payload'\n\ntype ResolveViewDataParams = {\n payload: BasePayload\n layout: any[]\n}\n\ntype ViewDataResult = Record<number, any[]>\n\nexport async function resolveViewData(\n payload: BasePayload,\n layout: any[],\n): Promise<ViewDataResult> {\n const results: ViewDataResult = {}\n\n for (let index = 0; index < layout.length; index++) {\n const block = layout[index]\n\n if (!isViewBlock(block)) {\n continue\n }\n\n const data = await fetchViewBlockData({\n payload,\n block,\n })\n\n results[index] = Array.isArray(data) ? data : []\n }\n\n return results\n}\n\n// ──────────────────────────────────────────────\n// Helpers locali\n// ──────────────────────────────────────────────\n\nfunction isViewBlock(block: any): boolean {\n return block.blockType === 'view'\n}\n\nasync function fetchViewBlockData({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n // Sorgente interna (Payload)\n if (block.useInternalSource) {\n return fetchInternalCollection({\n payload,\n block,\n })\n }\n\n // Sorgente esterna (REST)\n if (block.dataSource) {\n return fetchExternalSource({\n payload,\n block,\n })\n }\n\n return []\n}\n\nasync function fetchInternalCollection({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n const result = await payload.find({\n collection: block.internalCollection,\n sort: block.internalSort || undefined,\n depth: block.internalDepth ?? 1,\n })\n\n return result?.docs ?? []\n}\n\nasync function fetchExternalSource({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n try {\n const res = await fetch(block.dataSource)\n const json = await res.json()\n\n return Array.isArray(json?.[block.dataSet]) ? json[block.dataSet] : []\n } catch {\n return []\n }\n}\n","import type { ReactNode } from 'react'\n\ntype CardTextProps = {\n text?: string\n className?: string\n}\n\ntype CardImageProps = {\n src?: string\n alt?: string\n className?: string\n}\n\nexport type CardProps = {\n className?: string\n imageProps?: CardImageProps\n titleProps?: CardTextProps\n descriptionProps?: CardTextProps\n children?: ReactNode\n}\n\nexport const Card = (args: any) => {\n const { className, imageProps, titleProps, descriptionProps, children } = args\n // # TODO sarebbe da aggiungere un componente specifico per la stampa dei valori non stilati. Ossia se non viene selezionato alcun componente in fase di editing e per esempio le proprietà di una card arrivano a un DIV\n // Questo non è in grado di stampare i valori simil JSON, discorso diverso invece si presenta se a ricevere tutte le proprietà è invece un componente dedicato (comodo anche per debug)\n return (\n <div className={className}>\n {imageProps?.src && (\n <img src={imageProps.src} alt={imageProps.alt ?? ''} className={imageProps.className} />\n )}\n\n {titleProps?.text && <h3 className={titleProps.className}>{titleProps.text}</h3>}\n\n {descriptionProps?.text && (\n <p className={descriptionProps.className}>{descriptionProps.text}</p>\n )}\n\n {children}\n </div>\n )\n}\n","export type ContainerProps = {\n className?: string\n children?: []\n}\n\nexport const Container = ({ className, children }: ContainerProps) => {\n return <div className={className}>{children}</div>\n}\n","export function View(args: any) {\n const { RowComponent, rows } = args\n \n return (\n <>\n {rows.map((rowProps: any, i: number) => {\n return <RowComponent key={i} {...rowProps} />\n })}\n </>\n )\n}\n","// components/registry.ts\nimport { Card } from './components/Card'\nimport { Section } from './components/Section'\nimport { Container } from './components/Container'\nimport { View } from './components/View'\n\nexport const componentRegistry: Record<string, any> = {\n Section,\n Container,\n View,\n Card,\n}\n","export type SectionProps = {\n className?: string\n children?: []\n}\n\nexport const Section = ({ className, children }: SectionProps) => {\n return <section className={className}>{children}</section>\n}\n","type ViewMode = {\n css?: {\n className?: string\n }\n styles?: Array<{\n slot: string\n style: string\n }>\n}\n\nexport function resolveStylesBySlot(viewMode: ViewMode): Record<string, string> {\n const result: Record<string, string> = {}\n\n if (!viewMode?.styles) return result\n\n for (const entry of viewMode.styles) {\n const classNames = entry.style\n\n if (classNames) {\n result[entry.slot] = classNames\n }\n }\n\n return result\n}\n","type StylesBySlot = Record<string, string>\ntype AnyProps = Record<string, any>\n\nexport function applyStylesToProps<T extends AnyProps>(props: T, stylesBySlot?: StylesBySlot): T {\n if (!stylesBySlot) return props\n const nextProps = { ...props } as AnyProps\n\n for (const [slot, className] of Object.entries(stylesBySlot)) {\n if (slot === 'root') {\n nextProps['className'] = [nextProps['className'], className].filter(Boolean).join(' ')\n continue\n }\n if (nextProps[slot] && typeof nextProps[slot] === 'object') {\n nextProps[slot] = {\n ...nextProps[slot],\n className: [nextProps[slot].className, className].filter(Boolean).join(' '),\n }\n }\n }\n\n return nextProps as T\n}\n","export function getValueByPath(obj: any, path: string): any {\n return path.split('.').reduce((acc, key) => (acc ? acc[key] : undefined), obj)\n}\n","import { getValueByPath } from './getValueByPath'\n\ntype Mapper = Record<string, any>\n\nexport function mapDataToProps<T = any>({ data, mapper }: { data: any; mapper: Mapper }): T {\n const result: any = {}\n if (!mapper) return result\n for (const key of Object.keys(mapper)) {\n const rule = mapper[key]\n if (typeof rule === 'string' && rule.startsWith('__static:')) {\n result[key] = rule.replace('__static:', '')\n continue\n }\n\n if (typeof rule === 'string') {\n result[key] = getValueByPath(data, rule)\n continue\n }\n\n if (typeof rule === 'object' && rule !== null) {\n result[key] = mapDataToProps({\n data,\n mapper: rule,\n })\n continue\n }\n\n result[key] = undefined\n }\n\n return result\n}\n","import { componentRegistry } from '../../react/componentRegistry'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { mapDataToProps } from '../mapper/mapDataToProps'\n\nexport function resolveInlineBlock({ block, context }: { block: any; context: UIMSContext }) {\n const viewMode = context.registries.viewMode.byName[block.viewMode]\n const sectionViewMode = context.registries.viewMode.byName[block.sectionViewMode]\n const containerViewMode = context.registries.viewMode.byName[block.containerViewMode]\n const SectionComponent = componentRegistry[sectionViewMode?.component]\n const ContainerComponent = componentRegistry[containerViewMode?.component]\n const ContentComponent = componentRegistry[viewMode.component]\n const SectionStylesBySlot = resolveStylesBySlot(sectionViewMode)\n const ContainerStylesBySlot = resolveStylesBySlot(containerViewMode)\n const ContentStyleBySlot = resolveStylesBySlot(viewMode)\n const content = applyStylesToProps(\n mapDataToProps({\n data: block,\n mapper: viewMode.blockPropsMapping,\n }),\n ContentStyleBySlot,\n )\n\n return {\n section: {\n SectionComponent,\n SectionStylesBySlot,\n },\n container: {\n ContainerComponent,\n ContainerStylesBySlot,\n },\n content: {\n ContentComponent,\n ...content,\n },\n }\n}\n","import { mapDataToProps } from '../mapper/mapDataToProps'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { componentRegistry } from '../../react'\n\nexport function resolveViewBlock({\n block,\n rows,\n context,\n}: {\n block: any\n rows: any[]\n context: UIMSContext\n}) {\n const sectionViewMode = context.registries.viewMode.byName[block.sectionViewMode]\n const containerViewMode = context.registries.viewMode.byName[block.containerViewMode]\n const rowViewMode = context.registries.viewMode.byName[block.rowViewMode]\n\n const SectionComponent = componentRegistry[sectionViewMode?.component]\n const ContainerComponent = componentRegistry[containerViewMode?.component]\n const ContentComponent = componentRegistry['View']\n const RowComponent = componentRegistry[rowViewMode?.component]\n\n const SectionStylesBySlot = resolveStylesBySlot(sectionViewMode)\n const ContainerStylesBySlot = resolveStylesBySlot(containerViewMode)\n const RowStylesBySlot = resolveStylesBySlot(rowViewMode)\n\n const viewRows = rows.map((row) =>\n applyStylesToProps(\n mapDataToProps({\n data: row,\n mapper: block.rowPropsMapping,\n }),\n RowStylesBySlot,\n ),\n )\n\n return {\n section: {\n SectionComponent,\n SectionStylesBySlot,\n },\n container: {\n ContainerComponent,\n ContainerStylesBySlot,\n },\n content: {\n ContentComponent,\n RowComponent,\n rows: viewRows,\n },\n }\n}\n","import { resolveInlineBlock } from './resolveInlineBlock'\nimport { resolveViewBlock } from './resolveViewBlock'\nimport { resolveViewData } from './resolveViewData'\nimport { UIMSContext } from '../types/UIMSContext'\n\nexport async function resolveLayout({\n layout,\n context,\n}: {\n layout: Array<any>\n context: UIMSContext\n}) {\n const resolved: any[] = []\n const viewData = await resolveViewData(context.payload, layout)\n for (const [index, block] of layout.entries()) {\n if (block.blockType === 'view') {\n resolved.push(\n resolveViewBlock({\n block,\n rows: viewData[index] ?? [],\n context,\n }),\n )\n } else if (block.blockType === 'reference') {\n const nestedResolved = await resolveLayout({ layout: block.block.value.layout, context })\n resolved.push(...nestedResolved)\n } else {\n resolved.push(resolveInlineBlock({ block, context }))\n }\n }\n return resolved\n}\n"],"names":["async","resolveViewData","payload","layout","results","index","length","block","isViewBlock","data","fetchViewBlockData","Array","isArray","blockType","useInternalSource","result","find","collection","internalCollection","sort","internalSort","undefined","depth","internalDepth","docs","fetchInternalCollection","dataSource","res","fetch","json","dataSet","fetchExternalSource","Card","args","className","imageProps","titleProps","descriptionProps","children","_jsxs","src","_jsx","alt","text","Container","View","RowComponent","rows","_Fragment","map","rowProps","i","componentRegistry","Section","resolveStylesBySlot","viewMode","styles","entry","classNames","style","slot","applyStylesToProps","props","stylesBySlot","nextProps","Object","entries","filter","Boolean","join","getValueByPath","obj","path","split","reduce","acc","key","mapDataToProps","mapper","keys","rule","startsWith","replace","resolveInlineBlock","context","registries","byName","sectionViewMode","containerViewMode","SectionComponent","component","ContainerComponent","ContentComponent","SectionStylesBySlot","ContainerStylesBySlot","ContentStyleBySlot","section","container","content","blockPropsMapping","resolveViewBlock","rowViewMode","RowStylesBySlot","row","rowPropsMapping","resolveLayout","resolved","viewData","push","nestedResolved","value"],"mappings":"gEASOA,eAAeC,EACpBC,EACAC,GAEA,MAAMC,EAA0B,CAAA,EAEhC,IAAK,IAAIC,EAAQ,EAAGA,EAAQF,EAAOG,OAAQD,IAAS,CAClD,MAAME,EAAQJ,EAAOE,GAErB,IAAKG,EAAYD,GACf,SAGF,MAAME,QAAaC,EAAmB,CACpCR,UACAK,UAGFH,EAAQC,GAASM,MAAMC,QA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,mBACA9C,eACAC,KAtBaA,EAAKE,IAAKsD,GACzB1C,EACEgB,EAAe,CACbpE,KAAM8F,EACNzB,OAAQvE,EAAMiG,kBAEhBF,KAmBN,CChDOtG,eAAeyG,GAActG,OAClCA,EAAMiF,QACNA,IAKA,MAAMsB,EAAkB,GAClBC,QAAiB1G,EAAgBmF,EAAQlF,QAASC,GACxD,IAAK,MAAOE,EAAOE,KAAUJ,EAAO+D,UAClC,GAAwB,SAApB3D,EAAMM,UACR6F,EAASE,KACPR,EAAiB,CACf7F,QACAwC,KAAM4D,EAAStG,IAAU,GACzB+E,kBAGC,GAAwB,cAApB7E,EAAMM,UAA2B,CAC1C,MAAMgG,QAAuBJ,EAAc,CAAEtG,OAAQI,EAAMA,MAAMuG,MAAM3G,OAAQiF,YAC/EsB,EAASE,QAAQC,EACnB,MACEH,EAASE,KAAKzB,EAAmB,CAAE5E,QAAO6E,aAG9C,OAAOsB,CACT"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("../resolveLayout-DlRnQBn8.js");require("react/jsx-runtime"),exports.applyStylesToProps=e.applyStylesToProps,exports.getValueByPath=e.getValueByPath,exports.mapDataToProps=e.mapDataToProps,exports.resolveLayout=e.resolveLayout,exports.resolveViewData=e.resolveViewData;
1
+ "use strict";var e=require("../resolveLayout-C5t_MveG.js");require("react/jsx-runtime"),exports.applyStylesToProps=e.applyStylesToProps,exports.getValueByPath=e.getValueByPath,exports.mapDataToProps=e.mapDataToProps,exports.resolveLayout=e.resolveLayout,exports.resolveViewData=e.resolveViewData;
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1,2 +1,2 @@
1
- export{b as applyStylesToProps,g as getValueByPath,m as mapDataToProps,a as resolveLayout,r as resolveViewData}from"../resolveLayout-DryOXHEy.js";import"react/jsx-runtime";
1
+ export{b as applyStylesToProps,g as getValueByPath,m as mapDataToProps,a as resolveLayout,r as resolveViewData}from"../resolveLayout-DGll1vY2.js";import"react/jsx-runtime";
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -3,6 +3,13 @@ export declare function resolveInlineBlock({ block, context }: {
3
3
  block: any;
4
4
  context: UIMSContext;
5
5
  }): {
6
- Component: any;
7
- props: any;
8
- } | null;
6
+ section: {
7
+ SectionComponent: any;
8
+ SectionStylesBySlot: Record<string, string>;
9
+ };
10
+ container: {
11
+ ContainerComponent: any;
12
+ ContainerStylesBySlot: Record<string, string>;
13
+ };
14
+ content: any;
15
+ };
@@ -3,20 +3,31 @@ import { resolveStylesBySlot } from './resolveStylesBySlot';
3
3
  import { applyStylesToProps } from '../mapper/applyStylesToProps';
4
4
  import { mapDataToProps } from '../mapper/mapDataToProps';
5
5
  export function resolveInlineBlock({ block, context }) {
6
- //const viewMode = context.registries.viewMode.byId[block.viewMode.value]
7
6
  const viewMode = context.registries.viewMode.byName[block.viewMode];
8
- console.log('viewMode', viewMode);
9
- if (!viewMode)
10
- return null;
11
- const Component = componentRegistry[viewMode.component];
12
- const stylesBySlot = resolveStylesBySlot(viewMode);
7
+ const sectionViewMode = context.registries.viewMode.byName[block.sectionViewMode];
8
+ const containerViewMode = context.registries.viewMode.byName[block.containerViewMode];
9
+ const SectionComponent = componentRegistry[sectionViewMode?.component];
10
+ const ContainerComponent = componentRegistry[containerViewMode?.component];
11
+ const ContentComponent = componentRegistry[viewMode.component];
12
+ const SectionStylesBySlot = resolveStylesBySlot(sectionViewMode);
13
+ const ContainerStylesBySlot = resolveStylesBySlot(containerViewMode);
14
+ const ContentStyleBySlot = resolveStylesBySlot(viewMode);
15
+ const content = applyStylesToProps(mapDataToProps({
16
+ data: block,
17
+ mapper: viewMode.blockPropsMapping,
18
+ }), ContentStyleBySlot);
13
19
  return {
14
- Component,
15
- props: {
16
- ...applyStylesToProps(mapDataToProps({
17
- data: block,
18
- mapper: viewMode.blockPropsMapping,
19
- }), stylesBySlot),
20
+ section: {
21
+ SectionComponent,
22
+ SectionStylesBySlot,
23
+ },
24
+ container: {
25
+ ContainerComponent,
26
+ ContainerStylesBySlot,
27
+ },
28
+ content: {
29
+ ContentComponent,
30
+ ...content,
20
31
  },
21
32
  };
22
33
  }
@@ -4,9 +4,17 @@ export declare function resolveViewBlock({ block, rows, context, }: {
4
4
  rows: any[];
5
5
  context: UIMSContext;
6
6
  }): {
7
- className: any;
8
- viewMode: any;
9
- props: any;
10
- rowViewMode: any;
11
- rows: any[];
7
+ section: {
8
+ SectionComponent: any;
9
+ SectionStylesBySlot: Record<string, string>;
10
+ };
11
+ container: {
12
+ ContainerComponent: any;
13
+ ContainerStylesBySlot: Record<string, string>;
14
+ };
15
+ content: {
16
+ ContentComponent: any;
17
+ RowComponent: any;
18
+ rows: any[];
19
+ };
12
20
  };
@@ -1,26 +1,35 @@
1
1
  import { mapDataToProps } from '../mapper/mapDataToProps';
2
2
  import { resolveStylesBySlot } from './resolveStylesBySlot';
3
3
  import { applyStylesToProps } from '../mapper/applyStylesToProps';
4
+ import { componentRegistry } from '../../react';
4
5
  export function resolveViewBlock({ block, rows, context, }) {
5
- const viewMode = context.registries.viewMode.byName[block.viewMode];
6
+ const sectionViewMode = context.registries.viewMode.byName[block.sectionViewMode];
7
+ const containerViewMode = context.registries.viewMode.byName[block.containerViewMode];
6
8
  const rowViewMode = context.registries.viewMode.byName[block.rowViewMode];
7
- const stylesBySlot = resolveStylesBySlot(rowViewMode);
8
- const className = viewMode?.styles.map((style) => {
9
- return style.style
10
- .map((ss, i) => {
11
- const s = context.registries.styles.byName[ss.value.name];
12
- return ss.value.css.className;
13
- })
14
- .join(' ');
15
- });
9
+ const SectionComponent = componentRegistry[sectionViewMode?.component];
10
+ const ContainerComponent = componentRegistry[containerViewMode?.component];
11
+ const ContentComponent = componentRegistry['View'];
12
+ const RowComponent = componentRegistry[rowViewMode?.component];
13
+ const SectionStylesBySlot = resolveStylesBySlot(sectionViewMode);
14
+ const ContainerStylesBySlot = resolveStylesBySlot(containerViewMode);
15
+ const RowStylesBySlot = resolveStylesBySlot(rowViewMode);
16
+ const viewRows = rows.map((row) => applyStylesToProps(mapDataToProps({
17
+ data: row,
18
+ mapper: block.rowPropsMapping,
19
+ }), RowStylesBySlot));
16
20
  return {
17
- className,
18
- viewMode,
19
- props: block,
20
- rowViewMode,
21
- rows: rows.map((row) => applyStylesToProps(mapDataToProps({
22
- data: row,
23
- mapper: block.rowPropsMapping,
24
- }), stylesBySlot)),
21
+ section: {
22
+ SectionComponent,
23
+ SectionStylesBySlot,
24
+ },
25
+ container: {
26
+ ContainerComponent,
27
+ ContainerStylesBySlot,
28
+ },
29
+ content: {
30
+ ContentComponent,
31
+ RowComponent,
32
+ rows: viewRows,
33
+ },
25
34
  };
26
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woodylab/payload",
3
- "version": "0.0.133",
3
+ "version": "0.0.134",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -1,2 +0,0 @@
1
- "use strict";var n=require("react/jsx-runtime"),e=require("./resolveLayout-DlRnQBn8.js");function t({className:t="",rows:o=[],viewMode:a,rowViewMode:r}){const i=e.componentRegistry[a?.component]??"div",s=e.componentRegistry[r?.component]??"div";return n.jsx(i,{className:t,children:o.map((e,t)=>n.jsx(s,{...e},t))})}let o=null;async function a(n){if(o)return o;const e=await n.find({collection:"styles",depth:4,pagination:!1}),t={};for(const n of e.docs??[])n.name&&(t[n.name]=n);return o={byName:t},o}let r=null;async function i(n){if(r)return r;const e=await n.find({collection:"view-modes",depth:4,pagination:!1}),t={};for(const n of e.docs??[])n.name&&(t[n.name]=n);return r={byName:t},r}let s=null;async function c(n){if(s)return s;const e=await n.find({collection:"component-definitions",depth:4,pagination:!1}),t={};for(const n of e.docs??[])n.name&&(t[n.name]=n);return s={byName:t},s}exports.LayoutRenderer=async function({layout:o,payload:r}){const s=await async function(n){return{payload:n,registries:{styles:await a(n),viewMode:await i(n),component:await c(n)}}}(r),u=await e.resolveLayout({layout:o,context:s});return n.jsx(n.Fragment,{children:u.map((e,o)=>{if(!e)return null;if(e.rows)return n.jsx(t,{...e},o);const{Component:a,props:r}=e;return n.jsx(a,{...r},o)})})},exports.View=t;
2
- //# sourceMappingURL=LayoutRenderer-B1IoWb16.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LayoutRenderer-B1IoWb16.js","sources":["../src/react/components/View.tsx","../src/uims/registry/styleRegistry.ts","../src/uims/registry/viewModeRegistry.ts","../src/uims/registry/componentRegistry.ts","../src/react/LayoutRenderer.tsx","../src/uims/resolver/createUIMSContext.ts"],"sourcesContent":["import { componentRegistry } from '../componentRegistry'\n\nexport function View({ className = '', rows = [], viewMode, rowViewMode }: any) {\n const ContainerComponent = componentRegistry[viewMode?.component] ?? 'div'\n const RowComponent = componentRegistry[rowViewMode?.component] ?? 'div'\n\n return (\n <ContainerComponent className={className}>\n {rows.map((rowProps: any, i: number) => {\n return <RowComponent key={i} {...rowProps} />\n })}\n </ContainerComponent>\n )\n}\n","import { BasePayload } from 'payload'\n\nlet cache: {\n byName: Record<string, any>\n} | null = null\n\n//# TODO sarebbe sensato cancellare la cache o forzare un nuovo caricamento quando viene fatta una modifica a uno degli elementi della collection\nexport async function getStyleRegistry(payload: BasePayload) {\n if (cache) {\n return cache\n }\n\n const result = await payload.find({\n collection: 'styles',\n depth: 4,\n pagination: false,\n })\n\n const byName: Record<string, any> = {}\n\n for (const vm of result.docs ?? []) {\n if (vm.name) {\n byName[vm.name] = vm\n }\n }\n\n cache = { byName }\n return cache\n}\n","import { BasePayload } from 'payload'\n\nlet cache: {\n byName: Record<string, any>\n} | null = null\n\n//# TODO sarebbe sensato cancellare la cache o forzare un nuovo caricamento quando viene fatta una modifica a uno degli elementi della collection\nexport async function getViewModeRegistry(payload: BasePayload) {\n if (cache) {\n return cache\n }\n\n const result = await payload.find({\n collection: 'view-modes',\n depth: 4,\n pagination: false,\n })\n\n const byName: Record<string, any> = {}\n\n for (const vm of result.docs ?? []) {\n if (vm.name) {\n byName[vm.name] = vm\n }\n }\n\n cache = { byName }\n return cache\n}\n","import { BasePayload } from 'payload'\n\nlet cache: {\n byName: Record<string, any>\n} | null = null\n\n//# TODO sarebbe sensato cancellare la cache o forzare un nuovo caricamento quando viene fatta una modifica a uno degli elementi della collection\nexport async function getComponentRegistry(payload: BasePayload) {\n if (cache) {\n return cache\n }\n\n const result = await payload.find({\n collection: 'component-definitions',\n depth: 4,\n pagination: false,\n })\n\n const byName: Record<string, any> = {}\n\n for (const vm of result.docs ?? []) {\n if (vm.name) {\n byName[vm.name] = vm\n }\n }\n\n cache = { byName }\n return cache\n}\n","import { BasePayload } from 'payload'\nimport { View } from './components/View'\nimport { resolveLayout } from '../uims'\nimport { createUIMSContext } from '../uims/resolver/createUIMSContext'\n\n//#TODO Ricordarsi di introdurre il concetto di PageRenderer, sarebbe carino se riuscissimo a delegarle la stampa anche dei meta dati e info accessorie oltre al layout.\nexport async function LayoutRenderer({ layout, payload }: { layout: any[]; payload: BasePayload }) {\n const uims = await createUIMSContext(payload)\n const resolvedLayout = await resolveLayout({ layout, context: uims })\n return (\n <>\n {resolvedLayout.map((block: any, i: any) => {\n if (!block) return null\n if (block.rows) {\n return <View key={i} {...block} />\n }\n\n const { Component, props } = block\n return <Component key={i} {...props} />\n\n return null\n })}\n </>\n )\n}\n","import { BasePayload } from 'payload'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { getStyleRegistry } from '../registry/styleRegistry'\nimport { getViewModeRegistry } from '../registry/viewModeRegistry'\nimport { getComponentRegistry } from '../registry/componentRegistry'\n\nexport async function createUIMSContext(payload: BasePayload): Promise<UIMSContext> {\n return {\n payload,\n registries: {\n styles: await getStyleRegistry(payload),\n viewMode: await getViewModeRegistry(payload),\n component: await getComponentRegistry(payload),\n },\n }\n}\n"],"names":["View","className","rows","viewMode","rowViewMode","ContainerComponent","componentRegistry","component","RowComponent","_jsx","children","map","rowProps","i","cache","async","getStyleRegistry","payload","result","find","collection","depth","pagination","byName","vm","docs","name","getViewModeRegistry","getComponentRegistry","layout","uims","registries","styles","createUIMSContext","resolvedLayout","resolveLayout","context","_Fragment","block","Component","props"],"mappings":"yFAEM,SAAUA,GAAKC,UAAEA,EAAY,GAAEC,KAAEA,EAAO,GAAEC,SAAEA,EAAQC,YAAEA,IAC1D,MAAMC,EAAqBC,EAAAA,kBAAkBH,GAAUI,YAAc,MAC/DC,EAAeF,EAAAA,kBAAkBF,GAAaG,YAAc,MAElE,OACEE,MAACJ,EAAkB,CAACJ,UAAWA,EAASS,SACrCR,EAAKS,IAAI,CAACC,EAAeC,IACjBJ,EAAAA,IAACD,EAAY,IAAaI,GAAPC,KAIlC,CCXA,IAAIC,EAEO,KAGJC,eAAeC,EAAiBC,GACrC,GAAIH,EACF,OAAOA,EAGT,MAAMI,QAAeD,EAAQE,KAAK,CAChCC,WAAY,SACZC,MAAO,EACPC,YAAY,IAGRC,EAA8B,CAAA,EAEpC,IAAK,MAAMC,KAAMN,EAAOO,MAAQ,GAC1BD,EAAGE,OACLH,EAAOC,EAAGE,MAAQF,GAKtB,OADAV,EAAQ,CAAES,UACHT,CACT,CC1BA,IAAIA,EAEO,KAGJC,eAAeY,EAAoBV,GACxC,GAAIH,EACF,OAAOA,EAGT,MAAMI,QAAeD,EAAQE,KAAK,CAChCC,WAAY,aACZC,MAAO,EACPC,YAAY,IAGRC,EAA8B,CAAA,EAEpC,IAAK,MAAMC,KAAMN,EAAOO,MAAQ,GAC1BD,EAAGE,OACLH,EAAOC,EAAGE,MAAQF,GAKtB,OADAV,EAAQ,CAAES,UACHT,CACT,CC1BA,IAAIA,EAEO,KAGJC,eAAea,EAAqBX,GACzC,GAAIH,EACF,OAAOA,EAGT,MAAMI,QAAeD,EAAQE,KAAK,CAChCC,WAAY,wBACZC,MAAO,EACPC,YAAY,IAGRC,EAA8B,CAAA,EAEpC,IAAK,MAAMC,KAAMN,EAAOO,MAAQ,GAC1BD,EAAGE,OACLH,EAAOC,EAAGE,MAAQF,GAKtB,OADAV,EAAQ,CAAES,UACHT,CACT,wBCtBOC,gBAA8Bc,OAAEA,EAAMZ,QAAEA,IAC7C,MAAMa,QCDDf,eAAiCE,GACtC,MAAO,CACLA,UACAc,WAAY,CACVC,aAAchB,EAAiBC,GAC/Bd,eAAgBwB,EAAoBV,GACpCV,gBAAiBqB,EAAqBX,IAG5C,CDRqBgB,CAAkBhB,GAC/BiB,QAAuBC,EAAAA,cAAc,CAAEN,SAAQO,QAASN,IAC9D,OACErB,EAAAA,IAAA4B,EAAAA,SAAA,CAAA3B,SACGwB,EAAevB,IAAI,CAAC2B,EAAYzB,KAC/B,IAAKyB,EAAO,OAAO,KACnB,GAAIA,EAAMpC,KACR,OAAOO,EAAAA,IAACT,EAAI,IAAasC,GAAPzB,GAGpB,MAAM0B,UAAEA,EAASC,MAAEA,GAAUF,EAC7B,OAAO7B,EAAAA,IAAC8B,EAAS,IAAaC,GAAP3B,MAM/B"}
@@ -1,2 +0,0 @@
1
- import{jsx as n,Fragment as t}from"react/jsx-runtime";import{d as o,a as e}from"./resolveLayout-DryOXHEy.js";function a({className:t="",rows:e=[],viewMode:a,rowViewMode:i}){const r=o[a?.component]??"div",c=o[i?.component]??"div";return n(r,{className:t,children:e.map((t,o)=>n(c,{...t},o))})}let i=null;async function r(n){if(i)return i;const t=await n.find({collection:"styles",depth:4,pagination:!1}),o={};for(const n of t.docs??[])n.name&&(o[n.name]=n);return i={byName:o},i}let c=null;async function s(n){if(c)return c;const t=await n.find({collection:"view-modes",depth:4,pagination:!1}),o={};for(const n of t.docs??[])n.name&&(o[n.name]=n);return c={byName:o},c}let l=null;async function u(n){if(l)return l;const t=await n.find({collection:"component-definitions",depth:4,pagination:!1}),o={};for(const n of t.docs??[])n.name&&(o[n.name]=n);return l={byName:o},l}async function m({layout:o,payload:i}){const c=await async function(n){return{payload:n,registries:{styles:await r(n),viewMode:await s(n),component:await u(n)}}}(i),l=await e({layout:o,context:c});return n(t,{children:l.map((t,o)=>{if(!t)return null;if(t.rows)return n(a,{...t},o);const{Component:e,props:i}=t;return n(e,{...i},o)})})}export{m as L,a as V};
2
- //# sourceMappingURL=LayoutRenderer-Ba6ITI7O.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LayoutRenderer-Ba6ITI7O.js","sources":["../src/react/components/View.tsx","../src/uims/registry/styleRegistry.ts","../src/uims/registry/viewModeRegistry.ts","../src/uims/registry/componentRegistry.ts","../src/react/LayoutRenderer.tsx","../src/uims/resolver/createUIMSContext.ts"],"sourcesContent":["import { componentRegistry } from '../componentRegistry'\n\nexport function View({ className = '', rows = [], viewMode, rowViewMode }: any) {\n const ContainerComponent = componentRegistry[viewMode?.component] ?? 'div'\n const RowComponent = componentRegistry[rowViewMode?.component] ?? 'div'\n\n return (\n <ContainerComponent className={className}>\n {rows.map((rowProps: any, i: number) => {\n return <RowComponent key={i} {...rowProps} />\n })}\n </ContainerComponent>\n )\n}\n","import { BasePayload } from 'payload'\n\nlet cache: {\n byName: Record<string, any>\n} | null = null\n\n//# TODO sarebbe sensato cancellare la cache o forzare un nuovo caricamento quando viene fatta una modifica a uno degli elementi della collection\nexport async function getStyleRegistry(payload: BasePayload) {\n if (cache) {\n return cache\n }\n\n const result = await payload.find({\n collection: 'styles',\n depth: 4,\n pagination: false,\n })\n\n const byName: Record<string, any> = {}\n\n for (const vm of result.docs ?? []) {\n if (vm.name) {\n byName[vm.name] = vm\n }\n }\n\n cache = { byName }\n return cache\n}\n","import { BasePayload } from 'payload'\n\nlet cache: {\n byName: Record<string, any>\n} | null = null\n\n//# TODO sarebbe sensato cancellare la cache o forzare un nuovo caricamento quando viene fatta una modifica a uno degli elementi della collection\nexport async function getViewModeRegistry(payload: BasePayload) {\n if (cache) {\n return cache\n }\n\n const result = await payload.find({\n collection: 'view-modes',\n depth: 4,\n pagination: false,\n })\n\n const byName: Record<string, any> = {}\n\n for (const vm of result.docs ?? []) {\n if (vm.name) {\n byName[vm.name] = vm\n }\n }\n\n cache = { byName }\n return cache\n}\n","import { BasePayload } from 'payload'\n\nlet cache: {\n byName: Record<string, any>\n} | null = null\n\n//# TODO sarebbe sensato cancellare la cache o forzare un nuovo caricamento quando viene fatta una modifica a uno degli elementi della collection\nexport async function getComponentRegistry(payload: BasePayload) {\n if (cache) {\n return cache\n }\n\n const result = await payload.find({\n collection: 'component-definitions',\n depth: 4,\n pagination: false,\n })\n\n const byName: Record<string, any> = {}\n\n for (const vm of result.docs ?? []) {\n if (vm.name) {\n byName[vm.name] = vm\n }\n }\n\n cache = { byName }\n return cache\n}\n","import { BasePayload } from 'payload'\nimport { View } from './components/View'\nimport { resolveLayout } from '../uims'\nimport { createUIMSContext } from '../uims/resolver/createUIMSContext'\n\n//#TODO Ricordarsi di introdurre il concetto di PageRenderer, sarebbe carino se riuscissimo a delegarle la stampa anche dei meta dati e info accessorie oltre al layout.\nexport async function LayoutRenderer({ layout, payload }: { layout: any[]; payload: BasePayload }) {\n const uims = await createUIMSContext(payload)\n const resolvedLayout = await resolveLayout({ layout, context: uims })\n return (\n <>\n {resolvedLayout.map((block: any, i: any) => {\n if (!block) return null\n if (block.rows) {\n return <View key={i} {...block} />\n }\n\n const { Component, props } = block\n return <Component key={i} {...props} />\n\n return null\n })}\n </>\n )\n}\n","import { BasePayload } from 'payload'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { getStyleRegistry } from '../registry/styleRegistry'\nimport { getViewModeRegistry } from '../registry/viewModeRegistry'\nimport { getComponentRegistry } from '../registry/componentRegistry'\n\nexport async function createUIMSContext(payload: BasePayload): Promise<UIMSContext> {\n return {\n payload,\n registries: {\n styles: await getStyleRegistry(payload),\n viewMode: await getViewModeRegistry(payload),\n component: await getComponentRegistry(payload),\n },\n }\n}\n"],"names":["View","className","rows","viewMode","rowViewMode","ContainerComponent","componentRegistry","component","RowComponent","_jsx","children","map","rowProps","i","cache","async","getStyleRegistry","payload","result","find","collection","depth","pagination","byName","vm","docs","name","getViewModeRegistry","getComponentRegistry","LayoutRenderer","layout","uims","registries","styles","createUIMSContext","resolvedLayout","resolveLayout","context","_Fragment","block","Component","props"],"mappings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ACAe,WAAY,CACVC,aAAcjB,EAAiBC,GAC/Bd,eAAgBwB,EAAoBV,GACpCV,gBAAiBqB,EAAqBX,IAG5C,CDRqBiB,CAAkBjB,GAC/BkB,QAAuBC,EAAc,CAAEN,SAAQO,QAASN,IAC9D,OACEtB,EAAA6B,EAAA,CAAA5B,SACGyB,EAAexB,IAAI,CAAC4B,EAAY1B,KAC/B,IAAK0B,EAAO,OAAO,KACnB,GAAIA,EAAMrC,KACR,OAAOO,EAACT,EAAI,IAAauC,GAAP1B,GAGpB,MAAM2B,UAAEA,EAASC,MAAEA,GAAUF,EAC7B,OAAO9B,EAAC+B,EAAS,IAAaC,GAAP5B,MAM/B"}
@@ -1 +0,0 @@
1
- export declare function ComponentRenderer({ type, view, data }: any): import("react/jsx-runtime").JSX.Element | null;
@@ -1,29 +0,0 @@
1
- // components/ComponentRenderer.tsx
2
- 'use client';
3
- import { jsx as _jsx } from "react/jsx-runtime";
4
- import { componentRegistry } from './componentRegistry';
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
- }
@@ -1,2 +0,0 @@
1
- "use strict";var e=require("react/jsx-runtime");async function t(e,t){const a={};for(let r=0;r<t.length;r++){const n=t[r];if(!o(n))continue;const c=await s({payload:e,block:n});a[r]=Array.isArray(c)?c:[]}return a}function o(e){return"view"===e.blockType}async function s({payload:e,block:t}){return t.useInternalSource?async function({payload:e,block:t}){const o=await e.find({collection:t.internalCollection,sort:t.internalSort||void 0,depth:t.internalDepth??1});return o?.docs??[]}({payload:e,block:t}):t.dataSource?async function({payload:e,block:t}){try{const e=await fetch(t.dataSource),o=await e.json();return Array.isArray(o?.[t.dataSet])?o[t.dataSet]:[]}catch{return[]}}({payload:e,block:t}):[]}const a=({className:t,imageProps:o,titleProps:s,descriptionProps:a,children:r})=>e.jsxs("div",{className:t,children:[o?.src&&e.jsx("img",{src:o.src,alt:o.alt??"",className:o.className}),s?.text&&e.jsx("h3",{className:s.className,children:s.text}),a?.text&&e.jsx("p",{className:a.className,children:a.text}),r]}),r=({className:t,children:o})=>e.jsx("div",{className:t,children:o}),n={Card:a,Container:r};function c(e){const t={};if(!e?.styles)return t;for(const o of e.styles){const e=o.style;e&&(t[o.slot]=e)}return t}function i(e,t){if(!t)return e;const o={...e};for(const[e,s]of Object.entries(t))"root"!==e?o[e]&&"object"==typeof o[e]&&(o[e]={...o[e],className:[o[e].className,s].filter(Boolean).join(" ")}):o.className=[o.className,s].filter(Boolean).join(" ");return o}function l(e,t){return t.split(".").reduce((e,t)=>e?e[t]:void 0,e)}function p({data:e,mapper:t}){const o={};if(!t)return o;for(const s of Object.keys(t)){const a=t[s];"string"==typeof a&&a.startsWith("__static:")?o[s]=a.replace("__static:",""):o[s]="string"!=typeof a?"object"!=typeof a||null===a?void 0:p({data:e,mapper:a}):l(e,a)}return o}function u({block:e,context:t}){const o=t.registries.viewMode.byName[e.viewMode];if(console.log("viewMode",o),!o)return null;const s=n[o.component],a=c(o);return{Component:s,props:{...i(p({data:e,mapper:o.blockPropsMapping}),a)}}}function y({block:e,rows:t,context:o}){const s=o.registries.viewMode.byName[e.viewMode],a=o.registries.viewMode.byName[e.rowViewMode],r=c(a),n=s?.styles.map(e=>e.style.map((e,t)=>(o.registries.styles.byName[e.value.name],e.value.css.className)).join(" "));return{className:n,viewMode:s,props:e,rowViewMode:a,rows:t.map(t=>i(p({data:t,mapper:e.rowPropsMapping}),r))}}exports.Card=a,exports.Container=r,exports.applyStylesToProps=i,exports.componentRegistry=n,exports.getValueByPath=l,exports.mapDataToProps=p,exports.resolveLayout=async function e({layout:o,context:s}){const a=[],r=await t(s.payload,o);for(const[t,n]of o.entries())if("view"===n.blockType)a.push(y({block:n,rows:r[t]??[],context:s}));else if("reference"===n.blockType){const t=await e({layout:n.block.value.layout,context:s});a.push(...t)}else a.push(u({block:n,context:s}));return a},exports.resolveViewData=t;
2
- //# sourceMappingURL=resolveLayout-DlRnQBn8.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveLayout-DlRnQBn8.js","sources":["../src/uims/resolver/resolveViewData.ts","../src/react/components/Card.tsx","../src/react/components/Container.tsx","../src/react/componentRegistry.ts","../src/uims/resolver/resolveStylesBySlot.ts","../src/uims/mapper/applyStylesToProps.ts","../src/uims/mapper/getValueByPath.ts","../src/uims/mapper/mapDataToProps.ts","../src/uims/resolver/resolveInlineBlock.ts","../src/uims/resolver/resolveViewBlock.ts","../src/uims/resolver/resolveLayout.ts"],"sourcesContent":["import { BasePayload } from 'payload'\n\ntype ResolveViewDataParams = {\n payload: BasePayload\n layout: any[]\n}\n\ntype ViewDataResult = Record<number, any[]>\n\nexport async function resolveViewData(\n payload: BasePayload,\n layout: any[],\n): Promise<ViewDataResult> {\n const results: ViewDataResult = {}\n\n for (let index = 0; index < layout.length; index++) {\n const block = layout[index]\n\n if (!isViewBlock(block)) {\n continue\n }\n\n const data = await fetchViewBlockData({\n payload,\n block,\n })\n\n results[index] = Array.isArray(data) ? data : []\n }\n\n return results\n}\n\n// ──────────────────────────────────────────────\n// Helpers locali\n// ──────────────────────────────────────────────\n\nfunction isViewBlock(block: any): boolean {\n return block.blockType === 'view'\n}\n\nasync function fetchViewBlockData({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n // Sorgente interna (Payload)\n if (block.useInternalSource) {\n return fetchInternalCollection({\n payload,\n block,\n })\n }\n\n // Sorgente esterna (REST)\n if (block.dataSource) {\n return fetchExternalSource({\n payload,\n block,\n })\n }\n\n return []\n}\n\nasync function fetchInternalCollection({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n const result = await payload.find({\n collection: block.internalCollection,\n sort: block.internalSort || undefined,\n depth: block.internalDepth ?? 1,\n })\n\n return result?.docs ?? []\n}\n\nasync function fetchExternalSource({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n try {\n const res = await fetch(block.dataSource)\n const json = await res.json()\n\n return Array.isArray(json?.[block.dataSet]) ? json[block.dataSet] : []\n } catch {\n return []\n }\n}\n","import type { ReactNode } from 'react'\n\ntype CardTextProps = {\n text?: string\n className?: string\n}\n\ntype CardImageProps = {\n src?: string\n alt?: string\n className?: string\n}\n\nexport type CardProps = {\n className?: string\n imageProps?: CardImageProps\n titleProps?: CardTextProps\n descriptionProps?: CardTextProps\n children?: ReactNode\n}\n\nexport const Card = ({\n className,\n imageProps,\n titleProps,\n descriptionProps,\n children,\n}: CardProps) => {\n // # TODO sarebbe da aggiungere un componente specifico per la stampa dei valori non stilati. Ossia se non viene selezionato alcun componente in fase di editing e per esempio le proprietà di una card arrivano a un DIV\n // Questo non è in grado di stampare i valori simil JSON, discorso diverso invece si presenta se a ricevere tutte le proprietà è invece un componente dedicato (comodo anche per debug)\n return (\n <div className={className}>\n {imageProps?.src && (\n <img src={imageProps.src} alt={imageProps.alt ?? ''} className={imageProps.className} />\n )}\n\n {titleProps?.text && <h3 className={titleProps.className}>{titleProps.text}</h3>}\n\n {descriptionProps?.text && (\n <p className={descriptionProps.className}>{descriptionProps.text}</p>\n )}\n\n {children}\n </div>\n )\n}\n","export type ContainerProps = {\n className?: string\n children?: []\n}\n\nexport const Container = ({ className, children }: ContainerProps) => {\n return <div className={className}>{children}</div>\n}\n","// components/registry.ts\nimport { Container } from '.'\nimport { Card } from './components/Card'\n\nexport const componentRegistry: Record<string, any> = {\n Card,\n Container,\n}\n","type ViewMode = {\n css?: {\n className?: string\n }\n styles?: Array<{\n slot: string\n style: string\n }>\n}\n\nexport function resolveStylesBySlot(viewMode: ViewMode): Record<string, string> {\n const result: Record<string, string> = {}\n\n if (!viewMode?.styles) return result\n\n for (const entry of viewMode.styles) {\n const classNames = entry.style\n\n if (classNames) {\n result[entry.slot] = classNames\n }\n }\n\n return result\n}\n","type StylesBySlot = Record<string, string>\ntype AnyProps = Record<string, any>\n\nexport function applyStylesToProps<T extends AnyProps>(props: T, stylesBySlot?: StylesBySlot): T {\n if (!stylesBySlot) return props\n const nextProps = { ...props } as AnyProps\n\n for (const [slot, className] of Object.entries(stylesBySlot)) {\n if (slot === 'root') {\n nextProps['className'] = [nextProps['className'], className].filter(Boolean).join(' ')\n continue\n }\n if (nextProps[slot] && typeof nextProps[slot] === 'object') {\n nextProps[slot] = {\n ...nextProps[slot],\n className: [nextProps[slot].className, className].filter(Boolean).join(' '),\n }\n }\n }\n\n return nextProps as T\n}\n","export function getValueByPath(obj: any, path: string): any {\n return path.split('.').reduce((acc, key) => (acc ? acc[key] : undefined), obj)\n}\n","import { getValueByPath } from './getValueByPath'\n\ntype Mapper = Record<string, any>\n\nexport function mapDataToProps<T = any>({ data, mapper }: { data: any; mapper: Mapper }): T {\n const result: any = {}\n if (!mapper) return result\n for (const key of Object.keys(mapper)) {\n const rule = mapper[key]\n if (typeof rule === 'string' && rule.startsWith('__static:')) {\n result[key] = rule.replace('__static:', '')\n continue\n }\n\n if (typeof rule === 'string') {\n result[key] = getValueByPath(data, rule)\n continue\n }\n\n if (typeof rule === 'object' && rule !== null) {\n result[key] = mapDataToProps({\n data,\n mapper: rule,\n })\n continue\n }\n\n result[key] = undefined\n }\n\n return result\n}\n","import { componentRegistry } from '../../react/componentRegistry'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { mapDataToProps } from '../mapper/mapDataToProps'\n\nexport function resolveInlineBlock({ block, context }: { block: any; context: UIMSContext }) {\n //const viewMode = context.registries.viewMode.byId[block.viewMode.value]\n const viewMode = context.registries.viewMode.byName[block.viewMode]\n console.log('viewMode', viewMode)\n if (!viewMode) return null\n\n const Component = componentRegistry[viewMode.component]\n const stylesBySlot = resolveStylesBySlot(viewMode)\n return {\n Component,\n props: {\n ...applyStylesToProps(\n mapDataToProps({\n data: block,\n mapper: viewMode.blockPropsMapping,\n }),\n stylesBySlot,\n ),\n },\n }\n}\n","import { mapDataToProps } from '../mapper/mapDataToProps'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\n\nexport function resolveViewBlock({\n block,\n rows,\n context,\n}: {\n block: any\n rows: any[]\n context: UIMSContext\n}) {\n const viewMode = context.registries.viewMode.byName[block.viewMode]\n const rowViewMode = context.registries.viewMode.byName[block.rowViewMode]\n const stylesBySlot = resolveStylesBySlot(rowViewMode)\n const className = viewMode?.styles.map((style: any) => {\n return style.style\n .map((ss: any, i: any) => {\n const s = context.registries.styles.byName[ss.value.name]\n return ss.value.css.className\n })\n .join(' ')\n })\n\n return {\n className,\n viewMode,\n props: block,\n rowViewMode,\n rows: rows.map((row) =>\n applyStylesToProps(\n mapDataToProps({\n data: row,\n mapper: block.rowPropsMapping,\n }),\n stylesBySlot,\n ),\n ),\n }\n}\n","import { resolveInlineBlock } from './resolveInlineBlock'\nimport { resolveViewBlock } from './resolveViewBlock'\nimport { resolveViewData } from './resolveViewData'\nimport { UIMSContext } from '../types/UIMSContext'\n\nexport async function resolveLayout({\n layout,\n context,\n}: {\n layout: Array<any>\n context: UIMSContext\n}) {\n const resolved: any[] = []\n const viewData = await resolveViewData(context.payload, layout)\n for (const [index, block] of layout.entries()) {\n if (block.blockType === 'view') {\n resolved.push(\n resolveViewBlock({\n block,\n rows: viewData[index] ?? [],\n context,\n }),\n )\n } else if (block.blockType === 'reference') {\n const nestedResolved = await resolveLayout({ layout: block.block.value.layout, context })\n resolved.push(...nestedResolved)\n } else {\n resolved.push(resolveInlineBlock({ block, context }))\n }\n }\n return resolved\n}\n"],"names":["async","resolveViewData","payload","layout","results","index","length","block","isViewBlock","data","fetchViewBlockData","Array","isArray","blockType","useInternalSource","result","find","collection","internalCollection","sort","internalSort","undefined","depth","internalDepth","docs","fetchInternalCollection","dataSource","res","fetch","json","dataSet","fetchExternalSource","Card","className","imageProps","titleProps","descriptionProps","children","_jsxs","src","_jsx","alt","text","Container","componentRegistry","resolveStylesBySlot","viewMode","styles","entry","classNames","style","slot","applyStylesToProps","props","stylesBySlot","nextProps","Object","entries","filter","Boolean","join","getValueByPath","obj","path","split","reduce","acc","key","mapDataToProps","mapper","keys","rule","startsWith","replace","resolveInlineBlock","context","registries","byName","console","log","Component","component","blockPropsMapping","resolveViewBlock","rows","rowViewMode","map","ss","i","value","name","css","row","rowPropsMapping","resolveLayout","resolved","viewData","push","nestedResolved"],"mappings":"gDASOA,eAAeC,EACpBC,EACAC,GAEA,MAAMC,EAA0B,CAAA,EAEhC,IAAK,IAAIC,EAAQ,EAAGA,EAAQF,EAAOG,OAAQD,IAAS,CAClD,MAAME,EAAQJ,EAAOE,GAErB,IAAKG,EAAYD,GACf,SAGF,MAAME,QAAaC,EAAmB,CACpCR,UACAK,UAGFH,EAAQC,GAASM,MAAMC,QAAQH,GAAQA,EAAO,EAChD,CAEA,OAAOL,CACT,CAMA,SAASI,EAAYD,GACnB,MAA2B,SAApBA,EAAMM,SACf,CAEAb,eAAeU,GAAmBR,QAChCA,EAAOK,MACPA,IAMA,OAAIA,EAAMO,kBAkBZd,gBAAuCE,QACrCA,EAAOK,MACPA,IAKA,MAAMQ,QAAeb,EAAQc,KAAK,CAChC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C,WAAW9B,SAAS+B,OAAOtE,EAAMuC,UACpDuC,EAAcV,EAAQC,WAAW9B,SAAS+B,OAAOtE,EAAM8E,aACvD/B,EAAeT,EAAoBwC,GACnCpD,EAAYa,GAAUC,OAAOuC,IAAKpC,GAC/BA,EAAMA,MACVoC,IAAI,CAACC,EAASC,KACHb,EAAQC,WAAW7B,OAAO8B,OAAOU,EAAGE,MAAMC,MAC7CH,EAAGE,MAAME,IAAI1D,YAErB2B,KAAK,MAGV,MAAO,CACL3B,YACAa,WACAO,MAAO9C,EACP8E,cACAD,KAAMA,EAAKE,IAAKM,GACdxC,EACEgB,EAAe,CACb3D,KAAMmF,EACNvB,OAAQ9D,EAAMsF,kBAEhBvC,IAIR,qKCpCOtD,eAAe8F,GAAc3F,OAClCA,EAAMwE,QACNA,IAKA,MAAMoB,EAAkB,GAClBC,QAAiB/F,EAAgB0E,EAAQzE,QAASC,GACxD,IAAK,MAAOE,EAAOE,KAAUJ,EAAOsD,UAClC,GAAwB,SAApBlD,EAAMM,UACRkF,EAASE,KACPd,EAAiB,CACf5E,QACA6E,KAAMY,EAAS3F,IAAU,GACzBsE,kBAGC,GAAwB,cAApBpE,EAAMM,UAA2B,CAC1C,MAAMqF,QAAuBJ,EAAc,CAAE3F,OAAQI,EAAMA,MAAMkF,MAAMtF,OAAQwE,YAC/EoB,EAASE,QAAQC,EACnB,MACEH,EAASE,KAAKvB,EAAmB,CAAEnE,QAAOoE,aAG9C,OAAOoB,CACT"}
@@ -1,2 +0,0 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";async function o(e,t){const o={};for(let n=0;n<t.length;n++){const r=t[n];if(!a(r))continue;const c=await s({payload:e,block:r});o[n]=Array.isArray(c)?c:[]}return o}function a(e){return"view"===e.blockType}async function s({payload:e,block:t}){return t.useInternalSource?async function({payload:e,block:t}){const o=await e.find({collection:t.internalCollection,sort:t.internalSort||void 0,depth:t.internalDepth??1});return o?.docs??[]}({payload:e,block:t}):t.dataSource?async function({payload:e,block:t}){try{const e=await fetch(t.dataSource),o=await e.json();return Array.isArray(o?.[t.dataSet])?o[t.dataSet]:[]}catch{return[]}}({payload:e,block:t}):[]}const n=({className:o,imageProps:a,titleProps:s,descriptionProps:n,children:r})=>e("div",{className:o,children:[a?.src&&t("img",{src:a.src,alt:a.alt??"",className:a.className}),s?.text&&t("h3",{className:s.className,children:s.text}),n?.text&&t("p",{className:n.className,children:n.text}),r]}),r=({className:e,children:o})=>t("div",{className:e,children:o}),c={Card:n,Container:r};function i(e){const t={};if(!e?.styles)return t;for(const o of e.styles){const e=o.style;e&&(t[o.slot]=e)}return t}function l(e,t){if(!t)return e;const o={...e};for(const[e,a]of Object.entries(t))"root"!==e?o[e]&&"object"==typeof o[e]&&(o[e]={...o[e],className:[o[e].className,a].filter(Boolean).join(" ")}):o.className=[o.className,a].filter(Boolean).join(" ");return o}function p(e,t){return t.split(".").reduce((e,t)=>e?e[t]:void 0,e)}function u({data:e,mapper:t}){const o={};if(!t)return o;for(const a of Object.keys(t)){const s=t[a];"string"==typeof s&&s.startsWith("__static:")?o[a]=s.replace("__static:",""):o[a]="string"!=typeof s?"object"!=typeof s||null===s?void 0:u({data:e,mapper:s}):p(e,s)}return o}function d({block:e,context:t}){const o=t.registries.viewMode.byName[e.viewMode];if(console.log("viewMode",o),!o)return null;const a=c[o.component],s=i(o);return{Component:a,props:{...l(u({data:e,mapper:o.blockPropsMapping}),s)}}}function f({block:e,rows:t,context:o}){const a=o.registries.viewMode.byName[e.viewMode],s=o.registries.viewMode.byName[e.rowViewMode],n=i(s),r=a?.styles.map(e=>e.style.map((e,t)=>(o.registries.styles.byName[e.value.name],e.value.css.className)).join(" "));return{className:r,viewMode:a,props:e,rowViewMode:s,rows:t.map(t=>l(u({data:t,mapper:e.rowPropsMapping}),n))}}async function y({layout:e,context:t}){const a=[],s=await o(t.payload,e);for(const[o,n]of e.entries())if("view"===n.blockType)a.push(f({block:n,rows:s[o]??[],context:t}));else if("reference"===n.blockType){const e=await y({layout:n.block.value.layout,context:t});a.push(...e)}else a.push(d({block:n,context:t}));return a}export{n as C,y as a,l as b,r as c,c as d,p as g,u as m,o as r};
2
- //# sourceMappingURL=resolveLayout-DryOXHEy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveLayout-DryOXHEy.js","sources":["../src/uims/resolver/resolveViewData.ts","../src/react/components/Card.tsx","../src/react/components/Container.tsx","../src/react/componentRegistry.ts","../src/uims/resolver/resolveStylesBySlot.ts","../src/uims/mapper/applyStylesToProps.ts","../src/uims/mapper/getValueByPath.ts","../src/uims/mapper/mapDataToProps.ts","../src/uims/resolver/resolveInlineBlock.ts","../src/uims/resolver/resolveViewBlock.ts","../src/uims/resolver/resolveLayout.ts"],"sourcesContent":["import { BasePayload } from 'payload'\n\ntype ResolveViewDataParams = {\n payload: BasePayload\n layout: any[]\n}\n\ntype ViewDataResult = Record<number, any[]>\n\nexport async function resolveViewData(\n payload: BasePayload,\n layout: any[],\n): Promise<ViewDataResult> {\n const results: ViewDataResult = {}\n\n for (let index = 0; index < layout.length; index++) {\n const block = layout[index]\n\n if (!isViewBlock(block)) {\n continue\n }\n\n const data = await fetchViewBlockData({\n payload,\n block,\n })\n\n results[index] = Array.isArray(data) ? data : []\n }\n\n return results\n}\n\n// ──────────────────────────────────────────────\n// Helpers locali\n// ──────────────────────────────────────────────\n\nfunction isViewBlock(block: any): boolean {\n return block.blockType === 'view'\n}\n\nasync function fetchViewBlockData({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n // Sorgente interna (Payload)\n if (block.useInternalSource) {\n return fetchInternalCollection({\n payload,\n block,\n })\n }\n\n // Sorgente esterna (REST)\n if (block.dataSource) {\n return fetchExternalSource({\n payload,\n block,\n })\n }\n\n return []\n}\n\nasync function fetchInternalCollection({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n const result = await payload.find({\n collection: block.internalCollection,\n sort: block.internalSort || undefined,\n depth: block.internalDepth ?? 1,\n })\n\n return result?.docs ?? []\n}\n\nasync function fetchExternalSource({\n payload,\n block,\n}: {\n payload: BasePayload\n block: any\n}): Promise<any[]> {\n try {\n const res = await fetch(block.dataSource)\n const json = await res.json()\n\n return Array.isArray(json?.[block.dataSet]) ? json[block.dataSet] : []\n } catch {\n return []\n }\n}\n","import type { ReactNode } from 'react'\n\ntype CardTextProps = {\n text?: string\n className?: string\n}\n\ntype CardImageProps = {\n src?: string\n alt?: string\n className?: string\n}\n\nexport type CardProps = {\n className?: string\n imageProps?: CardImageProps\n titleProps?: CardTextProps\n descriptionProps?: CardTextProps\n children?: ReactNode\n}\n\nexport const Card = ({\n className,\n imageProps,\n titleProps,\n descriptionProps,\n children,\n}: CardProps) => {\n // # TODO sarebbe da aggiungere un componente specifico per la stampa dei valori non stilati. Ossia se non viene selezionato alcun componente in fase di editing e per esempio le proprietà di una card arrivano a un DIV\n // Questo non è in grado di stampare i valori simil JSON, discorso diverso invece si presenta se a ricevere tutte le proprietà è invece un componente dedicato (comodo anche per debug)\n return (\n <div className={className}>\n {imageProps?.src && (\n <img src={imageProps.src} alt={imageProps.alt ?? ''} className={imageProps.className} />\n )}\n\n {titleProps?.text && <h3 className={titleProps.className}>{titleProps.text}</h3>}\n\n {descriptionProps?.text && (\n <p className={descriptionProps.className}>{descriptionProps.text}</p>\n )}\n\n {children}\n </div>\n )\n}\n","export type ContainerProps = {\n className?: string\n children?: []\n}\n\nexport const Container = ({ className, children }: ContainerProps) => {\n return <div className={className}>{children}</div>\n}\n","// components/registry.ts\nimport { Container } from '.'\nimport { Card } from './components/Card'\n\nexport const componentRegistry: Record<string, any> = {\n Card,\n Container,\n}\n","type ViewMode = {\n css?: {\n className?: string\n }\n styles?: Array<{\n slot: string\n style: string\n }>\n}\n\nexport function resolveStylesBySlot(viewMode: ViewMode): Record<string, string> {\n const result: Record<string, string> = {}\n\n if (!viewMode?.styles) return result\n\n for (const entry of viewMode.styles) {\n const classNames = entry.style\n\n if (classNames) {\n result[entry.slot] = classNames\n }\n }\n\n return result\n}\n","type StylesBySlot = Record<string, string>\ntype AnyProps = Record<string, any>\n\nexport function applyStylesToProps<T extends AnyProps>(props: T, stylesBySlot?: StylesBySlot): T {\n if (!stylesBySlot) return props\n const nextProps = { ...props } as AnyProps\n\n for (const [slot, className] of Object.entries(stylesBySlot)) {\n if (slot === 'root') {\n nextProps['className'] = [nextProps['className'], className].filter(Boolean).join(' ')\n continue\n }\n if (nextProps[slot] && typeof nextProps[slot] === 'object') {\n nextProps[slot] = {\n ...nextProps[slot],\n className: [nextProps[slot].className, className].filter(Boolean).join(' '),\n }\n }\n }\n\n return nextProps as T\n}\n","export function getValueByPath(obj: any, path: string): any {\n return path.split('.').reduce((acc, key) => (acc ? acc[key] : undefined), obj)\n}\n","import { getValueByPath } from './getValueByPath'\n\ntype Mapper = Record<string, any>\n\nexport function mapDataToProps<T = any>({ data, mapper }: { data: any; mapper: Mapper }): T {\n const result: any = {}\n if (!mapper) return result\n for (const key of Object.keys(mapper)) {\n const rule = mapper[key]\n if (typeof rule === 'string' && rule.startsWith('__static:')) {\n result[key] = rule.replace('__static:', '')\n continue\n }\n\n if (typeof rule === 'string') {\n result[key] = getValueByPath(data, rule)\n continue\n }\n\n if (typeof rule === 'object' && rule !== null) {\n result[key] = mapDataToProps({\n data,\n mapper: rule,\n })\n continue\n }\n\n result[key] = undefined\n }\n\n return result\n}\n","import { componentRegistry } from '../../react/componentRegistry'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { mapDataToProps } from '../mapper/mapDataToProps'\n\nexport function resolveInlineBlock({ block, context }: { block: any; context: UIMSContext }) {\n //const viewMode = context.registries.viewMode.byId[block.viewMode.value]\n const viewMode = context.registries.viewMode.byName[block.viewMode]\n console.log('viewMode', viewMode)\n if (!viewMode) return null\n\n const Component = componentRegistry[viewMode.component]\n const stylesBySlot = resolveStylesBySlot(viewMode)\n return {\n Component,\n props: {\n ...applyStylesToProps(\n mapDataToProps({\n data: block,\n mapper: viewMode.blockPropsMapping,\n }),\n stylesBySlot,\n ),\n },\n }\n}\n","import { mapDataToProps } from '../mapper/mapDataToProps'\nimport { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\n\nexport function resolveViewBlock({\n block,\n rows,\n context,\n}: {\n block: any\n rows: any[]\n context: UIMSContext\n}) {\n const viewMode = context.registries.viewMode.byName[block.viewMode]\n const rowViewMode = context.registries.viewMode.byName[block.rowViewMode]\n const stylesBySlot = resolveStylesBySlot(rowViewMode)\n const className = viewMode?.styles.map((style: any) => {\n return style.style\n .map((ss: any, i: any) => {\n const s = context.registries.styles.byName[ss.value.name]\n return ss.value.css.className\n })\n .join(' ')\n })\n\n return {\n className,\n viewMode,\n props: block,\n rowViewMode,\n rows: rows.map((row) =>\n applyStylesToProps(\n mapDataToProps({\n data: row,\n mapper: block.rowPropsMapping,\n }),\n stylesBySlot,\n ),\n ),\n }\n}\n","import { resolveInlineBlock } from './resolveInlineBlock'\nimport { resolveViewBlock } from './resolveViewBlock'\nimport { resolveViewData } from './resolveViewData'\nimport { UIMSContext } from '../types/UIMSContext'\n\nexport async function resolveLayout({\n layout,\n context,\n}: {\n layout: Array<any>\n context: UIMSContext\n}) {\n const resolved: any[] = []\n const viewData = await resolveViewData(context.payload, layout)\n for (const [index, block] of layout.entries()) {\n if (block.blockType === 'view') {\n resolved.push(\n resolveViewBlock({\n block,\n rows: viewData[index] ?? [],\n context,\n }),\n )\n } else if (block.blockType === 'reference') {\n const nestedResolved = await resolveLayout({ layout: block.block.value.layout, context })\n resolved.push(...nestedResolved)\n } else {\n resolved.push(resolveInlineBlock({ block, context }))\n }\n }\n return resolved\n}\n"],"names":["async","resolveViewData","payload","layout","results","index","length","block","isViewBlock","data","fetchViewBlockData","Array","isArray","blockType","useInternalSource","result","find","collection","internalCollection","sort","internalSort","undefined","depth","internalDepth","docs","fetchInternalCollection","dataSource","res","fetch","json","dataSet","fetchExternalSource","Card","className","imageProps","titleProps","descriptionProps","children","_jsxs","src","_jsx","alt","text","Container","componentRegistry","resolveStylesBySlot","viewMode","styles","entry","classNames","style","slot","applyStylesToProps","props","stylesBySlot","nextProps","Object","entries","filter","Boolean","join","getValueByPath","obj","path","split","reduce","acc","key","mapDataToProps","mapper","keys","rule","startsWith","replace","resolveInlineBlock","context","registries","byName","console","log","Component","component","blockPropsMapping","resolveViewBlock","rows","rowViewMode","map","ss","i","value","name","css","row","rowPropsMapping","resolveLayout","resolved","viewData","push","nestedResolved"],"mappings":"kDASOA,eAAeC,EACpBC,EACAC,GAEA,MAAMC,EAA0B,CAAA,EAEhC,IAAK,IAAIC,EAAQ,EAAGA,EAAQF,EAAOG,OAAQD,IAAS,CAClD,MAAME,EAAQJ,EAAOE,GAErB,IAAKG,EAAYD,GACf,SAGF,MAAME,QAAaC,EAAmB,CACpCR,UACAK,UAGFH,EAAQC,GAASM,MAAMC,QAAQH,GAAQA,EAAO,EAChD,CAEA,OAAOL,CACT,CAMA,SAASI,EAAYD,GACnB,MAA2B,SAApBA,EAAMM,SACf,CAEAb,eAAeU,GAAmBR,QAChCA,EAAOK,MACPA,IAMA,OAAIA,EAAMO,kBAkBZd,gBAAuCE,QACrCA,EAAOK,MACPA,IAKA,MAAMQ,QAAeb,EAAQc,KAAK,CAChCC,WAAYV,EAAMW,mBAClBC,KAAMZ,EAAMa,mBAAgBC,EAC5BC,MAAOf,EAAMgB,eAAiB,IAGhC,OAAOR,GAAQS,MAAQ,EACzB,CA/BWC,CAAwB,CAC7BvB,UACAK,UAKAA,EAAMmB,WA0BZ1B,gBAAmCE,QACjCA,EAAOK,MACPA,IAKA,IACE,MAAMoB,QAAYC,MAAMrB,EAAMmB,YACxBG,QAAaF,EAAIE,OAEvB,OAAOlB,MAAMC,QAAQiB,IAAOtB,EAAMuB,UAAYD,EAAKtB,EAAMuB,S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