!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@graphiql/react"),require("graphql")):"function"==typeof define&&define.amd?define(["exports","react","@graphiql/react","graphql"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GraphiQLPluginExplorer={},e.React,e.GraphiQL.React,e.GraphiQL.GraphQL)}(this,(function(e,t,n,r){"use strict";function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const o=i(t),a=i(r);function l(e){return e&&Object.prototype.hasOwnProperty.call(e,"default")&&1===Object.keys(e).length?e.default:e}var s={},p={};const u=l(o),c=l(a);var f,d;function m(){if(f)return p;f=1,Object.defineProperty(p,"__esModule",{value:!0});var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,l=e[Symbol.iterator]();!(r=(a=l.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(s){i=!0,o=s}finally{try{!r&&l.return&&l.return()}finally{if(i)throw o}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=Object.assign||function(e){for(var t=1;t0?""+r+i:r;var u=s.type.toString(),c={kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:p}},type:(0,o.parseType)(u),directives:[]},f=void 0,d={};if(null!=a){var m=(0,o.visit)(a,{Variable:function(t){var n,r=t.name.value,i=(n=r,(e.props.definition.variableDefinitions||[]).find((function(e){return e.variable.name.value===n})));if(d[r]=d[r]+1||1,i)return i.defaultValue}}),g="NonNullType"===c.type.kind?n({},c,{type:c.type.type}):c;f=n({},g,{defaultValue:m})}else f=c;var y=Object.entries(d).filter((function(e){var n=t(e,2);return n[0],n[1]<2})).map((function(e){var n=t(e,2),r=n[0];return n[1],r}));if(f){var v=e.props.setArgValue(f,!1);if(v){var h=v.definitions.find((function(t){return!!(t.operation&&t.name&&t.name.value&&e.props.definition.name&&e.props.definition.name.value)&&t.name.value===e.props.definition.name.value})),b=[].concat(l(h.variableDefinitions||[]),[f]).filter((function(e){return-1===y.indexOf(e.variable.name.value)})),k=n({},h,{variableDefinitions:b}),S=v.definitions.map((function(e){return h===e?k:e})),E=n({},v,{definitions:S});e.props.onCommit(E)}}},m=a&&"Variable"===a.kind,g=this.state.displayArgActions?i.createElement("button",{type:"submit",className:"toolbar-button",title:m?"Remove the variable":"Extract the current value into a GraphQL variable",onClick:function(t){t.preventDefault(),t.stopPropagation(),m?function(){if(a&&a.name&&a.name.value){var t=a.name.value,r=(e.props.definition.variableDefinitions||[]).find((function(e){return e.variable.name.value===t}));if(r){var i=r.defaultValue,l=e.props.setArgValue(i,{commit:!1});if(l){var s=l.definitions.find((function(t){return t.name.value===e.props.definition.name.value}));if(!s)return;var p=0;(0,o.visit)(s,{Variable:function(e){e.name.value===t&&(p+=1)}});var u=s.variableDefinitions||[];p<2&&(u=u.filter((function(e){return e.variable.name.value!==t})));var c=n({},s,{variableDefinitions:u}),f=l.definitions.map((function(e){return s===e?c:e})),d=n({},l,{definitions:f});e.props.onCommit(d)}}}}():d()},style:p.styles.actionButtonStyle},i.createElement("span",{style:{color:p.colors.variable}},"$")):null;return i.createElement("div",{style:{cursor:"pointer",minHeight:"16px",WebkitUserSelect:"none",userSelect:"none"},"data-arg-name":s.name,"data-arg-type":u.name,className:"graphiql-explorer-"+s.name},i.createElement("span",{style:{cursor:"pointer"},onClick:function(t){var n=!a;n?e.props.addArg(!0):e.props.removeArg(!0),e.setState({displayArgActions:n})}},(0,o.isInputObjectType)(u)?i.createElement("span",null,a?this.props.styleConfig.arrowOpen:this.props.styleConfig.arrowClosed):i.createElement(S,{checked:!!a,styleConfig:this.props.styleConfig}),i.createElement("span",{style:{color:p.colors.attribute},title:s.description,onMouseEnter:function(){null!=a&&e.setState({displayArgActions:!0})},onMouseLeave:function(){return e.setState({displayArgActions:!1})}},s.name,C(s)?"*":"",": ",g," ")," "),c||i.createElement("span",null)," ")}}]),a}(i.PureComponent),T=function(e){function t(){var e,n,r;s(this,t);for(var i=arguments.length,o=Array(i),a=0;a0&&e.setState({displayFieldActions:!0})},onMouseLeave:function(){return e.setState({displayFieldActions:!1})}},(0,o.isObjectType)(f)?i.createElement("span",null,c?this.props.styleConfig.arrowOpen:this.props.styleConfig.arrowClosed):null,(0,o.isObjectType)(f)?null:i.createElement(S,{checked:!!c,styleConfig:this.props.styleConfig}),i.createElement("span",{style:{color:u.colors.property},className:"graphiql-explorer-field-view"},a.name),this.state.displayFieldActions?i.createElement("button",{type:"submit",className:"toolbar-button",title:"Extract selections into a new reusable fragment",onClick:function(t){t.preventDefault(),t.stopPropagation();var r=f.name+"Fragment",i=(g||[]).filter((function(e){return e.name.value.startsWith(r)})).length;i>0&&(r=""+r+i);var o=c&&c.selectionSet?c.selectionSet.selections:[],a=[{kind:"FragmentSpread",name:{kind:"Name",value:r},directives:[]}],s={kind:"FragmentDefinition",name:{kind:"Name",value:r},typeCondition:{kind:"NamedType",name:{kind:"Name",value:f.name}},directives:[],selectionSet:{kind:"SelectionSet",selections:o}},p=e._modifyChildSelections(a,!1);if(p){var u=n({},p,{definitions:[].concat(l(p.definitions),[s])});e.props.onCommit(u)}else console.warn("Unable to complete extractFragment operation")},style:n({},u.styles.actionButtonStyle)},i.createElement("span",null,"…")):null),c&&d.length?i.createElement("div",{style:{marginLeft:16},className:"graphiql-explorer-graphql-arguments"},d.map((function(t){return i.createElement(F,{key:t.name,parentField:a,arg:t,selection:c,modifyArguments:e._setArguments,getDefaultScalarArgValue:e.props.getDefaultScalarArgValue,makeDefaultArg:e.props.makeDefaultArg,onRunOperation:e.props.onRunOperation,styleConfig:e.props.styleConfig,onCommit:e.props.onCommit,definition:e.props.definition})}))):null);if(c&&((0,o.isObjectType)(f)||(0,o.isInterfaceType)(f)||(0,o.isUnionType)(f))){var v=(0,o.isUnionType)(f)?{}:f.getFields(),h=c&&c.selectionSet?c.selectionSet.selections:[];return i.createElement("div",{className:"graphiql-explorer-"+a.name},y,i.createElement("div",{style:{marginLeft:16}},g?g.map((function(t){var n=s.getType(t.typeCondition.name.value),r=t.name.value;return n?i.createElement(N,{key:r,fragment:t,selections:h,modifySelections:e._modifyChildSelections,schema:s,styleConfig:e.props.styleConfig,onCommit:e.props.onCommit}):null})):null,Object.keys(v).sort().map((function(n){return i.createElement(t,{key:n,field:v[n],selections:h,modifySelections:e._modifyChildSelections,schema:s,getDefaultFieldNames:p,getDefaultScalarArgValue:e.props.getDefaultScalarArgValue,makeDefaultArg:e.props.makeDefaultArg,onRunOperation:e.props.onRunOperation,styleConfig:e.props.styleConfig,onCommit:e.props.onCommit,definition:e.props.definition,availableFragments:e.props.availableFragments})})),(0,o.isInterfaceType)(f)||(0,o.isUnionType)(f)?s.getPossibleTypes(f).map((function(t){return i.createElement(T,{key:t.name,implementingType:t,selections:h,modifySelections:e._modifyChildSelections,schema:s,getDefaultFieldNames:p,getDefaultScalarArgValue:e.props.getDefaultScalarArgValue,makeDefaultArg:e.props.makeDefaultArg,onRunOperation:e.props.onRunOperation,styleConfig:e.props.styleConfig,onCommit:e.props.onCommit,definition:e.props.definition})})):null))}return y}}]),t}(i.PureComponent);var P={kind:"Document",definitions:[{kind:"OperationDefinition",operation:"query",variableDefinitions:[],name:{kind:"Name",value:"MyQuery"},directives:[],selectionSet:{kind:"SelectionSet",selections:[]}}]},I=null;function R(e){if(I&&I[0]===e)return I[1];var t=function(e){try{return e.trim()?(0,o.parse)(e,{noLocation:!0}):null}catch(t){return new Error(t)}}(e);return t?t instanceof Error?I?I[1]:P:(I=[e,t],t):P}var q={buttonStyle:{fontSize:"1.2em",padding:"0px",backgroundColor:"white",border:"none",margin:"5px 0px",height:"40px",width:"100%",display:"block",maxWidth:"none"},actionButtonStyle:{padding:"0px",backgroundColor:"white",border:"none",margin:"0px",maxWidth:"none",height:"15px",width:"15px",display:"inline-block",fontSize:"smaller"},explorerActionsStyle:{margin:"4px -8px -8px",paddingLeft:"8px",bottom:"0px",width:"100%",textAlign:"center",background:"none",borderTop:"none",borderBottom:"none"}},B=function(e){function t(){var e,r,i;s(this,t);for(var o=arguments.length,a=Array(o),l=0;lo.createElement("svg",{width:5,height:8,viewBox:"0 0 5 8",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-labelledby":t,...n},e?o.createElement("title",{id:t},e):null,o.createElement("path",{d:"M0.910453 6.86965L3.88955 3.89061C4.09782 3.68233 4.09782 3.34465 3.88955 3.13637L0.910453 0.157278C0.574475 -0.178701 0 0.0592511 0 0.534408V6.49259C0 6.96768 0.574475 7.20565 0.910453 6.86965Z"})),v=({title:e,titleId:t,...n})=>o.createElement("svg",{height:"1em",strokeWidth:1.5,viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-labelledby":t,...n},e?o.createElement("title",{id:t},e):null,o.createElement("path",{d:"M18 6H20M22 6H20M20 6V4M20 6V8",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M21.4 20H2.6C2.26863 20 2 19.7314 2 19.4V11H21.4C21.7314 11 22 11.2686 22 11.6V19.4C22 19.7314 21.7314 20 21.4 20Z"}),o.createElement("path",{d:"M2 11V4.6C2 4.26863 2.26863 4 2.6 4H8.77805C8.92127 4 9.05977 4.05124 9.16852 4.14445L12.3315 6.85555C12.4402 6.94876 12.5787 7 12.722 7H14",strokeLinecap:"round",strokeLinejoin:"round"})),h=({title:e,titleId:t,...n})=>o.createElement("svg",{width:15,height:15,viewBox:"0 0 15 15",xmlns:"http://www.w3.org/2000/svg",stroke:"currentColor",fill:"none","aria-labelledby":t,...n},e?o.createElement("title",{id:t},e):null,o.createElement("circle",{cx:7.5,cy:7.5,r:6,strokeWidth:2})),b=({title:e,titleId:t,...n})=>o.createElement("svg",{width:15,height:15,viewBox:"0 0 15 15",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor","aria-labelledby":t,...n},e?o.createElement("title",{id:t},e):null,o.createElement("circle",{cx:7.5,cy:7.5,r:7.5}),o.createElement("path",{d:"M4.64641 7.00106L6.8801 9.23256L10.5017 5.61325",stroke:"white",strokeWidth:1.5})),k={keyword:"hsl(var(--color-primary))",def:"hsl(var(--color-tertiary))",property:"hsl(var(--color-info))",qualifier:"hsl(var(--color-secondary))",attribute:"hsl(var(--color-tertiary))",number:"hsl(var(--color-success))",string:"hsl(var(--color-warning))",builtin:"hsl(var(--color-success))",string2:"hsl(var(--color-secondary))",variable:"hsl(var(--color-secondary))",atom:"hsl(var(--color-tertiary))"},S=t.createElement(y,{style:{width:"var(--px-16)",transform:"rotate(90deg)"}}),E=t.createElement(y,{style:{width:"var(--px-16)"}}),C=t.createElement(h,{style:{marginRight:"var(--px-4)"}}),_=t.createElement(b,{style:{fill:"hsl(var(--color-info))",marginRight:"var(--px-4)"}}),A={buttonStyle:{cursor:"pointer",fontSize:"2em",lineHeight:0},explorerActionsStyle:{paddingTop:"var(--px-16)"},actionButtonStyle:{}},O=e=>{const{setOperationName:r}=n.useEditorContext({nonNull:!0}),{schema:i}=n.useSchemaStore(),{run:o}=n.useExecutionContext({nonNull:!0}),a=t.useCallback((e=>{e&&r(e),o()}),[o,r]),[l,s]=n.useOptimisticState(n.useOperationsEditorState());return t.createElement(g.Explorer,{schema:i,onRunOperation:a,explorerIsOpen:!0,colors:k,arrowOpen:S,arrowClosed:E,checkboxUnchecked:C,checkboxChecked:_,styles:A,query:l,onEdit:s,...e})};e.explorerPlugin=function(e){return{title:"GraphiQL Explorer",icon:v,content:()=>t.createElement(O,{...e})}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));