Liferay.Loader.define("portal-workflow-kaleo-designer-web@5.0.115/designer/js/definition-builder/source-builder/SourceBuilder",["module","exports","require","@frontend-taglib-clay$clayui/alert","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/layout","@frontend-taglib-clay$clayui/link","@frontend-taglib-clay$clayui/loading-indicator","@frontend-taglib-clay$clayui/toolbar","frontend-editor-ckeditor-web","liferay!frontend-js-react-web$react","liferay!frontend-js-dependencies-web$react-flow-renderer","../DefinitionBuilderContext","../constants","./constants","./serializeUtil"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function SourceBuilder(){const{currentEditor:e,definitionDescription:t,definitionName:a,elements:p,setCurrentEditor:b,version:E}=(0,c.useContext)(s.DefinitionBuilderContext),w=(0,c.useRef)(),[C,v]=(0,c.useState)(!0),[L,_]=(0,c.useState)(!1),[D,R]=(0,c.useState)(!1);(0,c.useEffect)((()=>{const n=setInterval((()=>{e&&("source"!==e.mode?setTimeout((()=>{e.setMode("source")}),1e3):(clearInterval(n),function loadXmlContent(){if("source"===(null==e?void 0:e.mode)&&p){const n=(0,m.serializeDefinition)(g.xmlNamespace,{description:t,name:a,version:E},p.filter(f.isNode),p.filter(f.isEdge));n&&(e.setData(n),v(!1))}}()))}),1e3)}),[e,a,p,E]),(0,c.useEffect)((()=>{if(D)return document.addEventListener("keydown",(()=>{R(!1)})),()=>{document.removeEventListener("keydown",(()=>{R(!1)}))}}),[R,D]);const $=Liferay.Language.get("write-your-definition-or-x").substring(0,25),q=Liferay.Language.get("import-a-file").toLowerCase();return c.default.createElement(c.default.Fragment,null,c.default.createElement(u.default,{className:"source-toolbar"},c.default.createElement(r.default.ContainerFluid,null,c.default.createElement(u.default.Nav,null,c.default.createElement(u.default.Item,null,c.default.createElement("span",null,Liferay.Language.get("source"))),c.default.createElement(u.default.Item,null,c.default.createElement("div",{className:"import-file"},c.default.createElement(l.default,{symbol:"document-code"}),c.default.createElement("span",null,$),c.default.createElement("label",{className:"pt-1",htmlFor:"fileInput"},c.default.createElement(i.default,{className:"ml-1"},"".concat(q,"."))),c.default.createElement("input",{id:"fileInput",onChange:t=>function loadFile(t){R(!1);const a=t.target.files;if("text/xml"===a[0].type){const t=new FileReader;t.onloadend=t=>{t.target.readyState===FileReader.DONE&&(e.setData(t.target.result),document.querySelector("#fileInput").value="",_(!0))},t.readAsText(a[0])}else"text/xml"!==a[0].type&&R(!0)}(t),type:"file"})))))),C&&c.default.createElement(o.default,{displayType:"primary",shape:"squares",size:"md"}),c.default.createElement(d.Editor,{config:y.editorConfig,onInstanceReady:({editor:e})=>{e.setMode("source"),b(e)},ref:w}),L&&c.default.createElement(n.default.ToastContainer,null,c.default.createElement(n.default,{autoClose:5e3,displayType:"success",onClose:()=>_(!1),title:"".concat(Liferay.Language.get("success"),":")},Liferay.Language.get("definition-imported-successfully"))),D&&c.default.createElement(n.default.ToastContainer,null,c.default.createElement(n.default,{autoClose:5e3,displayType:"danger",onClose:()=>D(!1),title:"".concat(Liferay.Language.get("error"),":")},Liferay.Language.get("please-select-a-valid-xml-file"))))};var n=_interopRequireDefault(a("@frontend-taglib-clay$clayui/alert")),l=_interopRequireDefault(a("@frontend-taglib-clay$clayui/icon")),r=_interopRequireDefault(a("@frontend-taglib-clay$clayui/layout")),i=_interopRequireDefault(a("@frontend-taglib-clay$clayui/link")),o=_interopRequireDefault(a("@frontend-taglib-clay$clayui/loading-indicator")),u=_interopRequireDefault(a("@frontend-taglib-clay$clayui/toolbar")),d=a("frontend-editor-ckeditor-web"),c=function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var l in e)if(Object.prototype.hasOwnProperty.call(e,l)){var r=n?Object.getOwnPropertyDescriptor(e,l):null;r&&(r.get||r.set)?Object.defineProperty(a,l,r):a[l]=e[l]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react")),f=a("liferay!frontend-js-dependencies-web$react-flow-renderer"),s=a("../DefinitionBuilderContext"),y=a("../constants"),g=a("./constants"),m=a("./serializeUtil");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}}}));
//# sourceMappingURL=SourceBuilder.js.map