@sitecore/byoc
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -88,2 +88,3 @@ import { transformSchema } from './schema.js'; | ||
export function registerDatasource(handler, options) { | ||
var _a; | ||
if (typeof handler !== 'function') { | ||
@@ -99,3 +100,3 @@ throw new Error(`The first argument of registerDatasource must be a function returning DataSettings or Promise of data`); | ||
} | ||
if (getDatasource(options.id)) { | ||
if (((_a = getDatasource(options.id)) === null || _a === void 0 ? void 0 : _a.handler) != null) { | ||
throw new Error(`Datasource with id ${options.id} already registered`); | ||
@@ -102,0 +103,0 @@ } |
@@ -1,2 +0,2 @@ | ||
var S=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[b(r)]:e[r]}),{}),Y=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[O(r)]:e[r]}),{});function b(e){let t=/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;return O(e).replace(t,function(r){return"-"+r.toLowerCase()})}function O(e){return e=e.replace(/[-_ ]+/g," "),e=e.charAt(0).toLowerCase()+e.slice(1),e.split(/\s+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join("")}function h(e,t={}){let r=e.properties||{},n=e.required||[];return Object.assign(Object.assign({type:"object"},e),{required:n,properties:Object.keys(r).reduce((i,o)=>{let s=Object.assign(Object.assign({},r[o]),{default:t.hasOwnProperty(o)?t[o]:r[o].default,title:r[o].title||b(o).split("-").map(c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()).join(" ")});return s.default===void 0&&delete s.default,"required"in s&&typeof s.required=="boolean"&&(n.indexOf(o)==-1&&n.push(o),delete s.required),Object.assign(i,{[o]:s})},{})})}var E=(e,t)=>{let r=Object.assign({},e);return Object.keys(t).filter(i=>/(integer|number)/.test(t[i].type)).forEach(i=>{var o;!((o=r[i])===null||o===void 0)&&o["ui:widget"]||(r[i]=Object.assign(Object.assign({},r[i]),{"ui:widget":"updown"}))}),r};function v(e,t){switch(t){case"string":return e;case"object":try{return typeof e=="object"&&e!=null?e:JSON.parse(e)}catch(r){return null}case"array":try{return Array.isArray(e)?e:JSON.parse(e)}catch(r){return null}case"number":return parseFloat(e);case"integer":return parseInt(e);case"boolean":return e=="true"||e=="1";default:return e}}function H(e,t){return Object.keys(t).reduce((r,n)=>{let i=t[n],o=O(n),s=e==null?void 0:e.properties[o],c=s==null?void 0:s.type,d=v(i,c);return d!=null&&!n.startsWith("data-attribute")&&!["class","id","contenteditable"].includes(n)?Object.assign(Object.assign({},r),{[o]:d}):r},{})}function _(e,t){return Object.assign(Object.assign({},I(e)),H(e,t))}function I(e){return Object.keys(e.properties).reduce((t,r)=>{var n,i;return((n=e.properties[r])===null||n===void 0?void 0:n.default)!=null?Object.assign(Object.assign({},t),{[r]:(i=e.properties[r])===null||i===void 0?void 0:i.default}):t},{})}var j=typeof window!="undefined"?window.BYOCDatasources||(window.BYOCDatasources={}):{};function D(e,t){if(typeof e!="function")throw new Error("The first argument of registerDatasource must be a function returning DataSettings or Promise of data");if(!t.id)throw new Error("Missing 'id' property in input");if(!/^[a-zA-Z0-9-_]+$/.test(t.id))throw new Error("Invalid 'id' property in input. 'id' should only contain alphanumeric characters, hyphens, and underscores.");if(W(t.id))throw new Error(`Datasource with id ${t.id} already registered`);j[t.id]=Object.assign(Object.assign({},B(t)),{handler:e}),A()}function W(e){return j[e]}function B(e){let{id:t,name:r,title:n,properties:i,sample:o,schema:s,description:c=null,type:d="object"}=e;return{id:t,description:c,sample:o,name:r||n||t,handler:u=>u,schema:s||i?h(Object.assign(Object.assign({},s||{properties:i,type:d}),{title:(s==null?void 0:s.title)||n||r})):void 0}}var P;function A(){clearTimeout(P),P=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-datasources",data:Object.values(j)}),"*"))},30)}A();function G(e,t){let r=j[e];return r!=null&&r.handler?r.handler(t):t}var N=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};function U(e,t,r){let{thumbnail:n="https://feaasstatic.blob.core.windows.net/assets/thumbnails/byoc.svg",name:i,id:o=e.name,group:s=null,ui:c,isHidden:d=!1,datasourceIds:u=[],links:g={},uiSchema:p,schema:l}=e,a=N(e,["thumbnail","name","id","group","ui","isHidden","datasourceIds","links","uiSchema","schema"]),f=l||a||{},C=p||c||{},m=h(Object.assign(Object.assign({description:"External component"},f),{type:"object"}),r),M=E(C,m.properties||{});return{component:t||(()=>null),name:i,schema:m,uiSchema:M,thumbnail:n,group:s||"Default collection",isHidden:d,id:o,datasourceIds:u,links:g,title:(m==null?void 0:m.title)||(a==null?void 0:a.title)||i}}var J,k=typeof HTMLElement!="undefined"?HTMLElement:typeof windowJSDOM!="undefined"?windowJSDOM.HTMLElement:class{setAttribute(){}},y=typeof window!="undefined"?window.BYOCComponents||(window.BYOCComponents={}):{};function q(e,t,r={}){if(!(t!=null&&t.name))throw new Error("Could not register external component. Please make sure you provide a name in the options"+JSON.stringify(t));let n=U(t,e,r);y[n.id]=n,z(e)&&w.register("byoc-"+b(t.name),void 0,e),K()}function z(e){return e&&"prototype"in e&&"setAttribute"in e.prototype}function L(e,t={}){var r;let n=(r=T(e))===null||r===void 0?void 0:r.schema;return n?_(n,t):t}function re(e){let t=T(e);return Object.keys((t==null?void 0:t.schema.properties)||{}).filter(r=>{var n,i;return((i=(n=t==null?void 0:t.uiSchema)===null||n===void 0?void 0:n[r])===null||i===void 0?void 0:i["ui:widget"])!="hidden"})}function T(e){if(typeof e!="string"){if(e&&"schema"in e)return e;throw new Error(`Component name should be a string, got ${typeof e}`)}let[t,r]=e.split("?");var n=y[t];if(r){let i=y[e];if(!i&&!n)return null;i&&(n=Object.assign(Object.assign(Object.assign({},n),i),{component:i.component||(n==null?void 0:n.component)})),r.split(/\&/g).forEach(o=>{var s,c,d;let[u,g]=o.split("="),p=((s=n.schema.properties)===null||s===void 0?void 0:s[u])||{type:"string"};n=Object.assign(Object.assign({},n),{schema:Object.assign(Object.assign({},n.schema),{properties:Object.assign(Object.assign({},n.schema.properties),{[u]:Object.assign(Object.assign({},p),{default:v(decodeURIComponent(g),p.type)})})}),uiSchema:Object.assign(Object.assign({},n.uiSchema),{[u]:Object.assign(Object.assign({},n.uiSchema[u]),{"ui:widget":(d=(c=n.uiSchema[u])===null||c===void 0?void 0:c["ui:widget"])!==null&&d!==void 0?d:"hidden"})})})})}return n}function ne(e){let{componentName:t,className:r,fallbackWrapper:n,fallback:i,suppressHydrationWarning:o,_dynamic:s,datasources:c}=e,d=N(e,["componentName","className","fallbackWrapper","fallback","suppressHydrationWarning","_dynamic","datasources"]);try{var u=typeof c=="string"?JSON.parse(c):c}catch(a){}let g=Object.values(u||{}).find(a=>a&&!Array.isArray(a)&&Object.keys(a).length>0),p=Object.assign(Object.assign(Object.assign({},g),L(t,Object.assign(Object.assign({},g),d))),u?{datasources:u}:{}),l=Object.assign(Object.assign({"data-external-id":t},S(p)),{suppressHydrationWarning:!0,class:r});return R.forEach(a=>{Object.assign(l,{[b(a)]:x[a]})}),Object.keys(l).forEach(a=>{let f=l[a];if(f&&typeof f=="object"&&a!="class"&&a!="children")try{Object.assign(l,{[a]:JSON.stringify(f)})}catch(C){delete l[a]}(typeof f=="function"||f==null)&&delete l[a]}),{attributes:l,properties:p,merged:Object.assign(Object.assign({},x),p)}}function K(){clearTimeout(J),J=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-components",data:Object.values(y)}),"*"))},30)}K();var w=class extends k{connectedCallback(){try{JSON.parse(String(this.getAttribute("components"))).forEach(t=>{q(null,t)}),JSON.parse(String(this.getAttribute("datasources"))).forEach(t=>{D(r=>r,t)})}catch(t){}}static register(t,r,n=this){r==null&&(r=typeof window!="undefined"?window:void 0),r&&!r.customElements.get(t)&&r.customElements.define(t,class extends n{})}},x={};function ie(e){x=e}var R=["sitecoreEdgeUrl","sitecoreEdgeContextId"];w.register("byoc-registration");export{w as BYOCRegistration,k as WebComponent,x as contextProperties,G as customizeDataSettings,T as getComponent,re as getComponentConfigurablePropertyNames,L as getComponentProperties,W as getDatasource,ne as getMergedComponentProperties,I as getSchemaDefaults,_ as getSchemaProperties,z as isWebComponent,U as normalizeOptions,Y as objectKeysToCamelCase,S as objectKeysToKebabCase,H as parseSchemaProperties,v as parseValue,q as registerComponent,D as registerDatasource,y as registered,j as registeredDatasources,R as serializedContextProperties,ie as setContextProperties,K as setRegistrationCallback,O as toCamelCase,b as toKebabCase,h as transformSchema,E as transformUiSchema}; | ||
var S=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[b(r)]:e[r]}),{}),Y=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[O(r)]:e[r]}),{});function b(e){let t=/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;return O(e).replace(t,function(r){return"-"+r.toLowerCase()})}function O(e){return e=e.replace(/[-_ ]+/g," "),e=e.charAt(0).toLowerCase()+e.slice(1),e.split(/\s+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join("")}function h(e,t={}){let r=e.properties||{},n=e.required||[];return Object.assign(Object.assign({type:"object"},e),{required:n,properties:Object.keys(r).reduce((i,o)=>{let s=Object.assign(Object.assign({},r[o]),{default:t.hasOwnProperty(o)?t[o]:r[o].default,title:r[o].title||b(o).split("-").map(c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()).join(" ")});return s.default===void 0&&delete s.default,"required"in s&&typeof s.required=="boolean"&&(n.indexOf(o)==-1&&n.push(o),delete s.required),Object.assign(i,{[o]:s})},{})})}var E=(e,t)=>{let r=Object.assign({},e);return Object.keys(t).filter(i=>/(integer|number)/.test(t[i].type)).forEach(i=>{var o;!((o=r[i])===null||o===void 0)&&o["ui:widget"]||(r[i]=Object.assign(Object.assign({},r[i]),{"ui:widget":"updown"}))}),r};function v(e,t){switch(t){case"string":return e;case"object":try{return typeof e=="object"&&e!=null?e:JSON.parse(e)}catch(r){return null}case"array":try{return Array.isArray(e)?e:JSON.parse(e)}catch(r){return null}case"number":return parseFloat(e);case"integer":return parseInt(e);case"boolean":return e=="true"||e=="1";default:return e}}function H(e,t){return Object.keys(t).reduce((r,n)=>{let i=t[n],o=O(n),s=e==null?void 0:e.properties[o],c=s==null?void 0:s.type,d=v(i,c);return d!=null&&!n.startsWith("data-attribute")&&!["class","id","contenteditable"].includes(n)?Object.assign(Object.assign({},r),{[o]:d}):r},{})}function _(e,t){return Object.assign(Object.assign({},I(e)),H(e,t))}function I(e){return Object.keys(e.properties).reduce((t,r)=>{var n,i;return((n=e.properties[r])===null||n===void 0?void 0:n.default)!=null?Object.assign(Object.assign({},t),{[r]:(i=e.properties[r])===null||i===void 0?void 0:i.default}):t},{})}var j=typeof window!="undefined"?window.BYOCDatasources||(window.BYOCDatasources={}):{};function D(e,t){var r;if(typeof e!="function")throw new Error("The first argument of registerDatasource must be a function returning DataSettings or Promise of data");if(!t.id)throw new Error("Missing 'id' property in input");if(!/^[a-zA-Z0-9-_]+$/.test(t.id))throw new Error("Invalid 'id' property in input. 'id' should only contain alphanumeric characters, hyphens, and underscores.");if(((r=W(t.id))===null||r===void 0?void 0:r.handler)!=null)throw new Error(`Datasource with id ${t.id} already registered`);j[t.id]=Object.assign(Object.assign({},B(t)),{handler:e}),A()}function W(e){return j[e]}function B(e){let{id:t,name:r,title:n,properties:i,sample:o,schema:s,description:c=null,type:d="object"}=e;return{id:t,description:c,sample:o,name:r||n||t,handler:u=>u,schema:s||i?h(Object.assign(Object.assign({},s||{properties:i,type:d}),{title:(s==null?void 0:s.title)||n||r})):void 0}}var P;function A(){clearTimeout(P),P=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-datasources",data:Object.values(j)}),"*"))},30)}A();function G(e,t){let r=j[e];return r!=null&&r.handler?r.handler(t):t}var N=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};function U(e,t,r){let{thumbnail:n="https://feaasstatic.blob.core.windows.net/assets/thumbnails/byoc.svg",name:i,id:o=e.name,group:s=null,ui:c,isHidden:d=!1,datasourceIds:u=[],links:g={},uiSchema:p,schema:l}=e,a=N(e,["thumbnail","name","id","group","ui","isHidden","datasourceIds","links","uiSchema","schema"]),f=l||a||{},C=p||c||{},m=h(Object.assign(Object.assign({description:"External component"},f),{type:"object"}),r),M=E(C,m.properties||{});return{component:t||(()=>null),name:i,schema:m,uiSchema:M,thumbnail:n,group:s||"Default collection",isHidden:d,id:o,datasourceIds:u,links:g,title:(m==null?void 0:m.title)||(a==null?void 0:a.title)||i}}var J,k=typeof HTMLElement!="undefined"?HTMLElement:typeof windowJSDOM!="undefined"?windowJSDOM.HTMLElement:class{setAttribute(){}},y=typeof window!="undefined"?window.BYOCComponents||(window.BYOCComponents={}):{};function q(e,t,r={}){if(!(t!=null&&t.name))throw new Error("Could not register external component. Please make sure you provide a name in the options"+JSON.stringify(t));let n=U(t,e,r);y[n.id]=n,z(e)&&w.register("byoc-"+b(t.name),void 0,e),K()}function z(e){return e&&"prototype"in e&&"setAttribute"in e.prototype}function L(e,t={}){var r;let n=(r=T(e))===null||r===void 0?void 0:r.schema;return n?_(n,t):t}function re(e){let t=T(e);return Object.keys((t==null?void 0:t.schema.properties)||{}).filter(r=>{var n,i;return((i=(n=t==null?void 0:t.uiSchema)===null||n===void 0?void 0:n[r])===null||i===void 0?void 0:i["ui:widget"])!="hidden"})}function T(e){if(typeof e!="string"){if(e&&"schema"in e)return e;throw new Error(`Component name should be a string, got ${typeof e}`)}let[t,r]=e.split("?");var n=y[t];if(r){let i=y[e];if(!i&&!n)return null;i&&(n=Object.assign(Object.assign(Object.assign({},n),i),{component:i.component||(n==null?void 0:n.component)})),r.split(/\&/g).forEach(o=>{var s,c,d;let[u,g]=o.split("="),p=((s=n.schema.properties)===null||s===void 0?void 0:s[u])||{type:"string"};n=Object.assign(Object.assign({},n),{schema:Object.assign(Object.assign({},n.schema),{properties:Object.assign(Object.assign({},n.schema.properties),{[u]:Object.assign(Object.assign({},p),{default:v(decodeURIComponent(g),p.type)})})}),uiSchema:Object.assign(Object.assign({},n.uiSchema),{[u]:Object.assign(Object.assign({},n.uiSchema[u]),{"ui:widget":(d=(c=n.uiSchema[u])===null||c===void 0?void 0:c["ui:widget"])!==null&&d!==void 0?d:"hidden"})})})})}return n}function ne(e){let{componentName:t,className:r,fallbackWrapper:n,fallback:i,suppressHydrationWarning:o,_dynamic:s,datasources:c}=e,d=N(e,["componentName","className","fallbackWrapper","fallback","suppressHydrationWarning","_dynamic","datasources"]);try{var u=typeof c=="string"?JSON.parse(c):c}catch(a){}let g=Object.values(u||{}).find(a=>a&&!Array.isArray(a)&&Object.keys(a).length>0),p=Object.assign(Object.assign(Object.assign({},g),L(t,Object.assign(Object.assign({},g),d))),u?{datasources:u}:{}),l=Object.assign(Object.assign({"data-external-id":t},S(p)),{suppressHydrationWarning:!0,class:r});return R.forEach(a=>{Object.assign(l,{[b(a)]:x[a]})}),Object.keys(l).forEach(a=>{let f=l[a];if(f&&typeof f=="object"&&a!="class"&&a!="children")try{Object.assign(l,{[a]:JSON.stringify(f)})}catch(C){delete l[a]}(typeof f=="function"||f==null)&&delete l[a]}),{attributes:l,properties:p,merged:Object.assign(Object.assign({},x),p)}}function K(){clearTimeout(J),J=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-components",data:Object.values(y)}),"*"))},30)}K();var w=class extends k{connectedCallback(){try{JSON.parse(String(this.getAttribute("components"))).forEach(t=>{q(null,t)}),JSON.parse(String(this.getAttribute("datasources"))).forEach(t=>{D(r=>r,t)})}catch(t){}}static register(t,r,n=this){r==null&&(r=typeof window!="undefined"?window:void 0),r&&!r.customElements.get(t)&&r.customElements.define(t,class extends n{})}},x={};function ie(e){x=e}var R=["sitecoreEdgeUrl","sitecoreEdgeContextId"];w.register("byoc-registration");export{w as BYOCRegistration,k as WebComponent,x as contextProperties,G as customizeDataSettings,T as getComponent,re as getComponentConfigurablePropertyNames,L as getComponentProperties,W as getDatasource,ne as getMergedComponentProperties,I as getSchemaDefaults,_ as getSchemaProperties,z as isWebComponent,U as normalizeOptions,Y as objectKeysToCamelCase,S as objectKeysToKebabCase,H as parseSchemaProperties,v as parseValue,q as registerComponent,D as registerDatasource,y as registered,j as registeredDatasources,R as serializedContextProperties,ie as setContextProperties,K as setRegistrationCallback,O as toCamelCase,b as toKebabCase,h as transformSchema,E as transformUiSchema}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var S=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[b(r)]:e[r]}),{}),Y=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[O(r)]:e[r]}),{});function b(e){let t=/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;return O(e).replace(t,function(r){return"-"+r.toLowerCase()})}function O(e){return e=e.replace(/[-_ ]+/g," "),e=e.charAt(0).toLowerCase()+e.slice(1),e.split(/\s+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join("")}function h(e,t={}){let r=e.properties||{},n=e.required||[];return Object.assign(Object.assign({type:"object"},e),{required:n,properties:Object.keys(r).reduce((i,o)=>{let s=Object.assign(Object.assign({},r[o]),{default:t.hasOwnProperty(o)?t[o]:r[o].default,title:r[o].title||b(o).split("-").map(c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()).join(" ")});return s.default===void 0&&delete s.default,"required"in s&&typeof s.required=="boolean"&&(n.indexOf(o)==-1&&n.push(o),delete s.required),Object.assign(i,{[o]:s})},{})})}var E=(e,t)=>{let r=Object.assign({},e);return Object.keys(t).filter(i=>/(integer|number)/.test(t[i].type)).forEach(i=>{var o;!((o=r[i])===null||o===void 0)&&o["ui:widget"]||(r[i]=Object.assign(Object.assign({},r[i]),{"ui:widget":"updown"}))}),r};function v(e,t){switch(t){case"string":return e;case"object":try{return typeof e=="object"&&e!=null?e:JSON.parse(e)}catch(r){return null}case"array":try{return Array.isArray(e)?e:JSON.parse(e)}catch(r){return null}case"number":return parseFloat(e);case"integer":return parseInt(e);case"boolean":return e=="true"||e=="1";default:return e}}function H(e,t){return Object.keys(t).reduce((r,n)=>{let i=t[n],o=O(n),s=e==null?void 0:e.properties[o],c=s==null?void 0:s.type,d=v(i,c);return d!=null&&!n.startsWith("data-attribute")&&!["class","id","contenteditable"].includes(n)?Object.assign(Object.assign({},r),{[o]:d}):r},{})}function _(e,t){return Object.assign(Object.assign({},I(e)),H(e,t))}function I(e){return Object.keys(e.properties).reduce((t,r)=>{var n,i;return((n=e.properties[r])===null||n===void 0?void 0:n.default)!=null?Object.assign(Object.assign({},t),{[r]:(i=e.properties[r])===null||i===void 0?void 0:i.default}):t},{})}var j=typeof window!="undefined"?window.BYOCDatasources||(window.BYOCDatasources={}):{};function D(e,t){if(typeof e!="function")throw new Error("The first argument of registerDatasource must be a function returning DataSettings or Promise of data");if(!t.id)throw new Error("Missing 'id' property in input");if(!/^[a-zA-Z0-9-_]+$/.test(t.id))throw new Error("Invalid 'id' property in input. 'id' should only contain alphanumeric characters, hyphens, and underscores.");if(W(t.id))throw new Error(`Datasource with id ${t.id} already registered`);j[t.id]=Object.assign(Object.assign({},B(t)),{handler:e}),A()}function W(e){return j[e]}function B(e){let{id:t,name:r,title:n,properties:i,sample:o,schema:s,description:c=null,type:d="object"}=e;return{id:t,description:c,sample:o,name:r||n||t,handler:u=>u,schema:s||i?h(Object.assign(Object.assign({},s||{properties:i,type:d}),{title:(s==null?void 0:s.title)||n||r})):void 0}}var P;function A(){clearTimeout(P),P=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-datasources",data:Object.values(j)}),"*"))},30)}A();function G(e,t){let r=j[e];return r!=null&&r.handler?r.handler(t):t}var N=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};function U(e,t,r){let{thumbnail:n="https://feaasstatic.blob.core.windows.net/assets/thumbnails/byoc.svg",name:i,id:o=e.name,group:s=null,ui:c,isHidden:d=!1,datasourceIds:u=[],links:g={},uiSchema:p,schema:l}=e,a=N(e,["thumbnail","name","id","group","ui","isHidden","datasourceIds","links","uiSchema","schema"]),f=l||a||{},C=p||c||{},m=h(Object.assign(Object.assign({description:"External component"},f),{type:"object"}),r),M=E(C,m.properties||{});return{component:t||(()=>null),name:i,schema:m,uiSchema:M,thumbnail:n,group:s||"Default collection",isHidden:d,id:o,datasourceIds:u,links:g,title:(m==null?void 0:m.title)||(a==null?void 0:a.title)||i}}var J,k=typeof HTMLElement!="undefined"?HTMLElement:typeof windowJSDOM!="undefined"?windowJSDOM.HTMLElement:class{setAttribute(){}},y=typeof window!="undefined"?window.BYOCComponents||(window.BYOCComponents={}):{};function q(e,t,r={}){if(!(t!=null&&t.name))throw new Error("Could not register external component. Please make sure you provide a name in the options"+JSON.stringify(t));let n=U(t,e,r);y[n.id]=n,z(e)&&w.register("byoc-"+b(t.name),void 0,e),K()}function z(e){return e&&"prototype"in e&&"setAttribute"in e.prototype}function L(e,t={}){var r;let n=(r=T(e))===null||r===void 0?void 0:r.schema;return n?_(n,t):t}function re(e){let t=T(e);return Object.keys((t==null?void 0:t.schema.properties)||{}).filter(r=>{var n,i;return((i=(n=t==null?void 0:t.uiSchema)===null||n===void 0?void 0:n[r])===null||i===void 0?void 0:i["ui:widget"])!="hidden"})}function T(e){if(typeof e!="string"){if(e&&"schema"in e)return e;throw new Error(`Component name should be a string, got ${typeof e}`)}let[t,r]=e.split("?");var n=y[t];if(r){let i=y[e];if(!i&&!n)return null;i&&(n=Object.assign(Object.assign(Object.assign({},n),i),{component:i.component||(n==null?void 0:n.component)})),r.split(/\&/g).forEach(o=>{var s,c,d;let[u,g]=o.split("="),p=((s=n.schema.properties)===null||s===void 0?void 0:s[u])||{type:"string"};n=Object.assign(Object.assign({},n),{schema:Object.assign(Object.assign({},n.schema),{properties:Object.assign(Object.assign({},n.schema.properties),{[u]:Object.assign(Object.assign({},p),{default:v(decodeURIComponent(g),p.type)})})}),uiSchema:Object.assign(Object.assign({},n.uiSchema),{[u]:Object.assign(Object.assign({},n.uiSchema[u]),{"ui:widget":(d=(c=n.uiSchema[u])===null||c===void 0?void 0:c["ui:widget"])!==null&&d!==void 0?d:"hidden"})})})})}return n}function ne(e){let{componentName:t,className:r,fallbackWrapper:n,fallback:i,suppressHydrationWarning:o,_dynamic:s,datasources:c}=e,d=N(e,["componentName","className","fallbackWrapper","fallback","suppressHydrationWarning","_dynamic","datasources"]);try{var u=typeof c=="string"?JSON.parse(c):c}catch(a){}let g=Object.values(u||{}).find(a=>a&&!Array.isArray(a)&&Object.keys(a).length>0),p=Object.assign(Object.assign(Object.assign({},g),L(t,Object.assign(Object.assign({},g),d))),u?{datasources:u}:{}),l=Object.assign(Object.assign({"data-external-id":t},S(p)),{suppressHydrationWarning:!0,class:r});return R.forEach(a=>{Object.assign(l,{[b(a)]:x[a]})}),Object.keys(l).forEach(a=>{let f=l[a];if(f&&typeof f=="object"&&a!="class"&&a!="children")try{Object.assign(l,{[a]:JSON.stringify(f)})}catch(C){delete l[a]}(typeof f=="function"||f==null)&&delete l[a]}),{attributes:l,properties:p,merged:Object.assign(Object.assign({},x),p)}}function K(){clearTimeout(J),J=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-components",data:Object.values(y)}),"*"))},30)}K();var w=class extends k{connectedCallback(){try{JSON.parse(String(this.getAttribute("components"))).forEach(t=>{q(null,t)}),JSON.parse(String(this.getAttribute("datasources"))).forEach(t=>{D(r=>r,t)})}catch(t){}}static register(t,r,n=this){r==null&&(r=typeof window!="undefined"?window:void 0),r&&!r.customElements.get(t)&&r.customElements.define(t,class extends n{})}},x={};function ie(e){x=e}var R=["sitecoreEdgeUrl","sitecoreEdgeContextId"];w.register("byoc-registration");export{w as BYOCRegistration,k as WebComponent,x as contextProperties,G as customizeDataSettings,T as getComponent,re as getComponentConfigurablePropertyNames,L as getComponentProperties,W as getDatasource,ne as getMergedComponentProperties,I as getSchemaDefaults,_ as getSchemaProperties,z as isWebComponent,U as normalizeOptions,Y as objectKeysToCamelCase,S as objectKeysToKebabCase,H as parseSchemaProperties,v as parseValue,q as registerComponent,D as registerDatasource,y as registered,j as registeredDatasources,R as serializedContextProperties,ie as setContextProperties,K as setRegistrationCallback,O as toCamelCase,b as toKebabCase,h as transformSchema,E as transformUiSchema}; | ||
var S=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[b(r)]:e[r]}),{}),Y=(e={})=>Object.keys(e).reduce((t,r)=>Object.assign(t,{[O(r)]:e[r]}),{});function b(e){let t=/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;return O(e).replace(t,function(r){return"-"+r.toLowerCase()})}function O(e){return e=e.replace(/[-_ ]+/g," "),e=e.charAt(0).toLowerCase()+e.slice(1),e.split(/\s+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join("")}function h(e,t={}){let r=e.properties||{},n=e.required||[];return Object.assign(Object.assign({type:"object"},e),{required:n,properties:Object.keys(r).reduce((i,o)=>{let s=Object.assign(Object.assign({},r[o]),{default:t.hasOwnProperty(o)?t[o]:r[o].default,title:r[o].title||b(o).split("-").map(c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()).join(" ")});return s.default===void 0&&delete s.default,"required"in s&&typeof s.required=="boolean"&&(n.indexOf(o)==-1&&n.push(o),delete s.required),Object.assign(i,{[o]:s})},{})})}var E=(e,t)=>{let r=Object.assign({},e);return Object.keys(t).filter(i=>/(integer|number)/.test(t[i].type)).forEach(i=>{var o;!((o=r[i])===null||o===void 0)&&o["ui:widget"]||(r[i]=Object.assign(Object.assign({},r[i]),{"ui:widget":"updown"}))}),r};function v(e,t){switch(t){case"string":return e;case"object":try{return typeof e=="object"&&e!=null?e:JSON.parse(e)}catch(r){return null}case"array":try{return Array.isArray(e)?e:JSON.parse(e)}catch(r){return null}case"number":return parseFloat(e);case"integer":return parseInt(e);case"boolean":return e=="true"||e=="1";default:return e}}function H(e,t){return Object.keys(t).reduce((r,n)=>{let i=t[n],o=O(n),s=e==null?void 0:e.properties[o],c=s==null?void 0:s.type,d=v(i,c);return d!=null&&!n.startsWith("data-attribute")&&!["class","id","contenteditable"].includes(n)?Object.assign(Object.assign({},r),{[o]:d}):r},{})}function _(e,t){return Object.assign(Object.assign({},I(e)),H(e,t))}function I(e){return Object.keys(e.properties).reduce((t,r)=>{var n,i;return((n=e.properties[r])===null||n===void 0?void 0:n.default)!=null?Object.assign(Object.assign({},t),{[r]:(i=e.properties[r])===null||i===void 0?void 0:i.default}):t},{})}var j=typeof window!="undefined"?window.BYOCDatasources||(window.BYOCDatasources={}):{};function D(e,t){var r;if(typeof e!="function")throw new Error("The first argument of registerDatasource must be a function returning DataSettings or Promise of data");if(!t.id)throw new Error("Missing 'id' property in input");if(!/^[a-zA-Z0-9-_]+$/.test(t.id))throw new Error("Invalid 'id' property in input. 'id' should only contain alphanumeric characters, hyphens, and underscores.");if(((r=W(t.id))===null||r===void 0?void 0:r.handler)!=null)throw new Error(`Datasource with id ${t.id} already registered`);j[t.id]=Object.assign(Object.assign({},B(t)),{handler:e}),A()}function W(e){return j[e]}function B(e){let{id:t,name:r,title:n,properties:i,sample:o,schema:s,description:c=null,type:d="object"}=e;return{id:t,description:c,sample:o,name:r||n||t,handler:u=>u,schema:s||i?h(Object.assign(Object.assign({},s||{properties:i,type:d}),{title:(s==null?void 0:s.title)||n||r})):void 0}}var P;function A(){clearTimeout(P),P=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-datasources",data:Object.values(j)}),"*"))},30)}A();function G(e,t){let r=j[e];return r!=null&&r.handler?r.handler(t):t}var N=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};function U(e,t,r){let{thumbnail:n="https://feaasstatic.blob.core.windows.net/assets/thumbnails/byoc.svg",name:i,id:o=e.name,group:s=null,ui:c,isHidden:d=!1,datasourceIds:u=[],links:g={},uiSchema:p,schema:l}=e,a=N(e,["thumbnail","name","id","group","ui","isHidden","datasourceIds","links","uiSchema","schema"]),f=l||a||{},C=p||c||{},m=h(Object.assign(Object.assign({description:"External component"},f),{type:"object"}),r),M=E(C,m.properties||{});return{component:t||(()=>null),name:i,schema:m,uiSchema:M,thumbnail:n,group:s||"Default collection",isHidden:d,id:o,datasourceIds:u,links:g,title:(m==null?void 0:m.title)||(a==null?void 0:a.title)||i}}var J,k=typeof HTMLElement!="undefined"?HTMLElement:typeof windowJSDOM!="undefined"?windowJSDOM.HTMLElement:class{setAttribute(){}},y=typeof window!="undefined"?window.BYOCComponents||(window.BYOCComponents={}):{};function q(e,t,r={}){if(!(t!=null&&t.name))throw new Error("Could not register external component. Please make sure you provide a name in the options"+JSON.stringify(t));let n=U(t,e,r);y[n.id]=n,z(e)&&w.register("byoc-"+b(t.name),void 0,e),K()}function z(e){return e&&"prototype"in e&&"setAttribute"in e.prototype}function L(e,t={}){var r;let n=(r=T(e))===null||r===void 0?void 0:r.schema;return n?_(n,t):t}function re(e){let t=T(e);return Object.keys((t==null?void 0:t.schema.properties)||{}).filter(r=>{var n,i;return((i=(n=t==null?void 0:t.uiSchema)===null||n===void 0?void 0:n[r])===null||i===void 0?void 0:i["ui:widget"])!="hidden"})}function T(e){if(typeof e!="string"){if(e&&"schema"in e)return e;throw new Error(`Component name should be a string, got ${typeof e}`)}let[t,r]=e.split("?");var n=y[t];if(r){let i=y[e];if(!i&&!n)return null;i&&(n=Object.assign(Object.assign(Object.assign({},n),i),{component:i.component||(n==null?void 0:n.component)})),r.split(/\&/g).forEach(o=>{var s,c,d;let[u,g]=o.split("="),p=((s=n.schema.properties)===null||s===void 0?void 0:s[u])||{type:"string"};n=Object.assign(Object.assign({},n),{schema:Object.assign(Object.assign({},n.schema),{properties:Object.assign(Object.assign({},n.schema.properties),{[u]:Object.assign(Object.assign({},p),{default:v(decodeURIComponent(g),p.type)})})}),uiSchema:Object.assign(Object.assign({},n.uiSchema),{[u]:Object.assign(Object.assign({},n.uiSchema[u]),{"ui:widget":(d=(c=n.uiSchema[u])===null||c===void 0?void 0:c["ui:widget"])!==null&&d!==void 0?d:"hidden"})})})})}return n}function ne(e){let{componentName:t,className:r,fallbackWrapper:n,fallback:i,suppressHydrationWarning:o,_dynamic:s,datasources:c}=e,d=N(e,["componentName","className","fallbackWrapper","fallback","suppressHydrationWarning","_dynamic","datasources"]);try{var u=typeof c=="string"?JSON.parse(c):c}catch(a){}let g=Object.values(u||{}).find(a=>a&&!Array.isArray(a)&&Object.keys(a).length>0),p=Object.assign(Object.assign(Object.assign({},g),L(t,Object.assign(Object.assign({},g),d))),u?{datasources:u}:{}),l=Object.assign(Object.assign({"data-external-id":t},S(p)),{suppressHydrationWarning:!0,class:r});return R.forEach(a=>{Object.assign(l,{[b(a)]:x[a]})}),Object.keys(l).forEach(a=>{let f=l[a];if(f&&typeof f=="object"&&a!="class"&&a!="children")try{Object.assign(l,{[a]:JSON.stringify(f)})}catch(C){delete l[a]}(typeof f=="function"||f==null)&&delete l[a]}),{attributes:l,properties:p,merged:Object.assign(Object.assign({},x),p)}}function K(){clearTimeout(J),J=setTimeout(()=>{var e;typeof window!="undefined"&&window.parent!==window&&((e=window.parent)===null||e===void 0||e.postMessage(JSON.stringify({action:"register-components",data:Object.values(y)}),"*"))},30)}K();var w=class extends k{connectedCallback(){try{JSON.parse(String(this.getAttribute("components"))).forEach(t=>{q(null,t)}),JSON.parse(String(this.getAttribute("datasources"))).forEach(t=>{D(r=>r,t)})}catch(t){}}static register(t,r,n=this){r==null&&(r=typeof window!="undefined"?window:void 0),r&&!r.customElements.get(t)&&r.customElements.define(t,class extends n{})}},x={};function ie(e){x=e}var R=["sitecoreEdgeUrl","sitecoreEdgeContextId"];w.register("byoc-registration");export{w as BYOCRegistration,k as WebComponent,x as contextProperties,G as customizeDataSettings,T as getComponent,re as getComponentConfigurablePropertyNames,L as getComponentProperties,W as getDatasource,ne as getMergedComponentProperties,I as getSchemaDefaults,_ as getSchemaProperties,z as isWebComponent,U as normalizeOptions,Y as objectKeysToCamelCase,S as objectKeysToKebabCase,H as parseSchemaProperties,v as parseValue,q as registerComponent,D as registerDatasource,y as registered,j as registeredDatasources,R as serializedContextProperties,ie as setContextProperties,K as setRegistrationCallback,O as toCamelCase,b as toKebabCase,h as transformSchema,E as transformUiSchema}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -5,3 +5,3 @@ { | ||
"description": "Bring-Your-Own-Components runtime to register and retrieve react components", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -123,3 +123,3 @@ import { DataSettings } from './lib/types.js' | ||
if (getDatasource(options.id)) { | ||
if (getDatasource(options.id)?.handler != null) { | ||
throw new Error(`Datasource with id ${options.id} already registered`) | ||
@@ -126,0 +126,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
473161
2762