UNPKG

next-slicezone

Version:

A component that maps other components to Prismic slices

2 lines (1 loc) 6.13 kB
import e from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/regenerator";import n from"@babel/runtime/helpers/toConsumableArray";import a from"@babel/runtime/helpers/objectWithoutProperties";var o=["uid"],i=["repeat","repeatable","multi"];function s(e){return c.apply(this,arguments)}function c(){return(c=r(t.mark((function e(r){var s,c,u,p,l,f,d;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=r.queryType,c=r.apiParams,u=r.type,p=r.client,l=c.uid,f=a(c,o),d=-1!==i.indexOf(s)?["getByUID",[u,l,f]]:["getSingle",[u,f]],e.next=5,p[d[0]].apply(p,n(d[1]));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function u(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function p(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?u(Object(n),!0).forEach((function(t){e(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}var l=function(e,r){var t;if(e)if(r)r in e.data&&Array.isArray(e.data[r])?t=e.data[r]:console.error("[SliceZone/useGetStaticProps] Cannot find slice zone at specified key `%s`\n\nCheck the document below to make sure you provided the right key:",r,e.data);else{for(var n=0,a=["body","slices"];n<a.length;n++){var o=a[n];if(o in e.data&&Array.isArray(e.data[o])){t=e.data[o];break}}t||console.error('[SliceZone/useGetStaticProps] Cannot find slice zone in document\n\nCheck the document below to make sure your slice zone is here or provide the `slicesKey` option:\n\nuseGetStaticProps({ /* ... */ slicesKey: "mySliceZone" });\n',e.data)}return t||[]},f=function(e){var n=e.client,a=e.slicesKey,o=e.type,i=void 0===o?"page":o,c=e.getStaticPropsParams,u=void 0===c?{}:c,f=e.queryType,d=void 0===f?"repeat":f,y=e.apiParams,b=e.uid,v=e.lang,m=e.body;return b&&console.warn('[next-slicezone/useGetStaticProps]: Parameter "uid" is deprecated, use "apiParams.uid" instead.'),v&&console.warn('[next-slicezone/useGetStaticProps]: Parameter "lang" is deprecated, use "apiParams.lang" instead.'),m&&console.warn('[next-slicezone/useGetStaticProps]: Parameter "body" is deprecated, use "slicesKey" instead.'),function(){var e=r(t.mark((function e(r){var o,c,f,b,v,h,P,g,w,O;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=r.preview,c=void 0===o?null:o,f=r.previewData,b=void 0===f?{}:f,v=r.params,h=void 0===v?{}:v,P=b.ref,g=void 0===P?null:P,w=y&&"function"==typeof y?y({params:h,previewData:b,preview:c}):y,e.prev=3,e.next=6,s({queryType:d,apiParams:Object.assign({ref:g},w),type:i,client:n});case 6:return O=e.sent,e.abrupt("return",p({props:p(p({},O),{},{error:null,preview:c,previewData:b,slices:l(O,a||m)})},u));case 10:return e.prev=10,e.t0=e.catch(3),"production"!==process.env.NODE_ENV&&console.error("[next-slicezone] ".concat(e.t0.toString())),e.abrupt("return",p({props:{ref:g,error:e.t0.toString(),apiParams:y,slices:[],preview:c,previewData:b}},u));case 14:case"end":return e.stop()}}),e,null,[[3,10]])})));return function(r){return e.apply(this,arguments)}}()};function d(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function y(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){e(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}function b(e,r,t){return v.apply(this,arguments)}function v(){return(v=r(t.mark((function e(r,a,o){var i,s,c,u,p=arguments;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=p.length>3&&void 0!==p[3]?p[3]:1,s=p.length>4&&void 0!==p[4]?p[4]:[],e.next=4,r.query('[at(document.type, "'.concat(a,'")]'),y(y({pageSize:100,lang:"*"},o),{},{page:i}));case 4:if(c=e.sent,u=s.concat(c.results),!(c.results_size+s.length<c.total_results_size)){e.next=8;break}return e.abrupt("return",b(r,a,o,i+1,u));case 8:return e.abrupt("return",n(new Set(u)));case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function m(e,r){return h.apply(this,arguments)}function h(){return(h=r(t.mark((function e(r,n){var a,o=arguments;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=o.length>2&&void 0!==o[2]?o[2]:{},e.next=3,b(r,n,a);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var P=function(e){var a=e.type,o=void 0===a?"page":a,i=e.formatPath,s=void 0===i?function(){return null}:i,c=e.apiParams,u=e.client,p=e.getStaticPathsParams,l=void 0===p?{fallback:!1}:p,f=e.lang,d=e.params,b=e.fallback;!function(e){null!=e&&console.warn("[next-slicezone] Parameter `fallback` is deprecated. Use getStaticPathsParams.fallback instead.")}(b);var v=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;return(arguments.length>2?arguments[2]:void 0)&&console.warn("[next-slicezone] Parameter `lang` is deprecated. Use `apiParams.lang` instead."),r?(console.warn("[next-slicezone] Parameter `params` is deprecated. Use `apiParams` instead."),r):e}(c,d,f);return function(){var e=r(t.mark((function e(){var r;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,m(u,o,v);case 2:return r=e.sent,e.abrupt("return",y({paths:r.reduce((function(e,r){var t=s(r);return t?[].concat(n(e),[t]):e}),[]),fallback:b},l));case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}()};export{P as useGetStaticPaths,f as useGetStaticProps};