superleap-code-editor 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/examples/codeEditorExamples.d.ts +5 -5
- package/dist/examples/codeEditorExamples.d.ts.map +1 -1
- package/dist/index.cjs.js +14 -11
- package/dist/index.esm.js +833 -499
- package/package.json +11 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const ExampleWorkflowEditor: () =>
|
|
2
|
-
export declare const ExampleFormEditor: () =>
|
|
3
|
-
export declare const ExampleURLEditor: () =>
|
|
4
|
-
export declare const ExampleCustomEditor: () =>
|
|
5
|
-
export declare const ExampleAdvancedWorkflow: () =>
|
|
1
|
+
export declare const ExampleWorkflowEditor: () => JSX.Element;
|
|
2
|
+
export declare const ExampleFormEditor: () => JSX.Element;
|
|
3
|
+
export declare const ExampleURLEditor: () => JSX.Element;
|
|
4
|
+
export declare const ExampleCustomEditor: () => JSX.Element;
|
|
5
|
+
export declare const ExampleAdvancedWorkflow: () => JSX.Element;
|
|
6
6
|
//# sourceMappingURL=codeEditorExamples.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeEditorExamples.d.ts","sourceRoot":"","sources":["../../src/examples/codeEditorExamples.tsx"],"names":[],"mappings":"AAUA,eAAO,MAAM,qBAAqB
|
|
1
|
+
{"version":3,"file":"codeEditorExamples.d.ts","sourceRoot":"","sources":["../../src/examples/codeEditorExamples.tsx"],"names":[],"mappings":"AAUA,eAAO,MAAM,qBAAqB,mBA0BjC,CAAC;AAGF,eAAO,MAAM,iBAAiB,mBAwB7B,CAAC;AAGF,eAAO,MAAM,gBAAgB,mBA8B5B,CAAC;AAGF,eAAO,MAAM,mBAAmB,mBAgB/B,CAAC;AAGF,eAAO,MAAM,uBAAuB,mBAoDnC,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react"),xr=require("@monaco-editor/react"),x=require("antd"),O=require("@tabler/icons-react");var q={exports:{}},L={};/**
|
|
2
2
|
* @license React
|
|
3
|
-
* react-jsx-runtime.production.js
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
5
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Se;function Fr(){if(Se)return L;Se=1;var o=w,t=Symbol.for("react.element"),a=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,d=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,E={key:!0,ref:!0,__self:!0,__source:!0};function F(R,g,S){var u,j={},C=null,k=null;S!==void 0&&(C=""+S),g.key!==void 0&&(C=""+g.key),g.ref!==void 0&&(k=g.ref);for(u in g)i.call(g,u)&&!E.hasOwnProperty(u)&&(j[u]=g[u]);if(R&&R.defaultProps)for(u in g=R.defaultProps,g)j[u]===void 0&&(j[u]=g[u]);return{$$typeof:t,type:R,key:C,ref:k,props:j,_owner:d.current}}return L.Fragment=a,L.jsx=F,L.jsxs=F,L}var W={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
13
|
-
* Copyright (c)
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<%s key={someKey} {...props} />`,h,p,C,p),V[p+h]=!0)}if(p=null,u!==void 0&&(r(u),p=""+u),m(s)&&(r(s.key),p=""+s.key),"key"in s){u={};for(var M in s)M!=="key"&&(u[M]=s[M])}else u=s;return p&&b(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),w(e,p,x,R,a(),u,L,z)}function F(e){typeof e=="object"&&e!==null&&e.$$typeof===T&&e._store&&(e._store.validated=1)}var E=g,T=Symbol.for("react.transitional.element"),O=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),se=Symbol.for("react.context"),le=Symbol.for("react.forward_ref"),ce=Symbol.for("react.suspense"),ue=Symbol.for("react.suspense_list"),fe=Symbol.for("react.memo"),B=Symbol.for("react.lazy"),de=Symbol.for("react.activity"),me=Symbol.for("react.client.reference"),I=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,he=Array.isArray,$=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var Y,W={},U=E.react_stack_bottom_frame.bind(E,l)(),q=$(n(l)),V={};k.Fragment=S,k.jsx=function(e,s,u,h,R){var x=1e4>I.recentlyCreatedOwnerStacks++;return c(e,s,u,!1,h,R,x?Error("react-stack-top-frame"):U,x?$(n(e)):q)},k.jsxs=function(e,s,u,h,R){var x=1e4>I.recentlyCreatedOwnerStacks++;return c(e,s,u,!0,h,R,x?Error("react-stack-top-frame"):U,x?$(n(e)):q)}})()),k}var X;function Ee(){return X||(X=1,process.env.NODE_ENV==="production"?P.exports=be():P.exports=ve()),P.exports}var o=Ee();function H(i){const[t,r]=g.useState([]),[n,a]=g.useState(null),[l,m]=g.useState(""),[b,y]=g.useState(!1),[w,c]=g.useState(null),F=g.useCallback(async()=>{try{y(!0),c(null);const f=await i.getFiles();if(r(f),!n&&f.length>0){const v=Z(f);v&&a(v.id)}}catch(f){c(f instanceof Error?f.message:"Failed to load files")}finally{y(!1)}},[i,n]),E=g.useCallback(async f=>{try{y(!0),c(null);const v=await i.getFileContent(f);m(v)}catch(v){c(v instanceof Error?v.message:"Failed to load file content"),m("")}finally{y(!1)}},[i]),T=g.useCallback(async f=>{if(n)try{c(null),await i.updateFileContent(n,f),m(f),r(v=>K(v,n,{content:f}))}catch(v){c(v instanceof Error?v.message:"Failed to update file content")}},[n,i]),O=g.useCallback(f=>{a(f),E(f)},[E]),S=g.useCallback(()=>{F()},[F]),A=g.useCallback(f=>Q(t,f),[t]);return g.useEffect(()=>{F()},[F]),g.useEffect(()=>{n&&E(n)},[n,E]),{files:t,activeFile:n,fileContent:l,loading:b,error:w,setActiveFile:O,updateFileContent:T,refreshFiles:S,getFileById:A}}function Z(i){for(const t of i){if(t.type==="file")return t;if(t.children){const r=Z(t.children);if(r)return r}}return null}function Q(i,t){for(const r of i){if(r.id===t)return r;if(r.children){const n=Q(r.children,t);if(n)return n}}return null}function K(i,t,r){return i.map(n=>n.id===t?{...n,...r}:n.children?{...n,children:K(n.children,t,r)}:n)}class ee{config;files=[];constructor(t){this.config=t}async getFiles(){return this.files.length===0&&await this.loadFiles(),this.files}async getFileContent(t){if(t==="main-function")return await this.config.fetchFunction(this.config.functionId,this.config.version);throw new Error(`File ${t} not found`)}async updateFileContent(t,r){const n=this.findFileById(t);n&&(n.content=r),console.log(`Updated file ${t} with content:`,r)}async getFileMetadata(t){return this.findFileById(t)?.metadata||{}}async loadFiles(){this.files=[{id:"main-function",name:"function.js",type:"file",path:"/function.js",metadata:{language:"javascript",lastModified:new Date}},{id:"versions",name:"versions",type:"folder",path:"/versions",children:this.config.versionList.map(t=>({id:`version-${t}`,name:`v${t}.js`,type:"file",path:`/versions/v${t}.js`,metadata:{language:"javascript"}}))}]}findFileById(t){const r=n=>{for(const a of n){if(a.id===t)return a;if(a.children){const l=r(a.children);if(l)return l}}return null};return r(this.files)}}class te{config;files=[];constructor(t){this.config=t,this.initializeFiles()}async getFiles(){return this.files}async getFileContent(t){if(t==="form-code")return this.config.codeContent;throw new Error(`File ${t} not found`)}async updateFileContent(t,r){if(t==="form-code"){this.config.codeContent=r;const n=this.files.find(a=>a.id===t);n&&(n.content=r)}}async getFileMetadata(t){return this.findFileById(t)?.metadata||{}}initializeFiles(){this.files=[{id:"form-code",name:this.config.fileName||"code.js",type:"file",path:`/${this.config.fileName||"code.js"}`,content:this.config.codeContent,metadata:{language:this.config.language||"javascript",lastModified:new Date}}]}findFileById(t){return this.files.find(r=>r.id===t)||null}}class re{config;files=[];constructor(t){this.config=t,this.initializeFiles()}async getFiles(){return this.files}async getFileContent(t){const r=this.findFileById(t);if(!r||!r.metadata?.url)throw new Error(`File ${t} not found`);try{const n=await fetch(r.metadata.url);if(!n.ok)throw new Error(`Failed to fetch file: ${n.statusText}`);return await n.text()}catch(n){throw new Error(`Error fetching file content: ${n}`)}}async updateFileContent(t,r){console.log(`Would save file ${t} content to backend:`,r);const n=this.findFileById(t);n&&(n.content=r)}async getFileMetadata(t){return this.findFileById(t)?.metadata||{}}initializeFiles(){this.files=this.config.fileUrls.map((t,r)=>({id:`url-file-${r}`,name:t.name,type:"file",path:`/${t.name}`,metadata:{language:t.type,url:t.url,lastModified:new Date}}))}findFileById(t){return this.files.find(r=>r.id===t)||null}}function ne(i){if(i.workflowConfig)return new ee(i.workflowConfig);if(i.formConfig)return new te(i.formConfig);if(i.urlConfig)return new re(i.urlConfig);throw new Error("No valid configuration provided")}const ie=({value:i,onChange:t,language:r="javascript",filename:n,readOnly:a=!1,loading:l=!1})=>{const m=b=>{b!==void 0&&t(b)};return o.jsx("div",{className:"h-full w-full",children:o.jsx(ge,{height:"100%",defaultLanguage:r,defaultValue:i,onChange:m,theme:"vs-light",options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",automaticLayout:!0,padding:{top:16},scrollBeyondLastLine:!1,readOnly:a}})})},ye=({activePanel:i,setActivePanel:t})=>{const r=[{id:"explorer",icon:j.IconFolderOpen,label:"Files"},{id:"data",icon:j.IconDatabase,label:"Data"},{id:"functions",icon:j.IconCode,label:"Functions"},{id:"versions",icon:j.IconHistory,label:"Versions"},{id:"tests",icon:j.IconFlask,label:"Tests"}];return o.jsxs("div",{className:"w-14 border-r border-slate-200 bg-white flex flex-col gap-4 items-center py-4",children:[r.map(n=>{const a=n.icon;return o.jsx(d.Tooltip,{title:n.label,placement:"right",children:o.jsx(d.Button,{type:i===n.id?"primary":"text",icon:o.jsx(a,{size:16}),onClick:()=>t(n.id)})},n.id)}),o.jsx("div",{className:"mt-auto",children:o.jsx(d.Tooltip,{title:"Settings",placement:"right",children:o.jsx(d.Button,{type:"text",icon:o.jsx(j.IconSettings,{size:20})})})})]})},oe=({leftPanel:i,editor:t,rightPanel:r,activePanel:n,setActivePanel:a})=>o.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[o.jsx(ye,{activePanel:n,setActivePanel:a}),o.jsx("div",{className:"flex-1",children:r?o.jsxs(d.Splitter,{style:{height:"100%"},onResize:l=>console.log(l),children:[o.jsx(d.Splitter.Panel,{defaultSize:"25%",min:"15%",max:"40%",className:"bg-white border-r border-slate-200",collapsible:!0,children:o.jsx("div",{className:"h-full overflow-y-auto",children:i})}),o.jsx(d.Splitter.Panel,{defaultSize:"50%",min:"30%",children:t}),o.jsx(d.Splitter.Panel,{defaultSize:"25%",min:"20%",max:"50%",className:"bg-white border-l border-slate-200",children:o.jsx("div",{className:"h-full overflow-y-auto",children:r})})]}):o.jsxs(d.Splitter,{style:{height:"100%"},children:[o.jsx(d.Splitter.Panel,{defaultSize:"25%",min:"15%",max:"40%",className:"bg-white border-r border-slate-200",children:o.jsx("div",{className:"h-full overflow-y-auto",children:i})}),o.jsx(d.Splitter.Panel,{defaultSize:"75%",min:"60%",children:t})]})})]}),ae=({files:i,activeFile:t,onFileSelect:r,loading:n=!1,error:a=null,onRefresh:l})=>{const m=w=>w.map(c=>({title:c.name,key:c.id,icon:c.type==="file"?o.jsx(j.IconFile,{size:16,className:"text-slate-500 flex"}):o.jsx(j.IconFolderOpen,{size:16,className:"text-slate-500 flex"}),isLeaf:c.type==="file",children:c.children?m(c.children):void 0,metadata:c.metadata})),b=m(i),y=(w,c)=>{c?.node.isLeaf&&c.node.key&&r(c.node.key)};return o.jsxs("div",{className:"h-full",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200",children:[o.jsx("h2",{className:"font-medium text-sm",children:"Files"}),o.jsx("div",{className:"flex items-center gap-2",children:l&&o.jsx(d.Button,{type:"text",icon:o.jsx(j.IconPlus,{size:16}),onClick:l,loading:n,title:"Refresh files"})})]}),o.jsxs("div",{className:"p-2",children:[a&&o.jsx(d.Alert,{message:"Error loading files",description:a,type:"error",className:"mb-2"}),o.jsx(d.Tree,{treeData:b,onSelect:y,selectedKeys:t?[t]:[],showIcon:!0,defaultExpandAll:!0,showLine:!0,className:"file-explorer-tree"})]})]})},N=({config:i,rightPanel:t=!1})=>{const r=g.useMemo(()=>ne(i),[i]);console.log({config:i});const{files:n,activeFile:a,fileContent:l,loading:m,error:b,setActiveFile:y,updateFileContent:w,refreshFiles:c,getFileById:F}=H(r),E=a?F(a):null,T=E?.metadata?.language||"javascript";return o.jsx(oe,{leftPanel:o.jsx(ae,{files:n,activeFile:a,onFileSelect:y,loading:m,error:b,onRefresh:c}),editor:o.jsx(ie,{value:l,onChange:w,language:T,filename:E?.name,readOnly:i.settings?.readOnly,loading:m}),rightPanel:t,activePanel:"explorer",setActivePanel:()=>{}})},xe=({functionId:i,version:t,versionList:r,fetchFunction:n,fetchVersionList:a})=>{const l={workflowConfig:{functionId:i,version:t,versionList:r,fetchFunction:n,fetchVersionList:a}};return o.jsx(N,{config:l})},Fe=({codeContent:i,fileName:t="code.js",language:r="javascript",readOnly:n=!1})=>{const a={formConfig:{codeContent:i,fileName:t,language:r},settings:{readOnly:n}};return o.jsx(N,{config:a})},je=({fileUrls:i,rightPanel:t})=>{const r={urlConfig:{fileUrls:i}};return o.jsx(N,{config:r,rightPanel:t})},we="1.0.0";Object.defineProperty(exports,"Alert",{enumerable:!0,get:()=>d.Alert});Object.defineProperty(exports,"Button",{enumerable:!0,get:()=>d.Button});Object.defineProperty(exports,"Splitter",{enumerable:!0,get:()=>d.Splitter});Object.defineProperty(exports,"Tooltip",{enumerable:!0,get:()=>d.Tooltip});Object.defineProperty(exports,"Tree",{enumerable:!0,get:()=>d.Tree});exports.CodeEditor=ie;exports.CodeEditorWrapper=N;exports.EditorLayout=oe;exports.FileExplorer=ae;exports.FormCodeEditor=Fe;exports.FormFileProvider=te;exports.URLCodeEditor=je;exports.URLFileProvider=re;exports.VERSION=we;exports.WorkflowCodeEditor=xe;exports.WorkflowFileProvider=ee;exports.createFileProvider=ne;exports.useFileManager=H;
|
|
17
|
+
*/var Te;function Rr(){return Te||(Te=1,process.env.NODE_ENV!=="production"&&(function(){var o=w,t=Symbol.for("react.element"),a=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),E=Symbol.for("react.profiler"),F=Symbol.for("react.provider"),R=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),k=Symbol.for("react.offscreen"),B=Symbol.iterator,G="@@iterator";function K(e){if(e===null||typeof e!="object")return null;var r=B&&e[B]||e[G];return typeof r=="function"?r:null}var m=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){{for(var r=arguments.length,n=new Array(r>1?r-1:0),s=1;s<r;s++)n[s-1]=arguments[s];Ye("error",e,n)}}function Ye(e,r,n){{var s=m.ReactDebugCurrentFrame,v=s.getStackAddendum();v!==""&&(r+="%s",n=n.concat([v]));var p=n.map(function(f){return String(f)});p.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,p)}}var ze=!1,Ve=!1,Ue=!1,qe=!1,Je=!1,ne;ne=Symbol.for("react.module.reference");function Ge(e){return!!(typeof e=="string"||typeof e=="function"||e===i||e===E||Je||e===d||e===S||e===u||qe||e===k||ze||Ve||Ue||typeof e=="object"&&e!==null&&(e.$$typeof===C||e.$$typeof===j||e.$$typeof===F||e.$$typeof===R||e.$$typeof===g||e.$$typeof===ne||e.getModuleId!==void 0))}function Ke(e,r,n){var s=e.displayName;if(s)return s;var v=r.displayName||r.name||"";return v!==""?n+"("+v+")":n}function ie(e){return e.displayName||"Context"}function I(e){if(e==null)return null;if(typeof e.tag=="number"&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case i:return"Fragment";case a:return"Portal";case E:return"Profiler";case d:return"StrictMode";case S:return"Suspense";case u:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case R:var r=e;return ie(r)+".Consumer";case F:var n=e;return ie(n._context)+".Provider";case g:return Ke(e,e.render,"ForwardRef");case j:var s=e.displayName||null;return s!==null?s:I(e.type)||"Memo";case C:{var v=e,p=v._payload,f=v._init;try{return I(f(p))}catch{return null}}}return null}var D=Object.assign,$=0,ae,oe,se,le,ce,ue,fe;function de(){}de.__reactDisabledLog=!0;function He(){{if($===0){ae=console.log,oe=console.info,se=console.warn,le=console.error,ce=console.group,ue=console.groupCollapsed,fe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:de,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}$++}}function Xe(){{if($--,$===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:ae}),info:D({},e,{value:oe}),warn:D({},e,{value:se}),error:D({},e,{value:le}),group:D({},e,{value:ce}),groupCollapsed:D({},e,{value:ue}),groupEnd:D({},e,{value:fe})})}$<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var H=m.ReactCurrentDispatcher,X;function M(e,r,n){{if(X===void 0)try{throw Error()}catch(v){var s=v.stack.trim().match(/\n( *(at )?)/);X=s&&s[1]||""}return`
|
|
18
|
+
`+X+e}}var Z=!1,Y;{var Ze=typeof WeakMap=="function"?WeakMap:Map;Y=new Ze}function ve(e,r){if(!e||Z)return"";{var n=Y.get(e);if(n!==void 0)return n}var s;Z=!0;var v=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var p;p=H.current,H.current=null,He();try{if(r){var f=function(){throw Error()};if(Object.defineProperty(f.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(f,[])}catch(P){s=P}Reflect.construct(e,[],f)}else{try{f.call()}catch(P){s=P}e.call(f.prototype)}}else{try{throw Error()}catch(P){s=P}e()}}catch(P){if(P&&s&&typeof P.stack=="string"){for(var c=P.stack.split(`
|
|
19
|
+
`),_=s.stack.split(`
|
|
20
|
+
`),y=c.length-1,b=_.length-1;y>=1&&b>=0&&c[y]!==_[b];)b--;for(;y>=1&&b>=0;y--,b--)if(c[y]!==_[b]){if(y!==1||b!==1)do if(y--,b--,b<0||c[y]!==_[b]){var T=`
|
|
21
|
+
`+c[y].replace(" at new "," at ");return e.displayName&&T.includes("<anonymous>")&&(T=T.replace("<anonymous>",e.displayName)),typeof e=="function"&&Y.set(e,T),T}while(y>=1&&b>=0);break}}}finally{Z=!1,H.current=p,Xe(),Error.prepareStackTrace=v}var N=e?e.displayName||e.name:"",_e=N?M(N):"";return typeof e=="function"&&Y.set(e,_e),_e}function Qe(e,r,n){return ve(e,!1)}function er(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function z(e,r,n){if(e==null)return"";if(typeof e=="function")return ve(e,er(e));if(typeof e=="string")return M(e);switch(e){case S:return M("Suspense");case u:return M("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case g:return Qe(e.render);case j:return z(e.type,r,n);case C:{var s=e,v=s._payload,p=s._init;try{return z(p(v),r,n)}catch{}}}return""}var V=Object.prototype.hasOwnProperty,he={},pe=m.ReactDebugCurrentFrame;function U(e){if(e){var r=e._owner,n=z(e.type,e._source,r?r.type:null);pe.setExtraStackFrame(n)}else pe.setExtraStackFrame(null)}function rr(e,r,n,s,v){{var p=Function.call.bind(V);for(var f in e)if(p(e,f)){var c=void 0;try{if(typeof e[f]!="function"){var _=Error((s||"React class")+": "+n+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw _.name="Invariant Violation",_}c=e[f](r,f,s,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(y){c=y}c&&!(c instanceof Error)&&(U(v),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",s||"React class",n,f,typeof c),U(null)),c instanceof Error&&!(c.message in he)&&(he[c.message]=!0,U(v),h("Failed %s type: %s",n,c.message),U(null))}}}var tr=Array.isArray;function Q(e){return tr(e)}function nr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,n=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function ir(e){try{return ge(e),!1}catch{return!0}}function ge(e){return""+e}function me(e){if(ir(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",nr(e)),ge(e)}var ye=m.ReactCurrentOwner,ar={key:!0,ref:!0,__self:!0,__source:!0},be,Ee;function or(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function sr(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function lr(e,r){typeof e.ref=="string"&&ye.current}function cr(e,r){{var n=function(){be||(be=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function ur(e,r){{var n=function(){Ee||(Ee=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var fr=function(e,r,n,s,v,p,f){var c={$$typeof:t,type:e,key:r,ref:n,props:f,_owner:p};return c._store={},Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:v}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c};function dr(e,r,n,s,v){{var p,f={},c=null,_=null;n!==void 0&&(me(n),c=""+n),sr(r)&&(me(r.key),c=""+r.key),or(r)&&(_=r.ref,lr(r,v));for(p in r)V.call(r,p)&&!ar.hasOwnProperty(p)&&(f[p]=r[p]);if(e&&e.defaultProps){var y=e.defaultProps;for(p in y)f[p]===void 0&&(f[p]=y[p])}if(c||_){var b=typeof e=="function"?e.displayName||e.name||"Unknown":e;c&&cr(f,b),_&&ur(f,b)}return fr(e,c,_,v,s,ye.current,f)}}var ee=m.ReactCurrentOwner,xe=m.ReactDebugCurrentFrame;function A(e){if(e){var r=e._owner,n=z(e.type,e._source,r?r.type:null);xe.setExtraStackFrame(n)}else xe.setExtraStackFrame(null)}var re;re=!1;function te(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function Fe(){{if(ee.current){var e=I(ee.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function vr(e){return""}var Re={};function hr(e){{var r=Fe();if(!r){var n=typeof e=="string"?e:e.displayName||e.name;n&&(r=`
|
|
24
|
+
|
|
25
|
+
Check the top-level render call using <`+n+">.")}return r}}function je(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=hr(r);if(Re[n])return;Re[n]=!0;var s="";e&&e._owner&&e._owner!==ee.current&&(s=" It was passed a child from "+I(e._owner.type)+"."),A(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,s),A(null)}}function we(e,r){{if(typeof e!="object")return;if(Q(e))for(var n=0;n<e.length;n++){var s=e[n];te(s)&&je(s,r)}else if(te(e))e._store&&(e._store.validated=!0);else if(e){var v=K(e);if(typeof v=="function"&&v!==e.entries)for(var p=v.call(e),f;!(f=p.next()).done;)te(f.value)&&je(f.value,r)}}}function pr(e){{var r=e.type;if(r==null||typeof r=="string")return;var n;if(typeof r=="function")n=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===g||r.$$typeof===j))n=r.propTypes;else return;if(n){var s=I(r);rr(n,e.props,"prop",s,e)}else if(r.PropTypes!==void 0&&!re){re=!0;var v=I(r);h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function gr(e){{for(var r=Object.keys(e.props),n=0;n<r.length;n++){var s=r[n];if(s!=="children"&&s!=="key"){A(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",s),A(null);break}}e.ref!==null&&(A(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),A(null))}}function Ce(e,r,n,s,v,p){{var f=Ge(e);if(!f){var c="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(c+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var _=vr();_?c+=_:c+=Fe();var y;e===null?y="null":Q(e)?y="array":e!==void 0&&e.$$typeof===t?(y="<"+(I(e.type)||"Unknown")+" />",c=" Did you accidentally export a JSX literal instead of a component?"):y=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",y,c)}var b=dr(e,r,n,v,p);if(b==null)return b;if(f){var T=r.children;if(T!==void 0)if(s)if(Q(T)){for(var N=0;N<T.length;N++)we(T[N],e);Object.freeze&&Object.freeze(T)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else we(T,e)}return e===i?gr(b):pr(b),b}}function mr(e,r,n){return Ce(e,r,n,!0)}function yr(e,r,n){return Ce(e,r,n,!1)}var br=yr,Er=mr;W.Fragment=i,W.jsx=br,W.jsxs=Er})()),W}var Pe;function jr(){return Pe||(Pe=1,process.env.NODE_ENV==="production"?q.exports=Fr():q.exports=Rr()),q.exports}var l=jr();function Oe(o){const[t,a]=w.useState([]),[i,d]=w.useState(null),[E,F]=w.useState(""),[R,g]=w.useState(!1),[S,u]=w.useState(null),j=w.useCallback(async()=>{try{g(!0),u(null);const m=await o.getFiles();if(a(m),!i&&m.length>0){const h=ke(m);h&&d(h.id)}}catch(m){u(m instanceof Error?m.message:"Failed to load files")}finally{g(!1)}},[o,i]),C=w.useCallback(async m=>{try{g(!0),u(null);const h=await o.getFileContent(m);F(h)}catch(h){u(h instanceof Error?h.message:"Failed to load file content"),F("")}finally{g(!1)}},[o]),k=w.useCallback(async m=>{if(i)try{u(null),await o.updateFileContent(i,m),F(m),a(h=>De(h,i,{content:m}))}catch(h){u(h instanceof Error?h.message:"Failed to update file content")}},[i,o]),B=w.useCallback(m=>{d(m),C(m)},[C]),G=w.useCallback(()=>{j()},[j]),K=w.useCallback(m=>Ie(t,m),[t]);return w.useEffect(()=>{j()},[j]),w.useEffect(()=>{i&&C(i)},[i,C]),{files:t,activeFile:i,fileContent:E,loading:R,error:S,setActiveFile:B,updateFileContent:k,refreshFiles:G,getFileById:K}}function ke(o){for(const t of o){if(t.type==="file")return t;if(t.children){const a=ke(t.children);if(a)return a}}return null}function Ie(o,t){for(const a of o){if(a.id===t)return a;if(a.children){const i=Ie(a.children,t);if(i)return i}}return null}function De(o,t,a){return o.map(i=>i.id===t?{...i,...a}:i.children?{...i,children:De(i.children,t,a)}:i)}class Ae{config;files=[];constructor(t){this.config=t}async getFiles(){return this.files.length===0&&await this.loadFiles(),this.files}async getFileContent(t){if(t==="main-function")return await this.config.fetchFunction(this.config.functionId,this.config.version);throw new Error(`File ${t} not found`)}async updateFileContent(t,a){const i=this.findFileById(t);i&&(i.content=a),console.log(`Updated file ${t} with content:`,a)}async getFileMetadata(t){return this.findFileById(t)?.metadata||{}}async loadFiles(){this.files=[{id:"main-function",name:"function.js",type:"file",path:"/function.js",metadata:{language:"javascript",lastModified:new Date}},{id:"versions",name:"versions",type:"folder",path:"/versions",children:this.config.versionList.map(t=>({id:`version-${t}`,name:`v${t}.js`,type:"file",path:`/versions/v${t}.js`,metadata:{language:"javascript"}}))}]}findFileById(t){const a=i=>{for(const d of i){if(d.id===t)return d;if(d.children){const E=a(d.children);if(E)return E}}return null};return a(this.files)}}class Ne{config;files=[];constructor(t){this.config=t,this.initializeFiles()}async getFiles(){return this.files}async getFileContent(t){if(t==="form-code")return this.config.codeContent;throw new Error(`File ${t} not found`)}async updateFileContent(t,a){if(t==="form-code"){this.config.codeContent=a;const i=this.files.find(d=>d.id===t);i&&(i.content=a)}}async getFileMetadata(t){return this.findFileById(t)?.metadata||{}}initializeFiles(){this.files=[{id:"form-code",name:this.config.fileName||"code.js",type:"file",path:`/${this.config.fileName||"code.js"}`,content:this.config.codeContent,metadata:{language:this.config.language||"javascript",lastModified:new Date}}]}findFileById(t){return this.files.find(a=>a.id===t)||null}}class $e{config;files=[];constructor(t){this.config=t,this.initializeFiles()}async getFiles(){return this.files}async getFileContent(t){const a=this.findFileById(t);if(!a||!a.metadata?.url)throw new Error(`File ${t} not found`);try{const i=await fetch(a.metadata.url);if(!i.ok)throw new Error(`Failed to fetch file: ${i.statusText}`);return await i.text()}catch(i){throw new Error(`Error fetching file content: ${i}`)}}async updateFileContent(t,a){console.log(`Would save file ${t} content to backend:`,a);const i=this.findFileById(t);i&&(i.content=a)}async getFileMetadata(t){return this.findFileById(t)?.metadata||{}}initializeFiles(){this.files=this.config.fileUrls.map((t,a)=>({id:`url-file-${a}`,name:t.name,type:"file",path:`/${t.name}`,metadata:{language:t.type,url:t.url,lastModified:new Date}}))}findFileById(t){return this.files.find(a=>a.id===t)||null}}function Le(o){if(o.workflowConfig)return new Ae(o.workflowConfig);if(o.formConfig)return new Ne(o.formConfig);if(o.urlConfig)return new $e(o.urlConfig);throw new Error("No valid configuration provided")}const We=({value:o,onChange:t,language:a="javascript",filename:i,readOnly:d=!1,loading:E=!1})=>{const F=R=>{R!==void 0&&t(R)};return l.jsx("div",{className:"h-full w-full",children:l.jsx(xr,{height:"100%",defaultLanguage:a,defaultValue:o,onChange:F,theme:"vs-light",options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",automaticLayout:!0,padding:{top:16},scrollBeyondLastLine:!1,readOnly:d}})})},wr=({activePanel:o,setActivePanel:t})=>{const a=[{id:"explorer",icon:O.IconFolderOpen,label:"Files"},{id:"data",icon:O.IconDatabase,label:"Data"},{id:"functions",icon:O.IconCode,label:"Functions"},{id:"versions",icon:O.IconHistory,label:"Versions"},{id:"tests",icon:O.IconFlask,label:"Tests"}];return l.jsxs("div",{className:"w-14 border-r border-slate-200 bg-white flex flex-col gap-4 items-center py-4",children:[a.map(i=>{const d=i.icon;return l.jsx(x.Tooltip,{title:i.label,placement:"right",children:l.jsx(x.Button,{type:o===i.id?"primary":"text",icon:l.jsx(d,{size:16}),onClick:()=>t(i.id)})},i.id)}),l.jsx("div",{className:"mt-auto",children:l.jsx(x.Tooltip,{title:"Settings",placement:"right",children:l.jsx(x.Button,{type:"text",icon:l.jsx(O.IconSettings,{size:20})})})})]})},Be=({leftPanel:o,editor:t,rightPanel:a,activePanel:i,setActivePanel:d})=>l.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[l.jsx(wr,{activePanel:i,setActivePanel:d}),l.jsx("div",{className:"flex-1",children:a?l.jsxs(x.Splitter,{style:{height:"100%"},onResize:E=>console.log(E),children:[l.jsx(x.Splitter.Panel,{defaultSize:"25%",min:"15%",max:"40%",className:"bg-white border-r border-slate-200",collapsible:!0,children:l.jsx("div",{className:"h-full overflow-y-auto",children:o})}),l.jsx(x.Splitter.Panel,{defaultSize:"50%",min:"30%",children:t}),l.jsx(x.Splitter.Panel,{defaultSize:"25%",min:"20%",max:"50%",className:"bg-white border-l border-slate-200",children:l.jsx("div",{className:"h-full overflow-y-auto",children:a})})]}):l.jsxs(x.Splitter,{style:{height:"100%"},children:[l.jsx(x.Splitter.Panel,{defaultSize:"25%",min:"15%",max:"40%",className:"bg-white border-r border-slate-200",children:l.jsx("div",{className:"h-full overflow-y-auto",children:o})}),l.jsx(x.Splitter.Panel,{defaultSize:"75%",min:"60%",children:t})]})})]}),Me=({files:o,activeFile:t,onFileSelect:a,loading:i=!1,error:d=null,onRefresh:E})=>{const F=S=>S.map(u=>({title:u.name,key:u.id,icon:u.type==="file"?l.jsx(O.IconFile,{size:16,className:"text-slate-500 flex"}):l.jsx(O.IconFolderOpen,{size:16,className:"text-slate-500 flex"}),isLeaf:u.type==="file",children:u.children?F(u.children):void 0,metadata:u.metadata})),R=F(o),g=(S,u)=>{u?.node.isLeaf&&u.node.key&&a(u.node.key)};return l.jsxs("div",{className:"h-full",children:[l.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200",children:[l.jsx("h2",{className:"font-medium text-sm",children:"Files"}),l.jsx("div",{className:"flex items-center gap-2",children:E&&l.jsx(x.Button,{type:"text",icon:l.jsx(O.IconPlus,{size:16}),onClick:E,loading:i,title:"Refresh files"})})]}),l.jsxs("div",{className:"p-2",children:[d&&l.jsx(x.Alert,{message:"Error loading files",description:d,type:"error",className:"mb-2"}),l.jsx(x.Tree,{treeData:R,onSelect:g,selectedKeys:t?[t]:[],showIcon:!0,defaultExpandAll:!0,showLine:!0,className:"file-explorer-tree"})]})]})},J=({config:o,rightPanel:t=!1})=>{const a=w.useMemo(()=>Le(o),[o]);console.log({config:o});const{files:i,activeFile:d,fileContent:E,loading:F,error:R,setActiveFile:g,updateFileContent:S,refreshFiles:u,getFileById:j}=Oe(a),C=d?j(d):null,k=C?.metadata?.language||"javascript";return l.jsx(Be,{leftPanel:l.jsx(Me,{files:i,activeFile:d,onFileSelect:g,loading:F,error:R,onRefresh:u}),editor:l.jsx(We,{value:E,onChange:S,language:k,filename:C?.name,readOnly:o.settings?.readOnly,loading:F}),rightPanel:t,activePanel:"explorer",setActivePanel:()=>{}})},Cr=({functionId:o,version:t,versionList:a,fetchFunction:i,fetchVersionList:d})=>{const E={workflowConfig:{functionId:o,version:t,versionList:a,fetchFunction:i,fetchVersionList:d}};return l.jsx(J,{config:E})},_r=({codeContent:o,fileName:t="code.js",language:a="javascript",readOnly:i=!1})=>{const d={formConfig:{codeContent:o,fileName:t,language:a},settings:{readOnly:i}};return l.jsx(J,{config:d})},Sr=({fileUrls:o,rightPanel:t})=>{const a={urlConfig:{fileUrls:o}};return l.jsx(J,{config:a,rightPanel:t})},Tr="1.0.0";Object.defineProperty(exports,"Alert",{enumerable:!0,get:()=>x.Alert});Object.defineProperty(exports,"Button",{enumerable:!0,get:()=>x.Button});Object.defineProperty(exports,"Splitter",{enumerable:!0,get:()=>x.Splitter});Object.defineProperty(exports,"Tooltip",{enumerable:!0,get:()=>x.Tooltip});Object.defineProperty(exports,"Tree",{enumerable:!0,get:()=>x.Tree});exports.CodeEditor=We;exports.CodeEditorWrapper=J;exports.EditorLayout=Be;exports.FileExplorer=Me;exports.FormCodeEditor=_r;exports.FormFileProvider=Ne;exports.URLCodeEditor=Sr;exports.URLFileProvider=$e;exports.VERSION=Tr;exports.WorkflowCodeEditor=Cr;exports.WorkflowFileProvider=Ae;exports.createFileProvider=Le;exports.useFileManager=Oe;
|