@kubed/code-editor 0.2.37 → 0.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/CodeEditor.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),H=require("react-ace"),T=require("react-file-reader"),q=require("@kubed/icons"),W=require("@kubed/hooks"),z=require("file-saver"),R=require("lodash"),p=require("./styles.js");require("ace-builds/src-noconflict/mode-yaml"),require("ace-builds/src-noconflict/mode-groovy"),require("ace-builds/src-noconflict/theme-chaos"),require("ace-builds/src-noconflict/keybinding-vscode"),require("ace-builds/src-noconflict/ext-searchbox");function v(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var o=v(n),I=v(H),M=v(T),N=Object.defineProperty,s=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,j=(e,r,a)=>r in e?N(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,_=(e,r)=>{for(var a in r||(r={}))E.call(r,a)&&j(e,a,r[a]);if(s)for(var a of s(r))k.call(r,a)&&j(e,a,r[a]);return e},$=(e,r)=>{var a={};for(var l in e)E.call(e,l)&&r.indexOf(l)<0&&(a[l]=e[l]);if(e!=null&&s)for(var l of s(e))r.indexOf(l)<0&&k.call(e,l)&&(a[l]=e[l]);return a};const B=(e="",r)=>{const a=new Blob([e],{type:"text/plain;charset=utf-8"});z.saveAs(a,r)},J=n.forwardRef((e,r)=>{var a=e,{value:l="",mode:y="yaml",acceptFileTypes:D=[".yaml"],onChange:m=()=>{},hasDownload:u=!0,hasUpload:d=!0,fileName:x,readOnly:i,defaultValue:K,onDownload:C=t=>t,onUpload:P=t=>t}=a,b=$(a,["value","mode","acceptFileTypes","onChange","hasDownload","hasUpload","fileName","readOnly","defaultValue","onDownload","onUpload"]);const U=W.useForceUpdate(),[f,c]=n.useState(l),F=x||`default.${y}`,h=t=>{c(t),m&&m(t)},S=t=>{const g=new FileReader;g.onload=w=>{if(!R.isEmpty(w.target.result)){const O=P(w.target.result);c(O),h(O),U()}},g.readAsText(t[0])},V=()=>{const t=C(f);B(t,F)};n.useEffect(()=>{c(l)},[l]),n.useImperativeHandle(r,()=>({getValue:()=>f,setValue:t=>{c(t)}}));const A=()=>!u&&(!d||i)?null:o.createElement(p.ActionWrapper,null,d&&!i&&o.createElement(M,{fileTypes:D,handleFiles:S},o.createElement(q.Upload,{fill:"#fff",color:"#fff",size:20})),d&&!i&&u&&o.createElement(p.Divider,null,"|"),u&&o.createElement(q.Download,{fill:"#fff",color:"#fff",size:20,onClick:V}));return o.createElement(p.EditorWrapper,null,o.createElement(I,_({ref:r,theme:"chaos",width:"auto",height:"100%",tabSize:2,editorProps:{$blockScrolling:!0},showPrintMargin:!1,keyboardHandler:"vscode",mode:y,onChange:h,value:f,setOptions:_({useWorker:!1},b.setOptions),wrapEnabled:!0,readOnly:i},b)),A())});exports.CodeEditor=J;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime"),s=require("react"),N=require("react-ace"),T=require("react-file-reader"),O=require("@kubed/icons"),V=require("@kubed/hooks"),W=require("file-saver"),H=require("lodash"),p=require("./styles.js");require("ace-builds/src-noconflict/mode-yaml"),require("ace-builds/src-noconflict/mode-groovy"),require("ace-builds/src-noconflict/theme-chaos"),require("ace-builds/src-noconflict/keybinding-vscode"),require("ace-builds/src-noconflict/ext-searchbox");function w(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var I=w(N),L=w(T),M=Object.defineProperty,c=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,k=(e,r,a)=>r in e?M(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,D=(e,r)=>{for(var a in r||(r={}))q.call(r,a)&&k(e,a,r[a]);if(c)for(var a of c(r))g.call(r,a)&&k(e,a,r[a]);return e},R=(e,r)=>{var a={};for(var o in e)q.call(e,o)&&r.indexOf(o)<0&&(a[o]=e[o]);if(e!=null&&c)for(var o of c(e))r.indexOf(o)<0&&g.call(e,o)&&(a[o]=e[o]);return a};const $=(e="",r)=>{const a=new Blob([e],{type:"text/plain;charset=utf-8"});W.saveAs(a,r)},B=s.forwardRef((e,r)=>{var a=e,{value:o="",mode:v="yaml",acceptFileTypes:E=[".yaml"],onChange:h=()=>{},hasDownload:d=!0,hasUpload:u=!0,fileName:C,readOnly:n,defaultValue:K,onDownload:P=l=>l,onUpload:U=l=>l}=a,y=R(a,["value","mode","acceptFileTypes","onChange","hasDownload","hasUpload","fileName","readOnly","defaultValue","onDownload","onUpload"]);const _=V.useForceUpdate(),[f,i]=s.useState(o),F=C||`default.${v}`,b=l=>{i(l),h&&h(l)},S=l=>{const m=new FileReader;m.onload=j=>{if(!H.isEmpty(j.target.result)){const x=U(j.target.result);i(x),b(x),_()}},m.readAsText(l[0])},z=()=>{const l=P(f);$(l,F)};s.useEffect(()=>{i(o)},[o]),s.useImperativeHandle(r,()=>({getValue:()=>f,setValue:l=>{i(l)}}));const A=()=>!d&&(!u||n)?null:t.jsxs(p.ActionWrapper,{children:[u&&!n&&t.jsx(L,{fileTypes:E,handleFiles:S,children:t.jsx(O.Upload,{fill:"#fff",color:"#fff",size:20})}),u&&!n&&d&&t.jsx(p.Divider,{children:"|"}),d&&t.jsx(O.Download,{fill:"#fff",color:"#fff",size:20,onClick:z})]});return t.jsxs(p.EditorWrapper,{children:[t.jsx(I,D({ref:r,theme:"chaos",width:"auto",height:"100%",tabSize:2,editorProps:{$blockScrolling:!0},showPrintMargin:!1,keyboardHandler:"vscode",mode:v,onChange:b,value:f,setOptions:D({useWorker:!1},y.setOptions),wrapEnabled:!0,readOnly:n},y)),A()]})});exports.CodeEditor=B;
2
2
  //# sourceMappingURL=CodeEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.js","sources":["../src/CodeEditor.tsx"],"sourcesContent":["import React, { useState, useEffect, useImperativeHandle, RefObject, forwardRef } from 'react';\nimport AceEditor, { IAceEditorProps } from 'react-ace';\nimport ReactFileReader from 'react-file-reader';\nimport { Download, Upload } from '@kubed/icons';\nimport { useForceUpdate } from '@kubed/hooks';\nimport { saveAs } from 'file-saver';\nimport { isEmpty } from 'lodash';\nimport { EditorWrapper, ActionWrapper, Divider } from './styles';\n\nimport 'ace-builds/src-noconflict/mode-yaml';\nimport 'ace-builds/src-noconflict/mode-groovy';\nimport 'ace-builds/src-noconflict/theme-chaos';\nimport 'ace-builds/src-noconflict/keybinding-vscode';\nimport 'ace-builds/src-noconflict/ext-searchbox';\n\nconst saveAsFile = (text = '', fileName) => {\n const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });\n saveAs(blob, fileName);\n};\n\nexport interface CodeEditorRef {\n getValue?: () => void;\n setValue?: (value: string) => void;\n}\n\nexport interface CodeEditorProps extends IAceEditorProps {\n onUpload?: (value?: string) => string;\n onDownload?: (value?: string) => string;\n hasUpload?: boolean;\n hasDownload?: boolean;\n fileName?: string;\n acceptFileTypes?: string[];\n ref?: RefObject<CodeEditorRef>;\n}\n\nexport const CodeEditor = forwardRef(\n (\n {\n value = '',\n mode = 'yaml',\n acceptFileTypes = ['.yaml'],\n onChange = () => {},\n hasDownload = true,\n hasUpload = true,\n fileName,\n readOnly,\n defaultValue,\n onDownload = (v) => v,\n onUpload = (v) => v,\n ...rest\n }: CodeEditorProps,\n ref\n ) => {\n const forceUpdate = useForceUpdate();\n const [_value, setValue] = useState(value);\n const _fileName = fileName || `default.${mode}`;\n\n const handleChange = (v) => {\n setValue(v);\n onChange && onChange(v);\n };\n\n const handleUpload = (file) => {\n const reader = new FileReader();\n reader.onload = (e) => {\n if (!isEmpty(e.target.result)) {\n const v = onUpload(e.target.result as string);\n setValue(v);\n handleChange(v);\n forceUpdate();\n }\n };\n reader.readAsText(file[0]);\n };\n\n const handleDownload = () => {\n const downloadValue = onDownload(_value);\n saveAsFile(downloadValue, _fileName);\n };\n\n useEffect(() => {\n setValue(value);\n }, [value]);\n\n useImperativeHandle(ref, () => ({\n // only use for imperative mode\n getValue: () => {\n return _value;\n },\n setValue: (v) => {\n setValue(v);\n },\n }));\n\n const renderActions = () => {\n if (!hasDownload && (!hasUpload || readOnly)) return null;\n\n return (\n <ActionWrapper>\n {hasUpload && !readOnly && (\n <ReactFileReader fileTypes={acceptFileTypes} handleFiles={handleUpload}>\n <Upload fill=\"#fff\" color=\"#fff\" size={20} />\n </ReactFileReader>\n )}\n {hasUpload && !readOnly && hasDownload && <Divider>|</Divider>}\n {hasDownload && <Download fill=\"#fff\" color=\"#fff\" size={20} onClick={handleDownload} />}\n </ActionWrapper>\n );\n };\n\n return (\n <EditorWrapper>\n <AceEditor\n // @ts-ignore\n ref={ref}\n theme=\"chaos\"\n width=\"auto\"\n height=\"100%\"\n tabSize={2}\n editorProps={{ $blockScrolling: true }}\n showPrintMargin={false}\n keyboardHandler=\"vscode\"\n mode={mode}\n onChange={handleChange}\n value={_value}\n setOptions={{\n useWorker: false,\n ...rest.setOptions,\n }}\n wrapEnabled\n readOnly={readOnly}\n {...rest}\n />\n {renderActions()}\n </EditorWrapper>\n );\n }\n);\n"],"names":["$","T","_","z","B","I","S","s","q","H","O","G","N","M","j"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CA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,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAOL,UAAC,CAAC,aAAa,CAACM,oBAAC,CAAC,IAAI,CAACN,UAAC,CAAC,aAAa,CAACO,UAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"CodeEditor.js","sources":["../src/CodeEditor.tsx"],"sourcesContent":["import React, { useState, useEffect, useImperativeHandle, RefObject, forwardRef } from 'react';\nimport AceEditor, { IAceEditorProps } from 'react-ace';\nimport ReactFileReader from 'react-file-reader';\nimport { Download, Upload } from '@kubed/icons';\nimport { useForceUpdate } from '@kubed/hooks';\nimport { saveAs } from 'file-saver';\nimport { isEmpty } from 'lodash';\nimport { EditorWrapper, ActionWrapper, Divider } from './styles';\n\nimport 'ace-builds/src-noconflict/mode-yaml';\nimport 'ace-builds/src-noconflict/mode-groovy';\nimport 'ace-builds/src-noconflict/theme-chaos';\nimport 'ace-builds/src-noconflict/keybinding-vscode';\nimport 'ace-builds/src-noconflict/ext-searchbox';\n\nconst saveAsFile = (text = '', fileName) => {\n const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });\n saveAs(blob, fileName);\n};\n\nexport interface CodeEditorRef {\n getValue?: () => void;\n setValue?: (value: string) => void;\n}\n\nexport interface CodeEditorProps extends IAceEditorProps {\n onUpload?: (value?: string) => string;\n onDownload?: (value?: string) => string;\n hasUpload?: boolean;\n hasDownload?: boolean;\n fileName?: string;\n acceptFileTypes?: string[];\n ref?: RefObject<CodeEditorRef>;\n}\n\nexport const CodeEditor = forwardRef(\n (\n {\n value = '',\n mode = 'yaml',\n acceptFileTypes = ['.yaml'],\n onChange = () => {},\n hasDownload = true,\n hasUpload = true,\n fileName,\n readOnly,\n defaultValue,\n onDownload = (v) => v,\n onUpload = (v) => v,\n ...rest\n }: CodeEditorProps,\n ref\n ) => {\n const forceUpdate = useForceUpdate();\n const [_value, setValue] = useState(value);\n const _fileName = fileName || `default.${mode}`;\n\n const handleChange = (v) => {\n setValue(v);\n onChange && onChange(v);\n };\n\n const handleUpload = (file) => {\n const reader = new FileReader();\n reader.onload = (e) => {\n if (!isEmpty(e.target.result)) {\n const v = onUpload(e.target.result as string);\n setValue(v);\n handleChange(v);\n forceUpdate();\n }\n };\n reader.readAsText(file[0]);\n };\n\n const handleDownload = () => {\n const downloadValue = onDownload(_value);\n saveAsFile(downloadValue, _fileName);\n };\n\n useEffect(() => {\n setValue(value);\n }, [value]);\n\n useImperativeHandle(ref, () => ({\n // only use for imperative mode\n getValue: () => {\n return _value;\n },\n setValue: (v) => {\n setValue(v);\n },\n }));\n\n const renderActions = () => {\n if (!hasDownload && (!hasUpload || readOnly)) return null;\n\n return (\n <ActionWrapper>\n {hasUpload && !readOnly && (\n <ReactFileReader fileTypes={acceptFileTypes} handleFiles={handleUpload}>\n <Upload fill=\"#fff\" color=\"#fff\" size={20} />\n </ReactFileReader>\n )}\n {hasUpload && !readOnly && hasDownload && <Divider>|</Divider>}\n {hasDownload && <Download fill=\"#fff\" color=\"#fff\" size={20} onClick={handleDownload} />}\n </ActionWrapper>\n );\n };\n\n return (\n <EditorWrapper>\n <AceEditor\n // @ts-ignore\n ref={ref}\n theme=\"chaos\"\n width=\"auto\"\n height=\"100%\"\n tabSize={2}\n editorProps={{ $blockScrolling: true }}\n showPrintMargin={false}\n keyboardHandler=\"vscode\"\n mode={mode}\n onChange={handleChange}\n value={_value}\n setOptions={{\n useWorker: false,\n ...rest.setOptions,\n }}\n wrapEnabled\n readOnly={readOnly}\n {...rest}\n />\n {renderActions()}\n </EditorWrapper>\n );\n }\n);\n"],"names":["B","H","j","I","M","S","T","V","G","s","O","$","J","_","q","N"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC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eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;;;;"}
package/esm/CodeEditor.js CHANGED
@@ -1,2 +1,2 @@
1
- import l,{forwardRef as A,useState as S,useEffect as T,useImperativeHandle as W}from"react";import z from"react-ace";import H from"react-file-reader";import{Upload as R,Download as I}from"@kubed/icons";import{useForceUpdate as N}from"@kubed/hooks";import{saveAs as $}from"file-saver";import{isEmpty as B}from"lodash";import{EditorWrapper as J,ActionWrapper as K,Divider as M}from"./styles.js";import"ace-builds/src-noconflict/mode-yaml";import"ace-builds/src-noconflict/mode-groovy";import"ace-builds/src-noconflict/theme-chaos";import"ace-builds/src-noconflict/keybinding-vscode";import"ace-builds/src-noconflict/ext-searchbox";var q=Object.defineProperty,i=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,O=(e,r,o)=>r in e?q(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,E=(e,r)=>{for(var o in r||(r={}))w.call(r,o)&&O(e,o,r[o]);if(i)for(var o of i(r))g.call(r,o)&&O(e,o,r[o]);return e},G=(e,r)=>{var o={};for(var a in e)w.call(e,a)&&r.indexOf(a)<0&&(o[a]=e[a]);if(e!=null&&i)for(var a of i(e))r.indexOf(a)<0&&g.call(e,a)&&(o[a]=e[a]);return o};const L=(e="",r)=>{const o=new Blob([e],{type:"text/plain;charset=utf-8"});$(o,r)},Q=A((e,r)=>{var o=e,{value:a="",mode:p="yaml",acceptFileTypes:k=[".yaml"],onChange:m=()=>{},hasDownload:s=!0,hasUpload:f=!0,fileName:x,readOnly:n,defaultValue:X,onDownload:D=t=>t,onUpload:U=t=>t}=o,u=G(o,["value","mode","acceptFileTypes","onChange","hasDownload","hasUpload","fileName","readOnly","defaultValue","onDownload","onUpload"]);const j=N(),[d,c]=S(a),C=x||`default.${p}`,v=t=>{c(t),m&&m(t)},F=t=>{const y=new FileReader;y.onload=b=>{if(!B(b.target.result)){const h=U(b.target.result);c(h),v(h),j()}},y.readAsText(t[0])},P=()=>{const t=D(d);L(t,C)};T(()=>{c(a)},[a]),W(r,()=>({getValue:()=>d,setValue:t=>{c(t)}}));const V=()=>!s&&(!f||n)?null:l.createElement(K,null,f&&!n&&l.createElement(H,{fileTypes:k,handleFiles:F},l.createElement(R,{fill:"#fff",color:"#fff",size:20})),f&&!n&&s&&l.createElement(M,null,"|"),s&&l.createElement(I,{fill:"#fff",color:"#fff",size:20,onClick:P}));return l.createElement(J,null,l.createElement(z,E({ref:r,theme:"chaos",width:"auto",height:"100%",tabSize:2,editorProps:{$blockScrolling:!0},showPrintMargin:!1,keyboardHandler:"vscode",mode:p,onChange:v,value:d,setOptions:E({useWorker:!1},u.setOptions),wrapEnabled:!0,readOnly:n},u)),V())});export{Q as CodeEditor};
1
+ import{jsxs as w,jsx as t}from"react/jsx-runtime";import{forwardRef as S,useState as T,useEffect as V,useImperativeHandle as W}from"react";import N from"react-ace";import H from"react-file-reader";import{Upload as I,Download as $}from"@kubed/icons";import{useForceUpdate as B}from"@kubed/hooks";import{saveAs as K}from"file-saver";import{isEmpty as L}from"lodash";import{EditorWrapper as M,ActionWrapper as R,Divider as q}from"./styles.js";import"ace-builds/src-noconflict/mode-yaml";import"ace-builds/src-noconflict/mode-groovy";import"ace-builds/src-noconflict/theme-chaos";import"ace-builds/src-noconflict/keybinding-vscode";import"ace-builds/src-noconflict/ext-searchbox";var G=Object.defineProperty,f=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,x=(e,o,r)=>o in e?G(e,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[o]=r,D=(e,o)=>{for(var r in o||(o={}))O.call(o,r)&&x(e,r,o[r]);if(f)for(var r of f(o))g.call(o,r)&&x(e,r,o[r]);return e},J=(e,o)=>{var r={};for(var a in e)O.call(e,a)&&o.indexOf(a)<0&&(r[a]=e[a]);if(e!=null&&f)for(var a of f(e))o.indexOf(a)<0&&g.call(e,a)&&(r[a]=e[a]);return r};const Q=(e="",o)=>{const r=new Blob([e],{type:"text/plain;charset=utf-8"});K(r,o)},X=S((e,o)=>{var r=e,{value:a="",mode:c="yaml",acceptFileTypes:E=[".yaml"],onChange:m=()=>{},hasDownload:p=!0,hasUpload:s=!0,fileName:U,readOnly:n,defaultValue:Y,onDownload:j=l=>l,onUpload:C=l=>l}=r,u=J(r,["value","mode","acceptFileTypes","onChange","hasDownload","hasUpload","fileName","readOnly","defaultValue","onDownload","onUpload"]);const F=B(),[d,i]=T(a),P=U||`default.${c}`,h=l=>{i(l),m&&m(l)},k=l=>{const v=new FileReader;v.onload=y=>{if(!L(y.target.result)){const b=C(y.target.result);i(b),h(b),F()}},v.readAsText(l[0])},z=()=>{const l=j(d);Q(l,P)};V(()=>{i(a)},[a]),W(o,()=>({getValue:()=>d,setValue:l=>{i(l)}}));const A=()=>!p&&(!s||n)?null:w(R,{children:[s&&!n&&t(H,{fileTypes:E,handleFiles:k,children:t(I,{fill:"#fff",color:"#fff",size:20})}),s&&!n&&p&&t(q,{children:"|"}),p&&t($,{fill:"#fff",color:"#fff",size:20,onClick:z})]});return w(M,{children:[t(N,D({ref:o,theme:"chaos",width:"auto",height:"100%",tabSize:2,editorProps:{$blockScrolling:!0},showPrintMargin:!1,keyboardHandler:"vscode",mode:c,onChange:h,value:d,setOptions:D({useWorker:!1},u.setOptions),wrapEnabled:!0,readOnly:n},u)),A()]})});export{X as CodeEditor};
2
2
  //# sourceMappingURL=CodeEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.js","sources":["../src/CodeEditor.tsx"],"sourcesContent":["import React, { useState, useEffect, useImperativeHandle, RefObject, forwardRef } from 'react';\nimport AceEditor, { IAceEditorProps } from 'react-ace';\nimport ReactFileReader from 'react-file-reader';\nimport { Download, Upload } from '@kubed/icons';\nimport { useForceUpdate } from '@kubed/hooks';\nimport { saveAs } from 'file-saver';\nimport { isEmpty } from 'lodash';\nimport { EditorWrapper, ActionWrapper, Divider } from './styles';\n\nimport 'ace-builds/src-noconflict/mode-yaml';\nimport 'ace-builds/src-noconflict/mode-groovy';\nimport 'ace-builds/src-noconflict/theme-chaos';\nimport 'ace-builds/src-noconflict/keybinding-vscode';\nimport 'ace-builds/src-noconflict/ext-searchbox';\n\nconst saveAsFile = (text = '', fileName) => {\n const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });\n saveAs(blob, fileName);\n};\n\nexport interface CodeEditorRef {\n getValue?: () => void;\n setValue?: (value: string) => void;\n}\n\nexport interface CodeEditorProps extends IAceEditorProps {\n onUpload?: (value?: string) => string;\n onDownload?: (value?: string) => string;\n hasUpload?: boolean;\n hasDownload?: boolean;\n fileName?: string;\n acceptFileTypes?: string[];\n ref?: RefObject<CodeEditorRef>;\n}\n\nexport const CodeEditor = forwardRef(\n (\n {\n value = '',\n mode = 'yaml',\n acceptFileTypes = ['.yaml'],\n onChange = () => {},\n hasDownload = true,\n hasUpload = true,\n fileName,\n readOnly,\n defaultValue,\n onDownload = (v) => v,\n onUpload = (v) => v,\n ...rest\n }: CodeEditorProps,\n ref\n ) => {\n const forceUpdate = useForceUpdate();\n const [_value, setValue] = useState(value);\n const _fileName = fileName || `default.${mode}`;\n\n const handleChange = (v) => {\n setValue(v);\n onChange && onChange(v);\n };\n\n const handleUpload = (file) => {\n const reader = new FileReader();\n reader.onload = (e) => {\n if (!isEmpty(e.target.result)) {\n const v = onUpload(e.target.result as string);\n setValue(v);\n handleChange(v);\n forceUpdate();\n }\n };\n reader.readAsText(file[0]);\n };\n\n const handleDownload = () => {\n const downloadValue = onDownload(_value);\n saveAsFile(downloadValue, _fileName);\n };\n\n useEffect(() => {\n setValue(value);\n }, [value]);\n\n useImperativeHandle(ref, () => ({\n // only use for imperative mode\n getValue: () => {\n return _value;\n },\n setValue: (v) => {\n setValue(v);\n },\n }));\n\n const renderActions = () => {\n if (!hasDownload && (!hasUpload || readOnly)) return null;\n\n return (\n <ActionWrapper>\n {hasUpload && !readOnly && (\n <ReactFileReader fileTypes={acceptFileTypes} handleFiles={handleUpload}>\n <Upload fill=\"#fff\" color=\"#fff\" size={20} />\n </ReactFileReader>\n )}\n {hasUpload && !readOnly && hasDownload && <Divider>|</Divider>}\n {hasDownload && <Download fill=\"#fff\" color=\"#fff\" size={20} onClick={handleDownload} />}\n </ActionWrapper>\n );\n };\n\n return (\n <EditorWrapper>\n <AceEditor\n // @ts-ignore\n ref={ref}\n theme=\"chaos\"\n width=\"auto\"\n height=\"100%\"\n tabSize={2}\n editorProps={{ $blockScrolling: true }}\n showPrintMargin={false}\n keyboardHandler=\"vscode\"\n mode={mode}\n onChange={handleChange}\n value={_value}\n setOptions={{\n useWorker: false,\n ...rest.setOptions,\n }}\n wrapEnabled\n readOnly={readOnly}\n {...rest}\n />\n {renderActions()}\n </EditorWrapper>\n );\n }\n);\n"],"names":["$","T","_","z","B","I","S","q","O","G","N","M"],"mappings":";;;;;;;;;;;;;;AAAA,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC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AC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,CAACC,aAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"CodeEditor.js","sources":["../src/CodeEditor.tsx"],"sourcesContent":["import React, { useState, useEffect, useImperativeHandle, RefObject, forwardRef } from 'react';\nimport AceEditor, { IAceEditorProps } from 'react-ace';\nimport ReactFileReader from 'react-file-reader';\nimport { Download, Upload } from '@kubed/icons';\nimport { useForceUpdate } from '@kubed/hooks';\nimport { saveAs } from 'file-saver';\nimport { isEmpty } from 'lodash';\nimport { EditorWrapper, ActionWrapper, Divider } from './styles';\n\nimport 'ace-builds/src-noconflict/mode-yaml';\nimport 'ace-builds/src-noconflict/mode-groovy';\nimport 'ace-builds/src-noconflict/theme-chaos';\nimport 'ace-builds/src-noconflict/keybinding-vscode';\nimport 'ace-builds/src-noconflict/ext-searchbox';\n\nconst saveAsFile = (text = '', fileName) => {\n const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });\n saveAs(blob, fileName);\n};\n\nexport interface CodeEditorRef {\n getValue?: () => void;\n setValue?: (value: string) => void;\n}\n\nexport interface CodeEditorProps extends IAceEditorProps {\n onUpload?: (value?: string) => string;\n onDownload?: (value?: string) => string;\n hasUpload?: boolean;\n hasDownload?: boolean;\n fileName?: string;\n acceptFileTypes?: string[];\n ref?: RefObject<CodeEditorRef>;\n}\n\nexport const CodeEditor = forwardRef(\n (\n {\n value = '',\n mode = 'yaml',\n acceptFileTypes = ['.yaml'],\n onChange = () => {},\n hasDownload = true,\n hasUpload = true,\n fileName,\n readOnly,\n defaultValue,\n onDownload = (v) => v,\n onUpload = (v) => v,\n ...rest\n }: CodeEditorProps,\n ref\n ) => {\n const forceUpdate = useForceUpdate();\n const [_value, setValue] = useState(value);\n const _fileName = fileName || `default.${mode}`;\n\n const handleChange = (v) => {\n setValue(v);\n onChange && onChange(v);\n };\n\n const handleUpload = (file) => {\n const reader = new FileReader();\n reader.onload = (e) => {\n if (!isEmpty(e.target.result)) {\n const v = onUpload(e.target.result as string);\n setValue(v);\n handleChange(v);\n forceUpdate();\n }\n };\n reader.readAsText(file[0]);\n };\n\n const handleDownload = () => {\n const downloadValue = onDownload(_value);\n saveAsFile(downloadValue, _fileName);\n };\n\n useEffect(() => {\n setValue(value);\n }, [value]);\n\n useImperativeHandle(ref, () => ({\n // only use for imperative mode\n getValue: () => {\n return _value;\n },\n setValue: (v) => {\n setValue(v);\n },\n }));\n\n const renderActions = () => {\n if (!hasDownload && (!hasUpload || readOnly)) return null;\n\n return (\n <ActionWrapper>\n {hasUpload && !readOnly && (\n <ReactFileReader fileTypes={acceptFileTypes} handleFiles={handleUpload}>\n <Upload fill=\"#fff\" color=\"#fff\" size={20} />\n </ReactFileReader>\n )}\n {hasUpload && !readOnly && hasDownload && <Divider>|</Divider>}\n {hasDownload && <Download fill=\"#fff\" color=\"#fff\" size={20} onClick={handleDownload} />}\n </ActionWrapper>\n );\n };\n\n return (\n <EditorWrapper>\n <AceEditor\n // @ts-ignore\n ref={ref}\n theme=\"chaos\"\n width=\"auto\"\n height=\"100%\"\n tabSize={2}\n editorProps={{ $blockScrolling: true }}\n showPrintMargin={false}\n keyboardHandler=\"vscode\"\n mode={mode}\n onChange={handleChange}\n value={_value}\n setOptions={{\n useWorker: false,\n ...rest.setOptions,\n }}\n wrapEnabled\n readOnly={readOnly}\n {...rest}\n />\n {renderActions()}\n </EditorWrapper>\n );\n }\n);\n"],"names":["B","H","j","I","M","S","T","V","G","s","$","J","_","q"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CA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AQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;;;;"}
package/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{CodeEditor as r}from"./CodeEditor.js";export{r as CodeEditor};
1
+ import{CodeEditor as d}from"./CodeEditor.js";export{d as CodeEditor};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubed/code-editor",
3
- "version": "0.2.37",
3
+ "version": "0.3.0-alpha.2",
4
4
  "homepage": "https://github.com/kubesphere/kube-design",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,10 +29,10 @@
29
29
  "@types/file-saver": "^2.0.5"
30
30
  },
31
31
  "peerDependencies": {
32
- "@kubed/hooks": "0.2.37",
33
- "@kubed/icons": "0.2.37",
34
- "react": ">=16.8.6",
35
- "react-dom": ">=16.8.6",
36
- "react-is": "^17.0.2"
32
+ "@kubed/hooks": "0.3.0-alpha.2",
33
+ "@kubed/icons": "0.3.0-alpha.2",
34
+ "react": ">=19.0.0 <20",
35
+ "react-dom": ">=19.0.0 <20",
36
+ "react-is": ">=19.0.0 <20"
37
37
  }
38
38
  }