sanity-plugin-documents-pane 2.0.0-v3-studio.3 → 2.0.0-v3-studio.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/lib/index.esm.js +2 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/src/index.d.ts +47 -0
- package/package.json +36 -31
- package/src/Documents.tsx +2 -3
- package/src/hooks/useListeningQuery.ts +1 -1
- package/lib/cjs/index.js +0 -365
- package/lib/cjs/index.js.map +0 -1
- package/lib/esm/index.js +0 -353
- package/lib/esm/index.js.map +0 -1
- package/lib/types/index.d.ts +0 -40
- package/lib/types/index.d.ts.map +0 -1
- package/src/parts.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# sanity-plugin-documents-pane
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> **NOTE**
|
|
4
4
|
>
|
|
5
|
-
>
|
|
5
|
+
> This is the **Sanity Studio v3 version** of sanity-plugin-documents-pane.
|
|
6
|
+
>
|
|
7
|
+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-plugin-documents-pane).
|
|
8
|
+
|
|
6
9
|
|
|
7
10
|
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.
|
|
8
11
|
|
|
@@ -101,5 +104,19 @@ This plugin is based on [Incoming References](https://github.com/sanity-io/sanit
|
|
|
101
104
|
|
|
102
105
|
## License
|
|
103
106
|
|
|
104
|
-
MIT
|
|
105
|
-
|
|
107
|
+
MIT-licensed. See LICENSE.
|
|
108
|
+
|
|
109
|
+
## Develop & test
|
|
110
|
+
|
|
111
|
+
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
|
|
112
|
+
with default configuration for build & watch scripts.
|
|
113
|
+
|
|
114
|
+
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
|
|
115
|
+
on how to run this plugin with hotreload in the studio.
|
|
116
|
+
|
|
117
|
+
### Release new version
|
|
118
|
+
|
|
119
|
+
Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-documents-pane/actions/workflows/main.yml).
|
|
120
|
+
Make sure to select the main branch and check "Release new version".
|
|
121
|
+
|
|
122
|
+
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
package/lib/index.esm.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function r(r){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){t(r,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))}))}return r}function t(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}import{jsxs as n,Fragment as i,jsx as o}from"react/jsx-runtime";import{Stack as a,Box as c,Label as l,Code as d,Card as u,Text as s,Flex as p,Button as m,Spinner as f}from"@sanity/ui";import{useState as h,useRef as y,useEffect as b,useCallback as g}from"react";import{fromString as O}from"@sanity/util/paths";import{useDocumentStore as v,useSchema as j,SanityPreview as P}from"sanity";import{usePaneRouter as T}from"sanity/desk";import{distinctUntilChanged as q,catchError as w}from"rxjs/operators";import D from"react-fast-compare";import{ComposeIcon as x}from"@sanity/icons";import{uuid as V}from"@sanity/uuid";import k from"dlv";function R(e){let{query:r,params:t}=e;return n(i,{children:[n(a,{space:4,children:[o(c,{children:o(l,{children:"Query"})}),o(c,{children:o(d,{children:r})})]}),t&&n(a,{space:4,children:[o(c,{children:o(l,{children:"Params"})}),o(c,{children:o(d,{children:JSON.stringify(t)})})]})]})}function S(e){const{children:r,tone:t="caution"}=e;return o(u,{padding:3,radius:2,shadow:1,tone:t,children:o(s,{size:1,children:r})})}const _={},E={apiVersion:"v2022-05-09"};function C(e){const{initialValueTemplates:r=[]}=e,{ReferenceChildLink:t}=T();return r.length?o(u,{borderBottom:!0,padding:2,children:o(p,{justify:"flex-end",gap:1,children:r.map((e=>e.template?o(t,{documentId:V(),documentType:e.schemaType,template:{id:e.template,params:e.parameters},parentRefPath:[],children:o(m,{icon:o(x,{}),text:e.title,mode:"bleed",as:"span"})},"".concat(e.schemaType,"-").concat(e.template)):null))})}):null}function I(e){const{query:r,params:t,debug:l,initialValueTemplates:d}=e,{routerPanesState:u,groupIndex:s,handleEditReference:x}=T(),V=j(),{loading:k,error:I,data:N}=function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:_,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:E;const[n,i]=h(!0),[o,a]=h(!1),[c,l]=h(null),d=y(null),u=v();return b((()=>(e&&(d.current=u.listenQuery(e,r,t).pipe(q(D),w((e=>(console.error(e),a(e),i(!1),l(null),e)))).subscribe((e=>{l((r=>D(r,e)?r:e)),i(!1),a(!1)}))),()=>d.current?d.current.unsubscribe():void 0)),[e,r,t,u]),{loading:n,error:o,data:c}}(r,t),Q=g(((e,r)=>{var t;const n=(null==(t=u[s+1])?void 0:t[0].params)||{},{parentRefPath:i}=n;x({id:e,type:r,parentRefPath:i?O(i):[""],template:{id:e}})}),[u,s,x]);return k?o(c,{padding:4,children:o(p,{justify:"center",align:"center",children:o(f,{muted:!0})})}):I?n(a,{padding:4,space:5,children:[o(S,{children:"There was en error performing this query"}),l&&o(R,{query:r,params:t})]}):(null==N?void 0:N.length)?n(i,{children:[o(C,{initialValueTemplates:d}),o(a,{padding:2,space:1,children:N.map((e=>{const r=V.get(e._type);return r?o(m,{onClick:()=>Q(e._id,e._type),padding:2,mode:"bleed",children:o(P,{value:e,schemaType:r})},e._id):null}))})]}):n(i,{children:[o(C,{initialValueTemplates:d}),n(a,{padding:4,space:5,children:[o(S,{children:"No Documents found"}),l&&o(R,{query:r,params:t})]})]})}function N(e){const{params:t,document:n}=e,i="function"==typeof t?t({document:n}):function(e){const{params:t,document:n,useDraft:i}=e;if(!t)return{};const o=i?n.displayed:n.published;return Object.keys(t).reduce(((e,n)=>r(r({},e),{},{[n]:k(o,t[n])})),{})}(e);if(!Object.values(i).includes(void 0))return i}function Q(e){const{document:r,options:t}=e,{query:i,params:c,useDraft:l=!1,debug:d=!1,initialValueTemplates:u}=t;if(l&&"function"==typeof c)return n(a,{padding:4,space:5,children:[n(S,{children:[o("code",{children:"useDraft"})," should not be ",o("code",{children:"true"})," when supplying a function for",o("code",{children:"params"})]}),d&&o(R,{query:i})]});const s=N({document:r,params:c,useDraft:l}),p=function(e){const{resolver:r,document:t}=e||{};return r?r({document:t}):[]}({resolver:u,document:r});return s?o(I,{query:i,params:s,debug:d,initialValueTemplates:p}):n(a,{padding:4,space:5,children:[o(S,{children:"Parameters for this query could not be resolved. This may mean the document does not yet exist or is incomplete."}),d&&o(R,{query:i})]})}export{Q as default};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/Debug.tsx","../src/Feedback.tsx","../src/hooks/useListeningQuery.ts","../src/NewDocument.tsx","../src/Documents.tsx","../src/resolveParams.ts","../src/DocumentsPane.tsx","../src/resolveInitialValueTemplates.ts"],"sourcesContent":["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, documentStore])\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 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: string, type: string) => {\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 template: {id},\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 {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 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 {\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":["Debug","_ref","query","params","jsxs","Fragment","children","Stack","space","jsx","Box","Label","Code","JSON","stringify","Feedback","props","tone","Card","padding","radius","shadow","Text","size","DEFAULT_PARAMS","DEFAULT_OPTIONS","apiVersion","NewDocument","initialValueTemplates","ReferenceChildLink","usePaneRouter","length","borderBottom","Flex","justify","gap","map","template","documentId","uuid","documentType","schemaType","id","parameters","parentRefPath","Button","icon","ComposeIcon","text","title","mode","as","concat","Documents","debug","routerPanesState","groupIndex","handleEditReference","schema","useSchema","loading","error","data","options","setLoading","useState","setError","setData","subscription","useRef","documentStore","useDocumentStore","useEffect","current","listenQuery","pipe","distinctUntilChanged","isEqual","catchError","err","console","subscribe","documents","unsubscribe","useListeningQuery","handleClick","useCallback","type","_a","childParams","pathFromString","align","Spinner","muted","doc","get","_type","onClick","_id","SanityPreview","value","resolveParams","document","resolvedParams","useDraft","displayed","published","Object","keys","reduce","acc","key","delve","defaultResolver","values","includes","DocumentsPane","initialValueTemplatesResolver","paramValues","resolver","resolveInitialValueTemplates"],"mappings":"+yCAGA,SAAwBA,EAA0EC,GAAA,IAApEC,MAACA,EAAOC,OAAAA,GAA4DF,EAE9F,OAAAG,EAAAC,EAAA,CACEC,SAAA,CAACF,EAAAG,EAAA,CAAMC,MAAO,EACZF,SAAA,CAACG,EAAAC,EAAA,CACCJ,SAACG,EAAAE,EAAA,CAAML,SAAA,YAERG,EAAAC,EAAA,CACCJ,SAACG,EAAAG,EAAA,CAAMN,SAAAJ,SAGVC,GACEC,EAAAG,EAAA,CAAMC,MAAO,EACZF,SAAA,CAACG,EAAAC,EAAA,CACCJ,SAACG,EAAAE,EAAA,CAAML,SAAA,aAERG,EAAAC,EAAA,CACCJ,SAACG,EAAAG,EAAA,CAAMN,SAAAO,KAAKC,UAAUX,YAMlC,CCjBA,SAAwBY,EAASC,GAC/B,MAAMV,SAACA,EAAAW,KAAUA,EAAO,WAAaD,EAErC,OACGP,EAAAS,EAAA,CAAKC,QAAS,EAAGC,OAAQ,EAAGC,OAAQ,EAAGJ,OACtCX,SAACG,EAAAa,EAAA,CAAKC,KAAM,EAAIjB,cAGtB,CCKA,MAAMkB,EAAiB,CAAA,EACjBC,EAAk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,aAFK,EAGxB,CDegCkB,CAA6B,CACzDD,SAAUF,EACVf,aAGF,OAAKgB,EAaF7G,EAAA4C,EAAA,CACCnD,QACAC,OAAQmH,EACRhE,QACA1B,0BAfCxB,EAAAG,EAAA,CAAMY,QAAS,EAAGX,MAAO,EACxBF,SAAA,CAACG,EAAAM,EAAA,CAAST,SAAA,qHAITgD,GAAU7C,EAAAT,EAAA,CAAME,YAazB"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function e(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function r(r){for(var n=1;n<arguments.length;n++){var s=null!=arguments[n]?arguments[n]:{};n%2?e(Object(s),!0).forEach((function(e){t(r,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(s)):e(Object(s)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(s,e))}))}return r}function t(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var n=require("react/jsx-runtime"),s=require("@sanity/ui"),i=require("react"),a=require("@sanity/util/paths"),c=require("sanity"),u=require("sanity/desk"),o=require("rxjs/operators"),l=require("react-fast-compare"),d=require("@sanity/icons"),p=require("@sanity/uuid"),m=require("dlv");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var j=h(l),f=h(m);function x(e){let{query:r,params:t}=e;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Stack,{space:4,children:[n.jsx(s.Box,{children:n.jsx(s.Label,{children:"Query"})}),n.jsx(s.Box,{children:n.jsx(s.Code,{children:r})})]}),t&&n.jsxs(s.Stack,{space:4,children:[n.jsx(s.Box,{children:n.jsx(s.Label,{children:"Params"})}),n.jsx(s.Box,{children:n.jsx(s.Code,{children:JSON.stringify(t)})})]})]})}function y(e){const{children:r,tone:t="caution"}=e;return n.jsx(s.Card,{padding:3,radius:2,shadow:1,tone:t,children:n.jsx(s.Text,{size:1,children:r})})}const g={},b={apiVersion:"v2022-05-09"};function v(e){const{initialValueTemplates:r=[]}=e,{ReferenceChildLink:t}=u.usePaneRouter();return r.length?n.jsx(s.Card,{borderBottom:!0,padding:2,children:n.jsx(s.Flex,{justify:"flex-end",gap:1,children:r.map((e=>e.template?n.jsx(t,{documentId:p.uuid(),documentType:e.schemaType,template:{id:e.template,params:e.parameters},parentRefPath:[],children:n.jsx(s.Button,{icon:n.jsx(d.ComposeIcon,{}),text:e.title,mode:"bleed",as:"span"})},"".concat(e.schemaType,"-").concat(e.template)):null))})}):null}function q(e){const{query:r,params:t,debug:l,initialValueTemplates:d}=e,{routerPanesState:p,groupIndex:m,handleEditReference:h}=u.usePaneRouter(),f=c.useSchema(),{loading:q,error:O,data:S}=function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:g,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:b;const[n,s]=i.useState(!0),[a,u]=i.useState(!1),[l,d]=i.useState(null),p=i.useRef(null),m=c.useDocumentStore();return i.useEffect((()=>(e&&(p.current=m.listenQuery(e,r,t).pipe(o.distinctUntilChanged(j.default),o.catchError((e=>(console.error(e),u(e),s(!1),d(null),e)))).subscribe((e=>{d((r=>j.default(r,e)?r:e)),s(!1),u(!1)}))),()=>p.current?p.current.unsubscribe():void 0)),[e,r,t,m]),{loading:n,error:a,data:l}}(r,t),P=i.useCallback(((e,r)=>{var t;const n=(null==(t=p[m+1])?void 0:t[0].params)||{},{parentRefPath:s}=n;h({id:e,type:r,parentRefPath:s?a.fromString(s):[""],template:{id:e}})}),[p,m,h]);return q?n.jsx(s.Box,{padding:4,children:n.jsx(s.Flex,{justify:"center",align:"center",children:n.jsx(s.Spinner,{muted:!0})})}):O?n.jsxs(s.Stack,{padding:4,space:5,children:[n.jsx(y,{children:"There was en error performing this query"}),l&&n.jsx(x,{query:r,params:t})]}):(null==S?void 0:S.length)?n.jsxs(n.Fragment,{children:[n.jsx(v,{initialValueTemplates:d}),n.jsx(s.Stack,{padding:2,space:1,children:S.map((e=>{const r=f.get(e._type);return r?n.jsx(s.Button,{onClick:()=>P(e._id,e._type),padding:2,mode:"bleed",children:n.jsx(c.SanityPreview,{value:e,schemaType:r})},e._id):null}))})]}):n.jsxs(n.Fragment,{children:[n.jsx(v,{initialValueTemplates:d}),n.jsxs(s.Stack,{padding:4,space:5,children:[n.jsx(y,{children:"No Documents found"}),l&&n.jsx(x,{query:r,params:t})]})]})}function O(e){const{params:t,document:n}=e,s="function"==typeof t?t({document:n}):function(e){const{params:t,document:n,useDraft:s}=e;if(!t)return{};const i=s?n.displayed:n.published;return Object.keys(t).reduce(((e,n)=>r(r({},e),{},{[n]:f.default(i,t[n])})),{})}(e);if(!Object.values(s).includes(void 0))return s}module.exports=function(e){const{document:r,options:t}=e,{query:i,params:a,useDraft:c=!1,debug:u=!1,initialValueTemplates:o}=t;if(c&&"function"==typeof a)return n.jsxs(s.Stack,{padding:4,space:5,children:[n.jsxs(y,{children:[n.jsx("code",{children:"useDraft"})," should not be ",n.jsx("code",{children:"true"})," when supplying a function for",n.jsx("code",{children:"params"})]}),u&&n.jsx(x,{query:i})]});const l=O({document:r,params:a,useDraft:c}),d=function(e){const{resolver:r,document:t}=e||{};return r?r({document:t}):[]}({resolver:o,document:r});return l?n.jsx(q,{query:i,params:l,debug:u,initialValueTemplates:d}):n.jsxs(s.Stack,{padding:4,space:5,children:[n.jsx(y,{children:"Parameters for this query could not be resolved. This may mean the document does not yet exist or is incomplete."}),u&&n.jsx(x,{query:i})]})};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Debug.tsx","../src/Feedback.tsx","../src/hooks/useListeningQuery.ts","../src/NewDocument.tsx","../src/Documents.tsx","../src/resolveParams.ts","../src/DocumentsPane.tsx","../src/resolveInitialValueTemplates.ts"],"sourcesContent":["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, documentStore])\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 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: string, type: string) => {\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 template: {id},\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 {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 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 {\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":["Debug","_ref","query","params","jsxs","Fragment","children","Stack","space","jsx","Box","Label","Code","JSON","stringify","Feedback","props","tone","Card","padding","radius","shadow","Text","size","DEFAULT_PARAMS","DEFAULT_OPTIONS","apiVersion","NewDocument","initialValueTemplates","ReferenceChildLink","usePaneRouter","length","borderBottom","Flex","justify","gap","map","template","documentId","uuid","documentType","schemaType","id","parameters","parentRefPath","Button","icon","ComposeIcon","text","title","mode","as","concat","Documents","debug","routerPanesState","groupIndex","handleEditReference","schema","useSchema","loading","error","data","options","setLoading","useState","setError","setData","subscription","useRef","documentStore","useDocumentStore","useEffect","current","listenQuery","pipe","distinctUntilChanged","isEqual","catchError","err","console","subscribe","documents","unsubscribe","useListeningQuery","handleClick","useCallback","type","_a","childParams","pathFromString","fromString","align","Spinner","muted","doc","get","_type","onClick","_id","SanityPreview","value","resolveParams","document","resolvedParams","useDraft","displayed","published","Object","keys","reduce","acc","key","delve","defaultResolver","values","includes","initialValueTemplatesResolver","paramValues","resolver","resolveInitialValueTemplates"],"mappings":"2jCAGA,SAAwBA,EAA0EC,GAAA,IAApEC,MAACA,EAAOC,OAAAA,GAA4DF,EAE9F,OAAAG,EAAAA,KAAAC,EAAAA,SAAA,CACEC,SAAA,CAACF,EAAAA,KAAAG,EAAAA,MAAA,CAAMC,MAAO,EACZF,SAAA,CAACG,EAAAA,IAAAC,EAAAA,IAAA,CACCJ,SAACG,EAAAA,IAAAE,QAAA,CAAML,SAAA,YAERG,EAAAA,IAAAC,EAAAA,IAAA,CACCJ,SAACG,EAAAA,IAAAG,OAAA,CAAMN,SAAAJ,SAGVC,GACEC,EAAAA,KAAAG,QAAA,CAAMC,M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AAA,CACHC,CAACA,GAAMC,EAAM,QAAAlB,EAAK5F,EAAO6G,OAE3B,CAAC,EAEL,CAK4EE,CAAgBnD,GAI1F,IAAI6C,OAAOO,OAAOX,GAAgBY,cAAS,GAIpC,OAAAZ,CACT,gBCjCA,SAAsCxF,GAC9B,MAAAuF,SAACA,EAAUxC,QAAAA,GAAW/C,GACtBd,MACJA,EAAAC,OACAA,EAAAsG,SACAA,GAAW,EAAAnD,MACXA,GAAQ,EACR1B,sBAAuByF,GACrBtD,EAEA,GAAA0C,GAA8B,mBAAXtG,EACrB,OACGC,EAAAA,KAAAG,EAAAA,MAAA,CAAMY,QAAS,EAAGX,MAAO,EACxBF,SAAA,CAACF,EAAAA,KAAAW,EAAA,CACCT,SAAA,CAACG,EAAAA,IAAA,OAAA,CAAKH,SAAA,aAAe,kBAAgBG,EAAAA,IAAA,OAAA,CAAKH,SAAA,SAAW,iCACpDG,EAAAA,IAAA,OAAA,CAAKH,SAAA,cAEPgD,GAAU7C,EAAAA,IAAAT,EAAA,CAAME,aAKvB,MAAMoH,EAAchB,EAAc,CAACC,WAAUpG,SAAQsG,aAE/C7E,ECvBR,SACEmC,GAEA,MAAMwD,SAACA,EAAAhB,SAAUA,GAAYxC,GAAW,CAAA,EAExC,OAAKwD,EAEEA,EAAS,CAAChB,aAFK,EAGxB,CDegCiB,CAA6B,CACzDD,SAAUF,EACVd,aAGF,OAAKe,EAaF7G,EAAAA,IAAA4C,EAAA,CACCnD,QACAC,OAAQmH,EACRhE,QACA1B,0BAfCxB,EAAAA,KAAAG,EAAAA,MAAA,CAAMY,QAAS,EAAGX,MAAO,EACxBF,SAAA,CAACG,EAAAA,IAAAM,EAAA,CAAST,SAAA,qHAITgD,GAAU7C,EAAAA,IAAAT,EAAA,CAAME,YAazB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {SanityDocument} from '@sanity/client'
|
|
2
|
+
|
|
3
|
+
declare function DocumentsPane(props: DocumentsPaneProps): JSX.Element
|
|
4
|
+
export default DocumentsPane
|
|
5
|
+
|
|
6
|
+
declare interface DocumentsPaneInitialValueTemplate {
|
|
7
|
+
schemaType: string
|
|
8
|
+
template?: string
|
|
9
|
+
parameters?: {
|
|
10
|
+
[key: string]: any
|
|
11
|
+
}
|
|
12
|
+
title: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare type DocumentsPaneInitialValueTemplateResolver = (params: {
|
|
16
|
+
document: DocumentVersionsCollection
|
|
17
|
+
}) => DocumentsPaneInitialValueTemplate[]
|
|
18
|
+
|
|
19
|
+
declare type DocumentsPaneOptions = {
|
|
20
|
+
query: string
|
|
21
|
+
params?: DocumentsPaneQueryParams
|
|
22
|
+
debug?: boolean
|
|
23
|
+
useDraft?: boolean
|
|
24
|
+
initialValueTemplates?: DocumentsPaneInitialValueTemplateResolver
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare type DocumentsPaneProps = {
|
|
28
|
+
document: DocumentVersionsCollection
|
|
29
|
+
options: DocumentsPaneOptions
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare type DocumentsPaneQueryParams = (params: {document: DocumentVersionsCollection}) =>
|
|
33
|
+
| {
|
|
34
|
+
[key: string]: string
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
[key: string]: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare interface DocumentVersionsCollection {
|
|
41
|
+
displayed: SanityDocument
|
|
42
|
+
published: SanityDocument
|
|
43
|
+
draft: SanityDocument
|
|
44
|
+
historical: SanityDocument
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {}
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-documents-pane",
|
|
3
|
-
"version": "2.0.0-v3-studio.
|
|
3
|
+
"version": "2.0.0-v3-studio.4",
|
|
4
4
|
"description": "Displays the results of a GROQ query in a View Pane",
|
|
5
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
6
|
+
"license": "MIT",
|
|
5
7
|
"source": "./src/index.ts",
|
|
6
8
|
"exports": {
|
|
7
9
|
".": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
+
"types": "./lib/src/index.d.ts",
|
|
11
|
+
"source": "./src/index.ts",
|
|
12
|
+
"import": "./lib/index.esm.js",
|
|
13
|
+
"require": "./lib/index.js",
|
|
14
|
+
"default": "./lib/index.esm.js"
|
|
10
15
|
}
|
|
11
16
|
},
|
|
12
|
-
"main": "./lib/
|
|
13
|
-
"module": "./lib/
|
|
14
|
-
"types": "./lib/
|
|
17
|
+
"main": "./lib/index.js",
|
|
18
|
+
"module": "./lib/index.esm.js",
|
|
19
|
+
"types": "./lib/src/index.d.ts",
|
|
15
20
|
"files": [
|
|
16
21
|
"src",
|
|
17
22
|
"lib",
|
|
@@ -19,13 +24,15 @@
|
|
|
19
24
|
"sanity.json"
|
|
20
25
|
],
|
|
21
26
|
"scripts": {
|
|
22
|
-
"prebuild": "plugin-kit verify-package --silent",
|
|
23
|
-
"build": "
|
|
24
|
-
"watch": "
|
|
27
|
+
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
|
|
28
|
+
"build": "pkg-utils build",
|
|
29
|
+
"watch": "pkg-utils watch",
|
|
25
30
|
"link-watch": "plugin-kit link-watch",
|
|
26
31
|
"lint": "eslint .",
|
|
27
32
|
"prepublishOnly": "npm run compile && npm run build",
|
|
28
|
-
"compile": "tsc --noEmit"
|
|
33
|
+
"compile": "tsc --noEmit",
|
|
34
|
+
"clean": "rimraf lib",
|
|
35
|
+
"prepare": "husky install"
|
|
29
36
|
},
|
|
30
37
|
"engines": {
|
|
31
38
|
"node": ">=14.0.0"
|
|
@@ -37,14 +44,12 @@
|
|
|
37
44
|
},
|
|
38
45
|
"repository": {
|
|
39
46
|
"type": "git",
|
|
40
|
-
"url": "git
|
|
47
|
+
"url": "git@github.com:sanity-io/sanity-plugin-documents-pane.git"
|
|
41
48
|
},
|
|
42
49
|
"keywords": [
|
|
43
50
|
"sanity",
|
|
44
51
|
"sanity-plugin"
|
|
45
52
|
],
|
|
46
|
-
"author": "Sanity.io <hello@sanity.io>",
|
|
47
|
-
"license": "MIT",
|
|
48
53
|
"dependencies": {
|
|
49
54
|
"@sanity/icons": "^1.3.4",
|
|
50
55
|
"@sanity/incompatible-plugin": "^1.0.4",
|
|
@@ -58,40 +63,40 @@
|
|
|
58
63
|
"@sanity/uuid": "^3.0.1",
|
|
59
64
|
"react": "^18.0.0",
|
|
60
65
|
"react-dom": "^18.0.0",
|
|
61
|
-
"sanity": "dev-preview || 3.0.0-
|
|
66
|
+
"sanity": "dev-preview || 3.0.0-rc.0"
|
|
62
67
|
},
|
|
63
68
|
"devDependencies": {
|
|
64
|
-
"@commitlint/cli": "^17.
|
|
65
|
-
"@commitlint/config-conventional": "^17.
|
|
66
|
-
"@parcel/packager-ts": "^2.7.0",
|
|
67
|
-
"@parcel/transformer-typescript-types": "^2.7.0",
|
|
69
|
+
"@commitlint/cli": "^17.2.0",
|
|
70
|
+
"@commitlint/config-conventional": "^17.2.0",
|
|
68
71
|
"@sanity/eslint-config-no-v2-imports": "^0.0.1-studio-v3.3",
|
|
69
|
-
"@sanity/
|
|
70
|
-
"@sanity/
|
|
72
|
+
"@sanity/pkg-utils": "^1.16.2",
|
|
73
|
+
"@sanity/plugin-kit": "^2.0.6",
|
|
74
|
+
"@sanity/semantic-release-preset": "^2.0.2",
|
|
71
75
|
"@sanity/util": "^2.29.5",
|
|
72
76
|
"@sanity/uuid": "^3.0.1",
|
|
73
77
|
"@types/dlv": "^1.1.2",
|
|
74
|
-
"@types/react": "^
|
|
75
|
-
"@types/react-dom": "^
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
77
|
-
"@typescript-eslint/parser": "^5.
|
|
78
|
-
"eslint": "^8.
|
|
78
|
+
"@types/react": "^18.0.0",
|
|
79
|
+
"@types/react-dom": "^18.0.0",
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
81
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
82
|
+
"eslint": "^8.26.0",
|
|
79
83
|
"eslint-config-prettier": "^8.5.0",
|
|
80
84
|
"eslint-config-sanity": "^6.0.0",
|
|
81
85
|
"eslint-plugin-prettier": "^4.2.1",
|
|
86
|
+
"eslint-plugin-react": "^7.31.10",
|
|
87
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
82
88
|
"husky": "^8.0.1",
|
|
83
89
|
"lint-staged": "^13.0.3",
|
|
84
|
-
"parcel": "^2.7.0",
|
|
85
90
|
"pinst": "^3.0.0",
|
|
86
91
|
"prettier": "^2.7.1",
|
|
87
92
|
"react": "^18.0.0",
|
|
88
93
|
"react-dom": "^18.0.0",
|
|
89
|
-
"
|
|
90
|
-
"sanity": "3.0.0-
|
|
91
|
-
"typescript": "4.
|
|
94
|
+
"rimraf": "^3.0.2",
|
|
95
|
+
"sanity": "dev-preview || 3.0.0-rc.0",
|
|
96
|
+
"typescript": "^4.8.4"
|
|
92
97
|
},
|
|
93
98
|
"bugs": {
|
|
94
|
-
"url": "https://github.com/sanity-io/sanity-plugin-
|
|
99
|
+
"url": "https://github.com/sanity-io/sanity-plugin-documents-pane/issues"
|
|
95
100
|
},
|
|
96
|
-
"homepage": "https://github.com/sanity-io/sanity-plugin-
|
|
101
|
+
"homepage": "https://github.com/sanity-io/sanity-plugin-documents-pane#readme"
|
|
97
102
|
}
|
package/src/Documents.tsx
CHANGED
|
@@ -25,7 +25,7 @@ export default function Documents(props: DocumentsProps) {
|
|
|
25
25
|
const {loading, error, data} = useListeningQuery(query, params)
|
|
26
26
|
|
|
27
27
|
const handleClick = useCallback(
|
|
28
|
-
(id, type) => {
|
|
28
|
+
(id: string, type: string) => {
|
|
29
29
|
const childParams = routerPanesState[groupIndex + 1]?.[0].params || {}
|
|
30
30
|
const {parentRefPath} = childParams
|
|
31
31
|
|
|
@@ -34,8 +34,7 @@ export default function Documents(props: DocumentsProps) {
|
|
|
34
34
|
type,
|
|
35
35
|
// Uncertain that this works as intended
|
|
36
36
|
parentRefPath: parentRefPath ? pathFromString(parentRefPath) : [``],
|
|
37
|
-
|
|
38
|
-
template: type,
|
|
37
|
+
template: {id},
|
|
39
38
|
})
|
|
40
39
|
},
|
|
41
40
|
[routerPanesState, groupIndex, handleEditReference]
|
|
@@ -59,7 +59,7 @@ export default function useListeningQuery(
|
|
|
59
59
|
return () => {
|
|
60
60
|
return subscription.current ? subscription.current.unsubscribe() : undefined
|
|
61
61
|
}
|
|
62
|
-
}, [query, params, options])
|
|
62
|
+
}, [query, params, options, documentStore])
|
|
63
63
|
|
|
64
64
|
return {loading, error, data}
|
|
65
65
|
}
|
package/lib/cjs/index.js
DELETED
|
@@ -1,365 +0,0 @@
|
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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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AK,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":"../../"}
|
package/lib/esm/index.js
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import {jsxs as $gGrEF$jsxs, jsx as $gGrEF$jsx, Fragment as $gGrEF$Fragment} from "react/jsx-runtime";
|
|
2
|
-
import {useCallback as $gGrEF$useCallback, useState as $gGrEF$useState, useRef as $gGrEF$useRef, useEffect as $gGrEF$useEffect} from "react";
|
|
3
|
-
import {Stack as $gGrEF$Stack, Box as $gGrEF$Box, Flex as $gGrEF$Flex, Spinner as $gGrEF$Spinner, Button as $gGrEF$Button, Label as $gGrEF$Label, Code as $gGrEF$Code, Card as $gGrEF$Card, Text as $gGrEF$Text} from "@sanity/ui";
|
|
4
|
-
import {fromString as $gGrEF$fromString} from "@sanity/util/paths";
|
|
5
|
-
import {useSchema as $gGrEF$useSchema, SanityPreview as $gGrEF$SanityPreview, useDocumentStore as $gGrEF$useDocumentStore} from "sanity";
|
|
6
|
-
import {usePaneRouter as $gGrEF$usePaneRouter} from "sanity/desk";
|
|
7
|
-
import {distinctUntilChanged as $gGrEF$distinctUntilChanged, catchError as $gGrEF$catchError} from "rxjs/operators";
|
|
8
|
-
import $gGrEF$reactfastcompare from "react-fast-compare";
|
|
9
|
-
import {ComposeIcon as $gGrEF$ComposeIcon} from "@sanity/icons";
|
|
10
|
-
import {uuid as $gGrEF$uuid} from "@sanity/uuid";
|
|
11
|
-
import $gGrEF$dlv from "dlv";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function $7a4dd2fc2cc8e1f5$export$2e2bcd8739ae039({ query: query , params: params }) {
|
|
26
|
-
return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Fragment), {
|
|
27
|
-
children: [
|
|
28
|
-
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
29
|
-
space: 4,
|
|
30
|
-
children: [
|
|
31
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
32
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Label), {
|
|
33
|
-
children: "Query"
|
|
34
|
-
})
|
|
35
|
-
}),
|
|
36
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
37
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Code), {
|
|
38
|
-
children: query
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
]
|
|
42
|
-
}),
|
|
43
|
-
params && /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
44
|
-
space: 4,
|
|
45
|
-
children: [
|
|
46
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
47
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Label), {
|
|
48
|
-
children: "Params"
|
|
49
|
-
})
|
|
50
|
-
}),
|
|
51
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
52
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Code), {
|
|
53
|
-
children: JSON.stringify(params)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
]
|
|
57
|
-
})
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function $60d135b0057fb272$export$2e2bcd8739ae039(props) {
|
|
67
|
-
const { children: children , tone: tone = `caution` } = props;
|
|
68
|
-
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
69
|
-
padding: 3,
|
|
70
|
-
radius: 2,
|
|
71
|
-
shadow: 1,
|
|
72
|
-
tone: tone,
|
|
73
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Text), {
|
|
74
|
-
size: 1,
|
|
75
|
-
children: children
|
|
76
|
-
})
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const $85ac1a186196bda6$var$DEFAULT_PARAMS = {};
|
|
86
|
-
const $85ac1a186196bda6$var$DEFAULT_OPTIONS = {
|
|
87
|
-
apiVersion: `v2022-05-09`
|
|
88
|
-
};
|
|
89
|
-
function $85ac1a186196bda6$export$2e2bcd8739ae039(query, params = $85ac1a186196bda6$var$DEFAULT_PARAMS, options = $85ac1a186196bda6$var$DEFAULT_OPTIONS) {
|
|
90
|
-
const [loading, setLoading] = (0, $gGrEF$useState)(true);
|
|
91
|
-
const [error, setError] = (0, $gGrEF$useState)(false);
|
|
92
|
-
const [data, setData] = (0, $gGrEF$useState)(null);
|
|
93
|
-
const subscription = (0, $gGrEF$useRef)(null);
|
|
94
|
-
const documentStore = (0, $gGrEF$useDocumentStore)();
|
|
95
|
-
(0, $gGrEF$useEffect)(()=>{
|
|
96
|
-
if (query) subscription.current = documentStore.listenQuery(query, params, options).pipe((0, $gGrEF$distinctUntilChanged)((0, $gGrEF$reactfastcompare)), (0, $gGrEF$catchError)((err)=>{
|
|
97
|
-
console.error(err);
|
|
98
|
-
setError(err);
|
|
99
|
-
setLoading(false);
|
|
100
|
-
setData(null);
|
|
101
|
-
return err;
|
|
102
|
-
})).subscribe((documents)=>{
|
|
103
|
-
setData((current)=>(0, $gGrEF$reactfastcompare)(current, documents) ? current : documents);
|
|
104
|
-
setLoading(false);
|
|
105
|
-
setError(false);
|
|
106
|
-
});
|
|
107
|
-
return ()=>{
|
|
108
|
-
return subscription.current ? subscription.current.unsubscribe() : undefined;
|
|
109
|
-
};
|
|
110
|
-
}, [
|
|
111
|
-
query,
|
|
112
|
-
params,
|
|
113
|
-
options
|
|
114
|
-
]);
|
|
115
|
-
return {
|
|
116
|
-
loading: loading,
|
|
117
|
-
error: error,
|
|
118
|
-
data: data
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
function $a08add133c8ba4bc$export$2e2bcd8739ae039(props) {
|
|
130
|
-
const { initialValueTemplates: initialValueTemplates = [] } = props;
|
|
131
|
-
const { ReferenceChildLink: ReferenceChildLink } = (0, $gGrEF$usePaneRouter)();
|
|
132
|
-
if (!initialValueTemplates.length) return null;
|
|
133
|
-
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
134
|
-
borderBottom: true,
|
|
135
|
-
padding: 2,
|
|
136
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Flex), {
|
|
137
|
-
justify: "flex-end",
|
|
138
|
-
gap: 1,
|
|
139
|
-
children: initialValueTemplates.map((template)=>{
|
|
140
|
-
if (!template.template) return null;
|
|
141
|
-
return /*#__PURE__*/ (0, $gGrEF$jsx)(ReferenceChildLink, {
|
|
142
|
-
documentId: (0, $gGrEF$uuid)(),
|
|
143
|
-
documentType: template.schemaType,
|
|
144
|
-
template: {
|
|
145
|
-
id: template.template,
|
|
146
|
-
params: template.parameters
|
|
147
|
-
},
|
|
148
|
-
parentRefPath: [],
|
|
149
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
150
|
-
icon: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$ComposeIcon), {}),
|
|
151
|
-
text: template.title,
|
|
152
|
-
mode: "bleed",
|
|
153
|
-
as: "span"
|
|
154
|
-
})
|
|
155
|
-
}, `${template.schemaType}-${template.template}`);
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
function $1026ba2eafe19170$export$2e2bcd8739ae039(props) {
|
|
163
|
-
const { query: query , params: params , debug: debug , initialValueTemplates: initialValueTemplates } = props;
|
|
164
|
-
const { routerPanesState: routerPanesState , groupIndex: groupIndex , handleEditReference: handleEditReference } = (0, $gGrEF$usePaneRouter)();
|
|
165
|
-
const schema = (0, $gGrEF$useSchema)();
|
|
166
|
-
const { loading: loading , error: error , data: data } = (0, $85ac1a186196bda6$export$2e2bcd8739ae039)(query, params);
|
|
167
|
-
const handleClick = (0, $gGrEF$useCallback)((id, type)=>{
|
|
168
|
-
const childParams = routerPanesState[groupIndex + 1]?.[0].params || {};
|
|
169
|
-
const { parentRefPath: parentRefPath } = childParams;
|
|
170
|
-
handleEditReference({
|
|
171
|
-
id: id,
|
|
172
|
-
type: type,
|
|
173
|
-
// Uncertain that this works as intended
|
|
174
|
-
parentRefPath: parentRefPath ? (0, $gGrEF$fromString)(parentRefPath) : [
|
|
175
|
-
``
|
|
176
|
-
],
|
|
177
|
-
// Added this to satisfy TS
|
|
178
|
-
template: type
|
|
179
|
-
});
|
|
180
|
-
}, [
|
|
181
|
-
routerPanesState,
|
|
182
|
-
groupIndex,
|
|
183
|
-
handleEditReference
|
|
184
|
-
]);
|
|
185
|
-
if (loading) return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
186
|
-
padding: 4,
|
|
187
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Flex), {
|
|
188
|
-
justify: "center",
|
|
189
|
-
align: "center",
|
|
190
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Spinner), {
|
|
191
|
-
muted: true
|
|
192
|
-
})
|
|
193
|
-
})
|
|
194
|
-
});
|
|
195
|
-
if (error) return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
196
|
-
padding: 4,
|
|
197
|
-
space: 5,
|
|
198
|
-
children: [
|
|
199
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $60d135b0057fb272$export$2e2bcd8739ae039), {
|
|
200
|
-
children: "There was en error performing this query"
|
|
201
|
-
}),
|
|
202
|
-
debug && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $7a4dd2fc2cc8e1f5$export$2e2bcd8739ae039), {
|
|
203
|
-
query: query,
|
|
204
|
-
params: params
|
|
205
|
-
})
|
|
206
|
-
]
|
|
207
|
-
});
|
|
208
|
-
if (!data?.length) return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Fragment), {
|
|
209
|
-
children: [
|
|
210
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $a08add133c8ba4bc$export$2e2bcd8739ae039), {
|
|
211
|
-
initialValueTemplates: initialValueTemplates
|
|
212
|
-
}),
|
|
213
|
-
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
214
|
-
padding: 4,
|
|
215
|
-
space: 5,
|
|
216
|
-
children: [
|
|
217
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $60d135b0057fb272$export$2e2bcd8739ae039), {
|
|
218
|
-
children: "No Documents found"
|
|
219
|
-
}),
|
|
220
|
-
debug && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $7a4dd2fc2cc8e1f5$export$2e2bcd8739ae039), {
|
|
221
|
-
query: query,
|
|
222
|
-
params: params
|
|
223
|
-
})
|
|
224
|
-
]
|
|
225
|
-
})
|
|
226
|
-
]
|
|
227
|
-
});
|
|
228
|
-
return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Fragment), {
|
|
229
|
-
children: [
|
|
230
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $a08add133c8ba4bc$export$2e2bcd8739ae039), {
|
|
231
|
-
initialValueTemplates: initialValueTemplates
|
|
232
|
-
}),
|
|
233
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Stack), {
|
|
234
|
-
padding: 2,
|
|
235
|
-
space: 1,
|
|
236
|
-
children: data.map((doc)=>{
|
|
237
|
-
const schemaType = schema.get(doc._type);
|
|
238
|
-
if (!schemaType) return null;
|
|
239
|
-
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
240
|
-
onClick: ()=>handleClick(doc._id, doc._type),
|
|
241
|
-
padding: 2,
|
|
242
|
-
mode: "bleed",
|
|
243
|
-
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$SanityPreview), {
|
|
244
|
-
value: doc,
|
|
245
|
-
schemaType: schemaType
|
|
246
|
-
})
|
|
247
|
-
}, doc._id);
|
|
248
|
-
})
|
|
249
|
-
})
|
|
250
|
-
]
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
function $27973bbf590df0c3$var$defaultResolver(options) {
|
|
259
|
-
const { params: params , document: document , useDraft: useDraft } = options;
|
|
260
|
-
// params is optional
|
|
261
|
-
if (!params) return {};
|
|
262
|
-
// legacy useDraft behaviour
|
|
263
|
-
const doc = useDraft ? document.displayed : document.published;
|
|
264
|
-
return Object.keys(params).reduce((acc, key)=>({
|
|
265
|
-
...acc,
|
|
266
|
-
[key]: (0, $gGrEF$dlv)(doc, params[key])
|
|
267
|
-
}), {});
|
|
268
|
-
}
|
|
269
|
-
function $27973bbf590df0c3$export$2e2bcd8739ae039(options) {
|
|
270
|
-
const { params: params , document: document } = options;
|
|
271
|
-
const resolvedParams = typeof params == "function" ? params({
|
|
272
|
-
document: document
|
|
273
|
-
}) : $27973bbf590df0c3$var$defaultResolver(options);
|
|
274
|
-
// if any of the parameters are undefined, the query will error
|
|
275
|
-
// so return undefined so the UI can show a more appropriate message
|
|
276
|
-
if (Object.values(resolvedParams).includes(undefined)) return undefined;
|
|
277
|
-
// Typescript can't tell that we've guarded against any value being undefined,
|
|
278
|
-
// so forcing the type
|
|
279
|
-
return resolvedParams;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
function $a1930928ca1dda36$export$2e2bcd8739ae039(options) {
|
|
284
|
-
const { resolver: resolver , document: document } = options || {};
|
|
285
|
-
if (!resolver) return [];
|
|
286
|
-
return resolver({
|
|
287
|
-
document: document
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
function $d69d7dc34affefb4$export$2e2bcd8739ae039(props) {
|
|
293
|
-
const { document: document , options: options } = props;
|
|
294
|
-
const { query: query , params: params , useDraft: useDraft = false , debug: debug = false , initialValueTemplates: initialValueTemplatesResolver , } = options;
|
|
295
|
-
if (useDraft && typeof params === "function") return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
296
|
-
padding: 4,
|
|
297
|
-
space: 5,
|
|
298
|
-
children: [
|
|
299
|
-
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $60d135b0057fb272$export$2e2bcd8739ae039), {
|
|
300
|
-
children: [
|
|
301
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)("code", {
|
|
302
|
-
children: "useDraft"
|
|
303
|
-
}),
|
|
304
|
-
" should not be ",
|
|
305
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)("code", {
|
|
306
|
-
children: "true"
|
|
307
|
-
}),
|
|
308
|
-
" when supplying a function for",
|
|
309
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)("code", {
|
|
310
|
-
children: "params"
|
|
311
|
-
})
|
|
312
|
-
]
|
|
313
|
-
}),
|
|
314
|
-
debug && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $7a4dd2fc2cc8e1f5$export$2e2bcd8739ae039), {
|
|
315
|
-
query: query
|
|
316
|
-
})
|
|
317
|
-
]
|
|
318
|
-
});
|
|
319
|
-
const paramValues = (0, $27973bbf590df0c3$export$2e2bcd8739ae039)({
|
|
320
|
-
document: document,
|
|
321
|
-
params: params,
|
|
322
|
-
useDraft: useDraft
|
|
323
|
-
});
|
|
324
|
-
const initialValueTemplates = (0, $a1930928ca1dda36$export$2e2bcd8739ae039)({
|
|
325
|
-
resolver: initialValueTemplatesResolver,
|
|
326
|
-
document: document
|
|
327
|
-
});
|
|
328
|
-
if (!paramValues) return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
329
|
-
padding: 4,
|
|
330
|
-
space: 5,
|
|
331
|
-
children: [
|
|
332
|
-
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $60d135b0057fb272$export$2e2bcd8739ae039), {
|
|
333
|
-
children: "Parameters for this query could not be resolved. This may mean the document does not yet exist or is incomplete."
|
|
334
|
-
}),
|
|
335
|
-
debug && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $7a4dd2fc2cc8e1f5$export$2e2bcd8739ae039), {
|
|
336
|
-
query: query
|
|
337
|
-
})
|
|
338
|
-
]
|
|
339
|
-
});
|
|
340
|
-
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $1026ba2eafe19170$export$2e2bcd8739ae039), {
|
|
341
|
-
query: query,
|
|
342
|
-
params: paramValues,
|
|
343
|
-
debug: debug,
|
|
344
|
-
initialValueTemplates: initialValueTemplates
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
var $df9eabe9bda49ea8$export$2e2bcd8739ae039 = (0, $d69d7dc34affefb4$export$2e2bcd8739ae039);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
export {$df9eabe9bda49ea8$export$2e2bcd8739ae039 as default};
|
|
353
|
-
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;ACAA;;;ACAA;;;;;;ACAA;;;AAGe,kDAAe,SAAC,KAAK,CAAA,UAAE,MAAM,CAAA,EAAoD,EAAE;IAChG,qBACE;;0BACE,iBAAC,CAAA,GAAA,YAAK,CAAA;gBAAC,KAAK,EAAE,CAAC;;kCACb,gBAAC,CAAA,GAAA,UAAG,CAAA;kCACF,cAAA,gBAAC,CAAA,GAAA,YAAK,CAAA;sCAAC,OAAK;0BAAQ;sBAChB;kCACN,gBAAC,CAAA,GAAA,UAAG,CAAA;kCACF,cAAA,gBAAC,CAAA,GAAA,WAAI,CAAA;sCAAE,KAAK;0BAAQ;sBAChB;;cACA;YACP,MAAM,kBACL,iBAAC,CAAA,GAAA,YAAK,CAAA;gBAAC,KAAK,EAAE,CAAC;;kCACb,gBAAC,CAAA,GAAA,UAAG,CAAA;kCACF,cAAA,gBAAC,CAAA,GAAA,YAAK,CAAA;sCAAC,QAAM;0BAAQ;sBACjB;kCACN,gBAAC,CAAA,GAAA,UAAG,CAAA;kCACF,cAAA,gBAAC,CAAA,GAAA,WAAI,CAAA;sCAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;0BAAQ;sBACjC;;cACA,AACT;;MACA,CACJ;CACF;;;AC1BD;;;AASe,kDAAkB,KAAoB,EAAE;IACrD,MAAM,Y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kCAAC,QAAM;sBAAO;;cACV;YACV,KAAK,kBAAI,gBAAC,CAAA,GAAA,wCAAK,CAAA;gBAAC,KAAK,EAAE,KAAK;cAAI;;MAC3B,CACT;IAGH,MAAM,WAAW,GAAG,CAAA,GAAA,wCAAa,CAAA,CAAC;kBAAC,QAAQ;gBAAE,MAAM;kBAAE,QAAQ;KAAC,CAAC;IAE/D,MAAM,qBAAqB,GAAG,CAAA,GAAA,wCAA4B,CAAA,CAAC;QACzD,QAAQ,EAAE,6BAA6B;kBACvC,QAAQ;KACT,CAAC;IAEF,IAAI,CAAC,WAAW,EACd,qBACE,iBAAC,CAAA,GAAA,YAAK,CAAA;QAAC,OAAO,EAAE,CAAC;QAAE,KAAK,EAAE,CAAC;;0BACzB,gBAAC,CAAA,GAAA,wCAAQ,CAAA;0BAAC,kHAGV;cAAW;YACV,KAAK,kBAAI,gBAAC,CAAA,GAAA,wCAAK,CAAA;gBAAC,KAAK,EAAE,KAAK;cAAI;;MAC3B,CACT;IAGH,qBACE,gBAAC,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":"../../"}
|
package/lib/types/index.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { SanityDocument } from "@sanity/client";
|
|
2
|
-
interface DocumentVersionsCollection {
|
|
3
|
-
displayed: SanityDocument;
|
|
4
|
-
published: SanityDocument;
|
|
5
|
-
draft: SanityDocument;
|
|
6
|
-
historical: SanityDocument;
|
|
7
|
-
}
|
|
8
|
-
type DocumentsPaneQueryParams = (params: {
|
|
9
|
-
document: DocumentVersionsCollection;
|
|
10
|
-
}) => ({
|
|
11
|
-
[key: string]: string;
|
|
12
|
-
}) | {
|
|
13
|
-
[key: string]: string;
|
|
14
|
-
};
|
|
15
|
-
interface DocumentsPaneInitialValueTemplate {
|
|
16
|
-
schemaType: string;
|
|
17
|
-
template?: string;
|
|
18
|
-
parameters?: {
|
|
19
|
-
[key: string]: any;
|
|
20
|
-
};
|
|
21
|
-
title: string;
|
|
22
|
-
}
|
|
23
|
-
type DocumentsPaneInitialValueTemplateResolver = (params: {
|
|
24
|
-
document: DocumentVersionsCollection;
|
|
25
|
-
}) => DocumentsPaneInitialValueTemplate[];
|
|
26
|
-
type DocumentsPaneOptions = {
|
|
27
|
-
query: string;
|
|
28
|
-
params?: DocumentsPaneQueryParams;
|
|
29
|
-
debug?: boolean;
|
|
30
|
-
useDraft?: boolean;
|
|
31
|
-
initialValueTemplates?: DocumentsPaneInitialValueTemplateResolver;
|
|
32
|
-
};
|
|
33
|
-
type DocumentsPaneProps = {
|
|
34
|
-
document: DocumentVersionsCollection;
|
|
35
|
-
options: DocumentsPaneOptions;
|
|
36
|
-
};
|
|
37
|
-
declare function DocumentsPane(props: DocumentsPaneProps): JSX.Element;
|
|
38
|
-
export default DocumentsPane;
|
|
39
|
-
|
|
40
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";AGEA;IACE,SAAS,EAAE,cAAc,CAAA;IACzB,SAAS,EAAE,cAAc,CAAA;IACzB,KAAK,EAAE,cAAc,CAAA;IACrB,UAAU,EAAE,cAAc,CAAA;CAC3B;AAGD,gCAAuC,CAAC,MAAM,EAAE;IAAC,QAAQ,EAAE,0BAA0B,CAAA;CAAC,KAAK,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,CAAC,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,CAAA;AAE9I;IACE,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAA;IACjC,KAAK,EAAE,MAAM,CAAA;CACd;AAGD,iDAAwD,CAAC,MAAM,EAAE;IAAC,QAAQ,EAAE,0BAA0B,CAAA;CAAC,KAAK,iCAAiC,EAAE,CAAA;AAE/I,4BAAmC;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,wBAAwB,CAAA;IACjC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,qBAAqB,CAAC,EAAE,yCAAyC,CAAA;CAClE,CAAA;AAED,0BAAiC;IAC/B,QAAQ,EAAE,0BAA0B,CAAA;IACpC,OAAO,EAAE,oBAAoB,CAAA;CAC9B,CAAA;AKvBD,+BAAsC,KAAK,EAAE,kBAAkB,eAiD9D;ACzDD,eAAe,aAAa,CAAA","sources":["src/src/Debug.tsx","src/src/Feedback.tsx","src/src/hooks/useListeningQuery.ts","src/src/types.ts","src/src/NewDocument.tsx","src/src/Documents.tsx","src/src/resolveParams.ts","src/src/resolveInitialValueTemplates.ts","src/src/DocumentsPane.tsx","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"import DocumentsPane from './DocumentsPane'\n\nexport default DocumentsPane\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../"}
|
package/src/parts.d.ts
DELETED