sanity-plugin-documents-pane 1.0.9 → 2.0.0-v3-studio.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Simeon Griggs
3
+ Copyright (c) 2022 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,18 +1,28 @@
1
1
  # sanity-plugin-documents-pane
2
2
 
3
+ > This version of `sanity-plugin-documents-pane` is for [Sanity Studio V3](https://www.sanity.io/blog/sanity-studio-v3-developer-preview), which is currently in developer preview.
4
+ >
5
+ > The Studio V2 compatible version can be found on the [V2 branch](https://github.com/sanity-io/sanity-plugin-documents-pane).
6
+
3
7
  Displays the results of a GROQ query in a View Pane. With the ability to use field values in the current document as query parameters.
4
8
 
5
9
  ![Incoming References](https://user-images.githubusercontent.com/9684022/121202594-52bc6180-c86d-11eb-897d-f418047b3d22.png)
6
10
 
7
11
  ## Installation
8
12
 
13
+ ```sh
14
+ npm install --save sanity-plugin-documents-pane@studio-v3
9
15
  ```
10
- sanity install documents-pane
16
+
17
+ or
18
+
19
+ ```sh
20
+ yarn add sanity-plugin-documents-pane@studio-v3
11
21
  ```
12
22
 
13
23
  This plugin is designed to be used as a [Component inside of a View](https://www.sanity.io/docs/structure-builder-reference#c0c8284844b7).
14
24
 
15
- The example below illustrates using the current Document being used to query for all Documents that reference it.
25
+ The example below illustrates using the current Document being used to query for all published documents that reference it.
16
26
 
17
27
  ```js
18
28
  // ./src/deskStructure.js
@@ -25,18 +35,65 @@ S.view
25
35
  .options({
26
36
  query: `*[!(_id in path("drafts.**")) && references($id)]`,
27
37
  params: {id: `_id`},
28
- useDraft: false,
29
- debug: true,
30
38
  })
31
39
  .title('Incoming References')
32
40
  ```
33
41
 
34
42
  The `.options()` configuration works as follows:
35
43
 
36
- - `query` (string, required)
37
- - `params` (object, optional) A [dot-notated string](https://www.npmjs.com/package/dlv) from the document object to a field, to use as variables in the query.
38
- - `useDraft` (bool, optional, default: `false`) When populating the `params` values, it will use the `published` version of the document by default.
44
+ - `query` (string, required) A string defining the entire GROQ query that will select documents to list.
45
+ - `params` (object or function, optional)
46
+ - Object: a [dot-notated string](https://www.npmjs.com/package/dlv) from the document object to a field, to use as variables in the query.
47
+ - Function: a function that receives the various displayed, draft, and published versions of the document, and returns an object of query parameters. Return null if the parameters cannot be resolved.
48
+ - `useDraft` (bool, optional, default: `false`) When populating the `params` values, it will use the `published` version of the document by default. Not permitted if using a function for `params` as the function will determine which version of the document to use.
39
49
  - `debug` (bool, optional, default: `false`) In case of an error or the query returning no documents, setting to `true` will display the query and params that were used.
50
+ - `initialValueTemplates` (function, optional) A function that receives the various displayed, draft, and published versions of the document, and returns a list of initial value templates. These will be used to define buttons at the top of the list so users can create new related documents.
51
+
52
+ ## Resolving query parameters with a function and providing initial value templates
53
+
54
+ Providing a function for `params` allows us to modify values from the current document, for example to list references to a draft document. Providing a function for the `initialValueTemplates` option allows us to determine which buttons to show and what parameters will be used for the new document.
55
+
56
+ ```js
57
+ const options = {
58
+ query: `*[_type=="post" && author._ref == $id]`,
59
+ params: ({document}) => {
60
+ // references will never point to a draft ID, so extract the regular ID
61
+ const id = document.displayed._id?.replace('drafts.', '')
62
+
63
+ // we don't have to worry about undefined parameters,
64
+ // as the plugin will handle them and show an appropriate message
65
+ return {id}
66
+ },
67
+ initialValueTemplates: ({document}) => {
68
+ const templates = []
69
+
70
+ // references must point to a non-draft ID, so if using the ID in the template,
71
+ // be sure it doesn't start with `drafts.`
72
+ const id = document?.displayed?._id.replace('drafts.', '')
73
+ const name = document?.displayed?.name || 'author'
74
+
75
+ if (id) {
76
+ templates.push({
77
+ // the name of the schema type that should be created (required)
78
+ schemaType: 'post',
79
+ // the title that should appear on the button - we can customize it (required)
80
+ title: `New post by ${name}`,
81
+ // the name of the template that should be used (optional)
82
+ template: 'postWithAuthor',
83
+ // values for parameters that can be passed to the template referenced above (optional)
84
+ parameters: {
85
+ authorId: id,
86
+ },
87
+ })
88
+
89
+ // we could push more templates if needed.
90
+ }
91
+
92
+ // must always return a list, even if empty
93
+ return templates
94
+ },
95
+ }
96
+ ```
40
97
 
41
98
  ## Thanks!
42
99
 
@@ -44,5 +101,5 @@ This plugin is based on [Incoming References](https://github.com/sanity-io/sanit
44
101
 
45
102
  ## License
46
103
 
47
- MIT © Simeon Griggs
48
- See LICENSE
104
+ MIT © Sanity.io
105
+ See [LICENSE](license)
@@ -0,0 +1,367 @@
1
+ var $k7rGe$reactjsxruntime = require("react/jsx-runtime");
2
+ var $k7rGe$react = require("react");
3
+ var $k7rGe$sanityui = require("@sanity/ui");
4
+ var $k7rGe$sanityutilpaths = require("@sanity/util/paths");
5
+ var $k7rGe$sanity = require("sanity");
6
+ var $k7rGe$sanitydesk = require("sanity/desk");
7
+ var $k7rGe$sanity_unstable = require("sanity/_unstable");
8
+ var $k7rGe$rxjsoperators = require("rxjs/operators");
9
+ var $k7rGe$reactfastcompare = require("react-fast-compare");
10
+ var $k7rGe$sanityicons = require("@sanity/icons");
11
+ var $k7rGe$sanityuuid = require("@sanity/uuid");
12
+ var $k7rGe$dlv = require("dlv");
13
+
14
+ function $parcel$defineInteropFlag(a) {
15
+ Object.defineProperty(a, '__esModule', {value: true, configurable: true});
16
+ }
17
+ function $parcel$export(e, n, v, s) {
18
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
19
+ }
20
+ function $parcel$interopDefault(a) {
21
+ return a && a.__esModule ? a.default : a;
22
+ }
23
+
24
+ $parcel$defineInteropFlag(module.exports);
25
+
26
+ $parcel$export(module.exports, "default", () => $244e63ca53592e4d$export$2e2bcd8739ae039);
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+ function $8bf99469d8dcf610$export$2e2bcd8739ae039({ query: query , params: params }) {
41
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$reactjsxruntime.Fragment), {
42
+ children: [
43
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
44
+ space: 4,
45
+ children: [
46
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
47
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Label), {
48
+ children: "Query"
49
+ })
50
+ }),
51
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
52
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Code), {
53
+ children: query
54
+ })
55
+ })
56
+ ]
57
+ }),
58
+ params && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
59
+ space: 4,
60
+ children: [
61
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
62
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Label), {
63
+ children: "Params"
64
+ })
65
+ }),
66
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
67
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Code), {
68
+ children: JSON.stringify(params)
69
+ })
70
+ })
71
+ ]
72
+ })
73
+ ]
74
+ });
75
+ }
76
+
77
+
78
+
79
+
80
+
81
+ function $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039(props) {
82
+ const { children: children , tone: tone = `caution` } = props;
83
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Card), {
84
+ padding: 3,
85
+ radius: 2,
86
+ shadow: 1,
87
+ tone: tone,
88
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Text), {
89
+ size: 1,
90
+ children: children
91
+ })
92
+ });
93
+ }
94
+
95
+
96
+
97
+
98
+
99
+
100
+ const $18acc44f6f71937f$var$DEFAULT_PARAMS = {};
101
+ const $18acc44f6f71937f$var$DEFAULT_OPTIONS = {
102
+ apiVersion: `v2022-05-09`
103
+ };
104
+ function $18acc44f6f71937f$export$2e2bcd8739ae039(query, params = $18acc44f6f71937f$var$DEFAULT_PARAMS, options = $18acc44f6f71937f$var$DEFAULT_OPTIONS) {
105
+ const [loading, setLoading] = (0, $k7rGe$react.useState)(true);
106
+ const [error, setError] = (0, $k7rGe$react.useState)(false);
107
+ const [data, setData] = (0, $k7rGe$react.useState)(null);
108
+ const subscription = (0, $k7rGe$react.useRef)(null);
109
+ const documentStore = (0, $k7rGe$sanity_unstable.useDocumentStore)();
110
+ (0, $k7rGe$react.useEffect)(()=>{
111
+ if (query) subscription.current = documentStore.listenQuery(query, params, options).pipe((0, $k7rGe$rxjsoperators.distinctUntilChanged)((0, ($parcel$interopDefault($k7rGe$reactfastcompare)))), (0, $k7rGe$rxjsoperators.catchError)((err)=>{
112
+ console.error(err);
113
+ setError(err);
114
+ setLoading(false);
115
+ setData(null);
116
+ return err;
117
+ })).subscribe((documents)=>{
118
+ setData((current)=>(0, ($parcel$interopDefault($k7rGe$reactfastcompare)))(current, documents) ? current : documents);
119
+ setLoading(false);
120
+ setError(false);
121
+ });
122
+ return ()=>{
123
+ return subscription.current ? subscription.current.unsubscribe() : undefined;
124
+ };
125
+ }, [
126
+ query,
127
+ params,
128
+ options
129
+ ]);
130
+ return {
131
+ loading: loading,
132
+ error: error,
133
+ data: data
134
+ };
135
+ }
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+ function $84571eed53af196d$export$2e2bcd8739ae039(props) {
145
+ const { initialValueTemplates: initialValueTemplates = [] } = props;
146
+ const { ReferenceChildLink: ReferenceChildLink } = (0, $k7rGe$sanitydesk.usePaneRouter)();
147
+ if (!initialValueTemplates.length) return null;
148
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Card), {
149
+ borderBottom: true,
150
+ padding: 2,
151
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Flex), {
152
+ justify: "flex-end",
153
+ gap: 1,
154
+ children: initialValueTemplates.map((template)=>{
155
+ if (!template.template) return null;
156
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)(ReferenceChildLink, {
157
+ documentId: (0, $k7rGe$sanityuuid.uuid)(),
158
+ documentType: template.schemaType,
159
+ template: {
160
+ id: template.template,
161
+ params: template.parameters
162
+ },
163
+ parentRefPath: [],
164
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Button), {
165
+ icon: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityicons.ComposeIcon), {}),
166
+ text: template.title,
167
+ mode: "bleed",
168
+ as: "span"
169
+ })
170
+ }, `${template.schemaType}-${template.template}`);
171
+ })
172
+ })
173
+ });
174
+ }
175
+
176
+
177
+ function $69bfdff7425bcf41$export$2e2bcd8739ae039(props) {
178
+ const { query: query , params: params , debug: debug , initialValueTemplates: initialValueTemplates } = props;
179
+ const { routerPanesState: routerPanesState , groupIndex: groupIndex , handleEditReference: handleEditReference } = (0, $k7rGe$sanitydesk.usePaneRouter)();
180
+ const schema = (0, $k7rGe$sanity.useSchema)();
181
+ const { loading: loading , error: error , data: data } = (0, $18acc44f6f71937f$export$2e2bcd8739ae039)(query, params);
182
+ const handleClick = (0, $k7rGe$react.useCallback)((id, type)=>{
183
+ const childParams = routerPanesState[groupIndex + 1]?.[0].params || {};
184
+ const { parentRefPath: parentRefPath } = childParams;
185
+ handleEditReference({
186
+ id: id,
187
+ type: type,
188
+ // Uncertain that this works as intended
189
+ parentRefPath: parentRefPath ? (0, $k7rGe$sanityutilpaths.fromString)(parentRefPath) : [
190
+ ``
191
+ ],
192
+ // Added this to satisfy TS
193
+ template: type
194
+ });
195
+ }, [
196
+ routerPanesState,
197
+ groupIndex,
198
+ handleEditReference
199
+ ]);
200
+ if (loading) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
201
+ padding: 4,
202
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Flex), {
203
+ justify: "center",
204
+ align: "center",
205
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Spinner), {
206
+ muted: true
207
+ })
208
+ })
209
+ });
210
+ if (error) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
211
+ padding: 4,
212
+ space: 5,
213
+ children: [
214
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
215
+ children: "There was en error performing this query"
216
+ }),
217
+ debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
218
+ query: query,
219
+ params: params
220
+ })
221
+ ]
222
+ });
223
+ if (!data?.length) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$reactjsxruntime.Fragment), {
224
+ children: [
225
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $84571eed53af196d$export$2e2bcd8739ae039), {
226
+ initialValueTemplates: initialValueTemplates
227
+ }),
228
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
229
+ padding: 4,
230
+ space: 5,
231
+ children: [
232
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
233
+ children: "No Documents found"
234
+ }),
235
+ debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
236
+ query: query,
237
+ params: params
238
+ })
239
+ ]
240
+ })
241
+ ]
242
+ });
243
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$reactjsxruntime.Fragment), {
244
+ children: [
245
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $84571eed53af196d$export$2e2bcd8739ae039), {
246
+ initialValueTemplates: initialValueTemplates
247
+ }),
248
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Stack), {
249
+ padding: 2,
250
+ space: 1,
251
+ children: data.map((doc)=>{
252
+ const schemaType = schema.get(doc._type);
253
+ if (!schemaType) return null;
254
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Button), {
255
+ onClick: ()=>handleClick(doc._id, doc._type),
256
+ padding: 2,
257
+ mode: "bleed",
258
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanity_unstable.SanityPreview), {
259
+ value: doc,
260
+ schemaType: schemaType
261
+ })
262
+ }, doc._id);
263
+ })
264
+ })
265
+ ]
266
+ });
267
+ }
268
+
269
+
270
+
271
+
272
+
273
+ function $b71c795eacf2ee6f$var$defaultResolver(options) {
274
+ const { params: params , document: document , useDraft: useDraft } = options;
275
+ // params is optional
276
+ if (!params) return {};
277
+ // legacy useDraft behaviour
278
+ const doc = useDraft ? document.displayed : document.published;
279
+ return Object.keys(params).reduce((acc, key)=>({
280
+ ...acc,
281
+ [key]: (0, ($parcel$interopDefault($k7rGe$dlv)))(doc, params[key])
282
+ }), {});
283
+ }
284
+ function $b71c795eacf2ee6f$export$2e2bcd8739ae039(options) {
285
+ const { params: params , document: document } = options;
286
+ const resolvedParams = typeof params == "function" ? params({
287
+ document: document
288
+ }) : $b71c795eacf2ee6f$var$defaultResolver(options);
289
+ // if any of the parameters are undefined, the query will error
290
+ // so return undefined so the UI can show a more appropriate message
291
+ if (Object.values(resolvedParams).includes(undefined)) return undefined;
292
+ // Typescript can't tell that we've guarded against any value being undefined,
293
+ // so forcing the type
294
+ return resolvedParams;
295
+ }
296
+
297
+
298
+ function $20e8f710b4927f0a$export$2e2bcd8739ae039(options) {
299
+ const { resolver: resolver , document: document } = options || {};
300
+ if (!resolver) return [];
301
+ return resolver({
302
+ document: document
303
+ });
304
+ }
305
+
306
+
307
+ function $39967e742aebc9bd$export$2e2bcd8739ae039(props) {
308
+ const { document: document , options: options } = props;
309
+ const { query: query , params: params , useDraft: useDraft = false , debug: debug = false , initialValueTemplates: initialValueTemplatesResolver , } = options;
310
+ if (useDraft && typeof params === "function") return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
311
+ padding: 4,
312
+ space: 5,
313
+ children: [
314
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
315
+ children: [
316
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)("code", {
317
+ children: "useDraft"
318
+ }),
319
+ " should not be ",
320
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)("code", {
321
+ children: "true"
322
+ }),
323
+ " when supplying a function for",
324
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)("code", {
325
+ children: "params"
326
+ })
327
+ ]
328
+ }),
329
+ debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
330
+ query: query
331
+ })
332
+ ]
333
+ });
334
+ const paramValues = (0, $b71c795eacf2ee6f$export$2e2bcd8739ae039)({
335
+ document: document,
336
+ params: params,
337
+ useDraft: useDraft
338
+ });
339
+ const initialValueTemplates = (0, $20e8f710b4927f0a$export$2e2bcd8739ae039)({
340
+ resolver: initialValueTemplatesResolver,
341
+ document: document
342
+ });
343
+ if (!paramValues) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
344
+ padding: 4,
345
+ space: 5,
346
+ children: [
347
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
348
+ children: "Parameters for this query could not be resolved. This may mean the document does not yet exist or is incomplete."
349
+ }),
350
+ debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
351
+ query: query
352
+ })
353
+ ]
354
+ });
355
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $69bfdff7425bcf41$export$2e2bcd8739ae039), {
356
+ query: query,
357
+ params: paramValues,
358
+ debug: debug,
359
+ initialValueTemplates: initialValueTemplates
360
+ });
361
+ }
362
+
363
+
364
+ var $244e63ca53592e4d$export$2e2bcd8739ae039 = (0, $39967e742aebc9bd$export$2e2bcd8739ae039);
365
+
366
+
367
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;ACAA;;;ACAA;;;;;;;ACAA;;;AAGe,kDAAe,SAAC,KAAK,CAAA,UAAE,MAAM,CAAA,EAAoD,EAAE;IAChG,qBACE;;0BACE,iCAAC,CAAA,GAAA,qBAAK,CAAA;gBAAC,KAAK,EAAE,CAAC;;kCACb,gCAAC,CAAA,GAAA,mBAAG,CAAA;kCACF,cAAA,gCAAC,CAAA,GAAA,qBAAK,CAAA;sCAAC,OAAK;0BAAQ;sBAChB;kCACN,gCAAC,CAAA,GAAA,mBAAG,CAAA;kCACF,cAAA,gCAAC,CAAA,GAAA,oBAAI,CAAA;sCAAE,KAAK;0BAAQ;sBAChB;;cACA;YACP,MAAM,k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A,GAAA,wCAAa,CAAA","sources":["src/index.ts","src/DocumentsPane.tsx","src/Documents.tsx","src/Debug.tsx","src/Feedback.tsx","src/hooks/useListeningQuery.ts","src/NewDocument.tsx","src/resolveParams.ts","src/resolveInitialValueTemplates.ts"],"sourcesContent":["import DocumentsPane from './DocumentsPane'\n\nexport default DocumentsPane\n","import React from 'react'\nimport {Stack} from '@sanity/ui'\n\nimport Documents from './Documents'\nimport Feedback from './Feedback'\nimport Debug from './Debug'\nimport {DocumentsPaneProps} from './types'\nimport resolveParams from './resolveParams'\nimport resolveInitialValueTemplates from './resolveInitialValueTemplates'\n\nexport default function DocumentsPane(props: DocumentsPaneProps) {\n const {document, options} = props\n const {\n query,\n params,\n useDraft = false,\n debug = false,\n initialValueTemplates: initialValueTemplatesResolver,\n } = options\n\n if (useDraft && typeof params === 'function') {\n return (\n <Stack padding={4} space={5}>\n <Feedback>\n <code>useDraft</code> should not be <code>true</code> when supplying a function for\n <code>params</code>\n </Feedback>\n {debug && <Debug query={query} />}\n </Stack>\n )\n }\n\n const paramValues = resolveParams({document, params, useDraft})\n\n const initialValueTemplates = resolveInitialValueTemplates({\n resolver: initialValueTemplatesResolver,\n document,\n })\n\n if (!paramValues) {\n return (\n <Stack padding={4} space={5}>\n <Feedback>\n Parameters for this query could not be resolved. This may mean the document does not yet\n exist or is incomplete.\n </Feedback>\n {debug && <Debug query={query} />}\n </Stack>\n )\n }\n\n return (\n <Documents\n query={query}\n params={paramValues}\n debug={debug}\n initialValueTemplates={initialValueTemplates}\n />\n )\n}\n","import React, {useCallback} from 'react'\nimport {Box, Button, Stack, Flex, Spinner} from '@sanity/ui'\nimport {fromString as pathFromString} from '@sanity/util/paths'\nimport {useSchema} from 'sanity'\nimport {usePaneRouter} from 'sanity/desk'\nimport {SanityPreview} from 'sanity/_unstable'\n\nimport Debug from './Debug'\nimport Feedback from './Feedback'\nimport useListeningQuery from './hooks/useListeningQuery'\nimport {DocumentsPaneInitialValueTemplate} from './types'\nimport NewDocument from './NewDocument'\n\ntype DocumentsProps = {\n query: string\n params: {[key: string]: string}\n debug: boolean\n initialValueTemplates: DocumentsPaneInitialValueTemplate[]\n}\n\nexport default function Documents(props: DocumentsProps) {\n const {query, params, debug, initialValueTemplates} = props\n const {routerPanesState, groupIndex, handleEditReference} = usePaneRouter()\n const schema = useSchema()\n\n const {loading, error, data} = useListeningQuery(query, params)\n\n const handleClick = useCallback(\n (id, type) => {\n const childParams = routerPanesState[groupIndex + 1]?.[0].params || {}\n const {parentRefPath} = childParams\n\n handleEditReference({\n id,\n type,\n // Uncertain that this works as intended\n parentRefPath: parentRefPath ? pathFromString(parentRefPath) : [``],\n // Added this to satisfy TS\n template: type,\n })\n },\n [routerPanesState, groupIndex, handleEditReference]\n )\n\n if (loading) {\n return (\n <Box padding={4}>\n <Flex justify=\"center\" align=\"center\">\n <Spinner muted />\n </Flex>\n </Box>\n )\n }\n\n if (error) {\n return (\n <Stack padding={4} space={5}>\n <Feedback>There was en error performing this query</Feedback>\n {debug && <Debug query={query} params={params} />}\n </Stack>\n )\n }\n\n if (!data?.length) {\n return (\n <>\n <NewDocument initialValueTemplates={initialValueTemplates} />\n <Stack padding={4} space={5}>\n <Feedback>No Documents found</Feedback>\n {debug && <Debug query={query} params={params} />}\n </Stack>\n </>\n )\n }\n\n return (\n <>\n <NewDocument initialValueTemplates={initialValueTemplates} />\n <Stack padding={2} space={1}>\n {data.map((doc) => {\n const schemaType = schema.get(doc._type)\n if (!schemaType) {\n return null\n }\n return (\n <Button\n key={doc._id}\n onClick={() => handleClick(doc._id, doc._type)}\n padding={2}\n mode=\"bleed\"\n >\n <SanityPreview value={doc} schemaType={schemaType} />\n </Button>\n )\n })}\n </Stack>\n </>\n )\n}\n","import React from 'react'\nimport {Code, Box, Label, Stack} from '@sanity/ui'\n\nexport default function Debug({query, params}: {query: string; params?: {[key: string]: string}}) {\n return (\n <>\n <Stack space={4}>\n <Box>\n <Label>Query</Label>\n </Box>\n <Box>\n <Code>{query}</Code>\n </Box>\n </Stack>\n {params && (\n <Stack space={4}>\n <Box>\n <Label>Params</Label>\n </Box>\n <Box>\n <Code>{JSON.stringify(params)}</Code>\n </Box>\n </Stack>\n )}\n </>\n )\n}\n","import React from 'react'\nimport {Card, Text} from '@sanity/ui'\nimport type {BadgeTone} from '@sanity/ui'\n\ntype FeedbackProps = {\n children?: React.ReactNode\n tone?: BadgeTone\n}\n\nexport default function Feedback(props: FeedbackProps) {\n const {children, tone = `caution`} = props\n\n return (\n <Card padding={3} radius={2} shadow={1} tone={tone}>\n <Text size={1}>{children}</Text>\n </Card>\n )\n}\n","import {useEffect, useState, useRef} from 'react'\nimport {catchError, distinctUntilChanged} from 'rxjs/operators'\nimport isEqual from 'react-fast-compare'\nimport type {SanityDocument} from 'sanity'\nimport {useDocumentStore} from 'sanity/_unstable'\n\ntype Params = Record<string, string | number | boolean | string[]>\n\ninterface ListenQueryOptions {\n tag?: string\n apiVersion?: string\n}\n\ntype ReturnShape = {\n loading: boolean\n error: boolean\n data: SanityDocument[] | null\n}\n\ntype Observable = {\n unsubscribe: () => void\n}\n\nconst DEFAULT_PARAMS = {}\nconst DEFAULT_OPTIONS = {apiVersion: `v2022-05-09`}\n\nexport default function useListeningQuery(\n query: string,\n params: Params = DEFAULT_PARAMS,\n options: ListenQueryOptions = DEFAULT_OPTIONS\n): ReturnShape {\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState(false)\n const [data, setData] = useState<SanityDocument[] | null>(null)\n const subscription = useRef<null | Observable>(null)\n const documentStore = useDocumentStore()\n\n useEffect(() => {\n if (query) {\n subscription.current = documentStore\n .listenQuery(query, params, options)\n .pipe(\n distinctUntilChanged(isEqual),\n catchError((err) => {\n console.error(err)\n setError(err)\n setLoading(false)\n setData(null)\n\n return err\n })\n )\n .subscribe((documents: SanityDocument[]) => {\n setData((current) => (isEqual(current, documents) ? current : documents))\n setLoading(false)\n setError(false)\n })\n }\n\n return () => {\n return subscription.current ? subscription.current.unsubscribe() : undefined\n }\n }, [query, params, options])\n\n return {loading, error, data}\n}\n","import {Button, Card, Flex} from '@sanity/ui'\nimport React from 'react'\nimport {DocumentsPaneInitialValueTemplate} from './types'\nimport {ComposeIcon} from '@sanity/icons'\nimport {usePaneRouter} from 'sanity/desk'\nimport {uuid} from '@sanity/uuid'\n\ninterface NewDocumentProps {\n initialValueTemplates: DocumentsPaneInitialValueTemplate[]\n}\n\nexport default function NewDocument(props: NewDocumentProps) {\n const {initialValueTemplates = []} = props\n const {ReferenceChildLink} = usePaneRouter()\n\n if (!initialValueTemplates.length) return null\n\n return (\n <Card borderBottom={true} padding={2}>\n <Flex justify=\"flex-end\" gap={1}>\n {initialValueTemplates.map((template) => {\n if (!template.template) {\n return null\n }\n return (\n <ReferenceChildLink\n documentId={uuid()}\n documentType={template.schemaType}\n template={{id: template.template, params: template.parameters}}\n parentRefPath={[]}\n key={`${template.schemaType}-${template.template}`}\n >\n <Button icon={<ComposeIcon />} text={template.title} mode=\"bleed\" as=\"span\" />\n </ReferenceChildLink>\n )\n })}\n </Flex>\n </Card>\n )\n}\n","import {DocumentsPaneQueryParams, DocumentVersionsCollection} from './types'\nimport delve from 'dlv'\n\ninterface ResolveParamsOptions {\n params?: DocumentsPaneQueryParams\n document: DocumentVersionsCollection\n useDraft: boolean\n}\n\ntype ResolveParamsReturn = undefined | {[key: string]: string}\n\nfunction defaultResolver(options: ResolveParamsOptions): {\n [key: string]: string | undefined\n} {\n const {params, document, useDraft} = options\n\n // params is optional\n if (!params) return {}\n\n // legacy useDraft behaviour\n const doc = useDraft ? document.displayed : document.published\n\n return Object.keys(params).reduce(\n (acc, key) => ({\n ...acc,\n [key]: delve(doc, params[key as keyof DocumentsPaneQueryParams]),\n }),\n {}\n )\n}\n\nexport default function resolveParams(options: ResolveParamsOptions): ResolveParamsReturn {\n const {params, document} = options\n\n const resolvedParams = typeof params == 'function' ? params({document}) : defaultResolver(options)\n\n // if any of the parameters are undefined, the query will error\n // so return undefined so the UI can show a more appropriate message\n if (Object.values(resolvedParams).includes(undefined)) return undefined\n\n // Typescript can't tell that we've guarded against any value being undefined,\n // so forcing the type\n return resolvedParams as {[key: string]: string}\n}\n","import {\n DocumentsPaneInitialValueTemplate,\n DocumentsPaneInitialValueTemplateResolver,\n DocumentVersionsCollection,\n} from './types'\n\ninterface ResolveInitialValueTemplatesOptions {\n resolver: DocumentsPaneInitialValueTemplateResolver | undefined\n document: DocumentVersionsCollection\n}\n\nexport default function resolveInitialValueTemplates(\n options: ResolveInitialValueTemplatesOptions\n): DocumentsPaneInitialValueTemplate[] {\n const {resolver, document} = options || {}\n\n if (!resolver) return []\n\n return resolver({document})\n}\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../"}