/*!
 * Copyright © 2018 Splunk Inc.
 * SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
 * in part without a valid written license from Splunk Inc. is PROHIBITED.
 */(()=>{"use strict";var e={7970:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,a)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return a(t,e),t},i=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]])}return r},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const u=o(r(9497)),l=o(r(23)),c=s(r(232)),d=r(1398),p=s(r(1018)),m=s(r(6447)),f=r(6649),b=r(8987),g=s(r(4703)),v=s(r(4723)),O=s(r(4784)),x=s(r(7110)),h=s(r(6078)),y=s(r(3757)),j=s(r(785)),_=s(r(6301)),k=s(r(821)),E=s(r(7020)),q=s(r(6379)),w=s(r(5905)),C=s(r(2621)),M=r(3563),P=r(5135),R=r(962),S=r(137),D=[Object.assign(Object.assign({},d.commands.heading3),{icon:u.createElement(O.default,null),name:"header"}),Object.assign(Object.assign({},d.commands.bold),{icon:u.createElement(g.default,null),name:"bold"}),Object.assign(Object.assign({},d.commands.italic),{icon:u.createElement(x.default,null),name:"italic"}),Object.assign(Object.assign({},d.commands.link),{icon:u.createElement(v.default,null),name:"link"}),Object.assign(Object.assign({},d.commands.quote),{icon:u.createElement(k.default,null),name:"quote"}),Object.assign(Object.assign({},d.commands.code),{icon:u.createElement(h.default,null),name:"code"}),Object.assign(Object.assign({},d.commands.image),{icon:u.createElement(y.default,null),name:"image"}),Object.assign(Object.assign({},d.commands.unorderedListCommand),{icon:u.createElement(j.default,null),name:"unordered-list"}),Object.assign(Object.assign({},d.commands.orderedListCommand),{icon:u.createElement(_.default,null),name:"ordered-list"})],L=c.default.div`
    font-family: ${M.variables.sansFontFamily};
`,T=c.default.div`
    display: flex;
    padding: 12px 0;
    justify-content: space-between;
`,F=(0,c.default)(w.default)`
    [data-test='textbox'] {
        resize: vertical;
    }
`,I=c.default.div`
    display: none;
`,B=(0,c.default)(E.default)`
    flex: 0;
`,$={error:1,warning:2,other:3},A=u.memo((({command:e,isFocusable:t,onFocus:r,onExecute:n})=>{const{icon:a,buttonProps:o}=e,{title:s}=o||{};return u.createElement(q.default,{content:s||"",contentRelationship:"label",renderAnchor:o=>{var{onFocus:s,onClick:l}=o,c=i(o,["onFocus","onClick"]);return u.createElement(B,Object.assign({appearance:"subtle","data-name":e.name,onFocus:t=>{s(t),r(e.name||"")},tabIndex:t?0:-1,onClick:t=>{l(t),n(e)}},c),a)}})}));A.displayName="ToolbarButton",A.propTypes={command:l.object.isRequired,isFocusable:l.bool.isRequired,onFocus:l.func.isRequired,onExecute:l.func.isRequired};const U=({onChange:e,name:t,value:r="",defaultErrors:n={}})=>{const a=u.useMemo((()=>(0,b.createDOMID)("markdown-editor")),[]),o=u.useRef(null),[i,s]=u.useState(r),[l,c]=u.useState(D[0].name||""),g=u.useRef(null),[v,O]=u.useState(n);u.useEffect((()=>(o.current&&!g.current&&(g.current=new d.TextAreaCommandOrchestrator(o.current)),()=>{g.current=null})),[]);const x=u.useCallback(((e,{value:t})=>{s(t)}),[]),h=u.useCallback((a=>{i!==r&&(e(a,t,i),O(n))}),[i,r,e,t,n]),y=u.useCallback((e=>{g.current&&o.current&&(g.current.executeCommand(e),s(o.current.value))}),[]),j=u.useMemo((()=>{let e=null;return Object.values(v).includes("error")?e=u.createElement(R.CSPMessage,{type:"error"}):Object.values(v).includes("warning")&&(e=u.createElement(R.CSPMessage,{type:"warning"})),Object.values(v).includes("other")&&(e=u.createElement(u.Fragment,null,e,u.createElement(m.default,{appearance:"fill",type:"error","data-test":"image-error"},(0,f._)("We can't find an image with this URL. Please enter a new URL")))),e}),[Object.values(v).join("")]),_=u.useMemo((()=>{return u.createElement(I,null,u.createElement(p.default,{text:r,imageRenderer:(e=(e,t)=>{var r,n;(null!==(r=$[v[e]])&&void 0!==r?r:1/0)>(null!==(n=$[t])&&void 0!==n?n:0)&&O(Object.assign(Object.assign({},v),{[e]:t}))},function({src:t,alt:r}){const n=(0,P.useCSPViolationObserver)(t);return u.useEffect((()=>{"none"!==n&&e(t,n)}),[n,t]),u.createElement("img",{src:t,alt:r,onError:()=>{"none"===n&&e(t,"other")}})})}));var e}),[r,v]),k=u.useCallback((e=>{var t,r;const n=e.target;if("BUTTON"!==n.tagName)return;const a=e.currentTarget,o=Array.from(a.querySelectorAll("button")),i=o.indexOf(n);if(-1===i)return;const s="ArrowLeft"===e.key,u="ArrowRight"===e.key,l="Home"===e.key,c="End"===e.key;let d=null;s?d=null!==(t=o[i-1])&&void 0!==t?t:o[o.length-1]:u?d=null!==(r=o[i+1])&&void 0!==r?r:o[0]:l?[d]=o:c&&(d=o[o.length-1]),d&&(e.preventDefault(),d.focus())}),[]),E=u.useCallback((e=>{(0,d.handleKeyDown)(e,2,!0),g.current&&((0,d.shortcuts)(e,D,g.current),o.current&&s(o.current.value))}),[]);return u.createElement(L,{"data-test":t},u.createElement(T,{role:"toolbar","aria-label":(0,f._)("Markdown formatting"),"aria-orientation":"horizontal","aria-controls":`${a}-textarea`,onKeyDown:k},D.map((e=>u.createElement(A,{key:e.name,command:e,isFocusable:l===e.name,onFocus:c,onExecute:y})))),u.createElement(C.default,{id:`${a}-textarea-label`},(0,f._)("Markdown editor")),u.createElement(F,{inputRef:o,"data-test":`${t}-textarea`,id:`${a}-textarea`,labelledBy:`${a}-textarea-label`,value:i,onChange:x,onBlur:h,onKeyDown:E}),_,j&&u.createElement(S.MessageContainer,null,j))};U.propTypes={onChange:l.func.isRequired,name:l.string.isRequired,value:l.string,defaultErrors:l.objectOf(l.oneOf(["warning","error","other"]))},t.default=U},5135:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useCSPViolationObserver=void 0;const n=r(9497);t.useCSPViolationObserver=(e,t="none")=>{const[r,a]=(0,n.useState)(t);return(0,n.useEffect)((()=>{const r=t=>{t.blockedURI!==e&&t.blockedURI!==`${e}/`||"enforce"!==t.disposition?t.blockedURI!==e&&t.blockedURI!==`${e}/`||"report"!==t.disposition||a("warning"):a("error")};return document.addEventListener("securitypolicyviolation",r),a(t),()=>{document.removeEventListener("securitypolicyviolation",r)}}),[e]),r}},962:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,a)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return a(t,e),t},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.CSPMessage=void 0;const s=o(r(9497)),u=r(6649),l=i(r(6447)),c=i(r(451)),d=i(r(5711));t.CSPMessage=({type:e})=>{const{cspMessageLink:t}=s.useContext(d.default);return s.createElement(l.default,{appearance:"fill",type:e,"data-test":`csp-message-${e}`},(0,u._)("External image URLs must now have their domains listed in the Dashboards Trusted Domains List by working with your administrator. Alternatively, you can upload the image directly into the dashboard. "),t&&s.createElement(c.default,{to:t,openInNewContext:!0},(0,u._)("Learn more")))}},137:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.MessageContainer=void 0;const a=n(r(232));t.MessageContainer=a.default.div`
    margin-top: 10px;
`},4723:e=>{e.exports=require("@splunk/react-icons/Chain")},6078:e=>{e.exports=require("@splunk/react-icons/ChevronsSlash")},785:e=>{e.exports=require("@splunk/react-icons/List")},6301:e=>{e.exports=require("@splunk/react-icons/ListNumbered")},3757:e=>{e.exports=require("@splunk/react-icons/Picture")},821:e=>{e.exports=require("@splunk/react-icons/QuotationDouble")},4703:e=>{e.exports=require("@splunk/react-icons/TextBBold")},4784:e=>{e.exports=require("@splunk/react-icons/TextH")},7110:e=>{e.exports=require("@splunk/react-icons/TextIItalic")},7020:e=>{e.exports=require("@splunk/react-ui/Button")},451:e=>{e.exports=require("@splunk/react-ui/Link")},1018:e=>{e.exports=require("@splunk/react-ui/Markdown")},6447:e=>{e.exports=require("@splunk/react-ui/Message")},2621:e=>{e.exports=require("@splunk/react-ui/ScreenReaderContent")},5905:e=>{e.exports=require("@splunk/react-ui/TextArea")},6379:e=>{e.exports=require("@splunk/react-ui/Tooltip")},3563:e=>{e.exports=require("@splunk/themes")},6649:e=>{e.exports=require("@splunk/ui-utils/i18n")},8987:e=>{e.exports=require("@splunk/ui-utils/id")},5711:e=>{e.exports=require("@splunk/visualization-context/MessageContext")},1398:e=>{e.exports=require("@uiw/react-md-editor/nohighlight")},23:e=>{e.exports=require("prop-types")},9497:e=>{e.exports=require("react")},232:e=>{e.exports=require("styled-components")}},t={};var r=function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}(7970);module.exports=r})();
//# sourceMappingURL=MarkdownEditor.js.map