sanity-plugin-documents-pane 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/Debug.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Debug.tsx"],"names":["Debug","query","params","JSON","stringify"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEe,SAASA,KAAT,OAAgC;AAAA,MAAhBC,KAAgB,QAAhBA,KAAgB;AAAA,MAATC,MAAS,QAATA,MAAS;AAC7C,sBACE,yEACE,6BAAC,SAAD;AAAO,IAAA,KAAK,EAAE;AAAd,kBACE,6BAAC,OAAD,qBAAK,6BAAC,SAAD,gBAAL,CADF,eAEE,6BAAC,OAAD,qBACE,6BAAC,QAAD,QAAOD,KAAP,CADF,CAFF,CADF,eAOE,6BAAC,SAAD;AAAO,IAAA,KAAK,EAAE;AAAd,kBACE,6BAAC,OAAD,qBAAK,6BAAC,SAAD,iBAAL,CADF,eAEE,6BAAC,OAAD,qBACE,6BAAC,QAAD,QAAOE,IAAI,CAACC,SAAL,CAAeF,MAAf,CAAP,CADF,CAFF,CAPF,CADF;AAgBD","sourcesContent":["import React from 'react'\nimport {Code, Box, Label, Stack} from '@sanity/ui'\n\nexport default function Debug({query, params}) {\n return (\n <>\n <Stack space={4}>\n <Box><Label>Query</Label></Box>\n <Box>\n <Code>{query}</Code>\n </Box>\n </Stack>\n <Stack space={4}>\n <Box><Label>Params</Label></Box>\n <Box>\n <Code>{JSON.stringify(params)}</Code>\n </Box>\n </Stack>\n </>\n )\n}\n"],"file":"Debug.js"}
1
+ {"version":3,"file":"Debug.js","names":["Debug","query","params","JSON","stringify"],"sources":["../src/Debug.tsx"],"sourcesContent":["import React from 'react'\nimport {Code, Box, Label, Stack} from '@sanity/ui'\n\nexport default function Debug({query, params}) {\n return (\n <>\n <Stack space={4}>\n <Box><Label>Query</Label></Box>\n <Box>\n <Code>{query}</Code>\n </Box>\n </Stack>\n <Stack space={4}>\n <Box><Label>Params</Label></Box>\n <Box>\n <Code>{JSON.stringify(params)}</Code>\n </Box>\n </Stack>\n </>\n )\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEe,SAASA,KAAT,OAAgC;EAAA,IAAhBC,KAAgB,QAAhBA,KAAgB;EAAA,IAATC,MAAS,QAATA,MAAS;EAC7C,oBACE,yEACE,6BAAC,SAAD;IAAO,KAAK,EAAE;EAAd,gBACE,6BAAC,OAAD,qBAAK,6BAAC,SAAD,gBAAL,CADF,eAEE,6BAAC,OAAD,qBACE,6BAAC,QAAD,QAAOD,KAAP,CADF,CAFF,CADF,eAOE,6BAAC,SAAD;IAAO,KAAK,EAAE;EAAd,gBACE,6BAAC,OAAD,qBAAK,6BAAC,SAAD,iBAAL,CADF,eAEE,6BAAC,OAAD,qBACE,6BAAC,QAAD,QAAOE,IAAI,CAACC,SAAL,CAAeF,MAAf,CAAP,CADF,CAFF,CAPF,CADF;AAgBD"}
package/lib/Documents.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = Documents;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _reactQuery = require("react-query");
11
11
 
@@ -13,7 +13,7 @@ var _ui = require("@sanity/ui");
13
13
 
14
14
  var _deskTool = require("@sanity/desk-tool");
15
15
 
16
- var _RouterContext = require("@sanity/state-router/lib/RouterContext");
16
+ var _paths = require("@sanity/util/paths");
17
17
 
18
18
  var _preview = _interopRequireDefault(require("part:@sanity/base/preview"));
19
19
 
@@ -27,15 +27,21 @@ var _Feedback = _interopRequireDefault(require("./Feedback"));
27
27
 
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
29
 
30
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
+
32
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
+
34
+ // import {RouterContext} from '@sanity/state-router/lib/RouterContext'
30
35
  var client = _client.default.withConfig({
31
36
  apiVersion: "2021-05-19"
32
37
  });
33
38
 
34
39
  function Documents(props) {
40
+ var _routerPanesState;
41
+
35
42
  var query = props.query,
36
43
  params = props.params,
37
- debug = props.debug,
38
- _rev = props._rev;
44
+ debug = props.debug;
39
45
 
40
46
  var _useQuery = (0, _reactQuery.useQuery)(['useDocuments', {
41
47
  props
@@ -44,35 +50,23 @@ function Documents(props) {
44
50
  error = _useQuery.error,
45
51
  data = _useQuery.data;
46
52
 
47
- var routerContext = _react.default.useContext(_RouterContext.RouterContext);
48
-
49
53
  var _usePaneRouter = (0, _deskTool.usePaneRouter)(),
50
54
  routerPanesState = _usePaneRouter.routerPanesState,
51
- groupIndex = _usePaneRouter.groupIndex;
52
-
53
- var openDocumentInSidePane = _react.default.useCallback((id, type) => {
54
- var newPane = [{
55
- id: id,
56
- params: {
57
- type
58
- }
59
- }];
60
- var panes = [routerPanesState[0], routerPanesState[1], newPane];
61
- var href = routerContext.resolvePathFromState({
62
- panes
55
+ groupIndex = _usePaneRouter.groupIndex,
56
+ handleEditReference = _usePaneRouter.handleEditReference;
57
+
58
+ var childParams = ((_routerPanesState = routerPanesState[groupIndex + 1]) === null || _routerPanesState === void 0 ? void 0 : _routerPanesState[0].params) || {};
59
+ var parentRefPath = childParams.parentRefPath;
60
+ var handleClick = (0, _react.useCallback)((id, type) => {
61
+ handleEditReference({
62
+ id,
63
+ type,
64
+ // Uncertain that this works as intended
65
+ parentRefPath: parentRefPath ? (0, _paths.fromString)(parentRefPath) : [""],
66
+ // Added this to satisfy TS
67
+ template: type
63
68
  });
64
- routerContext.navigateUrl(href);
65
- }, [routerContext, routerPanesState, groupIndex]);
66
-
67
- if (!_rev) {
68
- return /*#__PURE__*/_react.default.createElement(_ui.Stack, {
69
- padding: 4,
70
- space: 5
71
- }, /*#__PURE__*/_react.default.createElement(_Feedback.default, null, "Document must be Published"), debug && /*#__PURE__*/_react.default.createElement(_Debug.default, {
72
- query: query,
73
- params: params
74
- }));
75
- }
69
+ }, [routerPanesState]);
76
70
 
77
71
  if (isLoading) {
78
72
  return /*#__PURE__*/_react.default.createElement(_ui.Box, {
@@ -107,13 +101,11 @@ function Documents(props) {
107
101
 
108
102
  return /*#__PURE__*/_react.default.createElement(_ui.Stack, {
109
103
  padding: 2,
110
- space: 2
104
+ space: 1
111
105
  }, data.map(doc => /*#__PURE__*/_react.default.createElement(_ui.Button, {
112
- key: doc._id,
113
- onClick: () => openDocumentInSidePane(doc._id, doc._type),
114
- mode: "bleed",
115
- radius: 2,
116
- padding: 2
106
+ onClick: () => handleClick(doc._id, doc._type),
107
+ padding: 2,
108
+ mode: "bleed"
117
109
  }, /*#__PURE__*/_react.default.createElement(_preview.default, {
118
110
  value: doc,
119
111
  type: _schema.default.get(doc._type)
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Documents.tsx"],"names":["client","sanityClient","withConfig","apiVersion","Documents","props","query","params","debug","_rev","fetch","isLoading","error","data","routerContext","React","useContext","RouterContext","routerPanesState","groupIndex","openDocumentInSidePane","useCallback","id","type","newPane","panes","href","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AMD;;AAED,sBACE,6BAAC,SAAD;AAAO,IAAA,OAAO,EAAE,CAAhB;AAAmB,IAAA,KAAK,EAAE;AAA1B,KACGM,IAAI,CAACiB,GAAL,CAAUC,GAAD,iBACR,6BAAC,UAAD;AACE,IAAA,GAAG,EAAEA,GAAG,CAACC,GADX;AAEE,IAAA,OAAO,EAAE,MAAMZ,sBAAsB,CAACW,GAAG,CAACC,GAAL,EAAUD,GAAG,CAACE,KAAd,CAFvC;AAGE,IAAA,IAAI,EAAC,OAHP;AAIE,IAAA,MAAM,EAAE,CAJV;AAKE,IAAA,OAAO,EAAE;AALX,kBAOE,6BAAC,gBAAD;AAAS,IAAA,KAAK,EAAEF,GAAhB;AAAqB,IAAA,IAAI,EAAEG,gBAAOC,GAAP,CAAWJ,GAAG,CAACE,KAAf;AAA3B,IAPF,CADD,CADH,CADF;AAeD","sourcesContent":["import React from 'react'\nimport {useQuery} from 'react-query'\nimport {Button, Box, Stack, Flex, Spinner} from '@sanity/ui'\nimport {usePaneRouter} from '@sanity/desk-tool'\nimport {RouterContext} from '@sanity/state-router/lib/RouterContext'\nimport Preview from 'part:@sanity/base/preview'\nimport schema from 'part:@sanity/base/schema'\nimport sanityClient from 'part:@sanity/base/client'\n\nimport Debug from './Debug'\nimport Feedback from './Feedback'\n\n const client = sanityClient.withConfig({apiVersion: `2021-05-19`})\n\nexport default function Documents(props) {\n const {query, params, debug, _rev} = props\n\n const {isLoading, error, data} = useQuery(['useDocuments', {props}], () =>\n client.fetch(query, params)\n )\n\n const routerContext = React.useContext(RouterContext)\n const {routerPanesState, groupIndex} = usePaneRouter()\n\n const openDocumentInSidePane = React.useCallback(\n (id: string, type: string) => {\n const newPane = [\n {\n id: id,\n params: {type},\n },\n ]\n let panes = [routerPanesState[0], routerPanesState[1], newPane]\n\n const href = routerContext.resolvePathFromState({panes})\n routerContext.navigateUrl(href)\n },\n [routerContext, routerPanesState, groupIndex]\n )\n\n if (!_rev) {\n return (\n <Stack padding={4} space={5}>\n <Feedback>Document must be Published</Feedback>\n {debug && <Debug query={query} params={params} />}\n </Stack>\n )\n }\n\n if (isLoading) {\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 <Stack padding={4} space={5}>\n <Feedback>No Documents found</Feedback>\n {debug && <Debug query={query} params={params} />}\n </Stack>\n )\n }\n\n return (\n <Stack padding={2} space={2}>\n {data.map((doc) => (\n <Button\n key={doc._id}\n onClick={() => openDocumentInSidePane(doc._id, doc._type)}\n mode=\"bleed\"\n radius={2}\n padding={2}\n >\n <Preview value={doc} type={schema.get(doc._type)} />\n </Button>\n ))}\n </Stack>\n )\n}\n"],"file":"Documents.js"}
1
+ {"version":3,"file":"Documents.js","names":["client","sanityClient","withConfig","apiVersion","Documents","props","query","params","debug","fetch","isLoading","error","data","routerPanesState","groupIndex","handleEditReference","childParams","parentRefPath","handleClick","id","type","template","length","map","doc","_id","_type","schema","get"],"sources":["../src/Documents.tsx"],"sourcesContent":["import React, {useCallback} from 'react'\nimport {useQuery} from 'react-query'\nimport {Box, Button, Stack, Flex, Spinner} from '@sanity/ui'\nimport {usePaneRouter} from '@sanity/desk-tool'\nimport {fromString as pathFromString} from '@sanity/util/paths'\n// import {RouterContext} from '@sanity/state-router/lib/RouterContext'\nimport Preview from 'part:@sanity/base/preview'\nimport schema from 'part:@sanity/base/schema'\nimport sanityClient from 'part:@sanity/base/client'\n\nimport Debug from './Debug'\nimport Feedback from './Feedback'\n\nconst client = sanityClient.withConfig({apiVersion: `2021-05-19`})\n\nexport default function Documents(props) {\n const {query, params, debug} = props\n\n const {isLoading, error, data} = useQuery(['useDocuments', {props}], () =>\n client.fetch(query, params)\n )\n\n const {routerPanesState, groupIndex, handleEditReference} = usePaneRouter()\n const childParams = routerPanesState[groupIndex + 1]?.[0].params || {}\n const {parentRefPath} = childParams\n\n const handleClick = useCallback((id, type) => {\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 }, [routerPanesState])\n\n if (isLoading) {\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 <Stack padding={4} space={5}>\n <Feedback>No Documents found</Feedback>\n {debug && <Debug query={query} params={params} />}\n </Stack>\n )\n }\n\n return (\n <Stack padding={2} space={1}>\n {data.map((doc) => (\n <Button onClick={() => handleClick(doc._id, doc._type)} padding={2} mode=\"bleed\">\n <Preview value={doc} type={schema.get(doc._type)} />\n </Button>\n ))}\n </Stack>\n )\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;AANA;AAQA,IAAMA,MAAM,GAAGC,gBAAaC,UAAb,CAAwB;EAACC,UAAU;AAAX,CAAxB,CAAf;;AAEe,SAASC,SAAT,CAAmBC,KAAnB,EAA0B;EAAA;;EACvC,IAAOC,KAAP,GAA+BD,KAA/B,CAAOC,KAAP;EAAA,IAAcC,MAAd,GAA+BF,KAA/B,CAAcE,MAAd;EAAA,IAAsBC,KAAtB,GAA+BH,KAA/B,CAAsBG,KAAtB;;EAEA,gBAAiC,0BAAS,CAAC,cAAD,EAAiB;IAACH;EAAD,CAAjB,CAAT,EAAoC,MACnEL,MAAM,CAACS,KAAP,CAAaH,KAAb,EAAoBC,MAApB,CAD+B,CAAjC;EAAA,IAAOG,SAAP,aAAOA,SAAP;EAAA,IAAkBC,KAAlB,aAAkBA,KAAlB;EAAA,IAAy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AK,iBAAI,6BAAC,cAAD;MAAO,KAAK,EAAEF,KAAd;MAAqB,MAAM,EAAEC;IAA7B,EAFZ,CADF;EAMD;;EAED,oBACE,6BAAC,SAAD;IAAO,OAAO,EAAE,CAAhB;IAAmB,KAAK,EAAE;EAA1B,GACGK,IAAI,CAACW,GAAL,CAAUC,GAAD,iBACR,6BAAC,UAAD;IAAQ,OAAO,EAAE,MAAMN,WAAW,CAACM,GAAG,CAACC,GAAL,EAAUD,GAAG,CAACE,KAAd,CAAlC;IAAwD,OAAO,EAAE,CAAjE;IAAoE,IAAI,EAAC;EAAzE,gBACE,6BAAC,gBAAD;IAAS,KAAK,EAAEF,GAAhB;IAAqB,IAAI,EAAEG,gBAAOC,GAAP,CAAWJ,GAAG,CAACE,KAAf;EAA3B,EADF,CADD,CADH,CADF;AASD"}
@@ -11,8 +11,14 @@ var _dlv = _interopRequireDefault(require("dlv"));
11
11
 
12
12
  var _reactQuery = require("react-query");
13
13
 
14
+ var _ui = require("@sanity/ui");
15
+
14
16
  var _Documents = _interopRequireDefault(require("./Documents"));
15
17
 
18
+ var _Feedback = _interopRequireDefault(require("./Feedback"));
19
+
20
+ var _Debug = _interopRequireDefault(require("./Debug"));
21
+
16
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
23
 
18
24
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -33,16 +39,25 @@ function DocumentsPane(_ref) {
33
39
  var doc = useDraft ? sanityDocument.displayed : sanityDocument.published;
34
40
 
35
41
  var _ref2 = doc !== null && doc !== void 0 ? doc : {},
36
- _id = _ref2._id,
37
42
  _rev = _ref2._rev;
38
43
 
39
44
  var paramValues = Object.keys(params).reduce((acc, key) => _objectSpread(_objectSpread({}, acc), {}, {
40
45
  [key]: (0, _dlv.default)(doc, params[key])
41
46
  }), {});
47
+
48
+ if (!_rev) {
49
+ return /*#__PURE__*/_react.default.createElement(_ui.Stack, {
50
+ padding: 4,
51
+ space: 5
52
+ }, /*#__PURE__*/_react.default.createElement(_Feedback.default, null, "Document must be Published to have References"), debug && /*#__PURE__*/_react.default.createElement(_Debug.default, {
53
+ query: query,
54
+ params: params
55
+ }));
56
+ }
57
+
42
58
  return /*#__PURE__*/_react.default.createElement(_reactQuery.QueryClientProvider, {
43
59
  client: queryClient
44
60
  }, /*#__PURE__*/_react.default.createElement(_Documents.default, {
45
- _rev: _rev,
46
61
  query: query,
47
62
  params: paramValues,
48
63
  debug: debug
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/DocumentsPane.tsx"],"names":["queryClient","QueryClient","DocumentsPane","sanityDocument","document","options","query","params","useDraft","debug","doc","displayed","published","_id","_rev","paramValues","Object","keys","reduce","acc","key"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;AAEA,IAAMA,WAAW,GAAG,IAAIC,uBAAJ,EAApB;;AAEe,SAASC,aAAT,OAA4D;AAAA,MAA1BC,cAA0B,QAApCC,QAAoC;AAAA,MAAVC,OAAU,QAAVA,OAAU;AACzE,MAAOC,KAAP,GAAyCD,OAAzC,CAAOC,KAAP;AAAA,MAAcC,MAAd,GAAyCF,OAAzC,CAAcE,MAAd;AAAA,MAAsBC,QAAtB,GAAyCH,OAAzC,CAAsBG,QAAtB;AAAA,MAAgCC,KAAhC,GAAyCJ,OAAzC,CAAgCI,KAAhC;AAEA,MAAMC,GAAG,GAAGF,QAAQ,GAAGL,cAAc,CAACQ,SAAlB,GAA8BR,cAAc,CAACS,SAAjE;;AACA,cAAoBF,GAApB,aAAoBA,GAApB,cAAoBA,GAApB,GAA2B,EAA3B;AAAA,MAAOG,GAAP,SAAOA,GAAP;AAAA,MAAYC,IAAZ,SAAYA,IAAZ;;AAEA,MAAMC,WAAW,GAAGC,MAAM,CAACC,IAAP,CAAYV,MAAZ,EAAoBW,MAApB,CAClB,CAACC,GAAD,EAAMC,GAAN,qCAAmBD,GAAnB;AAAwB,KAACC,GAAD,GAAO,kBAAMV,GAAN,EAAWH,MAAM,CAACa,GAAD,CAAjB;AAA/B,IADkB,EAElB,EAFkB,CAApB;AAKA,sBACE,6BAAC,+BAAD;AAAqB,IAAA,MAAM,EAAEpB;AAA7B,kBACE,6BAAC,kBAAD;AAAW,IAAA,IAAI,EAAEc,IAAjB;AAAuB,IAAA,KAAK,EAAER,KAA9B;AAAqC,IAAA,MAAM,EAAES,WAA7C;AAA0D,IAAA,KAAK,EAAEN;AAAjE,IADF,CADF;AAKD","sourcesContent":["import React from 'react'\nimport delve from 'dlv'\nimport {QueryClient, QueryClientProvider} from 'react-query'\n\nimport Documents from './Documents'\n\nconst queryClient = new QueryClient()\n\nexport default function DocumentsPane({document: sanityDocument, options}) {\n const {query, params, useDraft, debug} = options\n\n const doc = useDraft ? sanityDocument.displayed : sanityDocument.published\n const {_id, _rev} = doc ?? {}\n\n const paramValues = Object.keys(params).reduce(\n (acc, key) => ({...acc, [key]: delve(doc, params[key])}),\n {}\n )\n\n return (\n <QueryClientProvider client={queryClient}>\n <Documents _rev={_rev} query={query} params={paramValues} debug={debug} />\n </QueryClientProvider>\n )\n}\n"],"file":"DocumentsPane.js"}
1
+ {"version":3,"file":"DocumentsPane.js","names":["queryClient","QueryClient","DocumentsPane","sanityDocument","document","options","query","params","useDraft","debug","doc","displayed","published","_rev","paramValues","Object","keys","reduce","acc","key"],"sources":["../src/DocumentsPane.tsx"],"sourcesContent":["import React from 'react'\nimport delve from 'dlv'\nimport {QueryClient, QueryClientProvider} from 'react-query'\nimport {Stack} from '@sanity/ui'\n\nimport Documents from './Documents'\nimport Feedback from './Feedback'\nimport Debug from './Debug'\n\nconst queryClient = new QueryClient()\n\nexport default function DocumentsPane({document: sanityDocument, options}) {\n const {query, params, useDraft, debug} = options\n\n const doc = useDraft ? sanityDocument.displayed : sanityDocument.published\n const {_rev} = doc ?? {}\n\n const paramValues = Object.keys(params).reduce(\n (acc, key) => ({...acc, [key]: delve(doc, params[key])}),\n {}\n )\n\n if (!_rev) {\n return (\n <Stack padding={4} space={5}>\n <Feedback>Document must be Published to have References</Feedback>\n {debug && <Debug query={query} params={params} />}\n </Stack>\n )\n }\n\n return (\n <QueryClientProvider client={queryClient}>\n <Documents query={query} params={paramValues} debug={debug} />\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,WAAW,GAAG,IAAIC,uBAAJ,EAApB;;AAEe,SAASC,aAAT,OAA4D;EAAA,IAA1BC,cAA0B,QAApCC,QAAoC;EAAA,IAAVC,OAAU,QAAVA,OAAU;EACzE,IAAOC,KAAP,GAAyCD,OAAzC,CAAOC,KAAP;EAAA,IAAcC,MAAd,GAAyCF,OAAzC,CAAcE,MAAd;EAAA,IAAsBC,QAAtB,GAAyCH,OAAzC,CAAsBG,QAAtB;EAAA,IAAgCC,KAAhC,GAAyCJ,OAAzC,CAAgCI,KAAhC;EAEA,IAAMC,GAAG,GAAGF,QAAQ,GAAGL,cAAc,CAACQ,SAAlB,GAA8BR,cAAc,CAACS,SAAjE;;EACA,YAAeF,GAAf,aAAeA,GAAf,cAAeA,GAAf,GAAsB,EAAtB;EAAA,IAAOG,IAAP,SAAOA,IAAP;;EAEA,IAAMC,WAAW,GAAGC,MAAM,CAACC,IAAP,CAAYT,MAAZ,EAAoBU,MAApB,CAClB,CAACC,GAAD,EAAMC,GAAN,qCAAmBD,GAAnB;IAAwB,CAACC,GAAD,GAAO,kBAAMT,GAAN,EAAWH,MAAM,CAACY,GAAD,CAAjB;EAA/B,EADkB,EAElB,EAFkB,CAApB;;EAKA,IAAI,CAACN,IAAL,EAAW;IACT,oBACE,6BAAC,SAAD;MAAO,OAAO,EAAE,CAAhB;MAAmB,KAAK,EAAE;IAA1B,gBACE,6BAAC,iBAAD,wDADF,EAEGJ,KAAK,iBAAI,6BAAC,cAAD;MAAO,KAAK,EAAEH,KAAd;MAAqB,MAAM,EAAEC;IAA7B,EAFZ,CADF;EAMD;;EAED,oBACE,6BAAC,+BAAD;IAAqB,MAAM,EAAEP;EAA7B,gBACE,6BAAC,kBAAD;IAAW,KAAK,EAAEM,KAAlB;IAAyB,MAAM,EAAEQ,WAAjC;IAA8C,KAAK,EAAEL;EAArD,EADF,CADF;AAKD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Feedback.tsx"],"names":["Feedback","props","children","tone"],"mappings":";;;;;;;AAAA;;AACA;;;;AAQe,SAASA,QAAT,CAAkBC,KAAlB,EAAwC;AACrD,MAAOC,QAAP,GAAqCD,KAArC,CAAOC,QAAP;AAAA,oBAAqCD,KAArC,CAAiBE,IAAjB;AAAA,MAAiBA,IAAjB;AAEA,sBACE,6BAAC,QAAD;AAAM,IAAA,OAAO,EAAE,CAAf;AAAkB,IAAA,MAAM,EAAE,CAA1B;AAA6B,IAAA,MAAM,EAAE,CAArC;AAAwC,IAAA,IAAI,EAAEA;AAA9C,kBACE,6BAAC,QAAD;AAAM,IAAA,IAAI,EAAE;AAAZ,KAAgBD,QAAhB,CADF,CADF;AAKD","sourcesContent":["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"],"file":"Feedback.js"}
1
+ {"version":3,"file":"Feedback.js","names":["Feedback","props","children","tone"],"sources":["../src/Feedback.tsx"],"sourcesContent":["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"],"mappings":";;;;;;;AAAA;;AACA;;;;AAQe,SAASA,QAAT,CAAkBC,KAAlB,EAAwC;EACrD,IAAOC,QAAP,GAAqCD,KAArC,CAAOC,QAAP;EAAA,kBAAqCD,KAArC,CAAiBE,IAAjB;EAAA,IAAiBA,IAAjB;EAEA,oBACE,6BAAC,QAAD;IAAM,OAAO,EAAE,CAAf;IAAkB,MAAM,EAAE,CAA1B;IAA6B,MAAM,EAAE,CAArC;IAAwC,IAAI,EAAEA;EAA9C,gBACE,6BAAC,QAAD;IAAM,IAAI,EAAE;EAAZ,GAAgBD,QAAhB,CADF,CADF;AAKD"}
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["DocumentsPane"],"mappings":";;;;;;;AACA;;;;eAEeA,sB","sourcesContent":["\nimport DocumentsPane from \"./DocumentsPane\";\n\nexport default DocumentsPane\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":["DocumentsPane"],"sources":["../src/index.js"],"sourcesContent":["\nimport DocumentsPane from \"./DocumentsPane\";\n\nexport default DocumentsPane\n"],"mappings":";;;;;;;AACA;;;;eAEeA,sB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-documents-pane",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Displays the results of a GROQ query in a View Pane",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -32,9 +32,10 @@
32
32
  "@sanity/desk-tool": "^2.29.5",
33
33
  "@sanity/state-router": "^2.29.3",
34
34
  "@sanity/ui": "^0.34.6",
35
+ "@sanity/util": "^2.29.5",
35
36
  "dlv": "^1.1.3",
36
- "react-query": "^3.19.1",
37
- "husky": "^7.0.1"
37
+ "husky": "^7.0.1",
38
+ "react-query": "^3.19.1"
38
39
  },
39
40
  "devDependencies": {
40
41
  "eslint": "7.31.0",
package/src/Documents.tsx CHANGED
@@ -1,8 +1,9 @@
1
- import React from 'react'
1
+ import React, {useCallback} from 'react'
2
2
  import {useQuery} from 'react-query'
3
- import {Button, Box, Stack, Flex, Spinner} from '@sanity/ui'
3
+ import {Box, Button, Stack, Flex, Spinner} from '@sanity/ui'
4
4
  import {usePaneRouter} from '@sanity/desk-tool'
5
- import {RouterContext} from '@sanity/state-router/lib/RouterContext'
5
+ import {fromString as pathFromString} from '@sanity/util/paths'
6
+ // import {RouterContext} from '@sanity/state-router/lib/RouterContext'
6
7
  import Preview from 'part:@sanity/base/preview'
7
8
  import schema from 'part:@sanity/base/schema'
8
9
  import sanityClient from 'part:@sanity/base/client'
@@ -10,42 +11,29 @@ import sanityClient from 'part:@sanity/base/client'
10
11
  import Debug from './Debug'
11
12
  import Feedback from './Feedback'
12
13
 
13
- const client = sanityClient.withConfig({apiVersion: `2021-05-19`})
14
+ const client = sanityClient.withConfig({apiVersion: `2021-05-19`})
14
15
 
15
16
  export default function Documents(props) {
16
- const {query, params, debug, _rev} = props
17
+ const {query, params, debug} = props
17
18
 
18
19
  const {isLoading, error, data} = useQuery(['useDocuments', {props}], () =>
19
20
  client.fetch(query, params)
20
21
  )
21
22
 
22
- const routerContext = React.useContext(RouterContext)
23
- const {routerPanesState, groupIndex} = usePaneRouter()
23
+ const {routerPanesState, groupIndex, handleEditReference} = usePaneRouter()
24
+ const childParams = routerPanesState[groupIndex + 1]?.[0].params || {}
25
+ const {parentRefPath} = childParams
24
26
 
25
- const openDocumentInSidePane = React.useCallback(
26
- (id: string, type: string) => {
27
- const newPane = [
28
- {
29
- id: id,
30
- params: {type},
31
- },
32
- ]
33
- let panes = [routerPanesState[0], routerPanesState[1], newPane]
34
-
35
- const href = routerContext.resolvePathFromState({panes})
36
- routerContext.navigateUrl(href)
37
- },
38
- [routerContext, routerPanesState, groupIndex]
39
- )
40
-
41
- if (!_rev) {
42
- return (
43
- <Stack padding={4} space={5}>
44
- <Feedback>Document must be Published</Feedback>
45
- {debug && <Debug query={query} params={params} />}
46
- </Stack>
47
- )
48
- }
27
+ const handleClick = useCallback((id, type) => {
28
+ handleEditReference({
29
+ id,
30
+ type,
31
+ // Uncertain that this works as intended
32
+ parentRefPath: parentRefPath ? pathFromString(parentRefPath) : [``],
33
+ // Added this to satisfy TS
34
+ template: type,
35
+ })
36
+ }, [routerPanesState])
49
37
 
50
38
  if (isLoading) {
51
39
  return (
@@ -76,15 +64,9 @@ export default function Documents(props) {
76
64
  }
77
65
 
78
66
  return (
79
- <Stack padding={2} space={2}>
67
+ <Stack padding={2} space={1}>
80
68
  {data.map((doc) => (
81
- <Button
82
- key={doc._id}
83
- onClick={() => openDocumentInSidePane(doc._id, doc._type)}
84
- mode="bleed"
85
- radius={2}
86
- padding={2}
87
- >
69
+ <Button onClick={() => handleClick(doc._id, doc._type)} padding={2} mode="bleed">
88
70
  <Preview value={doc} type={schema.get(doc._type)} />
89
71
  </Button>
90
72
  ))}
@@ -1,8 +1,11 @@
1
1
  import React from 'react'
2
2
  import delve from 'dlv'
3
3
  import {QueryClient, QueryClientProvider} from 'react-query'
4
+ import {Stack} from '@sanity/ui'
4
5
 
5
6
  import Documents from './Documents'
7
+ import Feedback from './Feedback'
8
+ import Debug from './Debug'
6
9
 
7
10
  const queryClient = new QueryClient()
8
11
 
@@ -10,16 +13,25 @@ export default function DocumentsPane({document: sanityDocument, options}) {
10
13
  const {query, params, useDraft, debug} = options
11
14
 
12
15
  const doc = useDraft ? sanityDocument.displayed : sanityDocument.published
13
- const {_id, _rev} = doc ?? {}
16
+ const {_rev} = doc ?? {}
14
17
 
15
18
  const paramValues = Object.keys(params).reduce(
16
19
  (acc, key) => ({...acc, [key]: delve(doc, params[key])}),
17
20
  {}
18
21
  )
19
22
 
23
+ if (!_rev) {
24
+ return (
25
+ <Stack padding={4} space={5}>
26
+ <Feedback>Document must be Published to have References</Feedback>
27
+ {debug && <Debug query={query} params={params} />}
28
+ </Stack>
29
+ )
30
+ }
31
+
20
32
  return (
21
33
  <QueryClientProvider client={queryClient}>
22
- <Documents _rev={_rev} query={query} params={paramValues} debug={debug} />
34
+ <Documents query={query} params={paramValues} debug={debug} />
23
35
  </QueryClientProvider>
24
36
  )
25
37
  }