theme.keycloak.v2.admin.resources.assets.CodeEditor-C-nZkUJx.js Maven / Gradle / Ivy
import*as s from"react";import ce,{forwardRef as pr,useImperativeHandle as fr,Fragment as dr,useMemo as pe,useRef as j,useReducer as mr,useEffect as H,useCallback as _,memo as ft,useState as Be}from"react";import{E as hr,d5 as de,d6 as me,d7 as ht,d8 as vt,o as dt,_ as vr,I as gr,i as we,a9 as $t,aK as yr,m as J,B as br,cT as wr}from"./main-C7ps2lmX.js";import{C as Er}from"./copy-icon-ACZmDH8e.js";import{E as gt,c as yt,a as Or,b as bt}from"./EmptyStateFooter-DqmBOP2I.js";import{E as wt,a as Et,b as et}from"./EmptyStateActions-DWNUFByn.js";const tt={button:"pf-v5-c-button",fileUpload:"pf-v5-c-file-upload",fileUploadFileDetails:"pf-v5-c-file-upload__file-details",fileUploadFileDetailsSpinner:"pf-v5-c-file-upload__file-details-spinner",fileUploadFileSelect:"pf-v5-c-file-upload__file-select",formControl:"pf-v5-c-form-control",modifiers:{dragHover:"pf-m-drag-hover",loading:"pf-m-loading",control:"pf-m-control"}};var Bt={exports:{}},Dr="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",jr=Dr,Cr=jr;function Nt(){}function Ht(){}Ht.resetWarningCache=Nt;var Sr=function(){function e(n,o,i,c,l,p){if(p!==Cr){var m=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw m.name="Invariant Violation",m}}e.isRequired=e;function t(){return e}var r={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:Ht,resetWarningCache:Nt};return r.PropTypes=r,r};Bt.exports=Sr();var Tr=Bt.exports;const g=hr(Tr);var xr=new Map([["aac","audio/aac"],["abw","application/x-abiword"],["arc","application/x-freearc"],["avif","image/avif"],["avi","video/x-msvideo"],["azw","application/vnd.amazon.ebook"],["bin","application/octet-stream"],["bmp","image/bmp"],["bz","application/x-bzip"],["bz2","application/x-bzip2"],["cda","application/x-cdf"],["csh","application/x-csh"],["css","text/css"],["csv","text/csv"],["doc","application/msword"],["docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],["eot","application/vnd.ms-fontobject"],["epub","application/epub+zip"],["gz","application/gzip"],["gif","image/gif"],["heic","image/heic"],["heif","image/heif"],["htm","text/html"],["html","text/html"],["ico","image/vnd.microsoft.icon"],["ics","text/calendar"],["jar","application/java-archive"],["jpeg","image/jpeg"],["jpg","image/jpeg"],["js","text/javascript"],["json","application/json"],["jsonld","application/ld+json"],["mid","audio/midi"],["midi","audio/midi"],["mjs","text/javascript"],["mp3","audio/mpeg"],["mp4","video/mp4"],["mpeg","video/mpeg"],["mpkg","application/vnd.apple.installer+xml"],["odp","application/vnd.oasis.opendocument.presentation"],["ods","application/vnd.oasis.opendocument.spreadsheet"],["odt","application/vnd.oasis.opendocument.text"],["oga","audio/ogg"],["ogv","video/ogg"],["ogx","application/ogg"],["opus","audio/opus"],["otf","font/otf"],["png","image/png"],["pdf","application/pdf"],["php","application/x-httpd-php"],["ppt","application/vnd.ms-powerpoint"],["pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation"],["rar","application/vnd.rar"],["rtf","application/rtf"],["sh","application/x-sh"],["svg","image/svg+xml"],["swf","application/x-shockwave-flash"],["tar","application/x-tar"],["tif","image/tiff"],["tiff","image/tiff"],["ts","video/mp2t"],["ttf","font/ttf"],["txt","text/plain"],["vsd","application/vnd.visio"],["wav","audio/wav"],["weba","audio/webm"],["webm","video/webm"],["webp","image/webp"],["woff","font/woff"],["woff2","font/woff2"],["xhtml","application/xhtml+xml"],["xls","application/vnd.ms-excel"],["xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],["xml","application/xml"],["xul","application/vnd.mozilla.xul+xml"],["zip","application/zip"],["7z","application/x-7z-compressed"],["mkv","video/x-matroska"],["mov","video/quicktime"],["msg","application/vnd.ms-outlook"]]);function Se(e,t){var r=Pr(e);if(typeof r.path!="string"){var n=e.webkitRelativePath;Object.defineProperty(r,"path",{value:typeof t=="string"?t:typeof n=="string"&&n.length>0?n:e.name,writable:!1,configurable:!1,enumerable:!0})}return r}function Pr(e){var t=e.name,r=t&&t.lastIndexOf(".")!==-1;if(r&&!e.type){var n=t.split(".").pop().toLowerCase(),o=xr.get(n);o&&Object.defineProperty(e,"type",{value:o,writable:!1,configurable:!1,enumerable:!0})}return e}var Ar=[".DS_Store","Thumbs.db"];function Fr(e){return de(this,void 0,void 0,function(){return me(this,function(t){return Ne(e)&&_r(e.dataTransfer)?[2,kr(e.dataTransfer,e.type)]:Mr(e)?[2,Ir(e)]:Array.isArray(e)&&e.every(function(r){return"getFile"in r&&typeof r.getFile=="function"})?[2,Rr(e)]:[2,[]]})})}function _r(e){return Ne(e)}function Mr(e){return Ne(e)&&Ne(e.target)}function Ne(e){return typeof e=="object"&&e!==null}function Ir(e){return ct(e.target.files).map(function(t){return Se(t)})}function Rr(e){return de(this,void 0,void 0,function(){var t;return me(this,function(r){switch(r.label){case 0:return[4,Promise.all(e.map(function(n){return n.getFile()}))];case 1:return t=r.sent(),[2,t.map(function(n){return Se(n)})]}})})}function kr(e,t){return de(this,void 0,void 0,function(){var r,n;return me(this,function(o){switch(o.label){case 0:return e.items?(r=ct(e.items).filter(function(i){return i.kind==="file"}),t!=="drop"?[2,r]:[4,Promise.all(r.map(zr))]):[3,2];case 1:return n=o.sent(),[2,Ot(Ut(n))];case 2:return[2,Ot(ct(e.files).map(function(i){return Se(i)}))]}})})}function Ot(e){return e.filter(function(t){return Ar.indexOf(t.name)===-1})}function ct(e){if(e===null)return[];for(var t=[],r=0;re.length)&&(t=e.length);for(var r=0,n=new Array(t);rr)return[!1,Tt(r)];if(e.sizer)return[!1,Tt(r)]}return[!0,null]}function ae(e){return e!=null}function Zr(e){var t=e.files,r=e.accept,n=e.minSize,o=e.maxSize,i=e.multiple,c=e.maxFiles,l=e.validator;return!i&&t.length>1||i&&c>=1&&t.length>c?!1:t.every(function(p){var m=qt(p,r),T=De(m,1),v=T[0],M=Lt(p,n,o),U=De(M,1),V=U[0],K=l?l(p):null;return v&&V&&!K})}function He(e){return typeof e.isPropagationStopped=="function"?e.isPropagationStopped():typeof e.cancelBubble<"u"?e.cancelBubble:!1}function Re(e){return e.dataTransfer?Array.prototype.some.call(e.dataTransfer.types,function(t){return t==="Files"||t==="application/x-moz-file"}):!!e.target&&!!e.target.files}function Pt(e){e.preventDefault()}function en(e){return e.indexOf("MSIE")!==-1||e.indexOf("Trident/")!==-1}function tn(e){return e.indexOf("Edge/")!==-1}function rn(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return en(e)||tn(e)}function Q(){for(var e=arguments.length,t=new Array(e),r=0;r1?o-1:0),c=1;ce.length)&&(t=e.length);for(var r=0,n=new Array(t);r=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function wn(e,t){if(e==null)return{};var r={},n=Object.keys(e),o,i;for(i=0;i=0)&&(r[o]=e[o]);return r}var Ke=pr(function(e,t){var r=e.children,n=Ue(e,sn),o=En(n),i=o.open,c=Ue(o,un);return fr(t,function(){return{open:i}},[i]),ce.createElement(dr,null,r(E(E({},c),{},{open:i})))});Ke.displayName="Dropzone";var Qt={disabled:!1,getFilesFromEvent:Fr,maxSize:1/0,minSize:0,multiple:!0,maxFiles:0,preventDropOnDocument:!0,noClick:!1,noKeyboard:!1,noDrag:!1,noDragEventsBubbling:!1,validator:null,useFsAccessApi:!0,autoFocus:!1};Ke.defaultProps=Qt;Ke.propTypes={children:g.func,accept:g.objectOf(g.arrayOf(g.string)),multiple:g.bool,preventDropOnDocument:g.bool,noClick:g.bool,noKeyboard:g.bool,noDrag:g.bool,noDragEventsBubbling:g.bool,minSize:g.number,maxSize:g.number,maxFiles:g.number,disabled:g.bool,getFilesFromEvent:g.func,onFileDialogCancel:g.func,onFileDialogOpen:g.func,useFsAccessApi:g.bool,autoFocus:g.bool,onDragEnter:g.func,onDragLeave:g.func,onDragOver:g.func,onDrop:g.func,onDropAccepted:g.func,onDropRejected:g.func,onError:g.func,validator:g.func};var pt={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function En(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=E(E({},Qt),e),r=t.accept,n=t.disabled,o=t.getFilesFromEvent,i=t.maxSize,c=t.minSize,l=t.multiple,p=t.maxFiles,m=t.onDragEnter,T=t.onDragLeave,v=t.onDragOver,M=t.onDrop,U=t.onDropAccepted,V=t.onDropRejected,K=t.onFileDialogCancel,X=t.onFileDialogOpen,te=t.useFsAccessApi,x=t.autoFocus,W=t.preventDropOnDocument,z=t.noClick,y=t.noKeyboard,O=t.noDrag,h=t.noDragEventsBubbling,q=t.onError,b=t.validator,d=pe(function(){return an(r)},[r]),I=pe(function(){return on(r)},[r]),L=pe(function(){return typeof X=="function"?X:Ft},[X]),G=pe(function(){return typeof K=="function"?K:Ft},[K]),w=j(null),f=j(null),D=mr(On,pt),oe=rt(D,2),Z=oe[0],P=oe[1],he=Z.isFocused,C=Z.isFileDialogActive,F=j(typeof window<"u"&&window.isSecureContext&&te&&nn()),re=function(){!F.current&&C&&setTimeout(function(){if(f.current){var u=f.current.files;u.length||(P({type:"closeDialog"}),G())}},300)};H(function(){return window.addEventListener("focus",re,!1),function(){window.removeEventListener("focus",re,!1)}},[f,C,G,F]);var $=j([]),ve=function(u){w.current&&w.current.contains(u.target)||(u.preventDefault(),$.current=[])};H(function(){return W&&(document.addEventListener("dragover",Pt,!1),document.addEventListener("drop",ve,!1)),function(){W&&(document.removeEventListener("dragover",Pt),document.removeEventListener("drop",ve))}},[w,W]),H(function(){return!n&&x&&w.current&&w.current.focus(),function(){}},[w,x,n]);var ee=_(function(a){q?q(a):console.error(a)},[q]),xe=_(function(a){a.preventDefault(),a.persist(),Me(a),$.current=[].concat(dn($.current),[a.target]),Re(a)&&Promise.resolve(o(a)).then(function(u){if(!(He(a)&&!h)){var S=u.length,A=S>0&&Zr({files:u,accept:d,minSize:c,maxSize:i,multiple:l,maxFiles:p,validator:b}),R=S>0&&!A;P({isDragAccept:A,isDragReject:R,isDragActive:!0,type:"setDraggedFiles"}),m&&m(a)}}).catch(function(u){return ee(u)})},[o,m,ee,h,d,c,i,l,p,b]),Pe=_(function(a){a.preventDefault(),a.persist(),Me(a);var u=Re(a);if(u&&a.dataTransfer)try{a.dataTransfer.dropEffect="copy"}catch{}return u&&v&&v(a),!1},[v,h]),Ae=_(function(a){a.preventDefault(),a.persist(),Me(a);var u=$.current.filter(function(A){return w.current&&w.current.contains(A)}),S=u.indexOf(a.target);S!==-1&&u.splice(S,1),$.current=u,!(u.length>0)&&(P({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Re(a)&&T&&T(a))},[w,T,h]),ie=_(function(a,u){var S=[],A=[];a.forEach(function(R){var be=qt(R,d),ue=rt(be,2),Le=ue[0],Ge=ue[1],Ye=Lt(R,c,i),Ie=rt(Ye,2),Je=Ie[0],Qe=Ie[1],Xe=b?b(R):null;if(Le&&Je&&!Xe)S.push(R);else{var Ze=[Ge,Qe];Xe&&(Ze=Ze.concat(Xe)),A.push({file:R,errors:Ze.filter(function(ur){return ur})})}}),(!l&&S.length>1||l&&p>=1&&S.length>p)&&(S.forEach(function(R){A.push({file:R,errors:[Xr]})}),S.splice(0)),P({acceptedFiles:S,fileRejections:A,type:"setFiles"}),M&&M(S,A,u),A.length>0&&V&&V(A,u),S.length>0&&U&&U(S,u)},[P,l,d,c,i,p,M,U,V,b]),le=_(function(a){a.preventDefault(),a.persist(),Me(a),$.current=[],Re(a)&&Promise.resolve(o(a)).then(function(u){He(a)&&!h||ie(u,a)}).catch(function(u){return ee(u)}),P({type:"reset"})},[o,ie,ee,h]),Y=_(function(){if(F.current){P({type:"openDialog"}),L();var a={multiple:l,types:I};window.showOpenFilePicker(a).then(function(u){return o(u)}).then(function(u){ie(u,null),P({type:"closeDialog"})}).catch(function(u){cn(u)?(G(u),P({type:"closeDialog"})):ln(u)?(F.current=!1,f.current?(f.current.value=null,f.current.click()):ee(new Error("Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no was provided."))):ee(u)});return}f.current&&(P({type:"openDialog"}),L(),f.current.value=null,f.current.click())},[P,L,G,te,ie,ee,I,l]),ge=_(function(a){!w.current||!w.current.isEqualNode(a.target)||(a.key===" "||a.key==="Enter"||a.keyCode===32||a.keyCode===13)&&(a.preventDefault(),Y())},[w,Y]),ye=_(function(){P({type:"focus"})},[]),Fe=_(function(){P({type:"blur"})},[]),mt=_(function(){z||(rn()?setTimeout(Y,0):Y())},[z,Y]),se=function(u){return n?null:u},qe=function(u){return y?null:se(u)},_e=function(u){return O?null:se(u)},Me=function(u){h&&u.stopPropagation()},cr=pe(function(){return function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},u=a.refKey,S=u===void 0?"ref":u,A=a.role,R=a.onKeyDown,be=a.onFocus,ue=a.onBlur,Le=a.onClick,Ge=a.onDragEnter,Ye=a.onDragOver,Ie=a.onDragLeave,Je=a.onDrop,Qe=Ue(a,pn);return E(E(ut({onKeyDown:qe(Q(R,ge)),onFocus:qe(Q(be,ye)),onBlur:qe(Q(ue,Fe)),onClick:se(Q(Le,mt)),onDragEnter:_e(Q(Ge,xe)),onDragOver:_e(Q(Ye,Pe)),onDragLeave:_e(Q(Ie,Ae)),onDrop:_e(Q(Je,le)),role:typeof A=="string"&&A!==""?A:"presentation"},S,w),!n&&!y?{tabIndex:0}:{}),Qe)}},[w,ge,ye,Fe,mt,xe,Pe,Ae,le,y,O,n]),lr=_(function(a){a.stopPropagation()},[]),sr=pe(function(){return function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},u=a.refKey,S=u===void 0?"ref":u,A=a.onChange,R=a.onClick,be=Ue(a,fn),ue=ut({accept:d,multiple:l,type:"file",style:{display:"none"},onChange:se(Q(A,le)),onClick:se(Q(R,lr)),tabIndex:-1},S,f);return E(E({},ue),be)}},[f,r,l,le,n]);return E(E({},Z),{},{isFocused:he&&!n,getRootProps:cr,getInputProps:sr,rootRef:w,inputRef:f,open:se(Y)})}function On(e,t){switch(t.type){case"focus":return E(E({},e),{},{isFocused:!0});case"blur":return E(E({},e),{},{isFocused:!1});case"openDialog":return E(E({},pt),{},{isFileDialogActive:!0});case"closeDialog":return E(E({},e),{},{isFileDialogActive:!1});case"setDraggedFiles":return E(E({},e),{},{isDragActive:t.isDragActive,isDragAccept:t.isDragAccept,isDragReject:t.isDragReject});case"setFiles":return E(E({},e),{},{acceptedFiles:t.acceptedFiles,fileRejections:t.fileRejections});case"reset":return E({},pt);default:return e}}function Ft(){}const Dn={name:"CodeIcon",height:512,width:640,svgPath:"M278.9 511.5l-61-17.7c-6.4-1.8-10-8.5-8.2-14.9L346.2 8.7c1.8-6.4 8.5-10 14.9-8.2l61 17.7c6.4 1.8 10 8.5 8.2 14.9L293.8 503.3c-1.9 6.4-8.5 10.1-14.9 8.2zm-114-112.2l43.5-46.4c4.6-4.9 4.3-12.7-.8-17.2L117 256l90.6-79.7c5.1-4.5 5.5-12.3.8-17.2l-43.5-46.4c-4.5-4.8-12.1-5.1-17-.5L3.8 247.2c-5.1 4.7-5.1 12.8 0 17.5l144.1 135.1c4.9 4.6 12.5 4.4 17-.5zm327.2.6l144.1-135.1c5.1-4.7 5.1-12.8 0-17.5L492.1 112.1c-4.8-4.5-12.4-4.3-17 .5L431.6 159c-4.6 4.9-4.3 12.7.8 17.2L523 256l-90.6 79.7c-5.1 4.5-5.5 12.3-.8 17.2l43.5 46.4c4.5 4.9 12.1 5.1 17 .6z",yOffset:0,xOffset:0},nt=dt(Dn),jn={name:"DownloadIcon",height:512,width:512,svgPath:"M216 0h80c13.3 0 24 10.7 24 24v168h87.7c17.8 0 26.7 21.5 14.1 34.1L269.7 378.3c-7.5 7.5-19.8 7.5-27.3 0L90.1 226.1c-12.6-12.6-3.7-34.1 14.1-34.1H192V24c0-13.3 10.7-24 24-24zm296 376v112c0 13.3-10.7 24-24 24H24c-13.3 0-24-10.7-24-24V376c0-13.3 10.7-24 24-24h146.7l49 49c20.1 20.1 52.5 20.1 72.6 0l49-49H488c13.3 0 24 10.7 24 24zm-124 88c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20zm64 0c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20z",yOffset:0,xOffset:0},Cn=dt(jn),Sn={name:"UploadIcon",height:512,width:512,svgPath:"M296 384h-80c-13.3 0-24-10.7-24-24V192h-87.7c-17.8 0-26.7-21.5-14.1-34.1L242.3 5.7c7.5-7.5 19.8-7.5 27.3 0l152.2 152.2c12.6 12.6 3.7 34.1-14.1 34.1H320v168c0 13.3-10.7 24-24 24zm216-8v112c0 13.3-10.7 24-24 24H24c-13.3 0-24-10.7-24-24V376c0-13.3 10.7-24 24-24h136v8c0 30.9 25.1 56 56 56h80c30.9 0 56-25.1 56-56v-8h136c13.3 0 24 10.7 24 24zm-124 88c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20zm64 0c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20z",yOffset:0,xOffset:0},Tn=dt(Sn),B={button:"pf-v5-c-button",codeEditor:"pf-v5-c-code-editor",codeEditorCode:"pf-v5-c-code-editor__code",codeEditorCodePre:"pf-v5-c-code-editor__code-pre",codeEditorControls:"pf-v5-c-code-editor__controls",codeEditorHeader:"pf-v5-c-code-editor__header",codeEditorHeaderMain:"pf-v5-c-code-editor__header-main",codeEditorMain:"pf-v5-c-code-editor__main",codeEditorTab:"pf-v5-c-code-editor__tab",codeEditorTabIcon:"pf-v5-c-code-editor__tab-icon",codeEditorTabText:"pf-v5-c-code-editor__tab-text",modifiers:{readOnly:"pf-m-read-only",control:"pf-m-control",dragHover:"pf-m-drag-hover"},monacoEditor:"monaco-editor",themeDark:"pf-v5-theme-dark"};function xn(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function Mt(e){for(var t=1;t=0)&&(r[o]=e[o]);return r}function An(e,t){if(e==null)return{};var r=Pn(e,t),n,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function Fn(e,t){return _n(e)||Mn(e,t)||In(e,t)||Rn()}function _n(e){if(Array.isArray(e))return e}function Mn(e,t){if(!(typeof Symbol>"u"||!(Symbol.iterator in Object(e)))){var r=[],n=!0,o=!1,i=void 0;try{for(var c=e[Symbol.iterator](),l;!(n=(l=c.next()).done)&&(r.push(l.value),!(t&&r.length===t));n=!0);}catch(p){o=!0,i=p}finally{try{!n&&c.return!=null&&c.return()}finally{if(o)throw i}}return r}}function In(e,t){if(e){if(typeof e=="string")return It(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return It(e,t)}}function It(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r=e.length?e.apply(this,o):function(){for(var c=arguments.length,l=new Array(c),p=0;p1&&arguments[1]!==void 0?arguments[1]:{};ke.initial(e),ke.handler(t);var r={current:e},n=Ee(Yn)(r,t),o=Ee(Gn)(r),i=Ee(ke.changes)(e),c=Ee(Ln)(r);function l(){var m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(T){return T};return ke.selector(m),m(r.current)}function p(m){zn(n,o,i,c)(m)}return[l,p]}function Ln(e,t){return je(t)?t(e.current):t}function Gn(e,t){return e.current=kt(kt({},e.current),t),t}function Yn(e,t,r){return je(t)?t(e.current):Object.keys(r).forEach(function(n){var o;return(o=t[n])===null||o===void 0?void 0:o.call(t,e.current[n])}),r}var Jn={create:qn},Qn={paths:{vs:"https://cdn.jsdelivr.net/npm/[email protected]/min/vs"}};function Xn(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),i=0;i=e.length?e.apply(this,o):function(){for(var c=arguments.length,l=new Array(c),p=0;p{n.current=!1}:e,t)}var k=jo;function Oe(){}function fe(e,t,r,n){return Co(e,n)||So(e,t,r,n)}function Co(e,t){return e.editor.getModel(ir(e,t))}function So(e,t,r,n){return e.editor.createModel(t,r,n?ir(e,n):void 0)}function ir(e,t){return e.Uri.parse(t)}function To({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:o,originalModelPath:i,modifiedModelPath:c,keepCurrentOriginalModel:l=!1,keepCurrentModifiedModel:p=!1,theme:m="light",loading:T="Loading...",options:v={},height:M="100%",width:U="100%",className:V,wrapperProps:K={},beforeMount:X=Oe,onMount:te=Oe}){let[x,W]=Be(!1),[z,y]=Be(!0),O=j(null),h=j(null),q=j(null),b=j(te),d=j(X),I=j(!1);or(()=>{let f=rr.init();return f.then(D=>(h.current=D)&&y(!1)).catch(D=>D?.type!=="cancelation"&&console.error("Monaco initialization: error:",D)),()=>O.current?w():f.cancel()}),k(()=>{if(O.current&&h.current){let f=O.current.getOriginalEditor(),D=fe(h.current,e||"",n||r||"text",i||"");D!==f.getModel()&&f.setModel(D)}},[i],x),k(()=>{if(O.current&&h.current){let f=O.current.getModifiedEditor(),D=fe(h.current,t||"",o||r||"text",c||"");D!==f.getModel()&&f.setModel(D)}},[c],x),k(()=>{let f=O.current.getModifiedEditor();f.getOption(h.current.editor.EditorOption.readOnly)?f.setValue(t||""):t!==f.getValue()&&(f.executeEdits("",[{range:f.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),f.pushUndoStop())},[t],x),k(()=>{O.current?.getModel()?.original.setValue(e||"")},[e],x),k(()=>{let{original:f,modified:D}=O.current.getModel();h.current.editor.setModelLanguage(f,n||r||"text"),h.current.editor.setModelLanguage(D,o||r||"text")},[r,n,o],x),k(()=>{h.current?.editor.setTheme(m)},[m],x),k(()=>{O.current?.updateOptions(v)},[v],x);let L=_(()=>{if(!h.current)return;d.current(h.current);let f=fe(h.current,e||"",n||r||"text",i||""),D=fe(h.current,t||"",o||r||"text",c||"");O.current?.setModel({original:f,modified:D})},[r,t,o,e,n,i,c]),G=_(()=>{!I.current&&q.current&&(O.current=h.current.editor.createDiffEditor(q.current,{automaticLayout:!0,...v}),L(),h.current?.editor.setTheme(m),W(!0),I.current=!0)},[v,m,L]);H(()=>{x&&b.current(O.current,h.current)},[x]),H(()=>{!z&&!x&&G()},[z,x,G]);function w(){let f=O.current?.getModel();l||f?.original?.dispose(),p||f?.modified?.dispose(),O.current?.dispose()}return ce.createElement(nr,{width:U,height:M,isEditorReady:x,loading:T,_ref:q,className:V,wrapperProps:K})}var xo=To;ft(xo);function Po(e){let t=j();return H(()=>{t.current=e},[e]),t.current}var Ao=Po,ze=new Map;function Fo({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:o,path:i,theme:c="light",line:l,loading:p="Loading...",options:m={},overrideServices:T={},saveViewState:v=!0,keepCurrentModel:M=!1,width:U="100%",height:V="100%",className:K,wrapperProps:X={},beforeMount:te=Oe,onMount:x=Oe,onChange:W,onValidate:z=Oe}){let[y,O]=Be(!1),[h,q]=Be(!0),b=j(null),d=j(null),I=j(null),L=j(x),G=j(te),w=j(),f=j(n),D=Ao(i),oe=j(!1),Z=j(!1);or(()=>{let C=rr.init();return C.then(F=>(b.current=F)&&q(!1)).catch(F=>F?.type!=="cancelation"&&console.error("Monaco initialization: error:",F)),()=>d.current?he():C.cancel()}),k(()=>{let C=fe(b.current,e||n||"",t||o||"",i||r||"");C!==d.current?.getModel()&&(v&&ze.set(D,d.current?.saveViewState()),d.current?.setModel(C),v&&d.current?.restoreViewState(ze.get(i)))},[i],y),k(()=>{d.current?.updateOptions(m)},[m],y),k(()=>{!d.current||n===void 0||(d.current.getOption(b.current.editor.EditorOption.readOnly)?d.current.setValue(n):n!==d.current.getValue()&&(Z.current=!0,d.current.executeEdits("",[{range:d.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),d.current.pushUndoStop(),Z.current=!1))},[n],y),k(()=>{let C=d.current?.getModel();C&&o&&b.current?.editor.setModelLanguage(C,o)},[o],y),k(()=>{l!==void 0&&d.current?.revealLine(l)},[l],y),k(()=>{b.current?.editor.setTheme(c)},[c],y);let P=_(()=>{if(!(!I.current||!b.current)&&!oe.current){G.current(b.current);let C=i||r,F=fe(b.current,n||e||"",t||o||"",C||"");d.current=b.current?.editor.create(I.current,{model:F,automaticLayout:!0,...m},T),v&&d.current.restoreViewState(ze.get(C)),b.current.editor.setTheme(c),l!==void 0&&d.current.revealLine(l),O(!0),oe.current=!0}},[e,t,r,n,o,i,m,T,v,c,l]);H(()=>{y&&L.current(d.current,b.current)},[y]),H(()=>{!h&&!y&&P()},[h,y,P]),f.current=n,H(()=>{y&&W&&(w.current?.dispose(),w.current=d.current?.onDidChangeModelContent(C=>{Z.current||W(d.current.getValue(),C)}))},[y,W]),H(()=>{if(y){let C=b.current.editor.onDidChangeMarkers(F=>{let re=d.current.getModel()?.uri;if(re&&F.find($=>$.path===re.path)){let $=b.current.editor.getModelMarkers({resource:re});z?.($)}});return()=>{C?.dispose()}}return()=>{}},[y,z]);function he(){w.current?.dispose(),M?v&&ze.set(i,d.current.saveViewState()):d.current.getModel()?.dispose(),d.current.dispose()}return ce.createElement(nr,{width:U,height:V,isEditorReady:y,loading:p,_ref:I,className:K,wrapperProps:X})}var _o=Fo,Mo=ft(_o),Io=Mo;const ar=s.createContext(null),$e=e=>{var{icon:t,className:r,"aria-label":n,onClick:o=()=>{},isVisible:i=!0,tooltipProps:c={}}=e,l=vr(e,["icon","className","aria-label","onClick","isVisible","tooltipProps"]);const p=s.useContext(ar),m=T=>{o(p.code,T)};return i?s.createElement(gr,Object.assign({},c),s.createElement(we,Object.assign({className:r,onClick:m,variant:"control","aria-label":n},l),t)):null};$e.displayName="CodeEditorControl";var N;(function(e){e.abap="abap",e.aes="aes",e.apex="apex",e.azcli="azcli",e.bat="bat",e.bicep="bicep",e.c="c",e.cameligo="cameligo",e.clojure="clojure",e.coffeescript="coffeescript",e.cpp="cpp",e.csharp="csharp",e.csp="csp",e.css="css",e.dart="dart",e.dockerfile="dockerfile",e.ecl="ecl",e.elixir="elixir",e.fsharp="fsharp",e.go="go",e.graphql="graphql",e.handlebars="handlebars",e.hcl="hcl",e.html="html",e.ini="ini",e.java="java",e.javascript="javascript",e.json="json",e.julia="julia",e.kotlin="kotlin",e.less="less",e.lexon="lexon",e.liquid="liquid",e.lua="lua",e.m3="m3",e.markdown="markdown",e.mips="mips",e.msdax="msdax",e.mysql="mysql",e["objective-c"]="objective-c",e.pascal="pascal",e.pascaligo="pascaligo",e.perl="perl",e.pgsql="pgsql",e.php="php",e.plaintext="plaintext",e.postiats="postiats",e.powerquery="powerquery",e.powershell="powershell",e.pug="pug",e.python="python",e.r="r",e.razor="razor",e.redis="redis",e.redshift="redshift",e.restructuredtext="restructuredtext",e.ruby="ruby",e.rust="rust",e.sb="sb",e.scala="scala",e.scheme="scheme",e.scss="scss",e.shell="shell",e.sol="sol",e.sql="sql",e.st="st",e.swift="swift",e.systemverilog="systemverilog",e.tcl="tcl",e.twig="twig",e.typescript="typescript",e.vb="vb",e.verilog="verilog",e.xml="xml",e.yaml="yaml"})(N||(N={}));class Ce extends s.Component{constructor(t){super(t),this.editor=null,this.wrapperRef=s.createRef(),this.ref=s.createRef(),this.timer=null,this.observer=()=>{},this.onChange=(r,n)=>{this.props.height==="sizeToFit"&&this.setHeightToFitContent(),this.props.onChange&&this.props.onChange(r,n),this.setState({value:r}),this.props.onCodeChange(r)},this.handleResize=()=>{this.editor&&this.editor.layout()},this.handleGlobalKeys=r=>{var n;this.wrapperRef.current===document.activeElement&&(r.key==="ArrowDown"||r.key===" ")&&((n=this.editor)===null||n===void 0||n.focus(),r.preventDefault())},this.editorDidMount=(r,n)=>{r.addCommand(n.KeyMod.Shift|n.KeyCode.Tab,()=>this.wrapperRef.current.focus()),Array.from(document.getElementsByClassName("monaco-editor")).forEach(o=>o.removeAttribute("role")),this.props.onEditorDidMount(r,n),this.editor=r,this.props.height==="sizeToFit"&&this.setHeightToFitContent()},this.handleFileChange=(r,n)=>{this.setState({value:r,filename:n}),this.props.onCodeChange(r)},this.handleFileReadStarted=()=>this.setState({isLoading:!0}),this.handleFileReadFinished=()=>this.setState({isLoading:!1}),this.onDropAccepted=r=>{if(r.length>0){const n=r[0];this.handleFileChange("",n.name),this.handleFileReadStarted(),this.readFile(n).then(o=>{this.handleFileReadFinished(),this.toggleEmptyState(),this.handleFileChange(o,n.name)}).catch(o=>{console.error("error",o),this.handleFileReadFinished(),this.handleFileChange("","")})}},this.onDropRejected=r=>{r.length>0&&console.error("There was an error accepting that dropped file")},this.copyCode=()=>{navigator.clipboard.writeText(this.state.value),this.setState({copied:!0})},this.download=()=>{const{value:r}=this.state,n=document.createElement("a"),o=new Blob([r],{type:"text"});n.href=URL.createObjectURL(o),n.download=`${this.props.downloadFileName}.${Ce.getExtensionFromLanguage(this.props.language)}`,document.body.appendChild(n),n.click()},this.toggleEmptyState=()=>{this.setState({showEmptyState:!1})},this.state={height:this.props.height,prevPropsCode:this.props.code,value:this.props.code,filename:"",isLoading:!1,showEmptyState:!0,copied:!1}}static getExtensionFromLanguage(t){switch(t){case N.shell:return"sh";case N.ruby:return"rb";case N.perl:return"pl";case N.python:return"py";case N.mysql:return"sql";case N.javascript:return"js";case N.typescript:return"ts";case N.markdown:return"md";case N.plaintext:return"txt";default:return t.toString()}}setHeightToFitContent(){const t=this.editor.getContentHeight(),r=this.editor.getLayoutInfo();this.editor.layout({width:r.width,height:t})}static getDerivedStateFromProps(t,r){return t.code!==r.prevPropsCode?{value:t.code,prevPropsCode:t.code}:null}componentDidMount(){document.addEventListener("keydown",this.handleGlobalKeys),this.observer=yr(this.ref.current,this.handleResize,!0),this.handleResize()}componentWillUnmount(){document.removeEventListener("keydown",this.handleGlobalKeys),this.observer()}readFile(t){return new Promise((r,n)=>{const o=new FileReader;o.onload=()=>r(o.result),o.onerror=()=>n(o.error),o.readAsText(t)})}render(){const{height:t,value:r,isLoading:n,showEmptyState:o,copied:i}=this.state,{isDarkTheme:c,width:l,className:p,isCopyEnabled:m,copyButtonSuccessTooltipText:T,isReadOnly:v,isUploadEnabled:M,isLanguageLabelVisible:U,copyButtonAriaLabel:V,copyButtonToolTipText:K,uploadButtonAriaLabel:X,uploadButtonToolTipText:te,downloadButtonAriaLabel:x,downloadButtonToolTipText:W,toolTipDelay:z,toolTipCopyExitDelay:y,toolTipMaxWidth:O,toolTipPosition:h,isLineNumbersVisible:q,isDownloadEnabled:b,language:d,emptyState:I,emptyStateTitle:L,emptyStateBody:G,emptyStateButton:w,emptyStateLink:f,customControls:D,isMinimapVisible:oe,headerMainContent:Z,shortcutsPopoverButtonText:P,shortcutsPopoverProps:he,showEditor:C,options:F,overrideServices:re,editorProps:$}=this.props,ve=Object.assign(Object.assign({},Ce.defaultProps.shortcutsPopoverProps),he),ee=Object.assign({scrollBeyondLastLine:t!=="sizeToFit",readOnly:v,cursorStyle:"line",lineNumbers:q?"on":"off",tabIndex:-1,minimap:{enabled:oe}},F);return s.createElement(Ke,{multiple:!1,onDropAccepted:this.onDropAccepted,onDropRejected:this.onDropRejected},({getRootProps:xe,getInputProps:Pe,isDragActive:Ae,open:ie})=>{const le=I||(M?s.createElement(gt,{variant:yt.sm},s.createElement(wt,{titleText:L,icon:s.createElement(Et,{icon:nt}),headingLevel:"h4"}),s.createElement(Or,null,G),!v&&s.createElement(bt,null,s.createElement(et,null,s.createElement(we,{variant:"primary",onClick:ie},w)),s.createElement(et,null,s.createElement(we,{variant:"link",onClick:this.toggleEmptyState},f)))):s.createElement(gt,{variant:yt.sm},s.createElement(wt,{titleText:L,icon:s.createElement(Et,{icon:nt}),headingLevel:"h4"}),!v&&s.createElement(bt,null,s.createElement(et,null,s.createElement(we,{variant:"primary",onClick:this.toggleEmptyState},f))))),Y={position:h,exitDelay:z,entryDelay:z,maxWidth:O,trigger:"mouseenter focus"},ge=s.createElement("div",{className:J(B.codeEditorHeader)},s.createElement("div",{className:J(B.codeEditorControls)},s.createElement(ar.Provider,{value:{code:r}},m&&(!o||!!r)&&s.createElement($e,{icon:s.createElement(Er,null),"aria-label":V,tooltipProps:Object.assign(Object.assign({},Y),{"aria-live":"polite",content:s.createElement("div",null,i?T:K),exitDelay:i?y:z,onTooltipHidden:()=>this.setState({copied:!1})}),onClick:this.copyCode}),M&&s.createElement($e,{icon:s.createElement(Tn,null),"aria-label":X,tooltipProps:Object.assign({content:s.createElement("div",null,te)},Y),onClick:ie}),b&&(!o||!!r)&&s.createElement($e,{icon:s.createElement(Cn,null),"aria-label":x,tooltipProps:Object.assign({content:s.createElement("div",null,W)},Y),onClick:this.download}),D&&D)),s.createElement("div",{className:J(B.codeEditorHeaderMain)},Z),!!ve.bodyContent&&s.createElement("div",{className:`${B.codeEditor}__keyboard-shortcuts`},s.createElement($t,Object.assign({},ve),s.createElement(we,{variant:br.link,icon:s.createElement(wr,null)},P))),U&&s.createElement("div",{className:J(B.codeEditorTab)},s.createElement("span",{className:J(B.codeEditorTabIcon)},s.createElement(nt,null)),s.createElement("span",{className:J(B.codeEditorTabText)},d.toUpperCase()))),ye=s.createElement("div",{className:J(B.codeEditorCode),ref:this.wrapperRef,tabIndex:0,dir:"ltr"},s.createElement(Io,Object.assign({height:t,width:l,language:d,value:r,options:ee,overrideServices:re,onChange:this.onChange,onMount:this.editorDidMount,theme:c?"vs-dark":"vs-light"},$)));return s.createElement("div",{className:J(B.codeEditor,v&&B.modifiers.readOnly,p),ref:this.ref},M||I?s.createElement("div",Object.assign({},xe({onClick:Fe=>Fe.stopPropagation()}),{className:`${tt.fileUpload} ${Ae&&tt.modifiers.dragHover} ${n&&tt.modifiers.loading}`}),ge,s.createElement("div",{className:J(B.codeEditorMain)},s.createElement("input",Object.assign({},Pe())),(o||I)&&!r?le:ye)):s.createElement(s.Fragment,null,ge,C&&s.createElement("div",{className:J(B.codeEditorMain)},ye)))})}}Ce.displayName="CodeEditor";Ce.defaultProps={className:"",code:"",onEditorDidMount:()=>{},language:N.plaintext,isDarkTheme:!1,height:"",width:"",isLineNumbersVisible:!0,isReadOnly:!1,isLanguageLabelVisible:!1,loading:"",emptyState:"",emptyStateTitle:"Start editing",emptyStateBody:"Drag and drop a file or upload one.",emptyStateButton:"Browse",emptyStateLink:"Start from scratch",downloadFileName:Date.now().toString(),isUploadEnabled:!1,isDownloadEnabled:!1,isCopyEnabled:!1,copyButtonAriaLabel:"Copy code to clipboard",uploadButtonAriaLabel:"Upload code",downloadButtonAriaLabel:"Download code",copyButtonToolTipText:"Copy to clipboard",uploadButtonToolTipText:"Upload",downloadButtonToolTipText:"Download",copyButtonSuccessTooltipText:"Content added to clipboard",toolTipCopyExitDelay:1600,toolTipDelay:300,toolTipMaxWidth:"100px",toolTipPosition:"top",customControls:null,isMinimapVisible:!1,headerMainContent:"",shortcutsPopoverButtonText:"View Shortcuts",shortcutsPopoverProps:Object.assign({bodyContent:"","aria-label":"Keyboard Shortcuts"},$t.defaultProps),showEditor:!0,options:{},overrideServices:{},onCodeChange:()=>{}};export{Ce as C,N as L,Fr as a,tt as f,En as u};
//# sourceMappingURL=CodeEditor-C-nZkUJx.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy