sanity-plugin-dashboard-widget-document-list 3.0.0-studio-v3.0 → 3.0.0-studio-v3.3
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/README.md +4 -5
- package/lib/{index.js → cjs/index.js} +38 -38
- package/lib/{index.js.map → cjs/index.js.map} +0 -0
- package/lib/{index.modern.js → esm/index.js} +39 -39
- package/lib/{index.modern.js.map → esm/index.js.map} +1 -1
- package/lib/{index.d.ts → types/index.d.ts} +0 -0
- package/lib/{index.d.ts.map → types/index.d.ts.map} +0 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
# dashboard-widget-document-list
|
|
2
|
-
[dashboard-plugin]: https://github.com/sanity-io/v3-temp-sanity-dashboard/tree/v3
|
|
1
|
+
# sanity-plugin-dashboard-widget-document-list
|
|
3
2
|
|
|
4
3
|
> **NOTE**
|
|
5
4
|
>
|
|
@@ -14,16 +13,16 @@ Dashboard widget for the Sanity Content Studio which displays a list of document
|
|
|
14
13
|
## Install
|
|
15
14
|
|
|
16
15
|
```
|
|
17
|
-
npm install --save dashboard-widget-document-list
|
|
16
|
+
npm install --save sanity-plugin-dashboard-widget-document-list@studio-v3
|
|
18
17
|
```
|
|
19
18
|
|
|
20
19
|
or
|
|
21
20
|
|
|
22
21
|
```
|
|
23
|
-
yarn add dashboard-widget-document-list
|
|
22
|
+
yarn add sanity-plugin-dashboard-widget-document-list@studio-v3
|
|
24
23
|
```
|
|
25
24
|
|
|
26
|
-
Ensure that you have followed install and usage instructions for
|
|
25
|
+
Ensure that you have followed install and usage instructions for @sanity/dashboard.
|
|
27
26
|
|
|
28
27
|
## Usage
|
|
29
28
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
4
|
-
var $
|
|
5
|
-
var $
|
|
6
|
-
var $
|
|
7
|
-
var $
|
|
8
|
-
var $
|
|
9
|
-
var $
|
|
10
|
-
var $
|
|
1
|
+
var $7xGut$reactjsxruntime = require("react/jsx-runtime");
|
|
2
|
+
var $7xGut$react = require("react");
|
|
3
|
+
var $7xGut$sanity_unstable = require("sanity/_unstable");
|
|
4
|
+
var $7xGut$sanity = require("sanity");
|
|
5
|
+
var $7xGut$lodash = require("lodash");
|
|
6
|
+
var $7xGut$sanityui = require("@sanity/ui");
|
|
7
|
+
var $7xGut$sanitydashboard = require("@sanity/dashboard");
|
|
8
|
+
var $7xGut$rxjs = require("rxjs");
|
|
9
|
+
var $7xGut$rxjsoperators = require("rxjs/operators");
|
|
10
|
+
var $7xGut$lodashuniqBy = require("lodash/uniqBy");
|
|
11
11
|
|
|
12
12
|
function $parcel$export(e, n, v, s) {
|
|
13
13
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -40,7 +40,7 @@ function $91d1c422801a90a3$var$prepareDocumentList(incoming, client) {
|
|
|
40
40
|
const foundDraft = drafts.find((draft)=>draft._id === $91d1c422801a90a3$var$draftId(doc));
|
|
41
41
|
return foundDraft || doc;
|
|
42
42
|
});
|
|
43
|
-
return (0, ($parcel$interopDefault($
|
|
43
|
+
return (0, ($parcel$interopDefault($7xGut$lodashuniqBy)))(outgoing, "_id");
|
|
44
44
|
}).catch((error)=>{
|
|
45
45
|
throw new Error(`Problems fetching docs ${ids}. Error: ${error.message}`);
|
|
46
46
|
});
|
|
@@ -53,8 +53,8 @@ function $91d1c422801a90a3$export$161e8c29756c0df4(query, params, client) {
|
|
|
53
53
|
],
|
|
54
54
|
includeResult: false,
|
|
55
55
|
visibility: "query"
|
|
56
|
-
}).pipe((0, $
|
|
57
|
-
return (0, $
|
|
56
|
+
}).pipe((0, $7xGut$rxjsoperators.switchMap)((event)=>{
|
|
57
|
+
return (0, $7xGut$rxjs.of)(1).pipe(event.type === "welcome" ? (0, $7xGut$rxjsoperators.tap)() : (0, $7xGut$rxjsoperators.delay)(1000), (0, $7xGut$rxjsoperators.mergeMap)(()=>client.fetch(query, params).then((incoming)=>{
|
|
58
58
|
return $91d1c422801a90a3$var$prepareDocumentList(incoming, client);
|
|
59
59
|
}).catch((error)=>{
|
|
60
60
|
if (error.message.startsWith("Problems fetching docs")) throw error;
|
|
@@ -79,18 +79,18 @@ function $77d50d608d9ace00$export$65a803c9e13a7e5b(props) {
|
|
|
79
79
|
...$77d50d608d9ace00$var$defaultProps,
|
|
80
80
|
...props
|
|
81
81
|
};
|
|
82
|
-
const [documents, setDocuments] = (0, $
|
|
83
|
-
const [loading, setLoading] = (0, $
|
|
84
|
-
const [error, setError] = (0, $
|
|
85
|
-
const client = (0, $
|
|
86
|
-
const schema = (0, $
|
|
87
|
-
const versionedClient = (0, $
|
|
82
|
+
const [documents, setDocuments] = (0, $7xGut$react.useState)();
|
|
83
|
+
const [loading, setLoading] = (0, $7xGut$react.useState)(true);
|
|
84
|
+
const [error, setError] = (0, $7xGut$react.useState)();
|
|
85
|
+
const client = (0, $7xGut$sanity.useClient)();
|
|
86
|
+
const schema = (0, $7xGut$sanity.useSchema)();
|
|
87
|
+
const versionedClient = (0, $7xGut$react.useMemo)(()=>client.withConfig({
|
|
88
88
|
apiVersion: apiVersion
|
|
89
89
|
}), [
|
|
90
90
|
client,
|
|
91
91
|
apiVersion
|
|
92
92
|
]);
|
|
93
|
-
const { assembledQuery: assembledQuery , params: params } = (0, $
|
|
93
|
+
const { assembledQuery: assembledQuery , params: params } = (0, $7xGut$react.useMemo)(()=>{
|
|
94
94
|
if (query) return {
|
|
95
95
|
assembledQuery: query,
|
|
96
96
|
params: queryParams
|
|
@@ -102,7 +102,7 @@ function $77d50d608d9ace00$export$65a803c9e13a7e5b(props) {
|
|
|
102
102
|
return {
|
|
103
103
|
assembledQuery: `*[_type in $types] | order(${order}) [0...${limit * 2}]`,
|
|
104
104
|
params: {
|
|
105
|
-
types: types ? (0, $
|
|
105
|
+
types: types ? (0, $7xGut$lodash.intersection)(types, documentTypes) : documentTypes
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
}, [
|
|
@@ -113,7 +113,7 @@ function $77d50d608d9ace00$export$65a803c9e13a7e5b(props) {
|
|
|
113
113
|
limit,
|
|
114
114
|
types
|
|
115
115
|
]);
|
|
116
|
-
(0, $
|
|
116
|
+
(0, $7xGut$react.useEffect)(()=>{
|
|
117
117
|
if (!assembledQuery) return;
|
|
118
118
|
const subscription = (0, $91d1c422801a90a3$export$161e8c29756c0df4)(assembledQuery, params, versionedClient).subscribe({
|
|
119
119
|
next: (d)=>{
|
|
@@ -135,9 +135,9 @@ function $77d50d608d9ace00$export$65a803c9e13a7e5b(props) {
|
|
|
135
135
|
assembledQuery,
|
|
136
136
|
params
|
|
137
137
|
]);
|
|
138
|
-
return /*#__PURE__*/ (0, $
|
|
138
|
+
return /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanitydashboard.DashboardWidgetContainer), {
|
|
139
139
|
header: title,
|
|
140
|
-
footer: types && types.length === 1 && showCreateButton && /*#__PURE__*/ (0, $
|
|
140
|
+
footer: types && types.length === 1 && showCreateButton && /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanity_unstable.IntentButton), {
|
|
141
141
|
mode: "bleed",
|
|
142
142
|
style: {
|
|
143
143
|
width: "100%"
|
|
@@ -152,26 +152,26 @@ function $77d50d608d9ace00$export$65a803c9e13a7e5b(props) {
|
|
|
152
152
|
},
|
|
153
153
|
text: createButtonText || `Create new ${types[0]}`
|
|
154
154
|
}),
|
|
155
|
-
children: /*#__PURE__*/ (0, $
|
|
155
|
+
children: /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsxs)((0, $7xGut$sanityui.Card), {
|
|
156
156
|
children: [
|
|
157
|
-
error && /*#__PURE__*/ (0, $
|
|
157
|
+
error && /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)("div", {
|
|
158
158
|
children: error.message
|
|
159
159
|
}),
|
|
160
|
-
!error && loading && /*#__PURE__*/ (0, $
|
|
160
|
+
!error && loading && /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanityui.Card), {
|
|
161
161
|
padding: 4,
|
|
162
|
-
children: /*#__PURE__*/ (0, $
|
|
162
|
+
children: /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanityui.Flex), {
|
|
163
163
|
justify: "center",
|
|
164
|
-
children: /*#__PURE__*/ (0, $
|
|
164
|
+
children: /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanityui.Spinner), {
|
|
165
165
|
muted: true
|
|
166
166
|
})
|
|
167
167
|
})
|
|
168
168
|
}),
|
|
169
|
-
!error && !documents && !loading && /*#__PURE__*/ (0, $
|
|
169
|
+
!error && !documents && !loading && /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)("div", {
|
|
170
170
|
children: "Could not locate any documents :/"
|
|
171
171
|
}),
|
|
172
|
-
/*#__PURE__*/ (0, $
|
|
172
|
+
/*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanityui.Stack), {
|
|
173
173
|
space: 2,
|
|
174
|
-
children: documents && documents.map((doc)=>/*#__PURE__*/ (0, $
|
|
174
|
+
children: documents && documents.map((doc)=>/*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)($77d50d608d9ace00$var$MenuEntry, {
|
|
175
175
|
doc: doc
|
|
176
176
|
}, doc._id))
|
|
177
177
|
})
|
|
@@ -180,23 +180,23 @@ function $77d50d608d9ace00$export$65a803c9e13a7e5b(props) {
|
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
function $77d50d608d9ace00$var$MenuEntry({ doc: doc }) {
|
|
183
|
-
const schema = (0, $
|
|
183
|
+
const schema = (0, $7xGut$sanity.useSchema)();
|
|
184
184
|
const type = schema.get(doc._type);
|
|
185
|
-
return /*#__PURE__*/ (0, $
|
|
185
|
+
return /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanityui.Card), {
|
|
186
186
|
flex: 1,
|
|
187
|
-
children: /*#__PURE__*/ (0, $
|
|
187
|
+
children: /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanity_unstable.IntentButton), {
|
|
188
188
|
intent: "edit",
|
|
189
189
|
mode: "bleed",
|
|
190
190
|
padding: 1,
|
|
191
191
|
radius: 0,
|
|
192
192
|
params: {
|
|
193
193
|
type: doc._type,
|
|
194
|
-
id: (0, $
|
|
194
|
+
id: (0, $7xGut$sanity.getPublishedId)(doc._id)
|
|
195
195
|
},
|
|
196
196
|
style: {
|
|
197
197
|
width: "100%"
|
|
198
198
|
},
|
|
199
|
-
children: /*#__PURE__*/ (0, $
|
|
199
|
+
children: /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $7xGut$sanity_unstable.SanityPreview), {
|
|
200
200
|
layout: "default",
|
|
201
201
|
type: type,
|
|
202
202
|
value: doc
|
|
@@ -212,7 +212,7 @@ function $9233cea927cb9637$export$398a1547d616c51(config) {
|
|
|
212
212
|
return {
|
|
213
213
|
name: "document-list-widget",
|
|
214
214
|
component: function component() {
|
|
215
|
-
return /*#__PURE__*/ (0, $
|
|
215
|
+
return /*#__PURE__*/ (0, $7xGut$reactjsxruntime.jsx)((0, $77d50d608d9ace00$export$2e2bcd8739ae039), {
|
|
216
216
|
...config
|
|
217
217
|
});
|
|
218
218
|
},
|
|
File without changes
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {jsx as $
|
|
2
|
-
import {useState as $
|
|
3
|
-
import {IntentButton as $
|
|
4
|
-
import {useClient as $
|
|
5
|
-
import {intersection as $
|
|
6
|
-
import {Card as $
|
|
7
|
-
import {DashboardWidgetContainer as $
|
|
8
|
-
import {of as $
|
|
9
|
-
import {switchMap as $
|
|
10
|
-
import $
|
|
1
|
+
import {jsx as $5lYf0$jsx, jsxs as $5lYf0$jsxs} from "react/jsx-runtime";
|
|
2
|
+
import {useState as $5lYf0$useState, useMemo as $5lYf0$useMemo, useEffect as $5lYf0$useEffect} from "react";
|
|
3
|
+
import {IntentButton as $5lYf0$IntentButton, SanityPreview as $5lYf0$SanityPreview} from "sanity/_unstable";
|
|
4
|
+
import {useClient as $5lYf0$useClient, useSchema as $5lYf0$useSchema, getPublishedId as $5lYf0$getPublishedId} from "sanity";
|
|
5
|
+
import {intersection as $5lYf0$intersection} from "lodash";
|
|
6
|
+
import {Card as $5lYf0$Card, Flex as $5lYf0$Flex, Spinner as $5lYf0$Spinner, Stack as $5lYf0$Stack} from "@sanity/ui";
|
|
7
|
+
import {DashboardWidgetContainer as $5lYf0$DashboardWidgetContainer} from "@sanity/dashboard";
|
|
8
|
+
import {of as $5lYf0$of} from "rxjs";
|
|
9
|
+
import {switchMap as $5lYf0$switchMap, tap as $5lYf0$tap, delay as $5lYf0$delay, mergeMap as $5lYf0$mergeMap} from "rxjs/operators";
|
|
10
|
+
import $5lYf0$lodashuniqBy from "lodash/uniqBy";
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
@@ -32,7 +32,7 @@ function $31d241600102c2cb$var$prepareDocumentList(incoming, client) {
|
|
|
32
32
|
const foundDraft = drafts.find((draft)=>draft._id === $31d241600102c2cb$var$draftId(doc));
|
|
33
33
|
return foundDraft || doc;
|
|
34
34
|
});
|
|
35
|
-
return (0, $
|
|
35
|
+
return (0, $5lYf0$lodashuniqBy)(outgoing, "_id");
|
|
36
36
|
}).catch((error)=>{
|
|
37
37
|
throw new Error(`Problems fetching docs ${ids}. Error: ${error.message}`);
|
|
38
38
|
});
|
|
@@ -45,8 +45,8 @@ function $31d241600102c2cb$export$161e8c29756c0df4(query, params, client) {
|
|
|
45
45
|
],
|
|
46
46
|
includeResult: false,
|
|
47
47
|
visibility: "query"
|
|
48
|
-
}).pipe((0, $
|
|
49
|
-
return (0, $
|
|
48
|
+
}).pipe((0, $5lYf0$switchMap)((event)=>{
|
|
49
|
+
return (0, $5lYf0$of)(1).pipe(event.type === "welcome" ? (0, $5lYf0$tap)() : (0, $5lYf0$delay)(1000), (0, $5lYf0$mergeMap)(()=>client.fetch(query, params).then((incoming)=>{
|
|
50
50
|
return $31d241600102c2cb$var$prepareDocumentList(incoming, client);
|
|
51
51
|
}).catch((error)=>{
|
|
52
52
|
if (error.message.startsWith("Problems fetching docs")) throw error;
|
|
@@ -71,18 +71,18 @@ function $df774c2b801774e3$export$65a803c9e13a7e5b(props) {
|
|
|
71
71
|
...$df774c2b801774e3$var$defaultProps,
|
|
72
72
|
...props
|
|
73
73
|
};
|
|
74
|
-
const [documents, setDocuments] = (0, $
|
|
75
|
-
const [loading, setLoading] = (0, $
|
|
76
|
-
const [error, setError] = (0, $
|
|
77
|
-
const client = (0, $
|
|
78
|
-
const schema = (0, $
|
|
79
|
-
const versionedClient = (0, $
|
|
74
|
+
const [documents, setDocuments] = (0, $5lYf0$useState)();
|
|
75
|
+
const [loading, setLoading] = (0, $5lYf0$useState)(true);
|
|
76
|
+
const [error, setError] = (0, $5lYf0$useState)();
|
|
77
|
+
const client = (0, $5lYf0$useClient)();
|
|
78
|
+
const schema = (0, $5lYf0$useSchema)();
|
|
79
|
+
const versionedClient = (0, $5lYf0$useMemo)(()=>client.withConfig({
|
|
80
80
|
apiVersion: apiVersion
|
|
81
81
|
}), [
|
|
82
82
|
client,
|
|
83
83
|
apiVersion
|
|
84
84
|
]);
|
|
85
|
-
const { assembledQuery: assembledQuery , params: params } = (0, $
|
|
85
|
+
const { assembledQuery: assembledQuery , params: params } = (0, $5lYf0$useMemo)(()=>{
|
|
86
86
|
if (query) return {
|
|
87
87
|
assembledQuery: query,
|
|
88
88
|
params: queryParams
|
|
@@ -94,7 +94,7 @@ function $df774c2b801774e3$export$65a803c9e13a7e5b(props) {
|
|
|
94
94
|
return {
|
|
95
95
|
assembledQuery: `*[_type in $types] | order(${order}) [0...${limit * 2}]`,
|
|
96
96
|
params: {
|
|
97
|
-
types: types ? (0, $
|
|
97
|
+
types: types ? (0, $5lYf0$intersection)(types, documentTypes) : documentTypes
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
}, [
|
|
@@ -105,7 +105,7 @@ function $df774c2b801774e3$export$65a803c9e13a7e5b(props) {
|
|
|
105
105
|
limit,
|
|
106
106
|
types
|
|
107
107
|
]);
|
|
108
|
-
(0, $
|
|
108
|
+
(0, $5lYf0$useEffect)(()=>{
|
|
109
109
|
if (!assembledQuery) return;
|
|
110
110
|
const subscription = (0, $31d241600102c2cb$export$161e8c29756c0df4)(assembledQuery, params, versionedClient).subscribe({
|
|
111
111
|
next: (d)=>{
|
|
@@ -127,9 +127,9 @@ function $df774c2b801774e3$export$65a803c9e13a7e5b(props) {
|
|
|
127
127
|
assembledQuery,
|
|
128
128
|
params
|
|
129
129
|
]);
|
|
130
|
-
return /*#__PURE__*/ (0, $
|
|
130
|
+
return /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$DashboardWidgetContainer), {
|
|
131
131
|
header: title,
|
|
132
|
-
footer: types && types.length === 1 && showCreateButton && /*#__PURE__*/ (0, $
|
|
132
|
+
footer: types && types.length === 1 && showCreateButton && /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$IntentButton), {
|
|
133
133
|
mode: "bleed",
|
|
134
134
|
style: {
|
|
135
135
|
width: "100%"
|
|
@@ -144,26 +144,26 @@ function $df774c2b801774e3$export$65a803c9e13a7e5b(props) {
|
|
|
144
144
|
},
|
|
145
145
|
text: createButtonText || `Create new ${types[0]}`
|
|
146
146
|
}),
|
|
147
|
-
children: /*#__PURE__*/ (0, $
|
|
147
|
+
children: /*#__PURE__*/ (0, $5lYf0$jsxs)((0, $5lYf0$Card), {
|
|
148
148
|
children: [
|
|
149
|
-
error && /*#__PURE__*/ (0, $
|
|
149
|
+
error && /*#__PURE__*/ (0, $5lYf0$jsx)("div", {
|
|
150
150
|
children: error.message
|
|
151
151
|
}),
|
|
152
|
-
!error && loading && /*#__PURE__*/ (0, $
|
|
152
|
+
!error && loading && /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$Card), {
|
|
153
153
|
padding: 4,
|
|
154
|
-
children: /*#__PURE__*/ (0, $
|
|
154
|
+
children: /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$Flex), {
|
|
155
155
|
justify: "center",
|
|
156
|
-
children: /*#__PURE__*/ (0, $
|
|
156
|
+
children: /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$Spinner), {
|
|
157
157
|
muted: true
|
|
158
158
|
})
|
|
159
159
|
})
|
|
160
160
|
}),
|
|
161
|
-
!error && !documents && !loading && /*#__PURE__*/ (0, $
|
|
161
|
+
!error && !documents && !loading && /*#__PURE__*/ (0, $5lYf0$jsx)("div", {
|
|
162
162
|
children: "Could not locate any documents :/"
|
|
163
163
|
}),
|
|
164
|
-
/*#__PURE__*/ (0, $
|
|
164
|
+
/*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$Stack), {
|
|
165
165
|
space: 2,
|
|
166
|
-
children: documents && documents.map((doc)=>/*#__PURE__*/ (0, $
|
|
166
|
+
children: documents && documents.map((doc)=>/*#__PURE__*/ (0, $5lYf0$jsx)($df774c2b801774e3$var$MenuEntry, {
|
|
167
167
|
doc: doc
|
|
168
168
|
}, doc._id))
|
|
169
169
|
})
|
|
@@ -172,23 +172,23 @@ function $df774c2b801774e3$export$65a803c9e13a7e5b(props) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
function $df774c2b801774e3$var$MenuEntry({ doc: doc }) {
|
|
175
|
-
const schema = (0, $
|
|
175
|
+
const schema = (0, $5lYf0$useSchema)();
|
|
176
176
|
const type = schema.get(doc._type);
|
|
177
|
-
return /*#__PURE__*/ (0, $
|
|
177
|
+
return /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$Card), {
|
|
178
178
|
flex: 1,
|
|
179
|
-
children: /*#__PURE__*/ (0, $
|
|
179
|
+
children: /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$IntentButton), {
|
|
180
180
|
intent: "edit",
|
|
181
181
|
mode: "bleed",
|
|
182
182
|
padding: 1,
|
|
183
183
|
radius: 0,
|
|
184
184
|
params: {
|
|
185
185
|
type: doc._type,
|
|
186
|
-
id: (0, $
|
|
186
|
+
id: (0, $5lYf0$getPublishedId)(doc._id)
|
|
187
187
|
},
|
|
188
188
|
style: {
|
|
189
189
|
width: "100%"
|
|
190
190
|
},
|
|
191
|
-
children: /*#__PURE__*/ (0, $
|
|
191
|
+
children: /*#__PURE__*/ (0, $5lYf0$jsx)((0, $5lYf0$SanityPreview), {
|
|
192
192
|
layout: "default",
|
|
193
193
|
type: type,
|
|
194
194
|
value: doc
|
|
@@ -204,7 +204,7 @@ function $090815f5086f7f29$export$398a1547d616c51(config) {
|
|
|
204
204
|
return {
|
|
205
205
|
name: "document-list-widget",
|
|
206
206
|
component: function component() {
|
|
207
|
-
return /*#__PURE__*/ (0, $
|
|
207
|
+
return /*#__PURE__*/ (0, $5lYf0$jsx)((0, $df774c2b801774e3$export$2e2bcd8739ae039), {
|
|
208
208
|
...config
|
|
209
209
|
});
|
|
210
210
|
},
|
|
@@ -214,4 +214,4 @@ function $090815f5086f7f29$export$398a1547d616c51(config) {
|
|
|
214
214
|
|
|
215
215
|
|
|
216
216
|
export {$090815f5086f7f29$export$398a1547d616c51 as documentListWidget};
|
|
217
|
-
//# sourceMappingURL=index.
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;ACAA;;;;;ACAA;;;AAMA,MAAM,6BAAO,GAAG,CAAC,WAA2B,GAAK,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;AAE5E,SAAS,yCAAmB,CAC1B,QAA2C,EAC3C,MAAoB,EACO;IAC3B,IAAI,CAAC,QAAQ,EACX,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAE5B,MAAM,SAAS,GAAG,KAAK,CAAC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3D;MACV,CACR;CACF;IAED,wCAA2B,GAAZ,yCAAY;;;;ADhJpB,SAAS,wCAAkB,CAAC,MAAgC,EAAmB;IACpF,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,SAAS,EAAE,SAAS,SAAS,GAAG;YAC9B,qBAAO,gBAAC,CAAA,GAAA,wCAAY,CAAA;gBAAE,GAAG,MAAM;cAAI,CAAA;SACpC;QACD,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAA;CACF","sources":["src/index.tsx","src/DocumentList.tsx","src/sanityConnector.ts"],"sourcesContent":["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","import React, {useEffect, useMemo, useState} from 'react'\nimport {IntentButton, SanityPreview} from 'sanity/_unstable'\nimport {getPublishedId, useClient, useSchema} from 'sanity'\nimport {intersection} from 'lodash'\nimport {getSubscription} from './sanityConnector'\nimport {SanityDocument} from '@sanity/types'\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 client = useClient()\n const schema = useSchema()\n const versionedClient = useMemo(() => client.withConfig({apiVersion}), [client, apiVersion])\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 && 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 <SanityPreview layout=\"default\" type={type} value={doc} key={doc._id} />\n </IntentButton>\n </Card>\n )\n}\n\nexport default DocumentList\n","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/types'\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('*[_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"],"names":[],"version":3,"file":"index.modern.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;ACAA;;;;;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AAE,CAAA,GAAA,qBAAc,CAAA,CAAC,GAAG,CAAC,GAAG,CAAC;aAC5B;YACD,KAAK,EAAE;gBAAC,KAAK,EAAE,MAAM;aAAC;sBAEtB,cAAA,gBAAC,CAAA,GAAA,oBAAa,CAAA;gBAAC,MAAM,EAAC,SAAS;gBAAC,IAAI,EAAE,IAAI;gBAAE,KAAK,EAAE,GAAG;eAAO,GAAG,CAAC,GAAG,CAAI;UAC3D;MACV,CACR;CACF;IAED,wCAA2B,GAAZ,yCAAY;;;;ADhJpB,SAAS,wCAAkB,CAAC,MAAgC,EAAmB;IACpF,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,SAAS,EAAE,SAAS,SAAS,GAAG;YAC9B,qBAAO,gBAAC,CAAA,GAAA,wCAAY,CAAA;gBAAE,GAAG,MAAM;cAAI,CAAA;SACpC;QACD,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAA;CACF","sources":["src/index.tsx","src/DocumentList.tsx","src/sanityConnector.ts"],"sourcesContent":["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","import React, {useEffect, useMemo, useState} from 'react'\nimport {IntentButton, SanityPreview} from 'sanity/_unstable'\nimport {getPublishedId, useClient, useSchema} from 'sanity'\nimport {intersection} from 'lodash'\nimport {getSubscription} from './sanityConnector'\nimport {SanityDocument} from '@sanity/types'\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 client = useClient()\n const schema = useSchema()\n const versionedClient = useMemo(() => client.withConfig({apiVersion}), [client, apiVersion])\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 && 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 <SanityPreview layout=\"default\" type={type} value={doc} key={doc._id} />\n </IntentButton>\n </Card>\n )\n}\n\nexport default DocumentList\n","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/types'\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('*[_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"],"names":[],"version":3,"file":"index.js.map"}
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"public": true,
|
|
3
3
|
"name": "sanity-plugin-dashboard-widget-document-list",
|
|
4
|
-
"version": "3.0.0-studio-v3.
|
|
4
|
+
"version": "3.0.0-studio-v3.3",
|
|
5
5
|
"author": "Sanity.io <hello@sanity.io>",
|
|
6
6
|
"description": "Example dashboard widget for Sanity Content Studio",
|
|
7
7
|
"homepage": "https://github.com/sanity-io/dashboard-widget-document-list#readme",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"prettier": "^2.6.2",
|
|
65
65
|
"react": "^17.0.0 || ^18.0.0",
|
|
66
66
|
"rimraf": "^3.0.2",
|
|
67
|
-
"sanity": "
|
|
67
|
+
"sanity": "purple-unicorn",
|
|
68
68
|
"typescript": "^4.7.3"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"react": "^17.0.0 || ^18.0.0",
|
|
72
|
-
"sanity": "
|
|
72
|
+
"sanity": "purple-unicorn"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@sanity/ui": "^0.37.9",
|