@sanity/dashboard 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,2 +1,745 @@
1
- "use strict";var e,t,n,r,i,o,s,a,l,d,c,u,h,p,g,f,x,m,j,b;function y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function w(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?y(Object(n),!0).forEach((function(t){v(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function v(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}Object.defineProperty(exports,"__esModule",{value:!0});var O=require("react/jsx-runtime"),S=require("react"),P=require("@sanity/ui"),C=require("styled-components"),z=require("sanity"),B=require("rxjs"),T=require("rxjs/operators"),q=require("@sanity/icons"),_=require("@sanity/image-url");function E(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var I=E(C),R=E(_);const M=I.default(P.Card)(e||(e=k(["\n display: flex;\n flex-direction: column;\n justify-content: stretch;\n height: 100%;\n box-sizing: border-box;\n position: relative;\n"]))),H=I.default(P.Card)(t||(t=k(["\n position: sticky;\n top: 0;\n z-index: 2;\n border-top-left-radius: inherit;\n border-top-right-radius: inherit;\n"]))),L=I.default(P.Card)(n||(n=k(["\n position: sticky;\n overflow: hidden;\n bottom: 0;\n z-index: 2;\n border-bottom-right-radius: inherit;\n border-bottom-left-radius: inherit;\n margin-top: auto;\n"]))),D=I.default(P.Box)(r||(r=k(["\n position: relative;\n z-index: 1;\n height: stretch;\n min-height: 21.5em;\n\n @media (min-width: ","px) {\n overflow-y: auto;\n outline: none;\n }\n"])),(e=>{let{theme:t}=e;return t.sanity.media[0]})),F=S.forwardRef((function(e,t){const{header:n,children:r,footer:i}=e;return O.jsxs(M,{radius:3,display:"flex",ref:t,children:[n&&O.jsx(H,{borderBottom:!0,paddingX:3,paddingY:4,children:O.jsx(P.Heading,{size:1,textOverflow:"ellipsis",children:n})}),r&&O.jsx(D,{children:r}),i&&O.jsx(L,{borderTop:!0,children:i})]})}));function A(){return z.useClient({apiVersion:"1"})}const Y=S.createContext({widgets:[]});function U(e){const t=S.useContext(Y),n=S.useMemo((()=>w(w({},e.layout||{}),t.layout||{})),[e.layout,t.layout]);return O.jsx(P.Card,{shadow:1,"data-width":n.width,"data-height":n.height,children:S.createElement(e.component,{})})}function V(e,t){return"https://".concat(e,".api.sanity.io/v1/groq/").concat(t)}function W(e){return"https://manage.sanity.io/projects/".concat(e)}const X=[],N=[];function G(e){const{__experimental_before:t=X,data:n=N}=e,[r,i]=S.useState(),[o,s]=S.useState(),a=A(),{projectId:l="unknown",dataset:d="unknown"}=a.config();S.useEffect((()=>{const e=[];return e.push(a.observable.request({uri:"/projects/".concat(l)}).subscribe({next:e=>{const{studioHost:t}=e;i(t?"https://".concat(t,".sanity.studio"):void 0)},error:e=>{console.error("Error while looking for studioHost",e),i({error:"Something went wrong while looking up studioHost. See console."})}})),e.push(a.observable.request({method:"HEAD",uri:"/graphql/".concat(d,"/default")}).subscribe({next:()=>s(function(e,t){return"https://".concat(e,".api.sanity.io/v1/graphql/").concat(t,"/default")}(l,d)),error:e=>{404===e.statusCode?s(void 0):(console.error("Error while looking for graphqlApi",e),s({error:"Something went wrong while looking up graphqlApi. See console."}))}})),()=>{e.forEach((e=>e.unsubscribe()))}}),[d,l,a,s,i]);const c=S.useMemo((()=>{var e;let t=[{title:"Sanity project",rows:[{title:"Project ID",value:l},{title:"Dataset",value:d}]}];const i=[r?{title:"Studio",value:r}:null,...n.filter((e=>"apps"===e.category))].filter((e=>!!e));i.length>0&&(t=t.concat([{title:"Apps",rows:i}])),t=t.concat([{title:"APIs",rows:[{title:"GROQ",value:V(l,d)},{title:"GraphQL",value:null!=(e="object"==typeof o?"Error":o)?e:"Not deployed"}]}],n.filter((e=>"apis"===e.category)));const s={};return n.forEach((e=>{e.category&&"apps"!==e.category&&"apis"!==e.category&&(s[e.category]||(s[e.category]=[]),s[e.category].push(e))})),Object.keys(s).forEach((e=>{t.push({title:e,rows:s[e]})})),t}),[o,r,l,d,n]);return O.jsxs(O.Fragment,{children:[t.map(((e,t)=>O.jsx(U,w({},e),t))),O.jsx(P.Box,{height:"fill",marginTop:(null==t?void 0:t.length)>0?4:0,children:O.jsx(F,{footer:O.jsx(P.Button,{style:{width:"100%"},paddingX:2,paddingY:4,mode:"bleed",tone:"primary",text:"Manage project",as:"a",href:W(l)}),children:O.jsx(P.Card,{paddingY:4,radius:2,role:"table","aria-label":"Project info","aria-describedby":"project_info_table",children:O.jsxs(P.Stack,{space:4,children:[O.jsx(P.Box,{paddingX:3,as:"header",children:O.jsx(P.Heading,{size:1,as:"h2",id:"project_info_table",children:"Project info"})}),c.map((e=>e&&e.rows?O.jsxs(P.Stack,{space:3,children:[O.jsx(P.Card,{borderBottom:!0,padding:3,children:O.jsx(P.Label,{size:0,muted:!0,role:"columnheader",children:e.title})}),O.jsx(P.Stack,{space:4,paddingX:3,role:"rowgroup",children:e.rows.map((e=>{var t,n;return O.jsxs(P.Grid,{columns:2,role:"row",children:[O.jsx(P.Text,{weight:"medium",role:"rowheader",children:e.title}),"object"==typeof e.value&&O.jsx(P.Text,{size:1,children:null==(t=e.value)?void 0:t.error}),"string"==typeof e.value&&O.jsx(O.Fragment,{children:(n=e.value,n&&/^https?:\/\//.test("".concat(n))?O.jsx(P.Text,{size:1,role:"cell",style:{wordBreak:"break-word"},children:O.jsx("a",{href:e.value,children:e.value})}):O.jsx(P.Code,{size:1,role:"cell",style:{wordBreak:"break-word"},children:e.value}))})]},e.title)}))})]},e.title):null))]})})})})]})}const Q=I.default(P.Card)(i||(i=k(["\n box-sizing: border-box;\n border-radius: 50%;\n border-color: transparent;\n overflow: hidden;\n width: 100%;\n height: 100%;\n\n & > img {\n width: 100%;\n height: auto;\n }\n"])));function Z(){const[e,t]=S.useState(),[n,r]=S.useState(),[i,o]=S.useState(),s=z.useUserStore(),a=A(),l=S.useCallback((()=>{const{projectId:e}=a.config(),n=a.observable.request({uri:"/projects/".concat(e)}).pipe(T.switchMap((e=>B.from(s.getUsers(e.members.map((e=>e.id)))).pipe(T.map((t=>({project:e,users:t}))))))).subscribe({next:e=>{let{users:n,project:i}=e;t(i),r((Array.isArray(n)?n:[n]).sort(((e,t)=>function(e,t,n){const{members:r}=n,i=r.find((t=>t.id===(null==e?void 0:e.id))),o=r.find((e=>e.id===(null==t?void 0:t.id)));if(null==i?void 0:i.isRobot)return 1;if(null==o?void 0:o.isRobot)return-1;return 0}(e,t,i))))},error:e=>o(e)});return()=>n.unsubscribe()}),[s,a]);S.useEffect((()=>l()),[l]);const d=S.useCallback((()=>l()),[l]),c=!n||!e;return i?O.jsx(F,{header:"Project users",children:O.jsx(P.Box,{padding:4,children:O.jsxs(P.Text,{children:["Something went wrong while fetching data. You could"," ",O.jsx("a",{onClick:d,title:"Retry users fetch",style:{cursor:"pointer"},children:"retry"}),"..?"]})})}):O.jsxs(F,{header:"Project users",footer:O.jsx(P.Button,{style:{width:"100%"},paddingX:2,paddingY:4,mode:"bleed",tone:"primary",text:"Invite members",as:"a",loading:c,href:c?void 0:(u=e.id,"https://manage.sanity.io/projects/".concat(u,"/team/invite"))}),children:[c&&O.jsx(P.Box,{paddingY:5,paddingX:2,children:O.jsxs(P.Stack,{space:4,children:[O.jsx(P.Text,{align:"center",muted:!0,size:1,children:O.jsx(P.Spinner,{})}),O.jsx(P.Text,{align:"center",size:1,muted:!0,children:"Loading items..."})]})}),!c&&O.jsx(P.Stack,{space:3,padding:3,children:null==n?void 0:n.map((t=>{const n=e.members.find((e=>e.id===t.id)),r=(null==n?void 0:n.isRobot)?O.jsx(P.Text,{size:3,children:O.jsx(q.RobotIcon,{})}):O.jsx(Q,{tone:"transparent",children:(null==t?void 0:t.imageUrl)&&O.jsx("img",{src:t.imageUrl,alt:null==t?void 0:t.displayName})});return O.jsx(P.Box,{children:O.jsx(z.DefaultPreview,{title:t.displayName,subtitle:null==n?void 0:n.role,media:r})},t.id)}))})]});var u}const J=I.default(P.Box)(o||(o=k(["\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n\n &:before {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 2.75em;\n height: 2.75em;\n border-radius: 50%;\n background: ",";\n opacity: 0.75;\n }\n"])),(e=>{let{theme:t}=e;return t.sanity.color.card.enabled.bg})),K=I.default(P.Flex)(s||(s=k(["\n &:hover {\n "," {\n &:before {\n opacity: 1;\n }\n }\n }\n"])),J),$=I.default(P.Card)(a||(a=k(["\n width: 100%;\n padding-bottom: calc(9 / 16 * 100%);\n position: relative;\n"]))),ee=I.default.img(l||(l=k(["\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n object-fit: cover;\n display: block;\n\n &:not([src]) {\n display: none;\n }\n"])));function te(e){const{title:t,posterURL:n,showPlayIcon:r,href:i,presenterName:o,presenterSubtitle:s}=e;return O.jsx(K,{flex:1,children:O.jsx(P.Card,{sizing:"border",flex:1,padding:2,radius:2,as:"a",href:i,target:"_blank",rel:"noopener noreferrer",style:{position:"relative"},children:O.jsxs(P.Flex,{direction:"column",style:{height:"100%"},children:[n&&O.jsxs($,{marginBottom:1,children:[O.jsx(ee,{src:n}),r&&O.jsx(J,{display:"flex",children:O.jsx(P.Text,{align:"center",children:O.jsx(q.PlayIcon,{})})})]}),O.jsxs(P.Flex,{direction:"column",justify:"space-between",paddingY:2,flex:1,children:[O.jsx(P.Heading,{as:"h3",size:1,children:t}),O.jsx(P.Box,{marginTop:4,children:O.jsxs(P.Stack,{space:2,flex:1,children:[O.jsx(P.Text,{size:1,children:o}),O.jsx(P.Text,{size:0,style:{opacity:.7},children:s})]})})]})]})})})}const ne={projectId:"3do82whm",dataset:"next"};function re(e){const{templateRepoId:t}=e,[n,r]=S.useState([]),{getFeed:i,urlBuilder:o}=function(){const e=A();return S.useMemo((()=>({getFeed:t=>{const n=t?"/addons/dashboard?templateRepoId=".concat(t):"/addons/dashboard";return e.observable.request({uri:n,withCredentials:!1})},urlBuilder:R.default(ne)})),[e])}();S.useEffect((()=>{const e=i(t).subscribe((e=>{r(e.items)}));return()=>{e.unsubscribe()}}),[r,i,t]);return O.jsx(F,{header:"Learn about Sanity",children:O.jsx(P.Flex,{as:"ul",overflow:"auto",align:"stretch",paddingY:2,children:null==n?void 0:n.map(((e,t)=>{var r;if(!e.title||!e.guideOrTutorial&&!e.externalLink)return null;const i=e.presenter||(null==(r=e.guideOrTutorial)?void 0:r.presenter)||{},s=e.category,{guideOrTutorial:a={}}=e,l=(a.slug?(d=a.slug,"tutorial"===(c=a._type)?"https://www.sanity.io/docs/tutorials/".concat(d.current):"guide"===c&&"https://www.sanity.io/docs/guides/".concat(d.current)):e.externalLink)||e.externalLink;var d,c;return O.jsx(P.Flex,{as:"li",paddingRight:t<(null==n?void 0:n.length)-1?1:3,paddingLeft:0===t?3:0,align:"stretch",style:{minWidth:272,width:"30%"},children:O.jsx(te,{title:e.title,href:null!=l?l:"",presenterName:i.name,presenterSubtitle:s,showPlayIcon:e.hasVideo,posterURL:e.poster?o.image(e.poster).height(360).url():void 0})},e._id)}))})})}function ie(e){return O.jsx(P.Container,{width:4,padding:4,sizing:"border",style:{minHeight:"100%"},children:e.children})}const oe=function(){return C.css(d||(d=k(["\n @media (min-width: ","px) {\n ","\n }\n "])),(e=>{let{theme:t}=e;return t.sanity.media[0]}),C.css(...arguments))},se=function(){return C.css(c||(c=k(["\n @media (min-width: ","px) {\n ","\n }\n "])),(e=>{let{theme:t}=e;return t.sanity.media[2]}),C.css(...arguments))},ae=I.default(P.Grid)(u||(u=k(["\n grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));\n\n & > div {\n overflow: hidden;\n }\n\n & > div[data-width='medium'] {\n ","\n }\n\n & > div[data-width='large'] {\n ","\n\n ","\n }\n\n & > div[data-width='full'] {\n ","\n }\n\n & > div[data-height='medium'] {\n ","\n }\n\n & > div[data-height='large'] {\n ","\n\n ","\n }\n\n & > div[data-height='full'] {\n ","\n }\n"])),oe(h||(h=k(["\n grid-column: span 2;\n "]))),oe(p||(p=k(["\n grid-column: span 2;\n "]))),se(g||(g=k(["\n grid-column: span 3;\n "]))),oe(f||(f=k(["\n grid-column: 1 / -1;\n "]))),oe(x||(x=k(["\n grid-row: span 2;\n "]))),oe(m||(m=k(["\n grid-row: span 2;\n "]))),se(j||(j=k(["\n grid-row: span 3;\n "]))),se(b||(b=k(["\n grid-row: 1 / -1;\n "])))),le=[],de={};function ce(e){const{config:{layout:t=de,widgets:n=le}}=e;return O.jsxs(ae,{autoFlow:"row dense","data-width":t.width||"auto","data-height":t.height||"auto",gap:4,children:[n.length?null:O.jsx(P.Card,{padding:4,shadow:1,tone:"primary",children:O.jsx(P.Text,{align:"center",children:"Add some widgets to populate this space."})}),n.map(((e,t)=>"__experimental_group"===e.type?O.jsx(ce,{config:e},t):e.component?O.jsx(U,w({},e),t):O.jsxs(P.Box,{children:[e.name," is missing widget component"]},t)))]})}function ue(e){let{config:t}=e;return t?O.jsx(Y.Provider,{value:t,children:O.jsx(ie,{children:O.jsx(ce,{config:t})})}):null}const he={stroke:"currentColor",strokeWidth:1.2},pe=()=>O.jsxs("svg",{"data-sanity-icon":!0,viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",preserveAspectRatio:"xMidYMid",width:"1em",height:"1em",children:[O.jsx("path",{d:"M19.5 19.5H5.5V5.5H19.5V19.5Z",style:he}),O.jsx("path",{d:"M5.5 12.5H19.5",style:he}),O.jsx("path",{d:"M14.5 19.5V12.5M10.5 12.5V5.5",style:he})]}),ge=z.definePlugin((function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};var t,n,r,i,o;const s={layout:null!=(t=e.defaultLayout)?t:{},widgets:null!=(n=e.widgets)?n:[]},a=null!=(r=e.title)?r:"Dashboard",l=null!=(i=e.name)?i:"dashboard",d=null!=(o=e.icon)?o:pe;return{name:"dashboard",tools:(e,t)=>[...e,{title:a,name:l,icon:d,component:()=>O.jsx(ue,{config:s})}]}}));exports.DashboardWidgetContainer=F,exports.dashboardTool=ge,exports.projectInfoWidget=function(e){var t;return{name:"project-info",component:G,layout:null!=(t=null==e?void 0:e.layout)?t:{width:"medium"}}},exports.projectUsersWidget=function(e){return{name:"project-info",component:Z,layout:null==e?void 0:e.layout}},exports.sanityTutorialsWidget=function(e){var t;return{name:"sanity-tutorials",component:re,layout:null!=(t=null==e?void 0:e.layout)?t:{width:"full"}}};
1
+ 'use strict';
2
+
3
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19, _templateObject20;
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
10
+ Object.defineProperty(exports, '__esModule', {
11
+ value: true
12
+ });
13
+ var jsxRuntime = require('react/jsx-runtime');
14
+ var react = require('react');
15
+ var ui = require('@sanity/ui');
16
+ var styled = require('styled-components');
17
+ var sanity = require('sanity');
18
+ var rxjs = require('rxjs');
19
+ var operators = require('rxjs/operators');
20
+ var icons = require('@sanity/icons');
21
+ var imageUrlBuilder = require('@sanity/image-url');
22
+ function _interopDefaultCompat(e) {
23
+ return e && typeof e === 'object' && 'default' in e ? e : {
24
+ default: e
25
+ };
26
+ }
27
+ var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
28
+ var imageUrlBuilder__default = /*#__PURE__*/_interopDefaultCompat(imageUrlBuilder);
29
+ const Root$2 = styled__default.default(ui.Card)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n justify-content: stretch;\n height: 100%;\n box-sizing: border-box;\n position: relative;\n"])));
30
+ const Header = styled__default.default(ui.Card)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: sticky;\n top: 0;\n z-index: 2;\n border-top-left-radius: inherit;\n border-top-right-radius: inherit;\n"])));
31
+ const Footer = styled__default.default(ui.Card)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: sticky;\n overflow: hidden;\n bottom: 0;\n z-index: 2;\n border-bottom-right-radius: inherit;\n border-bottom-left-radius: inherit;\n margin-top: auto;\n"])));
32
+ const Content = styled__default.default(ui.Box)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n z-index: 1;\n height: stretch;\n min-height: 21.5em;\n\n @media (min-width: ", "px) {\n overflow-y: auto;\n outline: none;\n }\n"])), _ref => {
33
+ let {
34
+ theme
35
+ } = _ref;
36
+ return theme.sanity.media[0];
37
+ });
38
+ const DashboardWidgetContainer = react.forwardRef(function DashboardWidgetContainer2(props, ref) {
39
+ const {
40
+ header,
41
+ children,
42
+ footer
43
+ } = props;
44
+ return /* @__PURE__ */jsxRuntime.jsxs(Root$2, {
45
+ radius: 3,
46
+ display: "flex",
47
+ ref,
48
+ children: [header && /* @__PURE__ */jsxRuntime.jsx(Header, {
49
+ borderBottom: true,
50
+ paddingX: 3,
51
+ paddingY: 4,
52
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Heading, {
53
+ size: 1,
54
+ textOverflow: "ellipsis",
55
+ children: header
56
+ })
57
+ }), children && /* @__PURE__ */jsxRuntime.jsx(Content, {
58
+ children
59
+ }), footer && /* @__PURE__ */jsxRuntime.jsx(Footer, {
60
+ borderTop: true,
61
+ children: footer
62
+ })]
63
+ });
64
+ });
65
+ function useVersionedClient() {
66
+ return sanity.useClient({
67
+ apiVersion: "1"
68
+ });
69
+ }
70
+ const DashboardContext = react.createContext({
71
+ widgets: []
72
+ });
73
+ function useDashboardConfig() {
74
+ return react.useContext(DashboardContext);
75
+ }
76
+ function WidgetContainer(props) {
77
+ const config = useDashboardConfig();
78
+ const layout = react.useMemo(() => _objectSpread(_objectSpread({}, props.layout || {}), config.layout || {}), [props.layout, config.layout]);
79
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
80
+ shadow: 1,
81
+ "data-width": layout.width,
82
+ "data-height": layout.height,
83
+ children: react.createElement(props.component, {})
84
+ });
85
+ }
86
+ function isUrl(url) {
87
+ return url && /^https?:\/\//.test("".concat(url));
88
+ }
89
+ function getGraphQlUrl(projectId, dataset) {
90
+ return "https://".concat(projectId, ".api.sanity.io/v1/graphql/").concat(dataset, "/default");
91
+ }
92
+ function getGroqUrl(projectId, dataset) {
93
+ return "https://".concat(projectId, ".api.sanity.io/v1/groq/").concat(dataset);
94
+ }
95
+ function getManageUrl(projectId) {
96
+ return "https://manage.sanity.io/projects/".concat(projectId);
97
+ }
98
+ const NO_EXPERIMENTAL = [];
99
+ const NO_DATA = [];
100
+ function ProjectInfo(props) {
101
+ const {
102
+ __experimental_before = NO_EXPERIMENTAL,
103
+ data = NO_DATA
104
+ } = props;
105
+ const [studioHost, setStudioHost] = react.useState();
106
+ const [graphqlApi, setGraphQlApi] = react.useState();
107
+ const versionedClient = useVersionedClient();
108
+ const {
109
+ projectId = "unknown",
110
+ dataset = "unknown"
111
+ } = versionedClient.config();
112
+ react.useEffect(() => {
113
+ const subscriptions = [];
114
+ subscriptions.push(versionedClient.observable.request({
115
+ uri: "/projects/".concat(projectId)
116
+ }).subscribe({
117
+ next: result => {
118
+ const {
119
+ studioHost: host
120
+ } = result;
121
+ setStudioHost(host ? "https://".concat(host, ".sanity.studio") : void 0);
122
+ },
123
+ error: error => {
124
+ console.error("Error while looking for studioHost", error);
125
+ setStudioHost({
126
+ error: "Something went wrong while looking up studioHost. See console."
127
+ });
128
+ }
129
+ }));
130
+ subscriptions.push(versionedClient.observable.request({
131
+ method: "HEAD",
132
+ uri: "/graphql/".concat(dataset, "/default")
133
+ }).subscribe({
134
+ next: () => setGraphQlApi(getGraphQlUrl(projectId, dataset)),
135
+ error: error => {
136
+ if (error.statusCode === 404) {
137
+ setGraphQlApi(void 0);
138
+ } else {
139
+ console.error("Error while looking for graphqlApi", error);
140
+ setGraphQlApi({
141
+ error: "Something went wrong while looking up graphqlApi. See console."
142
+ });
143
+ }
144
+ }
145
+ }));
146
+ return () => {
147
+ subscriptions.forEach(s => s.unsubscribe());
148
+ };
149
+ }, [dataset, projectId, versionedClient, setGraphQlApi, setStudioHost]);
150
+ const assembleTableRows = react.useMemo(() => {
151
+ var _a;
152
+ let result = [{
153
+ title: "Sanity project",
154
+ rows: [{
155
+ title: "Project ID",
156
+ value: projectId
157
+ }, {
158
+ title: "Dataset",
159
+ value: dataset
160
+ }]
161
+ }];
162
+ const apps = [studioHost ? {
163
+ title: "Studio",
164
+ value: studioHost
165
+ } : null, ...data.filter(item => item.category === "apps")].filter(a => !!a);
166
+ if (apps.length > 0) {
167
+ result = result.concat([{
168
+ title: "Apps",
169
+ rows: apps
170
+ }]);
171
+ }
172
+ result = result.concat([{
173
+ title: "APIs",
174
+ rows: [{
175
+ title: "GROQ",
176
+ value: getGroqUrl(projectId, dataset)
177
+ }, {
178
+ title: "GraphQL",
179
+ value: (_a = typeof graphqlApi === "object" ? "Error" : graphqlApi) != null ? _a : "Not deployed"
180
+ }]
181
+ }], data.filter(item => item.category === "apis"));
182
+ const otherStuff = {};
183
+ data.forEach(item => {
184
+ if (item.category && item.category !== "apps" && item.category !== "apis") {
185
+ if (!otherStuff[item.category]) {
186
+ otherStuff[item.category] = [];
187
+ }
188
+ otherStuff[item.category].push(item);
189
+ }
190
+ });
191
+ Object.keys(otherStuff).forEach(category => {
192
+ result.push({
193
+ title: category,
194
+ rows: otherStuff[category]
195
+ });
196
+ });
197
+ return result;
198
+ }, [graphqlApi, studioHost, projectId, dataset, data]);
199
+ return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
200
+ children: [__experimental_before.map((widgetConfig, idx) => /* @__PURE__ */jsxRuntime.jsx(WidgetContainer, _objectSpread({}, widgetConfig), idx)), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
201
+ height: "fill",
202
+ marginTop: (__experimental_before == null ? void 0 : __experimental_before.length) > 0 ? 4 : 0,
203
+ children: /* @__PURE__ */jsxRuntime.jsx(DashboardWidgetContainer, {
204
+ footer: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
205
+ style: {
206
+ width: "100%"
207
+ },
208
+ paddingX: 2,
209
+ paddingY: 4,
210
+ mode: "bleed",
211
+ tone: "primary",
212
+ text: "Manage project",
213
+ as: "a",
214
+ href: getManageUrl(projectId)
215
+ }),
216
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
217
+ paddingY: 4,
218
+ radius: 2,
219
+ role: "table",
220
+ "aria-label": "Project info",
221
+ "aria-describedby": "project_info_table",
222
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
223
+ space: 4,
224
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
225
+ paddingX: 3,
226
+ as: "header",
227
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Heading, {
228
+ size: 1,
229
+ as: "h2",
230
+ id: "project_info_table",
231
+ children: "Project info"
232
+ })
233
+ }), assembleTableRows.map(item => {
234
+ if (!item || !item.rows) {
235
+ return null;
236
+ }
237
+ return /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
238
+ space: 3,
239
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
240
+ borderBottom: true,
241
+ padding: 3,
242
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
243
+ size: 0,
244
+ muted: true,
245
+ role: "columnheader",
246
+ children: item.title
247
+ })
248
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
249
+ space: 4,
250
+ paddingX: 3,
251
+ role: "rowgroup",
252
+ children: item.rows.map(row => {
253
+ var _a;
254
+ return /* @__PURE__ */jsxRuntime.jsxs(ui.Grid, {
255
+ columns: 2,
256
+ role: "row",
257
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
258
+ weight: "medium",
259
+ role: "rowheader",
260
+ children: row.title
261
+ }), typeof row.value === "object" && /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
262
+ size: 1,
263
+ children: (_a = row.value) == null ? void 0 : _a.error
264
+ }), typeof row.value === "string" && /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
265
+ children: isUrl(row.value) ? /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
266
+ size: 1,
267
+ role: "cell",
268
+ style: {
269
+ wordBreak: "break-word"
270
+ },
271
+ children: /* @__PURE__ */jsxRuntime.jsx("a", {
272
+ href: row.value,
273
+ children: row.value
274
+ })
275
+ }) : /* @__PURE__ */jsxRuntime.jsx(ui.Code, {
276
+ size: 1,
277
+ role: "cell",
278
+ style: {
279
+ wordBreak: "break-word"
280
+ },
281
+ children: row.value
282
+ })
283
+ })]
284
+ }, row.title);
285
+ })
286
+ })]
287
+ }, item.title);
288
+ })]
289
+ })
290
+ })
291
+ })
292
+ })]
293
+ });
294
+ }
295
+ function projectInfoWidget(config) {
296
+ var _a;
297
+ return {
298
+ name: "project-info",
299
+ component: ProjectInfo,
300
+ layout: (_a = config == null ? void 0 : config.layout) != null ? _a : {
301
+ width: "medium"
302
+ }
303
+ };
304
+ }
305
+ const AvatarWrapper = styled__default.default(ui.Card)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n border-radius: 50%;\n border-color: transparent;\n overflow: hidden;\n width: 100%;\n height: 100%;\n\n & > img {\n width: 100%;\n height: auto;\n }\n"])));
306
+ function getInviteUrl(projectId) {
307
+ return "https://manage.sanity.io/projects/".concat(projectId, "/team/invite");
308
+ }
309
+ function ProjectUsers() {
310
+ const [project, setProject] = react.useState();
311
+ const [users, setUsers] = react.useState();
312
+ const [error, setError] = react.useState();
313
+ const userStore = sanity.useUserStore();
314
+ const versionedClient = useVersionedClient();
315
+ const fetchData = react.useCallback(() => {
316
+ const {
317
+ projectId
318
+ } = versionedClient.config();
319
+ const subscription = versionedClient.observable.request({
320
+ uri: "/projects/".concat(projectId)
321
+ }).pipe(operators.switchMap(_project => rxjs.from(userStore.getUsers(_project.members.map(mem => mem.id))).pipe(operators.map(_users => ({
322
+ project: _project,
323
+ users: _users
324
+ }))))).subscribe({
325
+ next: _ref2 => {
326
+ let {
327
+ users: _users,
328
+ project: _project
329
+ } = _ref2;
330
+ setProject(_project);
331
+ setUsers((Array.isArray(_users) ? _users : [_users]).sort((userA, userB) => sortUsersByRobotStatus(userA, userB, _project)));
332
+ },
333
+ error: e => setError(e)
334
+ });
335
+ return () => subscription.unsubscribe();
336
+ }, [userStore, versionedClient]);
337
+ react.useEffect(() => fetchData(), [fetchData]);
338
+ const handleRetryFetch = react.useCallback(() => fetchData(), [fetchData]);
339
+ const isLoading = !users || !project;
340
+ if (error) {
341
+ return /* @__PURE__ */jsxRuntime.jsx(DashboardWidgetContainer, {
342
+ header: "Project users",
343
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
344
+ padding: 4,
345
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
346
+ children: ["Something went wrong while fetching data. You could", " ", /* @__PURE__ */jsxRuntime.jsx("a", {
347
+ onClick: handleRetryFetch,
348
+ title: "Retry users fetch",
349
+ style: {
350
+ cursor: "pointer"
351
+ },
352
+ children: "retry"
353
+ }), "..?"]
354
+ })
355
+ })
356
+ });
357
+ }
358
+ return /* @__PURE__ */jsxRuntime.jsxs(DashboardWidgetContainer, {
359
+ header: "Project users",
360
+ footer: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
361
+ style: {
362
+ width: "100%"
363
+ },
364
+ paddingX: 2,
365
+ paddingY: 4,
366
+ mode: "bleed",
367
+ tone: "primary",
368
+ text: "Invite members",
369
+ as: "a",
370
+ loading: isLoading,
371
+ href: isLoading ? void 0 : getInviteUrl(project.id)
372
+ }),
373
+ children: [isLoading && /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
374
+ paddingY: 5,
375
+ paddingX: 2,
376
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
377
+ space: 4,
378
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
379
+ align: "center",
380
+ muted: true,
381
+ size: 1,
382
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
383
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
384
+ align: "center",
385
+ size: 1,
386
+ muted: true,
387
+ children: "Loading items..."
388
+ })]
389
+ })
390
+ }), !isLoading && /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
391
+ space: 3,
392
+ padding: 3,
393
+ children: users == null ? void 0 : users.map(user => {
394
+ const membership = project.members.find(member => member.id === user.id);
395
+ const media = (membership == null ? void 0 : membership.isRobot) ? /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
396
+ size: 3,
397
+ children: /* @__PURE__ */jsxRuntime.jsx(icons.RobotIcon, {})
398
+ }) : /* @__PURE__ */jsxRuntime.jsx(AvatarWrapper, {
399
+ tone: "transparent",
400
+ children: (user == null ? void 0 : user.imageUrl) && /* @__PURE__ */jsxRuntime.jsx("img", {
401
+ src: user.imageUrl,
402
+ alt: user == null ? void 0 : user.displayName
403
+ })
404
+ });
405
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
406
+ children: /* @__PURE__ */jsxRuntime.jsx(sanity.DefaultPreview, {
407
+ title: user.displayName,
408
+ subtitle: membership == null ? void 0 : membership.role,
409
+ media
410
+ })
411
+ }, user.id);
412
+ })
413
+ })]
414
+ });
415
+ }
416
+ function sortUsersByRobotStatus(userA, userB, project) {
417
+ const {
418
+ members
419
+ } = project;
420
+ const membershipA = members.find(member => member.id === (userA == null ? void 0 : userA.id));
421
+ const membershipB = members.find(member => member.id === (userB == null ? void 0 : userB.id));
422
+ if (membershipA == null ? void 0 : membershipA.isRobot) {
423
+ return 1;
424
+ }
425
+ if (membershipB == null ? void 0 : membershipB.isRobot) {
426
+ return -1;
427
+ }
428
+ return 0;
429
+ }
430
+ function projectUsersWidget(config) {
431
+ return {
432
+ name: "project-info",
433
+ component: ProjectUsers,
434
+ layout: config == null ? void 0 : config.layout
435
+ };
436
+ }
437
+ const PlayIconBox = styled__default.default(ui.Box)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n\n &:before {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 2.75em;\n height: 2.75em;\n border-radius: 50%;\n background: ", ";\n opacity: 0.75;\n }\n"])), _ref3 => {
438
+ let {
439
+ theme
440
+ } = _ref3;
441
+ return theme.sanity.color.card.enabled.bg;
442
+ });
443
+ const Root$1 = styled__default.default(ui.Flex)(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n &:hover {\n ", " {\n &:before {\n opacity: 1;\n }\n }\n }\n"])), PlayIconBox);
444
+ const PosterCard = styled__default.default(ui.Card)(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n width: 100%;\n padding-bottom: calc(9 / 16 * 100%);\n position: relative;\n"])));
445
+ const Poster = styled__default.default.img(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n object-fit: cover;\n display: block;\n\n &:not([src]) {\n display: none;\n }\n"])));
446
+ function Tutorial(props) {
447
+ const {
448
+ title,
449
+ posterURL,
450
+ showPlayIcon,
451
+ href,
452
+ presenterName,
453
+ presenterSubtitle
454
+ } = props;
455
+ return /* @__PURE__ */jsxRuntime.jsx(Root$1, {
456
+ flex: 1,
457
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
458
+ sizing: "border",
459
+ flex: 1,
460
+ padding: 2,
461
+ radius: 2,
462
+ as: "a",
463
+ href,
464
+ target: "_blank",
465
+ rel: "noopener noreferrer",
466
+ style: {
467
+ position: "relative"
468
+ },
469
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
470
+ direction: "column",
471
+ style: {
472
+ height: "100%"
473
+ },
474
+ children: [posterURL && /* @__PURE__ */jsxRuntime.jsxs(PosterCard, {
475
+ marginBottom: 1,
476
+ children: [/* @__PURE__ */jsxRuntime.jsx(Poster, {
477
+ src: posterURL
478
+ }), showPlayIcon && /* @__PURE__ */jsxRuntime.jsx(PlayIconBox, {
479
+ display: "flex",
480
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
481
+ align: "center",
482
+ children: /* @__PURE__ */jsxRuntime.jsx(icons.PlayIcon, {})
483
+ })
484
+ })]
485
+ }), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
486
+ direction: "column",
487
+ justify: "space-between",
488
+ paddingY: 2,
489
+ flex: 1,
490
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Heading, {
491
+ as: "h3",
492
+ size: 1,
493
+ children: title
494
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
495
+ marginTop: 4,
496
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
497
+ space: 2,
498
+ flex: 1,
499
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
500
+ size: 1,
501
+ children: presenterName
502
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
503
+ size: 0,
504
+ style: {
505
+ opacity: 0.7
506
+ },
507
+ children: presenterSubtitle
508
+ })]
509
+ })
510
+ })]
511
+ })]
512
+ })
513
+ })
514
+ });
515
+ }
516
+ const tutorialsProjectConfig = {
517
+ projectId: "3do82whm",
518
+ dataset: "next"
519
+ };
520
+ function useDataAdapter() {
521
+ const versionedClient = useVersionedClient();
522
+ return react.useMemo(() => ({
523
+ getFeed: templateRepoId => {
524
+ const uri = templateRepoId ? "/addons/dashboard?templateRepoId=".concat(templateRepoId) : "/addons/dashboard";
525
+ return versionedClient.observable.request({
526
+ uri,
527
+ withCredentials: false
528
+ });
529
+ },
530
+ urlBuilder: imageUrlBuilder__default.default(tutorialsProjectConfig)
531
+ }), [versionedClient]);
532
+ }
533
+ function createUrl(slug, type) {
534
+ if (type === "tutorial") {
535
+ return "https://www.sanity.io/docs/tutorials/".concat(slug.current);
536
+ } else if (type === "guide") {
537
+ return "https://www.sanity.io/docs/guides/".concat(slug.current);
538
+ }
539
+ return false;
540
+ }
541
+ function SanityTutorials(props) {
542
+ const {
543
+ templateRepoId
544
+ } = props;
545
+ const [feedItems, setFeedItems] = react.useState([]);
546
+ const {
547
+ getFeed,
548
+ urlBuilder
549
+ } = useDataAdapter();
550
+ react.useEffect(() => {
551
+ const subscription = getFeed(templateRepoId).subscribe(response => {
552
+ setFeedItems(response.items);
553
+ });
554
+ return () => {
555
+ subscription.unsubscribe();
556
+ };
557
+ }, [setFeedItems, getFeed, templateRepoId]);
558
+ const title = "Learn about Sanity";
559
+ return /* @__PURE__ */jsxRuntime.jsx(DashboardWidgetContainer, {
560
+ header: title,
561
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
562
+ as: "ul",
563
+ overflow: "auto",
564
+ align: "stretch",
565
+ paddingY: 2,
566
+ children: feedItems == null ? void 0 : feedItems.map((feedItem, index) => {
567
+ var _a;
568
+ if (!feedItem.title || !feedItem.guideOrTutorial && !feedItem.externalLink) {
569
+ return null;
570
+ }
571
+ const presenter = feedItem.presenter || ((_a = feedItem.guideOrTutorial) == null ? void 0 : _a.presenter) || {};
572
+ const subtitle = feedItem.category;
573
+ const {
574
+ guideOrTutorial = {}
575
+ } = feedItem;
576
+ const href = (guideOrTutorial.slug ? createUrl(guideOrTutorial.slug, guideOrTutorial._type) : feedItem.externalLink) || feedItem.externalLink;
577
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
578
+ as: "li",
579
+ paddingRight: index < (feedItems == null ? void 0 : feedItems.length) - 1 ? 1 : 3,
580
+ paddingLeft: index === 0 ? 3 : 0,
581
+ align: "stretch",
582
+ style: {
583
+ minWidth: 272,
584
+ width: "30%"
585
+ },
586
+ children: /* @__PURE__ */jsxRuntime.jsx(Tutorial, {
587
+ title: feedItem.title,
588
+ href: href != null ? href : "",
589
+ presenterName: presenter.name,
590
+ presenterSubtitle: subtitle,
591
+ showPlayIcon: feedItem.hasVideo,
592
+ posterURL: feedItem.poster ? urlBuilder.image(feedItem.poster).height(360).url() : void 0
593
+ })
594
+ }, feedItem._id);
595
+ })
596
+ })
597
+ });
598
+ }
599
+ function sanityTutorialsWidget(config) {
600
+ var _a;
601
+ return {
602
+ name: "sanity-tutorials",
603
+ component: SanityTutorials,
604
+ layout: (_a = config == null ? void 0 : config.layout) != null ? _a : {
605
+ width: "full"
606
+ }
607
+ };
608
+ }
609
+ function DashboardLayout(props) {
610
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Container, {
611
+ width: 4,
612
+ padding: 4,
613
+ sizing: "border",
614
+ style: {
615
+ height: "100%",
616
+ overflowY: "auto"
617
+ },
618
+ children: props.children
619
+ });
620
+ }
621
+ const media = {
622
+ small: function () {
623
+ return styled.css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n @media (min-width: ", "px) {\n ", "\n }\n "])), _ref4 => {
624
+ let {
625
+ theme
626
+ } = _ref4;
627
+ return theme.sanity.media[0];
628
+ }, styled.css(...arguments));
629
+ },
630
+ medium: function () {
631
+ return styled.css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n @media (min-width: ", "px) {\n ", "\n }\n "])), _ref5 => {
632
+ let {
633
+ theme
634
+ } = _ref5;
635
+ return theme.sanity.media[2];
636
+ }, styled.css(...arguments));
637
+ }
638
+ };
639
+ const Root = styled__default.default(ui.Grid)(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));\n\n & > div {\n overflow: hidden;\n }\n\n & > div[data-width='medium'] {\n ", "\n }\n\n & > div[data-width='large'] {\n ", "\n\n ", "\n }\n\n & > div[data-width='full'] {\n ", "\n }\n\n & > div[data-height='medium'] {\n ", "\n }\n\n & > div[data-height='large'] {\n ", "\n\n ", "\n }\n\n & > div[data-height='full'] {\n ", "\n }\n"])), media.small(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n grid-column: span 2;\n "]))), media.small(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n grid-column: span 2;\n "]))), media.medium(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n grid-column: span 3;\n "]))), media.small(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n grid-column: 1 / -1;\n "]))), media.small(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n grid-row: span 2;\n "]))), media.small(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n grid-row: span 2;\n "]))), media.medium(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n grid-row: span 3;\n "]))), media.medium(_templateObject20 || (_templateObject20 = _taggedTemplateLiteral(["\n grid-row: 1 / -1;\n "]))));
640
+ const NO_WIDGETS = [];
641
+ const NO_LAYOUT = {};
642
+ function WidgetGroup(props) {
643
+ const {
644
+ config: {
645
+ layout = NO_LAYOUT,
646
+ widgets = NO_WIDGETS
647
+ }
648
+ } = props;
649
+ return /* @__PURE__ */jsxRuntime.jsxs(Root, {
650
+ autoFlow: "row dense",
651
+ "data-width": layout.width || "auto",
652
+ "data-height": layout.height || "auto",
653
+ gap: 4,
654
+ children: [widgets.length ? null : /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
655
+ padding: 4,
656
+ shadow: 1,
657
+ tone: "primary",
658
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
659
+ align: "center",
660
+ children: "Add some widgets to populate this space."
661
+ })
662
+ }), widgets.map((widgetConfig, index) => {
663
+ if (widgetConfig.type === "__experimental_group") {
664
+ return /* @__PURE__ */jsxRuntime.jsx(WidgetGroup, {
665
+ config: widgetConfig
666
+ }, index);
667
+ }
668
+ if (widgetConfig.component) {
669
+ return /* @__PURE__ */jsxRuntime.jsx(WidgetContainer, _objectSpread({}, widgetConfig), index);
670
+ }
671
+ return /* @__PURE__ */jsxRuntime.jsxs(ui.Box, {
672
+ children: [widgetConfig.name, " is missing widget component"]
673
+ }, index);
674
+ })]
675
+ });
676
+ }
677
+ function Dashboard(_ref6) {
678
+ let {
679
+ config
680
+ } = _ref6;
681
+ if (!config) {
682
+ return null;
683
+ }
684
+ return /* @__PURE__ */jsxRuntime.jsx(DashboardContext.Provider, {
685
+ value: config,
686
+ children: /* @__PURE__ */jsxRuntime.jsx(DashboardLayout, {
687
+ children: /* @__PURE__ */jsxRuntime.jsx(WidgetGroup, {
688
+ config
689
+ })
690
+ })
691
+ });
692
+ }
693
+ const strokeStyle = {
694
+ stroke: "currentColor",
695
+ strokeWidth: 1.2
696
+ };
697
+ const DashboardIcon = () => /* @__PURE__ */jsxRuntime.jsxs("svg", {
698
+ "data-sanity-icon": true,
699
+ viewBox: "0 0 25 25",
700
+ fill: "none",
701
+ xmlns: "http://www.w3.org/2000/svg",
702
+ preserveAspectRatio: "xMidYMid",
703
+ width: "1em",
704
+ height: "1em",
705
+ children: [/* @__PURE__ */jsxRuntime.jsx("path", {
706
+ d: "M19.5 19.5H5.5V5.5H19.5V19.5Z",
707
+ style: strokeStyle
708
+ }), /* @__PURE__ */jsxRuntime.jsx("path", {
709
+ d: "M5.5 12.5H19.5",
710
+ style: strokeStyle
711
+ }), /* @__PURE__ */jsxRuntime.jsx("path", {
712
+ d: "M14.5 19.5V12.5M10.5 12.5V5.5",
713
+ style: strokeStyle
714
+ })]
715
+ });
716
+ const dashboardTool = sanity.definePlugin(function () {
717
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
718
+ var _a, _b, _c, _d, _e;
719
+ const pluginConfig = {
720
+ layout: (_a = config.defaultLayout) != null ? _a : {},
721
+ widgets: (_b = config.widgets) != null ? _b : []
722
+ };
723
+ const title = (_c = config.title) != null ? _c : "Dashboard";
724
+ const name = (_d = config.name) != null ? _d : "dashboard";
725
+ const icon = (_e = config.icon) != null ? _e : DashboardIcon;
726
+ return {
727
+ name: "dashboard",
728
+ tools: (prev, context) => {
729
+ return [...prev, {
730
+ title,
731
+ name,
732
+ icon,
733
+ component: () => /* @__PURE__ */jsxRuntime.jsx(Dashboard, {
734
+ config: pluginConfig
735
+ })
736
+ }];
737
+ }
738
+ };
739
+ });
740
+ exports.DashboardWidgetContainer = DashboardWidgetContainer;
741
+ exports.dashboardTool = dashboardTool;
742
+ exports.projectInfoWidget = projectInfoWidget;
743
+ exports.projectUsersWidget = projectUsersWidget;
744
+ exports.sanityTutorialsWidget = sanityTutorialsWidget;
2
745
  //# sourceMappingURL=index.js.map