@qoh/core-react 1.0.0-rc.11 → 1.0.0-rc.13
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/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +56 -69
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var M=Object.create;var g=Object.defineProperty,z=Object.defineProperties,B=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors,U=Object.getOwnPropertyNames,O=Object.getOwnPropertySymbols,J=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var q=(t,e,n)=>e in t?g(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,b=(t,e)=>{for(var n in e||(e={}))j.call(e,n)&&q(t,n,e[n]);if(O)for(var n of O(e))N.call(e,n)&&q(t,n,e[n]);return t},E=(t,e)=>z(t,H(e));var X=(t,e)=>{for(var n in e)g(t,n,{get:e[n],enumerable:!0})},R=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of U(e))!j.call(t,i)&&i!==n&&g(t,i,{get:()=>e[i],enumerable:!(r=B(e,i))||r.enumerable});return t};var f=(t,e,n)=>(n=t!=null?M(J(t)):{},R(e||!t||!t.__esModule?g(n,"default",{value:t,enumerable:!0}):n,t)),W=t=>R(g({},"__esModule",{value:!0}),t);var u=(t,e,n)=>new Promise((r,i)=>{var o=c=>{try{s(n.next(c))}catch(y){i(y)}},l=c=>{try{s(n.throw(c))}catch(y){i(y)}},s=c=>c.done?r(c.value):Promise.resolve(c.value).then(o,l);s((n=n.apply(t,e)).next())});var ce={};X(ce,{ApiError:()=>m,DatoCMS:()=>w,Filter:()=>P,QueenofheartsRenderComponent:()=>G,QueenofheartsService:()=>h,StrapiCMS:()=>C,componentRegistry:()=>d,fetchDynamicComponents:()=>ae,getAllregisteredComponents:()=>$,registerComponent:()=>oe,registerLazyComponent:()=>se,unregisterComponent:()=>ie});module.exports=W(ce);var A=require("react");var v=require("react/jsx-runtime");function G(t){let e=h.getInstance(),{data:n,contextProps:r}=t;return n&&e?Array.isArray(n)?(0,v.jsx)(A.Suspense,{fallback:null,children:n.map((i,o)=>e.createComponent({data:i,contextProps:r}))}):(0,v.jsx)(A.Suspense,{fallback:null,children:e.createComponent({data:n,contextProps:r})}):e?(0,v.jsx)("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):(0,v.jsx)("div",{children:"QueenofheartsService is not initialized"})}var m=class extends Error{constructor(e,n){super(n.summary),this.name="ApiError",this.status=e,this.body=n}};var x=f(require("react"));var p=f(require("react"));var a=require("react/jsx-runtime"),V=({children:t,style:e})=>(0,a.jsx)("details",{style:e,children:t}),K=({children:t})=>(0,a.jsx)("summary",{children:t}),Y=({children:t})=>(0,a.jsx)("div",{style:{paddingLeft:"1em"},children:t}),_=({children:t,style:e})=>(0,a.jsx)("div",{style:E(b({},e),{border:"1px solid #ccc",padding:".5em"}),children:t}),Z=()=>(0,a.jsx)("span",{children:"\u25BC"}),D=p.lazy(()=>import("@mui/material/Accordion").catch(()=>({default:V}))),Q=p.lazy(()=>import("@mui/material/AccordionSummary").catch(()=>({default:K}))),k=p.lazy(()=>import("@mui/material/AccordionDetails").catch(()=>({default:Y}))),ee=p.lazy(()=>import("@mui/material/Paper").catch(()=>({default:_}))),F=p.lazy(()=>import("@mui/icons-material/ExpandMore").catch(()=>({default:Z})));function ne(t,e,n){return(0,a.jsxs)(D,{style:{width:"100%"},children:[(0,a.jsxs)(Q,{style:{padding:0},expandIcon:(0,a.jsx)(F,{}),children:[t,": Array[",e.length,"]"]}),(0,a.jsx)(k,{children:e.map((r,i)=>S("",r,i))})]},`${t}_${n}`)}function te(t,e,n){return(0,a.jsxs)(D,{style:{width:"100%"},children:[(0,a.jsx)(Q,{expandIcon:(0,a.jsx)(F,{}),children:t}),(0,a.jsx)(k,{children:Object.entries(e).map((r,i)=>S(r[0],r[1],i))})]},`${t}_${n}`)}function I(t,e,n){return(0,a.jsxs)("div",{children:[t,": ",`${e}`]},`${t}_${n}`)}function S(t,e,n){var i;if(Array.isArray(e))return ne(t,e,n);if(!e||["string","number"].includes(typeof e))return I(t,e,n);if(typeof e=="boolean")return I(t,e?"true":"false",n);let r=`${t?t+": ":""}${(i=e.__typename)!=null?i:"object"}`;return te(r,e,n)}function T(t){return typeof t.data=="object"?(0,a.jsx)(p.Suspense,{fallback:(0,a.jsx)(_,{style:{margin:".5em",width:"calc(100% - 1em)"},children:S("",t.data,1)}),children:(0,a.jsx)(ee,{style:{margin:".5em",width:"calc(100% - 1em)"},children:S("",t.data,1)})}):null}var P=(i=>(i.eq="eq",i.in="in",i.neq="neq",i.notIn="notIn",i))(P||{}),re="https://headless.li/api",d={};function ie(t){delete d[t]}function oe(t,e,n,r){if(e!==void 0&&(r||d[e]===void 0)){let i={component:t,fieldNames:n};d[e]=i}}function se(t,e,n,r=!1){e?(r||d[e]===void 0)&&(d[e]={fieldNames:n,loader:t}):console.warn("registerComponent failed: undefined typeName ")}function $(){return d}var ae=t=>u(null,null,function*(){let e=h.getInstance(),n=e.findComponentsInProps(t).filter((i,o,l)=>l.indexOf(i)===o);return(yield e.fetchDynamicComponents(n)).filter(i=>i!==null)}),h=class t{constructor(e,n){this.latestUrl="";this.latestData={};this.findComponentsInProps=e=>{if(e&&typeof e!="string"){let n=e.__typename?[e.__typename]:[],r=Array.isArray(e)?e:Object.values(e);return[...n,...r.reduce((o,l)=>{let s=this.findComponentsInProps(l);return s&&(o=[...o,...s]),o},[])]}return[]};this.fetchDynamicComponents=e=>u(this,null,function*(){let n=!1,r=!1,i=Promise.all(e.map(o=>u(this,null,function*(){var l;return d[o]&&d[o].component===void 0?(n=!0,yield this.loadAsyncComponent(o)):(l=d[o])!=null&&l.loader?o:null})));return r=!0,i});this.buildUrl=e=>{var r;return`${(r=this.localServer)!=null?r:re}/${e}`};this.queryGraphql=e=>u(this,null,function*(){let n=this.buildUrl("execGraphqlQuery");if(console.info(`using url : ${n}`),n){let r=yield fetch(n,{method:"POST",headers:{Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({query:e})});if(r.ok){let i=yield r.json();return this.sendDebugEvent(),i}else{let i=yield r.json();throw console.log(i),new m(r.status,i)}}throw new m(500,{id:"99",summary:"queryUrl was not set",details:`LocalServer: ${this.localServer}`})});this.query=(e,n)=>u(this,null,function*(){var o,l;let r=this.buildUrl("execQuery"),i=n!=null&&n.variables?b({},n.variables):{};if(n!=null&&n.locale&&(i.locale=n.locale),n!=null&&n.filter&&Array.isArray(n.filter)&&(i.filter||(i.filter=[]),i.filter.push(...n.filter),(o=n==null?void 0:n.variables)!=null&&o.filter&&Array.isArray(n.variables.filter)&&i.filter.push(...n.variables.filter)),r&&n){let s=yield fetch(r,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiToken}`},method:"POST",credentials:"include",body:JSON.stringify({queryname:e,variables:i,components:this.getRegisteredComponentsWithFields(),ignoreProperties:n.ignoreProperties,depth:n.depth})});if(s.ok){let c=(l=yield s.json())==null?void 0:l.data,y=this.debug?this.injectIds(c):c;return this.latestData=y,this.sendDebugEvent(),y}else try{let c=yield s.json();throw console.log(c),new m(s.status,c)}catch(c){throw new m(s.status,c.toString())}}else throw new m(500,{id:"99",summary:`Query: queryUrl (${r}) or options are invalid`,details:`queryUrl: ${r}`})});this.getRegisteredComponentsWithFields=()=>{let e={},n=Object.entries($());return n&&Array.isArray(n)&&n.forEach(([r,i])=>{let o={},l=i.fieldNames,s=!1;l&&Array.isArray(l)&&l.forEach(c=>{o[c]=!0,s=!0}),s?e[r]=o:e[r]={__all:!0}}),e};this.getQueries=()=>u(this,null,function*(){let e=this.buildUrl("queries");if(e){let n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}});if(n.ok)try{return yield n.json()}catch(r){console.error(r)}}else console.error("api, uri and CMSToken have to be provided");return""});this.apiToken=e,this.localServer=n,this.debug=typeof document!="undefined"&&document.getElementsByTagName("body")[0].classList.contains("qoh-inject-ids"),this.debug&&typeof globalThis.window!="undefined"&&(globalThis.window.addEventListener("QueenOfHearts-RequestData",()=>{this.sendDebugEvent()}),globalThis.window.addEventListener("QueenOfHearts-RequestQueries",()=>{this.sendQueriesEvent()}),globalThis.window.addEventListener("QueenOfHearts-HighlightComponent",(r=>{this.highlightComponent(r.detail)})),globalThis.window.addEventListener("QueenOfHearts-RequestComponentHTML",(r=>{this.sendComponentHTML(r.detail)})))}static init(e,n){t.instance=new t(e,n)}static getInstance(){return t.instance||console.error("QueenofheartsService was not initialized using QueenofheartsService.init(backend, apiToken)"),t.instance}loadAsyncComponent(e){return u(this,null,function*(){let n=d[e];if(n&&n.component===void 0){if(!(n!=null&&n.component)&&n.loader){let r=n.loader,i=yield r();i?d[e].component=i.default:(console.error(`error loading ${e}`),console.error(i))}return e}return null})}createComponent(e){var s;let{data:n,contextProps:r={}}=e,i=n.__typename,o=d[i];o&&o.loader&&(0,x.lazy)(o.loader);let l=(s=o==null?void 0:o.component)!=null?s:T;return x.default.createElement(l,E(b({},n),{contextProps:r}))}injectIds(e){if(Array.isArray(e))e.forEach(n=>this.injectIds(n));else if(e&&typeof e=="object"){if(e.hasOwnProperty("__typename")){let n=Math.random().toString();e.__qohId=n.substr(n.indexOf(".")+1)}Object.keys(e).forEach(n=>e[n]=this.injectIds(e[n]))}return e}sendDebugEvent(){if(typeof window=="undefined")return;let e={registeredComponents:Object.keys(d),url:this.latestUrl,data:this.latestData},n=new CustomEvent("QueenOfHearts-DebuggingData",{detail:e});window.dispatchEvent(n)}sendQueriesEvent(){return u(this,null,function*(){if(typeof window=="undefined")return;let e=new CustomEvent("QueenOfHearts-AvailableQueries",{detail:yield this.getQueries()});window.dispatchEvent(e)})}sendComponentHTML(e){var r;if(typeof window=="undefined")return;let n=(r=document.querySelector(`[qohId='${e}']`))==null?void 0:r.nextElementSibling;if(n){let i=new CustomEvent("QueenOfHearts-SelectedComponentHTML",{detail:{qohId:e,html:n.outerHTML}});window.dispatchEvent(i)}}highlightComponent(e){var o;let n=[{outline:"thick auto white"},{outline:"thick auto red"}],r={duration:1e3,iterations:2},i=(o=document.querySelector(`[qohId='${e}']`))==null?void 0:o.nextElementSibling;i&&i.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),i&&i.animate(n,r)}};var w=class{constructor(e){this.token="";this.uri="https://graphql.datocms.com/";this.token=e}renameSEOMetaTags(e){e.forEach(function(n,r,i){i[r].__typename="SEOMetaTag"})}normalize(e){if(e)return e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(r=>this.normalize(r))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e}};var L=f(require("dotenv"));L.default.config();var C=class{constructor(e,n){this.token="";this.uri="";this.token=e,this.uri=n}renameSEOMetaTags(e){e.forEach(function(n,r,i){i[r].__typename="SEOMetaTag"})}normalize(e){return e&&(e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(r=>this.normalize(r))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e)}};0&&(module.exports={ApiError,DatoCMS,Filter,QueenofheartsRenderComponent,QueenofheartsService,StrapiCMS,componentRegistry,fetchDynamicComponents,getAllregisteredComponents,registerComponent,registerLazyComponent,unregisterComponent});
|
|
1
|
+
"use strict";var A=Object.create;var p=Object.defineProperty,j=Object.defineProperties,Q=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,R=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var E=(i,e,n)=>e in i?p(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,v=(i,e)=>{for(var n in e||(e={}))x.call(e,n)&&E(i,n,e[n]);if(C)for(var n of C(e))k.call(e,n)&&E(i,n,e[n]);return i},T=(i,e)=>j(i,I(e));var D=(i,e)=>{for(var n in e)p(i,n,{get:e[n],enumerable:!0})},S=(i,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of _(e))!x.call(i,r)&&r!==n&&p(i,r,{get:()=>e[r],enumerable:!(t=Q(e,r))||t.enumerable});return i};var M=(i,e,n)=>(n=i!=null?A(R(i)):{},S(e||!i||!i.__esModule?p(n,"default",{value:i,enumerable:!0}):n,i)),P=i=>S(p({},"__esModule",{value:!0}),i);var u=(i,e,n)=>new Promise((t,r)=>{var o=s=>{try{a(n.next(s))}catch(f){r(f)}},c=s=>{try{a(n.throw(s))}catch(f){r(f)}},a=s=>s.done?t(s.value):Promise.resolve(s.value).then(o,c);a((n=n.apply(i,e)).next())});var $={};D($,{ApiError:()=>d,DatoCMS:()=>g,Filter:()=>q,QueenofheartsRenderComponent:()=>L,QueenofheartsService:()=>m,StrapiCMS:()=>y,componentRegistry:()=>l,fetchDynamicComponents:()=>z,getAllregisteredComponents:()=>O,registerComponent:()=>H,registerLazyComponent:()=>U,unregisterComponent:()=>B});module.exports=P($);var w=require("react");var h=require("react/jsx-runtime");function L(i){let e=m.getInstance(),{data:n,contextProps:t}=i;return n&&e?Array.isArray(n)?(0,h.jsx)(w.Suspense,{fallback:null,children:n.map((r,o)=>e.createComponent({data:r,contextProps:t}))}):(0,h.jsx)(w.Suspense,{fallback:null,children:e.createComponent({data:n,contextProps:t})}):e?(0,h.jsx)("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):(0,h.jsx)("div",{children:"QueenofheartsService is not initialized"})}var d=class extends Error{constructor(e,n){super(n.summary),this.name="ApiError",this.status=e,this.body=n}};var b=M(require("react"));var q=(r=>(r.eq="eq",r.in="in",r.neq="neq",r.notIn="notIn",r))(q||{}),F="https://headless.li/api",l={};function B(i){delete l[i]}function H(i,e,n,t){if(e!==void 0&&(t||l[e]===void 0)){let r={component:i,fieldNames:n};l[e]=r}}function U(i,e,n,t=!1){e?(t||l[e]===void 0)&&(l[e]={fieldNames:n,loader:i}):console.warn("registerComponent failed: undefined typeName ")}function O(){return l}var z=i=>u(null,null,function*(){let e=m.getInstance(),n=e.findComponentsInProps(i).filter((r,o,c)=>c.indexOf(r)===o);return(yield e.fetchDynamicComponents(n)).filter(r=>r!==null)}),m=class i{constructor(e,n){this.latestUrl="";this.latestData={};this.findComponentsInProps=e=>{if(e&&typeof e!="string"){let n=e.__typename?[e.__typename]:[],t=Array.isArray(e)?e:Object.values(e);return[...n,...t.reduce((o,c)=>{let a=this.findComponentsInProps(c);return a&&(o=[...o,...a]),o},[])]}return[]};this.fetchDynamicComponents=e=>u(this,null,function*(){return Promise.all(e.map(t=>u(this,null,function*(){var r;return l[t]&&l[t].component===void 0?yield this.loadAsyncComponent(t):(r=l[t])!=null&&r.loader?t:null})))});this.buildUrl=e=>{var t;return`${(t=this.localServer)!=null?t:F}/${e}`};this.queryGraphql=e=>u(this,null,function*(){let n=this.buildUrl("execGraphqlQuery");if(console.info(`using url : ${n}`),n){let t=yield fetch(n,{method:"POST",headers:{Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({query:e})});if(t.ok){let r=yield t.json();return this.sendDebugEvent(),r}else{let r=yield t.json();throw console.log(r),new d(t.status,r)}}throw new d(500,{id:"99",summary:"queryUrl was not set",details:`LocalServer: ${this.localServer}`})});this.query=(e,n)=>u(this,null,function*(){var o,c;let t=this.buildUrl("execQuery"),r=n!=null&&n.variables?v({},n.variables):{};if(n!=null&&n.locale&&(r.locale=n.locale),n!=null&&n.filter&&Array.isArray(n.filter)&&(r.filter||(r.filter=[]),r.filter.push(...n.filter),(o=n==null?void 0:n.variables)!=null&&o.filter&&Array.isArray(n.variables.filter)&&r.filter.push(...n.variables.filter)),t&&n){let a=yield fetch(t,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiToken}`},method:"POST",credentials:"include",body:JSON.stringify({queryname:e,variables:r,components:this.getRegisteredComponentsWithFields(),ignoreProperties:n.ignoreProperties,depth:n.depth})});if(a.ok){let s=(c=yield a.json())==null?void 0:c.data,f=this.debug?this.injectIds(s):s;return this.latestData=f,this.sendDebugEvent(),f}else try{let s=yield a.json();throw console.log(s),new d(a.status,s)}catch(s){throw new d(a.status,s.toString())}}else throw new d(500,{id:"99",summary:`Query: queryUrl (${t}) or options are invalid`,details:`queryUrl: ${t}`})});this.getRegisteredComponentsWithFields=()=>{let e={},n=Object.entries(O());return n&&Array.isArray(n)&&n.forEach(([t,r])=>{let o={},c=r.fieldNames,a=!1;c&&Array.isArray(c)&&c.forEach(s=>{o[s]=!0,a=!0}),a?e[t]=o:e[t]={__all:!0}}),e};this.getQueries=()=>u(this,null,function*(){let e=this.buildUrl("queries");if(e){let n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}});if(n.ok)try{return yield n.json()}catch(t){console.error(t)}}else console.error("api, uri and CMSToken have to be provided");return""});this.apiToken=e,this.localServer=n,this.debug=typeof document!="undefined"&&document.getElementsByTagName("body")[0].classList.contains("qoh-inject-ids"),this.debug&&typeof globalThis.window!="undefined"&&(globalThis.window.addEventListener("QueenOfHearts-RequestData",()=>{this.sendDebugEvent()}),globalThis.window.addEventListener("QueenOfHearts-RequestQueries",()=>{this.sendQueriesEvent()}),globalThis.window.addEventListener("QueenOfHearts-HighlightComponent",(t=>{this.highlightComponent(t.detail)})),globalThis.window.addEventListener("QueenOfHearts-RequestComponentHTML",(t=>{this.sendComponentHTML(t.detail)})))}static init(e,n){i.instance=new i(e,n)}static getInstance(){return i.instance||console.error("QueenofheartsService was not initialized using QueenofheartsService.init(backend, apiToken)"),i.instance}loadAsyncComponent(e){return u(this,null,function*(){let n=l[e];if(n&&n.component===void 0){if(!(n!=null&&n.component)&&n.loader){let t=n.loader,r=yield t();r?l[e].component=r.default:(console.error(`error loading ${e}`),console.error(r))}return e}return null})}createComponent(e){let{data:n,contextProps:t={}}=e,r=n.__typename,o=l[r];return o&&o.loader&&(0,b.lazy)(o.loader),o!=null&&o.component?b.default.createElement(o.component,T(v({},n),{contextProps:t})):null}injectIds(e){if(Array.isArray(e))e.forEach(n=>this.injectIds(n));else if(e&&typeof e=="object"){if(e.hasOwnProperty("__typename")){let n=Math.random().toString();e.__qohId=n.substring(n.indexOf(".")+1)}Object.keys(e).forEach(n=>e[n]=this.injectIds(e[n]))}return e}sendDebugEvent(){if(typeof window=="undefined")return;let e={registeredComponents:Object.keys(l),url:this.latestUrl,data:this.latestData},n=new CustomEvent("QueenOfHearts-DebuggingData",{detail:e});window.dispatchEvent(n)}sendQueriesEvent(){return u(this,null,function*(){if(typeof window=="undefined")return;let e=new CustomEvent("QueenOfHearts-AvailableQueries",{detail:yield this.getQueries()});window.dispatchEvent(e)})}sendComponentHTML(e){var t;if(typeof window=="undefined")return;let n=(t=document.querySelector(`[qohId='${e}']`))==null?void 0:t.nextElementSibling;if(n){let r=new CustomEvent("QueenOfHearts-SelectedComponentHTML",{detail:{qohId:e,html:n.outerHTML}});window.dispatchEvent(r)}}highlightComponent(e){var o;let n=[{outline:"thick auto white"},{outline:"thick auto red"}],t={duration:1e3,iterations:2},r=(o=document.querySelector(`[qohId='${e}']`))==null?void 0:o.nextElementSibling;r&&r.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),r&&r.animate(n,t)}};var g=class{constructor(e){this.token="";this.uri="https://graphql.datocms.com/";this.token=e}renameSEOMetaTags(e){e.forEach(function(n,t,r){r[t].__typename="SEOMetaTag"})}normalize(e){if(e)return e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(t=>this.normalize(t))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e}};var y=class{constructor(e,n){this.token="";this.uri="";this.token=e,this.uri=n}renameSEOMetaTags(e){e.forEach(function(n,t,r){r[t].__typename="SEOMetaTag"})}normalize(e){return e&&(e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(t=>this.normalize(t))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e)}};0&&(module.exports={ApiError,DatoCMS,Filter,QueenofheartsRenderComponent,QueenofheartsService,StrapiCMS,componentRegistry,fetchDynamicComponents,getAllregisteredComponents,registerComponent,registerLazyComponent,unregisterComponent});
|
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var E=Object.defineProperty,x=Object.defineProperties;var T=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var v=(i,e,n)=>e in i?E(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,y=(i,e)=>{for(var n in e||(e={}))S.call(e,n)&&v(i,n,e[n]);if(b)for(var n of b(e))q.call(e,n)&&v(i,n,e[n]);return i},w=(i,e)=>x(i,T(e));var u=(i,e,n)=>new Promise((t,r)=>{var o=s=>{try{a(n.next(s))}catch(f){r(f)}},l=s=>{try{a(n.throw(s))}catch(f){r(f)}},a=s=>s.done?t(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(i,e)).next())});import{Suspense as C}from"react";import{jsx as p}from"react/jsx-runtime";function M(i){let e=m.getInstance(),{data:n,contextProps:t}=i;return n&&e?Array.isArray(n)?p(C,{fallback:null,children:n.map((r,o)=>e.createComponent({data:r,contextProps:t}))}):p(C,{fallback:null,children:e.createComponent({data:n,contextProps:t})}):e?p("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):p("div",{children:"QueenofheartsService is not initialized"})}var d=class extends Error{constructor(e,n){super(n.summary),this.name="ApiError",this.status=e,this.body=n}};import O,{lazy as A}from"react";var j=(r=>(r.eq="eq",r.in="in",r.neq="neq",r.notIn="notIn",r))(j||{}),Q="https://headless.li/api",c={};function z(i){delete c[i]}function $(i,e,n,t){if(e!==void 0&&(t||c[e]===void 0)){let r={component:i,fieldNames:n};c[e]=r}}function N(i,e,n,t=!1){e?(t||c[e]===void 0)&&(c[e]={fieldNames:n,loader:i}):console.warn("registerComponent failed: undefined typeName ")}function I(){return c}var W=i=>u(null,null,function*(){let e=m.getInstance(),n=e.findComponentsInProps(i).filter((r,o,l)=>l.indexOf(r)===o);return(yield e.fetchDynamicComponents(n)).filter(r=>r!==null)}),m=class i{constructor(e,n){this.latestUrl="";this.latestData={};this.findComponentsInProps=e=>{if(e&&typeof e!="string"){let n=e.__typename?[e.__typename]:[],t=Array.isArray(e)?e:Object.values(e);return[...n,...t.reduce((o,l)=>{let a=this.findComponentsInProps(l);return a&&(o=[...o,...a]),o},[])]}return[]};this.fetchDynamicComponents=e=>u(this,null,function*(){return Promise.all(e.map(t=>u(this,null,function*(){var r;return c[t]&&c[t].component===void 0?yield this.loadAsyncComponent(t):(r=c[t])!=null&&r.loader?t:null})))});this.buildUrl=e=>{var t;return`${(t=this.localServer)!=null?t:Q}/${e}`};this.queryGraphql=e=>u(this,null,function*(){let n=this.buildUrl("execGraphqlQuery");if(console.info(`using url : ${n}`),n){let t=yield fetch(n,{method:"POST",headers:{Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({query:e})});if(t.ok){let r=yield t.json();return this.sendDebugEvent(),r}else{let r=yield t.json();throw console.log(r),new d(t.status,r)}}throw new d(500,{id:"99",summary:"queryUrl was not set",details:`LocalServer: ${this.localServer}`})});this.query=(e,n)=>u(this,null,function*(){var o,l;let t=this.buildUrl("execQuery"),r=n!=null&&n.variables?y({},n.variables):{};if(n!=null&&n.locale&&(r.locale=n.locale),n!=null&&n.filter&&Array.isArray(n.filter)&&(r.filter||(r.filter=[]),r.filter.push(...n.filter),(o=n==null?void 0:n.variables)!=null&&o.filter&&Array.isArray(n.variables.filter)&&r.filter.push(...n.variables.filter)),t&&n){let a=yield fetch(t,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiToken}`},method:"POST",credentials:"include",body:JSON.stringify({queryname:e,variables:r,components:this.getRegisteredComponentsWithFields(),ignoreProperties:n.ignoreProperties,depth:n.depth})});if(a.ok){let s=(l=yield a.json())==null?void 0:l.data,f=this.debug?this.injectIds(s):s;return this.latestData=f,this.sendDebugEvent(),f}else try{let s=yield a.json();throw console.log(s),new d(a.status,s)}catch(s){throw new d(a.status,s.toString())}}else throw new d(500,{id:"99",summary:`Query: queryUrl (${t}) or options are invalid`,details:`queryUrl: ${t}`})});this.getRegisteredComponentsWithFields=()=>{let e={},n=Object.entries(I());return n&&Array.isArray(n)&&n.forEach(([t,r])=>{let o={},l=r.fieldNames,a=!1;l&&Array.isArray(l)&&l.forEach(s=>{o[s]=!0,a=!0}),a?e[t]=o:e[t]={__all:!0}}),e};this.getQueries=()=>u(this,null,function*(){let e=this.buildUrl("queries");if(e){let n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}});if(n.ok)try{return yield n.json()}catch(t){console.error(t)}}else console.error("api, uri and CMSToken have to be provided");return""});this.apiToken=e,this.localServer=n,this.debug=typeof document!="undefined"&&document.getElementsByTagName("body")[0].classList.contains("qoh-inject-ids"),this.debug&&typeof globalThis.window!="undefined"&&(globalThis.window.addEventListener("QueenOfHearts-RequestData",()=>{this.sendDebugEvent()}),globalThis.window.addEventListener("QueenOfHearts-RequestQueries",()=>{this.sendQueriesEvent()}),globalThis.window.addEventListener("QueenOfHearts-HighlightComponent",(t=>{this.highlightComponent(t.detail)})),globalThis.window.addEventListener("QueenOfHearts-RequestComponentHTML",(t=>{this.sendComponentHTML(t.detail)})))}static init(e,n){i.instance=new i(e,n)}static getInstance(){return i.instance||console.error("QueenofheartsService was not initialized using QueenofheartsService.init(backend, apiToken)"),i.instance}loadAsyncComponent(e){return u(this,null,function*(){let n=c[e];if(n&&n.component===void 0){if(!(n!=null&&n.component)&&n.loader){let t=n.loader,r=yield t();r?c[e].component=r.default:(console.error(`error loading ${e}`),console.error(r))}return e}return null})}createComponent(e){let{data:n,contextProps:t={}}=e,r=n.__typename,o=c[r];return o&&o.loader&&A(o.loader),o!=null&&o.component?O.createElement(o.component,w(y({},n),{contextProps:t})):null}injectIds(e){if(Array.isArray(e))e.forEach(n=>this.injectIds(n));else if(e&&typeof e=="object"){if(e.hasOwnProperty("__typename")){let n=Math.random().toString();e.__qohId=n.substring(n.indexOf(".")+1)}Object.keys(e).forEach(n=>e[n]=this.injectIds(e[n]))}return e}sendDebugEvent(){if(typeof window=="undefined")return;let e={registeredComponents:Object.keys(c),url:this.latestUrl,data:this.latestData},n=new CustomEvent("QueenOfHearts-DebuggingData",{detail:e});window.dispatchEvent(n)}sendQueriesEvent(){return u(this,null,function*(){if(typeof window=="undefined")return;let e=new CustomEvent("QueenOfHearts-AvailableQueries",{detail:yield this.getQueries()});window.dispatchEvent(e)})}sendComponentHTML(e){var t;if(typeof window=="undefined")return;let n=(t=document.querySelector(`[qohId='${e}']`))==null?void 0:t.nextElementSibling;if(n){let r=new CustomEvent("QueenOfHearts-SelectedComponentHTML",{detail:{qohId:e,html:n.outerHTML}});window.dispatchEvent(r)}}highlightComponent(e){var o;let n=[{outline:"thick auto white"},{outline:"thick auto red"}],t={duration:1e3,iterations:2},r=(o=document.querySelector(`[qohId='${e}']`))==null?void 0:o.nextElementSibling;r&&r.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),r&&r.animate(n,t)}};var h=class{constructor(e){this.token="";this.uri="https://graphql.datocms.com/";this.token=e}renameSEOMetaTags(e){e.forEach(function(n,t,r){r[t].__typename="SEOMetaTag"})}normalize(e){if(e)return e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(t=>this.normalize(t))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e}};var g=class{constructor(e,n){this.token="";this.uri="";this.token=e,this.uri=n}renameSEOMetaTags(e){e.forEach(function(n,t,r){r[t].__typename="SEOMetaTag"})}normalize(e){return e&&(e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(t=>this.normalize(t))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e)}};export{d as ApiError,h as DatoCMS,j as Filter,M as QueenofheartsRenderComponent,m as QueenofheartsService,g as StrapiCMS,c as componentRegistry,W as fetchDynamicComponents,I as getAllregisteredComponents,$ as registerComponent,N as registerLazyComponent,z as unregisterComponent};
|
package/package.json
CHANGED
|
@@ -1,69 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@qoh/core-react",
|
|
3
|
-
"description": "Queen of hearts Core React API",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"module": "lib/index.mjs",
|
|
8
|
-
"types": "lib/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./lib/index.d.ts",
|
|
12
|
-
"import": "./lib/index.mjs",
|
|
13
|
-
"require": "./lib/index.js"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"lib",
|
|
18
|
-
"README.md"
|
|
19
|
-
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"test": "jest --passWithNoTests",
|
|
22
|
-
"build:prod": "tsup",
|
|
23
|
-
"build": "npm run build:prod",
|
|
24
|
-
"build:dev": "tsup --no-minify",
|
|
25
|
-
"prepublishOnly": "npm run build:prod",
|
|
26
|
-
"release": "npm publish --access public"
|
|
27
|
-
},
|
|
28
|
-
"peerDependencies": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"@
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
"jest": {
|
|
59
|
-
"preset": "ts-jest",
|
|
60
|
-
"testEnvironment": "jsdom",
|
|
61
|
-
"testPathIgnorePatterns": [
|
|
62
|
-
"<rootDir>/.next/",
|
|
63
|
-
"<rootDir>/node_modules/"
|
|
64
|
-
],
|
|
65
|
-
"moduleNameMapper": {
|
|
66
|
-
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@qoh/core-react",
|
|
3
|
+
"description": "Queen of hearts Core React API",
|
|
4
|
+
"version": "1.0.0-rc.13",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "lib/index.mjs",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"import": "./lib/index.mjs",
|
|
13
|
+
"require": "./lib/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"lib",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "jest --passWithNoTests",
|
|
22
|
+
"build:prod": "tsup",
|
|
23
|
+
"build": "npm run build:prod",
|
|
24
|
+
"build:dev": "tsup --no-minify",
|
|
25
|
+
"prepublishOnly": "npm run build:prod",
|
|
26
|
+
"release": "npm publish --access public"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
30
|
+
"react-dom": " ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/jest": "^29.5.14",
|
|
34
|
+
"@types/react": "^17.0.0",
|
|
35
|
+
"@types/react-dom": "^17.0.0",
|
|
36
|
+
"cross-env": "^7.0.3",
|
|
37
|
+
"identity-obj-proxy": "^3.0.0",
|
|
38
|
+
"jest": "^29.7.0",
|
|
39
|
+
"next": "^16.2.4",
|
|
40
|
+
"prettier": "^3.3.3",
|
|
41
|
+
"ts-jest": "^29.1.0",
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"typescript": "^5.0.0"
|
|
44
|
+
},
|
|
45
|
+
"jest": {
|
|
46
|
+
"preset": "ts-jest",
|
|
47
|
+
"testEnvironment": "jsdom",
|
|
48
|
+
"testPathIgnorePatterns": [
|
|
49
|
+
"<rootDir>/.next/",
|
|
50
|
+
"<rootDir>/node_modules/"
|
|
51
|
+
],
|
|
52
|
+
"moduleNameMapper": {
|
|
53
|
+
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|