@qoh/core-react 1.0.0-rc.14 → 1.0.0-rc.17
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 +12 -4
- package/lib/index.d.ts +12 -4
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +4 -1
package/lib/index.d.mts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { JSX } from 'react';
|
|
3
|
+
import { z, ZodObject } from 'zod';
|
|
3
4
|
|
|
4
5
|
declare function QueenofheartsRenderComponent(props: Readonly<{
|
|
5
6
|
data: {} | [];
|
|
6
7
|
contextProps?: any;
|
|
7
8
|
}>): react_jsx_runtime.JSX.Element;
|
|
8
9
|
|
|
10
|
+
declare const componentField: z.ZodArray<z.ZodObject<{
|
|
11
|
+
__typename: z.ZodString;
|
|
12
|
+
}, z.core.$loose>>;
|
|
13
|
+
type ComponentFieldMap = {
|
|
14
|
+
[key: string]: boolean | ComponentFieldMap;
|
|
15
|
+
};
|
|
9
16
|
declare enum Filter {
|
|
10
17
|
eq = "eq",
|
|
11
18
|
in = "in",
|
|
@@ -27,13 +34,13 @@ interface IFCDictionary {
|
|
|
27
34
|
}
|
|
28
35
|
interface ReactFCWithFieldNames {
|
|
29
36
|
component?: React.FC<any>;
|
|
30
|
-
fieldNames?:
|
|
37
|
+
fieldNames?: ComponentFieldMap;
|
|
31
38
|
loader?: () => any;
|
|
32
39
|
}
|
|
33
40
|
declare let componentRegistry: IFCDictionary;
|
|
34
41
|
declare function unregisterComponent(name: string): void;
|
|
35
|
-
declare function registerComponent(functionalComponent: React.FC<
|
|
36
|
-
declare function registerLazyComponent(loader: () => any, typeName: string,
|
|
42
|
+
declare function registerComponent<S extends ZodObject<any, any>>(functionalComponent: React.FC<ReturnType<S['parse']>>, typeName: string, schema?: S, overwrite?: false): void;
|
|
43
|
+
declare function registerLazyComponent<S extends ZodObject<any, any>>(loader: () => any, typeName: string, schema?: S, overwrite?: boolean): void;
|
|
37
44
|
declare function getAllregisteredComponents(): IFCDictionary;
|
|
38
45
|
declare const fetchDynamicComponents: (props: any) => Promise<string[]>;
|
|
39
46
|
declare class QueenofheartsService {
|
|
@@ -77,6 +84,7 @@ declare class QueenofheartsService {
|
|
|
77
84
|
};
|
|
78
85
|
locale?: string;
|
|
79
86
|
depth?: number;
|
|
87
|
+
fieldArgs?: Record<string, unknown>;
|
|
80
88
|
}) => Promise<any>;
|
|
81
89
|
private readonly getRegisteredComponentsWithFields;
|
|
82
90
|
getQueries: () => Promise<any>;
|
|
@@ -120,4 +128,4 @@ declare class ApiError extends Error {
|
|
|
120
128
|
constructor(status: number, body: Body);
|
|
121
129
|
}
|
|
122
130
|
|
|
123
|
-
export { ApiError, type Backend, type ComponentTypes, DatoCMS, Filter, type IFCDictionary, type QohResponse, QueenofheartsRenderComponent, QueenofheartsService, type ReactFCWithFieldNames, StrapiCMS, componentRegistry, fetchDynamicComponents, getAllregisteredComponents, registerComponent, registerLazyComponent, unregisterComponent };
|
|
131
|
+
export { ApiError, type Backend, type ComponentFieldMap, type ComponentTypes, DatoCMS, Filter, type IFCDictionary, type QohResponse, QueenofheartsRenderComponent, QueenofheartsService, type ReactFCWithFieldNames, StrapiCMS, componentField, componentRegistry, fetchDynamicComponents, getAllregisteredComponents, registerComponent, registerLazyComponent, unregisterComponent };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { JSX } from 'react';
|
|
3
|
+
import { z, ZodObject } from 'zod';
|
|
3
4
|
|
|
4
5
|
declare function QueenofheartsRenderComponent(props: Readonly<{
|
|
5
6
|
data: {} | [];
|
|
6
7
|
contextProps?: any;
|
|
7
8
|
}>): react_jsx_runtime.JSX.Element;
|
|
8
9
|
|
|
10
|
+
declare const componentField: z.ZodArray<z.ZodObject<{
|
|
11
|
+
__typename: z.ZodString;
|
|
12
|
+
}, z.core.$loose>>;
|
|
13
|
+
type ComponentFieldMap = {
|
|
14
|
+
[key: string]: boolean | ComponentFieldMap;
|
|
15
|
+
};
|
|
9
16
|
declare enum Filter {
|
|
10
17
|
eq = "eq",
|
|
11
18
|
in = "in",
|
|
@@ -27,13 +34,13 @@ interface IFCDictionary {
|
|
|
27
34
|
}
|
|
28
35
|
interface ReactFCWithFieldNames {
|
|
29
36
|
component?: React.FC<any>;
|
|
30
|
-
fieldNames?:
|
|
37
|
+
fieldNames?: ComponentFieldMap;
|
|
31
38
|
loader?: () => any;
|
|
32
39
|
}
|
|
33
40
|
declare let componentRegistry: IFCDictionary;
|
|
34
41
|
declare function unregisterComponent(name: string): void;
|
|
35
|
-
declare function registerComponent(functionalComponent: React.FC<
|
|
36
|
-
declare function registerLazyComponent(loader: () => any, typeName: string,
|
|
42
|
+
declare function registerComponent<S extends ZodObject<any, any>>(functionalComponent: React.FC<ReturnType<S['parse']>>, typeName: string, schema?: S, overwrite?: false): void;
|
|
43
|
+
declare function registerLazyComponent<S extends ZodObject<any, any>>(loader: () => any, typeName: string, schema?: S, overwrite?: boolean): void;
|
|
37
44
|
declare function getAllregisteredComponents(): IFCDictionary;
|
|
38
45
|
declare const fetchDynamicComponents: (props: any) => Promise<string[]>;
|
|
39
46
|
declare class QueenofheartsService {
|
|
@@ -77,6 +84,7 @@ declare class QueenofheartsService {
|
|
|
77
84
|
};
|
|
78
85
|
locale?: string;
|
|
79
86
|
depth?: number;
|
|
87
|
+
fieldArgs?: Record<string, unknown>;
|
|
80
88
|
}) => Promise<any>;
|
|
81
89
|
private readonly getRegisteredComponentsWithFields;
|
|
82
90
|
getQueries: () => Promise<any>;
|
|
@@ -120,4 +128,4 @@ declare class ApiError extends Error {
|
|
|
120
128
|
constructor(status: number, body: Body);
|
|
121
129
|
}
|
|
122
130
|
|
|
123
|
-
export { ApiError, type Backend, type ComponentTypes, DatoCMS, Filter, type IFCDictionary, type QohResponse, QueenofheartsRenderComponent, QueenofheartsService, type ReactFCWithFieldNames, StrapiCMS, componentRegistry, fetchDynamicComponents, getAllregisteredComponents, registerComponent, registerLazyComponent, unregisterComponent };
|
|
131
|
+
export { ApiError, type Backend, type ComponentFieldMap, type ComponentTypes, DatoCMS, Filter, type IFCDictionary, type QohResponse, QueenofheartsRenderComponent, QueenofheartsService, type ReactFCWithFieldNames, StrapiCMS, componentField, componentRegistry, fetchDynamicComponents, getAllregisteredComponents, registerComponent, registerLazyComponent, unregisterComponent };
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _=Object.create;var m=Object.defineProperty,M=Object.defineProperties,Q=Object.getOwnPropertyDescriptor,k=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols,R=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var T=(i,e,n)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,C=(i,e)=>{for(var n in e||(e={}))S.call(e,n)&&T(i,n,e[n]);if(E)for(var n of E(e))F.call(e,n)&&T(i,n,e[n]);return i},O=(i,e)=>M(i,k(e));var D=(i,e)=>{for(var n in e)m(i,n,{get:e[n],enumerable:!0})},j=(i,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!S.call(i,r)&&r!==n&&m(i,r,{get:()=>e[r],enumerable:!(t=Q(e,r))||t.enumerable});return i};var P=(i,e,n)=>(n=i!=null?_(R(i)):{},j(e||!i||!i.__esModule?m(n,"default",{value:i,enumerable:!0}):n,i)),z=i=>j(m({},"__esModule",{value:!0}),i);var u=(i,e,n)=>new Promise((t,r)=>{var o=s=>{try{l(n.next(s))}catch(p){r(p)}},c=s=>{try{l(n.throw(s))}catch(p){r(p)}},l=s=>s.done?t(s.value):Promise.resolve(s.value).then(o,c);l((n=n.apply(i,e)).next())});var Z={};D(Z,{ApiError:()=>d,DatoCMS:()=>h,Filter:()=>q,QueenofheartsRenderComponent:()=>L,QueenofheartsService:()=>f,StrapiCMS:()=>b,componentField:()=>B,componentRegistry:()=>a,fetchDynamicComponents:()=>W,getAllregisteredComponents:()=>A,registerComponent:()=>$,registerLazyComponent:()=>J,unregisterComponent:()=>U});module.exports=z(Z);var x=require("react");var y=require("react/jsx-runtime");function L(i){let e=f.getInstance(),{data:n,contextProps:t}=i;return n&&e?Array.isArray(n)?(0,y.jsx)(x.Suspense,{fallback:null,children:n.map((r,o)=>e.createComponent({data:r,contextProps:t}))}):(0,y.jsx)(x.Suspense,{fallback:null,children:e.createComponent({data:n,contextProps:t})}):e?(0,y.jsx)("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):(0,y.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 w=P(require("react")),v=require("zod");var B=v.z.array(v.z.object({__typename:v.z.string()}).loose());function g(i){var n,t;let e=i._def;switch(e.type){case"optional":case"nullable":return g(e.innerType);case"array":return g(e.element);case"object":{if(((t=(n=e.catchall)==null?void 0:n._def)==null?void 0:t.type)==="unknown")return!0;let r={};for(let[o,c]of Object.entries(e.shape))r[o]=g(c);return r}default:return!0}}var q=(r=>(r.eq="eq",r.in="in",r.neq="neq",r.notIn="notIn",r))(q||{}),H="https://www.headless.li/api",a={};function U(i){delete a[i]}function $(i,e,n,t){e!==void 0&&(t||a[e]===void 0)&&(a[e]={component:i,fieldNames:n?g(n):void 0})}function J(i,e,n,t=!1){e?(t||a[e]===void 0)&&(a[e]={fieldNames:n?g(n):void 0,loader:i}):console.warn("registerComponent failed: undefined typeName ")}function A(){return a}var W=i=>u(null,null,function*(){let e=f.getInstance(),n=e.findComponentsInProps(i).filter((r,o,c)=>c.indexOf(r)===o);return(yield e.fetchDynamicComponents(n)).filter(r=>r!==null)}),f=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 l=this.findComponentsInProps(c);return l&&(o=[...o,...l]),o},[])]}return[]};this.fetchDynamicComponents=e=>u(this,null,function*(){return Promise.all(e.map(t=>u(this,null,function*(){var r;return a[t]&&a[t].component===void 0?yield this.loadAsyncComponent(t):(r=a[t])!=null&&r.loader?t:null})))});this.buildUrl=e=>{var t;return`${(t=this.localServer)!=null?t:H}/${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?C({},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 l=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(l.ok){let s=(c=yield l.json())==null?void 0:c.data,p=this.debug?this.injectIds(s):s;return this.latestData=p,this.sendDebugEvent(),p}else try{let s=yield l.json();throw console.log(s),new d(l.status,s)}catch(s){throw new d(l.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(A());return n&&Array.isArray(n)&&n.forEach(([t,r])=>{let{fieldNames:o}=r;e[t]=o!=null?o:{__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=a[e];if(n&&n.component===void 0){if(!(n!=null&&n.component)&&n.loader){let t=n.loader,r=yield t();r?a[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=a[r];return o&&o.loader&&(0,w.lazy)(o.loader),o!=null&&o.component?w.default.createElement(o.component,O(C({},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(a),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 b=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,componentField,componentRegistry,fetchDynamicComponents,getAllregisteredComponents,registerComponent,registerLazyComponent,unregisterComponent});
|
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var T=Object.defineProperty,S=Object.defineProperties;var O=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var C=(i,e,n)=>e in i?T(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,b=(i,e)=>{for(var n in e||(e={}))j.call(e,n)&&C(i,n,e[n]);if(w)for(var n of w(e))q.call(e,n)&&C(i,n,e[n]);return i},x=(i,e)=>S(i,O(e));var u=(i,e,n)=>new Promise((t,r)=>{var o=s=>{try{l(n.next(s))}catch(p){r(p)}},c=s=>{try{l(n.throw(s))}catch(p){r(p)}},l=s=>s.done?t(s.value):Promise.resolve(s.value).then(o,c);l((n=n.apply(i,e)).next())});import{Suspense as E}from"react";import{jsx as y}from"react/jsx-runtime";function P(i){let e=f.getInstance(),{data:n,contextProps:t}=i;return n&&e?Array.isArray(n)?y(E,{fallback:null,children:n.map((r,o)=>e.createComponent({data:r,contextProps:t}))}):y(E,{fallback:null,children:e.createComponent({data:n,contextProps:t})}):e?y("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):y("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 A,{lazy as _}from"react";import{z as v}from"zod";var Z=v.array(v.object({__typename:v.string()}).loose());function m(i){var n,t;let e=i._def;switch(e.type){case"optional":case"nullable":return m(e.innerType);case"array":return m(e.element);case"object":{if(((t=(n=e.catchall)==null?void 0:n._def)==null?void 0:t.type)==="unknown")return!0;let r={};for(let[o,c]of Object.entries(e.shape))r[o]=m(c);return r}default:return!0}}var M=(r=>(r.eq="eq",r.in="in",r.neq="neq",r.notIn="notIn",r))(M||{}),Q="https://www.headless.li/api",a={};function G(i){delete a[i]}function N(i,e,n,t){e!==void 0&&(t||a[e]===void 0)&&(a[e]={component:i,fieldNames:n?m(n):void 0})}function V(i,e,n,t=!1){e?(t||a[e]===void 0)&&(a[e]={fieldNames:n?m(n):void 0,loader:i}):console.warn("registerComponent failed: undefined typeName ")}function k(){return a}var X=i=>u(null,null,function*(){let e=f.getInstance(),n=e.findComponentsInProps(i).filter((r,o,c)=>c.indexOf(r)===o);return(yield e.fetchDynamicComponents(n)).filter(r=>r!==null)}),f=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 l=this.findComponentsInProps(c);return l&&(o=[...o,...l]),o},[])]}return[]};this.fetchDynamicComponents=e=>u(this,null,function*(){return Promise.all(e.map(t=>u(this,null,function*(){var r;return a[t]&&a[t].component===void 0?yield this.loadAsyncComponent(t):(r=a[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,c;let t=this.buildUrl("execQuery"),r=n!=null&&n.variables?b({},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 l=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(l.ok){let s=(c=yield l.json())==null?void 0:c.data,p=this.debug?this.injectIds(s):s;return this.latestData=p,this.sendDebugEvent(),p}else try{let s=yield l.json();throw console.log(s),new d(l.status,s)}catch(s){throw new d(l.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(k());return n&&Array.isArray(n)&&n.forEach(([t,r])=>{let{fieldNames:o}=r;e[t]=o!=null?o:{__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=a[e];if(n&&n.component===void 0){if(!(n!=null&&n.component)&&n.loader){let t=n.loader,r=yield t();r?a[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=a[r];return o&&o.loader&&_(o.loader),o!=null&&o.component?A.createElement(o.component,x(b({},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(a),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 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,M as Filter,P as QueenofheartsRenderComponent,f as QueenofheartsService,h as StrapiCMS,Z as componentField,a as componentRegistry,X as fetchDynamicComponents,k as getAllregisteredComponents,N as registerComponent,V as registerLazyComponent,G as unregisterComponent};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qoh/core-react",
|
|
3
3
|
"description": "Queen of hearts Core React API",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.17",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.mjs",
|
|
@@ -52,5 +52,8 @@
|
|
|
52
52
|
"moduleNameMapper": {
|
|
53
53
|
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
|
|
54
54
|
}
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"zod": "^4.4.3"
|
|
55
58
|
}
|
|
56
59
|
}
|