@plasmicpkgs/plasmic-wordpress-graphql 0.0.125 → 0.0.127
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.
|
@@ -446,7 +446,7 @@ function WordpressFetcher(_ref2) {
|
|
|
446
446
|
query: query$1,
|
|
447
447
|
creds: creds
|
|
448
448
|
});
|
|
449
|
-
var _usePlasmicQueryData = query.usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator(
|
|
449
|
+
var _usePlasmicQueryData = query.usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
450
450
|
var data;
|
|
451
451
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
452
452
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plasmic-wordpress-graphql.cjs.development.js","sources":["../src/wordpress.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n GlobalContextMeta,\n repeatedElement,\n useSelector,\n} from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport get from \"dlv\";\nimport React, { ReactNode, useContext } from \"react\";\n\nexport function ensure<T>(x: T | null | undefined): T {\n if (x === null || x === undefined) {\n debugger;\n throw new Error(`Value must not be undefined or null`);\n } else {\n return x;\n }\n}\n\nconst modulePath = \"@plasmicpkgs/plasmic-wordpress-graphql\";\n\ninterface WordpressProviderProps {\n graphqlEndpoint: string;\n}\n\nconst CredentialsContext = React.createContext<\n WordpressProviderProps | undefined\n>(undefined);\n\nexport const WordpressProviderMeta: GlobalContextMeta<WordpressProviderProps> = {\n name: \"WordpressGraphQLProvider\",\n displayName: \"Wordpress GraphQL Provider\",\n description: \"The GraphQL API Endpoint of your Wordpress\",\n importName: \"WordpressProvider\",\n importPath: modulePath,\n props: {\n graphqlEndpoint: {\n type: \"string\",\n displayName: \"GraphQL API Endpoint\",\n description: \"GraphQL API Endpoint of your Wordpress\",\n defaultValue: \"https://demo.wpgraphql.com/graphql\",\n },\n },\n};\n\nexport function WordpressProvider({\n graphqlEndpoint,\n children,\n}: React.PropsWithChildren<WordpressProviderProps>) {\n return (\n <CredentialsContext.Provider value={{ graphqlEndpoint }}>\n {children}\n </CredentialsContext.Provider>\n );\n}\n\ninterface WordpressFetcherProps {\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n query?: string;\n setControlContextData?: (data: { endpoint?: string }) => void;\n}\n\nexport const WordpressFetcherMeta: ComponentMeta<WordpressFetcherProps> = {\n name: \"WordpressGraphQLFetcher\",\n displayName: \"Wordpress Fetcher\",\n importName: \"WordpressFetcher\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Wordpress data and repeats content of children once for every row fetched. \",\n defaultStyles: {\n display: \"grid\",\n gridTemplateColumns: \"1fr 1fr 1fr 1fr\",\n gridRowGap: \"8px\",\n gridColumnGap: \"8px\",\n padding: \"8px\",\n maxWidth: \"100%\",\n },\n props: {\n children: {\n type: \"slot\",\n defaultValue: {\n type: \"vbox\",\n styles: {\n padding: \"8px\",\n },\n children: {\n type: \"component\",\n name: \"WordpressGraphQLField\",\n },\n },\n },\n query: {\n type: \"code\",\n lang: \"graphql\",\n endpoint: (props, ctx) => ctx?.endpoint ?? \"\",\n },\n noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every entry.\",\n defaultValue: false,\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Wordpress Fetcher will not layout its children; instead, the layout set on its parent element will be used. Useful if you want to set flex gap or control container tag type.\",\n defaultValue: false,\n },\n },\n};\n\nfunction compact(arr: any[]) {\n return arr.filter((x) => !!x);\n}\n\nexport function WordpressFetcher({\n query,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: WordpressFetcherProps) {\n const creds = ensure(useContext(CredentialsContext));\n const cacheKey = JSON.stringify({\n query,\n creds,\n });\n const { data } = usePlasmicQueryData<any | null>(cacheKey, async () => {\n if (!query) {\n return null;\n }\n const data = await fetch(creds.graphqlEndpoint, {\n method: \"POST\",\n body: JSON.stringify(query),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n return await data.json();\n });\n\n setControlContextData?.({\n endpoint: creds.graphqlEndpoint,\n });\n\n if (!query) {\n return <div>Please make a query in order to fetch data</div>;\n }\n\n if (!creds.graphqlEndpoint) {\n return (\n <div>\n Please specify a valid API Credentials: GraphQL Endpoint of your\n Wordpress project\n </div>\n );\n }\n\n if (!data?.data || compact(Object.values(data?.data)).length === 0) {\n return <div>Data not found</div>;\n }\n\n const renderedData = noAutoRepeat\n ? children\n : Object.values(data?.data).flatMap((model: any, i: number) =>\n (Array.isArray(model) ? model : [model]).map((item: any, j: number) => (\n <DataProvider\n key={JSON.stringify(item)}\n name={\"currentWordpressItem\"}\n data={item}\n >\n {repeatedElement(i === 0 && j === 0, children)}\n </DataProvider>\n ))\n );\n return noLayout ? (\n <> {renderedData} </>\n ) : (\n <div className={className}> {renderedData} </div>\n );\n}\n\ninterface WordpressFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: { data: any }) => void;\n}\nexport const WordpressFieldMeta: ComponentMeta<WordpressFieldProps> = {\n name: \"WordpressGraphQLField\",\n displayName: \"Wordpress Field\",\n importName: \"WordpressField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"dataSelector\",\n data: (props: any, ctx: any) => ctx?.data ?? {},\n displayName: \"Field\",\n description: \"Field to be displayed.\",\n },\n },\n};\nexport function WordpressField({\n className,\n path,\n setControlContextData,\n}: WordpressFieldProps) {\n const item = useSelector(\"currentWordpressItem\");\n\n if (!item) {\n return <div>WordpressField must be used within a WordpressFetcher </div>;\n }\n\n setControlContextData?.({\n data: item,\n });\n\n if (!path) {\n return <div>Please specify a valid path or select a field.</div>;\n }\n const data = get(item, path as string);\n if (typeof data === \"object\" && data.mediaType === \"image\") {\n return (\n <img className={className} src={data.mediaItemUrl} srcSet={data.srcSet} />\n );\n } else if (\n path.slice(-1)[0] === \"content\" ||\n path.slice(-1)[0] === \"excerpt\"\n ) {\n return (\n <div className={className} dangerouslySetInnerHTML={{ __html: data }} />\n );\n } else if (!data || typeof data === \"object\") {\n return <div className={className}>Please specify a valid field.</div>;\n } else {\n return <div className={className}> {data} </div>;\n }\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport {\n WordpressFetcher,\n WordpressFetcherMeta,\n WordpressField,\n WordpressFieldMeta,\n WordpressProvider,\n WordpressProviderMeta,\n} from \"./wordpress\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n\n if (loader) {\n loader.registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n } else {\n registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n }\n\n _registerComponent(WordpressFetcher, WordpressFetcherMeta);\n _registerComponent(WordpressField, WordpressFieldMeta);\n}\n\nexport * from \"./wordpress\";\n"],"names":["ensure","x","undefined","Error","modulePath","CredentialsContext","React","createContext","WordpressProviderMeta","name","displayName","description","importName","importPath","props","graphqlEndpoint","type","defaultValue","WordpressProvider","_ref","children","Provider","value","WordpressFetcherMeta","providesData","defaultStyles","display","gridTemplateColumns","gridRowGap","gridColumnGap","padding","maxWidth","styles","query","lang","endpoint","ctx","_ctx$endpoint","noAutoRepeat","noLayout","compact","arr","filter","WordpressFetcher","_ref2","className","setControlContextData","creds","useContext","cacheKey","JSON","stringify","_usePlasmicQueryData","usePlasmicQueryData","_asyncToGenerator","_regeneratorRuntime","mark","_callee","data","wrap","_callee$","_context","prev","next","abrupt","fetch","method","body","headers","sent","json","stop","Object","values","length","renderedData","flatMap","model","i","Array","isArray","map","item","j","DataProvider","key","repeatedElement","WordpressFieldMeta","path","_ctx$data","WordpressField","_ref4","useSelector","get","mediaType","src","mediaItemUrl","srcSet","slice","dangerouslySetInnerHTML","__html","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent","registerGlobalContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAWgBA,MAAMA,CAAIC,CAAuB;EAC/C,IAAIA,CAAC,KAAK,IAAI,IAAIA,CAAC,KAAKC,SAAS,EAAE;IACjC;IACA,MAAM,IAAIC,KAAK,sCAAsC,CAAC;GACvD,MAAM;IACL,OAAOF,CAAC;;AAEZ;AAEA,IAAMG,UAAU,GAAG,wCAAwC;AAM3D,IAAMC,kBAAkB,gBAAGC,cAAK,CAACC,aAAa,CAE5CL,SAAS,CAAC;IAECM,qBAAqB,GAA8C;EAC9EC,IAAI,EAAE,0BAA0B;EAChCC,WAAW,EAAE,4BAA4B;EACzCC,WAAW,EAAE,4CAA4C;EACzDC,UAAU,EAAE,mBAAmB;EAC/BC,UAAU,EAAET,UAAU;EACtBU,KAAK,EAAE;IACLC,eAAe,EAAE;MACfC,IAAI,EAAE,QAAQ;MACdN,WAAW,EAAE,sB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AAU;GAE7E,MAAM,IACLT,IAAI,CAACU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,IAC/BV,IAAI,CAACU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,EAC/B;IACA,OACE5F;MAAKuC,SAAS,EAAEA,SAAS;MAAEsD,uBAAuB,EAAE;QAAEC,MAAM,EAAE1C;;MAAU;GAE3E,MAAM,IAAI,CAACA,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAC5C,OAAOpD;MAAKuC,SAAS,EAAEA;uCAA8C;GACtE,MAAM;IACL,OAAOvC;MAAKuC,SAAS,EAAEA;YAAaa,IAAI,MAAQ;;AAEpD;;SCtOgB2C,WAAWA,CAACC,MAG3B;EACC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CACtBC,SAAY,EACZC,WAAmD;IAEnD,IAAIH,MAAM,EAAE;MACVA,MAAM,CAACI,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;KACjD,MAAM;MACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAED,IAAIH,MAAM,EAAE;IACVA,MAAM,CAACK,qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;GACvE,MAAM;IACLmG,qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;;EAGjE+F,kBAAkB,CAAC5D,gBAAgB,EAAEpB,oBAAoB,CAAC;EAC1DgF,kBAAkB,CAACb,cAAc,EAAEH,kBAAkB,CAAC;AACxD;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plasmic-wordpress-graphql.cjs.development.js","sources":["../src/wordpress.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n GlobalContextMeta,\n repeatedElement,\n useSelector,\n} from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport get from \"dlv\";\nimport React, { ReactNode, useContext } from \"react\";\n\nexport function ensure<T>(x: T | null | undefined): T {\n if (x === null || x === undefined) {\n debugger;\n throw new Error(`Value must not be undefined or null`);\n } else {\n return x;\n }\n}\n\nconst modulePath = \"@plasmicpkgs/plasmic-wordpress-graphql\";\n\ninterface WordpressProviderProps {\n graphqlEndpoint: string;\n}\n\nconst CredentialsContext = React.createContext<\n WordpressProviderProps | undefined\n>(undefined);\n\nexport const WordpressProviderMeta: GlobalContextMeta<WordpressProviderProps> = {\n name: \"WordpressGraphQLProvider\",\n displayName: \"Wordpress GraphQL Provider\",\n description: \"The GraphQL API Endpoint of your Wordpress\",\n importName: \"WordpressProvider\",\n importPath: modulePath,\n props: {\n graphqlEndpoint: {\n type: \"string\",\n displayName: \"GraphQL API Endpoint\",\n description: \"GraphQL API Endpoint of your Wordpress\",\n defaultValue: \"https://demo.wpgraphql.com/graphql\",\n },\n },\n};\n\nexport function WordpressProvider({\n graphqlEndpoint,\n children,\n}: React.PropsWithChildren<WordpressProviderProps>) {\n return (\n <CredentialsContext.Provider value={{ graphqlEndpoint }}>\n {children}\n </CredentialsContext.Provider>\n );\n}\n\ninterface WordpressFetcherProps {\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n query?: string;\n setControlContextData?: (data: { endpoint?: string }) => void;\n}\n\nexport const WordpressFetcherMeta: ComponentMeta<WordpressFetcherProps> = {\n name: \"WordpressGraphQLFetcher\",\n displayName: \"Wordpress Fetcher\",\n importName: \"WordpressFetcher\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Wordpress data and repeats content of children once for every row fetched. \",\n defaultStyles: {\n display: \"grid\",\n gridTemplateColumns: \"1fr 1fr 1fr 1fr\",\n gridRowGap: \"8px\",\n gridColumnGap: \"8px\",\n padding: \"8px\",\n maxWidth: \"100%\",\n },\n props: {\n children: {\n type: \"slot\",\n defaultValue: {\n type: \"vbox\",\n styles: {\n padding: \"8px\",\n },\n children: {\n type: \"component\",\n name: \"WordpressGraphQLField\",\n },\n },\n },\n query: {\n type: \"code\",\n lang: \"graphql\",\n endpoint: (props, ctx) => ctx?.endpoint ?? \"\",\n },\n noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every entry.\",\n defaultValue: false,\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Wordpress Fetcher will not layout its children; instead, the layout set on its parent element will be used. Useful if you want to set flex gap or control container tag type.\",\n defaultValue: false,\n },\n },\n};\n\nfunction compact(arr: any[]) {\n return arr.filter((x) => !!x);\n}\n\nexport function WordpressFetcher({\n query,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: WordpressFetcherProps) {\n const creds = ensure(useContext(CredentialsContext));\n const cacheKey = JSON.stringify({\n query,\n creds,\n });\n const { data } = usePlasmicQueryData<any | null>(cacheKey, async () => {\n if (!query) {\n return null;\n }\n const data = await fetch(creds.graphqlEndpoint, {\n method: \"POST\",\n body: JSON.stringify(query),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n return await data.json();\n });\n\n setControlContextData?.({\n endpoint: creds.graphqlEndpoint,\n });\n\n if (!query) {\n return <div>Please make a query in order to fetch data</div>;\n }\n\n if (!creds.graphqlEndpoint) {\n return (\n <div>\n Please specify a valid API Credentials: GraphQL Endpoint of your\n Wordpress project\n </div>\n );\n }\n\n if (!data?.data || compact(Object.values(data?.data)).length === 0) {\n return <div>Data not found</div>;\n }\n\n const renderedData = noAutoRepeat\n ? children\n : Object.values(data?.data).flatMap((model: any, i: number) =>\n (Array.isArray(model) ? model : [model]).map((item: any, j: number) => (\n <DataProvider\n key={JSON.stringify(item)}\n name={\"currentWordpressItem\"}\n data={item}\n >\n {repeatedElement(i === 0 && j === 0, children)}\n </DataProvider>\n ))\n );\n return noLayout ? (\n <> {renderedData} </>\n ) : (\n <div className={className}> {renderedData} </div>\n );\n}\n\ninterface WordpressFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: { data: any }) => void;\n}\nexport const WordpressFieldMeta: ComponentMeta<WordpressFieldProps> = {\n name: \"WordpressGraphQLField\",\n displayName: \"Wordpress Field\",\n importName: \"WordpressField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"dataSelector\",\n data: (props: any, ctx: any) => ctx?.data ?? {},\n displayName: \"Field\",\n description: \"Field to be displayed.\",\n },\n },\n};\nexport function WordpressField({\n className,\n path,\n setControlContextData,\n}: WordpressFieldProps) {\n const item = useSelector(\"currentWordpressItem\");\n\n if (!item) {\n return <div>WordpressField must be used within a WordpressFetcher </div>;\n }\n\n setControlContextData?.({\n data: item,\n });\n\n if (!path) {\n return <div>Please specify a valid path or select a field.</div>;\n }\n const data = get(item, path as string);\n if (typeof data === \"object\" && data.mediaType === \"image\") {\n return (\n <img className={className} src={data.mediaItemUrl} srcSet={data.srcSet} />\n );\n } else if (\n path.slice(-1)[0] === \"content\" ||\n path.slice(-1)[0] === \"excerpt\"\n ) {\n return (\n <div className={className} dangerouslySetInnerHTML={{ __html: data }} />\n );\n } else if (!data || typeof data === \"object\") {\n return <div className={className}>Please specify a valid field.</div>;\n } else {\n return <div className={className}> {data} </div>;\n }\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport {\n WordpressFetcher,\n WordpressFetcherMeta,\n WordpressField,\n WordpressFieldMeta,\n WordpressProvider,\n WordpressProviderMeta,\n} from \"./wordpress\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n\n if (loader) {\n loader.registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n } else {\n registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n }\n\n _registerComponent(WordpressFetcher, WordpressFetcherMeta);\n _registerComponent(WordpressField, WordpressFieldMeta);\n}\n\nexport * from \"./wordpress\";\n"],"names":["ensure","x","undefined","Error","modulePath","CredentialsContext","React","createContext","WordpressProviderMeta","name","displayName","description","importName","importPath","props","graphqlEndpoint","type","defaultValue","WordpressProvider","_ref","children","Provider","value","WordpressFetcherMeta","providesData","defaultStyles","display","gridTemplateColumns","gridRowGap","gridColumnGap","padding","maxWidth","styles","query","lang","endpoint","ctx","_ctx$endpoint","noAutoRepeat","noLayout","compact","arr","filter","WordpressFetcher","_ref2","className","setControlContextData","creds","useContext","cacheKey","JSON","stringify","_usePlasmicQueryData","usePlasmicQueryData","_asyncToGenerator","_regeneratorRuntime","mark","_callee","data","wrap","_callee$","_context","prev","next","abrupt","fetch","method","body","headers","sent","json","stop","Object","values","length","renderedData","flatMap","model","i","Array","isArray","map","item","j","DataProvider","key","repeatedElement","WordpressFieldMeta","path","_ctx$data","WordpressField","_ref4","useSelector","get","mediaType","src","mediaItemUrl","srcSet","slice","dangerouslySetInnerHTML","__html","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent","registerGlobalContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAWgBA,MAAMA,CAAIC,CAAuB;EAC/C,IAAIA,CAAC,KAA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qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;GACvE,MAAM;IACLmG,qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;;EAGjE+F,kBAAkB,CAAC5D,gBAAgB,EAAEpB,oBAAoB,CAAC;EAC1DgF,kBAAkB,CAACb,cAAc,EAAEH,kBAAkB,CAAC;AACxD;;;;;;;;;;;"}
|
|
@@ -439,7 +439,7 @@ function WordpressFetcher(_ref2) {
|
|
|
439
439
|
query: query,
|
|
440
440
|
creds: creds
|
|
441
441
|
});
|
|
442
|
-
var _usePlasmicQueryData = usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator(
|
|
442
|
+
var _usePlasmicQueryData = usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
443
443
|
var data;
|
|
444
444
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
445
445
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plasmic-wordpress-graphql.esm.js","sources":["../src/wordpress.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n GlobalContextMeta,\n repeatedElement,\n useSelector,\n} from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport get from \"dlv\";\nimport React, { ReactNode, useContext } from \"react\";\n\nexport function ensure<T>(x: T | null | undefined): T {\n if (x === null || x === undefined) {\n debugger;\n throw new Error(`Value must not be undefined or null`);\n } else {\n return x;\n }\n}\n\nconst modulePath = \"@plasmicpkgs/plasmic-wordpress-graphql\";\n\ninterface WordpressProviderProps {\n graphqlEndpoint: string;\n}\n\nconst CredentialsContext = React.createContext<\n WordpressProviderProps | undefined\n>(undefined);\n\nexport const WordpressProviderMeta: GlobalContextMeta<WordpressProviderProps> = {\n name: \"WordpressGraphQLProvider\",\n displayName: \"Wordpress GraphQL Provider\",\n description: \"The GraphQL API Endpoint of your Wordpress\",\n importName: \"WordpressProvider\",\n importPath: modulePath,\n props: {\n graphqlEndpoint: {\n type: \"string\",\n displayName: \"GraphQL API Endpoint\",\n description: \"GraphQL API Endpoint of your Wordpress\",\n defaultValue: \"https://demo.wpgraphql.com/graphql\",\n },\n },\n};\n\nexport function WordpressProvider({\n graphqlEndpoint,\n children,\n}: React.PropsWithChildren<WordpressProviderProps>) {\n return (\n <CredentialsContext.Provider value={{ graphqlEndpoint }}>\n {children}\n </CredentialsContext.Provider>\n );\n}\n\ninterface WordpressFetcherProps {\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n query?: string;\n setControlContextData?: (data: { endpoint?: string }) => void;\n}\n\nexport const WordpressFetcherMeta: ComponentMeta<WordpressFetcherProps> = {\n name: \"WordpressGraphQLFetcher\",\n displayName: \"Wordpress Fetcher\",\n importName: \"WordpressFetcher\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Wordpress data and repeats content of children once for every row fetched. \",\n defaultStyles: {\n display: \"grid\",\n gridTemplateColumns: \"1fr 1fr 1fr 1fr\",\n gridRowGap: \"8px\",\n gridColumnGap: \"8px\",\n padding: \"8px\",\n maxWidth: \"100%\",\n },\n props: {\n children: {\n type: \"slot\",\n defaultValue: {\n type: \"vbox\",\n styles: {\n padding: \"8px\",\n },\n children: {\n type: \"component\",\n name: \"WordpressGraphQLField\",\n },\n },\n },\n query: {\n type: \"code\",\n lang: \"graphql\",\n endpoint: (props, ctx) => ctx?.endpoint ?? \"\",\n },\n noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every entry.\",\n defaultValue: false,\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Wordpress Fetcher will not layout its children; instead, the layout set on its parent element will be used. Useful if you want to set flex gap or control container tag type.\",\n defaultValue: false,\n },\n },\n};\n\nfunction compact(arr: any[]) {\n return arr.filter((x) => !!x);\n}\n\nexport function WordpressFetcher({\n query,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: WordpressFetcherProps) {\n const creds = ensure(useContext(CredentialsContext));\n const cacheKey = JSON.stringify({\n query,\n creds,\n });\n const { data } = usePlasmicQueryData<any | null>(cacheKey, async () => {\n if (!query) {\n return null;\n }\n const data = await fetch(creds.graphqlEndpoint, {\n method: \"POST\",\n body: JSON.stringify(query),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n return await data.json();\n });\n\n setControlContextData?.({\n endpoint: creds.graphqlEndpoint,\n });\n\n if (!query) {\n return <div>Please make a query in order to fetch data</div>;\n }\n\n if (!creds.graphqlEndpoint) {\n return (\n <div>\n Please specify a valid API Credentials: GraphQL Endpoint of your\n Wordpress project\n </div>\n );\n }\n\n if (!data?.data || compact(Object.values(data?.data)).length === 0) {\n return <div>Data not found</div>;\n }\n\n const renderedData = noAutoRepeat\n ? children\n : Object.values(data?.data).flatMap((model: any, i: number) =>\n (Array.isArray(model) ? model : [model]).map((item: any, j: number) => (\n <DataProvider\n key={JSON.stringify(item)}\n name={\"currentWordpressItem\"}\n data={item}\n >\n {repeatedElement(i === 0 && j === 0, children)}\n </DataProvider>\n ))\n );\n return noLayout ? (\n <> {renderedData} </>\n ) : (\n <div className={className}> {renderedData} </div>\n );\n}\n\ninterface WordpressFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: { data: any }) => void;\n}\nexport const WordpressFieldMeta: ComponentMeta<WordpressFieldProps> = {\n name: \"WordpressGraphQLField\",\n displayName: \"Wordpress Field\",\n importName: \"WordpressField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"dataSelector\",\n data: (props: any, ctx: any) => ctx?.data ?? {},\n displayName: \"Field\",\n description: \"Field to be displayed.\",\n },\n },\n};\nexport function WordpressField({\n className,\n path,\n setControlContextData,\n}: WordpressFieldProps) {\n const item = useSelector(\"currentWordpressItem\");\n\n if (!item) {\n return <div>WordpressField must be used within a WordpressFetcher </div>;\n }\n\n setControlContextData?.({\n data: item,\n });\n\n if (!path) {\n return <div>Please specify a valid path or select a field.</div>;\n }\n const data = get(item, path as string);\n if (typeof data === \"object\" && data.mediaType === \"image\") {\n return (\n <img className={className} src={data.mediaItemUrl} srcSet={data.srcSet} />\n );\n } else if (\n path.slice(-1)[0] === \"content\" ||\n path.slice(-1)[0] === \"excerpt\"\n ) {\n return (\n <div className={className} dangerouslySetInnerHTML={{ __html: data }} />\n );\n } else if (!data || typeof data === \"object\") {\n return <div className={className}>Please specify a valid field.</div>;\n } else {\n return <div className={className}> {data} </div>;\n }\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport {\n WordpressFetcher,\n WordpressFetcherMeta,\n WordpressField,\n WordpressFieldMeta,\n WordpressProvider,\n WordpressProviderMeta,\n} from \"./wordpress\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n\n if (loader) {\n loader.registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n } else {\n registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n }\n\n _registerComponent(WordpressFetcher, WordpressFetcherMeta);\n _registerComponent(WordpressField, WordpressFieldMeta);\n}\n\nexport * from \"./wordpress\";\n"],"names":["ensure","x","undefined","Error","modulePath","CredentialsContext","React","createContext","WordpressProviderMeta","name","displayName","description","importName","importPath","props","graphqlEndpoint","type","defaultValue","WordpressProvider","_ref","children","Provider","value","WordpressFetcherMeta","providesData","defaultStyles","display","gridTemplateColumns","gridRowGap","gridColumnGap","padding","maxWidth","styles","query","lang","endpoint","ctx","_ctx$endpoint","noAutoRepeat","noLayout","compact","arr","filter","WordpressFetcher","_ref2","className","setControlContextData","creds","useContext","cacheKey","JSON","stringify","_usePlasmicQueryData","usePlasmicQueryData","_asyncToGenerator","_regeneratorRuntime","mark","_callee","data","wrap","_callee$","_context","prev","next","abrupt","fetch","method","body","headers","sent","json","stop","Object","values","length","renderedData","flatMap","model","i","Array","isArray","map","item","j","DataProvider","key","repeatedElement","WordpressFieldMeta","path","_ctx$data","WordpressField","_ref4","useSelector","get","mediaType","src","mediaItemUrl","srcSet","slice","dangerouslySetInnerHTML","__html","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent","registerGlobalContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAWgBA,MAAMA,CAAIC,CAAuB;EAC/C,IAAIA,CAAC,KAAK,IAAI,IAAIA,CAAC,KAAKC,SAAS,EAAE;IACjC;IACA,MAAM,IAAIC,KAAK,sCAAsC,CAAC;GACvD,MAAM;IACL,OAAOF,CAAC;;AAEZ;AAEA,IAAMG,UAAU,GAAG,wCAAwC;AAM3D,IAAMC,kBAAkB,gBAAGC,KAAK,CAACC,aAAa,CAE5CL,SAAS,CAAC;IAECM,qBAAqB,GAA8C;EAC9EC,IAAI,EAAE,0BAA0B;EAChCC,WAAW,EAAE,4BAA4B;EACzCC,WAAW,EAAE,4CAA4C;EACzDC,UAAU,EAAE,mBAAmB;EAC/BC,UAA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S,EAAEA,SAAS;MAAEkD,GAAG,EAAErC,IAAI,CAACsC,YAAY;MAAEC,MAAM,EAAEvC,IAAI,CAACuC;MAAU;GAE7E,MAAM,IACLT,IAAI,CAACU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,IAC/BV,IAAI,CAACU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,EAC/B;IACA,OACE5F;MAAKuC,SAAS,EAAEA,SAAS;MAAEsD,uBAAuB,EAAE;QAAEC,MAAM,EAAE1C;;MAAU;GAE3E,MAAM,IAAI,CAACA,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAC5C,OAAOpD;MAAKuC,SAAS,EAAEA;uCAA8C;GACtE,MAAM;IACL,OAAOvC;MAAKuC,SAAS,EAAEA;YAAaa,IAAI,MAAQ;;AAEpD;;SCtOgB2C,WAAWA,CAACC,MAG3B;EACC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CACtBC,SAAY,EACZC,WAAmD;IAEnD,IAAIH,MAAM,EAAE;MACVA,MAAM,CAACI,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;KACjD,MAAM;MACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAED,IAAIH,MAAM,EAAE;IACVA,MAAM,CAACK,qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;GACvE,MAAM;IACLmG,qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;;EAGjE+F,kBAAkB,CAAC5D,gBAAgB,EAAEpB,oBAAoB,CAAC;EAC1DgF,kBAAkB,CAACb,cAAc,EAAEH,kBAAkB,CAAC;AACxD;;;;"}
|
|
1
|
+
{"version":3,"file":"plasmic-wordpress-graphql.esm.js","sources":["../src/wordpress.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n GlobalContextMeta,\n repeatedElement,\n useSelector,\n} from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport get from \"dlv\";\nimport React, { ReactNode, useContext } from \"react\";\n\nexport function ensure<T>(x: T | null | undefined): T {\n if (x === null || x === undefined) {\n debugger;\n throw new Error(`Value must not be undefined or null`);\n } else {\n return x;\n }\n}\n\nconst modulePath = \"@plasmicpkgs/plasmic-wordpress-graphql\";\n\ninterface WordpressProviderProps {\n graphqlEndpoint: string;\n}\n\nconst CredentialsContext = React.createContext<\n WordpressProviderProps | undefined\n>(undefined);\n\nexport const WordpressProviderMeta: GlobalContextMeta<WordpressProviderProps> = {\n name: \"WordpressGraphQLProvider\",\n displayName: \"Wordpress GraphQL Provider\",\n description: \"The GraphQL API Endpoint of your Wordpress\",\n importName: \"WordpressProvider\",\n importPath: modulePath,\n props: {\n graphqlEndpoint: {\n type: \"string\",\n displayName: \"GraphQL API Endpoint\",\n description: \"GraphQL API Endpoint of your Wordpress\",\n defaultValue: \"https://demo.wpgraphql.com/graphql\",\n },\n },\n};\n\nexport function WordpressProvider({\n graphqlEndpoint,\n children,\n}: React.PropsWithChildren<WordpressProviderProps>) {\n return (\n <CredentialsContext.Provider value={{ graphqlEndpoint }}>\n {children}\n </CredentialsContext.Provider>\n );\n}\n\ninterface WordpressFetcherProps {\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n query?: string;\n setControlContextData?: (data: { endpoint?: string }) => void;\n}\n\nexport const WordpressFetcherMeta: ComponentMeta<WordpressFetcherProps> = {\n name: \"WordpressGraphQLFetcher\",\n displayName: \"Wordpress Fetcher\",\n importName: \"WordpressFetcher\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Wordpress data and repeats content of children once for every row fetched. \",\n defaultStyles: {\n display: \"grid\",\n gridTemplateColumns: \"1fr 1fr 1fr 1fr\",\n gridRowGap: \"8px\",\n gridColumnGap: \"8px\",\n padding: \"8px\",\n maxWidth: \"100%\",\n },\n props: {\n children: {\n type: \"slot\",\n defaultValue: {\n type: \"vbox\",\n styles: {\n padding: \"8px\",\n },\n children: {\n type: \"component\",\n name: \"WordpressGraphQLField\",\n },\n },\n },\n query: {\n type: \"code\",\n lang: \"graphql\",\n endpoint: (props, ctx) => ctx?.endpoint ?? \"\",\n },\n noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every entry.\",\n defaultValue: false,\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Wordpress Fetcher will not layout its children; instead, the layout set on its parent element will be used. Useful if you want to set flex gap or control container tag type.\",\n defaultValue: false,\n },\n },\n};\n\nfunction compact(arr: any[]) {\n return arr.filter((x) => !!x);\n}\n\nexport function WordpressFetcher({\n query,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: WordpressFetcherProps) {\n const creds = ensure(useContext(CredentialsContext));\n const cacheKey = JSON.stringify({\n query,\n creds,\n });\n const { data } = usePlasmicQueryData<any | null>(cacheKey, async () => {\n if (!query) {\n return null;\n }\n const data = await fetch(creds.graphqlEndpoint, {\n method: \"POST\",\n body: JSON.stringify(query),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n return await data.json();\n });\n\n setControlContextData?.({\n endpoint: creds.graphqlEndpoint,\n });\n\n if (!query) {\n return <div>Please make a query in order to fetch data</div>;\n }\n\n if (!creds.graphqlEndpoint) {\n return (\n <div>\n Please specify a valid API Credentials: GraphQL Endpoint of your\n Wordpress project\n </div>\n );\n }\n\n if (!data?.data || compact(Object.values(data?.data)).length === 0) {\n return <div>Data not found</div>;\n }\n\n const renderedData = noAutoRepeat\n ? children\n : Object.values(data?.data).flatMap((model: any, i: number) =>\n (Array.isArray(model) ? model : [model]).map((item: any, j: number) => (\n <DataProvider\n key={JSON.stringify(item)}\n name={\"currentWordpressItem\"}\n data={item}\n >\n {repeatedElement(i === 0 && j === 0, children)}\n </DataProvider>\n ))\n );\n return noLayout ? (\n <> {renderedData} </>\n ) : (\n <div className={className}> {renderedData} </div>\n );\n}\n\ninterface WordpressFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: { data: any }) => void;\n}\nexport const WordpressFieldMeta: ComponentMeta<WordpressFieldProps> = {\n name: \"WordpressGraphQLField\",\n displayName: \"Wordpress Field\",\n importName: \"WordpressField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"dataSelector\",\n data: (props: any, ctx: any) => ctx?.data ?? {},\n displayName: \"Field\",\n description: \"Field to be displayed.\",\n },\n },\n};\nexport function WordpressField({\n className,\n path,\n setControlContextData,\n}: WordpressFieldProps) {\n const item = useSelector(\"currentWordpressItem\");\n\n if (!item) {\n return <div>WordpressField must be used within a WordpressFetcher </div>;\n }\n\n setControlContextData?.({\n data: item,\n });\n\n if (!path) {\n return <div>Please specify a valid path or select a field.</div>;\n }\n const data = get(item, path as string);\n if (typeof data === \"object\" && data.mediaType === \"image\") {\n return (\n <img className={className} src={data.mediaItemUrl} srcSet={data.srcSet} />\n );\n } else if (\n path.slice(-1)[0] === \"content\" ||\n path.slice(-1)[0] === \"excerpt\"\n ) {\n return (\n <div className={className} dangerouslySetInnerHTML={{ __html: data }} />\n );\n } else if (!data || typeof data === \"object\") {\n return <div className={className}>Please specify a valid field.</div>;\n } else {\n return <div className={className}> {data} </div>;\n }\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport {\n WordpressFetcher,\n WordpressFetcherMeta,\n WordpressField,\n WordpressFieldMeta,\n WordpressProvider,\n WordpressProviderMeta,\n} from \"./wordpress\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n\n if (loader) {\n loader.registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n } else {\n registerGlobalContext(WordpressProvider, WordpressProviderMeta);\n }\n\n _registerComponent(WordpressFetcher, WordpressFetcherMeta);\n _registerComponent(WordpressField, WordpressFieldMeta);\n}\n\nexport * from \"./wordpress\";\n"],"names":["ensure","x","undefined","Error","modulePath","CredentialsContext","React","createContext","WordpressProviderMeta","name","displayName","description","importName","importPath","props","graphqlEndpoint","type","defaultValue","WordpressProvider","_ref","children","Provider","value","WordpressFetcherMeta","providesData","defaultStyles","display","gridTemplateColumns","gridRowGap","gridColumnGap","padding","maxWidth","styles","query","lang","endpoint","ctx","_ctx$endpoint","noAutoRepeat","noLayout","compact","arr","filter","WordpressFetcher","_ref2","className","setControlContextData","creds","useContext","cacheKey","JSON","stringify","_usePlasmicQueryData","usePlasmicQueryData","_asyncToGenerator","_regeneratorRuntime","mark","_callee","data","wrap","_callee$","_context","prev","next","abrupt","fetch","method","body","headers","sent","json","stop","Object","values","length","renderedData","flatMap","model","i","Array","isArray","map","item","j","DataProvider","key","repeatedElement","WordpressFieldMeta","path","_ctx$data","WordpressField","_ref4","useSelector","get","mediaType","src","mediaItemUrl","srcSet","slice","dangerouslySetInnerHTML","__html","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent","registerGlobalContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AEC,WAAW,CAAC;;GAE5C;EAED,IAAIH,MAAM,EAAE;IACVA,MAAM,CAACK,qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;GACvE,MAAM;IACLmG,qBAAqB,CAACzF,iBAAiB,EAAEV,qBAAqB,CAAC;;EAGjE+F,kBAAkB,CAAC5D,gBAAgB,EAAEpB,oBAAoB,CAAC;EAC1DgF,kBAAkB,CAACb,cAAc,EAAEH,kBAAkB,CAAC;AACxD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicpkgs/plasmic-wordpress-graphql",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.127",
|
|
4
4
|
"description": "Plasmic Wordpress GraphQL components.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@plasmicapp/host": "1.0.
|
|
37
|
+
"@plasmicapp/host": "1.0.211",
|
|
38
38
|
"@plasmicapp/query": "0.1.79",
|
|
39
39
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
40
40
|
"@types/react": "^18.0.27",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"@types/dlv": "^1.1.2",
|
|
51
51
|
"dlv": "^1.1.3"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "93119895a0d403158e497a0abdccdcb24d670fb7"
|
|
54
54
|
}
|