@qoh/core-react 1.0.0-rc.13 → 1.0.0-rc.15

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.d.mts CHANGED
@@ -77,6 +77,7 @@ declare class QueenofheartsService {
77
77
  };
78
78
  locale?: string;
79
79
  depth?: number;
80
+ fieldArgs?: Record<string, unknown>;
80
81
  }) => Promise<any>;
81
82
  private readonly getRegisteredComponentsWithFields;
82
83
  getQueries: () => Promise<any>;
package/lib/index.d.ts CHANGED
@@ -77,6 +77,7 @@ declare class QueenofheartsService {
77
77
  };
78
78
  locale?: string;
79
79
  depth?: number;
80
+ fieldArgs?: Record<string, unknown>;
80
81
  }) => Promise<any>;
81
82
  private readonly getRegisteredComponentsWithFields;
82
83
  getQueries: () => Promise<any>;
package/lib/index.js CHANGED
@@ -1 +1 @@
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});
1
+ "use strict";var O=Object.create;var p=Object.defineProperty,j=Object.defineProperties,Q=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,_=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 R(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?O(_(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 s=o=>{try{a(n.next(o))}catch(f){r(f)}},c=o=>{try{a(n.throw(o))}catch(f){r(f)}},a=o=>o.done?t(o.value):Promise.resolve(o.value).then(s,c);a((n=n.apply(i,e)).next())});var $={};D($,{ApiError:()=>d,DatoCMS:()=>h,Filter:()=>A,QueenofheartsRenderComponent:()=>L,QueenofheartsService:()=>m,StrapiCMS:()=>y,componentRegistry:()=>l,fetchDynamicComponents:()=>z,getAllregisteredComponents:()=>q,registerComponent:()=>H,registerLazyComponent:()=>U,unregisterComponent:()=>B});module.exports=P($);var w=require("react");var g=require("react/jsx-runtime");function L(i){let e=m.getInstance(),{data:n,contextProps:t}=i;return n&&e?Array.isArray(n)?(0,g.jsx)(w.Suspense,{fallback:null,children:n.map((r,s)=>e.createComponent({data:r,contextProps:t}))}):(0,g.jsx)(w.Suspense,{fallback:null,children:e.createComponent({data:n,contextProps:t})}):e?(0,g.jsx)("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):(0,g.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 A=(r=>(r.eq="eq",r.in="in",r.neq="neq",r.notIn="notIn",r))(A||{}),F="https://www.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 q(){return l}var z=i=>u(null,null,function*(){let e=m.getInstance(),n=e.findComponentsInProps(i).filter((r,s,c)=>c.indexOf(r)===s);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((s,c)=>{let a=this.findComponentsInProps(c);return a&&(s=[...s,...a]),s},[])]}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 s,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),(s=n==null?void 0:n.variables)!=null&&s.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,fieldArgs:n.fieldArgs})});if(a.ok){let o=(c=yield a.json())==null?void 0:c.data,f=this.debug?this.injectIds(o):o;return this.latestData=f,this.sendDebugEvent(),f}else try{let o=yield a.json();throw console.log(o),new d(a.status,o)}catch(o){throw new d(a.status,o.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(q());return n&&Array.isArray(n)&&n.forEach(([t,r])=>{let s={},c=r.fieldNames,a=!1;c&&Array.isArray(c)&&c.forEach(o=>{s[o]=!0,a=!0}),a?e[t]=s: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,s=l[r];return s&&s.loader&&(0,b.lazy)(s.loader),s!=null&&s.component?b.default.createElement(s.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 s;let n=[{outline:"thick auto white"},{outline:"thick auto red"}],t={duration:1e3,iterations:2},r=(s=document.querySelector(`[qohId='${e}']`))==null?void 0:s.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 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 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};
1
+ var E=Object.defineProperty,x=Object.defineProperties;var T=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,A=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))A.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 s=o=>{try{a(n.next(o))}catch(f){r(f)}},l=o=>{try{a(n.throw(o))}catch(f){r(f)}},a=o=>o.done?t(o.value):Promise.resolve(o.value).then(s,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,s)=>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 q,{lazy as O}from"react";var j=(r=>(r.eq="eq",r.in="in",r.neq="neq",r.notIn="notIn",r))(j||{}),Q="https://www.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,s,l)=>l.indexOf(r)===s);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((s,l)=>{let a=this.findComponentsInProps(l);return a&&(s=[...s,...a]),s},[])]}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 s,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),(s=n==null?void 0:n.variables)!=null&&s.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,fieldArgs:n.fieldArgs})});if(a.ok){let o=(l=yield a.json())==null?void 0:l.data,f=this.debug?this.injectIds(o):o;return this.latestData=f,this.sendDebugEvent(),f}else try{let o=yield a.json();throw console.log(o),new d(a.status,o)}catch(o){throw new d(a.status,o.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 s={},l=r.fieldNames,a=!1;l&&Array.isArray(l)&&l.forEach(o=>{s[o]=!0,a=!0}),a?e[t]=s: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,s=c[r];return s&&s.loader&&O(s.loader),s!=null&&s.component?q.createElement(s.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 s;let n=[{outline:"thick auto white"},{outline:"thick auto red"}],t={duration:1e3,iterations:2},r=(s=document.querySelector(`[qohId='${e}']`))==null?void 0:s.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 h=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,g as DatoCMS,j as Filter,M as QueenofheartsRenderComponent,m as QueenofheartsService,h as StrapiCMS,c as componentRegistry,W as fetchDynamicComponents,I as getAllregisteredComponents,$ as registerComponent,N as registerLazyComponent,z as unregisterComponent};
package/package.json CHANGED
@@ -1,56 +1,56 @@
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
- }
1
+ {
2
+ "name": "@qoh/core-react",
3
+ "description": "Queen of hearts Core React API",
4
+ "version": "1.0.0-rc.15",
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
+ }