sanity-plugin-taxonomy-manager 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.esm.js CHANGED
@@ -1 +1 @@
1
- import{useFormValue as e,defineType as t,defineField as i,defineArrayMember as n,useClient as o,definePlugin as r}from"sanity";import{jsxs as a,jsx as s,Fragment as c}from"react/jsx-runtime";import{AiFillTags as l,AiOutlineTag as d,AiFillTag as p}from"react-icons/ai";import{Stack as h,Text as u,Flex as m,Spinner as f,Inline as b,Container as y,Box as v}from"@sanity/ui";import{RiNodeTree as g}from"react-icons/ri";import{useState as C,useEffect as T}from"react";var _=t({name:"skosConcept",title:"Concept",type:"document",icon:l,initialValue:async(e,t)=>{var i;const{getClient:n}=t,o=n({apiVersion:"2021-03-25"});return{baseIri:null!=(i=await o.fetch("\n *[_type == 'skosConcept' && defined(baseIri)]| order(_createdAt desc)[0].baseIri\n "))?i:void 0,broader:[],related:[]}},groups:[{name:"label",title:"Labels",default:!0},{name:"relationship",title:"Relationships"},{name:"note",title:"Documentation"}],fields:[i({name:"prefLabel",title:"Preferred Label",group:"label",type:"string",description:"The preferred lexical label for this concept. This label is also used to unambiguously represent this concept via the concept IRI.",components:{input:function(t){var i;const n=e(["baseIri"]);return a(h,{space:2,children:[t.renderDefault(t),s(u,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:a(c,{children:[s("strong",{children:"Concept IRI: "}),n||"[base URI not defined] ",null==(i=t.value)?void 0:i.replaceAll(" ","")]})})]})}},validation:e=>e.required().custom(((e,t)=>{const{getClient:i}=t;return i({apiVersion:"2022-12-14"}).fetch('*[_type == "skosConcept" && prefLabel == "'.concat(e,'" && !(_id in path("drafts.**"))][0]._id')).then((e=>{var i;return!e||e===(null==(i=t.document)?void 0:i._id.replace("drafts.",""))||"Preferred Label must be unique."}))}))}),i({name:"baseIri",title:"Base IRI",type:"url",group:"label",validation:e=>e.required().error("Please supply a base IRI."),description:"The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies.",options:{collapsible:!0}}),i({name:"conceptIriBase",title:"Edit the base IRI",type:"baseIri",group:"label"}),i({name:"altLabel",title:"Alternate Label(s)",group:"label",type:"array",description:"Alternative labels can be used to assign synonyms, near-synonyms, abbreviations, and acronyms to a concept. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),i({name:"hiddenLabel",title:"Hidden Label(s)",group:"label",type:"array",description:"Hidden labels are for character strings that need to be accessible to applications performing text-based indexing and search operations, but not visible otherwise. Hidden labels may for instance be used to include misspelled variants of other lexical labels. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),i({name:"broader",title:"Broader Concept(s)",description:"Broader relationships create a hierarchy between concepts, for example to create category/subcategory, part/whole, or class/instance relationships.",group:"relationship",type:"array",of:[{type:"reference",to:{type:"skosConcept"},options:{filter:e=>{let{document:t}=e;return{filter:'!(_id in $broader || _id in $related || _id in path("drafts.**") || _id == $self)',params:{self:t._id.replace("drafts.",""),broader:t.broader.map((e=>{let{_ref:t}=e;return t})),related:t.related.map((e=>{let{_ref:t}=e;return t}))}}}}}]}),i({name:"related",title:"Related Concept(s)",description:'Associative links between concepts indicate that the two are inherently "related", but that one is not in any way more general than the other. Broader and Associated relationships are mutually exclusive.',group:"relationship",type:"array",of:[{type:"reference",to:[{type:"skosConcept"}]}]}),i({name:"scopeNote",title:"Scope Note",type:"text",description:"A brief statement on the intended meaning of this concept, especially as an indication of how the use of the concept is limited in indexing practice",rows:3,group:"note"}),i({name:"definition",title:"Definition",type:"text",description:"A complete explanation of the intended meaning of the concept",rows:3,group:"note"}),i({name:"example",title:"Examples",type:"text",description:"An example of the use of the concept.",rows:3,group:"note"}),i({name:"topConcept",title:"Top Concept",group:"relationship",type:"boolean",description:a(c,{children:['NOTE: Top Concepts are determined at the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, set Top Concept to "false."',s("br",{}),s("br",{}),"Description: Top concepts provide an efficient entry point to broader/narrower concept hierarchies and/or top level facets. By convention, resources can be a Top Concept, or have Broader relationships, but not both."]}),hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.topConcept)}}),i({name:"scheme",title:"Concept Scheme(s)",group:"relationship",type:"reference",hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.scheme)},description:a(c,{children:["NOTE: Concept Scheme inclusion is are determined from the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",s("br",{}),s("br",{}),"Description: Concept schemes are used to group concepts into defined sets, such as thesauri, classification schemes, or facets."]}),to:[{type:"skosConceptScheme"}],options:{disableNew:!0}})],orderings:[{title:"Top Concepts",name:"topConcept",by:[{field:"topConcept",direction:"desc"},{field:"prefLabel",direction:"asc"}]},{title:"Preferred Label",name:"prefLabel",by:[{field:"prefLabel",direction:"asc"}]}],preview:{select:{title:"prefLabel",topConcept:"topConcept",broader:"broader.0.prefLabel",broaderPlusOne:"broader.0.broader.0.prefLabel",broaderPlusTwo:"broader.0.broader.0.broader.0.prefLabel"},prepare(e){let{title:t,topConcept:i,broader:n,broaderPlusOne:o,broaderPlusTwo:r}=e;const a=[o,n].filter(Boolean),s=a.length>0?"".concat(a.join(" ▷ ")," ▶︎ ").concat(t):"",c=r?"... ".concat(s):s;return{title:t,subtitle:i?"Top Concept":c,media:i?d:p}}}}),R=t({name:"skosConceptScheme",title:"Concept Scheme",type:"document",icon:g,fields:[i({name:"title",title:"Title",type:"string",description:"Taxonomy schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like"}),i({name:"description",title:"Description",type:"text",rows:5,description:"Describe the intended use of this scheme."}),i({name:"topConcepts",title:"Top Concepts",type:"array",validation:e=>e.unique(),of:[n({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}}),i({name:"concepts",title:"Concepts",type:"array",validation:e=>e.unique(),of:[n({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}})],preview:{select:{title:"title"},prepare(e){let{title:t}=e;return{title:t,media:g}}}}),I=t({name:"baseIri",title:"Base IRI",type:"object",description:"NOTE: conceptIriBase.iriValue is deprecated in version 2 of this plugin. Please migrate this value to the baseIri field above. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",hidden:e=>{let{document:t}=e;var i;return!(null==(i=null==t?void 0:t.conceptIriBase)?void 0:i.iriValue)},fields:[i({name:"iriValue",title:"IRI Value",type:"url",description:"Description: The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies."})],options:{collapsible:!0,collapsed:!1}});const z=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return e>6?"":'"childConcepts": *[_id in coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]).concepts[]._ref && ^._id in broader[]._ref ]|order(prefLabel){\n "id": _id,\n "level": '.concat(e,",\n prefLabel,\n ").concat(z(e+1),"\n }")},L=e=>{let{concepts:t}=e;return s("ul",{style:{listStyle:"none"},children:t.map((e=>{var t;return a("li",{style:{fontWeight:"normal",marginTop:".75rem"},children:[e.prefLabel,(null==(t=e.childConcepts)?void 0:t.length)>0&&s(L,{concepts:e.childConcepts})]},e.id)}))})},w=e=>{let{document:t,documentId:i}=e;const n=o({apiVersion:"2021-10-21"}),[r,c]=C([]),[l,d]=C(!0),[p,h]=C(!1),[y,v]=C(!1);return T((()=>{if(void 0===t.displayed._id)return;if(!(i===t.displayed._id.replace(/^drafts\./,"")))return void console.log("document not loaded yet.");(async()=>{d(!0),h(!1),v(!1);try{const e=await n.fetch('coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]) {\n "topConcepts":topConcepts[]->|order(prefLabel){\n "id": _id,\n "level": 0,\n prefLabel,\n '.concat(z(),"\n },\n \"orphans\": *[\n // filter to concepts in this scheme only:\n _id in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref // filter to concepts in this scheme only\n // filter out concepts that reference a topConcept in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).topConcepts[]._ref]) < 1\n // filter out concepts that reference other concepts in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref]) < 1\n ]|order(prefLabel){\n \"id\": _id,\n \"level\": 0,\n prefLabel,\n ").concat(z(),"\n }\n }"),{id:i});null==e.topConcepts&&e.orphans.length<1?h(!0):(d(!1),c(e))}catch(e){console.log("Error: ",e),v(!0)}d(!1)})()}),[i,t.displayed._id,t.displayed.concepts,t.displayed.topConcepts]),1==y?s("p",{children:"Sorry, could not get concepts."}):1==p?s("p",{children:"This scheme does not yet have any concepts assigned to it."}):l?a(m,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},onResize:void 0,onResizeCapture:void 0,children:[s(f,{muted:!0,onResize:void 0,onResizeCapture:void 0}),s(u,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:"Loading hierarchy…"})]}):a("ul",{style:{listStyle:"none",paddingLeft:"0",marginTop:"1rem"},children:[r.topConcepts&&r.topConcepts.map((e=>{if(null==e?void 0:e.id)return a("li",{style:{paddingTop:".5rem",fontWeight:"bold",marginTop:".75rem"},children:[a(b,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,s(u,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"top concept"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&s(L,{concepts:e.childConcepts})]},e.id)})),r.orphans.map((e=>{var t;return a("li",{style:{paddingTop:".5rem",fontWeight:"normal",marginTop:".75rem"},children:[a(b,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,(null==(t=r.topConcept)?void 0:t.length)>0&&s(u,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"orphan"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&s(L,{concepts:e.childConcepts})]},e.id)}))]})},x=e=>{let{document:t,documentId:i}=e;return s(y,{width:1,style:{paddingTop:"1.25rem"},onResize:void 0,onResizeCapture:void 0,children:s(v,{padding:4,onResize:void 0,onResizeCapture:void 0,children:a(h,{space:2,children:[s(u,{size:1,weight:"semibold",onResize:void 0,onResizeCapture:void 0,children:"Hierarchy Tree"}),s(u,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"Concept hierarchy is determined by 'Broader' relationships assigned to each concept."}),s(w,{document:t,documentId:i})]})})})},P=r({name:"taxonomyManager",schema:{types:[_,R,I]}});export{x as TreeView,P as taxonomyManager};//# sourceMappingURL=index.esm.js.map
1
+ import{useFormValue as e,defineType as t,defineField as i,defineArrayMember as n,useClient as o,definePlugin as r}from"sanity";import{jsxs as a,jsx as s,Fragment as l}from"react/jsx-runtime";import{AiFillTags as c,AiFillTag as d}from"react-icons/ai";import{Stack as p,Text as h,Flex as u,Spinner as m,Inline as f,Container as b,Box as y}from"@sanity/ui";import{RiNodeTree as v}from"react-icons/ri";import{useState as g,useEffect as C}from"react";var _=t({name:"skosConcept",title:"Concept",type:"document",icon:c,initialValue:async(e,t)=>{var i;const{getClient:n}=t,o=n({apiVersion:"2021-03-25"});return{baseIri:null!=(i=await o.fetch("\n *[_type == 'skosConcept' && defined(baseIri)]| order(_createdAt desc)[0].baseIri\n "))?i:void 0,broader:[],related:[]}},groups:[{name:"label",title:"Labels",default:!0},{name:"relationship",title:"Relationships"},{name:"note",title:"Documentation"}],fields:[i({name:"prefLabel",title:"Preferred Label",group:"label",type:"string",description:"The preferred lexical label for this concept. This label is also used to unambiguously represent this concept via the concept IRI.",components:{input:function(t){var i;const n=e(["baseIri"]);return a(p,{space:2,children:[t.renderDefault(t),s(h,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:a(l,{children:[s("strong",{children:"Concept IRI: "}),n||"[base URI not defined] ",null==(i=t.value)?void 0:i.replaceAll(" ","")]})})]})}},validation:e=>e.required().custom(((e,t)=>{const{getClient:i}=t;return i({apiVersion:"2022-12-14"}).fetch('*[_type == "skosConcept" && prefLabel == "'.concat(e,'" && !(_id in path("drafts.**"))][0]._id')).then((e=>{var i;return!e||e===(null==(i=t.document)?void 0:i._id.replace("drafts.",""))||"Preferred Label must be unique."}))}))}),i({name:"baseIri",title:"Base IRI",type:"url",group:"label",validation:e=>e.required().error("Please supply a base IRI."),description:"The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies.",options:{collapsible:!0}}),i({name:"conceptIriBase",title:"Edit the base IRI",type:"baseIri",group:"label"}),i({name:"altLabel",title:"Alternate Label(s)",group:"label",type:"array",description:"Alternative labels can be used to assign synonyms, near-synonyms, abbreviations, and acronyms to a concept. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),i({name:"hiddenLabel",title:"Hidden Label(s)",group:"label",type:"array",description:"Hidden labels are for character strings that need to be accessible to applications performing text-based indexing and search operations, but not visible otherwise. Hidden labels may for instance be used to include misspelled variants of other lexical labels. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),i({name:"broader",title:"Broader Concept(s)",description:"Broader relationships create a hierarchy between concepts, for example to create category/subcategory, part/whole, or class/instance relationships.",group:"relationship",type:"array",of:[{type:"reference",to:{type:"skosConcept"},options:{filter:e=>{let{document:t}=e;return{filter:'!(_id in $broader || _id in $related || _id in path("drafts.**") || _id == $self)',params:{self:t._id.replace("drafts.",""),broader:t.broader.map((e=>{let{_ref:t}=e;return t})),related:t.related.map((e=>{let{_ref:t}=e;return t}))}}}}}]}),i({name:"related",title:"Related Concept(s)",description:'Associative links between concepts indicate that the two are inherently "related", but that one is not in any way more general than the other. Broader and Associated relationships are mutually exclusive.',group:"relationship",type:"array",of:[{type:"reference",to:[{type:"skosConcept"}]}]}),i({name:"scopeNote",title:"Scope Note",type:"text",description:"A brief statement on the intended meaning of this concept, especially as an indication of how the use of the concept is limited in indexing practice",rows:3,group:"note"}),i({name:"definition",title:"Definition",type:"text",description:"A complete explanation of the intended meaning of the concept",rows:3,group:"note"}),i({name:"example",title:"Examples",type:"text",description:"An example of the use of the concept.",rows:3,group:"note"}),i({name:"topConcept",title:"Top Concept",group:"relationship",type:"boolean",description:a(l,{children:['NOTE: Top Concepts are determined at the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, set Top Concept to "false."',s("br",{}),s("br",{}),"Description: Top concepts provide an efficient entry point to broader/narrower concept hierarchies and/or top level facets. By convention, resources can be a Top Concept, or have Broader relationships, but not both."]}),hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.topConcept)}}),i({name:"scheme",title:"Concept Scheme(s)",group:"relationship",type:"reference",hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.scheme)},description:a(l,{children:["NOTE: Concept Scheme inclusion is are determined from the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",s("br",{}),s("br",{}),"Description: Concept schemes are used to group concepts into defined sets, such as thesauri, classification schemes, or facets."]}),to:[{type:"skosConceptScheme"}],options:{disableNew:!0}})],orderings:[{title:"Top Concepts",name:"topConcept",by:[{field:"topConcept",direction:"desc"},{field:"prefLabel",direction:"asc"}]},{title:"Preferred Label",name:"prefLabel",by:[{field:"prefLabel",direction:"asc"}]}],preview:{select:{title:"prefLabel",broader0:"broader.0.prefLabel",broader1:"broader.1.prefLabel",broader2:"broader.2.prefLabel"},prepare(e){let{title:t,broader0:i,broader1:n,broader2:o}=e;const r=[i,n].filter(Boolean).join(", ")+(Boolean(o)?" ...":"");return{title:t,subtitle:i?"in "+r:r,media:d}}}}),R=t({name:"skosConceptScheme",title:"Concept Scheme",type:"document",icon:v,fields:[i({name:"title",title:"Title",type:"string",description:"Taxonomy schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like"}),i({name:"description",title:"Description",type:"text",rows:5,description:"Describe the intended use of this scheme."}),i({name:"topConcepts",title:"Top Concepts",type:"array",validation:e=>e.unique(),of:[n({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}}),i({name:"concepts",title:"Concepts",type:"array",validation:e=>e.unique(),of:[n({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}})],preview:{select:{title:"title"},prepare(e){let{title:t}=e;return{title:t,media:v}}}}),T=t({name:"baseIri",title:"Base IRI",type:"object",description:"NOTE: conceptIriBase.iriValue is deprecated in version 2 of this plugin. Please migrate this value to the baseIri field above. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",hidden:e=>{let{document:t}=e;var i;return!(null==(i=null==t?void 0:t.conceptIriBase)?void 0:i.iriValue)},fields:[i({name:"iriValue",title:"IRI Value",type:"url",description:"Description: The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies."})],options:{collapsible:!0,collapsed:!1}});const I=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return e>6?"":'"childConcepts": *[_id in coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]).concepts[]._ref && ^._id in broader[]._ref ]|order(prefLabel){\n "id": _id,\n "level": '.concat(e,",\n prefLabel,\n ").concat(I(e+1),"\n }")},z=e=>{let{concepts:t}=e;return s("ul",{style:{listStyle:"none"},children:t.map((e=>{var t;return a("li",{style:{fontWeight:"normal",marginTop:".75rem"},children:[e.prefLabel,(null==(t=e.childConcepts)?void 0:t.length)>0&&s(z,{concepts:e.childConcepts})]},e.id)}))})},L=e=>{let{document:t,documentId:i}=e;const n=o({apiVersion:"2021-10-21"}),[r,l]=g([]),[c,d]=g(!0),[p,b]=g(!1),[y,v]=g(!1);return C((()=>{if(void 0===t.displayed._id)return;if(!(i===t.displayed._id.replace(/^drafts\./,"")))return void console.log("document not loaded yet.");(async()=>{d(!0),b(!1),v(!1);try{const e=await n.fetch('coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]) {\n "topConcepts":topConcepts[]->|order(prefLabel){\n "id": _id,\n "level": 0,\n prefLabel,\n '.concat(I(),"\n },\n \"orphans\": *[\n // filter to concepts in this scheme only:\n _id in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref // filter to concepts in this scheme only\n // filter out concepts that reference a topConcept in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).topConcepts[]._ref]) < 1\n // filter out concepts that reference other concepts in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref]) < 1\n ]|order(prefLabel){\n \"id\": _id,\n \"level\": 0,\n prefLabel,\n ").concat(I(),"\n }\n }"),{id:i});null==e.topConcepts&&e.orphans.length<1?b(!0):(d(!1),l(e))}catch(e){console.log("Error: ",e),v(!0)}d(!1)})()}),[i,t.displayed._id,t.displayed.concepts,t.displayed.topConcepts]),1==y?s("p",{children:"Sorry, could not get concepts."}):1==p?s("p",{children:"This scheme does not yet have any concepts assigned to it."}):c?a(u,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},onResize:void 0,onResizeCapture:void 0,children:[s(m,{muted:!0,onResize:void 0,onResizeCapture:void 0}),s(h,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:"Loading hierarchy…"})]}):a("ul",{style:{listStyle:"none",paddingLeft:"0",marginTop:"1rem"},children:[r.topConcepts&&r.topConcepts.map((e=>{if(null==e?void 0:e.id)return a("li",{style:{paddingTop:".5rem",fontWeight:"bold",marginTop:".75rem"},children:[a(f,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,s(h,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"top concept"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&s(z,{concepts:e.childConcepts})]},e.id)})),r.orphans.map((e=>{var t;return a("li",{style:{paddingTop:".5rem",fontWeight:"normal",marginTop:".75rem"},children:[a(f,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,(null==(t=r.topConcept)?void 0:t.length)>0&&s(h,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"orphan"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&s(z,{concepts:e.childConcepts})]},e.id)}))]})},w=e=>{let{document:t,documentId:i}=e;return s(b,{width:1,style:{paddingTop:"1.25rem"},onResize:void 0,onResizeCapture:void 0,children:s(y,{padding:4,onResize:void 0,onResizeCapture:void 0,children:a(p,{space:2,children:[s(h,{size:1,weight:"semibold",onResize:void 0,onResizeCapture:void 0,children:"Hierarchy Tree"}),s(h,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"Concept hierarchy is determined by 'Broader' relationships assigned to each concept."}),s(L,{document:t,documentId:i})]})})})},x=r({name:"taxonomyManager",schema:{types:[_,R,T]}});export{w as TreeView,x as taxonomyManager};//# sourceMappingURL=index.esm.js.map
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("sanity"),t=require("react/jsx-runtime"),i=require("react-icons/ai"),n=require("@sanity/ui"),o=require("react-icons/ri"),r=require("react");var s=e.defineType({name:"skosConcept",title:"Concept",type:"document",icon:i.AiFillTags,initialValue:async(e,t)=>{var i;const{getClient:n}=t,o=n({apiVersion:"2021-03-25"});return{baseIri:null!=(i=await o.fetch("\n *[_type == 'skosConcept' && defined(baseIri)]| order(_createdAt desc)[0].baseIri\n "))?i:void 0,broader:[],related:[]}},groups:[{name:"label",title:"Labels",default:!0},{name:"relationship",title:"Relationships"},{name:"note",title:"Documentation"}],fields:[e.defineField({name:"prefLabel",title:"Preferred Label",group:"label",type:"string",description:"The preferred lexical label for this concept. This label is also used to unambiguously represent this concept via the concept IRI.",components:{input:function(i){var o;const r=e.useFormValue(["baseIri"]);return t.jsxs(n.Stack,{space:2,children:[i.renderDefault(i),t.jsx(n.Text,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:t.jsxs(t.Fragment,{children:[t.jsx("strong",{children:"Concept IRI: "}),r||"[base URI not defined] ",null==(o=i.value)?void 0:o.replaceAll(" ","")]})})]})}},validation:e=>e.required().custom(((e,t)=>{const{getClient:i}=t;return i({apiVersion:"2022-12-14"}).fetch('*[_type == "skosConcept" && prefLabel == "'.concat(e,'" && !(_id in path("drafts.**"))][0]._id')).then((e=>{var i;return!e||e===(null==(i=t.document)?void 0:i._id.replace("drafts.",""))||"Preferred Label must be unique."}))}))}),e.defineField({name:"baseIri",title:"Base IRI",type:"url",group:"label",validation:e=>e.required().error("Please supply a base IRI."),description:"The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies.",options:{collapsible:!0}}),e.defineField({name:"conceptIriBase",title:"Edit the base IRI",type:"baseIri",group:"label"}),e.defineField({name:"altLabel",title:"Alternate Label(s)",group:"label",type:"array",description:"Alternative labels can be used to assign synonyms, near-synonyms, abbreviations, and acronyms to a concept. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),e.defineField({name:"hiddenLabel",title:"Hidden Label(s)",group:"label",type:"array",description:"Hidden labels are for character strings that need to be accessible to applications performing text-based indexing and search operations, but not visible otherwise. Hidden labels may for instance be used to include misspelled variants of other lexical labels. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),e.defineField({name:"broader",title:"Broader Concept(s)",description:"Broader relationships create a hierarchy between concepts, for example to create category/subcategory, part/whole, or class/instance relationships.",group:"relationship",type:"array",of:[{type:"reference",to:{type:"skosConcept"},options:{filter:e=>{let{document:t}=e;return{filter:'!(_id in $broader || _id in $related || _id in path("drafts.**") || _id == $self)',params:{self:t._id.replace("drafts.",""),broader:t.broader.map((e=>{let{_ref:t}=e;return t})),related:t.related.map((e=>{let{_ref:t}=e;return t}))}}}}}]}),e.defineField({name:"related",title:"Related Concept(s)",description:'Associative links between concepts indicate that the two are inherently "related", but that one is not in any way more general than the other. Broader and Associated relationships are mutually exclusive.',group:"relationship",type:"array",of:[{type:"reference",to:[{type:"skosConcept"}]}]}),e.defineField({name:"scopeNote",title:"Scope Note",type:"text",description:"A brief statement on the intended meaning of this concept, especially as an indication of how the use of the concept is limited in indexing practice",rows:3,group:"note"}),e.defineField({name:"definition",title:"Definition",type:"text",description:"A complete explanation of the intended meaning of the concept",rows:3,group:"note"}),e.defineField({name:"example",title:"Examples",type:"text",description:"An example of the use of the concept.",rows:3,group:"note"}),e.defineField({name:"topConcept",title:"Top Concept",group:"relationship",type:"boolean",description:t.jsxs(t.Fragment,{children:['NOTE: Top Concepts are determined at the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, set Top Concept to "false."',t.jsx("br",{}),t.jsx("br",{}),"Description: Top concepts provide an efficient entry point to broader/narrower concept hierarchies and/or top level facets. By convention, resources can be a Top Concept, or have Broader relationships, but not both."]}),hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.topConcept)}}),e.defineField({name:"scheme",title:"Concept Scheme(s)",group:"relationship",type:"reference",hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.scheme)},description:t.jsxs(t.Fragment,{children:["NOTE: Concept Scheme inclusion is are determined from the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",t.jsx("br",{}),t.jsx("br",{}),"Description: Concept schemes are used to group concepts into defined sets, such as thesauri, classification schemes, or facets."]}),to:[{type:"skosConceptScheme"}],options:{disableNew:!0}})],orderings:[{title:"Top Concepts",name:"topConcept",by:[{field:"topConcept",direction:"desc"},{field:"prefLabel",direction:"asc"}]},{title:"Preferred Label",name:"prefLabel",by:[{field:"prefLabel",direction:"asc"}]}],preview:{select:{title:"prefLabel",topConcept:"topConcept",broader:"broader.0.prefLabel",broaderPlusOne:"broader.0.broader.0.prefLabel",broaderPlusTwo:"broader.0.broader.0.broader.0.prefLabel"},prepare(e){let{title:t,topConcept:n,broader:o,broaderPlusOne:r,broaderPlusTwo:s}=e;const a=[r,o].filter(Boolean),l=a.length>0?"".concat(a.join(" ▷ ")," ▶︎ ").concat(t):"",d=s?"... ".concat(l):l;return{title:t,subtitle:n?"Top Concept":d,media:n?i.AiOutlineTag:i.AiFillTag}}}}),a=e.defineType({name:"skosConceptScheme",title:"Concept Scheme",type:"document",icon:o.RiNodeTree,fields:[e.defineField({name:"title",title:"Title",type:"string",description:"Taxonomy schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like"}),e.defineField({name:"description",title:"Description",type:"text",rows:5,description:"Describe the intended use of this scheme."}),e.defineField({name:"topConcepts",title:"Top Concepts",type:"array",validation:e=>e.unique(),of:[e.defineArrayMember({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}}),e.defineField({name:"concepts",title:"Concepts",type:"array",validation:e=>e.unique(),of:[e.defineArrayMember({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}})],preview:{select:{title:"title"},prepare(e){let{title:t}=e;return{title:t,media:o.RiNodeTree}}}}),l=e.defineType({name:"baseIri",title:"Base IRI",type:"object",description:"NOTE: conceptIriBase.iriValue is deprecated in version 2 of this plugin. Please migrate this value to the baseIri field above. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",hidden:e=>{let{document:t}=e;var i;return!(null==(i=null==t?void 0:t.conceptIriBase)?void 0:i.iriValue)},fields:[e.defineField({name:"iriValue",title:"IRI Value",type:"url",description:"Description: The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies."})],options:{collapsible:!0,collapsed:!1}});const d=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return e>6?"":'"childConcepts": *[_id in coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]).concepts[]._ref && ^._id in broader[]._ref ]|order(prefLabel){\n "id": _id,\n "level": '.concat(e,",\n prefLabel,\n ").concat(d(e+1),"\n }")},c=e=>{let{concepts:i}=e;return t.jsx("ul",{style:{listStyle:"none"},children:i.map((e=>{var i;return t.jsxs("li",{style:{fontWeight:"normal",marginTop:".75rem"},children:[e.prefLabel,(null==(i=e.childConcepts)?void 0:i.length)>0&&t.jsx(c,{concepts:e.childConcepts})]},e.id)}))})},p=i=>{let{document:o,documentId:s}=i;const a=e.useClient({apiVersion:"2021-10-21"}),[l,p]=r.useState([]),[u,h]=r.useState(!0),[f,m]=r.useState(!1),[b,y]=r.useState(!1);return r.useEffect((()=>{if(void 0===o.displayed._id)return;if(!(s===o.displayed._id.replace(/^drafts\./,"")))return void console.log("document not loaded yet.");(async()=>{h(!0),m(!1),y(!1);try{const e=await a.fetch('coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]) {\n "topConcepts":topConcepts[]->|order(prefLabel){\n "id": _id,\n "level": 0,\n prefLabel,\n '.concat(d(),"\n },\n \"orphans\": *[\n // filter to concepts in this scheme only:\n _id in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref // filter to concepts in this scheme only\n // filter out concepts that reference a topConcept in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).topConcepts[]._ref]) < 1\n // filter out concepts that reference other concepts in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref]) < 1\n ]|order(prefLabel){\n \"id\": _id,\n \"level\": 0,\n prefLabel,\n ").concat(d(),"\n }\n }"),{id:s});null==e.topConcepts&&e.orphans.length<1?m(!0):(h(!1),p(e))}catch(e){console.log("Error: ",e),y(!0)}h(!1)})()}),[s,o.displayed._id,o.displayed.concepts,o.displayed.topConcepts]),1==b?t.jsx("p",{children:"Sorry, could not get concepts."}):1==f?t.jsx("p",{children:"This scheme does not yet have any concepts assigned to it."}):u?t.jsxs(n.Flex,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},onResize:void 0,onResizeCapture:void 0,children:[t.jsx(n.Spinner,{muted:!0,onResize:void 0,onResizeCapture:void 0}),t.jsx(n.Text,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:"Loading hierarchy…"})]}):t.jsxs("ul",{style:{listStyle:"none",paddingLeft:"0",marginTop:"1rem"},children:[l.topConcepts&&l.topConcepts.map((e=>{if(null==e?void 0:e.id)return t.jsxs("li",{style:{paddingTop:".5rem",fontWeight:"bold",marginTop:".75rem"},children:[t.jsxs(n.Inline,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,t.jsx(n.Text,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"top concept"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&t.jsx(c,{concepts:e.childConcepts})]},e.id)})),l.orphans.map((e=>{var i;return t.jsxs("li",{style:{paddingTop:".5rem",fontWeight:"normal",marginTop:".75rem"},children:[t.jsxs(n.Inline,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,(null==(i=l.topConcept)?void 0:i.length)>0&&t.jsx(n.Text,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"orphan"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&t.jsx(c,{concepts:e.childConcepts})]},e.id)}))]})},u=e.definePlugin({name:"taxonomyManager",schema:{types:[s,a,l]}});exports.TreeView=e=>{let{document:i,documentId:o}=e;return t.jsx(n.Container,{width:1,style:{paddingTop:"1.25rem"},onResize:void 0,onResizeCapture:void 0,children:t.jsx(n.Box,{padding:4,onResize:void 0,onResizeCapture:void 0,children:t.jsxs(n.Stack,{space:2,children:[t.jsx(n.Text,{size:1,weight:"semibold",onResize:void 0,onResizeCapture:void 0,children:"Hierarchy Tree"}),t.jsx(n.Text,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"Concept hierarchy is determined by 'Broader' relationships assigned to each concept."}),t.jsx(p,{document:i,documentId:o})]})})})},exports.taxonomyManager=u;//# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("sanity"),t=require("react/jsx-runtime"),i=require("react-icons/ai"),n=require("@sanity/ui"),o=require("react-icons/ri"),r=require("react");var s=e.defineType({name:"skosConcept",title:"Concept",type:"document",icon:i.AiFillTags,initialValue:async(e,t)=>{var i;const{getClient:n}=t,o=n({apiVersion:"2021-03-25"});return{baseIri:null!=(i=await o.fetch("\n *[_type == 'skosConcept' && defined(baseIri)]| order(_createdAt desc)[0].baseIri\n "))?i:void 0,broader:[],related:[]}},groups:[{name:"label",title:"Labels",default:!0},{name:"relationship",title:"Relationships"},{name:"note",title:"Documentation"}],fields:[e.defineField({name:"prefLabel",title:"Preferred Label",group:"label",type:"string",description:"The preferred lexical label for this concept. This label is also used to unambiguously represent this concept via the concept IRI.",components:{input:function(i){var o;const r=e.useFormValue(["baseIri"]);return t.jsxs(n.Stack,{space:2,children:[i.renderDefault(i),t.jsx(n.Text,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:t.jsxs(t.Fragment,{children:[t.jsx("strong",{children:"Concept IRI: "}),r||"[base URI not defined] ",null==(o=i.value)?void 0:o.replaceAll(" ","")]})})]})}},validation:e=>e.required().custom(((e,t)=>{const{getClient:i}=t;return i({apiVersion:"2022-12-14"}).fetch('*[_type == "skosConcept" && prefLabel == "'.concat(e,'" && !(_id in path("drafts.**"))][0]._id')).then((e=>{var i;return!e||e===(null==(i=t.document)?void 0:i._id.replace("drafts.",""))||"Preferred Label must be unique."}))}))}),e.defineField({name:"baseIri",title:"Base IRI",type:"url",group:"label",validation:e=>e.required().error("Please supply a base IRI."),description:"The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies.",options:{collapsible:!0}}),e.defineField({name:"conceptIriBase",title:"Edit the base IRI",type:"baseIri",group:"label"}),e.defineField({name:"altLabel",title:"Alternate Label(s)",group:"label",type:"array",description:"Alternative labels can be used to assign synonyms, near-synonyms, abbreviations, and acronyms to a concept. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),e.defineField({name:"hiddenLabel",title:"Hidden Label(s)",group:"label",type:"array",description:"Hidden labels are for character strings that need to be accessible to applications performing text-based indexing and search operations, but not visible otherwise. Hidden labels may for instance be used to include misspelled variants of other lexical labels. Preferred, alternative, and hidden label sets must not overlap.",of:[{type:"string"}],validation:e=>e.unique()}),e.defineField({name:"broader",title:"Broader Concept(s)",description:"Broader relationships create a hierarchy between concepts, for example to create category/subcategory, part/whole, or class/instance relationships.",group:"relationship",type:"array",of:[{type:"reference",to:{type:"skosConcept"},options:{filter:e=>{let{document:t}=e;return{filter:'!(_id in $broader || _id in $related || _id in path("drafts.**") || _id == $self)',params:{self:t._id.replace("drafts.",""),broader:t.broader.map((e=>{let{_ref:t}=e;return t})),related:t.related.map((e=>{let{_ref:t}=e;return t}))}}}}}]}),e.defineField({name:"related",title:"Related Concept(s)",description:'Associative links between concepts indicate that the two are inherently "related", but that one is not in any way more general than the other. Broader and Associated relationships are mutually exclusive.',group:"relationship",type:"array",of:[{type:"reference",to:[{type:"skosConcept"}]}]}),e.defineField({name:"scopeNote",title:"Scope Note",type:"text",description:"A brief statement on the intended meaning of this concept, especially as an indication of how the use of the concept is limited in indexing practice",rows:3,group:"note"}),e.defineField({name:"definition",title:"Definition",type:"text",description:"A complete explanation of the intended meaning of the concept",rows:3,group:"note"}),e.defineField({name:"example",title:"Examples",type:"text",description:"An example of the use of the concept.",rows:3,group:"note"}),e.defineField({name:"topConcept",title:"Top Concept",group:"relationship",type:"boolean",description:t.jsxs(t.Fragment,{children:['NOTE: Top Concepts are determined at the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, set Top Concept to "false."',t.jsx("br",{}),t.jsx("br",{}),"Description: Top concepts provide an efficient entry point to broader/narrower concept hierarchies and/or top level facets. By convention, resources can be a Top Concept, or have Broader relationships, but not both."]}),hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.topConcept)}}),e.defineField({name:"scheme",title:"Concept Scheme(s)",group:"relationship",type:"reference",hidden:e=>{let{document:t}=e;return!(null==t?void 0:t.scheme)},description:t.jsxs(t.Fragment,{children:["NOTE: Concept Scheme inclusion is are determined from the Concept Scheme for version 2 of this plugin. Please migrate this value accordingly. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",t.jsx("br",{}),t.jsx("br",{}),"Description: Concept schemes are used to group concepts into defined sets, such as thesauri, classification schemes, or facets."]}),to:[{type:"skosConceptScheme"}],options:{disableNew:!0}})],orderings:[{title:"Top Concepts",name:"topConcept",by:[{field:"topConcept",direction:"desc"},{field:"prefLabel",direction:"asc"}]},{title:"Preferred Label",name:"prefLabel",by:[{field:"prefLabel",direction:"asc"}]}],preview:{select:{title:"prefLabel",broader0:"broader.0.prefLabel",broader1:"broader.1.prefLabel",broader2:"broader.2.prefLabel"},prepare(e){let{title:t,broader0:n,broader1:o,broader2:r}=e;const s=[n,o].filter(Boolean).join(", ")+(Boolean(r)?" ...":"");return{title:t,subtitle:n?"in "+s:s,media:i.AiFillTag}}}}),a=e.defineType({name:"skosConceptScheme",title:"Concept Scheme",type:"document",icon:o.RiNodeTree,fields:[e.defineField({name:"title",title:"Title",type:"string",description:"Taxonomy schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like"}),e.defineField({name:"description",title:"Description",type:"text",rows:5,description:"Describe the intended use of this scheme."}),e.defineField({name:"topConcepts",title:"Top Concepts",type:"array",validation:e=>e.unique(),of:[e.defineArrayMember({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}}),e.defineField({name:"concepts",title:"Concepts",type:"array",validation:e=>e.unique(),of:[e.defineArrayMember({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}})],preview:{select:{title:"title"},prepare(e){let{title:t}=e;return{title:t,media:o.RiNodeTree}}}}),l=e.defineType({name:"baseIri",title:"Base IRI",type:"object",description:"NOTE: conceptIriBase.iriValue is deprecated in version 2 of this plugin. Please migrate this value to the baseIri field above. This field will be removed in future versions of this plugin. To hide it in the meantime, unset this value (delete it).",hidden:e=>{let{document:t}=e;var i;return!(null==(i=null==t?void 0:t.conceptIriBase)?void 0:i.iriValue)},fields:[e.defineField({name:"iriValue",title:"IRI Value",type:"url",description:"Description: The W3C encourages the use of HTTP URIs when minting concept URIs since they are resolvable to representations that can be accessed using standard Web technologies."})],options:{collapsible:!0,collapsed:!1}});const d=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return e>6?"":'"childConcepts": *[_id in coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]).concepts[]._ref && ^._id in broader[]._ref ]|order(prefLabel){\n "id": _id,\n "level": '.concat(e,",\n prefLabel,\n ").concat(d(e+1),"\n }")},c=e=>{let{concepts:i}=e;return t.jsx("ul",{style:{listStyle:"none"},children:i.map((e=>{var i;return t.jsxs("li",{style:{fontWeight:"normal",marginTop:".75rem"},children:[e.prefLabel,(null==(i=e.childConcepts)?void 0:i.length)>0&&t.jsx(c,{concepts:e.childConcepts})]},e.id)}))})},p=i=>{let{document:o,documentId:s}=i;const a=e.useClient({apiVersion:"2021-10-21"}),[l,p]=r.useState([]),[u,h]=r.useState(!0),[f,m]=r.useState(!1),[b,y]=r.useState(!1);return r.useEffect((()=>{if(void 0===o.displayed._id)return;if(!(s===o.displayed._id.replace(/^drafts\./,"")))return void console.log("document not loaded yet.");(async()=>{h(!0),m(!1),y(!1);try{const e=await a.fetch('coalesce(*[_id == \'drafts.\' + $id][0], *[_id == $id][0]) {\n "topConcepts":topConcepts[]->|order(prefLabel){\n "id": _id,\n "level": 0,\n prefLabel,\n '.concat(d(),"\n },\n \"orphans\": *[\n // filter to concepts in this scheme only:\n _id in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref // filter to concepts in this scheme only\n // filter out concepts that reference a topConcept in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).topConcepts[]._ref]) < 1\n // filter out concepts that reference other concepts in this scheme as a broader term:\n && count((broader[]._ref) [@ in coalesce(*[_id == 'drafts.' + $id][0], *[_id == $id][0]).concepts[]._ref]) < 1\n ]|order(prefLabel){\n \"id\": _id,\n \"level\": 0,\n prefLabel,\n ").concat(d(),"\n }\n }"),{id:s});null==e.topConcepts&&e.orphans.length<1?m(!0):(h(!1),p(e))}catch(e){console.log("Error: ",e),y(!0)}h(!1)})()}),[s,o.displayed._id,o.displayed.concepts,o.displayed.topConcepts]),1==b?t.jsx("p",{children:"Sorry, could not get concepts."}):1==f?t.jsx("p",{children:"This scheme does not yet have any concepts assigned to it."}):u?t.jsxs(n.Flex,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},onResize:void 0,onResizeCapture:void 0,children:[t.jsx(n.Spinner,{muted:!0,onResize:void 0,onResizeCapture:void 0}),t.jsx(n.Text,{muted:!0,size:1,onResize:void 0,onResizeCapture:void 0,children:"Loading hierarchy…"})]}):t.jsxs("ul",{style:{listStyle:"none",paddingLeft:"0",marginTop:"1rem"},children:[l.topConcepts&&l.topConcepts.map((e=>{if(null==e?void 0:e.id)return t.jsxs("li",{style:{paddingTop:".5rem",fontWeight:"bold",marginTop:".75rem"},children:[t.jsxs(n.Inline,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,t.jsx(n.Text,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"top concept"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&t.jsx(c,{concepts:e.childConcepts})]},e.id)})),l.orphans.map((e=>{var i;return t.jsxs("li",{style:{paddingTop:".5rem",fontWeight:"normal",marginTop:".75rem"},children:[t.jsxs(n.Inline,{space:2,onResize:void 0,onResizeCapture:void 0,children:[null==e?void 0:e.prefLabel,(null==(i=l.topConcept)?void 0:i.length)>0&&t.jsx(n.Text,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"orphan"})]}),(null==e?void 0:e.childConcepts)&&e.childConcepts.length>0&&t.jsx(c,{concepts:e.childConcepts})]},e.id)}))]})},u=e.definePlugin({name:"taxonomyManager",schema:{types:[s,a,l]}});exports.TreeView=e=>{let{document:i,documentId:o}=e;return t.jsx(n.Container,{width:1,style:{paddingTop:"1.25rem"},onResize:void 0,onResizeCapture:void 0,children:t.jsx(n.Box,{padding:4,onResize:void 0,onResizeCapture:void 0,children:t.jsxs(n.Stack,{space:2,children:[t.jsx(n.Text,{size:1,weight:"semibold",onResize:void 0,onResizeCapture:void 0,children:"Hierarchy Tree"}),t.jsx(n.Text,{size:1,muted:!0,onResize:void 0,onResizeCapture:void 0,children:"Concept hierarchy is determined by 'Broader' relationships assigned to each concept."}),t.jsx(p,{document:i,documentId:o})]})})})},exports.taxonomyManager=u;//# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-taxonomy-manager",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Create and manage SKOS compliant taxonomies, thesauri, and classification schemes in Sanity Studio.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * SKOS Concept Preferred Label input component
3
- * @todo Provide more appropriate type for component props
4
3
  */
5
4
 
6
5
  import {Stack, Text} from '@sanity/ui'
@@ -228,21 +228,18 @@ export default defineType({
228
228
  preview: {
229
229
  select: {
230
230
  title: 'prefLabel',
231
- topConcept: 'topConcept',
232
- broader: 'broader.0.prefLabel',
233
- broaderPlusOne: 'broader.0.broader.0.prefLabel',
234
- broaderPlusTwo: 'broader.0.broader.0.broader.0.prefLabel',
231
+ broader0: 'broader.0.prefLabel',
232
+ broader1: 'broader.1.prefLabel',
233
+ broader2: 'broader.2.prefLabel'
235
234
  },
236
- prepare({title, topConcept, broader, broaderPlusOne, broaderPlusTwo}) {
237
- const conceptBroader = [broaderPlusOne, broader].filter(Boolean)
238
- const broaderPath =
239
- conceptBroader.length > 0 ? `${conceptBroader.join(' ▷ ')} ▶︎ ${title}` : ''
240
- const hierarchy = broaderPlusTwo ? `... ${broaderPath}` : broaderPath
235
+ prepare({title, broader0, broader1, broader2 }) {
236
+ const subtitle = [broader0, broader1].filter(Boolean).join(', ') + (Boolean(broader2) ? ' ...' : '')
241
237
  return {
242
238
  title: title,
243
- subtitle: topConcept ? 'Top Concept' : hierarchy,
244
- media: topConcept ? AiOutlineTag : AiFillTag,
239
+ subtitle: broader0 ? 'in ' + subtitle : subtitle,
240
+ media: AiFillTag,
245
241
  }
246
242
  },
247
243
  },
248
244
  })
245
+
package/src/types.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @todo Troubleshoot PrefLableValue interface declaration. `components: {input: }` in skosConcept.tsx doesn't like it.
3
+ */
4
+
1
5
  import {SanityDocument} from '@sanity/client'
2
6
 
3
7
  export interface TopConceptTerms {