mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 21:20:57 +00:00
31 lines
12 KiB
JavaScript
31 lines
12 KiB
JavaScript
var j=Object.defineProperty;var F=(o,s,e)=>s in o?j(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var p=(o,s,e)=>F(o,typeof s!="symbol"?s+"":s,e);import{r as y,j as R,b4 as b,w as k,n as T,o as E}from"./index-Db-xuq0b.js";import{u as x,E as N,s as I,c as A,d as P,e as C,f as $,m as O,g as L}from"./Utils-BP0IYDrC.js";const z=(o,s,e)=>{const t=o.createElement("script");t.referrerPolicy="origin",t.type="application/javascript",t.id=s.id,t.src=s.src,t.async=s.async??!1,t.defer=s.defer??!1;const i=()=>{t.removeEventListener("load",i),t.removeEventListener("error",a),e(s.src)},a=r=>{t.removeEventListener("load",i),t.removeEventListener("error",a),e(s.src,r)};t.addEventListener("load",i),t.addEventListener("error",a),o.head&&o.head.appendChild(t)},q=o=>{let s={};const e=(r,c)=>{const n=s[r];n.done=!0,n.error=c;for(const l of n.handlers)l(r,c);n.handlers=[]};return{loadScripts:(r,c,n)=>{const l=h=>n!==void 0?n(h):void 0;if(r.length===0){l(new Error("At least one script must be provided"));return}let d=0,f=!1;const m=(h,u)=>{f||(u?(f=!0,l(u)):++d===r.length&&c())};for(const h of r){const u=s[h.src];if(u)u.done?m(h.src,u.error):u.handlers.push(m);else{const v=x("tiny-");s[h.src]={id:v,src:h.src,done:!1,error:null,handlers:[m]},z(o,{id:v,...h},e)}}},deleteScripts:()=>{var r;for(const c of Object.values(s)){const n=o.getElementById(c.id);n!=null&&n.tagName==="SCRIPT"&&((r=n.parentNode)==null||r.removeChild(n))}s={}},getDocument:()=>o}},K=()=>{const o=[],s=i=>{let a=o.find(r=>r.getDocument()===i);return a===void 0&&(a=q(i),o.push(a)),a};return{loadList:(i,a,r,c,n)=>{const l=()=>s(i).loadScripts(a,c,n);r>0?setTimeout(l,r):l()},reinitialize:()=>{for(let i=o.pop();i!=null;i=o.pop())i.deleteScripts()}}},U=K(),w=o=>{const s=o;return s&&s.tinymce?s.tinymce:null};class S extends y.Component{constructor(e){var t;super(e);p(this,"editor");p(this,"id");p(this,"elementRef");p(this,"inline");p(this,"currentContent");p(this,"boundHandlers");p(this,"rollbackTimer");p(this,"valueCursor");p(this,"rollbackChange",()=>{const e=this.editor,t=this.props.value;e&&t&&t!==this.currentContent&&e.undoManager.ignore(()=>{if(e.setContent(t),this.valueCursor&&(!this.inline||e.hasFocus()))try{e.selection.moveToBookmark(this.valueCursor)}catch{}}),this.rollbackTimer=void 0});p(this,"handleBeforeInput",e=>{if(this.props.value!==void 0&&this.props.value===this.currentContent&&this.editor&&(!this.inline||this.editor.hasFocus()))try{this.valueCursor=this.editor.selection.getBookmark(3)}catch{}});p(this,"handleBeforeInputSpecial",e=>{(e.key==="Enter"||e.key==="Backspace"||e.key==="Delete")&&this.handleBeforeInput(e)});p(this,"handleEditorChange",e=>{const t=this.editor;if(t&&t.initialized){const i=t.getContent();this.props.value!==void 0&&this.props.value!==i&&this.props.rollback!==!1&&(this.rollbackTimer||(this.rollbackTimer=window.setTimeout(this.rollbackChange,typeof this.props.rollback=="number"?this.props.rollback:200))),i!==this.currentContent&&(this.currentContent=i,C(this.props.onEditorChange)&&this.props.onEditorChange(i,t))}});p(this,"handleEditorChangeSpecial",e=>{(e.key==="Backspace"||e.key==="Delete")&&this.handleEditorChange(e)});p(this,"initialise",(e=0)=>{var r,c;const t=this.elementRef.current;if(!t)return;if(!$(t)){if(e===0)setTimeout(()=>this.initialise(1),1);else if(e<100)setTimeout(()=>this.initialise(e+1),100);else throw new Error("tinymce can only be initialised when in a document");return}const i=w(this.view);if(!i)throw new Error("tinymce should have been loaded into global scope");const a={...this.props.init,selector:void 0,target:t,readonly:this.props.disabled,inline:this.inline,plugins:O((r=this.props.init)==null?void 0:r.plugins,this.props.plugins),toolbar:this.props.toolbar??((c=this.props.init)==null?void 0:c.toolbar),...this.props.licenseKey?{license_key:this.props.licenseKey}:{},setup:n=>{this.editor=n,this.bindHandlers({}),this.inline&&!L(t)&&n.once("PostRender",l=>{n.setContent(this.getInitialValue(),{no_events:!0})}),this.props.init&&C(this.props.init.setup)&&this.props.init.setup(n)},init_instance_callback:n=>{const l=this.getInitialValue();this.currentContent=this.currentContent??n.getContent(),this.currentContent!==l&&(this.currentContent=l,n.setContent(l),n.undoManager.clear(),n.undoManager.add(),n.setDirty(!1));const d=this.props.disabled??!1;I(this.editor,d?"readonly":"design"),this.props.init&&C(this.props.init.init_instance_callback)&&this.props.init.init_instance_callback(n)}};this.inline||(t.style.visibility=""),L(t)&&(t.value=this.getInitialValue()),i.init(a)});this.id=this.props.id||x("tiny-react"),this.elementRef=y.createRef(),this.inline=this.props.inline??((t=this.props.init)==null?void 0:t.inline)??!1,this.boundHandlers={}}get view(){var e;return((e=this.elementRef.current)==null?void 0:e.ownerDocument.defaultView)??window}componentDidUpdate(e){if(this.rollbackTimer&&(clearTimeout(this.rollbackTimer),this.rollbackTimer=void 0),this.editor&&(this.bindHandlers(e),this.editor.initialized)){if(this.currentContent=this.currentContent??this.editor.getContent(),typeof this.props.initialValue=="string"&&this.props.initialValue!==e.initialValue)this.editor.setContent(this.props.initialValue),this.editor.undoManager.clear(),this.editor.undoManager.add(),this.editor.setDirty(!1);else if(typeof this.props.value=="string"&&this.props.value!==this.currentContent){const t=this.editor;t.undoManager.transact(()=>{let i;if(!this.inline||t.hasFocus())try{i=t.selection.getBookmark(3)}catch{}const a=this.valueCursor;if(t.setContent(this.props.value),!this.inline||t.hasFocus()){for(const r of[i,a])if(r)try{t.selection.moveToBookmark(r),this.valueCursor=r;break}catch{}}})}if(this.props.disabled!==e.disabled){const t=this.props.disabled??!1;I(this.editor,t?"readonly":"design")}}}componentDidMount(){var e,t,i,a;if(w(this.view)!==null)this.initialise();else if(Array.isArray(this.props.tinymceScriptSrc)&&this.props.tinymceScriptSrc.length===0)(t=(e=this.props).onScriptsLoadError)==null||t.call(e,new Error("No `tinymce` global is present but the `tinymceScriptSrc` prop was an empty array."));else if((i=this.elementRef.current)!=null&&i.ownerDocument){const r=()=>{var n,l;(l=(n=this.props).onScriptsLoad)==null||l.call(n),this.initialise()},c=n=>{var l,d;(d=(l=this.props).onScriptsLoadError)==null||d.call(l,n)};U.loadList(this.elementRef.current.ownerDocument,this.getScriptSources(),((a=this.props.scriptLoading)==null?void 0:a.delay)??0,r,c)}}componentWillUnmount(){const e=this.editor;e&&(e.off(this.changeEvents(),this.handleEditorChange),e.off(this.beforeInputEvent(),this.handleBeforeInput),e.off("keypress",this.handleEditorChangeSpecial),e.off("keydown",this.handleBeforeInputSpecial),e.off("NewBlock",this.handleEditorChange),Object.keys(this.boundHandlers).forEach(t=>{e.off(t,this.boundHandlers[t])}),this.boundHandlers={},e.remove(),this.editor=void 0)}render(){return this.inline?this.renderInline():this.renderIframe()}changeEvents(){var t,i,a;return((a=(i=(t=w(this.view))==null?void 0:t.Env)==null?void 0:i.browser)==null?void 0:a.isIE())?"change keyup compositionend setcontent CommentChange":"change input compositionend setcontent CommentChange"}beforeInputEvent(){return A()?"beforeinput SelectionChange":"SelectionChange"}renderInline(){const{tagName:e="div"}=this.props;return y.createElement(e,{ref:this.elementRef,id:this.id,tabIndex:this.props.tabIndex})}renderIframe(){return y.createElement("textarea",{ref:this.elementRef,style:{visibility:"hidden"},name:this.props.textareaName,id:this.id,tabIndex:this.props.tabIndex})}getScriptSources(){var i,a;const e=(i=this.props.scriptLoading)==null?void 0:i.async,t=(a=this.props.scriptLoading)==null?void 0:a.defer;return this.props.tinymceScriptSrc!==void 0?typeof this.props.tinymceScriptSrc=="string"?[{src:this.props.tinymceScriptSrc,async:e,defer:t}]:this.props.tinymceScriptSrc?.map(r=>typeof r=="string"?{src:r,async:e,defer:t}:r):[{src:"/tinymce/tinymce.min.js",async:e,defer:t}]}getInitialValue(){return typeof this.props.initialValue=="string"?this.props.initialValue:typeof this.props.value=="string"?this.props.value:""}bindHandlers(e){if(this.editor!==void 0){P(this.editor,e,this.props,this.boundHandlers,r=>this.props[r]);const t=r=>r.onEditorChange!==void 0||r.value!==void 0,i=t(e),a=t(this.props);!i&&a?(this.editor.on(this.changeEvents(),this.handleEditorChange),this.editor.on(this.beforeInputEvent(),this.handleBeforeInput),this.editor.on("keydown",this.handleBeforeInputSpecial),this.editor.on("keyup",this.handleEditorChangeSpecial),this.editor.on("NewBlock",this.handleEditorChange)):i&&!a&&(this.editor.off(this.changeEvents(),this.handleEditorChange),this.editor.off(this.beforeInputEvent(),this.handleBeforeInput),this.editor.off("keydown",this.handleBeforeInputSpecial),this.editor.off("keyup",this.handleEditorChangeSpecial),this.editor.off("NewBlock",this.handleEditorChange))}}}p(S,"propTypes",N),p(S,"defaultProps",{cloudChannel:"7"});const ie=({value:o,onEditorChange:s,apiKey:e,placeholders:t})=>{const i=t&&t.length>0,[a,r]=y.useState(()=>typeof window<"u"&&document.documentElement.classList.contains("dark"));y.useEffect(()=>{const n=new MutationObserver(()=>{r(document.documentElement.classList.contains("dark"))});return n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>n.disconnect()},[]);const c=y.useMemo(()=>({height:600,menubar:!0,skin:a?"oxide-dark":"oxide",skin_url:a?"/tinymce/skins/ui/oxide-dark":"/tinymce/skins/ui/oxide",content_css:a?"dark":"default",content_style:`
|
|
body {
|
|
font-family:Helvetica,Arial,sans-serif;
|
|
font-size:14px;
|
|
${a?`
|
|
background-color: #1f2937;
|
|
color: #e5e7eb;
|
|
`:`
|
|
background-color: #ffffff;
|
|
color: #1f2937;
|
|
`}
|
|
}
|
|
${i?`
|
|
.placeholder {
|
|
${a?`
|
|
background-color: #1e3a5f;
|
|
border: 1px dashed #60a5fa;
|
|
color: #93c5fd;
|
|
`:`
|
|
background-color: #e0f2fe;
|
|
border: 1px dashed #38bdf8;
|
|
`}
|
|
padding: 2px 4px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
display: inline-block;
|
|
margin: 0 2px;
|
|
}
|
|
`:""}
|
|
`,plugins:["autolink","link","lists","code","table","image","preview","searchreplace","wordcount",...i?["noneditable"]:[]].join(" "),toolbar:["undo redo | bold italic underline |","alignleft aligncenter alignright alignjustify |","bullist numlist outdent indent | link image table | code preview",i?"| placeholders":""].join(" "),noneditable_class:"mceNonEditable",setup:n=>{i&&(n.ui.registry.addMenuButton("placeholders",{text:"Placeholders",fetch:l=>{const d=t?.map(f=>({type:"menuitem",text:f.label,onAction:()=>{const m=`<span class="mceNonEditable placeholder" data-key="${f.key}">{{${f.key}}}</span>​`;n.insertContent(m)}}));l(d)}}),n.on("click",l=>{const d=l.target;d.classList.contains("placeholder")&&n.selection.select(d)}),n.on("keydown",l=>{if(l.key==="Backspace"||l.key==="Delete"){const d=n.selection.getNode();d&&d.classList.contains("placeholder")&&(l.preventDefault(),d.remove())}}))}}),[t,i,a]);return R.jsx(S,{tinymceScriptSrc:"/tinymce/tinymce.min.js",apiKey:e,value:o,onEditorChange:s,init:c},a?"dark":"light")},Q=async()=>{const{data:o}=await b.get("/record-templates/global",{headers:k()});return o},W=async(o,s)=>{const{data:e}=await b.get(`/record-templates/${o}`,{headers:k(),...s});return e},G=async o=>{const{data:s}=await b.post("/record-templates/global/delegation",o,{headers:k()});return s},J=async(o,s)=>{const{data:e}=await b.patch(`/record-templates/global/${o}`,s,{headers:k()});return e},X=async o=>{const{data:s}=await b.delete(`/record-templates/${o}`,{headers:k()});return s},Y=async o=>{const{data:s}=await b.post("/record-templates/adopt-to-unit",o,{headers:k()});return s},ne=o=>{const{data:s,isLoading:e,isError:t,refetch:i}=T({queryKey:["templates"],queryFn:async()=>await Q()}),{data:a,isLoading:r,isError:c,refetch:n}=T({queryKey:["template",o],queryFn:async()=>await W(o,{take:300})}),{mutate:l,isPending:d,isError:f}=E({mutationFn:async g=>await G(g)}),{mutate:m,isPending:h,isError:u}=E({mutationFn:async({id:g,template:V})=>await J(g,V)}),{mutate:v,isPending:D,isError:B}=E({mutationFn:async g=>await X(g)}),{mutate:H,isPending:_,isError:M}=E({mutationFn:async g=>await Y(g)});return{templates:s,isLoading:e,isError:t,refetch:i,template:a,isLoadingTemplate:r,isErrorTemplate:c,refetchTemplate:n,createTemplate:l,isCreatingTemplate:d,isErrorCreateTemplate:f,updateTemplate:m,isUpdatingTemplate:h,isErrorUpdateTemplate:u,deleteTemplate:v,isDeletingTemplate:D,isErrorDeleteTemplate:B,adoptTemplate:H,isAdoptingTemplate:_,isErrorAdoptingTemplate:M}};export{ie as T,ne as u};
|