sanity-plugin-documents-pane 1.1.0 → 1.1.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.
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no -- commitlint --edit ""
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@sanity/semantic-release-preset",
3
+ "branches": [
4
+ "main",
5
+ { "name": "studio-v2", "channel": "studio-v2", "range": "1.1.x" }
6
+ ]
7
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ <!-- markdownlint-disable --><!-- textlint-disable -->
2
+
3
+ # 📓 Changelog
4
+
5
+ All notable changes to this project will be documented in this file. See
6
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
7
+
8
+ ## [1.1.1](https://github.com/sanity-io/sanity-plugin-documents-pane/compare/v1.1.0...v1.1.1) (2022-11-22)
9
+
10
+ ### Bug Fixes
11
+
12
+ - **ci:** publish using semantic-release ([7624fac](https://github.com/sanity-io/sanity-plugin-documents-pane/commit/7624fac74aea307f7999071f5228af5df8447885))
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,13 +1,23 @@
1
1
  # sanity-plugin-documents-pane
2
2
 
3
+ > This is a **Sanity Studio v2** plugin.
4
+ > For the v3 version, please refer to the [v3-branch](https://github.com/sanity-io/sanity-plugin-documents-pane).
5
+
3
6
  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
7
 
5
8
  ![Incoming References](https://user-images.githubusercontent.com/9684022/121202594-52bc6180-c86d-11eb-897d-f418047b3d22.png)
6
9
 
7
10
  ## Installation
8
11
 
12
+ ```sh
13
+ yarn add sanity-plugin-documents-pane@studio-v2
9
14
  ```
10
- sanity install documents-pane
15
+
16
+ Next, add `"documents-pane"` to `sanity.json` plugins array:
17
+ ```json
18
+ "plugins": [
19
+ "documents-pane"
20
+ ]
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 © Simeon Griggs
94
- See LICENSE
104
+ MIT © Sanity.io
105
+ See [LICENSE](license)
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ }
@@ -32,6 +32,10 @@ function NewDocument(props) {
32
32
  justify: "flex-end",
33
33
  gap: 1
34
34
  }, initialValueTemplates.map(template => {
35
+ if (!template.template) {
36
+ return null;
37
+ }
38
+
35
39
  return /*#__PURE__*/_react.default.createElement(ReferenceChildLink, {
36
40
  documentId: (0, _uuid.uuid)(),
37
41
  documentType: template.schemaType,
@@ -40,10 +44,7 @@ function NewDocument(props) {
40
44
  params: template.parameters
41
45
  },
42
46
  parentRefPath: [],
43
- key: "".concat(template.schemaType, "-").concat(template.template),
44
- style: {
45
- textDecoration: 'none'
46
- }
47
+ key: "".concat(template.schemaType, "-").concat(template.template)
47
48
  }, /*#__PURE__*/_react.default.createElement(_ui.Button, {
48
49
  icon: /*#__PURE__*/_react.default.createElement(_icons.ComposeIcon, null),
49
50
  text: template.title,
@@ -1 +1 @@
1
- {"version":3,"file":"NewDocument.js","names":["NewDocument","props","initialValueTemplates","usePaneRouter","ReferenceChildLink","length","map","template","uuid","schemaType","id","params","parameters","textDecoration","title"],"sources":["../src/NewDocument.tsx"],"sourcesContent":["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-tool'\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 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 style={{textDecoration: 'none'}}\n >\n <Button icon={<ComposeIcon />} text={template.title} mode=\"bleed\" as=\"span\" />\n </ReferenceChildLink>\n )\n })}\n </Flex>\n </Card>\n )\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;;;AAMe,SAASA,WAAT,CAAqBC,KAArB,EAA8C;EAC3D,4BAAqCA,KAArC,CAAOC,qBAAP;EAAA,IAAOA,qBAAP,sCAA+B,EAA/B;;EACA,qBAA6B,IAAAC,uBAAA,GAA7B;EAAA,IAAOC,kBAAP,kBAAOA,kBAAP;;EAEA,IAAI,CAACF,qBAAqB,CAACG,MAA3B,EAAmC,OAAO,IAAP;EAEnC,oBACE,6BAAC,QAAD;IAAM,YAAY,EAAE,IAApB;IAA0B,OAAO,EAAE;EAAnC,gBACE,6BAAC,QAAD;IAAM,OAAO,EAAC,UAAd;IAAyB,GAAG,EAAE;EAA9B,GACGH,qBAAqB,CAACI,GAAtB,CAA2BC,QAAD,IAAc;IACvC,oBACE,6BAAC,kBAAD;MACE,UAAU,EAAE,IAAAC,UAAA,GADd;MAEE,YAAY,EAAED,QAAQ,CAACE,UAFzB;MAGE,QAAQ,EAAE;QAACC,EAAE,EAAEH,QAAQ,CAACA,QAAd;QAAwBI,MAAM,EAAEJ,QAAQ,CAACK;MAAzC,CAHZ;MAIE,aAAa,EAAE,EAJjB;MAKE,GAAG,YAAKL,QAAQ,CAACE,UAAd,cAA4BF,QAAQ,CAACA,QAArC,CALL;MAME,KAAK,EAAE;QAACM,cAAc,EAAE;MAAjB;IANT,gBAQE,6BAAC,UAAD;MAAQ,IAAI,eAAE,6BAAC,kBAAD,OAAd;MAA+B,IAAI,EAAEN,QAAQ,CAACO,KAA9C;MAAqD,IAAI,EAAC,OAA1D;MAAkE,EAAE,EAAC;IAArE,EARF,CADF;EAYD,CAbA,CADH,CADF,CADF;AAoBD"}
1
+ {"version":3,"file":"NewDocument.js","names":["NewDocument","props","initialValueTemplates","usePaneRouter","ReferenceChildLink","length","map","template","uuid","schemaType","id","params","parameters","title"],"sources":["../src/NewDocument.tsx"],"sourcesContent":["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-tool'\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"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;;;AAMe,SAASA,WAAT,CAAqBC,KAArB,EAA8C;EAC3D,4BAAqCA,KAArC,CAAOC,qBAAP;EAAA,IAAOA,qBAAP,sCAA+B,EAA/B;;EACA,qBAA6B,IAAAC,uBAAA,GAA7B;EAAA,IAAOC,kBAAP,kBAAOA,kBAAP;;EAEA,IAAI,CAACF,qBAAqB,CAACG,MAA3B,EAAmC,OAAO,IAAP;EAEnC,oBACE,6BAAC,QAAD;IAAM,YAAY,EAAE,IAApB;IAA0B,OAAO,EAAE;EAAnC,gBACE,6BAAC,QAAD;IAAM,OAAO,EAAC,UAAd;IAAyB,GAAG,EAAE;EAA9B,GACGH,qBAAqB,CAACI,GAAtB,CAA2BC,QAAD,IAAc;IACvC,IAAI,CAACA,QAAQ,CAACA,QAAd,EAAwB;MACtB,OAAO,IAAP;IACD;;IACD,oBACE,6BAAC,kBAAD;MACE,UAAU,EAAE,IAAAC,UAAA,GADd;MAEE,YAAY,EAAED,QAAQ,CAACE,UAFzB;MAGE,QAAQ,EAAE;QAACC,EAAE,EAAEH,QAAQ,CAACA,QAAd;QAAwBI,MAAM,EAAEJ,QAAQ,CAACK;MAAzC,CAHZ;MAIE,aAAa,EAAE,EAJjB;MAKE,GAAG,YAAKL,QAAQ,CAACE,UAAd,cAA4BF,QAAQ,CAACA,QAArC;IALL,gBAOE,6BAAC,UAAD;MAAQ,IAAI,eAAE,6BAAC,kBAAD,OAAd;MAA+B,IAAI,EAAEA,QAAQ,CAACM,KAA9C;MAAqD,IAAI,EAAC,OAA1D;MAAkE,EAAE,EAAC;IAArE,EAPF,CADF;EAWD,CAfA,CADH,CADF,CADF;AAsBD"}
@@ -1 +1 @@
1
- {"version":3,"file":"useListeningQuery.js","names":["DEFAULT_PARAMS","DEFAULT_OPTIONS","apiVersion","useListeningQuery","query","params","options","useState","loading","setLoading","error","setError","data","setData","subscription","useRef","useEffect","current","documentStore","listenQuery","pipe","distinctUntilChanged","isEqual","catchError","err","console","subscribe","documents","unsubscribe","undefined"],"sources":["../../src/hooks/useListeningQuery.ts"],"sourcesContent":["import React, {useEffect, useState, useRef} from 'react'\nimport documentStore from 'part:@sanity/base/datastore/document'\nimport {catchError, distinctUntilChanged} from 'rxjs/operators'\nimport isEqual from 'react-fast-compare'\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: any\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(null)\n const subscription = useRef<null | Observable>(null)\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) => {\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"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;AAmBA,IAAMA,cAAc,GAAG,EAAvB;AACA,IAAMC,eAAe,GAAG;EAACC,UAAU;AAAX,CAAxB;;AAEe,SAASC,iBAAT,CACbC,KADa,EAIA;EAAA,IAFbC,MAEa,uEAFIL,cAEJ;EAAA,IADbM,OACa,uEADiBL,eACjB;;EACb,gBAA8B,IAAAM,eAAA,EAAS,IAAT,CAA9B;EAAA;EAAA,IAAOC,OAAP;EAAA,IAAgBC,UAAhB;;EACA,iBAA0B,IAAAF,eAAA,EAAS,KAAT,CAA1B;EAAA;EAAA,IAAOG,KAAP;EAAA,IAAcC,QAAd;;EACA,iBAAwB,IAAAJ,eAAA,EAAS,IAAT,CAAxB;EAAA;EAAA,IAAOK,IAAP;EAAA,IAAaC,OAAb;;EACA,IAAMC,YAAY,GAAG,IAAAC,aAAA,EAA0B,IAA1B,CAArB;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACd,IAAIZ,KAAJ,EAAW;MACTU,YAAY,CAACG,OAAb,GAAuBC,iBAAA,CACpBC,WADoB,CACRf,KADQ,EACDC,MADC,EACOC,OADP,EAEpBc,IAFoB,CAGnB,IAAAC,+BAAA,EAAqBC,yBAArB,CAHmB,EAInB,IAAAC,qBAAA,EAAYC,GAAD,IAAS;QAClBC,OAAO,CAACf,KAAR,CAAcc,GAAd;QACAb,QAAQ,CAACa,GAAD,CAAR;QACAf,UAAU,CAAC,KAAD,CAAV;QACAI,OAAO,CAAC,IAAD,CAAP;QAEA,OAAOW,GAAP;MACD,CAPD,CAJmB,EAapBE,SAboB,CAaTC,SAAD,IAAe;QACxBd,OAAO,CAAEI,OAAD,IAAc,IAAAK,yBAAA,EAAQL,OAAR,EAAiBU,SAAjB,IAA8BV,OAA9B,GAAwCU,SAAvD,CAAP;QACAlB,UAAU,CAAC,KAAD,CAAV;QACAE,QAAQ,CAAC,KAAD,CAAR;MACD,CAjBoB,CAAvB;IAkBD;;IAED,OAAO,MAAM;MACX,OAAOG,YAAY,CAACG,OAAb,GAAuBH,YAAY,CAACG,OAAb,CAAqBW,WAArB,EAAvB,GAA4DC,SAAnE;IACD,CAFD;EAGD,CAzBD,EAyBG,CAACzB,KAAD,EAAQC,MAAR,EAAgBC,OAAhB,CAzBH;EA2BA,OAAO;IAACE,OAAD;IAAUE,KAAV;IAAiBE;EAAjB,CAAP;AACD"}
1
+ {"version":3,"file":"useListeningQuery.js","names":["DEFAULT_PARAMS","DEFAULT_OPTIONS","apiVersion","useListeningQuery","query","params","options","useState","loading","setLoading","error","setError","data","setData","subscription","useRef","useEffect","current","documentStore","listenQuery","pipe","distinctUntilChanged","isEqual","catchError","err","console","subscribe","documents","unsubscribe","undefined"],"sources":["../../src/hooks/useListeningQuery.ts"],"sourcesContent":["import type {SanityDocument} from '@sanity/types'\nimport {useEffect, useState, useRef} from 'react'\nimport documentStore from 'part:@sanity/base/datastore/document'\nimport {catchError, distinctUntilChanged} from 'rxjs/operators'\nimport isEqual from 'react-fast-compare'\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\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"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;AAmBA,IAAMA,cAAc,GAAG,EAAvB;AACA,IAAMC,eAAe,GAAG;EAACC,UAAU;AAAX,CAAxB;;AAEe,SAASC,iBAAT,CACbC,KADa,EAIA;EAAA,IAFbC,MAEa,uEAFIL,cAEJ;EAAA,IADbM,OACa,uEADiBL,eACjB;;EACb,gBAA8B,IAAAM,eAAA,EAAS,IAAT,CAA9B;EAAA;EAAA,IAAOC,OAAP;EAAA,IAAgBC,UAAhB;;EACA,iBAA0B,IAAAF,eAAA,EAAS,KAAT,CAA1B;EAAA;EAAA,IAAOG,KAAP;EAAA,IAAcC,QAAd;;EACA,iBAAwB,IAAAJ,eAAA,EAAkC,IAAlC,CAAxB;EAAA;EAAA,IAAOK,IAAP;EAAA,IAAaC,OAAb;;EACA,IAAMC,YAAY,GAAG,IAAAC,aAAA,EAA0B,IAA1B,CAArB;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACd,IAAIZ,KAAJ,EAAW;MACTU,YAAY,CAACG,OAAb,GAAuBC,iBAAA,CACpBC,WADoB,CACRf,KADQ,EACDC,MADC,EACOC,OADP,EAEpBc,IAFoB,CAGnB,IAAAC,+BAAA,EAAqBC,yBAArB,CAHmB,EAInB,IAAAC,qBAAA,EAAYC,GAAD,IAAS;QAClBC,OAAO,CAACf,KAAR,CAAcc,GAAd;QACAb,QAAQ,CAACa,GAAD,CAAR;QACAf,UAAU,CAAC,KAAD,CAAV;QACAI,OAAO,CAAC,IAAD,CAAP;QAEA,OAAOW,GAAP;MACD,CAPD,CAJmB,EAapBE,SAboB,CAaTC,SAAD,IAAiC;QAC1Cd,OAAO,CAAEI,OAAD,IAAc,IAAAK,yBAAA,EAAQL,OAAR,EAAiBU,SAAjB,IAA8BV,OAA9B,GAAwCU,SAAvD,CAAP;QACAlB,UAAU,CAAC,KAAD,CAAV;QACAE,QAAQ,CAAC,KAAD,CAAR;MACD,CAjBoB,CAAvB;IAkBD;;IAED,OAAO,MAAM;MACX,OAAOG,YAAY,CAACG,OAAb,GAAuBH,YAAY,CAACG,OAAb,CAAqBW,WAArB,EAAvB,GAA4DC,SAAnE;IACD,CAFD;EAGD,CAzBD,EAyBG,CAACzB,KAAD,EAAQC,MAAR,EAAgBC,OAAhB,CAzBH;EA2BA,OAAO;IAACE,OAAD;IAAUE,KAAV;IAAiBE;EAAjB,CAAP;AACD"}
package/lib/parts.d.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=parts.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parts.d.js","names":[],"sources":["../src/parts.d.ts"],"sourcesContent":["// Tells Typescript to skip typechecking imported parts\ndeclare module \"part:@sanity/*\";\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveParams.js","names":["defaultResolver","options","params","document","useDraft","doc","displayed","published","Object","keys","reduce","acc","key","delve","resolveParams","resolvedParams","values","includes","undefined"],"sources":["../src/resolveParams.ts"],"sourcesContent":["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): {[key: string]: string | undefined} {\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((acc, key) => ({...acc, [key]: delve(doc, params[key])}), {})\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"],"mappings":";;;;;;;AACA;;;;;;;;;;AAUA,SAASA,eAAT,CAAyBC,OAAzB,EAA6F;EAC3F,IAAOC,MAAP,GAAqCD,OAArC,CAAOC,MAAP;EAAA,IAAeC,QAAf,GAAqCF,OAArC,CAAeE,QAAf;EAAA,IAAyBC,QAAzB,GAAqCH,OAArC,CAAyBG,QAAzB,CAD2F,CAG3F;;EACA,IAAI,CAACF,MAAL,EAAa,OAAO,EAAP,CAJ8E,CAM3F;;EACA,IAAMG,GAAG,GAAGD,QAAQ,GAAGD,QAAQ,CAACG,SAAZ,GAAwBH,QAAQ,CAACI,SAArD;EAEA,OAAOC,MAAM,CAACC,IAAP,CAAYP,MAAZ,EAAoBQ,MAApB,CAA2B,CAACC,GAAD,EAAMC,GAAN,qCAAmBD,GAAnB;IAAwB,CAACC,GAAD,GAAO,IAAAC,YAAA,EAAMR,GAAN,EAAWH,MAAM,CAACU,GAAD,CAAjB;EAA/B,EAA3B,EAAqF,EAArF,CAAP;AACD;;AAEc,SAASE,aAAT,CAAuBb,OAAvB,EAA2E;EACxF,IAAOC,MAAP,GAA2BD,OAA3B,CAAOC,MAAP;EAAA,IAAeC,QAAf,GAA2BF,OAA3B,CAAeE,QAAf;EAEA,IAAMY,cAAc,GAAG,OAAOb,MAAP,IAAiB,UAAjB,GAA8BA,MAAM,CAAC;IAACC;EAAD,CAAD,CAApC,GAAmDH,eAAe,CAACC,OAAD,CAAzF,CAHwF,CAKxF;EACA;;EACA,IAAIO,MAAM,CAACQ,MAAP,CAAcD,cAAd,EAA8BE,QAA9B,CAAuCC,SAAvC,CAAJ,EAAuD,OAAOA,SAAP,CAPiC,CASxF;EACA;;EACA,OAAOH,cAAP;AACD"}
1
+ {"version":3,"file":"resolveParams.js","names":["defaultResolver","options","params","document","useDraft","doc","displayed","published","Object","keys","reduce","acc","key","delve","resolveParams","resolvedParams","values","includes","undefined"],"sources":["../src/resolveParams.ts"],"sourcesContent":["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"],"mappings":";;;;;;;AACA;;;;;;;;;;AAUA,SAASA,eAAT,CAAyBC,OAAzB,EAEE;EACA,IAAOC,MAAP,GAAqCD,OAArC,CAAOC,MAAP;EAAA,IAAeC,QAAf,GAAqCF,OAArC,CAAeE,QAAf;EAAA,IAAyBC,QAAzB,GAAqCH,OAArC,CAAyBG,QAAzB,CADA,CAGA;;EACA,IAAI,CAACF,MAAL,EAAa,OAAO,EAAP,CAJb,CAMA;;EACA,IAAMG,GAAG,GAAGD,QAAQ,GAAGD,QAAQ,CAACG,SAAZ,GAAwBH,QAAQ,CAACI,SAArD;EAEA,OAAOC,MAAM,CAACC,IAAP,CAAYP,MAAZ,EAAoBQ,MAApB,CACL,CAACC,GAAD,EAAMC,GAAN,qCACKD,GADL;IAEE,CAACC,GAAD,GAAO,IAAAC,YAAA,EAAMR,GAAN,EAAWH,MAAM,CAACU,GAAD,CAAjB;EAFT,EADK,EAKL,EALK,CAAP;AAOD;;AAEc,SAASE,aAAT,CAAuBb,OAAvB,EAA2E;EACxF,IAAOC,MAAP,GAA2BD,OAA3B,CAAOC,MAAP;EAAA,IAAeC,QAAf,GAA2BF,OAA3B,CAAeE,QAAf;EAEA,IAAMY,cAAc,GAAG,OAAOb,MAAP,IAAiB,UAAjB,GAA8BA,MAAM,CAAC;IAACC;EAAD,CAAD,CAApC,GAAmDH,eAAe,CAACC,OAAD,CAAzF,CAHwF,CAKxF;EACA;;EACA,IAAIO,MAAM,CAACQ,MAAP,CAAcD,cAAd,EAA8BE,QAA9B,CAAuCC,SAAvC,CAAJ,EAAuD,OAAOA,SAAP,CAPiC,CASxF;EACA;;EACA,OAAOH,cAAP;AACD"}
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ '**/*.{js,jsx}': ['eslint'],
3
+ '**/*.{ts,tsx}': ['eslint', () => 'tsc --noEmit'],
4
+ }
package/package.json CHANGED
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "name": "sanity-plugin-documents-pane",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Displays the results of a GROQ query in a View Pane",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "build": "sanipack build",
8
8
  "verify": "sanipack verify",
9
9
  "watch": "sanipack build --watch",
10
- "_postinstall": "husky install",
11
- "prepublishOnly": "pinst --disable && sanipack build && sanipack verify",
12
- "postpublish": "pinst --enable",
13
10
  "lint": "eslint .",
14
- "lint:fix": "eslint . --fix"
11
+ "prepublishOnly": "npm run compile && npm run build",
12
+ "compile": "tsc --noEmit"
15
13
  },
16
14
  "husky": {
17
15
  "hooks": {
@@ -38,20 +36,34 @@
38
36
  "peerDependencies": {
39
37
  "@sanity/base": "^2.30.1",
40
38
  "@sanity/desk-tool": "^2.30.1",
41
- "@sanity/uuid": "^3.0.1",
42
39
  "@sanity/util": "^2.29.5",
40
+ "@sanity/uuid": "^3.0.1",
43
41
  "react": "^16.0.0 || ^17.0.0"
44
42
  },
45
43
  "devDependencies": {
46
- "@sanity/eslint-config-studio": "^2.0.0",
47
- "eslint": "8.19.0",
44
+ "@commitlint/cli": "^17.1.2",
45
+ "@commitlint/config-conventional": "^17.1.0",
46
+ "@sanity/base": "^2.30.1",
47
+ "@sanity/desk-tool": "^2.30.1",
48
+ "@sanity/semantic-release-preset": "^2.0.1",
49
+ "@sanity/types": "^2.34.0",
50
+ "@sanity/util": "^2.29.5",
51
+ "@sanity/uuid": "^3.0.1",
52
+ "@types/dlv": "^1.1.2",
53
+ "@types/react": "^17.0.0",
54
+ "@types/react-dom": "^17.0.0",
55
+ "@typescript-eslint/eslint-plugin": "^5.38.1",
56
+ "@typescript-eslint/parser": "^5.38.1",
57
+ "eslint": "^8.24.0",
48
58
  "eslint-config-prettier": "^8.5.0",
49
- "eslint-config-sanity": "6.0.0",
59
+ "eslint-config-sanity": "^6.0.0",
50
60
  "eslint-plugin-prettier": "^4.2.1",
51
- "eslint-plugin-react": "^7.30.1",
52
61
  "husky": "^8.0.1",
62
+ "lint-staged": "^13.0.3",
53
63
  "pinst": "^3.0.0",
54
64
  "prettier": "^2.7.1",
65
+ "react": "^17.0.0",
66
+ "react-dom": "^17.0.2",
55
67
  "sanipack": "^2.1.0",
56
68
  "typescript": "^4.7.4"
57
69
  },
package/renovate.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "github>sanity-io/renovate-presets//ecosystem/auto",
5
+ "github>sanity-io/renovate-presets//ecosystem/studio-v3"
6
+ ]
7
+ }
@@ -3,7 +3,7 @@ import React from 'react'
3
3
  import {DocumentsPaneInitialValueTemplate} from './types'
4
4
  import {ComposeIcon} from '@sanity/icons'
5
5
  import {usePaneRouter} from '@sanity/desk-tool'
6
- import {uuid} from "@sanity/uuid"
6
+ import {uuid} from '@sanity/uuid'
7
7
 
8
8
  interface NewDocumentProps {
9
9
  initialValueTemplates: DocumentsPaneInitialValueTemplate[]
@@ -19,6 +19,9 @@ export default function NewDocument(props: NewDocumentProps) {
19
19
  <Card borderBottom={true} padding={2}>
20
20
  <Flex justify="flex-end" gap={1}>
21
21
  {initialValueTemplates.map((template) => {
22
+ if (!template.template) {
23
+ return null
24
+ }
22
25
  return (
23
26
  <ReferenceChildLink
24
27
  documentId={uuid()}
@@ -26,7 +29,6 @@ export default function NewDocument(props: NewDocumentProps) {
26
29
  template={{id: template.template, params: template.parameters}}
27
30
  parentRefPath={[]}
28
31
  key={`${template.schemaType}-${template.template}`}
29
- style={{textDecoration: 'none'}}
30
32
  >
31
33
  <Button icon={<ComposeIcon />} text={template.title} mode="bleed" as="span" />
32
34
  </ReferenceChildLink>
@@ -1,4 +1,5 @@
1
- import React, {useEffect, useState, useRef} from 'react'
1
+ import type {SanityDocument} from '@sanity/types'
2
+ import {useEffect, useState, useRef} from 'react'
2
3
  import documentStore from 'part:@sanity/base/datastore/document'
3
4
  import {catchError, distinctUntilChanged} from 'rxjs/operators'
4
5
  import isEqual from 'react-fast-compare'
@@ -13,7 +14,7 @@ interface ListenQueryOptions {
13
14
  type ReturnShape = {
14
15
  loading: boolean
15
16
  error: boolean
16
- data: any
17
+ data: SanityDocument[] | null
17
18
  }
18
19
 
19
20
  type Observable = {
@@ -30,7 +31,7 @@ export default function useListeningQuery(
30
31
  ): ReturnShape {
31
32
  const [loading, setLoading] = useState(true)
32
33
  const [error, setError] = useState(false)
33
- const [data, setData] = useState(null)
34
+ const [data, setData] = useState<SanityDocument[] | null>(null)
34
35
  const subscription = useRef<null | Observable>(null)
35
36
 
36
37
  useEffect(() => {
@@ -48,7 +49,7 @@ export default function useListeningQuery(
48
49
  return err
49
50
  })
50
51
  )
51
- .subscribe((documents) => {
52
+ .subscribe((documents: SanityDocument[]) => {
52
53
  setData((current) => (isEqual(current, documents) ? current : documents))
53
54
  setLoading(false)
54
55
  setError(false)
package/src/parts.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Tells Typescript to skip typechecking imported parts
2
+ declare module "part:@sanity/*";
@@ -9,7 +9,9 @@ interface ResolveParamsOptions {
9
9
 
10
10
  type ResolveParamsReturn = undefined | {[key: string]: string}
11
11
 
12
- function defaultResolver(options: ResolveParamsOptions): {[key: string]: string | undefined} {
12
+ function defaultResolver(options: ResolveParamsOptions): {
13
+ [key: string]: string | undefined
14
+ } {
13
15
  const {params, document, useDraft} = options
14
16
 
15
17
  // params is optional
@@ -18,7 +20,13 @@ function defaultResolver(options: ResolveParamsOptions): {[key: string]: string
18
20
  // legacy useDraft behaviour
19
21
  const doc = useDraft ? document.displayed : document.published
20
22
 
21
- return Object.keys(params).reduce((acc, key) => ({...acc, [key]: delve(doc, params[key])}), {})
23
+ return Object.keys(params).reduce(
24
+ (acc, key) => ({
25
+ ...acc,
26
+ [key]: delve(doc, params[key as keyof DocumentsPaneQueryParams]),
27
+ }),
28
+ {}
29
+ )
22
30
  }
23
31
 
24
32
  export default function resolveParams(options: ResolveParamsOptions): ResolveParamsReturn {
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "jsx": "react",
4
+ "moduleResolution": "node",
5
+ "target": "es5",
6
+ "esModuleInterop": true,
7
+ "module": "es2015",
8
+ "lib": ["es2015", "es2016", "es2017", "dom"],
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ "sourceMap": true,
12
+ "declaration": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "experimentalDecorators": true,
15
+ "emitDecoratorMetadata": true,
16
+ "outDir": "lib",
17
+ "typeRoots": ["node_modules/@types"],
18
+ "baseUrl": "."
19
+ },
20
+ "include": ["src/**/*"]
21
+ }