@woodylab/payload 0.0.142 → 0.0.144
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{LayoutRenderer-DMN7UMr-.js → LayoutRenderer-DaL3F4jD.js} +2 -2
- package/dist/{LayoutRenderer-D4zKYdMC.js.map → LayoutRenderer-DaL3F4jD.js.map} +1 -1
- package/dist/{LayoutRenderer-D4zKYdMC.js → LayoutRenderer-UTztjxah.js} +2 -2
- package/dist/LayoutRenderer-UTztjxah.js.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/react/LayoutRenderer.js +0 -4
- package/dist/react/components/View.d.ts +1 -1
- package/dist/react/components/View.js +2 -2
- package/dist/react/index.cjs.js +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.esm.js +1 -1
- package/dist/react/index.js +1 -1
- package/dist/resolveLayout-D0mOcO8S.js +2 -0
- package/dist/resolveLayout-D0mOcO8S.js.map +1 -0
- package/dist/resolveLayout-DT9L5tmd.js +2 -0
- package/dist/resolveLayout-DT9L5tmd.js.map +1 -0
- package/dist/seeders/UIMSSeeder.js +3 -3
- package/dist/seeders/index.cjs.js +1 -1
- package/dist/seeders/index.cjs.js.map +1 -1
- package/dist/seeders/index.d.ts +3 -1
- package/dist/seeders/index.esm.js +1 -1
- package/dist/seeders/index.esm.js.map +1 -1
- package/dist/seeders/index.js +3 -1
- package/dist/seeders/{ComponentList.d.ts → listComponent.d.ts} +1 -1
- package/dist/seeders/{ComponentList.js → listComponent.js} +1 -1
- package/dist/seeders/{generateTailwindStyles.d.ts → listStyles.d.ts} +1 -1
- package/dist/seeders/{generateTailwindStyles.js → listStyles.js} +1 -1
- package/dist/seeders/{ViewModeList.d.ts → listViewMode.d.ts} +1 -1
- package/dist/seeders/{ViewModeList.js → listViewMode.js} +1 -1
- package/dist/seeders/{components.js → seedComponent.js} +2 -2
- package/dist/seeders/{styles.js → seedStyles.js} +2 -2
- package/dist/seeders/{viewModes.js → seedViewMode.js} +2 -2
- package/dist/uims/index.cjs.js +1 -1
- package/dist/uims/index.esm.js +1 -1
- package/dist/uims/resolver/resolveInlineBlock.js +2 -1
- package/dist/uims/resolver/resolveLayout.js +1 -0
- package/dist/uims/resolver/resolveViewBlock.js +2 -0
- package/package.json +1 -1
- package/dist/LayoutRenderer-DMN7UMr-.js.map +0 -1
- package/dist/resolveLayout-C5t_MveG.js +0 -2
- package/dist/resolveLayout-C5t_MveG.js.map +0 -1
- package/dist/resolveLayout-DGll1vY2.js +0 -2
- package/dist/resolveLayout-DGll1vY2.js.map +0 -1
- /package/dist/seeders/{components.d.ts → seedComponent.d.ts} +0 -0
- /package/dist/seeders/{styles.d.ts → seedStyles.d.ts} +0 -0
- /package/dist/seeders/{viewModes.d.ts → seedViewMode.d.ts} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var n=require("react/jsx-runtime"),t=require("./resolveLayout-
|
|
2
|
-
//# sourceMappingURL=LayoutRenderer-
|
|
1
|
+
"use strict";var n=require("react/jsx-runtime"),t=require("./resolveLayout-DT9L5tmd.js");let e=null;async function o(n){if(e)return e;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 e={byName:o},e}let a=null;async function i(n){if(a)return a;const t=await n.find({collection:"view-modes",depth:4,pagination:!1}),e={};for(const n of t.docs??[])n.name&&(e[n.name]=n);return a={byName:e},a}let r=null;async function c(n){if(r)return r;const t=await n.find({collection:"component-definitions",depth:4,pagination:!1}),e={};for(const n of t.docs??[])n.name&&(e[n.name]=n);return r={byName:e},r}exports.LayoutRenderer=async function({layout:e,payload:a}){const r=await async function(n){return{payload:n,registries:{styles:await o(n),viewMode:await i(n),component:await c(n)}}}(a),s=await t.resolveLayout({layout:e,context:r});return n.jsx(n.Fragment,{children:s.map((t,e)=>{if(!t)return null;const{section:o,container:a,content:i}=t,{SectionComponent:r,SectionStylesBySlot:c}=o,{ContainerComponent:s,ContainerStylesBySlot:l}=a,{ContentComponent:u}=i;return n.jsx(r,{className:c.root,children:n.jsx(s,{className:l.root,children:n.jsx(u,{...i})})},e)})})};
|
|
2
|
+
//# sourceMappingURL=LayoutRenderer-DaL3F4jD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutRenderer-
|
|
1
|
+
{"version":3,"file":"LayoutRenderer-DaL3F4jD.js","sources":["../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 { 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 { 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 const { section, container, content } = block\n const { SectionComponent, SectionStylesBySlot } = section\n const { ContainerComponent, ContainerStylesBySlot } = container\n const { ContentComponent } = content\n\n return (\n <SectionComponent key={i} className={SectionStylesBySlot.root}>\n <ContainerComponent className={ContainerStylesBySlot.root}>\n <ContentComponent {...content} />\n </ContainerComponent>\n </SectionComponent>\n )\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":["cache","async","getStyleRegistry","payload","result","find","collection","depth","pagination","byName","vm","docs","name","getViewModeRegistry","getComponentRegistry","layout","uims","registries","styles","viewMode","component","createUIMSContext","resolvedLayout","resolveLayout","context","_jsx","_Fragment","children","map","block","i","section","container","content","SectionComponent","SectionStylesBySlot","ContainerComponent","ContainerStylesBySlot","Content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MAAME,QAAEA,EAAOC,UAAEA,EAASC,QAAEA,GAAYJ,GAClCK,iBAAEA,EAAgBC,oBAAEA,GAAwBJ,GAC5CK,mBAAEA,EAAkBC,sBAAEA,GAA0BL,GAChDM,iBAAEA,GAAqBL,EAE7B,OACER,EAAAA,IAACS,EAAgB,CAASK,UAAWJ,EAAoBK,KAAIb,SAC3DF,MAACW,EAAkB,CAACG,UAAWF,EAAsBG,KAAIb,SACvDF,EAAAA,IAACa,EAAgB,IAAKL,OAFHH,MASjC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as n,Fragment as t}from"react/jsx-runtime";import{a as o}from"./resolveLayout-
|
|
2
|
-
//# sourceMappingURL=LayoutRenderer-
|
|
1
|
+
import{jsx as n,Fragment as t}from"react/jsx-runtime";import{a as o}from"./resolveLayout-D0mOcO8S.js";let e=null;async function a(n){if(e)return e;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 e={byName:o},e}let i=null;async function c(n){if(i)return i;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 i={byName:o},i}let r=null;async function s(n){if(r)return r;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 r={byName:o},r}async function l({layout:e,payload:i}){const r=await async function(n){return{payload:n,registries:{styles:await a(n),viewMode:await c(n),component:await s(n)}}}(i),l=await o({layout:e,context:r});return n(t,{children:l.map((t,o)=>{if(!t)return null;const{section:e,container:a,content:i}=t,{SectionComponent:c,SectionStylesBySlot:r}=e,{ContainerComponent:s,ContainerStylesBySlot:l}=a,{ContentComponent:m}=i;return n(c,{className:r.root,children:n(s,{className:l.root,children:n(m,{...i})})},o)})})}export{l as L};
|
|
2
|
+
//# sourceMappingURL=LayoutRenderer-UTztjxah.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LayoutRenderer-UTztjxah.js","sources":["../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 { 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 { 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 const { section, container, content } = block\n const { SectionComponent, SectionStylesBySlot } = section\n const { ContainerComponent, ContainerStylesBySlot } = container\n const { ContentComponent } = content\n\n return (\n <SectionComponent key={i} className={SectionStylesBySlot.root}>\n <ContainerComponent className={ContainerStylesBySlot.root}>\n <ContentComponent {...content} />\n </ContainerComponent>\n </SectionComponent>\n )\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":["cache","async","getStyleRegistry","payload","result","find","collection","depth","pagination","byName","vm","docs","name","getViewModeRegistry","getComponentRegistry","LayoutRenderer","layout","uims","registries","styles","viewMode","component","createUIMSContext","resolvedLayout","resolveLayout","context","_jsx","_Fragment","children","map","block","i","section","container","content","SectionComponent","SectionStylesBySlot","ContainerComponent","ContainerStylesBySlot","ContentComponent","className","root"],"mappings":"sGAEA,IAAIA,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,EAAO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vDF,EAACa,EAAgB,IAAKL,OAFHH,MASjC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("./resolveLayout-
|
|
1
|
+
"use strict";var e=require("./resolveLayout-DT9L5tmd.js"),o=require("./config/index.cjs.js"),t=require("./utils/index.cjs.js"),s=require("./LayoutRenderer-DaL3F4jD.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,V as View,b as applyStylesToProps,d as componentRegistry,g as getValueByPath,m as mapDataToProps,a as resolveLayout,r as resolveViewData}from"./resolveLayout-
|
|
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-D0mOcO8S.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-UTztjxah.js";import"react/jsx-runtime";
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
|
@@ -12,10 +12,6 @@ export async function LayoutRenderer({ layout, payload }) {
|
|
|
12
12
|
const { SectionComponent, SectionStylesBySlot } = section;
|
|
13
13
|
const { ContainerComponent, ContainerStylesBySlot } = container;
|
|
14
14
|
const { ContentComponent } = content;
|
|
15
|
-
if (!ContentComponent) {
|
|
16
|
-
console.warn('ContentComponent undefined for block:', block);
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
15
|
return (_jsx(SectionComponent, { className: SectionStylesBySlot.root, children: _jsx(ContainerComponent, { className: ContainerStylesBySlot.root, children: _jsx(ContentComponent, { ...content }) }) }, i));
|
|
20
16
|
}) }));
|
|
21
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare const View: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
export
|
|
2
|
+
export const View = (args) => {
|
|
3
3
|
const { RowComponent, rows } = args;
|
|
4
4
|
return (_jsx(_Fragment, { children: rows.map((rowProps, i) => {
|
|
5
5
|
return _jsx(RowComponent, { ...rowProps }, i);
|
|
6
6
|
}) }));
|
|
7
|
-
}
|
|
7
|
+
};
|
package/dist/react/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../resolveLayout-
|
|
1
|
+
"use strict";var e=require("../resolveLayout-DT9L5tmd.js"),r=require("../LayoutRenderer-DaL3F4jD.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
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { Card } from './components/Card';
|
|
|
2
2
|
export { Container } from './components/Container';
|
|
3
3
|
export { View } from './components/View';
|
|
4
4
|
export { LayoutRenderer } from './LayoutRenderer';
|
|
5
|
-
export
|
|
5
|
+
export { componentRegistry } from './componentRegistry';
|
package/dist/react/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{C as Card,c as Container,V as View,d as componentRegistry}from"../resolveLayout-
|
|
1
|
+
export{C as Card,c as Container,V as View,d as componentRegistry}from"../resolveLayout-D0mOcO8S.js";export{L as LayoutRenderer}from"../LayoutRenderer-UTztjxah.js";import"react/jsx-runtime";
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/react/index.js
CHANGED
|
@@ -2,4 +2,4 @@ export { Card } from './components/Card';
|
|
|
2
2
|
export { Container } from './components/Container';
|
|
3
3
|
export { View } from './components/View';
|
|
4
4
|
export { LayoutRenderer } from './LayoutRenderer';
|
|
5
|
-
export
|
|
5
|
+
export { componentRegistry } from './componentRegistry';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsxs as e,jsx as o,Fragment as t}from"react/jsx-runtime";async function n(e,o){const t={};for(let n=0;n<o.length;n++){const s=o[n];if(!c(s))continue;const r=await a({payload:e,block:s});t[n]=Array.isArray(r)?r:[]}return t}function c(e){return"view"===e.blockType}async function a({payload:e,block:o}){return o.useInternalSource?async function({payload:e,block:o}){const t=await e.find({collection:o.internalCollection,sort:o.internalSort||void 0,depth:o.internalDepth??1});return t?.docs??[]}({payload:e,block:o}):o.dataSource?async function({payload:e,block:o}){try{const e=await fetch(o.dataSource),t=await e.json();return Array.isArray(t?.[o.dataSet])?t[o.dataSet]:[]}catch{return[]}}({payload:e,block:o}):[]}function s(e){const o={};if(!e?.styles)return o;for(const t of e.styles){const e=t.style;e&&(o[t.slot]=e)}return o}function r(e,o){if(!o)return e;const t={...e};for(const[e,n]of Object.entries(o))"root"!==e?t[e]&&"object"==typeof t[e]&&(t[e]={...t[e],className:[t[e].className,n].filter(Boolean).join(" ")}):t.className=[t.className,n].filter(Boolean).join(" ");return t}function i(e,o){return o.split(".").reduce((e,o)=>e?e[o]:void 0,e)}function l({data:e,mapper:o}){const t={};if(!o)return t;for(const n of Object.keys(o)){const c=o[n];"string"==typeof c&&c.startsWith("__static:")?t[n]=c.replace("__static:",""):t[n]="string"!=typeof c?"object"!=typeof c||null===c?void 0:l({data:e,mapper:c}):i(e,c)}return t}const p=t=>{const{className:n,imageProps:c,titleProps:a,descriptionProps:s,children:r}=t;return e("div",{className:n,children:[c?.src&&o("img",{src:c.src,alt:c.alt??"",className:c.className}),a?.text&&o("h3",{className:a.className,children:a.text}),s?.text&&o("p",{className:s.className,children:s.text}),r]})},m=({className:e,children:t})=>o("div",{className:e,children:t}),d=e=>{const{RowComponent:n,rows:c}=e;return o(t,{children:c.map((e,t)=>o(n,{...e},t))})},u={Section:({className:e,children:t})=>o("section",{className:e,children:t}),Container:m,View:d,Card:p};function y({block:e,context:o}){console.log(e);const t=o.registries.viewMode.byName[e.viewMode],n=o.registries.viewMode.byName[e.sectionViewMode],c=o.registries.viewMode.byName[e.containerViewMode],a=u[n?.component],i=u[c?.component],p=u[t.component],m=s(n),d=s(c),y=s(t);return{section:{SectionComponent:a,SectionStylesBySlot:m},container:{ContainerComponent:i,ContainerStylesBySlot:d},content:{ContentComponent:p,...r(l({data:e,mapper:t.blockPropsMapping}),y)}}}function f({block:e,rows:o,context:t}){const n=t.registries.viewMode.byName[e.sectionViewMode],c=t.registries.viewMode.byName[e.containerViewMode],a=t.registries.viewMode.byName[e.rowViewMode],i=u[n?.component],p=u[c?.component],m=u.View,d=u[a?.component];console.log("ContentComponent",m),console.log("RowComponent",d);const y=s(n),f=s(c),w=s(a);return{section:{SectionComponent:i,SectionStylesBySlot:y},container:{ContainerComponent:p,ContainerStylesBySlot:f},content:{ContentComponent:m,RowComponent:d,rows:o.map(o=>r(l({data:o,mapper:e.rowPropsMapping}),w))}}}async function w({layout:e,context:o}){const t=[],c=await n(o.payload,e);for(const[n,a]of e.entries())if(console.log("CURRENTBLOCK:",a),"view"===a.blockType)t.push(f({block:a,rows:c[n]??[],context:o}));else if("reference"===a.blockType){const e=await w({layout:a.block.value.layout,context:o});t.push(...e)}else t.push(y({block:a,context:o}));return t}export{p as C,d as V,w as a,r as b,m as c,u as d,i as g,l as m,n as r};
|
|
2
|
+
//# sourceMappingURL=resolveLayout-D0mOcO8S.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveLayout-D0mOcO8S.js","sources":["../src/uims/resolver/resolveViewData.ts","../src/uims/resolver/resolveStylesBySlot.ts","../src/uims/mapper/applyStylesToProps.ts","../src/uims/mapper/getValueByPath.ts","../src/uims/mapper/mapDataToProps.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/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","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 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 const 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","import { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { mapDataToProps } from '../mapper/mapDataToProps'\nimport { componentRegistry } from '../../react'\n\nexport function resolveInlineBlock({ block, context }: { block: any; context: UIMSContext }) {\n console.log(block)\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 console.log('ContentComponent', ContentComponent)\n console.log('RowComponent', RowComponent)\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 console.log('CURRENTBLOCK:', block)\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","resolveStylesBySlot","viewMode","styles","entry","classNames","style","slot","applyStylesToProps","props","stylesBySlot","nextProps","className","Object","entries","filter","Boolean","join","getValueByPath","obj","path","split","reduce","acc","key","mapDataToProps","mapper","keys","rule","startsWith","replace","Card","args","imageProps","titleProps","descriptionProps","children","_jsxs","src","_jsx","alt","text","Container","View","RowComponent","rows","_Fragment","map","rowProps","i","componentRegistry","Section","resolveInlineBlock","context","console","log","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,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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AApB7E,EAAMM,UAA2B,CAC1C,MAAMkG,QAAuBJ,EAAc,CAAExG,OAAQI,EAAMA,MAAMyG,MAAM7G,OAAQiF,YAC/EwB,EAASE,QAAQC,EACnB,MACEH,EAASE,KAAK3B,EAAmB,CAAE5E,QAAO6E,aAG9C,OAAOwB,CACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime");async function o(e,o){const s={};for(let r=0;r<o.length;r++){const a=o[r];if(!t(a))continue;const c=await n({payload:e,block:a});s[r]=Array.isArray(c)?c:[]}return s}function t(e){return"view"===e.blockType}async function n({payload:e,block:o}){return o.useInternalSource?async function({payload:e,block:o}){const t=await e.find({collection:o.internalCollection,sort:o.internalSort||void 0,depth:o.internalDepth??1});return t?.docs??[]}({payload:e,block:o}):o.dataSource?async function({payload:e,block:o}){try{const e=await fetch(o.dataSource),t=await e.json();return Array.isArray(t?.[o.dataSet])?t[o.dataSet]:[]}catch{return[]}}({payload:e,block:o}):[]}function s(e){const o={};if(!e?.styles)return o;for(const t of e.styles){const e=t.style;e&&(o[t.slot]=e)}return o}function r(e,o){if(!o)return e;const t={...e};for(const[e,n]of Object.entries(o))"root"!==e?t[e]&&"object"==typeof t[e]&&(t[e]={...t[e],className:[t[e].className,n].filter(Boolean).join(" ")}):t.className=[t.className,n].filter(Boolean).join(" ");return t}function a(e,o){return o.split(".").reduce((e,o)=>e?e[o]:void 0,e)}function c({data:e,mapper:o}){const t={};if(!o)return t;for(const n of Object.keys(o)){const s=o[n];"string"==typeof s&&s.startsWith("__static:")?t[n]=s.replace("__static:",""):t[n]="string"!=typeof s?"object"!=typeof s||null===s?void 0:c({data:e,mapper:s}):a(e,s)}return t}const i=o=>{const{className:t,imageProps:n,titleProps:s,descriptionProps:r,children:a}=o;return e.jsxs("div",{className:t,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]})},l=({className:o,children:t})=>e.jsx("div",{className:o,children:t}),p=o=>{const{RowComponent:t,rows:n}=o;return e.jsx(e.Fragment,{children:n.map((o,n)=>e.jsx(t,{...o},n))})},m={Section:({className:o,children:t})=>e.jsx("section",{className:o,children:t}),Container:l,View:p,Card:i};function y({block:e,context:o}){console.log(e);const t=o.registries.viewMode.byName[e.viewMode],n=o.registries.viewMode.byName[e.sectionViewMode],a=o.registries.viewMode.byName[e.containerViewMode],i=m[n?.component],l=m[a?.component],p=m[t.component],y=s(n),u=s(a),d=s(t);return{section:{SectionComponent:i,SectionStylesBySlot:y},container:{ContainerComponent:l,ContainerStylesBySlot:u},content:{ContentComponent:p,...r(c({data:e,mapper:t.blockPropsMapping}),d)}}}function u({block:e,rows:o,context:t}){const n=t.registries.viewMode.byName[e.sectionViewMode],a=t.registries.viewMode.byName[e.containerViewMode],i=t.registries.viewMode.byName[e.rowViewMode],l=m[n?.component],p=m[a?.component],y=m.View,u=m[i?.component];console.log("ContentComponent",y),console.log("RowComponent",u);const d=s(n),f=s(a),w=s(i);return{section:{SectionComponent:l,SectionStylesBySlot:d},container:{ContainerComponent:p,ContainerStylesBySlot:f},content:{ContentComponent:y,RowComponent:u,rows:o.map(o=>r(c({data:o,mapper:e.rowPropsMapping}),w))}}}exports.Card=i,exports.Container=l,exports.View=p,exports.applyStylesToProps=r,exports.componentRegistry=m,exports.getValueByPath=a,exports.mapDataToProps=c,exports.resolveLayout=async function e({layout:t,context:n}){const s=[],r=await o(n.payload,t);for(const[o,a]of t.entries())if(console.log("CURRENTBLOCK:",a),"view"===a.blockType)s.push(u({block:a,rows:r[o]??[],context:n}));else if("reference"===a.blockType){const o=await e({layout:a.block.value.layout,context:n});s.push(...o)}else s.push(y({block:a,context:n}));return s},exports.resolveViewData=o;
|
|
2
|
+
//# sourceMappingURL=resolveLayout-DT9L5tmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveLayout-DT9L5tmd.js","sources":["../src/uims/resolver/resolveViewData.ts","../src/uims/resolver/resolveStylesBySlot.ts","../src/uims/mapper/applyStylesToProps.ts","../src/uims/mapper/getValueByPath.ts","../src/uims/mapper/mapDataToProps.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/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","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 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 const 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","import { UIMSContext } from '../types/UIMSContext'\nimport { resolveStylesBySlot } from './resolveStylesBySlot'\nimport { applyStylesToProps } from '../mapper/applyStylesToProps'\nimport { mapDataToProps } from '../mapper/mapDataToProps'\nimport { componentRegistry } from '../../react'\n\nexport function resolveInlineBlock({ block, context }: { block: any; context: UIMSContext }) {\n console.log(block)\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 console.log('ContentComponent', ContentComponent)\n console.log('RowComponent', RowComponent)\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 console.log('CURRENTBLOCK:', block)\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","resolveStylesBySlot","viewMode","styles","entry","classNames","style","slot","applyStylesToProps","props","stylesBySlot","nextProps","className","Object","entries","filter","Boolean","join","getValueByPath","obj","path","split","reduce","acc","key","mapDataToProps","mapper","keys","rule","startsWith","replace","Card","args","imageProps","titleProps","descriptionProps","children","_jsxs","src","_jsx","alt","text","Container","View","RowComponent","rows","_Fragment","map","rowProps","i","componentRegistry","Section","resolveInlineBlock","context","console","log","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,E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,GAAiBG,WACtDC,EAAqBZ,EAAkBS,GAAmBE,WAC1DE,EAAmBb,EAAwB,KAC3CN,EAAeM,EAAkBsB,GAAaX,WACpDP,QAAQC,IAAI,mBAAoBQ,GAChCT,QAAQC,IAAI,eAAgBX,GAE5B,MAAMoB,EAAsB/D,EAAoByD,GAC1CO,EAAwBhE,EAAoB0D,GAC5Cc,EAAkBxE,EAAoBuE,GAY5C,MAAO,CACLL,QAAS,CACPP,mBACAI,uBAEFI,UAAW,CACTN,qBACAG,yBAEFI,QAAS,CACPN,mBACAnB,eACAC,KAtBaA,EAAKE,IAAK2B,GACzBlE,EACEiB,EAAe,CACb/C,KAAMgG,EACNhD,OAAQlD,EAAMmG,kBAEhBF,KAmBN,oLClDOxG,eAAe2G,GAAcxG,OAClCA,EAAMiF,QACNA,IAKA,MAAMwB,EAAkB,GAClBC,QAAiB5G,EAAgBmF,EAAQlF,QAASC,GACxD,IAAK,MAAOE,EAAOE,KAAUJ,EAAO0C,UAElC,GADAwC,QAAQC,IAAI,gBAAiB/E,GACL,SAApBA,EAAMM,UACR+F,EAASE,KACPR,EAAiB,CACf/F,QACAqE,KAAMiC,EAASxG,IAAU,GACzB+E,kBAGC,GAAwB,cAApB7E,EAAMM,UAA2B,CAC1C,MAAMkG,QAAuBJ,EAAc,CAAExG,OAAQI,EAAMA,MAAMyG,MAAM7G,OAAQiF,YAC/EwB,EAASE,QAAQC,EACnB,MACEH,EAASE,KAAK3B,EAAmB,CAAE5E,QAAO6E,aAG9C,OAAOwB,CACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { seedStyles } from './
|
|
2
|
-
import { seedViewModes } from './
|
|
3
|
-
import { seedComponents } from './
|
|
1
|
+
import { seedStyles } from './seedStyles';
|
|
2
|
+
import { seedViewModes } from './seedViewMode';
|
|
3
|
+
import { seedComponents } from './seedComponent';
|
|
4
4
|
export async function UIMSSeeder({ payload, include }) {
|
|
5
5
|
if (include.includes('styles')) {
|
|
6
6
|
await seedStyles(payload);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../tailwind/index.cjs.js");function t(){const t=[];for(const s of e.tailwindSelectorVariants)for(const
|
|
1
|
+
"use strict";var e=require("../tailwind/index.cjs.js");function t(){const t=[];for(const s of e.tailwindSelectorVariants)for(const o of Object.values(e.tailwindFieldsSelectors))for(const e of o){const o=`${s.value}${e}`,n=`t:${o}`;t.push({name:n,css:o})}return t}const s=[{name:"Container",component:"Container",styles:[{slot:"root",style:"container mx-auto"}]},{name:"Card",component:"Card",blockPropsMapping:{titleProps:{text:"titleProps.text"},descriptionProps:{text:"descriptionProps.text"},imageProps:{src:"imageProps.image.value.url"}},styles:[{slot:"root",style:"bg-white rounded-md shadow-md"}]}];const o=[{name:"Card",componentName:"Card",propsSchema:{titleProps:{text:"string",className:"string"},descriptionProps:{text:"string",className:"string"},imageProps:{src:"string",className:"string"}}}];exports.ListComponent=o,exports.ListViewMode=s,exports.UIMSSeeder=async function({payload:e,include:n}){n.includes("styles")&&await async function(e){const s=t(),o=await e.find({collection:"styles",limit:1e6,depth:0}),n=new Set(o.docs.map(e=>e.name));for(const t of s)if(!n.has(t.name))try{await e.create({collection:"styles",data:{name:t.name,css:{className:t.css}}})}catch(e){console.warn(`[SEED STYLES] Errore su "${t.name}", skip`,e?.message??e)}}(e),n.includes("viewMode")&&await async function(e){const t=await e.find({collection:"view-modes",limit:1e6,depth:0}),o=new Set(t.docs.map(e=>e.name));for(const t of s)if(!o.has(t.name))try{await e.create({collection:"view-modes",data:{...t}})}catch(e){console.warn(`[SEED VIEWMODE] Errore su "${t.name}", skip`,e?.message??e)}}(e),n.includes("component")&&await async function(e){const t=await e.find({collection:"component-definitions",limit:1e6,depth:0}),s=new Set(t.docs.map(e=>e.name));for(const t of o)if(!s.has(t.name))try{await e.create({collection:"component-definitions",data:{...t}})}catch(e){console.warn(`[SEED VIEWMODE] Errore su "${t.name}", skip`,e?.message??e)}}(e)},exports.listStyles=t;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/seeders/
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/seeders/listStyles.ts","../../src/seeders/listViewMode.ts","../../src/seeders/listComponent.ts","../../src/seeders/UIMSSeeder.ts","../../src/seeders/seedStyles.ts","../../src/seeders/seedViewMode.ts","../../src/seeders/seedComponent.ts"],"sourcesContent":["import { tailwindSelectorVariants } from '../tailwind/tailwindSelectorVariants'\nimport { tailwindFieldsSelectors } from '../tailwind/tailwindFieldSelectors'\n\ntype StyleSeed = {\n name: string\n css: string\n}\n\nexport function listStyles(): StyleSeed[] {\n const styles: StyleSeed[] = []\n\n for (const variant of tailwindSelectorVariants) {\n for (const selectors of Object.values(tailwindFieldsSelectors)) {\n for (const selector of selectors) {\n const value = `${variant.value}${selector}` // es. md:mx-auto\n const name = `t:${value}`\n styles.push({\n name,\n css: value,\n })\n }\n }\n }\n\n return styles\n}\n","export const ListViewMode = [\n {\n name: 'Container',\n component: 'Container',\n styles: [\n {\n slot: 'root',\n style: 'container mx-auto',\n },\n ],\n },\n {\n name: 'Card',\n component: 'Card',\n blockPropsMapping: {\n titleProps: {\n text: 'titleProps.text',\n },\n descriptionProps: {\n text: 'descriptionProps.text',\n },\n imageProps: {\n src: 'imageProps.image.value.url',\n },\n },\n styles: [\n {\n slot: 'root',\n style: 'bg-white rounded-md shadow-md',\n },\n ],\n },\n]\n","export const ListComponent = [\n {\n name: 'Card',\n componentName: 'Card',\n propsSchema: {\n titleProps: {\n text: 'string',\n className: 'string',\n },\n descriptionProps: {\n text: 'string',\n className: 'string',\n },\n imageProps: {\n src: 'string',\n className: 'string',\n },\n },\n },\n]\n","import { seedStyles } from './seedStyles'\nimport { seedViewModes } from './seedViewMode'\nimport { seedComponents } from './seedComponent'\n\ntype SeederTarget = 'styles' | 'viewMode' | 'component'\n\ninterface SeederOptions {\n payload: any\n include: SeederTarget[]\n}\n\nexport async function UIMSSeeder({ payload, include }: SeederOptions): Promise<void> {\n if (include.includes('styles')) {\n await seedStyles(payload)\n }\n\n if (include.includes('viewMode')) {\n await seedViewModes(payload)\n }\n\n if (include.includes('component')) {\n await seedComponents(payload)\n }\n}\n","import { listStyles } from './listStyles'\n\nexport async function seedStyles(payload: any): Promise<void> {\n const generatedStyles = listStyles()\n\n const existing = await payload.find({\n collection: 'styles',\n limit: 1000000,\n depth: 0,\n })\n\n const existingNames = new Set(existing.docs.map((style: any) => style.name))\n\n for (const style of generatedStyles) {\n if (existingNames.has(style.name)) {\n continue\n }\n\n try {\n await payload.create({\n collection: 'styles',\n data: {\n name: style.name,\n css: { className: style.css },\n },\n })\n } catch (error: any) {\n console.warn(`[SEED STYLES] Errore su \"${style.name}\", skip`, error?.message ?? error)\n }\n }\n}\n","import { ListViewMode } from './listViewMode'\n\nexport async function seedViewModes(payload: any): Promise<void> {\n const existing = await payload.find({\n collection: 'view-modes',\n limit: 1000000,\n depth: 0,\n })\n\n const existingNames = new Set(existing.docs.map((vm: any) => vm.name))\n\n for (const viewMode of ListViewMode) {\n if (existingNames.has(viewMode.name)) {\n continue\n }\n\n try {\n await payload.create({\n collection: 'view-modes',\n data: {\n ...viewMode,\n },\n })\n } catch (error: any) {\n console.warn(`[SEED VIEWMODE] Errore su \"${viewMode.name}\", skip`, error?.message ?? error)\n }\n }\n}\n","import { ListComponent } from './listComponent'\n\nexport async function seedComponents(payload: any): Promise<void> {\n const existing = await payload.find({\n collection: 'component-definitions',\n limit: 1000000,\n depth: 0,\n })\n\n const existingNames = new Set(existing.docs.map((vm: any) => vm.name))\n\n for (const component of ListComponent) {\n if (existingNames.has(component.name)) {\n continue\n }\n\n try {\n await payload.create({\n collection: 'component-definitions',\n data: {\n ...component,\n },\n })\n } catch (error: any) {\n console.warn(`[SEED VIEWMODE] Errore su \"${component.name}\", skip`, error?.message ?? error)\n }\n }\n}\n"],"names":["listStyles","styles","variant","tailwindSelectorVariants","selectors","Object","values","tailwindFieldsSelectors","selector","value","name","push","css","ListViewMode","component","slot","style","blockPropsMapping","titleProps","text","descriptionProps","imageProps","src","ListComponent","componentName","propsSchema","className","async","payload","include","includes","generatedStyles","existing","find","collection","limit","depth","existingNames","Set","docs","map","has","create","data","error","console","warn","message","seedStyles","vm","viewMode","seedViewModes","seedComponents"],"mappings":"gEAQgBA,IACd,MAAMC,EAAsB,GAE5B,IAAK,MAAMC,KAAWC,2BACpB,IAAK,MAAMC,KAAaC,OAAOC,OAAOC,EAAAA,yBACpC,IAAK,MAAMC,KAAYJ,EAAW,CAChC,MAAMK,EAAQ,GAAGP,EAAQO,QAAQD,IAC3BE,EAAO,KAAKD,IAClBR,EAAOU,KAAK,CACVD,OACAE,IAAKH,GAET,CAIJ,OAAOR,CACT,CCzBO,MAAMY,EAAe,CAC1B,CACEH,KAAM,YACNI,UAAW,YACXb,OAAQ,CACN,CACEc,KAAM,OACNC,MAAO,uBAIb,CACEN,KAAM,OACNI,UAAW,OACXG,kBAAmB,CACjBC,WAAY,CACVC,KAAM,mBAERC,iBAAkB,CAChBD,KAAM,yBAERE,WAAY,CACVC,IAAK,+BAGTrB,OAAQ,CACN,CACEc,KAAM,OACNC,MAAO,oCC5BR,MAAMO,EAAgB,CAC3B,CACEb,KAAM,OACNc,cAAe,OACfC,YAAa,CACXP,WAAY,CACVC,KAAM,SACNO,UAAW,UAEbN,iBAAkB,CAChBD,KAAM,SACNO,UAAW,UAEbL,WAAY,CACVC,IAAK,SACLI,UAAW,+ECJZC,gBAA0BC,QAAEA,EAAOC,QAAEA,IACtCA,EAAQC,SAAS,iBCVhBH,eAA0BC,GAC/B,MAAMG,EAAkB/B,IAElBgC,QAAiBJ,EAAQK,KAAK,CAClCC,WAAY,SACZC,MAAO,IACPC,MAAO,IAGHC,EAAgB,IAAIC,IAAIN,EAASO,KAAKC,IAAKxB,GAAeA,EAAMN,OAEtE,IAAK,MAAMM,KAASe,EAClB,IAAIM,EAAcI,IAAIzB,EAAMN,MAI5B,UACQkB,EAAQc,OAAO,CACnBR,WAAY,SACZS,KAAM,CACJjC,KAAMM,EAAMN,KACZE,IAAK,CAAEc,UAAWV,EAAMJ,OAG9B,CAAE,MAAOgC,GACPC,QAAQC,KAAK,4BAA4B9B,EAAMN,cAAekC,GAAOG,SAAWH,EAClF,CAEJ,CDjBUI,CAAWpB,GAGfC,EAAQC,SAAS,mBEdhBH,eAA6BC,GAClC,MAAMI,QAAiBJ,EAAQK,KAAK,CAClCC,WAAY,aACZC,MAAO,IACPC,MAAO,IAGHC,EAAgB,IAAIC,IAAIN,EAASO,KAAKC,IAAKS,GAAYA,EAAGvC,OAEhE,IAAK,MAAMwC,KAAYrC,EACrB,IAAIwB,EAAcI,IAAIS,EAASxC,MAI/B,UACQkB,EAAQc,OAAO,CACnBR,WAAY,aACZS,KAAM,IACDO,IAGT,CAAE,MAAON,GACPC,QAAQC,KAAK,8BAA8BI,EAASxC,cAAekC,GAAOG,SAAWH,EACvF,CAEJ,CFVUO,CAAcvB,GAGlBC,EAAQC,SAAS,oBGlBhBH,eAA8BC,GACnC,MAAMI,QAAiBJ,EAAQK,KAAK,CAClCC,WAAY,wBACZC,MAAO,IACPC,MAAO,IAGHC,EAAgB,IAAIC,IAAIN,EAASO,KAAKC,IAAKS,GAAYA,EAAGvC,OAEhE,IAAK,MAAMI,KAAaS,EACtB,IAAIc,EAAcI,IAAI3B,EAAUJ,MAIhC,UACQkB,EAAQc,OAAO,CACnBR,WAAY,wBACZS,KAAM,IACD7B,IAGT,CAAE,MAAO8B,GACPC,QAAQC,KAAK,8BAA8BhC,EAAUJ,cAAekC,GAAOG,SAAWH,EACxF,CAEJ,CHNUQ,CAAexB,EAEzB"}
|
package/dist/seeders/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{tailwindSelectorVariants as e,tailwindFieldsSelectors as t}from"../tailwind/index.esm.js";function o(){const o=[];for(const n of e)for(const e of Object.values(t))for(const t of e){const e=`${n.value}${t}`,s=`t:${e}`;o.push({name:s,css:e})}return o}const n=[{name:"Container",component:"Container",styles:[{slot:"root",style:"container mx-auto"}]},{name:"Card",component:"Card",blockPropsMapping:{titleProps:{text:"titleProps.text"},descriptionProps:{text:"descriptionProps.text"},imageProps:{src:"imageProps.image.value.url"}},styles:[{slot:"root",style:"bg-white rounded-md shadow-md"}]}];const s=[{name:"Card",componentName:"Card",propsSchema:{titleProps:{text:"string",className:"string"},descriptionProps:{text:"string",className:"string"},imageProps:{src:"string",className:"string"}}}];async function a({payload:e,include:t}){t.includes("styles")&&await async function(e){const t=o(),n=await e.find({collection:"styles",limit:1e6,depth:0}),s=new Set(n.docs.map(e=>e.name));for(const o of t)if(!s.has(o.name))try{await e.create({collection:"styles",data:{name:o.name,css:{className:o.css}}})}catch(e){console.warn(`[SEED STYLES] Errore su "${o.name}", skip`,e?.message??e)}}(e),t.includes("viewMode")&&await async function(e){const t=await e.find({collection:"view-modes",limit:1e6,depth:0}),o=new Set(t.docs.map(e=>e.name));for(const t of n)if(!o.has(t.name))try{await e.create({collection:"view-modes",data:{...t}})}catch(e){console.warn(`[SEED VIEWMODE] Errore su "${t.name}", skip`,e?.message??e)}}(e),t.includes("component")&&await async function(e){const t=await e.find({collection:"component-definitions",limit:1e6,depth:0}),o=new Set(t.docs.map(e=>e.name));for(const t of s)if(!o.has(t.name))try{await e.create({collection:"component-definitions",data:{...t}})}catch(e){console.warn(`[SEED VIEWMODE] Errore su "${t.name}", skip`,e?.message??e)}}(e)}export{a as UIMSSeeder,o as
|
|
1
|
+
import{tailwindSelectorVariants as e,tailwindFieldsSelectors as t}from"../tailwind/index.esm.js";function o(){const o=[];for(const n of e)for(const e of Object.values(t))for(const t of e){const e=`${n.value}${t}`,s=`t:${e}`;o.push({name:s,css:e})}return o}const n=[{name:"Container",component:"Container",styles:[{slot:"root",style:"container mx-auto"}]},{name:"Card",component:"Card",blockPropsMapping:{titleProps:{text:"titleProps.text"},descriptionProps:{text:"descriptionProps.text"},imageProps:{src:"imageProps.image.value.url"}},styles:[{slot:"root",style:"bg-white rounded-md shadow-md"}]}];const s=[{name:"Card",componentName:"Card",propsSchema:{titleProps:{text:"string",className:"string"},descriptionProps:{text:"string",className:"string"},imageProps:{src:"string",className:"string"}}}];async function a({payload:e,include:t}){t.includes("styles")&&await async function(e){const t=o(),n=await e.find({collection:"styles",limit:1e6,depth:0}),s=new Set(n.docs.map(e=>e.name));for(const o of t)if(!s.has(o.name))try{await e.create({collection:"styles",data:{name:o.name,css:{className:o.css}}})}catch(e){console.warn(`[SEED STYLES] Errore su "${o.name}", skip`,e?.message??e)}}(e),t.includes("viewMode")&&await async function(e){const t=await e.find({collection:"view-modes",limit:1e6,depth:0}),o=new Set(t.docs.map(e=>e.name));for(const t of n)if(!o.has(t.name))try{await e.create({collection:"view-modes",data:{...t}})}catch(e){console.warn(`[SEED VIEWMODE] Errore su "${t.name}", skip`,e?.message??e)}}(e),t.includes("component")&&await async function(e){const t=await e.find({collection:"component-definitions",limit:1e6,depth:0}),o=new Set(t.docs.map(e=>e.name));for(const t of s)if(!o.has(t.name))try{await e.create({collection:"component-definitions",data:{...t}})}catch(e){console.warn(`[SEED VIEWMODE] Errore su "${t.name}", skip`,e?.message??e)}}(e)}export{s as ListComponent,n as ListViewMode,a as UIMSSeeder,o as listStyles};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../../src/seeders/
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/seeders/listStyles.ts","../../src/seeders/listViewMode.ts","../../src/seeders/listComponent.ts","../../src/seeders/UIMSSeeder.ts","../../src/seeders/seedStyles.ts","../../src/seeders/seedViewMode.ts","../../src/seeders/seedComponent.ts"],"sourcesContent":["import { tailwindSelectorVariants } from '../tailwind/tailwindSelectorVariants'\nimport { tailwindFieldsSelectors } from '../tailwind/tailwindFieldSelectors'\n\ntype StyleSeed = {\n name: string\n css: string\n}\n\nexport function listStyles(): StyleSeed[] {\n const styles: StyleSeed[] = []\n\n for (const variant of tailwindSelectorVariants) {\n for (const selectors of Object.values(tailwindFieldsSelectors)) {\n for (const selector of selectors) {\n const value = `${variant.value}${selector}` // es. md:mx-auto\n const name = `t:${value}`\n styles.push({\n name,\n css: value,\n })\n }\n }\n }\n\n return styles\n}\n","export const ListViewMode = [\n {\n name: 'Container',\n component: 'Container',\n styles: [\n {\n slot: 'root',\n style: 'container mx-auto',\n },\n ],\n },\n {\n name: 'Card',\n component: 'Card',\n blockPropsMapping: {\n titleProps: {\n text: 'titleProps.text',\n },\n descriptionProps: {\n text: 'descriptionProps.text',\n },\n imageProps: {\n src: 'imageProps.image.value.url',\n },\n },\n styles: [\n {\n slot: 'root',\n style: 'bg-white rounded-md shadow-md',\n },\n ],\n },\n]\n","export const ListComponent = [\n {\n name: 'Card',\n componentName: 'Card',\n propsSchema: {\n titleProps: {\n text: 'string',\n className: 'string',\n },\n descriptionProps: {\n text: 'string',\n className: 'string',\n },\n imageProps: {\n src: 'string',\n className: 'string',\n },\n },\n },\n]\n","import { seedStyles } from './seedStyles'\nimport { seedViewModes } from './seedViewMode'\nimport { seedComponents } from './seedComponent'\n\ntype SeederTarget = 'styles' | 'viewMode' | 'component'\n\ninterface SeederOptions {\n payload: any\n include: SeederTarget[]\n}\n\nexport async function UIMSSeeder({ payload, include }: SeederOptions): Promise<void> {\n if (include.includes('styles')) {\n await seedStyles(payload)\n }\n\n if (include.includes('viewMode')) {\n await seedViewModes(payload)\n }\n\n if (include.includes('component')) {\n await seedComponents(payload)\n }\n}\n","import { listStyles } from './listStyles'\n\nexport async function seedStyles(payload: any): Promise<void> {\n const generatedStyles = listStyles()\n\n const existing = await payload.find({\n collection: 'styles',\n limit: 1000000,\n depth: 0,\n })\n\n const existingNames = new Set(existing.docs.map((style: any) => style.name))\n\n for (const style of generatedStyles) {\n if (existingNames.has(style.name)) {\n continue\n }\n\n try {\n await payload.create({\n collection: 'styles',\n data: {\n name: style.name,\n css: { className: style.css },\n },\n })\n } catch (error: any) {\n console.warn(`[SEED STYLES] Errore su \"${style.name}\", skip`, error?.message ?? error)\n }\n }\n}\n","import { ListViewMode } from './listViewMode'\n\nexport async function seedViewModes(payload: any): Promise<void> {\n const existing = await payload.find({\n collection: 'view-modes',\n limit: 1000000,\n depth: 0,\n })\n\n const existingNames = new Set(existing.docs.map((vm: any) => vm.name))\n\n for (const viewMode of ListViewMode) {\n if (existingNames.has(viewMode.name)) {\n continue\n }\n\n try {\n await payload.create({\n collection: 'view-modes',\n data: {\n ...viewMode,\n },\n })\n } catch (error: any) {\n console.warn(`[SEED VIEWMODE] Errore su \"${viewMode.name}\", skip`, error?.message ?? error)\n }\n }\n}\n","import { ListComponent } from './listComponent'\n\nexport async function seedComponents(payload: any): Promise<void> {\n const existing = await payload.find({\n collection: 'component-definitions',\n limit: 1000000,\n depth: 0,\n })\n\n const existingNames = new Set(existing.docs.map((vm: any) => vm.name))\n\n for (const component of ListComponent) {\n if (existingNames.has(component.name)) {\n continue\n }\n\n try {\n await payload.create({\n collection: 'component-definitions',\n data: {\n ...component,\n },\n })\n } catch (error: any) {\n console.warn(`[SEED VIEWMODE] Errore su \"${component.name}\", skip`, error?.message ?? error)\n }\n }\n}\n"],"names":["listStyles","styles","variant","tailwindSelectorVariants","selectors","Object","values","tailwindFieldsSelectors","selector","value","name","push","css","ListViewMode","component","slot","style","blockPropsMapping","titleProps","text","descriptionProps","imageProps","src","ListComponent","componentName","propsSchema","className","async","UIMSSeeder","payload","include","includes","generatedStyles","existing","find","collection","limit","depth","existingNames","Set","docs","map","has","create","data","error","console","warn","message","seedStyles","vm","viewMode","seedViewModes","seedComponents"],"mappings":"0GAQgBA,IACd,MAAMC,EAAsB,GAE5B,IAAK,MAAMC,KAAWC,EACpB,IAAK,MAAMC,KAAaC,OAAOC,OAAOC,GACpC,IAAK,MAAMC,KAAYJ,EAAW,CAChC,MAAMK,EAAQ,GAAGP,EAAQO,QAAQD,IAC3B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E,IAAK,MAAMyC,KAAYtC,EACrB,IAAIyB,EAAcI,IAAIS,EAASzC,MAI/B,UACQmB,EAAQc,OAAO,CACnBR,WAAY,aACZS,KAAM,IACDO,IAGT,CAAE,MAAON,GACPC,QAAQC,KAAK,8BAA8BI,EAASzC,cAAemC,GAAOG,SAAWH,EACvF,CAEJ,CFVUO,CAAcvB,GAGlBC,EAAQC,SAAS,oBGlBhBJ,eAA8BE,GACnC,MAAMI,QAAiBJ,EAAQK,KAAK,CAClCC,WAAY,wBACZC,MAAO,IACPC,MAAO,IAGHC,EAAgB,IAAIC,IAAIN,EAASO,KAAKC,IAAKS,GAAYA,EAAGxC,OAEhE,IAAK,MAAMI,KAAaS,EACtB,IAAIe,EAAcI,IAAI5B,EAAUJ,MAIhC,UACQmB,EAAQc,OAAO,CACnBR,WAAY,wBACZS,KAAM,IACD9B,IAGT,CAAE,MAAO+B,GACPC,QAAQC,KAAK,8BAA8BjC,EAAUJ,cAAemC,GAAOG,SAAWH,EACxF,CAEJ,CHNUQ,CAAexB,EAEzB"}
|
package/dist/seeders/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tailwindSelectorVariants } from '../tailwind/tailwindSelectorVariants';
|
|
2
2
|
import { tailwindFieldsSelectors } from '../tailwind/tailwindFieldSelectors';
|
|
3
|
-
export function
|
|
3
|
+
export function listStyles() {
|
|
4
4
|
const styles = [];
|
|
5
5
|
for (const variant of tailwindSelectorVariants) {
|
|
6
6
|
for (const selectors of Object.values(tailwindFieldsSelectors)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ListComponent } from './listComponent';
|
|
2
2
|
export async function seedComponents(payload) {
|
|
3
3
|
const existing = await payload.find({
|
|
4
4
|
collection: 'component-definitions',
|
|
@@ -6,7 +6,7 @@ export async function seedComponents(payload) {
|
|
|
6
6
|
depth: 0,
|
|
7
7
|
});
|
|
8
8
|
const existingNames = new Set(existing.docs.map((vm) => vm.name));
|
|
9
|
-
for (const component of
|
|
9
|
+
for (const component of ListComponent) {
|
|
10
10
|
if (existingNames.has(component.name)) {
|
|
11
11
|
continue;
|
|
12
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { listStyles } from './listStyles';
|
|
2
2
|
export async function seedStyles(payload) {
|
|
3
|
-
const generatedStyles =
|
|
3
|
+
const generatedStyles = listStyles();
|
|
4
4
|
const existing = await payload.find({
|
|
5
5
|
collection: 'styles',
|
|
6
6
|
limit: 1000000,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ListViewMode } from './listViewMode';
|
|
2
2
|
export async function seedViewModes(payload) {
|
|
3
3
|
const existing = await payload.find({
|
|
4
4
|
collection: 'view-modes',
|
|
@@ -6,7 +6,7 @@ export async function seedViewModes(payload) {
|
|
|
6
6
|
depth: 0,
|
|
7
7
|
});
|
|
8
8
|
const existingNames = new Set(existing.docs.map((vm) => vm.name));
|
|
9
|
-
for (const viewMode of
|
|
9
|
+
for (const viewMode of ListViewMode) {
|
|
10
10
|
if (existingNames.has(viewMode.name)) {
|
|
11
11
|
continue;
|
|
12
12
|
}
|
package/dist/uims/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../resolveLayout-
|
|
1
|
+
"use strict";var e=require("../resolveLayout-DT9L5tmd.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
|
package/dist/uims/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{b as applyStylesToProps,g as getValueByPath,m as mapDataToProps,a as resolveLayout,r as resolveViewData}from"../resolveLayout-
|
|
1
|
+
export{b as applyStylesToProps,g as getValueByPath,m as mapDataToProps,a as resolveLayout,r as resolveViewData}from"../resolveLayout-D0mOcO8S.js";import"react/jsx-runtime";
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { componentRegistry } from '../../react/componentRegistry';
|
|
2
1
|
import { resolveStylesBySlot } from './resolveStylesBySlot';
|
|
3
2
|
import { applyStylesToProps } from '../mapper/applyStylesToProps';
|
|
4
3
|
import { mapDataToProps } from '../mapper/mapDataToProps';
|
|
4
|
+
import { componentRegistry } from '../../react';
|
|
5
5
|
export function resolveInlineBlock({ block, context }) {
|
|
6
|
+
console.log(block);
|
|
6
7
|
const viewMode = context.registries.viewMode.byName[block.viewMode];
|
|
7
8
|
const sectionViewMode = context.registries.viewMode.byName[block.sectionViewMode];
|
|
8
9
|
const containerViewMode = context.registries.viewMode.byName[block.containerViewMode];
|
|
@@ -5,6 +5,7 @@ export async function resolveLayout({ layout, context, }) {
|
|
|
5
5
|
const resolved = [];
|
|
6
6
|
const viewData = await resolveViewData(context.payload, layout);
|
|
7
7
|
for (const [index, block] of layout.entries()) {
|
|
8
|
+
console.log('CURRENTBLOCK:', block);
|
|
8
9
|
if (block.blockType === 'view') {
|
|
9
10
|
resolved.push(resolveViewBlock({
|
|
10
11
|
block,
|
|
@@ -10,6 +10,8 @@ export function resolveViewBlock({ block, rows, context, }) {
|
|
|
10
10
|
const ContainerComponent = componentRegistry[containerViewMode?.component];
|
|
11
11
|
const ContentComponent = componentRegistry['View'];
|
|
12
12
|
const RowComponent = componentRegistry[rowViewMode?.component];
|
|
13
|
+
console.log('ContentComponent', ContentComponent);
|
|
14
|
+
console.log('RowComponent', RowComponent);
|
|
13
15
|
const SectionStylesBySlot = resolveStylesBySlot(sectionViewMode);
|
|
14
16
|
const ContainerStylesBySlot = resolveStylesBySlot(containerViewMode);
|
|
15
17
|
const RowStylesBySlot = resolveStylesBySlot(rowViewMode);
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutRenderer-DMN7UMr-.js","sources":["../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 { 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 { 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 const { section, container, content } = block\n const { SectionComponent, SectionStylesBySlot } = section\n const { ContainerComponent, ContainerStylesBySlot } = container\n const { ContentComponent } = content\n\n if (!ContentComponent) {\n console.warn('ContentComponent undefined for block:', block)\n return null\n }\n\n return (\n <SectionComponent key={i} className={SectionStylesBySlot.root}>\n <ContainerComponent className={ContainerStylesBySlot.root}>\n <ContentComponent {...content} />\n </ContainerComponent>\n </SectionComponent>\n )\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":["cache","async","getStyleRegistry","payload","result","find","collection","depth","pagination","byName","vm","docs","name","getViewModeRegistry","getComponentRegistry","layout","uims","registries","styles","viewMode","component","createUIMSContext","resolvedLayout","resolveLayout","context","_jsx","_Fragment","children","map","block","i","section","container","content","SectionComponent","SectionStylesBySlot","ContainerComponent","ContainerStylesBySlot","ContentComponent","className","root","console","warn"],"mappings":"yFAEA,IAAIA,EAEO,KAGJC,eAAeC,EAAiBC,GACrC,GAAIH,EACF,OAAOA,EAGT,MAAMI,QAAeD,EAAQE,KAAK,CAChCC,WAAY,SACZC,MAAO,EACPC,YAAY,IAGRC,EAA8B,CAAA,EAEpC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A,IAACS,EAAgB,CAASK,UAAWJ,EAAoBK,KAAIb,SAC3DF,MAACW,EAAkB,CAACG,UAAWF,EAAsBG,KAAIb,SACvDF,EAAAA,IAACa,EAAgB,IAAKL,OAFHH,IALvBW,QAAQC,KAAK,wCAAyCb,GAC/C,SAajB"}
|
|
@@ -1,2 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,MA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C5Cc,EAAkBhD,EAAoB+C,GAY5C,MAAO,CACLL,QAAS,CACPP,mBACAI,uBAEFI,UAAW,CACTN,qBACAG,yBAEFI,QAAS,CACPN,mBACA9C,eACAC,KAtBaA,EAAKE,IAAKsD,GACzB1C,EACEgB,EAAe,CACbpE,KAAM8F,EACNzB,OAAQvE,EAAMiG,kBAEhBF,KAmBN,oLChDOtG,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 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,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,SAAW,EACtE,CAAE,MACA,MAAO,EACT,CACF,CAxCWC,CAAoB,CACzB7B,UACAK,UAIG,EACT,CC5CO,MAAMyB,EAAQC,IACnB,MAAMC,UAAEA,EAASC,WAAEA,EAAUC,WAAEA,EAAUC,iBAAEA,EAAgBC,SAAEA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