import t from"@babel/runtime/helpers/toConsumableArray";import e from"@babel/runtime/helpers/defineProperty";import{useMemo as r,useCallback as n}from"react";import a from"prop-types";import{withReact as o,Slate as i,Editable as l}from"slate-react";import{createEditor as c}from"slate";import{every as s}from"lodash";import{Element as p,Leaf as d}from"./RenderElements.js";import{slateFormattingTextUtils as f}from"./utils.js";import{jsx as u,jsxs as m}from"react/jsx-runtime";function O(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function S(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?O(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var x=function(e){var a,O=e.text,x=e.textsList,y=e.defaultText,b=e.defaultRenderingTextNode,g=e.locator,h="".concat(g,"_slateText"),T=r((function(){return o(c())}),[]),j=n((function(t){return u(p,S({},t))}),[]),N=n((function(t){return u(d,S({},t))}),[]),v=r((function(){var e=f.getValidSlateJSON(O),r=e.isTextValidSlateJSON,n=e.parsedJSON;if(x.length){var a=x.map((function(t){return f.getValidSlateJSON(t)}));r=s(a,(function(t){return t.isTextValidSlateJSON})),n=f.getDefaultParagraphObjectEmpty(),r&&a.forEach((function(e){var r,a=e.parsedJSON;f.isSlateTextEmpty(a)||(n[0].children=(r=n[0].children).concat.apply(r,t(a.map((function(t){return t.children})))));n[0].children=n[0].children.concat({text:"\n"})}))}var o=r&&f.isSlateTextEmpty(n);return{isValidSlateJSON:r,parsedSlateJSON:n,isEmptySlateJSON:o}}),[O,String(x)]),J=v.isValidSlateJSON,E=v.parsedSlateJSON,P=v.isEmptySlateJSON,V=f.getFormattedText({isValid:J,isEmpty:P,text:O,parsedText:E,defaultText:y});return a=x.length>0?x.map((function(t){return m("span",{"data-testid":"".concat(h,"_listItem"),children:[t,u("br",{})]},t)})):J&&P||!b?V:b,J&&!P?u(i,{editor:T,value:V,children:u(l,{"data-testid":"".concat(h,"_editable"),renderElement:j,renderLeaf:N,readOnly:!0})}):a};x.propTypes={text:a.string,textsList:a.arrayOf(a.string),defaultText:a.oneOfType([a.string,a.node]),defaultRenderingTextNode:a.node,locator:a.string},x.defaultProps={text:"",textsList:[],defaultText:"",defaultRenderingTextNode:void 0,locator:"SlateFormattedText"};export{x as default};
//# sourceMappingURL=SlateFormattedText.js.map
