sanity-plugin-dashboard-widget-document-list 1.0.0 → 2.0.0
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/LICENSE +1 -1
- package/README.md +35 -32
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/{lib/src → dist}/index.d.ts +2 -4
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -43
- package/src/DocumentList.tsx +19 -10
- package/src/plugin.tsx +3 -3
- package/src/sanityConnector.ts +11 -10
- package/lib/index.esm.js +0 -2
- package/lib/index.esm.js.map +0 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# sanity-plugin-dashboard-widget-document-list
|
|
2
2
|
|
|
3
|
-
>This is a **Sanity Studio v3** plugin.
|
|
3
|
+
> This is a **Sanity Studio v3** plugin.
|
|
4
4
|
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/dashboard-widget-document-list/tree/studio-v2).
|
|
5
5
|
|
|
6
6
|
## What is it?
|
|
@@ -26,86 +26,88 @@ Ensure that you have followed install and usage instructions for @sanity/dashboa
|
|
|
26
26
|
Add dashboard-widget-document-list as a widget to @sanity/dashboard plugin in sanity.config.ts (or .js):
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
29
|
+
import {dashboardTool} from '@sanity/dashboard'
|
|
30
|
+
import {documentListWidget} from 'sanity-plugin-dashboard-widget-document-list'
|
|
31
31
|
|
|
32
32
|
export default defineConfig({
|
|
33
33
|
// ...
|
|
34
34
|
plugins: [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
),
|
|
41
|
-
]
|
|
35
|
+
dashboardTool({
|
|
36
|
+
widgets: [documentListWidget()],
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
42
39
|
})
|
|
43
40
|
```
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
_Note_: If a document in the result (as returned by the backend) has a draft, that draft is rendered instead of the published document.
|
|
46
43
|
|
|
47
44
|
## Options
|
|
48
45
|
|
|
49
46
|
There are some options available, as specified by [DocumentListConfig](src/DocumentList.tsx):
|
|
50
47
|
|
|
51
48
|
### `title` (string)
|
|
49
|
+
|
|
52
50
|
Widget title
|
|
53
51
|
|
|
54
52
|
```js
|
|
55
53
|
documentListWidget({
|
|
56
|
-
|
|
54
|
+
title: 'Some documents',
|
|
57
55
|
})
|
|
58
56
|
```
|
|
59
57
|
|
|
60
58
|
### `order` (string)
|
|
59
|
+
|
|
61
60
|
Field and direction to order by when docs are rendered
|
|
62
61
|
|
|
63
62
|
```js
|
|
64
63
|
documentListWidget({
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
title: 'Last edited',
|
|
65
|
+
order: '_updatedAt desc',
|
|
67
66
|
})
|
|
68
67
|
```
|
|
69
68
|
|
|
70
69
|
### `limit` (number)
|
|
70
|
+
|
|
71
71
|
Number of docs rendered
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
74
|
documentListWidget({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
title: 'Last edited',
|
|
76
|
+
order: '_updatedAt desc',
|
|
77
|
+
limit: 3,
|
|
78
78
|
})
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
### `types` (array)
|
|
82
|
+
|
|
82
83
|
Array of strings signifying which document (schema) types are fetched
|
|
83
84
|
|
|
84
85
|
```js
|
|
85
86
|
documentListWidget({
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
title: 'Last edited',
|
|
88
|
+
order: '_updatedAt desc',
|
|
89
|
+
types: ['book', 'author'],
|
|
89
90
|
})
|
|
90
91
|
```
|
|
91
92
|
|
|
92
93
|
### `query` (string) and `params` (object)
|
|
94
|
+
|
|
93
95
|
Customized GROQ query with params for maximum control. If you use the query option, the `types`, `order`, and `limit` options will cease to function. You're on your own.
|
|
94
96
|
|
|
95
97
|
```js
|
|
96
98
|
documentListWidget({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
title: 'Published books by title',
|
|
100
|
+
query: '*[_type == "book" && published == true] | order(title asc) [0...10]',
|
|
99
101
|
})
|
|
100
102
|
```
|
|
101
103
|
|
|
102
104
|
```js
|
|
103
105
|
documentListWidget({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
title: 'My favorite documents',
|
|
107
|
+
query: '*[_id in $ids]',
|
|
108
|
+
params: {
|
|
109
|
+
ids: ['ab2', 'c5z', '654'],
|
|
110
|
+
},
|
|
109
111
|
})
|
|
110
112
|
```
|
|
111
113
|
|
|
@@ -115,9 +117,9 @@ You can override the button default button text (`Create new ${types[0]}`) by se
|
|
|
115
117
|
|
|
116
118
|
```js
|
|
117
119
|
documentListWidget({
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
title: 'Blog posts',
|
|
121
|
+
query: '*[_type == "post"]',
|
|
122
|
+
createButtonText: 'Create new blog post',
|
|
121
123
|
})
|
|
122
124
|
```
|
|
123
125
|
|
|
@@ -127,16 +129,17 @@ You can disable the create button altogether by passing a `showCreateButton` boo
|
|
|
127
129
|
|
|
128
130
|
```js
|
|
129
131
|
documentListWidget({
|
|
130
|
-
|
|
132
|
+
showCreateButton: false,
|
|
131
133
|
})
|
|
132
134
|
```
|
|
133
135
|
|
|
134
136
|
### Widget size
|
|
135
137
|
|
|
136
138
|
You can change the width of the plugin using `layout.width`:
|
|
139
|
+
|
|
137
140
|
```js
|
|
138
141
|
documentListWidget({
|
|
139
|
-
|
|
142
|
+
layout: {width: 'small'},
|
|
140
143
|
})
|
|
141
144
|
```
|
|
142
145
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("@sanity/dashboard"),r=require("@sanity/ui"),s=require("lodash/intersection.js"),i=require("react"),n=require("sanity"),a=require("lodash/uniqBy"),o=require("rxjs"),u=require("rxjs/operators");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=d(s),l=d(a);const m=e=>`drafts.${e._id}`;function p(e,t,r){return r.listen(e,t,{events:["welcome","mutation"],includeResult:!1,visibility:"query"}).pipe(u.switchMap((s=>o.of(1).pipe("welcome"===s.type?u.tap():u.delay(1e3),u.mergeMap((()=>r.fetch(e,t).then((e=>function(e,t){if(!e)return Promise.resolve([]);const r=Array.isArray(e)?e:[e],s=r.filter((e=>!e._id.startsWith("drafts."))).map(m);return t.fetch("*[_id in $ids]",{ids:s}).then((e=>{const t=r.map((t=>e.find((e=>e._id===m(t)))||t));return l.default(t,"_id")})).catch((e=>{throw new Error(`Problems fetching docs ${s}. Error: ${e.message}`)}))}(e,r))).catch((r=>{throw r.message.startsWith("Problems fetching docs")?r:new Error(`Query failed ${e} and ${JSON.stringify(t)}. Error: ${r.message}`)}))))))))}const y={title:"Last created",order:"_createdAt desc",limit:10,queryParams:{},showCreateButton:!0,apiVersion:"v1"};function h(s){const{query:a,limit:o,apiVersion:u,queryParams:d,types:l,order:m,title:h,showCreateButton:x,createButtonText:j}={...y,...s},[g,b]=i.useState(),[q,v]=i.useState(!0),[w,_]=i.useState(),$=n.useClient({apiVersion:u}),C=n.useSchema(),{assembledQuery:P,params:S}=i.useMemo((()=>{if(a)return{assembledQuery:a,params:d};const e=C.getTypeNames().filter((e=>{var t;const r=C.get(e);return"document"===(null==(t=null==r?void 0:r.type)?void 0:t.name)}));return{assembledQuery:`*[_type in $types] | order(${m}) [0...${2*o}]`,params:{types:l?c.default(l,e):e}}}),[C,a,d,m,o,l]);return i.useEffect((()=>{if(!P)return;const e=p(P,S,$).subscribe({next:e=>{b(e.slice(0,o)),v(!1)},error:e=>{_(e),v(!1)}});return()=>{e.unsubscribe()}}),[o,$,P,S]),e.jsx(t.DashboardWidgetContainer,{header:h,footer:l&&1===l.length&&x&&e.jsx(n.IntentButton,{mode:"bleed",style:{width:"100%"},paddingY:4,tone:"primary",type:"button",intent:"create",params:{type:l[0]},text:j||`Create new ${l[0]}`}),children:e.jsxs(r.Card,{children:[w&&e.jsx("div",{children:w.message}),!w&&q&&e.jsx(r.Card,{padding:4,children:e.jsx(r.Flex,{justify:"center",children:e.jsx(r.Spinner,{muted:!0})})}),!w&&!g&&!q&&e.jsx("div",{children:"Could not locate any documents :/"}),e.jsx(r.Stack,{space:2,children:g&&g.map((t=>e.jsx(f,{doc:t},t._id)))})]})})}function f({doc:t}){const s=n.useSchema().get(t._type);return e.jsx(r.Card,{flex:1,children:e.jsx(n.IntentButton,{intent:"edit",mode:"bleed",tooltipProps:{},params:{type:t._type,id:n.getPublishedId(t._id)},style:{width:"100%"},children:s?e.jsx(n.Preview,{layout:"default",schemaType:s,value:t},t._id):"Schema-type missing"})})}exports.documentListWidget=function(t){return{name:"document-list-widget",component:function(){return e.jsx(h,{...t})},layout:t.layout}};//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/sanityConnector.ts","../src/DocumentList.tsx","../src/plugin.tsx"],"sourcesContent":["import type {SanityClient} from '@sanity/client'\nimport uniqBy from 'lodash/uniqBy'\nimport {type Observable, of as observableOf} from 'rxjs'\nimport {delay, mergeMap, switchMap, tap} from 'rxjs/operators'\nimport type {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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 {DashboardWidgetContainer} from '@sanity/dashboard'\nimport {Card, Flex, Spinner, Stack} from '@sanity/ui'\nimport {intersection} from 'lodash'\nimport {type ReactNode, useEffect, useMemo, useState} from 'react'\nimport {\n getPublishedId,\n IntentButton,\n Preview,\n type SanityDocument,\n useClient,\n useSchema,\n} from 'sanity'\n\nimport {getSubscription} from './sanityConnector'\n\nexport interface DocumentListConfig {\n title?: string\n types?: string[]\n query?: string\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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): ReactNode {\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 tooltipProps={{}}\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 type {DashboardWidget, LayoutConfig} from '@sanity/dashboard'\n\nimport DocumentList, {type DocumentListConfig} from './DocumentList'\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":["Object","defineProperty","exports","value","jsxRuntime","require","dashboard","ui","intersection","react","sanity","uniqBy","rxjs","operators","_interopDefaultCompat","e","default","intersection__default","uniqBy__default","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","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","useEffect","subscription","subscribe","next","d","slice","unsubscribe","jsx","DashboardWidgetContainer","header","footer","length","IntentButton","mode","style","width","paddingY","tone","intent","text","children","Card","padding","Flex","justify","Spinner","muted","Stack","space","MenuEntry","_type","flex","tooltipProps","id","getPublishedId","Preview","layout","documentListWidget","config","component"],"mappings":"aAMAA,OAAAC,eAAAC,QAAA,aAAA,CAAAC,OAAA,IAAA,IAAAC,EAAAC,QAAA,qBAAAC,EAAAD,QAAA,qBAAAE,EAAAF,QAA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WACF,SAAAhC,IAAC7B,EAAc,IAAG4D,GAC3B,EACAF,OAAQE,EAAOF,OAEnB"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {DashboardWidget} from '@sanity/dashboard'
|
|
2
|
+
import type {LayoutConfig} from '@sanity/dashboard'
|
|
3
|
+
|
|
4
|
+
declare interface DocumentListConfig {
|
|
5
|
+
title?: string
|
|
6
|
+
types?: string[]
|
|
7
|
+
query?: string
|
|
8
|
+
queryParams?: Record<string, any>
|
|
9
|
+
order?: string
|
|
10
|
+
limit?: number
|
|
11
|
+
showCreateButton?: boolean
|
|
12
|
+
createButtonText?: string
|
|
13
|
+
apiVersion?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare function documentListWidget(config: DocumentListWidgetConfig): DashboardWidget
|
|
17
|
+
|
|
18
|
+
export declare interface DocumentListWidgetConfig extends DocumentListConfig {
|
|
19
|
+
layout?: LayoutConfig
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {DashboardWidget} from '@sanity/dashboard'
|
|
4
|
-
import {LayoutConfig} from '@sanity/dashboard'
|
|
1
|
+
import type {DashboardWidget} from '@sanity/dashboard'
|
|
2
|
+
import type {LayoutConfig} from '@sanity/dashboard'
|
|
5
3
|
|
|
6
4
|
declare interface DocumentListConfig {
|
|
7
5
|
title?: string
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{DashboardWidgetContainer as r}from"@sanity/dashboard";import{Card as i,Flex as n,Spinner as o,Stack as s}from"@sanity/ui";import a from"lodash/intersection.js";import{useState as d,useMemo as c,useEffect as m}from"react";import{useClient as u,useSchema as l,IntentButton as p,getPublishedId as y,Preview as f}from"sanity";import h from"lodash/uniqBy";import{of as g}from"rxjs";import{switchMap as b,tap as w,delay as _,mergeMap as $}from"rxjs/operators";const v=e=>`drafts.${e._id}`;function x(e,t,r){return r.listen(e,t,{events:["welcome","mutation"],includeResult:!1,visibility:"query"}).pipe(b((i=>g(1).pipe("welcome"===i.type?w():_(1e3),$((()=>r.fetch(e,t).then((e=>function(e,t){if(!e)return Promise.resolve([]);const r=Array.isArray(e)?e:[e],i=r.filter((e=>!e._id.startsWith("drafts."))).map(v);return t.fetch("*[_id in $ids]",{ids:i}).then((e=>{const t=r.map((t=>e.find((e=>e._id===v(t)))||t));return h(t,"_id")})).catch((e=>{throw new Error(`Problems fetching docs ${i}. Error: ${e.message}`)}))}(e,r))).catch((r=>{throw r.message.startsWith("Problems fetching docs")?r:new Error(`Query failed ${e} and ${JSON.stringify(t)}. Error: ${r.message}`)}))))))))}const P={title:"Last created",order:"_createdAt desc",limit:10,queryParams:{},showCreateButton:!0,apiVersion:"v1"};function j(y){const{query:f,limit:h,apiVersion:g,queryParams:b,types:w,order:_,title:$,showCreateButton:v,createButtonText:j}={...P,...y},[B,C]=d(),[E,Q]=d(!0),[A,T]=d(),V=u({apiVersion:g}),N=l(),{assembledQuery:S,params:W}=c((()=>{if(f)return{assembledQuery:f,params:b};const e=N.getTypeNames().filter((e=>{var t;const r=N.get(e);return"document"===(null==(t=null==r?void 0:r.type)?void 0:t.name)}));return{assembledQuery:`*[_type in $types] | order(${_}) [0...${2*h}]`,params:{types:w?a(w,e):e}}}),[N,f,b,_,h,w]);return m((()=>{if(!S)return;const e=x(S,W,V).subscribe({next:e=>{C(e.slice(0,h)),Q(!1)},error:e=>{T(e),Q(!1)}});return()=>{e.unsubscribe()}}),[h,V,S,W]),e(r,{header:$,footer:w&&1===w.length&&v&&e(p,{mode:"bleed",style:{width:"100%"},paddingY:4,tone:"primary",type:"button",intent:"create",params:{type:w[0]},text:j||`Create new ${w[0]}`}),children:t(i,{children:[A&&e("div",{children:A.message}),!A&&E&&e(i,{padding:4,children:e(n,{justify:"center",children:e(o,{muted:!0})})}),!A&&!B&&!E&&e("div",{children:"Could not locate any documents :/"}),e(s,{space:2,children:B&&B.map((t=>e(q,{doc:t},t._id)))})]})})}function q({doc:t}){const r=l().get(t._type);return e(i,{flex:1,children:e(p,{intent:"edit",mode:"bleed",tooltipProps:{},params:{type:t._type,id:y(t._id)},style:{width:"100%"},children:r?e(f,{layout:"default",schemaType:r,value:t},t._id):"Schema-type missing"})})}function B(t){return{name:"document-list-widget",component:function(){return e(j,{...t})},layout:t.layout}}export{B as documentListWidget};//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/sanityConnector.ts","../src/DocumentList.tsx","../src/plugin.tsx"],"sourcesContent":["import type {SanityClient} from '@sanity/client'\nimport uniqBy from 'lodash/uniqBy'\nimport {type Observable, of as observableOf} from 'rxjs'\nimport {delay, mergeMap, switchMap, tap} from 'rxjs/operators'\nimport type {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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 {DashboardWidgetContainer} from '@sanity/dashboard'\nimport {Card, Flex, Spinner, Stack} from '@sanity/ui'\nimport {intersection} from 'lodash'\nimport {type ReactNode, useEffect, useMemo, useState} from 'react'\nimport {\n getPublishedId,\n IntentButton,\n Preview,\n type SanityDocument,\n useClient,\n useSchema,\n} from 'sanity'\n\nimport {getSubscription} from './sanityConnector'\n\nexport interface DocumentListConfig {\n title?: string\n types?: string[]\n query?: string\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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): ReactNode {\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 tooltipProps={{}}\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 type {DashboardWidget, LayoutConfig} from '@sanity/dashboard'\n\nimport DocumentList, {type DocumentListConfig} from './DocumentList'\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":["jsx","jsxs","DashboardWidgetContainer","Card","Flex","Spinner","Stack","intersection","useState","useMemo","useEffect","useClient","useSchema","IntentButton","getPublishedId","Preview","uniqBy","of","switchMap","tap","delay","mergeMap","draftId","nonDraftDoc","_id","getSubscription","query","params","client","listen","events","includeResult","visibility","pipe","event","observableOf","type","fetch","then","incoming","Promise","resolve","documents","Array","isArray","ids","filter","doc","startsWith","map","drafts","outgoing","find","draft","catch","error","Error","message","prepareDocumentList","JSON","stringify","defaultProps","title","order","limit","queryParams","showCreateButton","apiVersion","DocumentList","props","types","createButtonText","setDocuments","loading","setLoading","setError","versionedClient","schema","assembledQuery","documentTypes","getTypeNames","typeName","_a","schemaType","get","name","subscription","subscribe","next","d","slice","e","unsubscribe","header","footer","length","mode","style","width","paddingY","tone","intent","text","children","padding","justify","muted","space","MenuEntry","_type","flex","tooltipProps","id","layout","value","documentListWidget","config","component"],"mappings":"cAMAA,UAAAC,MAAA,uDAAAC,MAAA,mCAAAC,UAAAC,aAAAC,WAAAC,MAAA,oBAAAC,MAAA,4CAAAC,aAAAC,eAAAC,MAAA,4BAAAC,eAAAC,kBAAAC,oBAAAC,aAAAC,MAAA,gBAAAC,MAAA,6BAAAC,MAAA,2BAAAC,SAAAC,WAAAC,cAAAC,MAAA,iBAAA,MAAMC,EAAWC,GAAgC,UAAUA,EAAYC,MA2BvD,SAAAC,EACdC,EAEAC,EACAC,GAEO,OAAAA,EACJC,OAAOH,EAAOC,EAAQ,CACrBG,OAAQ,CAAC,UAAW,YACpBC,eAAe,EACfC,WAAY,UAEbC,KACCf,GAAWgB,GACFC,EAAa,GAAGF,KACN,YAAfC,EAAME,KAAqBjB,IAAQC,EAAM,KACzCC,GAAS,IACPO,EACGS,MAAMX,EAAOC,GACbW,MAAMC,GA5CrB,SACEA,EACAX,GAEA,IAAKW,EACI,OAAAC,QAAQC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AAI8D,OAE1B,OAAC7G,EAAAG,EAAK,CAAA2G,KAAM,EACVP,SAAAvG,EAACa,EAAA,CACCwF,OAAO,OACPL,KAAK,QACLe,aAAc,CAAC,EAGfpF,OAAQ,CACNS,KAAMW,EAAI8D,MACVG,GAAIlG,EAAeiC,EAAIvB,MAEzByE,MAAO,CAACC,MAAO,QAEdK,SAAAnE,EACEpC,EAAAe,EAAA,CAAQkG,OAAO,UAAU9B,WAAY/C,EAAM8E,MAAOnE,GAAUA,EAAIvB,KAEjE,yBAKV,CCzJO,SAAS2F,EAAmBC,GAC1B,MAAA,CACL/B,KAAM,uBACNgC,UAAW,WACF,OAACrH,EAAAoE,EAAc,IAAGgD,GAC3B,EACAH,OAAQG,EAAOH,OAEnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-dashboard-widget-document-list",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "> **NOTE**",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -22,74 +22,76 @@
|
|
|
22
22
|
"author": "Sanity.io <hello@sanity.io>",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
-
"types": "./lib/src/index.d.ts",
|
|
26
25
|
"source": "./src/index.ts",
|
|
27
|
-
"import": "./
|
|
28
|
-
"require": "./
|
|
29
|
-
"default": "./
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.cjs",
|
|
28
|
+
"default": "./dist/index.js"
|
|
30
29
|
},
|
|
31
30
|
"./package.json": "./package.json"
|
|
32
31
|
},
|
|
33
|
-
"main": "./
|
|
34
|
-
"module": "./
|
|
35
|
-
"
|
|
36
|
-
"types": "./lib/src/index.d.ts",
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
37
35
|
"files": [
|
|
38
36
|
"src",
|
|
39
|
-
"
|
|
37
|
+
"dist",
|
|
40
38
|
"v2-incompatible.js",
|
|
41
39
|
"sanity.json"
|
|
42
40
|
],
|
|
43
41
|
"scripts": {
|
|
44
|
-
"
|
|
45
|
-
"build": "pkg-utils build --strict",
|
|
46
|
-
"clean": "rimraf lib",
|
|
42
|
+
"build": "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
|
|
47
43
|
"compile": "tsc --noEmit",
|
|
48
44
|
"link-watch": "plugin-kit link-watch",
|
|
49
45
|
"lint": "eslint .",
|
|
50
|
-
"prepare": "husky
|
|
46
|
+
"prepare": "husky",
|
|
51
47
|
"prepublishOnly": "npm run build",
|
|
52
|
-
"watch": "pkg-utils watch"
|
|
48
|
+
"watch": "pkg-utils watch --strict"
|
|
53
49
|
},
|
|
54
50
|
"dependencies": {
|
|
55
51
|
"@sanity/incompatible-plugin": "^1.0.4",
|
|
56
|
-
"@sanity/ui": "
|
|
57
|
-
"lodash": "^4.17.
|
|
58
|
-
"rxjs": "^
|
|
52
|
+
"@sanity/ui": "^2.8.8",
|
|
53
|
+
"lodash": "^4.17.21",
|
|
54
|
+
"rxjs": "^7.8.1"
|
|
59
55
|
},
|
|
60
56
|
"devDependencies": {
|
|
61
|
-
"@commitlint/cli": "^
|
|
62
|
-
"@commitlint/config-conventional": "^
|
|
63
|
-
"@sanity/dashboard": "^
|
|
64
|
-
"@sanity/pkg-utils": "^
|
|
65
|
-
"@sanity/plugin-kit": "^
|
|
66
|
-
"@sanity/semantic-release-preset": "^
|
|
57
|
+
"@commitlint/cli": "^19.3.0",
|
|
58
|
+
"@commitlint/config-conventional": "^19.2.2",
|
|
59
|
+
"@sanity/dashboard": "^4.0.0",
|
|
60
|
+
"@sanity/pkg-utils": "^6.10.7",
|
|
61
|
+
"@sanity/plugin-kit": "^4.0.17",
|
|
62
|
+
"@sanity/semantic-release-preset": "^5.0.0",
|
|
67
63
|
"@types/react": "^18",
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
69
|
-
"@typescript-eslint/parser": "^
|
|
70
|
-
"eslint": "^8.
|
|
71
|
-
"eslint-config-prettier": "^
|
|
72
|
-
"eslint-config-sanity": "^
|
|
73
|
-
"eslint-plugin-prettier": "^
|
|
74
|
-
"eslint-plugin-react": "^7.
|
|
75
|
-
"eslint-plugin-react-hooks": "^4.6.
|
|
76
|
-
"husky": "^
|
|
77
|
-
"lint-staged": "^
|
|
78
|
-
"prettier": "^
|
|
79
|
-
"prettier-plugin-packagejson": "^2.
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
65
|
+
"@typescript-eslint/parser": "^7.17.0",
|
|
66
|
+
"eslint": "^8.57.0",
|
|
67
|
+
"eslint-config-prettier": "^9.1.0",
|
|
68
|
+
"eslint-config-sanity": "^7.1.2",
|
|
69
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
70
|
+
"eslint-plugin-react": "^7.35.0",
|
|
71
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
72
|
+
"husky": "^9.1.3",
|
|
73
|
+
"lint-staged": "^15.2.7",
|
|
74
|
+
"prettier": "^3.3.3",
|
|
75
|
+
"prettier-plugin-packagejson": "^2.5.1",
|
|
80
76
|
"react": "^18",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"typescript": "
|
|
77
|
+
"sanity": "^3.52.2",
|
|
78
|
+
"semantic-release": "^24.0.0",
|
|
79
|
+
"typescript": "5.5.4"
|
|
84
80
|
},
|
|
85
81
|
"peerDependencies": {
|
|
86
|
-
"@sanity/dashboard": "^
|
|
82
|
+
"@sanity/dashboard": "^4.0.0",
|
|
87
83
|
"react": "^18",
|
|
88
|
-
"sanity": "
|
|
84
|
+
"sanity": "^3.0.0"
|
|
89
85
|
},
|
|
90
86
|
"engines": {
|
|
91
|
-
"node": ">=
|
|
87
|
+
"node": ">=18"
|
|
92
88
|
},
|
|
93
89
|
"public": true,
|
|
94
|
-
"sanityExchangeUrl": "https://www.sanity.io/plugins/sanity-plugin-dashboard-widget-document-list"
|
|
90
|
+
"sanityExchangeUrl": "https://www.sanity.io/plugins/sanity-plugin-dashboard-widget-document-list",
|
|
91
|
+
"browserslist": "extends @sanity/browserslist-config",
|
|
92
|
+
"sideEffects": false,
|
|
93
|
+
"type": "module",
|
|
94
|
+
"overrides": {
|
|
95
|
+
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|
|
96
|
+
}
|
|
95
97
|
}
|
package/src/DocumentList.tsx
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import {DashboardWidgetContainer} from '@sanity/dashboard'
|
|
2
|
+
import {Card, Flex, Spinner, Stack} from '@sanity/ui'
|
|
3
3
|
import {intersection} from 'lodash'
|
|
4
|
+
import {type ReactNode, useEffect, useMemo, useState} from 'react'
|
|
5
|
+
import {
|
|
6
|
+
getPublishedId,
|
|
7
|
+
IntentButton,
|
|
8
|
+
Preview,
|
|
9
|
+
type SanityDocument,
|
|
10
|
+
useClient,
|
|
11
|
+
useSchema,
|
|
12
|
+
} from 'sanity'
|
|
13
|
+
|
|
4
14
|
import {getSubscription} from './sanityConnector'
|
|
5
|
-
import {SanityDocument, IntentButton, SanityPreview} from 'sanity'
|
|
6
|
-
import {Card, Flex, Spinner, Stack} from '@sanity/ui'
|
|
7
|
-
import {DashboardWidgetContainer} from '@sanity/dashboard'
|
|
8
15
|
|
|
9
16
|
export interface DocumentListConfig {
|
|
10
17
|
title?: string
|
|
11
18
|
types?: string[]
|
|
12
19
|
query?: string
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
21
|
queryParams?: Record<string, any>
|
|
14
22
|
order?: string
|
|
15
23
|
limit?: number
|
|
@@ -27,7 +35,7 @@ const defaultProps = {
|
|
|
27
35
|
apiVersion: 'v1',
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
export function DocumentList(props: DocumentListConfig) {
|
|
38
|
+
export function DocumentList(props: DocumentListConfig): ReactNode {
|
|
31
39
|
const {
|
|
32
40
|
query,
|
|
33
41
|
limit,
|
|
@@ -97,7 +105,7 @@ export function DocumentList(props: DocumentListConfig) {
|
|
|
97
105
|
<IntentButton
|
|
98
106
|
mode="bleed"
|
|
99
107
|
style={{width: '100%'}}
|
|
100
|
-
paddingX={2}
|
|
108
|
+
// paddingX={2}
|
|
101
109
|
paddingY={4}
|
|
102
110
|
tone="primary"
|
|
103
111
|
type="button"
|
|
@@ -134,8 +142,9 @@ function MenuEntry({doc}: {doc: SanityDocument}) {
|
|
|
134
142
|
<IntentButton
|
|
135
143
|
intent="edit"
|
|
136
144
|
mode="bleed"
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
tooltipProps={{}}
|
|
146
|
+
// padding={1}
|
|
147
|
+
// radius={0}
|
|
139
148
|
params={{
|
|
140
149
|
type: doc._type,
|
|
141
150
|
id: getPublishedId(doc._id),
|
|
@@ -143,7 +152,7 @@ function MenuEntry({doc}: {doc: SanityDocument}) {
|
|
|
143
152
|
style={{width: '100%'}}
|
|
144
153
|
>
|
|
145
154
|
{type ? (
|
|
146
|
-
<
|
|
155
|
+
<Preview layout="default" schemaType={type} value={doc} key={doc._id} />
|
|
147
156
|
) : (
|
|
148
157
|
'Schema-type missing'
|
|
149
158
|
)}
|
package/src/plugin.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
1
|
+
import type {DashboardWidget, LayoutConfig} from '@sanity/dashboard'
|
|
2
|
+
|
|
3
|
+
import DocumentList, {type DocumentListConfig} from './DocumentList'
|
|
4
4
|
|
|
5
5
|
export interface DocumentListWidgetConfig extends DocumentListConfig {
|
|
6
6
|
layout?: LayoutConfig
|
package/src/sanityConnector.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {delay, mergeMap, switchMap, tap} from 'rxjs/operators'
|
|
1
|
+
import type {SanityClient} from '@sanity/client'
|
|
3
2
|
import uniqBy from 'lodash/uniqBy'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import {type Observable, of as observableOf} from 'rxjs'
|
|
4
|
+
import {delay, mergeMap, switchMap, tap} from 'rxjs/operators'
|
|
5
|
+
import type {SanityDocument} from 'sanity'
|
|
6
6
|
|
|
7
7
|
const draftId = (nonDraftDoc: SanityDocument) => `drafts.${nonDraftDoc._id}`
|
|
8
8
|
|
|
9
9
|
function prepareDocumentList(
|
|
10
10
|
incoming: SanityDocument | SanityDocument[],
|
|
11
|
-
client: SanityClient
|
|
11
|
+
client: SanityClient,
|
|
12
12
|
): Promise<SanityDocument[]> {
|
|
13
13
|
if (!incoming) {
|
|
14
14
|
return Promise.resolve([])
|
|
@@ -33,8 +33,9 @@ function prepareDocumentList(
|
|
|
33
33
|
|
|
34
34
|
export function getSubscription(
|
|
35
35
|
query: string,
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
37
|
params: Record<string, any>,
|
|
37
|
-
client: SanityClient
|
|
38
|
+
client: SanityClient,
|
|
38
39
|
): Observable<SanityDocument[]> {
|
|
39
40
|
return client
|
|
40
41
|
.listen(query, params, {
|
|
@@ -57,11 +58,11 @@ export function getSubscription(
|
|
|
57
58
|
throw error
|
|
58
59
|
}
|
|
59
60
|
throw new Error(
|
|
60
|
-
`Query failed ${query} and ${JSON.stringify(params)}. Error: ${error.message}
|
|
61
|
+
`Query failed ${query} and ${JSON.stringify(params)}. Error: ${error.message}`,
|
|
61
62
|
)
|
|
62
|
-
})
|
|
63
|
-
)
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
64
65
|
)
|
|
65
|
-
})
|
|
66
|
+
}),
|
|
66
67
|
)
|
|
67
68
|
}
|
package/lib/index.esm.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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};
|
|
2
|
-
//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,MACAA,EAAAI,iBACAA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mB,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"}
|
package/lib/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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}};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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","getPublish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