{"version":3,"file":"render.mjs","sources":["src/common.mjs","src/render.mjs"],"sourcesContent":["// Common Utilities Class\nexport default class {\n constructor(objArgs) {\n this.sectionLayoutData = objArgs.sectionLayoutData\n this.renderMode = objArgs.renderMode\n this.customSettingsData = objArgs.customSettingsData\n this.DOMNode = objArgs.parser || false\n this.arrComponents = this.sectionLayoutData.components || []\n }\n\n addComponentToColumn(componentGroup) {\n const elDropzone = this.createElement('div')\n elDropzone.setAttribute('id', componentGroup)\n this.elColumnsDiv.appendChild(elDropzone)\n }\n\n addDropzones() {\n // We don't want dropzones to be added in compilation (wouldn't work anyway since this function uses SCSRenderAPI).\n if (this.DOMNode) {\n return\n }\n // Variable to hold component groups\n let arSectionLayoutComponentGroups = this.arrComponents || []\n while (arSectionLayoutComponentGroups.length < this.customSettingsData.numColumns) {\n try {\n arSectionLayoutComponentGroups.push(\n SCSRenderAPI.addComponentToPageModel({\n type: 'scs-componentgroup',\n id: 'scs-componentgroup',\n data: {\n components: [],\n grid: '',\n },\n }),\n )\n } catch (error) {\n console.error(error)\n }\n // Remove components if the number of components is greater than the number of sections set in the settings\n while (arSectionLayoutComponentGroups.length > this.customSettingsData.numColumns) {\n arSectionLayoutComponentGroups.pop()\n }\n this.arrComponents = arSectionLayoutComponentGroups\n }\n }\n\n // createElement() creates a DOM element with the given tag name\n createElement(element) {\n // element: string\n // uses DOMNode in compilation, or the document object in the renderer\n return this.DOMNode ? new this.DOMNode(element, {}, '') : document.createElement(element)\n }\n\n initializeLayout(layout) {\n try {\n this.elColumnsDiv = this.createElement('div')\n this.elColumnsDiv.classList.add('mnh-columns')\n this.elColumnsDiv.setAttribute(\"style\", `--number-of-columns: ${this.customSettingsData.numColumns}`)\n layout.appendChild(this.elColumnsDiv)\n // handle component groups\n this.addDropzones()\n this.arrComponents.forEach(component => this.addComponentToColumn(component))\n return layout;\n } catch (error) {\n console.error(error)\n }\n }\n}\n","import shared from './common.mjs'\n\nexport default class {\n\n\tconstructor(params) {\n\n\t\t// store the path to the /assets folder\n\t\tthis.assetsPath =\n\t\t\timport.meta.url.replace('/render.mjs', '')\n\n\t\t// get any OCM environment resources\n\t\tthis.$ = SCSRenderAPI.getJQuery()\n\n\t\t// load up the component's CSS\n\t\tSCSRenderAPI.importCSS(this.assetsPath + '/styles/layout.css')\n\n\t\t// start common.mjs\n\t\tconst objArgs = {\n\t\t\t// sectionLayoutData - contains customSettingsData, and components array\n\t\t\tsectionLayoutData: params.sectionLayoutData || {},\n\t\t\t// renderMode - edit or view so we know if we're in sitebuilder\n\t\t\trenderMode: params.renderMode || SCSRenderAPI.getRenderMode(),\n\t\t\tcustomSettingsData: params.sectionLayoutData.customSettingsData || {}\n\t\t}\n\t\tthis.shared = new shared(objArgs)\n\t}\n\n\t// add in the listeners for the settings values change, rerender\n\taddEventListeners(parentObj) {\n\t\t// listen for settings update\n\t\t// TODO this is not working yet, sitesSDK should be in sl params eventually\n\t\t// https://support.oracle.com/epmos/faces/SrDetail?srNumber=3-30168014461\n\t\t// this.sitesSDK.subscribe(\n\t\t// \tthis.sitesSDK.MESSAGE_TYPES.SETTINGS_UPDATED,\n\t\t// \t(props) => {\n\t\t// console.log({props})\n\t\t// \t\tif (props.property === 'customSettingsData') {\n\t\t// this.shared.sectionLayoutData.customSettingsData = props.value;\n\t\t// \t\t\tthis.render({\n\t\t// \t\t\t\tcustomSettingsData: props.value,\n\t\t// \t\t\t})\n\t\t// \t}\n\t\t// );\n\t}\n\n\taddEditModeHandlers(parentObj, shared) {\n\t\t// Add a drop zone to the section layout in edit mode, if applicable\n\t\tif (shared.renderMode === SCSRenderAPI.RENDER_MODE_EDIT) {\n\t\t\tconst emptyClass = (shared.arrComponents.length > 0) ? '' : 'sl-empty'\n\t\t\t// Uncomment to enforce a maximum number of items in the section layout\n\n\t\t\t// if (shared.components.length < shared.customSettingsData.maxItems) {\n\t\t\tthis.$(parentObj).append('
+
')\n\t\t\t// }\n\n\t\t}\n\t}\n\n\thydrate(parentObj) {\n\t}\n\n\trender(parentObj) {\n\t\ttry {\n\t\t\tthis.shared.initializeLayout(parentObj)\n\t\t\tthis.addEventListeners()\n\t\t\tthis.addEditModeHandlers(parentObj, this.shared)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t}\n\t}\n}"],"names":["constructor","objArgs","this","sectionLayoutData","renderMode","customSettingsData","DOMNode","parser","arrComponents","components","addComponentToColumn","componentGroup","elDropzone","createElement","setAttribute","elColumnsDiv","appendChild","addDropzones","arSectionLayoutComponentGroups","length","numColumns","push","SCSRenderAPI","addComponentToPageModel","type","id","data","grid","error","console","pop","element","document","initializeLayout","layout","classList","add","concat","forEach","component","render","params","assetsPath","import","meta","url","replace","$","getJQuery","importCSS","getRenderMode","shared","addEventListeners","parentObj","addEditModeHandlers","RENDER_MODE_EDIT","emptyClass","append","hydrate","e"],"mappings":"QAEIA,YAAYC,GACRC,KAAKC,kBAAoBF,EAAQE,kBACjCD,KAAKE,WAAaH,EAAQG,WAC1BF,KAAKG,mBAAqBJ,EAAQI,mBAClCH,KAAKI,QAAUL,EAAQM,SAAU,EACjCL,KAAKM,cAAgBN,KAAKC,kBAAkBM,YAAc,EAC9D,CAEAC,qBAAqBC,GACjB,MAAMC,EAAaV,KAAKW,cAAc,OACtCD,EAAWE,aAAa,KAAMH,GAC9BT,KAAKa,aAAaC,YAAYJ,EACjC,CAEDK,eAEI,GAAIf,KAAKI,QACL,OAGJ,IAAkCY,EAAGhB,KAAKM,eAAiB,GAC3D,KAAOU,EAA+BC,OAASjB,KAAKG,mBAAmBe,YAAY,CAC/E,IACIF,EAA+BG,KAC3BC,aAAaC,wBAAwB,CACjCC,KAAM,qBACNC,GAAI,qBACJC,KAAM,CACFjB,WAAY,GACZkB,KAAM,MAMrB,CAFC,MAAOC,GACLC,QAAQD,MAAMA,EACjB,CAED,KAAOV,EAA+BC,OAASjB,KAAKG,mBAAmBe,YACnEF,EAA+BY,MAEnC5B,KAAKM,cAAgBU,CACxB,CACJ,CAGDL,cAAckB,GAGV,OAAYz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