sanity-plugin-dashboard-widget-document-list 1.0.0 → 1.0.1

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.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}import{jsx as n,jsxs as i}from"react/jsx-runtime";import{useState as o,useMemo as c,useEffect as a}from"react";import{useClient as s,useSchema as d,IntentButton as u,getPublishedId as p,SanityPreview as l}from"sanity";import{intersection as m}from"lodash";import{of as y}from"rxjs";import{switchMap as f,tap as h,delay as b,mergeMap as g}from"rxjs/operators";import w from"lodash/uniqBy";import{Card as O,Flex as j,Spinner as v,Stack as P}from"@sanity/ui";import{DashboardWidgetContainer as _}from"@sanity/dashboard";const x=e=>"drafts.".concat(e._id);function E(e,t,r){return r.listen(e,t,{events:["welcome","mutation"],includeResult:!1,visibility:"query"}).pipe(f((n=>y(1).pipe("welcome"===n.type?h():b(1e3),g((()=>r.fetch(e,t).then((e=>function(e,t){if(!e)return Promise.resolve([]);const r=Array.isArray(e)?e:[e],n=r.filter((e=>!e._id.startsWith("drafts."))).map(x);return t.fetch("*[_id in $ids]",{ids:n}).then((e=>{const t=r.map((t=>e.find((e=>e._id===x(t)))||t));return w(t,"_id")})).catch((e=>{throw new Error("Problems fetching docs ".concat(n,". Error: ").concat(e.message))}))}(e,r))).catch((r=>{if(r.message.startsWith("Problems fetching docs"))throw r;throw new Error("Query failed ".concat(e," and ").concat(JSON.stringify(t),". Error: ").concat(r.message))}))))))))}const q={title:"Last created",order:"_createdAt desc",limit:10,queryParams:{},showCreateButton:!0,apiVersion:"v1"};function B(e){const{query:r,limit:p,apiVersion:l,queryParams:y,types:f,order:h,title:b,showCreateButton:g,createButtonText:w}=t(t({},q),e),[x,B]=o(),[D,Q]=o(!0),[S,A]=o(),T=s({apiVersion:l}),V=d(),{assembledQuery:N,params:W}=c((()=>{if(r)return{assembledQuery:r,params:y};const e=V.getTypeNames().filter((e=>{var t;const r=V.get(e);return"document"===(null==(t=null==r?void 0:r.type)?void 0:t.name)}));return{assembledQuery:"*[_type in $types] | order(".concat(h,") [0...").concat(2*p,"]"),params:{types:f?m(f,e):e}}}),[V,r,y,h,p,f]);return a((()=>{if(!N)return;const e=E(N,W,T).subscribe({next:e=>{B(e.slice(0,p)),Q(!1)},error:e=>{A(e),Q(!1)}});return()=>{e.unsubscribe()}}),[p,T,N,W]),n(_,{header:b,footer:f&&1===f.length&&g&&n(u,{mode:"bleed",style:{width:"100%"},paddingX:2,paddingY:4,tone:"primary",type:"button",intent:"create",params:{type:f[0]},text:w||"Create new ".concat(f[0])}),children:i(O,{children:[S&&n("div",{children:S.message}),!S&&D&&n(O,{padding:4,children:n(j,{justify:"center",children:n(v,{muted:!0})})}),!S&&!x&&!D&&n("div",{children:"Could not locate any documents :/"}),n(P,{space:2,children:x&&x.map((e=>n(C,{doc:e},e._id)))})]})})}function C(e){let{doc:t}=e;const r=d().get(t._type);return n(O,{flex:1,children:n(u,{intent:"edit",mode:"bleed",padding:1,radius:0,params:{type:t._type,id:p(t._id)},style:{width:"100%"},children:r?n(l,{layout:"default",schemaType:r,value:t},t._id):"Schema-type missing"})})}function D(e){return{name:"document-list-widget",component:function(){return n(B,t({},e))},layout:e.layout}}export{D as documentListWidget};
1
+ function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}import{jsx as n,jsxs as i}from"react/jsx-runtime";import{useState as o,useMemo as c,useEffect as a}from"react";import{useClient as s,useSchema as d,IntentButton as u,getPublishedId as p,Preview as l}from"sanity";import{intersection as m}from"lodash";import{of as y}from"rxjs";import{switchMap as f,tap as h,delay as b,mergeMap as g}from"rxjs/operators";import w from"lodash/uniqBy";import{Card as O,Flex as j,Spinner as v,Stack as P}from"@sanity/ui";import{DashboardWidgetContainer as _}from"@sanity/dashboard";const x=e=>"drafts.".concat(e._id);function E(e,t,r){return r.listen(e,t,{events:["welcome","mutation"],includeResult:!1,visibility:"query"}).pipe(f((n=>y(1).pipe("welcome"===n.type?h():b(1e3),g((()=>r.fetch(e,t).then((e=>function(e,t){if(!e)return Promise.resolve([]);const r=Array.isArray(e)?e:[e],n=r.filter((e=>!e._id.startsWith("drafts."))).map(x);return t.fetch("*[_id in $ids]",{ids:n}).then((e=>{const t=r.map((t=>e.find((e=>e._id===x(t)))||t));return w(t,"_id")})).catch((e=>{throw new Error("Problems fetching docs ".concat(n,". Error: ").concat(e.message))}))}(e,r))).catch((r=>{if(r.message.startsWith("Problems fetching docs"))throw r;throw new Error("Query failed ".concat(e," and ").concat(JSON.stringify(t),". Error: ").concat(r.message))}))))))))}const q={title:"Last created",order:"_createdAt desc",limit:10,queryParams:{},showCreateButton:!0,apiVersion:"v1"};function B(e){const{query:r,limit:p,apiVersion:l,queryParams:y,types:f,order:h,title:b,showCreateButton:g,createButtonText:w}=t(t({},q),e),[x,B]=o(),[D,Q]=o(!0),[S,A]=o(),T=s({apiVersion:l}),V=d(),{assembledQuery:N,params:W}=c((()=>{if(r)return{assembledQuery:r,params:y};const e=V.getTypeNames().filter((e=>{var t;const r=V.get(e);return"document"===(null==(t=null==r?void 0:r.type)?void 0:t.name)}));return{assembledQuery:"*[_type in $types] | order(".concat(h,") [0...").concat(2*p,"]"),params:{types:f?m(f,e):e}}}),[V,r,y,h,p,f]);return a((()=>{if(!N)return;const e=E(N,W,T).subscribe({next:e=>{B(e.slice(0,p)),Q(!1)},error:e=>{A(e),Q(!1)}});return()=>{e.unsubscribe()}}),[p,T,N,W]),n(_,{header:b,footer:f&&1===f.length&&g&&n(u,{mode:"bleed",style:{width:"100%"},paddingX:2,paddingY:4,tone:"primary",type:"button",intent:"create",params:{type:f[0]},text:w||"Create new ".concat(f[0])}),children:i(O,{children:[S&&n("div",{children:S.message}),!S&&D&&n(O,{padding:4,children:n(j,{justify:"center",children:n(v,{muted:!0})})}),!S&&!x&&!D&&n("div",{children:"Could not locate any documents :/"}),n(P,{space:2,children:x&&x.map((e=>n(C,{doc:e},e._id)))})]})})}function C(e){let{doc:t}=e;const r=d().get(t._type);return n(O,{flex:1,children:n(u,{intent:"edit",mode:"bleed",padding:1,radius:0,params:{type:t._type,id:p(t._id)},style:{width:"100%"},children:r?n(l,{layout:"default",schemaType:r,value:t},t._id):"Schema-type missing"})})}function D(e){return{name:"document-list-widget",component:function(){return n(B,t({},e))},layout:e.layout}}export{D as documentListWidget};
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/sanityConnector.ts","../src/DocumentList.tsx","../src/plugin.tsx"],"sourcesContent":["import {Observable, of as observableOf} from 'rxjs'\nimport {delay, mergeMap, switchMap, tap} from 'rxjs/operators'\nimport uniqBy from 'lodash/uniqBy'\nimport {SanityClient} from '@sanity/client'\nimport {SanityDocument} from 'sanity'\n\nconst draftId = (nonDraftDoc: SanityDocument) => `drafts.${nonDraftDoc._id}`\n\nfunction prepareDocumentList(\n incoming: SanityDocument | SanityDocument[],\n client: SanityClient\n): Promise<SanityDocument[]> {\n if (!incoming) {\n return Promise.resolve([])\n }\n const documents = Array.isArray(incoming) ? incoming : [incoming]\n\n const ids = documents.filter((doc) => !doc._id.startsWith('drafts.')).map(draftId)\n\n return client\n .fetch<SanityDocument[]>('*[_id in $ids]', {ids})\n .then((drafts) => {\n const outgoing = documents.map((doc) => {\n const foundDraft = drafts.find((draft) => draft._id === draftId(doc))\n return foundDraft || doc\n })\n return uniqBy(outgoing, '_id')\n })\n .catch((error) => {\n throw new Error(`Problems fetching docs ${ids}. Error: ${error.message}`)\n })\n}\n\nexport function getSubscription(\n query: string,\n params: Record<string, any>,\n client: SanityClient\n): Observable<SanityDocument[]> {\n return client\n .listen(query, params, {\n events: ['welcome', 'mutation'],\n includeResult: false,\n visibility: 'query',\n })\n .pipe(\n switchMap((event) => {\n return observableOf(1).pipe(\n event.type === 'welcome' ? tap() : delay(1000),\n mergeMap(() =>\n client\n .fetch(query, params)\n .then((incoming) => {\n return prepareDocumentList(incoming, client)\n })\n .catch((error) => {\n if (error.message.startsWith('Problems fetching docs')) {\n throw error\n }\n throw new Error(\n `Query failed ${query} and ${JSON.stringify(params)}. Error: ${error.message}`\n )\n })\n )\n )\n })\n )\n}\n","import React, {useEffect, useMemo, useState} from 'react'\nimport {getPublishedId, useClient, useSchema} from 'sanity'\nimport {intersection} from 'lodash'\nimport {getSubscription} from './sanityConnector'\nimport {SanityDocument, IntentButton, SanityPreview} from 'sanity'\nimport {Card, Flex, Spinner, Stack} from '@sanity/ui'\nimport {DashboardWidgetContainer} from '@sanity/dashboard'\n\nexport interface DocumentListConfig {\n title?: string\n types?: string[]\n query?: string\n queryParams?: Record<string, any>\n order?: string\n limit?: number\n showCreateButton?: boolean\n createButtonText?: string\n apiVersion?: string\n}\n\nconst defaultProps = {\n title: 'Last created',\n order: '_createdAt desc',\n limit: 10,\n queryParams: {},\n showCreateButton: true,\n apiVersion: 'v1',\n}\n\nexport function DocumentList(props: DocumentListConfig) {\n const {\n query,\n limit,\n apiVersion,\n queryParams,\n types,\n order,\n title,\n showCreateButton,\n createButtonText,\n } = {\n ...defaultProps,\n ...props,\n }\n\n const [documents, setDocuments] = useState<SanityDocument[] | undefined>()\n const [loading, setLoading] = useState<boolean>(true)\n const [error, setError] = useState<Error | undefined>()\n\n const versionedClient = useClient({apiVersion})\n const schema = useSchema()\n\n const {assembledQuery, params} = useMemo(() => {\n if (query) {\n return {assembledQuery: query, params: queryParams}\n }\n\n const documentTypes = schema.getTypeNames().filter((typeName) => {\n const schemaType = schema.get(typeName)\n return schemaType?.type?.name === 'document'\n })\n\n return {\n assembledQuery: `*[_type in $types] | order(${order}) [0...${limit * 2}]`,\n params: {types: types ? intersection(types, documentTypes) : documentTypes},\n }\n }, [schema, query, queryParams, order, limit, types])\n\n useEffect(() => {\n if (!assembledQuery) {\n return\n }\n\n const subscription = getSubscription(assembledQuery, params, versionedClient).subscribe({\n next: (d) => {\n setDocuments(d.slice(0, limit))\n setLoading(false)\n },\n error: (e) => {\n setError(e)\n setLoading(false)\n },\n })\n // eslint-disable-next-line consistent-return\n return () => {\n subscription.unsubscribe()\n }\n }, [limit, versionedClient, assembledQuery, params])\n\n return (\n <DashboardWidgetContainer\n header={title}\n footer={\n types &&\n types.length === 1 &&\n showCreateButton && (\n <IntentButton\n mode=\"bleed\"\n style={{width: '100%'}}\n paddingX={2}\n paddingY={4}\n tone=\"primary\"\n type=\"button\"\n intent=\"create\"\n params={{type: types[0]}}\n text={createButtonText || `Create new ${types[0]}`}\n />\n )\n }\n >\n <Card>\n {error && <div>{error.message}</div>}\n {!error && loading && (\n <Card padding={4}>\n <Flex justify=\"center\">\n <Spinner muted />\n </Flex>\n </Card>\n )}\n {!error && !documents && !loading && <div>Could not locate any documents :/</div>}\n <Stack space={2}>\n {documents && documents.map((doc) => <MenuEntry key={doc._id} doc={doc} />)}\n </Stack>\n </Card>\n </DashboardWidgetContainer>\n )\n}\n\nfunction MenuEntry({doc}: {doc: SanityDocument}) {\n const schema = useSchema()\n const type = schema.get(doc._type)\n return (\n <Card flex={1}>\n <IntentButton\n intent=\"edit\"\n mode=\"bleed\"\n padding={1}\n radius={0}\n params={{\n type: doc._type,\n id: getPublishedId(doc._id),\n }}\n style={{width: '100%'}}\n >\n {type ? (\n <SanityPreview layout=\"default\" schemaType={type} value={doc} key={doc._id} />\n ) : (\n 'Schema-type missing'\n )}\n </IntentButton>\n </Card>\n )\n}\n\nexport default DocumentList\n","import DocumentList, {DocumentListConfig} from './DocumentList'\nimport React from 'react'\nimport {LayoutConfig, DashboardWidget} from '@sanity/dashboard'\n\nexport interface DocumentListWidgetConfig extends DocumentListConfig {\n layout?: LayoutConfig\n}\n\nexport function documentListWidget(config: DocumentListWidgetConfig): DashboardWidget {\n return {\n name: 'document-list-widget',\n component: function component() {\n return <DocumentList {...config} />\n },\n layout: config.layout,\n }\n}\n"],"names":["draftId","nonDraftDoc","_id","getSubscription","query","params","client","listen","events","includeResult","visibility","pipe","switchMap","event","observableOf","type","tap","delay","mergeMap","fetch","then","incoming","Promise","resolve","documents","Array","isArray","ids","filter","doc","startsWith","map","drafts","outgoing","find","draft","uniqBy","catch","error","Error","message","prepareDocumentList","JSON","stringify","defaultProps","title","order","limit","queryParams","showCreateButton","apiVersion","DocumentList","props","types","createButtonText","setDocuments","useState","loading","setLoading","setError","versionedClient","useClient","schema","useSchema","assembledQuery","useMemo","documentTypes","getTypeNames","typeName","_a","schemaType","get","name","concat","intersection","useEffect","subscription","subscribe","next","d","slice","e","unsubscribe","jsx","DashboardWidgetContainer","header","footer","length","IntentButton","mode","style","width","paddingX","paddingY","tone","intent","text","children","jsxs","Card","padding","Flex","justify","Spinner","muted","Stack","space","MenuEntry","_ref","_type","flex","radius","id","getPublishedId","SanityPreview","layout","value","documentListWidget","config","component","_objectSpread"],"mappings":"4rCAMA,MAAMA,EAAWC,oBAA0CA,EAAYC,KA2BvD,SAAAC,EACdC,EACAC,EACAC,GAEO,OAAAA,EACJC,OAAOH,EAAOC,EAAQ,CACrBG,OAAQ,CAAC,UAAW,YACpBC,eAAe,EACfC,WAAY,UAEbC,KACCC,GAAWC,GACFC,EAAa,GAAGH,KACN,YAAfE,EAAME,KAAqBC,IAAQC,EAAM,KACzCC,GAAS,IACPZ,EACGa,MAAMf,EAAOC,GACbe,MAAMC,GA3CrB,SACEA,EACAf,GAEA,IAAKe,EACI,OAAAC,QAAQC,QAAQ,IAEzB,MAAMC,EAAYC,MAAMC,QAAQL,GAAYA,EAAW,CAACA,GAElDM,EAAMH,EAAUI,QAAQC,IAASA,EAAI3B,IAAI4B,WAAW,aAAYC,IAAI/B,GAEnE,OAAAM,EACJa,MAAwB,iBAAkB,CAACQ,QAC3CP,MAAMY,IACL,MAAMC,EAAWT,EAAUO,KAAKF,GACXG,EAAOE,MAAMC,GAAUA,EAAMjC,MAAQF,EAAQ6B,MAC3CA,IAEhB,OAAAO,EAAOH,EAAU,MAAK,IAE9BI,OAAOC,IACN,MAAM,IAAIC,MAAgCZ,0BAAAA,OAAAA,sBAAeW,EAAME,SAAS,GAE9E,CAqBuBC,CAAoBpB,EAAUf,KAEtC+B,OAAOC,IACN,GAAIA,EAAME,QAAQV,WAAW,0BACrB,MAAAQ,EAER,MAAM,IAAIC,MACQnC,gBAAAA,OAAAA,kBAAasC,KAAKC,UAAUtC,uBAAmBiC,EAAME,SACvE,SAMhB,CC9CA,MAAMI,EAAe,CACnBC,MAAO,eACPC,MAAO,kBACPC,MAAO,GACPC,YAAa,CAAC,EACdC,kBAAkB,EAClBC,WAAY,MAGP,SAASC,EAAaC,GACrB,MAAAhD,MACJA,EAAA2C,MACAA,EAAAG,WACAA,EAAAF,YACAA,EAAAK,MACAA,EAAAP,MACAA,EAAAD,MACA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1C,GAAoB,cAAAmB,OAAcpB,EAAM,MAKpD4C,SAACC,EAAAC,EAAA,CACEF,SAAA,CAAA3D,GAAU6C,EAAA,MAAA,CAAKc,SAAM3D,EAAAE,WACpBF,GAASmB,GACR0B,EAAAgB,EAAA,CAAKC,QAAS,EACbH,SAACd,EAAAkB,EAAA,CAAKC,QAAQ,SACZL,SAACd,EAAAoB,EAAA,CAAQC,OAAK,SAIlBlE,IAAUd,IAAciC,GAAY0B,EAAA,MAAA,CAAIc,SAAA,sCACzCd,EAAAsB,EAAA,CAAMC,MAAO,EACXT,SAAazE,GAAAA,EAAUO,KAAKF,GAASsD,EAAAwB,EAAA,CAAwB9E,OAATA,EAAI3B,aAKnE,CAEA,SAASyG,EAAwCC,GAAA,IAA9B/E,IAACA,GAA6B+E,EAC/C,MACM7F,EADSgD,IACKQ,IAAI1C,EAAIgF,OAC5B,OACG1B,EAAAgB,EAAA,CAAKW,KAAM,EACVb,SAACd,EAAAK,EAAA,CACCO,OAAO,OACPN,KAAK,QACLW,QAAS,EACTW,OAAQ,EACR1G,OAAQ,CACNU,KAAMc,EAAIgF,MACVG,GAAIC,EAAepF,EAAI3B,MAEzBwF,MAAO,CAACC,MAAO,QAEdM,WACEd,EAAA+B,EAAA,CAAcC,OAAO,UAAU7C,WAAYvD,EAAMqG,MAAOvF,GAAUA,EAAI3B,KAEvE,yBAKV,CChJO,SAASmH,EAAmBC,GAC1B,MAAA,CACL9C,KAAM,uBACN+C,UAAW,WACT,OAAQpC,EAAAhC,EAAAqE,EAAA,CAAA,EAAiBF,GAC3B,EACAH,OAAQG,EAAOH,OAEnB"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/sanityConnector.ts","../src/DocumentList.tsx","../src/plugin.tsx"],"sourcesContent":["import {Observable, of as observableOf} from 'rxjs'\nimport {delay, mergeMap, switchMap, tap} from 'rxjs/operators'\nimport uniqBy from 'lodash/uniqBy'\nimport {SanityClient} from '@sanity/client'\nimport {SanityDocument} from 'sanity'\n\nconst draftId = (nonDraftDoc: SanityDocument) => `drafts.${nonDraftDoc._id}`\n\nfunction prepareDocumentList(\n incoming: SanityDocument | SanityDocument[],\n client: SanityClient\n): Promise<SanityDocument[]> {\n if (!incoming) {\n return Promise.resolve([])\n }\n const documents = Array.isArray(incoming) ? incoming : [incoming]\n\n const ids = documents.filter((doc) => !doc._id.startsWith('drafts.')).map(draftId)\n\n return client\n .fetch<SanityDocument[]>('*[_id in $ids]', {ids})\n .then((drafts) => {\n const outgoing = documents.map((doc) => {\n const foundDraft = drafts.find((draft) => draft._id === draftId(doc))\n return foundDraft || doc\n })\n return uniqBy(outgoing, '_id')\n })\n .catch((error) => {\n throw new Error(`Problems fetching docs ${ids}. Error: ${error.message}`)\n })\n}\n\nexport function getSubscription(\n query: string,\n params: Record<string, any>,\n client: SanityClient\n): Observable<SanityDocument[]> {\n return client\n .listen(query, params, {\n events: ['welcome', 'mutation'],\n includeResult: false,\n visibility: 'query',\n })\n .pipe(\n switchMap((event) => {\n return observableOf(1).pipe(\n event.type === 'welcome' ? tap() : delay(1000),\n mergeMap(() =>\n client\n .fetch(query, params)\n .then((incoming) => {\n return prepareDocumentList(incoming, client)\n })\n .catch((error) => {\n if (error.message.startsWith('Problems fetching docs')) {\n throw error\n }\n throw new Error(\n `Query failed ${query} and ${JSON.stringify(params)}. Error: ${error.message}`\n )\n })\n )\n )\n })\n )\n}\n","import React, {useEffect, useMemo, useState} from 'react'\nimport {getPublishedId, useClient, useSchema} from 'sanity'\nimport {intersection} from 'lodash'\nimport {getSubscription} from './sanityConnector'\nimport {SanityDocument, IntentButton, Preview} from 'sanity'\nimport {Card, Flex, Spinner, Stack} from '@sanity/ui'\nimport {DashboardWidgetContainer} from '@sanity/dashboard'\n\nexport interface DocumentListConfig {\n title?: string\n types?: string[]\n query?: string\n queryParams?: Record<string, any>\n order?: string\n limit?: number\n showCreateButton?: boolean\n createButtonText?: string\n apiVersion?: string\n}\n\nconst defaultProps = {\n title: 'Last created',\n order: '_createdAt desc',\n limit: 10,\n queryParams: {},\n showCreateButton: true,\n apiVersion: 'v1',\n}\n\nexport function DocumentList(props: DocumentListConfig) {\n const {\n query,\n limit,\n apiVersion,\n queryParams,\n types,\n order,\n title,\n showCreateButton,\n createButtonText,\n } = {\n ...defaultProps,\n ...props,\n }\n\n const [documents, setDocuments] = useState<SanityDocument[] | undefined>()\n const [loading, setLoading] = useState<boolean>(true)\n const [error, setError] = useState<Error | undefined>()\n\n const versionedClient = useClient({apiVersion})\n const schema = useSchema()\n\n const {assembledQuery, params} = useMemo(() => {\n if (query) {\n return {assembledQuery: query, params: queryParams}\n }\n\n const documentTypes = schema.getTypeNames().filter((typeName) => {\n const schemaType = schema.get(typeName)\n return schemaType?.type?.name === 'document'\n })\n\n return {\n assembledQuery: `*[_type in $types] | order(${order}) [0...${limit * 2}]`,\n params: {types: types ? intersection(types, documentTypes) : documentTypes},\n }\n }, [schema, query, queryParams, order, limit, types])\n\n useEffect(() => {\n if (!assembledQuery) {\n return\n }\n\n const subscription = getSubscription(assembledQuery, params, versionedClient).subscribe({\n next: (d) => {\n setDocuments(d.slice(0, limit))\n setLoading(false)\n },\n error: (e) => {\n setError(e)\n setLoading(false)\n },\n })\n // eslint-disable-next-line consistent-return\n return () => {\n subscription.unsubscribe()\n }\n }, [limit, versionedClient, assembledQuery, params])\n\n return (\n <DashboardWidgetContainer\n header={title}\n footer={\n types &&\n types.length === 1 &&\n showCreateButton && (\n <IntentButton\n mode=\"bleed\"\n style={{width: '100%'}}\n paddingX={2}\n paddingY={4}\n tone=\"primary\"\n type=\"button\"\n intent=\"create\"\n params={{type: types[0]}}\n text={createButtonText || `Create new ${types[0]}`}\n />\n )\n }\n >\n <Card>\n {error && <div>{error.message}</div>}\n {!error && loading && (\n <Card padding={4}>\n <Flex justify=\"center\">\n <Spinner muted />\n </Flex>\n </Card>\n )}\n {!error && !documents && !loading && <div>Could not locate any documents :/</div>}\n <Stack space={2}>\n {documents && documents.map((doc) => <MenuEntry key={doc._id} doc={doc} />)}\n </Stack>\n </Card>\n </DashboardWidgetContainer>\n )\n}\n\nfunction MenuEntry({doc}: {doc: SanityDocument}) {\n const schema = useSchema()\n const type = schema.get(doc._type)\n return (\n <Card flex={1}>\n <IntentButton\n intent=\"edit\"\n mode=\"bleed\"\n padding={1}\n radius={0}\n params={{\n type: doc._type,\n id: getPublishedId(doc._id),\n }}\n style={{width: '100%'}}\n >\n {type ? (\n <Preview layout=\"default\" schemaType={type} value={doc} key={doc._id} />\n ) : (\n 'Schema-type missing'\n )}\n </IntentButton>\n </Card>\n )\n}\n\nexport default DocumentList\n","import DocumentList, {DocumentListConfig} from './DocumentList'\nimport React from 'react'\nimport {LayoutConfig, DashboardWidget} from '@sanity/dashboard'\n\nexport interface DocumentListWidgetConfig extends DocumentListConfig {\n layout?: LayoutConfig\n}\n\nexport function documentListWidget(config: DocumentListWidgetConfig): DashboardWidget {\n return {\n name: 'document-list-widget',\n component: function component() {\n return <DocumentList {...config} />\n },\n layout: config.layout,\n }\n}\n"],"names":["draftId","nonDraftDoc","_id","getSubscription","query","params","client","listen","events","includeResult","visibility","pipe","switchMap","event","observableOf","type","tap","delay","mergeMap","fetch","then","incoming","Promise","resolve","documents","Array","isArray","ids","filter","doc","startsWith","map","drafts","outgoing","find","draft","uniqBy","catch","error","Error","message","prepareDocumentList","JSON","stringify","defaultProps","title","order","limit","queryParams","showCreateButton","apiVersion","DocumentList","props","types","createButtonText","setDocuments","useState","loading","setLoading","setError","versionedClient","useClient","schema","useSchema","assembledQuery","useMemo","documentTypes","getTypeNames","typeName","_a","schemaType","get","name","concat","intersection","useEffect","subscription","subscribe","next","d","slice","e","unsubscribe","jsx","DashboardWidgetContainer","header","footer","length","IntentButton","mode","style","width","paddingX","paddingY","tone","intent","text","children","jsxs","Card","padding","Flex","justify","Spinner","muted","Stack","space","MenuEntry","_ref","_type","flex","radius","id","getPublishedId","Preview","layout","value","documentListWidget","config","component","_objectSpread"],"mappings":"srCAMA,MAAMA,EAAWC,oBAA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C,EAAA,MAAA,CAAKc,SAAM3D,EAAAE,WACpBF,GAASmB,GACR0B,EAAAgB,EAAA,CAAKC,QAAS,EACbH,SAACd,EAAAkB,EAAA,CAAKC,QAAQ,SACZL,SAACd,EAAAoB,EAAA,CAAQC,OAAK,SAIlBlE,IAAUd,IAAciC,GAAY0B,EAAA,MAAA,CAAIc,SAAA,sCACzCd,EAAAsB,EAAA,CAAMC,MAAO,EACXT,SAAazE,GAAAA,EAAUO,KAAKF,GAASsD,EAAAwB,EAAA,CAAwB9E,OAATA,EAAI3B,aAKnE,CAEA,SAASyG,EAAwCC,GAAA,IAA9B/E,IAACA,GAA6B+E,EAC/C,MACM7F,EADSgD,IACKQ,IAAI1C,EAAIgF,OAC5B,OACG1B,EAAAgB,EAAA,CAAKW,KAAM,EACVb,SAACd,EAAAK,EAAA,CACCO,OAAO,OACPN,KAAK,QACLW,QAAS,EACTW,OAAQ,EACR1G,OAAQ,CACNU,KAAMc,EAAIgF,MACVG,GAAIC,EAAepF,EAAI3B,MAEzBwF,MAAO,CAACC,MAAO,QAEdM,WACEd,EAAA+B,EAAA,CAAQC,OAAO,UAAU7C,WAAYvD,EAAMqG,MAAOvF,GAAUA,EAAI3B,KAEjE,yBAKV,CChJO,SAASmH,EAAmBC,GAC1B,MAAA,CACL9C,KAAM,uBACN+C,UAAW,WACT,OAAQpC,EAAAhC,EAAAqE,EAAA,CAAA,EAAiBF,GAC3B,EACAH,OAAQG,EAAOH,OAEnB"}
package/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react/jsx-runtime"),i=require("react"),s=require("sanity"),a=require("lodash"),o=require("rxjs"),c=require("rxjs/operators"),u=require("lodash/uniqBy"),d=require("@sanity/ui"),l=require("@sanity/dashboard");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var y=p(u);const f=e=>"drafts.".concat(e._id);function m(e,t,r){return r.listen(e,t,{events:["welcome","mutation"],includeResult:!1,visibility:"query"}).pipe(c.switchMap((n=>o.of(1).pipe("welcome"===n.type?c.tap():c.delay(1e3),c.mergeMap((()=>r.fetch(e,t).then((e=>function(e,t){if(!e)return Promise.resolve([]);const r=Array.isArray(e)?e:[e],n=r.filter((e=>!e._id.startsWith("drafts."))).map(f);return t.fetch("*[_id in $ids]",{ids:n}).then((e=>{const t=r.map((t=>e.find((e=>e._id===f(t)))||t));return y.default(t,"_id")})).catch((e=>{throw new Error("Problems fetching docs ".concat(n,". Error: ").concat(e.message))}))}(e,r))).catch((r=>{if(r.message.startsWith("Problems fetching docs"))throw r;throw new Error("Query failed ".concat(e," and ").concat(JSON.stringify(t),". Error: ").concat(r.message))}))))))))}const h={title:"Last created",order:"_createdAt desc",limit:10,queryParams:{},showCreateButton:!0,apiVersion:"v1"};function b(e){const{query:r,limit:o,apiVersion:c,queryParams:u,types:p,order:y,title:f,showCreateButton:b,createButtonText:g}=t(t({},h),e),[x,w]=i.useState(),[O,v]=i.useState(!0),[P,q]=i.useState(),_=s.useClient({apiVersion:c}),S=s.useSchema(),{assembledQuery:C,params:E}=i.useMemo((()=>{if(r)return{assembledQuery:r,params:u};const e=S.getTypeNames().filter((e=>{var t;const r=S.get(e);return"document"===(null==(t=null==r?void 0:r.type)?void 0:t.name)}));return{assembledQuery:"*[_type in $types] | order(".concat(y,") [0...").concat(2*o,"]"),params:{types:p?a.intersection(p,e):e}}}),[S,r,u,y,o,p]);return i.useEffect((()=>{if(!C)return;const e=m(C,E,_).subscribe({next:e=>{w(e.slice(0,o)),v(!1)},error:e=>{q(e),v(!1)}});return()=>{e.unsubscribe()}}),[o,_,C,E]),n.jsx(l.DashboardWidgetContainer,{header:f,footer:p&&1===p.length&&b&&n.jsx(s.IntentButton,{mode:"bleed",style:{width:"100%"},paddingX:2,paddingY:4,tone:"primary",type:"button",intent:"create",params:{type:p[0]},text:g||"Create new ".concat(p[0])}),children:n.jsxs(d.Card,{children:[P&&n.jsx("div",{children:P.message}),!P&&O&&n.jsx(d.Card,{padding:4,children:n.jsx(d.Flex,{justify:"center",children:n.jsx(d.Spinner,{muted:!0})})}),!P&&!x&&!O&&n.jsx("div",{children:"Could not locate any documents :/"}),n.jsx(d.Stack,{space:2,children:x&&x.map((e=>n.jsx(j,{doc:e},e._id)))})]})})}function j(e){let{doc:t}=e;const r=s.useSchema().get(t._type);return n.jsx(d.Card,{flex:1,children:n.jsx(s.IntentButton,{intent:"edit",mode:"bleed",padding:1,radius:0,params:{type:t._type,id:s.getPublishedId(t._id)},style:{width:"100%"},children:r?n.jsx(s.SanityPreview,{layout:"default",schemaType:r,value:t},t._id):"Schema-type missing"})})}exports.documentListWidget=function(e){return{name:"document-list-widget",component:function(){return n.jsx(b,t({},e))},layout:e.layout}};
1
+ "use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react/jsx-runtime"),i=require("react"),s=require("sanity"),a=require("lodash"),o=require("rxjs"),c=require("rxjs/operators"),u=require("lodash/uniqBy"),d=require("@sanity/ui"),l=require("@sanity/dashboard");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var y=p(u);const f=e=>"drafts.".concat(e._id);function m(e,t,r){return r.listen(e,t,{events:["welcome","mutation"],includeResult:!1,visibility:"query"}).pipe(c.switchMap((n=>o.of(1).pipe("welcome"===n.type?c.tap():c.delay(1e3),c.mergeMap((()=>r.fetch(e,t).then((e=>function(e,t){if(!e)return Promise.resolve([]);const r=Array.isArray(e)?e:[e],n=r.filter((e=>!e._id.startsWith("drafts."))).map(f);return t.fetch("*[_id in $ids]",{ids:n}).then((e=>{const t=r.map((t=>e.find((e=>e._id===f(t)))||t));return y.default(t,"_id")})).catch((e=>{throw new Error("Problems fetching docs ".concat(n,". Error: ").concat(e.message))}))}(e,r))).catch((r=>{if(r.message.startsWith("Problems fetching docs"))throw r;throw new Error("Query failed ".concat(e," and ").concat(JSON.stringify(t),". Error: ").concat(r.message))}))))))))}const h={title:"Last created",order:"_createdAt desc",limit:10,queryParams:{},showCreateButton:!0,apiVersion:"v1"};function b(e){const{query:r,limit:o,apiVersion:c,queryParams:u,types:p,order:y,title:f,showCreateButton:b,createButtonText:g}=t(t({},h),e),[x,w]=i.useState(),[O,v]=i.useState(!0),[P,q]=i.useState(),_=s.useClient({apiVersion:c}),S=s.useSchema(),{assembledQuery:C,params:E}=i.useMemo((()=>{if(r)return{assembledQuery:r,params:u};const e=S.getTypeNames().filter((e=>{var t;const r=S.get(e);return"document"===(null==(t=null==r?void 0:r.type)?void 0:t.name)}));return{assembledQuery:"*[_type in $types] | order(".concat(y,") [0...").concat(2*o,"]"),params:{types:p?a.intersection(p,e):e}}}),[S,r,u,y,o,p]);return i.useEffect((()=>{if(!C)return;const e=m(C,E,_).subscribe({next:e=>{w(e.slice(0,o)),v(!1)},error:e=>{q(e),v(!1)}});return()=>{e.unsubscribe()}}),[o,_,C,E]),n.jsx(l.DashboardWidgetContainer,{header:f,footer:p&&1===p.length&&b&&n.jsx(s.IntentButton,{mode:"bleed",style:{width:"100%"},paddingX:2,paddingY:4,tone:"primary",type:"button",intent:"create",params:{type:p[0]},text:g||"Create new ".concat(p[0])}),children:n.jsxs(d.Card,{children:[P&&n.jsx("div",{children:P.message}),!P&&O&&n.jsx(d.Card,{padding:4,children:n.jsx(d.Flex,{justify:"center",children:n.jsx(d.Spinner,{muted:!0})})}),!P&&!x&&!O&&n.jsx("div",{children:"Could not locate any documents :/"}),n.jsx(d.Stack,{space:2,children:x&&x.map((e=>n.jsx(j,{doc:e},e._id)))})]})})}function j(e){let{doc:t}=e;const r=s.useSchema().get(t._type);return n.jsx(d.Card,{flex:1,children:n.jsx(s.IntentButton,{intent:"edit",mode:"bleed",padding:1,radius:0,params:{type:t._type,id:s.getPublishedId(t._id)},style:{width:"100%"},children:r?n.jsx(s.Preview,{layout:"default",schemaType:r,value:t},t._id):"Schema-type missing"})})}exports.documentListWidget=function(e){return{name:"document-list-widget",component:function(){return n.jsx(b,t({},e))},layout:e.layout}};
2
2
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/sanityConnector.ts","../src/DocumentList.tsx","../src/plugin.tsx"],"sourcesContent":["import {Observable, of as observableOf} from 'rxjs'\nimport {delay, mergeMap, switchMap, tap} from 'rxjs/operators'\nimport uniqBy from 'lodash/uniqBy'\nimport {SanityClient} from '@sanity/client'\nimport {SanityDocument} from 'sanity'\n\nconst draftId = (nonDraftDoc: SanityDocument) => `drafts.${nonDraftDoc._id}`\n\nfunction prepareDocumentList(\n incoming: SanityDocument | SanityDocument[],\n client: SanityClient\n): Promise<SanityDocument[]> {\n if (!incoming) {\n return Promise.resolve([])\n }\n const documents = Array.isArray(incoming) ? incoming : [incoming]\n\n const ids = documents.filter((doc) => !doc._id.startsWith('drafts.')).map(draftId)\n\n return client\n .fetch<SanityDocument[]>('*[_id in $ids]', {ids})\n .then((drafts) => {\n const outgoing = documents.map((doc) => {\n const foundDraft = drafts.find((draft) => draft._id === draftId(doc))\n return foundDraft || doc\n })\n return uniqBy(outgoing, '_id')\n })\n .catch((error) => {\n throw new Error(`Problems fetching docs ${ids}. Error: ${error.message}`)\n })\n}\n\nexport function getSubscription(\n query: string,\n params: Record<string, any>,\n client: SanityClient\n): Observable<SanityDocument[]> {\n return client\n .listen(query, params, {\n events: ['welcome', 'mutation'],\n includeResult: false,\n visibility: 'query',\n })\n .pipe(\n switchMap((event) => {\n return observableOf(1).pipe(\n event.type === 'welcome' ? tap() : delay(1000),\n mergeMap(() =>\n client\n .fetch(query, params)\n .then((incoming) => {\n return prepareDocumentList(incoming, client)\n })\n .catch((error) => {\n if (error.message.startsWith('Problems fetching docs')) {\n throw error\n }\n throw new Error(\n `Query failed ${query} and ${JSON.stringify(params)}. Error: ${error.message}`\n )\n })\n )\n )\n })\n )\n}\n","import React, {useEffect, useMemo, useState} from 'react'\nimport {getPublishedId, useClient, useSchema} from 'sanity'\nimport {intersection} from 'lodash'\nimport {getSubscription} from './sanityConnector'\nimport {SanityDocument, IntentButton, SanityPreview} from 'sanity'\nimport {Card, Flex, Spinner, Stack} from '@sanity/ui'\nimport {DashboardWidgetContainer} from '@sanity/dashboard'\n\nexport interface DocumentListConfig {\n title?: string\n types?: string[]\n query?: string\n queryParams?: Record<string, any>\n order?: string\n limit?: number\n showCreateButton?: boolean\n createButtonText?: string\n apiVersion?: string\n}\n\nconst defaultProps = {\n title: 'Last created',\n order: '_createdAt desc',\n limit: 10,\n queryParams: {},\n showCreateButton: true,\n apiVersion: 'v1',\n}\n\nexport function DocumentList(props: DocumentListConfig) {\n const {\n query,\n limit,\n apiVersion,\n queryParams,\n types,\n order,\n title,\n showCreateButton,\n createButtonText,\n } = {\n ...defaultProps,\n ...props,\n }\n\n const [documents, setDocuments] = useState<SanityDocument[] | undefined>()\n const [loading, setLoading] = useState<boolean>(true)\n const [error, setError] = useState<Error | undefined>()\n\n const versionedClient = useClient({apiVersion})\n const schema = useSchema()\n\n const {assembledQuery, params} = useMemo(() => {\n if (query) {\n return {assembledQuery: query, params: queryParams}\n }\n\n const documentTypes = schema.getTypeNames().filter((typeName) => {\n const schemaType = schema.get(typeName)\n return schemaType?.type?.name === 'document'\n })\n\n return {\n assembledQuery: `*[_type in $types] | order(${order}) [0...${limit * 2}]`,\n params: {types: types ? intersection(types, documentTypes) : documentTypes},\n }\n }, [schema, query, queryParams, order, limit, types])\n\n useEffect(() => {\n if (!assembledQuery) {\n return\n }\n\n const subscription = getSubscription(assembledQuery, params, versionedClient).subscribe({\n next: (d) => {\n setDocuments(d.slice(0, limit))\n setLoading(false)\n },\n error: (e) => {\n setError(e)\n setLoading(false)\n },\n })\n // eslint-disable-next-line consistent-return\n return () => {\n subscription.unsubscribe()\n }\n }, [limit, versionedClient, assembledQuery, params])\n\n return (\n <DashboardWidgetContainer\n header={title}\n footer={\n types &&\n types.length === 1 &&\n showCreateButton && (\n <IntentButton\n mode=\"bleed\"\n style={{width: '100%'}}\n paddingX={2}\n paddingY={4}\n tone=\"primary\"\n type=\"button\"\n intent=\"create\"\n params={{type: types[0]}}\n text={createButtonText || `Create new ${types[0]}`}\n />\n )\n }\n >\n <Card>\n {error && <div>{error.message}</div>}\n {!error && loading && (\n <Card padding={4}>\n <Flex justify=\"center\">\n <Spinner muted />\n </Flex>\n </Card>\n )}\n {!error && !documents && !loading && <div>Could not locate any documents :/</div>}\n <Stack space={2}>\n {documents && documents.map((doc) => <MenuEntry key={doc._id} doc={doc} />)}\n </Stack>\n </Card>\n </DashboardWidgetContainer>\n )\n}\n\nfunction MenuEntry({doc}: {doc: SanityDocument}) {\n const schema = useSchema()\n const type = schema.get(doc._type)\n return (\n <Card flex={1}>\n <IntentButton\n intent=\"edit\"\n mode=\"bleed\"\n padding={1}\n radius={0}\n params={{\n type: doc._type,\n id: getPublishedId(doc._id),\n }}\n style={{width: '100%'}}\n >\n {type ? (\n <SanityPreview layout=\"default\" schemaType={type} value={doc} key={doc._id} />\n ) : (\n 'Schema-type missing'\n )}\n </IntentButton>\n </Card>\n )\n}\n\nexport default DocumentList\n","import DocumentList, {DocumentListConfig} from './DocumentList'\nimport React from 'react'\nimport {LayoutConfig, DashboardWidget} from '@sanity/dashboard'\n\nexport interface DocumentListWidgetConfig extends DocumentListConfig {\n layout?: LayoutConfig\n}\n\nexport function documentListWidget(config: DocumentListWidgetConfig): DashboardWidget {\n return {\n name: 'document-list-widget',\n component: function component() {\n return <DocumentList {...config} />\n },\n layout: config.layout,\n }\n}\n"],"names":["draftId","nonDraftDoc","_id","getSubscription","query","params","client","listen","events","includeResult","visibility","pipe","switchMap","event","observableOf","of","type","tap","delay","mergeMap","fetch","then","incoming","Promise","resolve","documents","Array","isArray","ids","filter","doc","startsWith","map","drafts","outgoing","find","draft","uniqBy","catch","error","Error","message","prepareDocumentList","JSON","stringify","defaultProps","title","order","limit","queryParams","showCreateButton","apiVersion","DocumentList","props","types","createButtonText","setDocuments","useState","loading","setLoading","setError","versionedClient","useClient","schema","useSchema","assembledQuery","useMemo","documentTypes","getTypeNames","typeName","_a","schemaType","get","name","concat","intersection","useEffect","subscription","subscribe","next","d","slice","e","unsubscribe","jsx","DashboardWidgetContainer","header","footer","length","IntentButton","mode","style","width","paddingX","paddingY","tone","intent","text","children","jsxs","Card","padding","Flex","justify","Spinner","muted","Stack","space","MenuEntry","_ref","_type","flex","radius","id","getPublishedId","SanityPreview","layout","value","config","component","_objectSpread"],"mappings":"4iCAMA,MAAMA,EAAWC,oBAA0CA,EAAYC,KA2BvD,SAAAC,EACdC,EACAC,EACAC,GAEO,OAAAA,EACJC,OAAOH,EAAOC,EAAQ,CACrBG,OAAQ,C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,CAAA3D,GAAU6C,EAAAA,IAAA,MAAA,CAAKc,SAAM3D,EAAAE,WACpBF,GAASmB,GACR0B,EAAAA,IAAAgB,OAAA,CAAKC,QAAS,EACbH,SAACd,EAAAA,IAAAkB,OAAA,CAAKC,QAAQ,SACZL,SAACd,EAAAA,IAAAoB,UAAA,CAAQC,OAAK,SAIlBlE,IAAUd,IAAciC,GAAY0B,EAAAA,IAAA,MAAA,CAAIc,SAAA,sCACzCd,EAAAA,IAAAsB,EAAAA,MAAA,CAAMC,MAAO,EACXT,SAAazE,GAAAA,EAAUO,KAAKF,GAASsD,EAAAA,IAAAwB,EAAA,CAAwB9E,OAATA,EAAI5B,aAKnE,CAEA,SAAS0G,EAAwCC,GAAA,IAA9B/E,IAACA,GAA6B+E,EAC/C,MACM7F,EADSgD,EAAAA,YACKQ,IAAI1C,EAAIgF,OAC5B,OACG1B,EAAAA,IAAAgB,EAAAA,KAAA,CAAKW,KAAM,EACVb,SAACd,EAAAA,IAAAK,eAAA,CACCO,OAAO,OACPN,KAAK,QACLW,QAAS,EACTW,OAAQ,EACR3G,OAAQ,CACNW,KAAMc,EAAIgF,MACVG,GAAIC,EAAAA,eAAepF,EAAI5B,MAEzByF,MAAO,CAACC,MAAO,QAEdM,WACEd,EAAAA,IAAA+B,gBAAA,CAAcC,OAAO,UAAU7C,WAAYvD,EAAMqG,MAAOvF,GAAUA,EAAI5B,KAEvE,yBAKV,4BChJO,SAA4BoH,GAC1B,MAAA,CACL7C,KAAM,uBACN8C,UAAW,WACT,OAAQnC,EAAAA,IAAAhC,EAAAoE,EAAA,CAAA,EAAiBF,GAC3B,EACAF,OAAQE,EAAOF,OAEnB"}
1
+ {"version":3,"file":"index.js","sources":["../src/sanityConnector.ts","../src/DocumentList.tsx","../src/plugin.tsx"],"sourcesContent":["import {Observable, of as observableOf} from 'rxjs'\nimport {delay, mergeMap, switchMap, tap} from 'rxjs/operators'\nimport uniqBy from 'lodash/uniqBy'\nimport {SanityClient} from '@sanity/client'\nimport {SanityDocument} from 'sanity'\n\nconst draftId = (nonDraftDoc: SanityDocument) => `drafts.${nonDraftDoc._id}`\n\nfunction prepareDocumentList(\n incoming: SanityDocument | SanityDocument[],\n client: SanityClient\n): Promise<SanityDocument[]> {\n if (!incoming) {\n return Promise.resolve([])\n }\n const documents = Array.isArray(incoming) ? incoming : [incoming]\n\n const ids = documents.filter((doc) => !doc._id.startsWith('drafts.')).map(draftId)\n\n return client\n .fetch<SanityDocument[]>('*[_id in $ids]', {ids})\n .then((drafts) => {\n const outgoing = documents.map((doc) => {\n const foundDraft = drafts.find((draft) => draft._id === draftId(doc))\n return foundDraft || doc\n })\n return uniqBy(outgoing, '_id')\n })\n .catch((error) => {\n throw new Error(`Problems fetching docs ${ids}. Error: ${error.message}`)\n })\n}\n\nexport function getSubscription(\n query: string,\n params: Record<string, any>,\n client: SanityClient\n): Observable<SanityDocument[]> {\n return client\n .listen(query, params, {\n events: ['welcome', 'mutation'],\n includeResult: false,\n visibility: 'query',\n })\n .pipe(\n switchMap((event) => {\n return observableOf(1).pipe(\n event.type === 'welcome' ? tap() : delay(1000),\n mergeMap(() =>\n client\n .fetch(query, params)\n .then((incoming) => {\n return prepareDocumentList(incoming, client)\n })\n .catch((error) => {\n if (error.message.startsWith('Problems fetching docs')) {\n throw error\n }\n throw new Error(\n `Query failed ${query} and ${JSON.stringify(params)}. Error: ${error.message}`\n )\n })\n )\n )\n })\n )\n}\n","import React, {useEffect, useMemo, useState} from 'react'\nimport {getPublishedId, useClient, useSchema} from 'sanity'\nimport {intersection} from 'lodash'\nimport {getSubscription} from './sanityConnector'\nimport {SanityDocument, IntentButton, Preview} from 'sanity'\nimport {Card, Flex, Spinner, Stack} from '@sanity/ui'\nimport {DashboardWidgetContainer} from '@sanity/dashboard'\n\nexport interface DocumentListConfig {\n title?: string\n types?: string[]\n query?: string\n queryParams?: Record<string, any>\n order?: string\n limit?: number\n showCreateButton?: boolean\n createButtonText?: string\n apiVersion?: string\n}\n\nconst defaultProps = {\n title: 'Last created',\n order: '_createdAt desc',\n limit: 10,\n queryParams: {},\n showCreateButton: true,\n apiVersion: 'v1',\n}\n\nexport function DocumentList(props: DocumentListConfig) {\n const {\n query,\n limit,\n apiVersion,\n queryParams,\n types,\n order,\n title,\n showCreateButton,\n createButtonText,\n } = {\n ...defaultProps,\n ...props,\n }\n\n const [documents, setDocuments] = useState<SanityDocument[] | undefined>()\n const [loading, setLoading] = useState<boolean>(true)\n const [error, setError] = useState<Error | undefined>()\n\n const versionedClient = useClient({apiVersion})\n const schema = useSchema()\n\n const {assembledQuery, params} = useMemo(() => {\n if (query) {\n return {assembledQuery: query, params: queryParams}\n }\n\n const documentTypes = schema.getTypeNames().filter((typeName) => {\n const schemaType = schema.get(typeName)\n return schemaType?.type?.name === 'document'\n })\n\n return {\n assembledQuery: `*[_type in $types] | order(${order}) [0...${limit * 2}]`,\n params: {types: types ? intersection(types, documentTypes) : documentTypes},\n }\n }, [schema, query, queryParams, order, limit, types])\n\n useEffect(() => {\n if (!assembledQuery) {\n return\n }\n\n const subscription = getSubscription(assembledQuery, params, versionedClient).subscribe({\n next: (d) => {\n setDocuments(d.slice(0, limit))\n setLoading(false)\n },\n error: (e) => {\n setError(e)\n setLoading(false)\n },\n })\n // eslint-disable-next-line consistent-return\n return () => {\n subscription.unsubscribe()\n }\n }, [limit, versionedClient, assembledQuery, params])\n\n return (\n <DashboardWidgetContainer\n header={title}\n footer={\n types &&\n types.length === 1 &&\n showCreateButton && (\n <IntentButton\n mode=\"bleed\"\n style={{width: '100%'}}\n paddingX={2}\n paddingY={4}\n tone=\"primary\"\n type=\"button\"\n intent=\"create\"\n params={{type: types[0]}}\n text={createButtonText || `Create new ${types[0]}`}\n />\n )\n }\n >\n <Card>\n {error && <div>{error.message}</div>}\n {!error && loading && (\n <Card padding={4}>\n <Flex justify=\"center\">\n <Spinner muted />\n </Flex>\n </Card>\n )}\n {!error && !documents && !loading && <div>Could not locate any documents :/</div>}\n <Stack space={2}>\n {documents && documents.map((doc) => <MenuEntry key={doc._id} doc={doc} />)}\n </Stack>\n </Card>\n </DashboardWidgetContainer>\n )\n}\n\nfunction MenuEntry({doc}: {doc: SanityDocument}) {\n const schema = useSchema()\n const type = schema.get(doc._type)\n return (\n <Card flex={1}>\n <IntentButton\n intent=\"edit\"\n mode=\"bleed\"\n padding={1}\n radius={0}\n params={{\n type: doc._type,\n id: getPublishedId(doc._id),\n }}\n style={{width: '100%'}}\n >\n {type ? (\n <Preview layout=\"default\" schemaType={type} value={doc} key={doc._id} />\n ) : (\n 'Schema-type missing'\n )}\n </IntentButton>\n </Card>\n )\n}\n\nexport default DocumentList\n","import DocumentList, {DocumentListConfig} from './DocumentList'\nimport React from 'react'\nimport {LayoutConfig, DashboardWidget} from '@sanity/dashboard'\n\nexport interface DocumentListWidgetConfig extends DocumentListConfig {\n layout?: LayoutConfig\n}\n\nexport function documentListWidget(config: DocumentListWidgetConfig): DashboardWidget {\n return {\n name: 'document-list-widget',\n component: function component() {\n return <DocumentList {...config} />\n },\n layout: config.layout,\n }\n}\n"],"names":["draftId","nonDraftDoc","_id","getSubscription","query","params","client","listen","events","includeResult","visibility","pipe","switchMap","event","observableOf","of","type","tap","delay","mergeMap","fetch","then","incoming","Promise","resolve","documents","Array","isArray","ids","filter","doc","startsWith","map","drafts","outgoing","find","draft","uniqBy","catch","error","Error","message","prepareDocumentList","JSON","stringify","defaultProps","title","order","limit","queryParams","showCreateButton","apiVersion","DocumentList","props","types","createButtonText","setDocuments","useState","loading","setLoading","setError","versionedClient","useClient","schema","useSchema","assembledQuery","useMemo","documentTypes","getTypeNames","typeName","_a","schemaType","get","name","concat","intersection","useEffect","subscription","subscribe","next","d","slice","e","unsubscribe","jsx","DashboardWidgetContainer","header","footer","length","IntentButton","mode","style","width","paddingX","paddingY","tone","intent","text","children","jsxs","Card","padding","Flex","justify","Spinner","muted","Stack","space","MenuEntry","_ref","_type","flex","radius","id","getPublishedId","Preview","layout","value","config","component","_objectSpread"],"mappings":"4iCA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
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "> **NOTE**",
5
5
  "keywords": [
6
6
  "sanity",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@sanity/incompatible-plugin": "^1.0.4",
56
- "@sanity/ui": "1.0.0-beta.32",
56
+ "@sanity/ui": "^1.0.0",
57
57
  "lodash": "^4.17.15",
58
58
  "rxjs": "^6.0.0"
59
59
  },
@@ -79,13 +79,13 @@
79
79
  "prettier-plugin-packagejson": "^2.3.0",
80
80
  "react": "^18",
81
81
  "rimraf": "^3.0.2",
82
- "sanity": "3.0.0-rc.2",
82
+ "sanity": "^3.0.0",
83
83
  "typescript": "^4.8.4"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@sanity/dashboard": "^3.0.0-v3-studio.8",
87
87
  "react": "^18",
88
- "sanity": "dev-preview || 3.0.0-rc.2"
88
+ "sanity": "^3.0.0"
89
89
  },
90
90
  "engines": {
91
91
  "node": ">=14"
@@ -2,7 +2,7 @@ import React, {useEffect, useMemo, useState} from 'react'
2
2
  import {getPublishedId, useClient, useSchema} from 'sanity'
3
3
  import {intersection} from 'lodash'
4
4
  import {getSubscription} from './sanityConnector'
5
- import {SanityDocument, IntentButton, SanityPreview} from 'sanity'
5
+ import {SanityDocument, IntentButton, Preview} from 'sanity'
6
6
  import {Card, Flex, Spinner, Stack} from '@sanity/ui'
7
7
  import {DashboardWidgetContainer} from '@sanity/dashboard'
8
8
 
@@ -143,7 +143,7 @@ function MenuEntry({doc}: {doc: SanityDocument}) {
143
143
  style={{width: '100%'}}
144
144
  >
145
145
  {type ? (
146
- <SanityPreview layout="default" schemaType={type} value={doc} key={doc._id} />
146
+ <Preview layout="default" schemaType={type} value={doc} key={doc._id} />
147
147
  ) : (
148
148
  'Schema-type missing'
149
149
  )}