@kubed/code-editor 0.3.0-alpha.1 → 0.3.0-alpha.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/cjs/CodeEditor.js +1 -1
- package/cjs/CodeEditor.js.map +1 -1
- package/esm/CodeEditor.js +1 -1
- package/esm/CodeEditor.js.map +1 -1
- package/esm/index.js +1 -1
- package/package.json +6 -6
package/cjs/CodeEditor.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
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
|
package/cjs/CodeEditor.js.map
CHANGED
|
@@ -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":["
|
|
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,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EA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AAC,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
|
|
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
|
package/esm/CodeEditor.js.map
CHANGED
|
@@ -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":["
|
|
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,qBAA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ANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubed/code-editor",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.3",
|
|
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.3.0-alpha.
|
|
33
|
-
"@kubed/icons": "0.3.0-alpha.
|
|
34
|
-
"react": ">=
|
|
35
|
-
"react-dom": ">=
|
|
36
|
-
"react-is": ">=
|
|
32
|
+
"@kubed/hooks": "0.3.0-alpha.3",
|
|
33
|
+
"@kubed/icons": "0.3.0-alpha.3",
|
|
34
|
+
"react": ">=19.0.0 <20",
|
|
35
|
+
"react-dom": ">=19.0.0 <20",
|
|
36
|
+
"react-is": ">=19.0.0 <20"
|
|
37
37
|
}
|
|
38
38
|
}
|