sanity-plugin-documents-pane 1.1.0 → 2.0.0-v3-studio.2
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 +18 -7
- package/lib/cjs/index.js +365 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/esm/index.js +353 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/types/index.d.ts +40 -0
- package/lib/types/index.d.ts.map +1 -0
- package/package.json +54 -19
- package/sanity.json +7 -6
- package/src/Documents.tsx +19 -13
- package/src/NewDocument.tsx +5 -3
- package/src/hooks/useListeningQuery.ts +6 -5
- package/src/parts.d.ts +2 -0
- package/src/resolveParams.ts +10 -2
- package/v2-incompatible.js +10 -0
- package/lib/Debug.js +0 -23
- package/lib/Debug.js.map +0 -1
- package/lib/Documents.js +0 -113
- package/lib/Documents.js.map +0 -1
- package/lib/DocumentsPane.js +0 -70
- package/lib/DocumentsPane.js.map +0 -1
- package/lib/Feedback.js +0 -27
- package/lib/Feedback.js.map +0 -1
- package/lib/NewDocument.js +0 -55
- package/lib/NewDocument.js.map +0 -1
- package/lib/hooks/useListeningQuery.js +0 -80
- package/lib/hooks/useListeningQuery.js.map +0 -1
- package/lib/index.js +0 -14
- package/lib/index.js.map +0 -1
- package/lib/resolveInitialValueTemplates.js +0 -18
- package/lib/resolveInitialValueTemplates.js.map +0 -1
- package/lib/resolveParams.js +0 -44
- package/lib/resolveParams.js.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
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
|

