@ws-ui/http-handlers-editor 1.11.12-rc1 → 1.11.12-rc2
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/dist/index.cjs.js +4 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +368 -362
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),L=require("@dnd-kit/core"),U=require("@dnd-kit/sortable"),y=require("@ws-ui/icons"),u=require("react"),b=require("@ws-ui/shared"),De=require("@dnd-kit/utilities"),T=require("@headlessui/react"),C=require("classnames"),D=require("downshift"),F=require("lodash"),O=require("@ws-ui/store"),R=require("zod"),q=require("short-uuid"),pe=require("rxjs"),ae=require("randexp"),xe=require("./common.cjs.js"),Te=({label:t,Icon:n,onClick:e})=>r.jsx(b.ToolbarIcon,{label:t,Icon:n,as:"button",onClick:e}),he=u.createContext(null),fe=({children:t,adapter:n})=>r.jsx(he.Provider,{value:n,children:t});function $(){const t=u.useContext(he);if(!t)throw new Error("useEditorStateAdapter must be used within an EditorStateAdapterProvider");return t}const Se=R.z.object({class:R.z.string().optional(),method:R.z.string().optional(),verbs:R.z.union([R.z.string(),R.z.array(R.z.string())]).optional(),id:R.z.string().optional(),pattern:R.z.string().optional(),regexPattern:R.z.string().optional()}),Ae=R.z.array(Se),oe="Invalid JSON";function B(t){let n=t??[];if(typeof t=="string")try{n=JSON.parse(t)}catch{throw new Error(oe)}const e=Ae.safeParse(n);if(!e.success)throw new Error(oe);return e.data.map(s=>{const a=!!s.regexPattern,o=(Array.isArray(s.verbs)?s.verbs:(s.verbs??"").split(",")).map(l=>l.toUpperCase()).filter(Boolean);return{...s,id:s.id??q.generate(),verbs:o,asRegex:a}})}function ee(t){return JSON.stringify(t.map(({isExpanded:n,asRegex:e,pattern:s,regexPattern:a,...o})=>{var d;const l=e?{regexPattern:a}:{pattern:s};return{...o,verbs:(d=o.verbs)==null?void 0:d.join(","),...l}}),null,2)}function M(t){return typeof t=="function"}function He(t){return M(t==null?void 0:t.lift)}function Re(t){return function(n){if(He(n))return n.lift(function(e){try{return t(e,this)}catch(s){this.error(s)}});throw new TypeError("Unable to lift unknown Observable type")}}var J=function(t,n){return J=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,s){e.__proto__=s}||function(e,s){for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])},J(t,n)};function te(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");J(t,n);function e(){this.constructor=t}t.prototype=n===null?Object.create(n):(e.prototype=n.prototype,new e)}function ie(t){var n=typeof Symbol=="function"&&Symbol.iterator,e=n&&t[n],s=0;if(e)return e.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function Q(t,n){var e=typeof Symbol=="function"&&t[Symbol.iterator];if(!e)return t;var s=e.call(t),a,o=[],l;try{for(;(n===void 0||n-- >0)&&!(a=s.next()).done;)o.push(a.value)}catch(d){l={error:d}}finally{try{a&&!a.done&&(e=s.return)&&e.call(s)}finally{if(l)throw l.error}}return o}function Z(t,n,e){if(e||arguments.length===2)for(var s=0,a=n.length,o;s<a;s++)(o||!(s in n))&&(o||(o=Array.prototype.slice.call(n,0,s)),o[s]=n[s]);return t.concat(o||Array.prototype.slice.call(n))}function Pe(t){var n=function(s){Error.call(s),s.stack=new Error().stack},e=t(n);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var Y=Pe(function(t){return function(e){t(this),this.message=e?e.length+` errors occurred during unsubscription:
|
|
2
2
|
`+e.map(function(s,a){return a+1+") "+s.toString()}).join(`
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=e}});function ie(t,n){if(t){var e=t.indexOf(n);0<=e&&t.splice(e,1)}}var te=(function(){function t(n){this.initialTeardown=n,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var n,e,s,a,o;if(!this.closed){this.closed=!0;var l=this._parentage;if(l)if(this._parentage=null,Array.isArray(l))try{for(var d=oe(l),x=d.next();!x.done;x=d.next()){var i=x.value;i.remove(this)}}catch(m){n={error:m}}finally{try{x&&!x.done&&(e=d.return)&&e.call(d)}finally{if(n)throw n.error}}else l.remove(this);var h=this.initialTeardown;if(O(h))try{h()}catch(m){o=m instanceof X?m.errors:[m]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var f=oe(p),w=f.next();!w.done;w=f.next()){var v=w.value;try{le(v)}catch(m){o=o??[],m instanceof X?o=Q(Q([],J(o)),J(m.errors)):o.push(m)}}}catch(m){s={error:m}}finally{try{w&&!w.done&&(a=f.return)&&a.call(f)}finally{if(s)throw s.error}}}if(o)throw new X(o)}},t.prototype.add=function(n){var e;if(n&&n!==this)if(this.closed)le(n);else{if(n instanceof t){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(n)}},t.prototype._hasParent=function(n){var e=this._parentage;return e===n||Array.isArray(e)&&e.includes(n)},t.prototype._addParent=function(n){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(n),e):e?[e,n]:n},t.prototype._removeParent=function(n){var e=this._parentage;e===n?this._parentage=null:Array.isArray(e)&&ie(e,n)},t.prototype.remove=function(n){var e=this._finalizers;e&&ie(e,n),n instanceof t&&n._removeParent(this)},t.EMPTY=(function(){var n=new t;return n.closed=!0,n})(),t})();te.EMPTY;function Pe(t){return t instanceof te||t&&"closed"in t&&O(t.remove)&&O(t.add)&&O(t.unsubscribe)}function le(t){O(t)?t():t.unsubscribe()}var _e={setTimeout:function(t,n){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];return setTimeout.apply(void 0,Q([t,n],J(e)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function ke(t){_e.setTimeout(function(){throw t})}function de(){}var fe=(function(t){ee(n,t);function n(e){var s=t.call(this)||this;return s.isStopped=!1,e?(s.destination=e,Pe(e)&&e.add(s)):s.destination=Me,s}return n.create=function(e,s,a){return new Le(e,s,a)},n.prototype.next=function(e){this.isStopped||this._next(e)},n.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},n.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(e){this.destination.next(e)},n.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n})(te),Ie=(function(){function t(n){this.partialObserver=n}return t.prototype.next=function(n){var e=this.partialObserver;if(e.next)try{e.next(n)}catch(s){$(s)}},t.prototype.error=function(n){var e=this.partialObserver;if(e.error)try{e.error(n)}catch(s){$(s)}else $(n)},t.prototype.complete=function(){var n=this.partialObserver;if(n.complete)try{n.complete()}catch(e){$(e)}},t})(),Le=(function(t){ee(n,t);function n(e,s,a){var o=t.call(this)||this,l;return O(e)||!e?l={next:e??void 0,error:s??void 0,complete:a??void 0}:l=e,o.destination=new Ie(l),o}return n})(fe);function $(t){ke(t)}function Oe(t){throw t}var Me={closed:!0,next:de,error:Oe,complete:de};function Fe(t,n,e,s,a){return new qe(t,n,e,s,a)}var qe=(function(t){ee(n,t);function n(e,s,a,o,l,d){var x=t.call(this,e)||this;return x.onFinalize=l,x.shouldUnsubscribe=d,x._next=s?function(i){try{s(i)}catch(h){e.error(h)}}:t.prototype._next,x._error=o?function(i){try{o(i)}catch(h){e.error(h)}finally{this.unsubscribe()}}:t.prototype._error,x._complete=a?function(){try{a()}catch(i){e.error(i)}finally{this.unsubscribe()}}:t.prototype._complete,x}return n.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var s=this.closed;t.prototype.unsubscribe.call(this),!s&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},n})(fe);function ze(t,n){return He(function(e,s){var a=0;e.subscribe(Fe(s,function(o){return t.call(n,o,a++)&&s.next(o)}))})}const me=new ue.Subject;function ne(t,n){switch(n.type){case"UPDATE_HANDLERS":return{...t,content:n.payload};case"SET_EDITING_HANDLER":{if(n.payload&&n.payload!==t.editing){const e=t.content.find(s=>s.id===t.editing);if(e&&!Object.values(M.omit(e,["id","verbs","asRegex","isExpanded"])).some(Boolean)&&e.verbs.length===0)return{...t,content:t.content.filter(a=>a.id!==e.id),editing:n.payload}}return{...t,editing:n.payload}}case"ADD_HANDLER":{const e=F.generate();return{...t,content:[...t.content,{...n.payload,id:e}],editing:e,newlyCreatedHandlerID:e}}case"UPDATE_HANDLER":return{...t,content:t.content.map(e=>e.id===n.id?{...e,...n.payload}:e),newlyCreatedHandlerID:null};case"DELETE_HANDLER":return{...t,content:t.content.filter(e=>e.id!==n.id)};case"TOGGLE_EXPANDED":return{...t,content:t.content.map(e=>e.id===n.id?{...e,isExpanded:!e.isExpanded}:e)};case"DUPLICATE_HANDLER":{const e=t.content.find(s=>s.id===n.id);return e?{...t,content:[...t.content,{...e,id:F.generate(),isExpanded:!0}]}:t}case"TOGGLE_ALL_EXPANDED":return{...t,content:t.content.map(e=>({...e,isExpanded:n.payload}))};case"SYNC_DATA":return{...t,content:n.payload.map(e=>{const s=t.content.find(a=>a.id===e.id);return s?{...e,...s}:e})};case"CREATE_MODAL":return{...t,modals:{...t.modals,list:[...t.modals.list,n.payload]}};case"REMOVE_MODAL":return{...t,modals:{...t.modals,list:t.modals.list.filter(e=>e.id!==n.payload)}};case"CLOSE_MODAL":{const{id:e,reason:s}=n.payload;let a;if(s)if(t.modals.list.find(l=>l.id===e))a={...t,modals:{...t.modals,list:t.modals.list.map(l=>l.id===e?{...l,closeReason:s,isOpen:!1}:l)}};else return t;else a={...t,modals:{...t.modals,list:t.modals.list.filter(o=>o.id!==e)}};return me.next(a.modals),a}case"EDIT_MODAL":{const{id:e,...s}=n.payload;return t.modals.list.find(o=>o.id===e)?{...t,modals:{...t.modals,list:t.modals.list.map(o=>o.id===e?{...o,...s}:o)}}:t}default:return t}}const B=u.createContext(null),re=t=>({content:t,editing:null,newlyCreatedHandlerID:null,modals:{list:[]}}),ge=({children:t,content:n,catalog:e=null})=>{const s=u.useMemo(()=>G(n),[n]),[a,o]=u.useReducer(ne,re(s));u.useEffect(()=>{o({type:"SYNC_DATA",payload:s})},[s]);const l=u.useMemo(()=>({catalog:e}),[e]);return r.jsx(B.Provider,{value:{state:a,dispatch:o,external:l},children:t})};function ye(){const t=u.useContext(B);if(!t)throw new Error("useReducerAdapter must be used within a ReducerAdapterProvider");const{state:n,dispatch:e,external:s}=t;return{getHandlers:u.useCallback(()=>n.content,[n.content]),getEditingHandlerId:u.useCallback(()=>n.editing,[n.editing]),getNewlyCreatedHandlerId:u.useCallback(()=>n.newlyCreatedHandlerID,[n.newlyCreatedHandlerID]),getCatalog:u.useCallback(()=>s.catalog??null,[s.catalog]),actions:{updateHandlers:u.useCallback(a=>{e({type:"UPDATE_HANDLERS",payload:a})},[]),addHandler:u.useCallback(a=>{e({type:"ADD_HANDLER",payload:a})},[]),updateHandler:u.useCallback((a,o)=>{e({type:"UPDATE_HANDLER",id:a,payload:o})},[]),deleteHandler:u.useCallback(a=>{e({type:"DELETE_HANDLER",id:a})},[]),toggleExpanded:u.useCallback(a=>{e({type:"TOGGLE_EXPANDED",id:a})},[]),duplicateHandler:u.useCallback(a=>{e({type:"DUPLICATE_HANDLER",id:a})},[]),toggleAllExpanded:u.useCallback(a=>{e({type:"TOGGLE_ALL_EXPANDED",payload:a})},[]),setEditingHandler:u.useCallback(a=>{e({type:"SET_EDITING_HANDLER",payload:a})},[]),openModal:u.useCallback(async a=>{const{type:o=b.ModalType.ALERT}=a,l=F.generate();return e({type:"CREATE_MODAL",payload:{id:l,type:o,isOpen:!0,...a}}),o===b.ModalType.CONFIRM?new Promise(d=>{const x=me.pipe(ze(i=>{const h=i.list.find(p=>p.id===l);return h!==void 0&&!h.isOpen})).subscribe(i=>{var p;const h=i.list.find(f=>f.id===l);if(h){const f=h.closeReason===b.ModalCloseReason.CONFIRMED,w=M.entries(((p=h.views)==null?void 0:p.toggles)||{}).reduce((v,m)=>({...v,[m[0]]:m[1].value}),{});e({type:"REMOVE_MODAL",payload:l}),x.unsubscribe(),d({confirmed:f,options:w})}})}):{confirmed:!1}},[e])}}}function Ue(t){const n=L.useAppDispatch(),e=L.useAppSelector(L.selectTabByPath(t),M.isEqual),s=L.useAppSelector(L.selectCatalog),a=u.useMemo(()=>G(e==null?void 0:e.content),[e==null?void 0:e.content]),[o,l]=u.useReducer(ne,re(a));return u.useEffect(()=>{l({type:"SYNC_DATA",payload:a})},[a]),u.useEffect(()=>{if(!e)return;const d=Z(o.content),x=typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2);d!==x&&n(L.setContent({path:t,content:d}))},[n,t,o.content,e]),{getHandlers:u.useCallback(()=>o.content,[o.content]),getEditingHandlerId:u.useCallback(()=>o.editing,[o.editing]),getNewlyCreatedHandlerId:u.useCallback(()=>o.newlyCreatedHandlerID,[o.newlyCreatedHandlerID]),getCatalog:u.useCallback(()=>s??null,[s]),actions:{updateHandlers:u.useCallback(d=>{l({type:"UPDATE_HANDLERS",payload:d})},[]),addHandler:u.useCallback(d=>{l({type:"ADD_HANDLER",payload:d})},[]),updateHandler:u.useCallback((d,x)=>{l({type:"UPDATE_HANDLER",id:d,payload:x})},[]),deleteHandler:u.useCallback(d=>{l({type:"DELETE_HANDLER",id:d})},[]),toggleExpanded:u.useCallback(d=>{l({type:"TOGGLE_EXPANDED",id:d})},[]),duplicateHandler:u.useCallback(d=>{l({type:"DUPLICATE_HANDLER",id:d})},[]),toggleAllExpanded:u.useCallback(d=>{l({type:"TOGGLE_ALL_EXPANDED",payload:d})},[]),setEditingHandler:u.useCallback(d=>{l({type:"SET_EDITING_HANDLER",payload:d})},[]),openModal:u.useCallback(async d=>await n(L.openModal(d)).unwrap(),[n]),switchEditor:u.useCallback(d=>{e&&n(L.switchEditor({tab:e,editor:d}))},[n,e])}}}function be(){const t=u.useContext(B);if(!t)throw new Error("useModals must be used within a ReducerAdapterProvider");const{state:n,dispatch:e}=t;return{modals:n.modals.list,closeModal:u.useCallback(s=>{e({type:"CLOSE_MODAL",payload:s})},[e]),editModal:u.useCallback(s=>{e({type:"EDIT_MODAL",payload:s})},[e]),removeModal:u.useCallback(s=>{e({type:"REMOVE_MODAL",payload:s})},[e])}}const q=new ue.Subject,$e=({initialSelectedItems:t,onChange:n,touched:e,onBlur:s,"data-cy":a})=>{const o=["GET","POST","PUT","DELETE"];function l(j,E){const c=E.toLowerCase();return o.filter(function(A){return!j.includes(A)&&A.toLowerCase().includes(c)})}const[d,x]=u.useState(""),[i,h]=u.useState(t);u.useEffect(()=>{h(t)},[t]);const p=u.useMemo(()=>l(i,d),[i,d]),{getSelectedItemProps:f,getDropdownProps:w,removeSelectedItem:v}=C.useMultipleSelection({selectedItems:i,onStateChange({selectedItems:j=[],type:E}){switch(E){case C.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownBackspace:case C.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownDelete:case C.useMultipleSelection.stateChangeTypes.DropdownKeyDownBackspace:case C.useMultipleSelection.stateChangeTypes.FunctionRemoveSelectedItem:h(j);break}}}),{isOpen:m,getToggleButtonProps:R,getMenuProps:_,getInputProps:T,highlightedIndex:S,getItemProps:P,selectedItem:k}=C.useCombobox({items:p,itemToString(j){return j||""},defaultHighlightedIndex:0,selectedItem:null,inputValue:d,stateReducer(j,E){const{changes:c,type:g}=E;switch(g){case C.useCombobox.stateChangeTypes.InputKeyDownEnter:case C.useCombobox.stateChangeTypes.ItemClick:return{...c,isOpen:!0,highlightedIndex:0};default:return c}},onStateChange({inputValue:j="",type:E,selectedItem:c}){switch(E){case C.useCombobox.stateChangeTypes.InputKeyDownEnter:case C.useCombobox.stateChangeTypes.ItemClick:case C.useCombobox.stateChangeTypes.InputBlur:c&&(h([...i,c]),x(""));break;case C.useCombobox.stateChangeTypes.InputChange:x(j);break}}});return u.useEffect(()=>{n(i)},[i]),r.jsxs("div",{className:"relative flex-1","data-cy":a,children:[r.jsxs("div",{className:N("bg-grey-300 focus-within:ring-1 focus-within:ring-primary-dark relative flex items-center w-full cursor-default overflow-hidden rounded p-px text-left focus:outline-none",{"ring-1 ring-primary-dark rounded-b-none":m&&p.length,"ring-1 ring-red-400 overflow-visible":i.length===0&&e}),onBlur:s,children:[i.length===0&&!m&&e&&r.jsx("div",{className:"absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",children:i.length===0&&"At least one HTTP verb is required"}),i.map(function(E,c){return r.jsxs("span",{className:N("bg-grey-600 text-s mr-1 flex items-center rounded px-1 py-0.5 uppercase",{"bg-red-400":!o.includes(E)}),...f({selectedItem:E,index:c}),children:[E,r.jsx("span",{onClick:g=>{g.stopPropagation(),v(E)},className:"hover:bg-primary-hover ml-2 inline-block cursor-pointer rounded p-0.5 text-gray-100 hover:text-white active:outline-none",children:r.jsx(y.FdCloseNaked,{})})]},`selected-item-${c}-${E}`)}),r.jsx("input",{...T(w({preventKeyAction:m},{suppressRefError:!0})),className:"flex-grow border-none bg-transparent px-1 py-1 text-xs outline-none",placeholder:i.length===0?"Select HTTP verbs":"",size:1}),r.jsx("button",{className:"absolute inset-y-0 right-0 flex items-center pr-2",type:"button",...R(),children:r.jsx(y.FdDown,{className:"h-3 w-3 text-gray-50","aria-hidden":"true"})})]}),r.jsx("ul",{className:`ring-primary-dark bg-grey-900 text-s absolute z-10 w-full rounded-b ring-1 p-1 text-white ${!(m&&p.length)&&"hidden"}`,..._(),children:m&&p.map((j,E)=>r.jsx("li",{className:N(S===E&&"bg-primary-hover",k===j&&"font-bold","flex flex-col p-1 shadow-sm"),...P({item:j,index:E}),children:r.jsx("span",{children:j})},`${j}${E}`))})]})},Ge=({value:t,options:n,errorMessage:e="",onChange:s,onBlur:a,"data-cy":o})=>{const[l,d]=u.useState(""),x=n.find(h=>h.name===t),i=l===""?n:n.filter(h=>h.name.toLowerCase().includes(l.toLowerCase()));return r.jsx(D.Combobox,{value:{name:t},onChange:h=>s(h.name),children:({open:h})=>r.jsxs("div",{className:"relative w-full","data-cy":o,children:[r.jsxs("div",{className:N("bg-grey-300 focus-within:ring-1 focus-within:ring-primary-dark relative w-full cursor-default overflow-hidden rounded text-left inline-flex",{"ring-1 ring-red-400":!x&&t||e,"ring-1 ring-primary-dark rounded-b-none":h,"overflow-visible":!x&&!h&&e}),children:[r.jsx(D.Combobox.Input,{className:N("bg-grey-300 text-s w-full border-none py-1 px-2 focus:outline-none rounded",{"!text-red-400":!x}),displayValue:p=>p.name,onChange:p=>d(p.target.value),style:{caretColor:"white"},onBlur:a}),r.jsxs("span",{className:"inset-y-0 right-0 flex items-center gap-1 pr-2",children:[!x&&!h&&e&&r.jsx("div",{className:"absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",children:e}),t?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{d(""),s("")},children:r.jsx(y.FdCloseNaked,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})}),r.jsx("span",{className:"bg-grey-50 h-3 w-[1px] rounded-full"})]}):null,r.jsx(D.Combobox.Button,{children:r.jsx(y.FdDown,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})})]})]}),r.jsx(D.Transition,{as:u.Fragment,leave:"transition ease-in durati pb-0.5on-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",afterLeave:()=>d(""),children:r.jsx(D.Combobox.Options,{className:"bg-grey-900 text-s text-grey-100 sm:text-s absolute z-50 max-h-60 w-full overflow-auto rounded-b ring-1 ring-primary-dark p-1 focus:outline-none",children:i.length===0?r.jsxs("div",{className:"text-s text-grey-200 relative cursor-default select-none px-0.5 py-0.5 ",children:[r.jsx(y.FdEmpty,{className:"inline h-4 w-4"})," Nothing found."]}):i.map((p,f)=>r.jsx(D.Combobox.Option,{className:({active:w})=>`relative cursor-default select-none ${w?"bg-primary-hover":""}`,value:p,children:({selected:w})=>r.jsx(r.Fragment,{children:r.jsx("span",{className:`block truncate p-2 py-1 ${w?"bg-primary-dark font-medium text-white":"font-normal"}`,children:p.name})})},f))})})]})},t)},Be=({value:t,options:n,onChange:e,errorMessage:s,onBlur:a,"data-cy":o})=>{const[l,d]=u.useState(""),x=n.find(p=>p.name===t),i=x&&x.exposed,h=l===""?n:n.filter(p=>p.name.toLowerCase().includes(l.toLowerCase()));return r.jsx(D.Combobox,{value:{name:t},onChange:p=>e(p.name),children:({open:p})=>r.jsxs("div",{className:"relative","data-cy":o,children:[r.jsxs("div",{className:N("bg-grey-300 focus-within:ring-1 focus-within:ring-primary-dark relative w-full cursor-default overflow-hidden rounded text-left inline-flex",{"ring-1 ring-red-400":s,"ring-1 ring-yellow-500":i,"ring-1 ring-primary-dark rounded-b-none":p,"overflow-visible":!p&&s}),children:[r.jsx(D.Combobox.Input,{className:N("bg-grey-300 text-s w-full border-none py-1 px-2 focus:outline-none truncate rounded",{"!text-red-400":s,"!text-yellow-500":i}),style:{caretColor:"white"},displayValue:f=>f.name,onChange:f=>d(f.target.value),onBlur:a}),!p&&s&&r.jsx("div",{className:N("absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",{"!text-yellow-500 ring-yellow-500 bg-white":i}),children:s}),r.jsxs("span",{className:"inset-y-0 right-0 flex items-center gap-1 pr-2",children:[t?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{d(""),e("")},children:r.jsx(y.FdCloseNaked,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})}),r.jsx("span",{className:"bg-grey-50 h-3 w-[1px] rounded-full"})]}):null,r.jsx(D.Combobox.Button,{children:r.jsx(y.FdDown,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})})]})]}),r.jsx(D.Transition,{as:u.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",afterLeave:()=>d(""),children:r.jsx(D.Combobox.Options,{className:"bg-grey-900 text-s text-grey-100 sm:text-s absolute z-50 max-h-60 w-full overflow-auto rounded-b ring-1 ring-primary-dark p-1 focus:outline-none",children:h.length?h.map((f,w)=>r.jsx(D.Combobox.Option,{className:({active:v})=>`relative cursor-default select-none ${v?"bg-primary-hover":""}`,value:f,children:({selected:v})=>r.jsx(r.Fragment,{children:r.jsxs("span",{className:`text-s flex items-center gap-2 truncate p-2 py-1 ${v?"bg-primary-dark font-medium text-white":"font-normal"}`,children:[f.exposed&&r.jsx(y.FdWarningDanger,{className:"text-yellow-500"}),r.jsx("span",{className:"flex-1 truncate",title:f.name,children:f.name})]})})},w)):r.jsxs("div",{className:"text-s text-grey-200 relative cursor-default select-none px-0.5 py-0.5",children:[r.jsx(y.FdEmpty,{className:"inline h-4 w-4"})," Nothing found."]})})})]})})},ve=({listeners:t,attributes:n})=>r.jsx("button",{"data-cy":"handler-row-drag-handle",...n,...t,children:r.jsx(y.FdDragHandle,{})}),Ee=t=>{var e;if(!t)return"";let n;se.prototype.max=8;try{n=(e=new se(t))==null?void 0:e.gen()}catch{n=""}return`Requests matching regex will be handled example: ${n}`},We=({id:t,class:n,method:e,pattern:s,verbs:a,regexPattern:o,asRegex:l,listeners:d,attributes:x})=>{var E;const[i,h]=u.useState({className:n,method:e,pattern:s,verbs:a,asRegex:l,regexPattern:o}),p=U(),f=p.getCatalog(),w=Object.values((f==null?void 0:f.singletons)||{}),v=(E=w.find(c=>c.name===i.className))==null?void 0:E.methods.map(({name:c,exposed:g})=>({name:c,exposed:g})),m=p.getNewlyCreatedHandlerId();function R(){const{className:c,method:g,asRegex:A,regexPattern:W,pattern:V,verbs:K}=i;return!!(c&&g&&(A?W:!V.endsWith("/"))&&K.length)}function _(){if(R()){const{className:c,method:g,asRegex:A,regexPattern:W,pattern:V,verbs:K}=i,Ne=A?{regexPattern:W}:{pattern:V};p.actions.updateHandler(t,{class:c,method:g,verbs:K,asRegex:A,...Ne}),p.actions.setEditingHandler(null)}}const T=async()=>{const c={className:n,method:e,pattern:s,regexPattern:o,verbs:a},g=M.omit(i,["id","isExpanded"]);if(!R()){m&&p.actions.deleteHandler(m),p.actions.setEditingHandler(null);return}if(!M.isEqual(c,g)){const{confirmed:A}=await p.actions.openModal({title:"Cancel Changes",type:b.ModalType.CONFIRM,color:b.ModalColor.DANGER,message:"Are you sure you want to cancel changes made to this Handler?",icon:"FdWarningDanger"});if(A){m&&m===t&&p.actions.deleteHandler(t),p.actions.setEditingHandler(null);return}}};b.useHotkeys("esc",()=>{setTimeout(()=>{T()},100)},[]),u.useEffect(()=>{q.subscribe(c=>{c===t&&_()})},[i,t]);const[S,P]=u.useState({className:!1,method:!1,pattern:!1,verbs:!1}),k=()=>{if(S.method&&!i.method)return"Method is required";if(v){const c=v==null?void 0:v.find(g=>g.name===i.method);if(i.method&&!c)return`The method "${i.method}" doesn't exist.`;if(c&&c.exposed)return`Method "${i.method}" is already exposed`}},j=()=>{var c;if(S.pattern){if(i.asRegex&&!i.regexPattern)return"Pattern is required";if(!i.asRegex&&((c=i.pattern)!=null&&c.endsWith("/")))return'Pattern should not end with a "/"'}};return r.jsxs("div",{className:"flex items-center gap-2 rounded-b py-2",children:[r.jsxs("div",{className:"flex w-60 flex-shrink-0 items-center gap-1",children:[r.jsx(ve,{listeners:d,attributes:x},"grab-handle"),r.jsx(Ge,{"data-cy":"handler-row-class-selector",value:i.className,onChange:c=>{h(g=>({...g,className:c}))},onBlur:()=>P(c=>({...c,className:!0})),options:w,errorMessage:S.className&&!i.className?"Class name is required":i.className!==""&&!w.find(c=>c.name===i.className)?`The singleton "${i.className}" doesn't exist.`:void 0},n)]}),r.jsx("div",{className:"w-60 flex-shrink-0",children:r.jsx(Be,{"data-cy":"handler-row-method-selector",value:i.method,onChange:c=>{h(g=>({...g,method:c}))},options:v||[],errorMessage:k(),onBlur:()=>P(c=>({...c,method:!0}))})}),r.jsxs("div",{className:"relative w-60 flex-shrink-0 flex items-center gap-1 overflow-visible",children:[r.jsx(b.Tooltip,{label:i.asRegex?Ee(i.regexPattern):i.pattern&&!i.pattern.endsWith("/")?`Requests starting with /${i.pattern}/ will be handled`:"",children:r.jsxs("div",{className:"relative w-full",children:[!i.asRegex&&r.jsx("span",{className:"absolute text-s inset-y-0 left-1 flex items-center gap-2",children:"/"}),r.jsx("input",{"data-cy":"handler-row-pattern-input",type:"text",className:N("bg-grey-300 text-s block w-full rounded p-1 pl-3 focus:outline-none focus:ring-1 focus:ring-primary-dark",{"focus:ring-red-400 ring-1 ring-red-400":S.pattern&&i.asRegex&&!i.regexPattern}),value:i.asRegex?i.regexPattern:i.pattern,onChange:c=>{h(g=>({...g,[i.asRegex?"regexPattern":"pattern"]:c.target.value}))},onBlur:()=>P(c=>({...c,pattern:!0})),placeholder:i.asRegex?"Required":""}),j()&&r.jsx("div",{className:"absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",children:j()})]})}),(l?o:s)&&r.jsx("button",{onClick:c=>{c.stopPropagation(),h(g=>({...g,[i.asRegex?"regexPattern":"pattern"]:""}))},className:"absolute inset-y-0 right-6 flex items-center gap-2 pr-2",children:r.jsx(y.FdCloseNaked,{className:"text-grey-200 h-3 w-3","aria-hidden":"true"})}),r.jsx(b.Tooltip,{label:i.asRegex?"Requests matching this regex will be handled. Check the match with the __[Match regex command](https://developer.4d.com/docs/commands/match-regex)__":`Prefixes are considered as regular expressions already containing starting and ending /
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=e}});function le(t,n){if(t){var e=t.indexOf(n);0<=e&&t.splice(e,1)}}var ne=(function(){function t(n){this.initialTeardown=n,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var n,e,s,a,o;if(!this.closed){this.closed=!0;var l=this._parentage;if(l)if(this._parentage=null,Array.isArray(l))try{for(var d=ie(l),x=d.next();!x.done;x=d.next()){var i=x.value;i.remove(this)}}catch(m){n={error:m}}finally{try{x&&!x.done&&(e=d.return)&&e.call(d)}finally{if(n)throw n.error}}else l.remove(this);var h=this.initialTeardown;if(M(h))try{h()}catch(m){o=m instanceof Y?m.errors:[m]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var f=ie(p),w=f.next();!w.done;w=f.next()){var v=w.value;try{de(v)}catch(m){o=o??[],m instanceof Y?o=Z(Z([],Q(o)),Q(m.errors)):o.push(m)}}}catch(m){s={error:m}}finally{try{w&&!w.done&&(a=f.return)&&a.call(f)}finally{if(s)throw s.error}}}if(o)throw new Y(o)}},t.prototype.add=function(n){var e;if(n&&n!==this)if(this.closed)de(n);else{if(n instanceof t){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(n)}},t.prototype._hasParent=function(n){var e=this._parentage;return e===n||Array.isArray(e)&&e.includes(n)},t.prototype._addParent=function(n){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(n),e):e?[e,n]:n},t.prototype._removeParent=function(n){var e=this._parentage;e===n?this._parentage=null:Array.isArray(e)&&le(e,n)},t.prototype.remove=function(n){var e=this._finalizers;e&&le(e,n),n instanceof t&&n._removeParent(this)},t.EMPTY=(function(){var n=new t;return n.closed=!0,n})(),t})();ne.EMPTY;function _e(t){return t instanceof ne||t&&"closed"in t&&M(t.remove)&&M(t.add)&&M(t.unsubscribe)}function de(t){M(t)?t():t.unsubscribe()}var ke={setTimeout:function(t,n){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];return setTimeout.apply(void 0,Z([t,n],Q(e)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function Ie(t){ke.setTimeout(function(){throw t})}function ce(){}var me=(function(t){te(n,t);function n(e){var s=t.call(this)||this;return s.isStopped=!1,e?(s.destination=e,_e(e)&&e.add(s)):s.destination=Fe,s}return n.create=function(e,s,a){return new Oe(e,s,a)},n.prototype.next=function(e){this.isStopped||this._next(e)},n.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},n.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(e){this.destination.next(e)},n.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n})(ne),Le=(function(){function t(n){this.partialObserver=n}return t.prototype.next=function(n){var e=this.partialObserver;if(e.next)try{e.next(n)}catch(s){G(s)}},t.prototype.error=function(n){var e=this.partialObserver;if(e.error)try{e.error(n)}catch(s){G(s)}else G(n)},t.prototype.complete=function(){var n=this.partialObserver;if(n.complete)try{n.complete()}catch(e){G(e)}},t})(),Oe=(function(t){te(n,t);function n(e,s,a){var o=t.call(this)||this,l;return M(e)||!e?l={next:e??void 0,error:s??void 0,complete:a??void 0}:l=e,o.destination=new Le(l),o}return n})(me);function G(t){Ie(t)}function Me(t){throw t}var Fe={closed:!0,next:ce,error:Me,complete:ce};function qe(t,n,e,s,a){return new ze(t,n,e,s,a)}var ze=(function(t){te(n,t);function n(e,s,a,o,l,d){var x=t.call(this,e)||this;return x.onFinalize=l,x.shouldUnsubscribe=d,x._next=s?function(i){try{s(i)}catch(h){e.error(h)}}:t.prototype._next,x._error=o?function(i){try{o(i)}catch(h){e.error(h)}finally{this.unsubscribe()}}:t.prototype._error,x._complete=a?function(){try{a()}catch(i){e.error(i)}finally{this.unsubscribe()}}:t.prototype._complete,x}return n.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var s=this.closed;t.prototype.unsubscribe.call(this),!s&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},n})(me);function Ue(t,n){return Re(function(e,s){var a=0;e.subscribe(qe(s,function(o){return t.call(n,o,a++)&&s.next(o)}))})}const ge=new pe.Subject;function re(t,n){switch(n.type){case"UPDATE_HANDLERS":return{...t,content:n.payload};case"SET_EDITING_HANDLER":{if(n.payload&&n.payload!==t.editing){const e=t.content.find(s=>s.id===t.editing);if(e&&!Object.values(F.omit(e,["id","verbs","asRegex","isExpanded"])).some(Boolean)&&e.verbs.length===0)return{...t,content:t.content.filter(a=>a.id!==e.id),editing:n.payload}}return{...t,editing:n.payload}}case"ADD_HANDLER":{const e=q.generate();return{...t,content:[...t.content,{...n.payload,id:e}],editing:e,newlyCreatedHandlerID:e}}case"UPDATE_HANDLER":return{...t,content:t.content.map(e=>e.id===n.id?{...e,...n.payload}:e),newlyCreatedHandlerID:null};case"DELETE_HANDLER":return{...t,content:t.content.filter(e=>e.id!==n.id)};case"TOGGLE_EXPANDED":return{...t,content:t.content.map(e=>e.id===n.id?{...e,isExpanded:!e.isExpanded}:e)};case"DUPLICATE_HANDLER":{const e=t.content.find(s=>s.id===n.id);return e?{...t,content:[...t.content,{...e,id:q.generate(),isExpanded:!0}]}:t}case"TOGGLE_ALL_EXPANDED":return{...t,content:t.content.map(e=>({...e,isExpanded:n.payload}))};case"SYNC_DATA":return{...t,content:n.payload.map(e=>{const s=t.content.find(a=>a.id===e.id);return s?{...e,...s}:e})};case"CREATE_MODAL":return{...t,modals:{...t.modals,list:[...t.modals.list,n.payload]}};case"REMOVE_MODAL":return{...t,modals:{...t.modals,list:t.modals.list.filter(e=>e.id!==n.payload)}};case"CLOSE_MODAL":{const{id:e,reason:s}=n.payload;let a;if(s)if(t.modals.list.find(l=>l.id===e))a={...t,modals:{...t.modals,list:t.modals.list.map(l=>l.id===e?{...l,closeReason:s,isOpen:!1}:l)}};else return t;else a={...t,modals:{...t.modals,list:t.modals.list.filter(o=>o.id!==e)}};return ge.next(a.modals),a}case"EDIT_MODAL":{const{id:e,...s}=n.payload;return t.modals.list.find(o=>o.id===e)?{...t,modals:{...t.modals,list:t.modals.list.map(o=>o.id===e?{...o,...s}:o)}}:t}default:return t}}const W=u.createContext(null),se=t=>({content:t,editing:null,newlyCreatedHandlerID:null,modals:{list:[]}}),ye=({children:t,content:n,catalog:e=null})=>{const s=u.useMemo(()=>B(n),[n]),[a,o]=u.useReducer(re,se(s));u.useEffect(()=>{o({type:"SYNC_DATA",payload:s})},[s]);const l=u.useMemo(()=>({catalog:e}),[e]);return r.jsx(W.Provider,{value:{state:a,dispatch:o,external:l},children:t})};function be(){const t=u.useContext(W);if(!t)throw new Error("useReducerAdapter must be used within a ReducerAdapterProvider");const{state:n,dispatch:e,external:s}=t;return{getHandlers:u.useCallback(()=>n.content,[n.content]),getEditingHandlerId:u.useCallback(()=>n.editing,[n.editing]),getNewlyCreatedHandlerId:u.useCallback(()=>n.newlyCreatedHandlerID,[n.newlyCreatedHandlerID]),getCatalog:u.useCallback(()=>s.catalog??null,[s.catalog]),actions:{updateHandlers:u.useCallback(a=>{e({type:"UPDATE_HANDLERS",payload:a})},[]),addHandler:u.useCallback(a=>{e({type:"ADD_HANDLER",payload:a})},[]),updateHandler:u.useCallback((a,o)=>{e({type:"UPDATE_HANDLER",id:a,payload:o})},[]),deleteHandler:u.useCallback(a=>{e({type:"DELETE_HANDLER",id:a})},[]),toggleExpanded:u.useCallback(a=>{e({type:"TOGGLE_EXPANDED",id:a})},[]),duplicateHandler:u.useCallback(a=>{e({type:"DUPLICATE_HANDLER",id:a})},[]),toggleAllExpanded:u.useCallback(a=>{e({type:"TOGGLE_ALL_EXPANDED",payload:a})},[]),setEditingHandler:u.useCallback(a=>{e({type:"SET_EDITING_HANDLER",payload:a})},[]),openModal:u.useCallback(async a=>{const{type:o=b.ModalType.ALERT}=a,l=q.generate();return e({type:"CREATE_MODAL",payload:{id:l,type:o,isOpen:!0,...a}}),o===b.ModalType.CONFIRM?new Promise(d=>{const x=ge.pipe(Ue(i=>{const h=i.list.find(p=>p.id===l);return h!==void 0&&!h.isOpen})).subscribe(i=>{var p;const h=i.list.find(f=>f.id===l);if(h){const f=h.closeReason===b.ModalCloseReason.CONFIRMED,w=F.entries(((p=h.views)==null?void 0:p.toggles)||{}).reduce((v,m)=>({...v,[m[0]]:m[1].value}),{});e({type:"REMOVE_MODAL",payload:l}),x.unsubscribe(),d({confirmed:f,options:w})}})}):{confirmed:!1}},[e])}}}function $e(t){const n=O.useAppDispatch(),e=O.useAppSelector(O.selectTabByPath(t),F.isEqual),s=O.useAppSelector(O.selectCatalog),a=u.useMemo(()=>B(e==null?void 0:e.content),[e==null?void 0:e.content]),[o,l]=u.useReducer(re,se(a));return u.useEffect(()=>{l({type:"SYNC_DATA",payload:a})},[a]),u.useEffect(()=>{if(!e)return;const d=ee(o.content),x=typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2);d!==x&&n(O.setContent({path:t,content:d}))},[n,t,o.content,e]),{getHandlers:u.useCallback(()=>o.content,[o.content]),getEditingHandlerId:u.useCallback(()=>o.editing,[o.editing]),getNewlyCreatedHandlerId:u.useCallback(()=>o.newlyCreatedHandlerID,[o.newlyCreatedHandlerID]),getCatalog:u.useCallback(()=>s??null,[s]),actions:{updateHandlers:u.useCallback(d=>{l({type:"UPDATE_HANDLERS",payload:d})},[]),addHandler:u.useCallback(d=>{l({type:"ADD_HANDLER",payload:d})},[]),updateHandler:u.useCallback((d,x)=>{l({type:"UPDATE_HANDLER",id:d,payload:x})},[]),deleteHandler:u.useCallback(d=>{l({type:"DELETE_HANDLER",id:d})},[]),toggleExpanded:u.useCallback(d=>{l({type:"TOGGLE_EXPANDED",id:d})},[]),duplicateHandler:u.useCallback(d=>{l({type:"DUPLICATE_HANDLER",id:d})},[]),toggleAllExpanded:u.useCallback(d=>{l({type:"TOGGLE_ALL_EXPANDED",payload:d})},[]),setEditingHandler:u.useCallback(d=>{l({type:"SET_EDITING_HANDLER",payload:d})},[]),openModal:u.useCallback(async d=>await n(O.openModal(d)).unwrap(),[n]),switchEditor:u.useCallback(d=>{e&&n(O.switchEditor({tab:e,editor:d}))},[n,e])}}}function ve(){const t=u.useContext(W);if(!t)throw new Error("useModals must be used within a ReducerAdapterProvider");const{state:n,dispatch:e}=t;return{modals:n.modals.list,closeModal:u.useCallback(s=>{e({type:"CLOSE_MODAL",payload:s})},[e]),editModal:u.useCallback(s=>{e({type:"EDIT_MODAL",payload:s})},[e]),removeModal:u.useCallback(s=>{e({type:"REMOVE_MODAL",payload:s})},[e])}}const z=new pe.Subject,N=()=>document.querySelector(`.${xe.HTTP_HANDLERS_EDITOR_SCOPE_CLASS}`)||document.body,Ge=({initialSelectedItems:t,onChange:n,touched:e,onBlur:s,"data-cy":a})=>{const o=["GET","POST","PUT","DELETE"];function l(j,E){const c=E.toLowerCase();return o.filter(function(H){return!j.includes(H)&&H.toLowerCase().includes(c)})}const[d,x]=u.useState(""),[i,h]=u.useState(t);u.useEffect(()=>{h(t)},[t]);const p=u.useMemo(()=>l(i,d),[i,d]),{getSelectedItemProps:f,getDropdownProps:w,removeSelectedItem:v}=D.useMultipleSelection({selectedItems:i,onStateChange({selectedItems:j=[],type:E}){switch(E){case D.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownBackspace:case D.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownDelete:case D.useMultipleSelection.stateChangeTypes.DropdownKeyDownBackspace:case D.useMultipleSelection.stateChangeTypes.FunctionRemoveSelectedItem:h(j);break}}}),{isOpen:m,getToggleButtonProps:P,getMenuProps:k,getInputProps:S,highlightedIndex:A,getItemProps:_,selectedItem:I}=D.useCombobox({items:p,itemToString(j){return j||""},defaultHighlightedIndex:0,selectedItem:null,inputValue:d,stateReducer(j,E){const{changes:c,type:g}=E;switch(g){case D.useCombobox.stateChangeTypes.InputKeyDownEnter:case D.useCombobox.stateChangeTypes.ItemClick:return{...c,isOpen:!0,highlightedIndex:0};default:return c}},onStateChange({inputValue:j="",type:E,selectedItem:c}){switch(E){case D.useCombobox.stateChangeTypes.InputKeyDownEnter:case D.useCombobox.stateChangeTypes.ItemClick:case D.useCombobox.stateChangeTypes.InputBlur:c&&(h([...i,c]),x(""));break;case D.useCombobox.stateChangeTypes.InputChange:x(j);break}}});return u.useEffect(()=>{n(i)},[i]),r.jsxs("div",{className:"relative flex-1","data-cy":a,children:[r.jsxs("div",{className:C("bg-grey-300 focus-within:ring-1 focus-within:ring-primary-dark relative flex items-center w-full cursor-default overflow-hidden rounded p-px text-left focus:outline-none",{"ring-1 ring-primary-dark rounded-b-none":m&&p.length,"ring-1 ring-red-400 overflow-visible":i.length===0&&e}),onBlur:s,children:[i.length===0&&!m&&e&&r.jsx("div",{className:"absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",children:i.length===0&&"At least one HTTP verb is required"}),i.map(function(E,c){return r.jsxs("span",{className:C("bg-grey-600 text-s mr-1 flex items-center rounded px-1 py-0.5 uppercase",{"bg-red-400":!o.includes(E)}),...f({selectedItem:E,index:c}),children:[E,r.jsx("span",{onClick:g=>{g.stopPropagation(),v(E)},className:"hover:bg-primary-hover ml-2 inline-block cursor-pointer rounded p-0.5 text-gray-100 hover:text-white active:outline-none",children:r.jsx(y.FdCloseNaked,{})})]},`selected-item-${c}-${E}`)}),r.jsx("input",{...S(w({preventKeyAction:m},{suppressRefError:!0})),className:"flex-grow border-none bg-transparent px-1 py-1 text-xs outline-none",placeholder:i.length===0?"Select HTTP verbs":"",size:1}),r.jsx("button",{className:"absolute inset-y-0 right-0 flex items-center pr-2",type:"button",...P(),children:r.jsx(y.FdDown,{className:"h-3 w-3 text-gray-50","aria-hidden":"true"})})]}),r.jsx("ul",{className:`ring-primary-dark bg-grey-900 text-s absolute z-10 w-full rounded-b ring-1 p-1 text-white ${!(m&&p.length)&&"hidden"}`,...k(),children:m&&p.map((j,E)=>r.jsx("li",{className:C(A===E&&"bg-primary-hover",I===j&&"font-bold","flex flex-col p-1 shadow-sm"),..._({item:j,index:E}),children:r.jsx("span",{children:j})},`${j}${E}`))})]})},Be=({value:t,options:n,errorMessage:e="",onChange:s,onBlur:a,"data-cy":o})=>{const[l,d]=u.useState(""),x=n.find(h=>h.name===t),i=l===""?n:n.filter(h=>h.name.toLowerCase().includes(l.toLowerCase()));return r.jsx(T.Combobox,{value:{name:t},onChange:h=>s(h.name),children:({open:h})=>r.jsxs("div",{className:"relative w-full","data-cy":o,children:[r.jsxs("div",{className:C("bg-grey-300 focus-within:ring-1 focus-within:ring-primary-dark relative w-full cursor-default overflow-hidden rounded text-left inline-flex",{"ring-1 ring-red-400":!x&&t||e,"ring-1 ring-primary-dark rounded-b-none":h,"overflow-visible":!x&&!h&&e}),children:[r.jsx(T.Combobox.Input,{className:C("bg-grey-300 text-s w-full border-none py-1 px-2 focus:outline-none rounded",{"!text-red-400":!x}),displayValue:p=>p.name,onChange:p=>d(p.target.value),style:{caretColor:"white"},onBlur:a}),r.jsxs("span",{className:"inset-y-0 right-0 flex items-center gap-1 pr-2",children:[!x&&!h&&e&&r.jsx("div",{className:"absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",children:e}),t?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{d(""),s("")},children:r.jsx(y.FdCloseNaked,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})}),r.jsx("span",{className:"bg-grey-50 h-3 w-[1px] rounded-full"})]}):null,r.jsx(T.Combobox.Button,{children:r.jsx(y.FdDown,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})})]})]}),r.jsx(T.Transition,{as:u.Fragment,leave:"transition ease-in durati pb-0.5on-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",afterLeave:()=>d(""),children:r.jsx(T.Combobox.Options,{className:"bg-grey-900 text-s text-grey-100 sm:text-s absolute z-50 max-h-60 w-full overflow-auto rounded-b ring-1 ring-primary-dark p-1 focus:outline-none",children:i.length===0?r.jsxs("div",{className:"text-s text-grey-200 relative cursor-default select-none px-0.5 py-0.5 ",children:[r.jsx(y.FdEmpty,{className:"inline h-4 w-4"})," Nothing found."]}):i.map((p,f)=>r.jsx(T.Combobox.Option,{className:({active:w})=>`relative cursor-default select-none ${w?"bg-primary-hover":""}`,value:p,children:({selected:w})=>r.jsx(r.Fragment,{children:r.jsx("span",{className:`block truncate p-2 py-1 ${w?"bg-primary-dark font-medium text-white":"font-normal"}`,children:p.name})})},f))})})]})},t)},We=({value:t,options:n,onChange:e,errorMessage:s,onBlur:a,"data-cy":o})=>{const[l,d]=u.useState(""),x=n.find(p=>p.name===t),i=x&&x.exposed,h=l===""?n:n.filter(p=>p.name.toLowerCase().includes(l.toLowerCase()));return r.jsx(T.Combobox,{value:{name:t},onChange:p=>e(p.name),children:({open:p})=>r.jsxs("div",{className:"relative","data-cy":o,children:[r.jsxs("div",{className:C("bg-grey-300 focus-within:ring-1 focus-within:ring-primary-dark relative w-full cursor-default overflow-hidden rounded text-left inline-flex",{"ring-1 ring-red-400":s,"ring-1 ring-yellow-500":i,"ring-1 ring-primary-dark rounded-b-none":p,"overflow-visible":!p&&s}),children:[r.jsx(T.Combobox.Input,{className:C("bg-grey-300 text-s w-full border-none py-1 px-2 focus:outline-none truncate rounded",{"!text-red-400":s,"!text-yellow-500":i}),style:{caretColor:"white"},displayValue:f=>f.name,onChange:f=>d(f.target.value),onBlur:a}),!p&&s&&r.jsx("div",{className:C("absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",{"!text-yellow-500 ring-yellow-500 bg-white":i}),children:s}),r.jsxs("span",{className:"inset-y-0 right-0 flex items-center gap-1 pr-2",children:[t?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{d(""),e("")},children:r.jsx(y.FdCloseNaked,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})}),r.jsx("span",{className:"bg-grey-50 h-3 w-[1px] rounded-full"})]}):null,r.jsx(T.Combobox.Button,{children:r.jsx(y.FdDown,{className:"text-grey-50 h-3 w-3","aria-hidden":"true"})})]})]}),r.jsx(T.Transition,{as:u.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",afterLeave:()=>d(""),children:r.jsx(T.Combobox.Options,{className:"bg-grey-900 text-s text-grey-100 sm:text-s absolute z-50 max-h-60 w-full overflow-auto rounded-b ring-1 ring-primary-dark p-1 focus:outline-none",children:h.length?h.map((f,w)=>r.jsx(T.Combobox.Option,{className:({active:v})=>`relative cursor-default select-none ${v?"bg-primary-hover":""}`,value:f,children:({selected:v})=>r.jsx(r.Fragment,{children:r.jsxs("span",{className:`text-s flex items-center gap-2 truncate p-2 py-1 ${v?"bg-primary-dark font-medium text-white":"font-normal"}`,children:[f.exposed&&r.jsx(y.FdWarningDanger,{className:"text-yellow-500"}),r.jsx("span",{className:"flex-1 truncate",title:f.name,children:f.name})]})})},w)):r.jsxs("div",{className:"text-s text-grey-200 relative cursor-default select-none px-0.5 py-0.5",children:[r.jsx(y.FdEmpty,{className:"inline h-4 w-4"})," Nothing found."]})})})]})})},Ee=({listeners:t,attributes:n})=>r.jsx("button",{"data-cy":"handler-row-drag-handle",...n,...t,children:r.jsx(y.FdDragHandle,{})}),we=t=>{var e;if(!t)return"";let n;ae.prototype.max=8;try{n=(e=new ae(t))==null?void 0:e.gen()}catch{n=""}return`Requests matching regex will be handled example: ${n}`},Ve=({id:t,class:n,method:e,pattern:s,verbs:a,regexPattern:o,asRegex:l,listeners:d,attributes:x})=>{var E;const[i,h]=u.useState({className:n,method:e,pattern:s,verbs:a,asRegex:l,regexPattern:o}),p=$(),f=p.getCatalog(),w=Object.values((f==null?void 0:f.singletons)||{}),v=(E=w.find(c=>c.name===i.className))==null?void 0:E.methods.map(({name:c,exposed:g})=>({name:c,exposed:g})),m=p.getNewlyCreatedHandlerId();function P(){const{className:c,method:g,asRegex:H,regexPattern:V,pattern:K,verbs:X}=i;return!!(c&&g&&(H?V:!K.endsWith("/"))&&X.length)}function k(){if(P()){const{className:c,method:g,asRegex:H,regexPattern:V,pattern:K,verbs:X}=i,Ce=H?{regexPattern:V}:{pattern:K};p.actions.updateHandler(t,{class:c,method:g,verbs:X,asRegex:H,...Ce}),p.actions.setEditingHandler(null)}}const S=async()=>{const c={className:n,method:e,pattern:s,regexPattern:o,verbs:a},g=F.omit(i,["id","isExpanded"]);if(!P()){m&&p.actions.deleteHandler(m),p.actions.setEditingHandler(null);return}if(!F.isEqual(c,g)){const{confirmed:H}=await p.actions.openModal({title:"Cancel Changes",type:b.ModalType.CONFIRM,color:b.ModalColor.DANGER,message:"Are you sure you want to cancel changes made to this Handler?",icon:"FdWarningDanger"});if(H){m&&m===t&&p.actions.deleteHandler(t),p.actions.setEditingHandler(null);return}}};b.useHotkeys("esc",()=>{setTimeout(()=>{S()},100)},[]),u.useEffect(()=>{z.subscribe(c=>{c===t&&k()})},[i,t]);const[A,_]=u.useState({className:!1,method:!1,pattern:!1,verbs:!1}),I=()=>{if(A.method&&!i.method)return"Method is required";if(v){const c=v==null?void 0:v.find(g=>g.name===i.method);if(i.method&&!c)return`The method "${i.method}" doesn't exist.`;if(c&&c.exposed)return`Method "${i.method}" is already exposed`}},j=()=>{var c;if(A.pattern){if(i.asRegex&&!i.regexPattern)return"Pattern is required";if(!i.asRegex&&((c=i.pattern)!=null&&c.endsWith("/")))return'Pattern should not end with a "/"'}};return r.jsxs("div",{className:"flex items-center gap-2 rounded-b py-2",children:[r.jsxs("div",{className:"flex w-60 flex-shrink-0 items-center gap-1",children:[r.jsx(Ee,{listeners:d,attributes:x},"grab-handle"),r.jsx(Be,{"data-cy":"handler-row-class-selector",value:i.className,onChange:c=>{h(g=>({...g,className:c}))},onBlur:()=>_(c=>({...c,className:!0})),options:w,errorMessage:A.className&&!i.className?"Class name is required":i.className!==""&&!w.find(c=>c.name===i.className)?`The singleton "${i.className}" doesn't exist.`:void 0},n)]}),r.jsx("div",{className:"w-60 flex-shrink-0",children:r.jsx(We,{"data-cy":"handler-row-method-selector",value:i.method,onChange:c=>{h(g=>({...g,method:c}))},options:v||[],errorMessage:I(),onBlur:()=>_(c=>({...c,method:!0}))})}),r.jsxs("div",{className:"relative w-60 flex-shrink-0 flex items-center gap-1 overflow-visible",children:[r.jsx(b.Tooltip,{label:i.asRegex?we(i.regexPattern):i.pattern&&!i.pattern.endsWith("/")?`Requests starting with /${i.pattern}/ will be handled`:"",container:N(),children:r.jsxs("div",{className:"relative w-full",children:[!i.asRegex&&r.jsx("span",{className:"absolute text-s inset-y-0 left-1 flex items-center gap-2",children:"/"}),r.jsx("input",{"data-cy":"handler-row-pattern-input",type:"text",className:C("bg-grey-300 text-s block w-full rounded p-1 pl-3 focus:outline-none focus:ring-1 focus:ring-primary-dark",{"focus:ring-red-400 ring-1 ring-red-400":A.pattern&&i.asRegex&&!i.regexPattern}),value:i.asRegex?i.regexPattern:i.pattern,onChange:c=>{h(g=>({...g,[i.asRegex?"regexPattern":"pattern"]:c.target.value}))},onBlur:()=>_(c=>({...c,pattern:!0})),placeholder:i.asRegex?"Required":""}),j()&&r.jsx("div",{className:"absolute inset-x-0 top-[25px] z-[1] rounded-b-sm bg-red-200 px-1 text-xs text-red-600 ring-1 ring-red-600",children:j()})]})}),(l?o:s)&&r.jsx("button",{onClick:c=>{c.stopPropagation(),h(g=>({...g,[i.asRegex?"regexPattern":"pattern"]:""}))},className:"absolute inset-y-0 right-6 flex items-center gap-2 pr-2",children:r.jsx(y.FdCloseNaked,{className:"text-grey-200 h-3 w-3","aria-hidden":"true"})}),r.jsx(b.Tooltip,{label:i.asRegex?"Requests matching this regex will be handled. Check the match with the __[Match regex command](https://developer.4d.com/docs/commands/match-regex)__":`Prefixes are considered as regular expressions already containing starting and ending /
|
|
4
4
|
|
|
5
|
-
__[documentation](https://developer.4d.com/qodly/4DQodlyPro/httpHandlers)__`,children:r.jsx("span",{className:"rounded hover:bg-gray-400/30 w-6 h-6 flex items-center content-center justify-center",children:r.jsx(y.FdInfoCircle,{className:"inline h-4 w-4 text-gray-100"})})})]}),r.jsx("div",{className:"w-20 px-2 flex justify-center",children:r.jsx(b.ControlledSwitch,{"data-cy":"handler-row-regex-switch",value:!!i.asRegex,onChange:c=>{const g=c?{regexPattern:s,asRegex:c}:{pattern:o,asRegex:c};h(
|
|
5
|
+
__[documentation](https://developer.4d.com/qodly/4DQodlyPro/httpHandlers)__`,container:N(),children:r.jsx("span",{className:"rounded hover:bg-gray-400/30 w-6 h-6 flex items-center content-center justify-center",children:r.jsx(y.FdInfoCircle,{className:"inline h-4 w-4 text-gray-100"})})})]}),r.jsx("div",{className:"w-20 px-2 flex justify-center",children:r.jsx(b.ControlledSwitch,{"data-cy":"handler-row-regex-switch",value:!!i.asRegex,onChange:c=>{const g=c?{regexPattern:s,asRegex:c}:{pattern:o,asRegex:c};h(H=>({...H,...g}))},className:`${i.asRegex?"bg-primary-dark":"bg-grey-300"}
|
|
6
6
|
relative inline-flex h-5 w-8 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`,children:r.jsx("span",{"aria-hidden":"true",className:`${i.asRegex?"translate-x-3":"translate-x-0"}
|
|
7
|
-
pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white ring-0 transition duration-200 ease-in-out`})})}),r.jsxs("div",{className:"flex flex-1 items-center",children:[r.jsx($e,{"data-cy":"handler-row-verbs-select",initialSelectedItems:i.verbs||[],onChange:c=>{h(g=>({...g,verbs:c}))},touched:S.verbs,onBlur:()=>P(c=>({...c,verbs:!0}))}),r.jsxs("div",{className:"flex items-center gap-0.5 px-2",children:[r.jsx(b.Tooltip,{label:"Duplicate Handler",className:"px-1 py-3",children:r.jsx("button",{"data-cy":"handler-row-duplicate-button",className:N("hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none opacity-50 cursor-not-allowed"),children:r.jsx(y.FdDuplicate,{})})}),r.jsx(b.Tooltip,{label:"Confirm Changes",className:"px-1 py-3",children:r.jsx("button",{"data-cy":"handler-row-save-button",className:N("hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",{"opacity-50 cursor-not-allowed":!R()}),onClick:_,children:r.jsx(y.FdCheckCircle,{})})}),r.jsx(b.Tooltip,{label:"Cancel Changes",className:"px-1 py-3",children:r.jsx("button",{"data-cy":"handler-row-cancel-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:T,children:r.jsx(y.FdClose,{})})})]})]})]})},ce=({id:t,class:n,method:e,pattern:s,verbs:a,isExpanded:o,regexPattern:l,asRegex:d})=>{var E;const{attributes:x,listeners:i,setNodeRef:h,transform:p,transition:f}=z.useSortable({id:t}),w={transform:Ce.CSS.Transform.toString(p),transition:f},v=U(),m=v.getEditingHandlerId(),R=d?l:s,_=v.getCatalog(),T=Object.values((_==null?void 0:_.singletons)||{}),S=(E=T==null?void 0:T.find(c=>c.name===n))==null?void 0:E.methods.map(({name:c,exposed:g})=>({name:c,exposed:g})),P=T==null?void 0:T.find(c=>c.name===n),k=S==null?void 0:S.find(c=>c.name===e),j=k&&k.exposed;return r.jsx("div",{className:"odd:bg-grey-500","data-cy":`handler-row-${m===t?"editing":"viewing"}`,ref:h,style:w,children:m===t?r.jsx(We,{id:t,class:n,method:e,pattern:s,verbs:a,isExpanded:o,regexPattern:l,asRegex:d,listeners:i,attributes:x}):r.jsxs("div",{className:"flex items-center gap-2 rounded-b py-2.5 text-grey-50",onDoubleClick:()=>{q.next(m),v.actions.setEditingHandler(t)},children:[r.jsxs("div",{className:"flex w-60 flex-shrink-0 items-center gap-1 ",children:[r.jsx(ve,{listeners:i,attributes:x},"grab-handle"),r.jsx("div",{className:"text-s w-full",children:n?r.jsxs("div",{className:N("flex items-center gap-2",!P&&"text-red-400"),children:[!P&&r.jsx(b.Tooltip,{label:`The singleton "${n}" doesn't exist.`,className:"!bg-red-300 !text-red-400",children:r.jsx("span",{className:"rounded p-0.5 hover:bg-red-400/30 pt-0.5 h-5 w-5 flex justify-center content-center",children:r.jsx(y.FdWarningDanger,{className:"inline h-4 w-4 pb-0.5 text-red-400"})})})," ",n]}):r.jsx("span",{className:"text-grey-200 italic",children:"undefined"})})]}),r.jsx("div",{className:"w-60 flex-shrink-0 ",children:r.jsx("div",{className:"text-s w-full",children:e?r.jsxs("div",{className:N("flex items-center gap-2",!k&&"text-red-400",j&&"text-yellow-400"),children:[!k&&r.jsx(b.Tooltip,{label:`The method "${e}" doesn't exist.`,className:"!bg-red-300 !text-red-400",children:r.jsx("span",{className:"rounded p-0.5 hover:bg-red-400/30 pt-0.5 h-5 w-5 flex justify-center content-center",children:r.jsx(y.FdWarningDanger,{className:"inline h-4 w-4 pb-0.5 text-red-400"})})})," ",j&&r.jsx(b.Tooltip,{label:`Method "${e}" is already exposed`,className:"!bg-yellow-100 !text-yellow-500",children:r.jsx("span",{className:"rounded p-0.5 hover:bg-red-400/30 pt-0.5 h-5 w-5 flex justify-center content-center",children:r.jsx(y.FdWarningDanger,{className:"inline h-4 w-4 pb-0.5 text-yellow-500"})})})," ",e]}):r.jsx("span",{className:"text-grey-200 italic",children:"undefined"})})}),r.jsx("div",{className:"text-s relative w-60 flex-shrink-0 ",children:R?r.jsx(b.Tooltip,{label:d?Ee(R):`Requests starting with /${R}/ will be handled`,children:r.jsx("span",{children:R})}):r.jsx("span",{className:"text-grey-200 italic",children:"/"})}),r.jsx("div",{className:"px-5 w-20 flex justify-center text-grey-200",children:d?r.jsx(y.FdRegex,{}):r.jsx(y.FdUnRegex,{})}),r.jsxs("div",{className:"flex flex-1 items-center",children:[r.jsx("div",{className:"text-s w-full",children:a.length?a.join(","):r.jsx("span",{className:"text-grey-200 italic",children:"undefined"})}),r.jsxs("div",{className:"flex items-center gap-0.5 px-2",children:[r.jsx(b.Tooltip,{label:"Duplicate Handler",className:"px-1 py-3",children:r.jsx("button",{"data-cy":"handler-row-duplicate-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:()=>v.actions.duplicateHandler(t),children:r.jsx(y.FdDuplicate,{})})}),r.jsx(b.Tooltip,{label:"Edit Handler",className:"px-1 py-3",children:r.jsx("button",{"data-cy":"handler-row-edit-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:()=>{q.next(m),v.actions.setEditingHandler(t)},children:r.jsx(y.FdPen,{})})}),r.jsx(b.Tooltip,{label:"Delete Handler",className:"px-1 py-3",placement:"top-end",children:r.jsx("button",{"data-cy":"handler-row-delete-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:async()=>{const{confirmed:c}=await v.actions.openModal({title:"Delete Handler",type:b.ModalType.CONFIRM,color:b.ModalColor.DANGER,message:"Are you sure you want to remove this Handler?",icon:"FdWarningDanger"});c&&v.actions.deleteHandler(t)},children:r.jsx(y.FdTrash,{})})})]})]})]})})},Ve=()=>{const t=U(),n=t.getHandlers(),e=t.getEditingHandlerId(),s=I.useSensors(I.useSensor(I.PointerSensor),I.useSensor(I.KeyboardSensor,{coordinateGetter:z.sortableKeyboardCoordinates})),[a,o]=u.useState(null),l=n.find(d=>d.id===a);return r.jsxs("div",{className:"bg-grey-700 flex h-full w-full flex-col text-white",children:[r.jsxs("div",{className:"flex items-center justify-between border-b border-black p-2",children:[!!t.actions.switchEditor&&r.jsx(De,{label:"Switch to text Editor",Icon:y.FdCode,onClick:()=>t.actions.switchEditor({config:{language:"json"},key:"editors:code"})}),r.jsxs("p",{className:"text-grey-100 text-s flex items-center gap-1",children:[r.jsx(y.FdInfoCircle,{className:"inline text-base text-white"})," HTTP handlers are evaluated in the order they are declared"]})]}),r.jsx("div",{className:"mt-1 flex flex-1 flex-col overflow-x-auto px-4",children:n.length?r.jsxs("div",{className:"flex h-full min-w-[1200px] flex-1 flex-col",children:[r.jsxs("div",{className:"mb-3 flex items-center gap-2 border-b",children:[r.jsx("div",{className:"w-60 flex-shrink-0 text-xs",children:r.jsx("span",{className:"pl-6",children:"Class"})}),r.jsx("div",{className:"w-60 flex-shrink-0 text-xs",children:"Method"}),r.jsx("div",{className:"w-60 flex-shrink-0 text-xs",children:"Pattern"}),r.jsx("div",{className:"w-20 px-2 text-center text-xs",children:"As Regex"}),r.jsxs("div",{className:"flex flex-1 items-center justify-between text-xs",children:[r.jsx("span",{children:"Verbs"}),r.jsx("div",{className:"flex items-center gap-2 text-2xl",children:r.jsx(b.Tooltip,{label:"Add a new HTTP Handler",children:r.jsx("button",{"data-cy":"handlers-editor-add-handler-button",disabled:!!e,onClick:()=>{q.next(e),t.actions.addHandler({class:"",isExpanded:!0,method:"",pattern:"",verbs:[],regexPattern:""})},className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none disabled:cursor-not-allowed disabled:opacity-30",children:r.jsx(y.FdPlus,{className:"h-5 w-5"})})})})]})]}),r.jsx("div",{className:"py-3","data-cy":"handlers-editor-list",children:r.jsxs(I.DndContext,{sensors:s,collisionDetection:I.closestCenter,onDragStart:d=>{o(d.active.id)},onDragEnd:d=>{const{active:x,over:i}=d;if(o(null),!(!x||!i)&&x.id!==(i==null?void 0:i.id)){const h=n.map(f=>f.id).indexOf(x.id),p=n.map(f=>f.id).indexOf(i.id);t.actions.updateHandlers(z.arrayMove(n,h,p))}},children:[r.jsx(z.SortableContext,{items:n,strategy:z.verticalListSortingStrategy,children:n.map(({id:d,...x})=>r.jsx(ce,{id:d,...x},d))}),r.jsx(I.DragOverlay,{children:a&&l?r.jsx("div",{className:"opacity-10",children:r.jsx(ce,{...l})}):null})]})})]}):r.jsxs("div",{className:"mt-6",children:[r.jsx("div",{children:r.jsx(y.FdEmpty,{className:"text-grey-200 mx-auto h-9 w-9"})}),r.jsxs("div",{className:"text-s text-grey-200 mx-auto mt-3 max-w-sm text-center",children:["There are no http handlers configured yet ",r.jsx("br",{}),"Please add a new one to add a new one."]}),r.jsx("div",{className:"mt-3 flex items-center justify-center",children:r.jsxs("button",{"data-cy":"handlers-editor-empty-add-handler-button",onClick:()=>{q.next(e),t.actions.addHandler({class:"",isExpanded:!0,method:"",pattern:"",verbs:[],regexPattern:""})},className:"bg-primary-dark text-s rounded px-2 py-1 flex items-center gap-1",children:[r.jsx(y.FdPlus,{className:"inline text-white h-4 w-4"})," Add New Handler"]})})]})})]})},we=()=>r.jsx(Ve,{}),je=u.createContext(void 0),Ke=(t,n)=>{switch(n.type){case"UPDATE_HANDLERS":return{...t,content:n.payload};case"SET_EDITING_HANDLER":{if(n.payload&&n.payload!==t.editing){const e=t.content.find(s=>s.id===t.editing);if(e&&!Object.values(M.omit(e,["id","verbs","asRegex","isExpanded"])).some(Boolean)&&e.verbs.length===0)return{...t,content:t.content.filter(a=>a.id!==e.id),editing:n.payload}}return{...t,editing:n.payload}}case"ADD_HANDLER":{const e=F.generate();return{...t,content:[...t.content,{...n.payload,id:e}],editing:e,newlyCreatedHandlerID:e}}case"UPDATE_HANDLER":return{...t,content:t.content.map(e=>e.id===n.id?{...e,...n.payload}:e),newlyCreatedHandlerID:null};case"DELETE_HANDLER":return{...t,content:t.content.filter(e=>e.id!==n.id)};case"TOGGLE_EXPANDED":return{...t,content:t.content.map(e=>e.id===n.id?{...e,isExpanded:!e.isExpanded}:e)};case"DUPLICATE_HANDLER":{const e=t.content.find(s=>s.id===n.id);return e?{...t,content:[...t.content,{...e,id:F.generate(),isExpanded:!0}]}:t}case"TOGGLE_ALL_EXPANDED":return{...t,content:t.content.map(e=>({...e,isExpanded:n.payload}))};case"SYNC_DATA":return{...t,content:n.payload.map(e=>{const s=t.content.find(a=>a.id===e.id);return s?{...e,...s}:e})};default:throw new Error("Unknown action type")}},Xe=({children:t,content:n})=>{const e={content:n,editing:null,newlyCreatedHandlerID:null},[s,a]=u.useReducer(Ke,e);return u.useEffect(()=>{a({type:"SYNC_DATA",payload:n})},[n]),r.jsx(je.Provider,{value:{state:s,dispatch:a},children:t})},Ye=()=>{const t=u.useContext(je);if(!t)throw new Error("useHTTPHandlers must be used within a HandlerProvider");return t},Je=()=>document.querySelector(`.${pe.HTTP_HANDLERS_EDITOR_SCOPE_CLASS}`)||document.body,Qe=()=>{const{modals:t,closeModal:n,editModal:e}=be();return r.jsx(r.Fragment,{children:t.map((s,a)=>r.jsx(b.Modal,{hasOverlay:a===0,...s,onClose:n,onEdit:e,container:Je()},s.id))})},Ze=({initialValue:t,onChange:n})=>{const e=U(),s=e.getHandlers(),a=u.useRef(t),o=u.useMemo(()=>Z(s),[s]);return u.useEffect(()=>{if(a.current!==t&&(a.current=t,t!==void 0))try{const l=G(t);M.isEqual(e.getHandlers(),l)||e.actions.updateHandlers(l)}catch(l){console.error("[HTTP Handlers Editor Standalone] Error while parsing the initial value:",l)}},[e,t]),b.useDidMountEffect(()=>{if(n)try{n(o)}catch(l){console.error("[HTTP Handlers Editor Standalone] Error on value stringify:",l)}},[n,o]),r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"h-screen bg-grey-900",children:r.jsx(we,{})}),r.jsx(Qe,{})]})},et=t=>{const n=ye();return r.jsx(he,{adapter:n,children:r.jsx(b.TipsProvider,{children:r.jsx(Ze,{...t})})})},tt=({initialValue:t=[],catalog:n,...e})=>r.jsx(ge,{content:t,catalog:n,children:r.jsx(et,{...e})});exports.HTTP_HANDLERS_EDITOR_SCOPE_CLASS=pe.HTTP_HANDLERS_EDITOR_SCOPE_CLASS;exports.$handlerSubject=q;exports.EditorStateAdapterProvider=he;exports.EditorStateContext=B;exports.HTTPHandlersEditor=we;exports.HandlerProvider=Xe;exports.ReducerAdapterProvider=ge;exports.Standalone=tt;exports.getDefaultInitialState=re;exports.handlerReducer=ne;exports.normalizeHandlers=G;exports.serializeHandlers=Z;exports.useEditorStateAdapter=U;exports.useHTTPHandlers=Ye;exports.useModals=be;exports.useReducerAdapter=ye;exports.useReduxAdapter=Ue;
|
|
7
|
+
pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white ring-0 transition duration-200 ease-in-out`})})}),r.jsxs("div",{className:"flex flex-1 items-center",children:[r.jsx(Ge,{"data-cy":"handler-row-verbs-select",initialSelectedItems:i.verbs||[],onChange:c=>{h(g=>({...g,verbs:c}))},touched:A.verbs,onBlur:()=>_(c=>({...c,verbs:!0}))}),r.jsxs("div",{className:"flex items-center gap-0.5 px-2",children:[r.jsx(b.Tooltip,{label:"Duplicate Handler",className:"px-1 py-3",container:N(),children:r.jsx("button",{"data-cy":"handler-row-duplicate-button",className:C("hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none opacity-50 cursor-not-allowed"),children:r.jsx(y.FdDuplicate,{})})}),r.jsx(b.Tooltip,{label:"Confirm Changes",className:"px-1 py-3",container:N(),children:r.jsx("button",{"data-cy":"handler-row-save-button",className:C("hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",{"opacity-50 cursor-not-allowed":!P()}),onClick:k,children:r.jsx(y.FdCheckCircle,{})})}),r.jsx(b.Tooltip,{label:"Cancel Changes",className:"px-1 py-3",container:N(),children:r.jsx("button",{"data-cy":"handler-row-cancel-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:S,children:r.jsx(y.FdClose,{})})})]})]})]})},ue=({id:t,class:n,method:e,pattern:s,verbs:a,isExpanded:o,regexPattern:l,asRegex:d})=>{var E;const{attributes:x,listeners:i,setNodeRef:h,transform:p,transition:f}=U.useSortable({id:t}),w={transform:De.CSS.Transform.toString(p),transition:f},v=$(),m=v.getEditingHandlerId(),P=d?l:s,k=v.getCatalog(),S=Object.values((k==null?void 0:k.singletons)||{}),A=(E=S==null?void 0:S.find(c=>c.name===n))==null?void 0:E.methods.map(({name:c,exposed:g})=>({name:c,exposed:g})),_=S==null?void 0:S.find(c=>c.name===n),I=A==null?void 0:A.find(c=>c.name===e),j=I&&I.exposed;return r.jsx("div",{className:"odd:bg-grey-500","data-cy":`handler-row-${m===t?"editing":"viewing"}`,ref:h,style:w,children:m===t?r.jsx(Ve,{id:t,class:n,method:e,pattern:s,verbs:a,isExpanded:o,regexPattern:l,asRegex:d,listeners:i,attributes:x}):r.jsxs("div",{className:"flex items-center gap-2 rounded-b py-2.5 text-grey-50",onDoubleClick:()=>{z.next(m),v.actions.setEditingHandler(t)},children:[r.jsxs("div",{className:"flex w-60 flex-shrink-0 items-center gap-1 ",children:[r.jsx(Ee,{listeners:i,attributes:x},"grab-handle"),r.jsx("div",{className:"text-s w-full",children:n?r.jsxs("div",{className:C("flex items-center gap-2",!_&&"text-red-400"),children:[!_&&r.jsx(b.Tooltip,{label:`The singleton "${n}" doesn't exist.`,className:"!bg-red-300 !text-red-400",container:N(),children:r.jsx("span",{className:"rounded p-0.5 hover:bg-red-400/30 pt-0.5 h-5 w-5 flex justify-center content-center",children:r.jsx(y.FdWarningDanger,{className:"inline h-4 w-4 pb-0.5 text-red-400"})})})," ",n]}):r.jsx("span",{className:"text-grey-200 italic",children:"undefined"})})]}),r.jsx("div",{className:"w-60 flex-shrink-0 ",children:r.jsx("div",{className:"text-s w-full",children:e?r.jsxs("div",{className:C("flex items-center gap-2",!I&&"text-red-400",j&&"text-yellow-400"),children:[!I&&r.jsx(b.Tooltip,{label:`The method "${e}" doesn't exist.`,className:"!bg-red-300 !text-red-400",container:N(),children:r.jsx("span",{className:"rounded p-0.5 hover:bg-red-400/30 pt-0.5 h-5 w-5 flex justify-center content-center",children:r.jsx(y.FdWarningDanger,{className:"inline h-4 w-4 pb-0.5 text-red-400"})})})," ",j&&r.jsx(b.Tooltip,{label:`Method "${e}" is already exposed`,className:"!bg-yellow-100 !text-yellow-500",container:N(),children:r.jsx("span",{className:"rounded p-0.5 hover:bg-red-400/30 pt-0.5 h-5 w-5 flex justify-center content-center",children:r.jsx(y.FdWarningDanger,{className:"inline h-4 w-4 pb-0.5 text-yellow-500"})})})," ",e]}):r.jsx("span",{className:"text-grey-200 italic",children:"undefined"})})}),r.jsx("div",{className:"text-s relative w-60 flex-shrink-0 ",children:P?r.jsx(b.Tooltip,{label:d?we(P):`Requests starting with /${P}/ will be handled`,container:N(),children:r.jsx("span",{children:P})}):r.jsx("span",{className:"text-grey-200 italic",children:"/"})}),r.jsx("div",{className:"px-5 w-20 flex justify-center text-grey-200",children:d?r.jsx(y.FdRegex,{}):r.jsx(y.FdUnRegex,{})}),r.jsxs("div",{className:"flex flex-1 items-center",children:[r.jsx("div",{className:"text-s w-full",children:a.length?a.join(","):r.jsx("span",{className:"text-grey-200 italic",children:"undefined"})}),r.jsxs("div",{className:"flex items-center gap-0.5 px-2",children:[r.jsx(b.Tooltip,{label:"Duplicate Handler",className:"px-1 py-3",container:N(),children:r.jsx("button",{"data-cy":"handler-row-duplicate-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:()=>v.actions.duplicateHandler(t),children:r.jsx(y.FdDuplicate,{})})}),r.jsx(b.Tooltip,{label:"Edit Handler",className:"px-1 py-3",container:N(),children:r.jsx("button",{"data-cy":"handler-row-edit-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:()=>{z.next(m),v.actions.setEditingHandler(t)},children:r.jsx(y.FdPen,{})})}),r.jsx(b.Tooltip,{label:"Delete Handler",className:"px-1 py-3",placement:"top-end",container:N(),children:r.jsx("button",{"data-cy":"handler-row-delete-button",className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none",onClick:async()=>{const{confirmed:c}=await v.actions.openModal({title:"Delete Handler",type:b.ModalType.CONFIRM,color:b.ModalColor.DANGER,message:"Are you sure you want to remove this Handler?",icon:"FdWarningDanger"});c&&v.actions.deleteHandler(t)},children:r.jsx(y.FdTrash,{})})})]})]})]})})},Ke=()=>{const t=$(),n=t.getHandlers(),e=t.getEditingHandlerId(),s=L.useSensors(L.useSensor(L.PointerSensor),L.useSensor(L.KeyboardSensor,{coordinateGetter:U.sortableKeyboardCoordinates})),[a,o]=u.useState(null),l=n.find(d=>d.id===a);return r.jsxs("div",{className:"bg-grey-700 flex h-full w-full flex-col text-white",children:[r.jsxs("div",{className:"flex items-center justify-between border-b border-black p-2",children:[!!t.actions.switchEditor&&r.jsx(Te,{label:"Switch to text Editor",Icon:y.FdCode,onClick:()=>t.actions.switchEditor({config:{language:"json"},key:"editors:code"})}),r.jsxs("p",{className:"text-grey-100 text-s flex items-center gap-1",children:[r.jsx(y.FdInfoCircle,{className:"inline text-base text-white"})," HTTP handlers are evaluated in the order they are declared"]})]}),r.jsx("div",{className:"mt-1 flex flex-1 flex-col overflow-x-auto px-4",children:n.length?r.jsxs("div",{className:"flex h-full min-w-[1200px] flex-1 flex-col",children:[r.jsxs("div",{className:"mb-3 flex items-center gap-2 border-b",children:[r.jsx("div",{className:"w-60 flex-shrink-0 text-xs",children:r.jsx("span",{className:"pl-6",children:"Class"})}),r.jsx("div",{className:"w-60 flex-shrink-0 text-xs",children:"Method"}),r.jsx("div",{className:"w-60 flex-shrink-0 text-xs",children:"Pattern"}),r.jsx("div",{className:"w-20 px-2 text-center text-xs",children:"As Regex"}),r.jsxs("div",{className:"flex flex-1 items-center justify-between text-xs",children:[r.jsx("span",{children:"Verbs"}),r.jsx("div",{className:"flex items-center gap-2 text-2xl",children:r.jsx(b.Tooltip,{label:"Add a new HTTP Handler",container:N(),children:r.jsx("button",{"data-cy":"handlers-editor-add-handler-button",disabled:!!e,onClick:()=>{z.next(e),t.actions.addHandler({class:"",isExpanded:!0,method:"",pattern:"",verbs:[],regexPattern:""})},className:"hover:bg-primary-hover rounded p-1 text-gray-100 hover:text-white active:outline-none disabled:cursor-not-allowed disabled:opacity-30",children:r.jsx(y.FdPlus,{className:"h-5 w-5"})})})})]})]}),r.jsx("div",{className:"py-3","data-cy":"handlers-editor-list",children:r.jsxs(L.DndContext,{sensors:s,collisionDetection:L.closestCenter,onDragStart:d=>{o(d.active.id)},onDragEnd:d=>{const{active:x,over:i}=d;if(o(null),!(!x||!i)&&x.id!==(i==null?void 0:i.id)){const h=n.map(f=>f.id).indexOf(x.id),p=n.map(f=>f.id).indexOf(i.id);t.actions.updateHandlers(U.arrayMove(n,h,p))}},children:[r.jsx(U.SortableContext,{items:n,strategy:U.verticalListSortingStrategy,children:n.map(({id:d,...x})=>r.jsx(ue,{id:d,...x},d))}),r.jsx(L.DragOverlay,{children:a&&l?r.jsx("div",{className:"opacity-10",children:r.jsx(ue,{...l})}):null})]})})]}):r.jsxs("div",{className:"mt-6",children:[r.jsx("div",{children:r.jsx(y.FdEmpty,{className:"text-grey-200 mx-auto h-9 w-9"})}),r.jsxs("div",{className:"text-s text-grey-200 mx-auto mt-3 max-w-sm text-center",children:["There are no http handlers configured yet ",r.jsx("br",{}),"Please add a new one to add a new one."]}),r.jsx("div",{className:"mt-3 flex items-center justify-center",children:r.jsxs("button",{"data-cy":"handlers-editor-empty-add-handler-button",onClick:()=>{z.next(e),t.actions.addHandler({class:"",isExpanded:!0,method:"",pattern:"",verbs:[],regexPattern:""})},className:"bg-primary-dark text-s rounded px-2 py-1 flex items-center gap-1",children:[r.jsx(y.FdPlus,{className:"inline text-white h-4 w-4"})," Add New Handler"]})})]})})]})},je=()=>r.jsx(Ke,{}),Ne=u.createContext(void 0),Xe=(t,n)=>{switch(n.type){case"UPDATE_HANDLERS":return{...t,content:n.payload};case"SET_EDITING_HANDLER":{if(n.payload&&n.payload!==t.editing){const e=t.content.find(s=>s.id===t.editing);if(e&&!Object.values(F.omit(e,["id","verbs","asRegex","isExpanded"])).some(Boolean)&&e.verbs.length===0)return{...t,content:t.content.filter(a=>a.id!==e.id),editing:n.payload}}return{...t,editing:n.payload}}case"ADD_HANDLER":{const e=q.generate();return{...t,content:[...t.content,{...n.payload,id:e}],editing:e,newlyCreatedHandlerID:e}}case"UPDATE_HANDLER":return{...t,content:t.content.map(e=>e.id===n.id?{...e,...n.payload}:e),newlyCreatedHandlerID:null};case"DELETE_HANDLER":return{...t,content:t.content.filter(e=>e.id!==n.id)};case"TOGGLE_EXPANDED":return{...t,content:t.content.map(e=>e.id===n.id?{...e,isExpanded:!e.isExpanded}:e)};case"DUPLICATE_HANDLER":{const e=t.content.find(s=>s.id===n.id);return e?{...t,content:[...t.content,{...e,id:q.generate(),isExpanded:!0}]}:t}case"TOGGLE_ALL_EXPANDED":return{...t,content:t.content.map(e=>({...e,isExpanded:n.payload}))};case"SYNC_DATA":return{...t,content:n.payload.map(e=>{const s=t.content.find(a=>a.id===e.id);return s?{...e,...s}:e})};default:throw new Error("Unknown action type")}},Ye=({children:t,content:n})=>{const e={content:n,editing:null,newlyCreatedHandlerID:null},[s,a]=u.useReducer(Xe,e);return u.useEffect(()=>{a({type:"SYNC_DATA",payload:n})},[n]),r.jsx(Ne.Provider,{value:{state:s,dispatch:a},children:t})},Je=()=>{const t=u.useContext(Ne);if(!t)throw new Error("useHTTPHandlers must be used within a HandlerProvider");return t},Qe=()=>{const{modals:t,closeModal:n,editModal:e}=ve();return r.jsx(r.Fragment,{children:t.map((s,a)=>r.jsx(b.Modal,{hasOverlay:a===0,...s,onClose:n,onEdit:e,container:N()},s.id))})},Ze=({initialValue:t,onChange:n})=>{const e=$(),s=e.getHandlers(),a=u.useRef(t),o=u.useMemo(()=>ee(s),[s]);return u.useEffect(()=>{if(a.current!==t&&(a.current=t,t!==void 0))try{const l=B(t);F.isEqual(e.getHandlers(),l)||e.actions.updateHandlers(l)}catch(l){console.error("[HTTP Handlers Editor Standalone] Error while parsing the initial value:",l)}},[e,t]),b.useDidMountEffect(()=>{if(n)try{n(o)}catch(l){console.error("[HTTP Handlers Editor Standalone] Error on value stringify:",l)}},[n,o]),r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"h-screen bg-grey-900",children:r.jsx(je,{})}),r.jsx(Qe,{})]})},et=t=>{const n=be();return r.jsx(fe,{adapter:n,children:r.jsx(b.TipsProvider,{children:r.jsx(Ze,{...t})})})},tt=({initialValue:t=[],catalog:n,...e})=>r.jsx(ye,{content:t,catalog:n,children:r.jsx(et,{...e})});exports.HTTP_HANDLERS_EDITOR_SCOPE_CLASS=xe.HTTP_HANDLERS_EDITOR_SCOPE_CLASS;exports.$handlerSubject=z;exports.EditorStateAdapterProvider=fe;exports.EditorStateContext=W;exports.HTTPHandlersEditor=je;exports.HandlerProvider=Ye;exports.ReducerAdapterProvider=ye;exports.Standalone=tt;exports.getDefaultInitialState=se;exports.handlerReducer=re;exports.normalizeHandlers=B;exports.serializeHandlers=ee;exports.useEditorStateAdapter=$;exports.useHTTPHandlers=Je;exports.useModals=ve;exports.useReducerAdapter=be;exports.useReduxAdapter=$e;
|
|
8
8
|
//# sourceMappingURL=index.cjs.js.map
|