|
|
6
10
|
|
|
7
11
|
## Installation
|
|
8
12
|
|
|
13
|
+
```sh
|
|
14
|
+
npm install --save sanity-plugin-documents-pane@studio-v3
|
|
9
15
|
```
|
|
10
|
-
|
|
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).
|
|
@@ -32,16 +42,17 @@ S.view
|
|
|
32
42
|
The `.options()` configuration works as follows:
|
|
33
43
|
|
|
34
44
|
- `query` (string, required) A string defining the entire GROQ query that will select documents to list.
|
|
35
|
-
- `params` (object or function, optional)
|
|
45
|
+
- `params` (object or function, optional)
|
|
36
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.
|
|
37
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.
|
|
38
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.
|
|
40
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.
|
|
41
51
|
|
|
42
|
-
|
|
43
52
|
## Resolving query parameters with a function and providing initial value templates
|
|
53
|
+
|
|
44
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
|
+
|
|
45
56
|
```js
|
|
46
57
|
const options = {
|
|
47
58
|
query: `*[_type=="post" && author._ref == $id]`,
|
|
@@ -49,14 +60,14 @@ const options = {
|
|
|
49
60
|
// references will never point to a draft ID, so extract the regular ID
|
|
50
61
|
const id = document.displayed._id?.replace('drafts.', '')
|
|
51
62
|
|
|
52
|
-
// we don't have to worry about undefined parameters,
|
|
63
|
+
// we don't have to worry about undefined parameters,
|
|
53
64
|
// as the plugin will handle them and show an appropriate message
|
|
54
65
|
return {id}
|
|
55
66
|
},
|
|
56
67
|
initialValueTemplates: ({document}) => {
|
|
57
68
|
const templates = []
|
|
58
69
|
|
|
59
|
-
// references must point to a non-draft ID, so if using the ID in the template,
|
|
70
|
+
// references must point to a non-draft ID, so if using the ID in the template,
|
|
60
71
|
// be sure it doesn't start with `drafts.`
|
|
61
72
|
const id = document?.displayed?._id.replace('drafts.', '')
|
|
62
73
|
const name = document?.displayed?.name || 'author'
|
|
@@ -90,5 +101,5 @@ This plugin is based on [Incoming References](https://github.com/sanity-io/sanit
|
|
|
90
101
|
|
|
91
102
|
## License
|
|
92
103
|
|
|
93
|
-
MIT ©
|
|
94
|
-
See LICENSE
|
|
104
|
+
MIT © Sanity.io
|
|
105
|
+
See [LICENSE](license)
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
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$rxjsoperators = require("rxjs/operators");
|
|
8
|
+
var $k7rGe$reactfastcompare = require("react-fast-compare");
|
|
9
|
+
var $k7rGe$sanityicons = require("@sanity/icons");
|
|
10
|
+
var $k7rGe$sanityuuid = require("@sanity/uuid");
|
|
11
|
+
var $k7rGe$dlv = require("dlv");
|
|
12
|
+
|
|
13
|
+
function $parcel$defineInteropFlag(a) {
|
|
14
|
+
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
15
|
+
}
|
|
16
|
+
function $parcel$export(e, n, v, s) {
|
|
17
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
18
|
+
}
|
|
19
|
+
function $parcel$interopDefault(a) {
|
|
20
|
+
return a && a.__esModule ? a.default : a;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
$parcel$defineInteropFlag(module.exports);
|
|
24
|
+
|
|
25
|
+
$parcel$export(module.exports, "default", () => $244e63ca53592e4d$export$2e2bcd8739ae039);
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function $8bf99469d8dcf610$export$2e2bcd8739ae039({ query: query , params: params }) {
|
|
39
|
+
return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$reactjsxruntime.Fragment), {
|
|
40
|
+
children: [
|
|
41
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
|
|
42
|
+
space: 4,
|
|
43
|
+
children: [
|
|
44
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
|
|
45
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Label), {
|
|
46
|
+
children: "Query"
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
|
|
50
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Code), {
|
|
51
|
+
children: query
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
}),
|
|
56
|
+
params && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
|
|
57
|
+
space: 4,
|
|
58
|
+
children: [
|
|
59
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
|
|
60
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Label), {
|
|
61
|
+
children: "Params"
|
|
62
|
+
})
|
|
63
|
+
}),
|
|
64
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
|
|
65
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Code), {
|
|
66
|
+
children: JSON.stringify(params)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
]
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
function $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039(props) {
|
|
80
|
+
const { children: children , tone: tone = `caution` } = props;
|
|
81
|
+
return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Card), {
|
|
82
|
+
padding: 3,
|
|
83
|
+
radius: 2,
|
|
84
|
+
shadow: 1,
|
|
85
|
+
tone: tone,
|
|
86
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Text), {
|
|
87
|
+
size: 1,
|
|
88
|
+
children: children
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const $18acc44f6f71937f$var$DEFAULT_PARAMS = {};
|
|
99
|
+
const $18acc44f6f71937f$var$DEFAULT_OPTIONS = {
|
|
100
|
+
apiVersion: `v2022-05-09`
|
|
101
|
+
};
|
|
102
|
+
function $18acc44f6f71937f$export$2e2bcd8739ae039(query, params = $18acc44f6f71937f$var$DEFAULT_PARAMS, options = $18acc44f6f71937f$var$DEFAULT_OPTIONS) {
|
|
103
|
+
const [loading, setLoading] = (0, $k7rGe$react.useState)(true);
|
|
104
|
+
const [error, setError] = (0, $k7rGe$react.useState)(false);
|
|
105
|
+
const [data, setData] = (0, $k7rGe$react.useState)(null);
|
|
106
|
+
const subscription = (0, $k7rGe$react.useRef)(null);
|
|
107
|
+
const documentStore = (0, $k7rGe$sanity.useDocumentStore)();
|
|
108
|
+
(0, $k7rGe$react.useEffect)(()=>{
|
|
109
|
+
if (query) subscription.current = documentStore.listenQuery(query, params, options).pipe((0, $k7rGe$rxjsoperators.distinctUntilChanged)((0, ($parcel$interopDefault($k7rGe$reactfastcompare)))), (0, $k7rGe$rxjsoperators.catchError)((err)=>{
|
|
110
|
+
console.error(err);
|
|
111
|
+
setError(err);
|
|
112
|
+
setLoading(false);
|
|
113
|
+
setData(null);
|
|
114
|
+
return err;
|
|
115
|
+
})).subscribe((documents)=>{
|
|
116
|
+
setData((current)=>(0, ($parcel$interopDefault($k7rGe$reactfastcompare)))(current, documents) ? current : documents);
|
|
117
|
+
setLoading(false);
|
|
118
|
+
setError(false);
|
|
119
|
+
});
|
|
120
|
+
return ()=>{
|
|
121
|
+
return subscription.current ? subscription.current.unsubscribe() : undefined;
|
|
122
|
+
};
|
|
123
|
+
}, [
|
|
124
|
+
query,
|
|
125
|
+
params,
|
|
126
|
+
options
|
|
127
|
+
]);
|
|
128
|
+
return {
|
|
129
|
+
loading: loading,
|
|
130
|
+
error: error,
|
|
131
|
+
data: data
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
function $84571eed53af196d$export$2e2bcd8739ae039(props) {
|
|
143
|
+
const { initialValueTemplates: initialValueTemplates = [] } = props;
|
|
144
|
+
const { ReferenceChildLink: ReferenceChildLink } = (0, $k7rGe$sanitydesk.usePaneRouter)();
|
|
145
|
+
if (!initialValueTemplates.length) return null;
|
|
146
|
+
return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Card), {
|
|
147
|
+
borderBottom: true,
|
|
148
|
+
padding: 2,
|
|
149
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Flex), {
|
|
150
|
+
justify: "flex-end",
|
|
151
|
+
gap: 1,
|
|
152
|
+
children: initialValueTemplates.map((template)=>{
|
|
153
|
+
if (!template.template) return null;
|
|
154
|
+
return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)(ReferenceChildLink, {
|
|
155
|
+
documentId: (0, $k7rGe$sanityuuid.uuid)(),
|
|
156
|
+
documentType: template.schemaType,
|
|
157
|
+
template: {
|
|
158
|
+
id: template.template,
|
|
159
|
+
params: template.parameters
|
|
160
|
+
},
|
|
161
|
+
parentRefPath: [],
|
|
162
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Button), {
|
|
163
|
+
icon: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityicons.ComposeIcon), {}),
|
|
164
|
+
text: template.title,
|
|
165
|
+
mode: "bleed",
|
|
166
|
+
as: "span"
|
|
167
|
+
})
|
|
168
|
+
}, `${template.schemaType}-${template.template}`);
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
function $69bfdff7425bcf41$export$2e2bcd8739ae039(props) {
|
|
176
|
+
const { query: query , params: params , debug: debug , initialValueTemplates: initialValueTemplates } = props;
|
|
177
|
+
const { routerPanesState: routerPanesState , groupIndex: groupIndex , handleEditReference: handleEditReference } = (0, $k7rGe$sanitydesk.usePaneRouter)();
|
|
178
|
+
const schema = (0, $k7rGe$sanity.useSchema)();
|
|
179
|
+
const { loading: loading , error: error , data: data } = (0, $18acc44f6f71937f$export$2e2bcd8739ae039)(query, params);
|
|
180
|
+
const handleClick = (0, $k7rGe$react.useCallback)((id, type)=>{
|
|
181
|
+
const childParams = routerPanesState[groupIndex + 1]?.[0].params || {};
|
|
182
|
+
const { parentRefPath: parentRefPath } = childParams;
|
|
183
|
+
handleEditReference({
|
|
184
|
+
id: id,
|
|
185
|
+
type: type,
|
|
186
|
+
// Uncertain that this works as intended
|
|
187
|
+
parentRefPath: parentRefPath ? (0, $k7rGe$sanityutilpaths.fromString)(parentRefPath) : [
|
|
188
|
+
``
|
|
189
|
+
],
|
|
190
|
+
// Added this to satisfy TS
|
|
191
|
+
template: type
|
|
192
|
+
});
|
|
193
|
+
}, [
|
|
194
|
+
routerPanesState,
|
|
195
|
+
groupIndex,
|
|
196
|
+
handleEditReference
|
|
197
|
+
]);
|
|
198
|
+
if (loading) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
|
|
199
|
+
padding: 4,
|
|
200
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Flex), {
|
|
201
|
+
justify: "center",
|
|
202
|
+
align: "center",
|
|
203
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Spinner), {
|
|
204
|
+
muted: true
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
});
|
|
208
|
+
if (error) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
|
|
209
|
+
padding: 4,
|
|
210
|
+
space: 5,
|
|
211
|
+
children: [
|
|
212
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
|
|
213
|
+
children: "There was en error performing this query"
|
|
214
|
+
}),
|
|
215
|
+
debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
|
|
216
|
+
query: query,
|
|
217
|
+
params: params
|
|
218
|
+
})
|
|
219
|
+
]
|
|
220
|
+
});
|
|
221
|
+
if (!data?.length) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$reactjsxruntime.Fragment), {
|
|
222
|
+
children: [
|
|
223
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $84571eed53af196d$export$2e2bcd8739ae039), {
|
|
224
|
+
initialValueTemplates: initialValueTemplates
|
|
225
|
+
}),
|
|
226
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
|
|
227
|
+
padding: 4,
|
|
228
|
+
space: 5,
|
|
229
|
+
children: [
|
|
230
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
|
|
231
|
+
children: "No Documents found"
|
|
232
|
+
}),
|
|
233
|
+
debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
|
|
234
|
+
query: query,
|
|
235
|
+
params: params
|
|
236
|
+
})
|
|
237
|
+
]
|
|
238
|
+
})
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$reactjsxruntime.Fragment), {
|
|
242
|
+
children: [
|
|
243
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $84571eed53af196d$export$2e2bcd8739ae039), {
|
|
244
|
+
initialValueTemplates: initialValueTemplates
|
|
245
|
+
}),
|
|
246
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Stack), {
|
|
247
|
+
padding: 2,
|
|
248
|
+
space: 1,
|
|
249
|
+
children: data.map((doc)=>{
|
|
250
|
+
const schemaType = schema.get(doc._type);
|
|
251
|
+
if (!schemaType) return null;
|
|
252
|
+
return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Button), {
|
|
253
|
+
onClick: ()=>handleClick(doc._id, doc._type),
|
|
254
|
+
padding: 2,
|
|
255
|
+
mode: "bleed",
|
|
256
|
+
children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanity.SanityPreview), {
|
|
257
|
+
value: doc,
|
|
258
|
+
schemaType: schemaType
|
|
259
|
+
})
|
|
260
|
+
}, doc._id);
|
|
261
|
+
})
|
|
262
|
+
})
|
|
263
|
+
]
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
function $b71c795eacf2ee6f$var$defaultResolver(options) {
|
|
272
|
+
const { params: params , document: document , useDraft: useDraft } = options;
|
|
273
|
+
// params is optional
|
|
274
|
+
if (!params) return {};
|
|
275
|
+
// legacy useDraft behaviour
|
|
276
|
+
const doc = useDraft ? document.displayed : document.published;
|
|
277
|
+
return Object.keys(params).reduce((acc, key)=>({
|
|
278
|
+
...acc,
|
|
279
|
+
[key]: (0, ($parcel$interopDefault($k7rGe$dlv)))(doc, params[key])
|
|
280
|
+
}), {});
|
|
281
|
+
}
|
|
282
|
+
function $b71c795eacf2ee6f$export$2e2bcd8739ae039(options) {
|
|
283
|
+
const { params: params , document: document } = options;
|
|
284
|
+
const resolvedParams = typeof params == "function" ? params({
|
|
285
|
+
document: document
|
|
286
|
+
}) : $b71c795eacf2ee6f$var$defaultResolver(options);
|
|
287
|
+
// if any of the parameters are undefined, the query will error
|
|
288
|
+
// so return undefined so the UI can show a more appropriate message
|
|
289
|
+
if (Object.values(resolvedParams).includes(undefined)) return undefined;
|
|
290
|
+
// Typescript can't tell that we've guarded against any value being undefined,
|
|
291
|
+
// so forcing the type
|
|
292
|
+
return resolvedParams;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
function $20e8f710b4927f0a$export$2e2bcd8739ae039(options) {
|
|
297
|
+
const { resolver: resolver , document: document } = options || {};
|
|
298
|
+
if (!resolver) return [];
|
|
299
|
+
return resolver({
|
|
300
|
+
document: document
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
function $39967e742aebc9bd$export$2e2bcd8739ae039(props) {
|
|
306
|
+
const { document: document , options: options } = props;
|
|
307
|
+
const { query: query , params: params , useDraft: useDraft = false , debug: debug = false , initialValueTemplates: initialValueTemplatesResolver , } = options;
|
|
308
|
+
if (useDraft && typeof params === "function") return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
|
|
309
|
+
padding: 4,
|
|
310
|
+
space: 5,
|
|
311
|
+
children: [
|
|
312
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
|
|
313
|
+
children: [
|
|
314
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)("code", {
|
|
315
|
+
children: "useDraft"
|
|
316
|
+
}),
|
|
317
|
+
" should not be ",
|
|
318
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)("code", {
|
|
319
|
+
children: "true"
|
|
320
|
+
}),
|
|
321
|
+
" when supplying a function for",
|
|
322
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)("code", {
|
|
323
|
+
children: "params"
|
|
324
|
+
})
|
|
325
|
+
]
|
|
326
|
+
}),
|
|
327
|
+
debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
|
|
328
|
+
query: query
|
|
329
|
+
})
|
|
330
|
+
]
|
|
331
|
+
});
|
|
332
|
+
const paramValues = (0, $b71c795eacf2ee6f$export$2e2bcd8739ae039)({
|
|
333
|
+
document: document,
|
|
334
|
+
params: params,
|
|
335
|
+
useDraft: useDraft
|
|
336
|
+
});
|
|
337
|
+
const initialValueTemplates = (0, $20e8f710b4927f0a$export$2e2bcd8739ae039)({
|
|
338
|
+
resolver: initialValueTemplatesResolver,
|
|
339
|
+
document: document
|
|
340
|
+
});
|
|
341
|
+
if (!paramValues) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
|
|
342
|
+
padding: 4,
|
|
343
|
+
space: 5,
|
|
344
|
+
children: [
|
|
345
|
+
/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8f6d54ef8e8d6bcf$export$2e2bcd8739ae039), {
|
|
346
|
+
children: "Parameters for this query could not be resolved. This may mean the document does not yet exist or is incomplete."
|
|
347
|
+
}),
|
|
348
|
+
debug && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $8bf99469d8dcf610$export$2e2bcd8739ae039), {
|
|
349
|
+
query: query
|
|
350
|
+
})
|
|
351
|
+
]
|
|
352
|
+
});
|
|
353
|
+
return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $69bfdff7425bcf41$export$2e2bcd8739ae039), {
|
|
354
|
+
query: query,
|
|
355
|
+
params: paramValues,
|
|
356
|
+
debug: debug,
|
|
357
|
+
initialValueTemplates: initialValueTemplates
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
var $244e63ca53592e4d$export$2e2bcd8739ae039 = (0, $39967e742aebc9bd$export$2e2bcd8739ae039);
|
|
363
|
+
|
|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AAC;QACzD,QAAQ,EAAE,6BAA6B;kBACvC,QAAQ;KACT,CAAC;IAEF,IAAI,CAAC,WAAW,EACd,qBACE,iCAAC,CAAA,GAAA,qBAAK,CAAA;QAAC,OAAO,EAAE,CAAC;QAAE,KAAK,EAAE,CAAC;;0BACzB,gCAAC,CAAA,GAAA,wCAAQ,CAAA;0BAAC,kHAGV;cAAW;YACV,KAAK,kBAAI,gCAAC,CAAA,GAAA,wCAAK,CAAA;gBAAC,KAAK,EAAE,KAAK;cAAI;;MAC3B,CACT;IAGH,qBACE,gCAAC,CAAA,GAAA,wCAAS,CAAA;QACR,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,WAAW;QACnB,KAAK,EAAE,KAAK;QACZ,qBAAqB,EAAE,qBAAqB;MAC5C,CACH;CACF;;AD3DD;IAEA,wCAA4B,GAAb,CAAA,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 {SanityPreview, useSchema} from 'sanity'\nimport {usePaneRouter} from 'sanity/desk'\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 {SanityDocument, useDocumentStore} from 'sanity'\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":"../../"}
|