Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bandicoot

Package Overview
Dependencies
Maintainers
5
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bandicoot - npm Package Compare versions

Comparing version 2.9.1 to 2.10.0

2

dist/bandicoot.esm.js

@@ -1,2 +0,2 @@

import React,{useRef,useEffect,forwardRef,useContext,useState}from"react";function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _objectSpread(a){for(var b=1;b<arguments.length;b++){var c=null==arguments[b]?{}:arguments[b],d=Object.keys(c);"function"==typeof Object.getOwnPropertySymbols&&(d=d.concat(Object.getOwnPropertySymbols(c).filter(function(a){return Object.getOwnPropertyDescriptor(c,a).enumerable}))),d.forEach(function(b){_defineProperty(a,b,c[b])})}return a}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function RichTextContainer(a){var b=useRef(Object.assign({},defaultContextValue)),c=b.current,d=useRef([]),e=useRef([]),f=useRef([]),g=useRef([]);return useEffect(()=>{var a=c.getContentEditableElement();a&&a.innerHTML&&c.fireNewHTML()},[c]),c.addSelectionChangedListener=a=>{d.current.push(a)},c.removeSelectionChangedListener=a=>{d.current=d.current.filter(b=>b!==a)},c.fireSelectionChanged=()=>{d.current.forEach(a=>a())},c.addBlurListener=a=>{e.current.push(a)},c.removeBlurListener=a=>{e.current=e.current.filter(b=>b!==a)},c.fireBlur=()=>{e.current.forEach(a=>a())},c.addNewHTMLListener=a=>{f.current.push(a)},c.removeNewHTMLListener=a=>{f.current=f.current.filter(b=>b!==a)},c.fireNewHTML=()=>{f.current.forEach(a=>a())},c.numSerializers=()=>g.current.length,c.addSerializer=a=>{g.current.push(a)},c.removeSerializer=a=>{g.current=g.current.filter(b=>b!==a)},c.serialize=a=>(g.current.forEach(b=>b(a)),a.innerHTML),React.createElement(RichTextContext.Provider,{value:c},a.children)}var noop=()=>{},defaultContextValue={addSelectionChangedListener:noop,removeSelectionChangedListener:noop,fireSelectionChanged:noop,selectRangeFromBeforeBlur:noop,getRangeBeforeBlur:noop,addBlurListener:noop,removeBlurListener:noop,fireBlur:noop,addNewHTMLListener:noop,removeNewHTMLListener:noop,fireNewHTML:noop,isFocused:noop,getContentEditableElement:noop,numSerializers:()=>0,addSerializer:noop,removeSerializer:noop,serialize:noop,sanitizeHTML:noop},RichTextContext=React.createContext(defaultContextValue),noop$1=()=>{},noopWithReturn=a=>a,globalBandicootId=0,RichTextEditor=forwardRef((a,b)=>{function c(b){b.preventDefault(),b.stopPropagation();var c=k.sanitizeHTML((window.clipboardData||b.clipboardData).getData("text/html"),"pasteHTML"),d=a.pasteFn(c);!1!==d&&document.execCommand("insertHTML",null,d)}function d(){var a=document.createRange();a.selectNodeContents(l.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("removeFormat"),document.execCommand("delete")}function e(){if(o()){var a=window.getSelection();0<a.rangeCount&&(m.current=window.getSelection().getRangeAt(0)),k.fireSelectionChanged()}}function f(){var b=i();b!==t&&(u(b),a.save(b))}function g(){var a=l.current.innerHTML;if(0<k.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=k.serialize(b.body)}return a}function h(a){d(),l.current.innerHTML=k.sanitizeHTML(a,"setHTML"),j(),k.fireNewHTML()}function i(){return k.sanitizeHTML(g(),"getHTML")}function j(){l.current.focus(),p(!0)}var k=useContext(RichTextContext);k.sanitizeHTML=a.sanitizeHTML;var l=useRef(null),m=useRef(null),n=useSynchronousFocusState(),o=n.isFocused,p=n.setFocused,q=useRef(globalBandicootId++),r=useState(()=>k.sanitizeHTML(a.initialHTML,"initialSetLastSavedHTML")),s=_slicedToArray(r,2),t=s[0],u=s[1],v=useState(!1),w=_slicedToArray(v,2),x=w[0],y=w[1];b&&(b.current={setHTML:h,resetEditor:function(){h("")},getHTML:i,focus:j}),useEffect(()=>(l.current.addEventListener("paste",c),()=>l.current.removeEventListener("paste",c)),[a.pasteFn]),useEffect(()=>(document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e))),useEffect(()=>{if(a.save&&a.unchangedInterval&&l.current&&o()){var b,c=new MutationObserver(()=>{clearTimeout(b),b=setTimeout(f,a.unchangedInterval)});return c.observe(l.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{c.disconnect(),clearTimeout(b)}}},[a.unchangedInterval,a.save,l.current,o()]),useEffect(()=>{if(!1===o()){var a=setTimeout(()=>{k.fireBlur(),f()},100);return()=>{clearTimeout(a)}}},[o()]),useEffect(()=>{k.selectRangeFromBeforeBlur=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{usePreviousRange:!1};if(l.current&&document.activeElement!==l.current&&!l.current.contains(document.activeElement)){if(a.usePreviousRange&&m.current){var b=window.getSelection();b.removeAllRanges(),b.addRange(m.current)}else l.current.focus();p(!0),setTimeout(e)}},k.getRangeFromBeforeBlur=()=>m.current,k.isFocused=o,k.getContentEditableElement=()=>l.current}),useEffect(()=>{!x&&a.initialHTML&&(y(!0),h(a.initialHTML))},[x,h,k]),useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${q.current}:empty:before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,q.current]);var z=a.style||{};return React.createElement("div",{contentEditable:!0,onBlur:()=>p(!1),onFocus:function(){p(!0);var a=window.getSelection();0<a.rangeCount&&(m.current=a.getRangeAt(0))},ref:l,className:a.className+" bandicoot-id-"+q.current,style:_objectSpread({wordBreak:"break-word",wordWrap:"break-word",overflowWrap:"break-word"},z),"data-placeholder":a.placeholder})});function useSynchronousFocusState(){var a=useRef(null),b=useState(!1),c=_slicedToArray(b,2),d=c[0],e=c[1];return{isFocused:function(){return a.current},setFocused:function(b){a.current=b,e(!d)}}}RichTextEditor.defaultProps={className:"",initialHTML:"",save:noop$1,placeholder:"",placeholderColor:"#CFCFCF",pasteFn:noopWithReturn,sanitizeHTML:noopWithReturn};function useDocumentExecCommand(a){var b=useContext(RichTextContext);return{performCommand(){b.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(c){b.selectRangeFromBeforeBlur();document.execCommand(a,null,c)}}}function useFormatBlock(){var a=useDocumentExecCommand("formatBlock"),b=a.performCommandWithValue;return{formatBlock(a){a===document.queryCommandValue("formatBlock")?b("div"):b(a)}}}var defaultActiveInfo={isActive:!1,value:!1};function useDocumentQueryCommandState(a,b){function c(){var c=document.queryCommandValue(a),d=b?b===c:document.queryCommandState(a);(d!==g.isActive||c!==g.value)&&h({isActive:d,value:c})}function d(){h(defaultActiveInfo)}var e=useState(defaultActiveInfo),f=_slicedToArray(e,2),g=f[0],h=f[1],i=useContext(RichTextContext);return useEffect(()=>(i.addSelectionChangedListener(c),()=>i.removeSelectionChangedListener(c)),[g,h]),useEffect(()=>(i.addBlurListener(d),()=>i.removeBlurListener(d)),[g,h]),{isActive:g.isActive,activeValue:g.value}}function useFontSize(a){var b=a.defaultFontSize,c=void 0===b?"14px":b,d=a.fontSizes;if(7<d.length)throw Error(`Browsers only support up to 7 font sizes with document.execCommand('fontSize', null, size)`);var e=useState(c),f=_slicedToArray(e,2),g=f[0],h=f[1],i=useState(null),j=_slicedToArray(i,2),k=j[0],l=j[1],m=useDocumentExecCommand("fontSize"),n=m.performCommandWithValue,o=useContext(RichTextContext),p=function(){return useEffect(()=>{function a(){var a=window.getSelection();if((!k||a.anchorNode!==k.anchorNode||a.anchorOffset!==k.anchorOffset||a.focusNode!==k.focusNode||a.focusOffset!==k.focusOffset)&&(l({anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),0<a.rangeCount)){var b=a.getRangeAt(0).startContainer;1!==b.nodeType&&(b=b.parentElement);var c=window.getComputedStyle(b).fontSize,d=c;d!==g&&h(d)}}return o.addSelectionChangedListener(a),()=>o.removeSelectionChangedListener(a)},[g,h,k]),g}();return function(){useEffect(()=>{var a=d.reduce((a,b,c)=>`${a} font[size="${c+1}"] {font-size: ${b}}`,""),b=document.createElement("style");return b.textContent=a,document.head.appendChild(b),()=>document.head.removeChild(b)},[d]),useEffect(()=>{function a(a){for(var b=a.querySelectorAll("font"),c=0;c<b.length;c++){var e=b[c],f=+e.getAttribute("size");if(f>d.length)throw Error(`Cannot find fontSize for integer size '${f}'`);var g=d[f-1];e.removeAttribute("size"),e.style.fontSize=g,e.dataset.integerSize=f}}return o.addSerializer(a),()=>o.removeSerializer(a)},[d]),useEffect(()=>{function a(){for(var a=o.getContentEditableElement().querySelectorAll("font"),b=function(b){var c=a[b],e=c.style.fontSize,f=d.findIndex(a=>a===e)+1;0<f&&(c.style.fontSize="",c.setAttribute("size",f))},c=0;c<a.length;c++)b(c)}return o.addNewHTMLListener(a),()=>o.removeNewHTMLListener(a)},[d])}(),{currentlySelectedFontSize:p,setSize(a){var b=d.findIndex(b=>b===a)+1;if(0>=b)throw Error(`Cannot set font size since '${a}' was not passed in the fontSizes array`);h(a),n(b)}}}var noop$2=()=>{},defaultOpts={processImgElement:noop$2,fileBlobToUrl:defaultFileBlobToUrl};function useImage(){function a(a){a.style.cursor="pointer",d(a)}var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOpts,c=b.processImgElement,d=void 0===c?noop$2:c,e=b.fileBlobToUrl,f=void 0===e?defaultFileBlobToUrl:e,g=useDocumentExecCommand("insertImage"),h=g.performCommandWithValue,i=useContext(RichTextContext),j=useRef(null);return function(){useEffect(()=>{function b(){var b=i.getContentEditableElement().querySelectorAll("img:not([data-text-as-image])");b.forEach(a)}return i.addNewHTMLListener(b),()=>i.removeNewHTMLListener(b)},[d])}(),function(){useEffect(()=>{j.current=document.createElement("input");var b=j.current;b.type="file",b.accept=".jpg, .png, image/*",b.multiple=!1,b.addEventListener("change",()=>{b.files&&0<b.files.length&&f(b.files[0],b=>{h(b);var c=document.querySelector(`img[src="${b}"]`);a(c)})})},[f,d])}(),{chooseFile(){j.current.click()},removeImage(a){var b=document.createRange();b.selectNode(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b),document.execCommand("delete")}}}function defaultFileBlobToUrl(a,b){b(URL.createObjectURL(a))}var tempId=0,noop$3=()=>{},defaultOptions={processAnchorElement:noop$3};function useLink(){function a(a,b){e.selectRangeFromBeforeBlur({usePreviousRange:!0});var c=`rte-link-temp-id-${tempId++}`;i(`<a href="${a}" id="${c}">${b}</a>`);var f=document.getElementById(c);f.removeAttribute("id"),d(f)}var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOptions,c=b.processAnchorElement,d=void 0===c?noop$3:c,e=useContext(RichTextContext),f=useDocumentExecCommand("unlink"),g=f.performCommand,h=useDocumentExecCommand("insertHTML"),i=h.performCommandWithValue;return function(){useEffect(()=>{function a(){var a=e.getContentEditableElement().querySelectorAll("a");a.forEach(d)}return e.addNewHTMLListener(a),()=>e.removeNewHTMLListener(a)},[d])}(),{getTextFromBeforeBlur:function(){var a=e.getRangeFromBeforeBlur();return a?a.toString():null},selectEntireLink:function(a){var b=document.createRange();b.selectNodeContents(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)},unlink:function(){g(),(window.navigator.userAgent.includes("Edge/14")||window.navigator.userAgent.includes("Edge/15")||window.navigator.userAgent.includes("Edge/16")||window.navigator.userAgent.includes("Edge/17"))&&document.execCommand("removeFormat")},insertLink:a}}var tempId$1=0,noop$4=()=>{},defaultOptions$1={processContentEditableFalseElement:noop$4};function useContentEditableFalse(){function a(a){if(a.removeAttribute("id"),a.contentEditable=!1,a.addEventListener("click",()=>selectRangeAfterNode(a)),!a.previousSibling&&a.parentElement===g.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===g.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}selectRangeAfterNode(a),d(a)}var b=0<arguments.length&&arguments[0]!==void 0?arguments[0]:defaultOptions$1,c=b.processContentEditableFalseElement,d=void 0===c?noop$4:c,e=useDocumentExecCommand("insertHTML"),f=e.performCommandWithValue,g=useContext(RichTextContext);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+tempId$1++,d=`<span id="${c}">${g.sanitizeHTML(b,"insertContentEditableFalseHTML")}</span>`;f(d);var e=document.getElementById(c);a(e)}}}function selectRangeAfterNode(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}var noop$5=()=>{},defaultOptions$2={processSerializedElement:noop$5,fontFamily:null};function useTextAsImage(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOptions$2,b=a.processSerializedElement,c=void 0===b?noop$5:b,d=a.fontFamily,e=void 0===d?null:d,f=useDocumentExecCommand("insertImage"),g=f.performCommandWithValue,h=useContext(RichTextContext);return function(){useEffect(()=>{function a(){for(var a=h.getContentEditableElement().querySelectorAll("span[data-text-as-image]"),b=0;b<a.length;b++){var c=a[b],d=textToUrl(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement,e),f=document.createElement("img");f.src=d,processImgElement(f,c.dataset.textAsImage),c.parentNode.replaceChild(f,c)}}return h.addNewHTMLListener(a),()=>h.removeNewHTMLListener(a)},[])}(),function(){useEffect(()=>{function a(a){for(var b=a.querySelectorAll("img[data-text-as-image]"),d=0;d<b.length;d++){var e=b[d],f=document.createElement("span");f.dataset.textAsImage=e.dataset.textAsImage,c(f,f.dataset.textAsImage),e.parentNode.replaceChild(f,e)}}return h.addSerializer(a),()=>h.removeSerializer(a)},[])}(),{insertTextAsImage(a){h.selectRangeFromBeforeBlur({usePreviousRange:!0});var b=textToUrl(a,getSelectedElement(),e);g(b);var c=document.querySelector(`img[src="${b}"]`);processImgElement(c,a)}}}function textToUrl(a,b,d){var e=window.getComputedStyle(b),f=+e.fontSize.replace("px",""),g=+e.lineHeight.replace("px",""),h=d||e.fontFamily,i=`bold ${f}px ${h}`,j=document.createElement("div");j.style.font=i,j.style.position="absolute",j.style.visibility="hidden",j.style.whiteSpace="nowrap",j.textContent=a,document.body.appendChild(j);var k=document.createElement("canvas");k.width=j.clientWidth+1,k.height=g;var l=k.getContext("2d");return l.font=i,l.fillStyle="#00bf4b",l.textBaseline="bottom",l.fillText(a,0,g-3),document.body.removeChild(j),l.canvas.toDataURL()}function processImgElement(a,b){a.style.verticalAlign="bottom",a.dataset.textAsImage=b,a.addEventListener("click",b=>{var c=a.getBoundingClientRect(),d=c.left+c.width/2,e=document.createRange();b.x<d?e.setStartBefore(a):e.setStartAfter(a);var f=window.getSelection();f.removeAllRanges(),f.addRange(e)})}function getSelectedElement(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}function useElementDeletionDetection(a,b){var c=useContext(RichTextContext);useEffect(()=>{if(a){function d(){a.isConnected||a._bandicoot_delete_callback_called||(a._bandicoot_delete_callback_called=!0,b(a))}return c.addSelectionChangedListener(d),()=>c.removeSelectionChangedListener(d)}},[a,b])}export{RichTextEditor,RichTextContainer,RichTextContext,useDocumentExecCommand,useFormatBlock,useDocumentQueryCommandState,useFontSize,useImage,useLink,useContentEditableFalse,useTextAsImage,useElementDeletionDetection};
import React,{useRef,useEffect,forwardRef,useContext,useState}from"react";function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _objectSpread(a){for(var b=1;b<arguments.length;b++){var c=null==arguments[b]?{}:arguments[b],d=Object.keys(c);"function"==typeof Object.getOwnPropertySymbols&&(d=d.concat(Object.getOwnPropertySymbols(c).filter(function(a){return Object.getOwnPropertyDescriptor(c,a).enumerable}))),d.forEach(function(b){_defineProperty(a,b,c[b])})}return a}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function RichTextContainer(a){var b=useRef(Object.assign({},defaultContextValue)),c=b.current,d=useRef([]),e=useRef([]),f=useRef([]),g=useRef([]);return useEffect(()=>{var a=c.getContentEditableElement();a&&a.innerHTML&&c.fireNewHTML()},[c]),c.addSelectionChangedListener=a=>{d.current.push(a)},c.removeSelectionChangedListener=a=>{d.current=d.current.filter(b=>b!==a)},c.fireSelectionChanged=()=>{d.current.forEach(a=>a())},c.addBlurListener=a=>{e.current.push(a)},c.removeBlurListener=a=>{e.current=e.current.filter(b=>b!==a)},c.fireBlur=()=>{e.current.forEach(a=>a())},c.addNewHTMLListener=a=>{f.current.push(a)},c.removeNewHTMLListener=a=>{f.current=f.current.filter(b=>b!==a)},c.fireNewHTML=()=>{f.current.forEach(a=>a())},c.numSerializers=()=>g.current.length,c.addSerializer=a=>{g.current.push(a)},c.removeSerializer=a=>{g.current=g.current.filter(b=>b!==a)},c.serialize=a=>(g.current.forEach(b=>b(a)),a.innerHTML),React.createElement(RichTextContext.Provider,{value:c},a.children)}var noop=()=>{},defaultContextValue={addSelectionChangedListener:noop,removeSelectionChangedListener:noop,fireSelectionChanged:noop,selectRangeFromBeforeBlur:noop,getRangeBeforeBlur:noop,addBlurListener:noop,removeBlurListener:noop,fireBlur:noop,addNewHTMLListener:noop,removeNewHTMLListener:noop,fireNewHTML:noop,isFocused:noop,getContentEditableElement:noop,numSerializers:()=>0,addSerializer:noop,removeSerializer:noop,serialize:noop,sanitizeHTML:noop},RichTextContext=React.createContext(defaultContextValue),noop$1=()=>{},noopWithReturn=a=>a,globalBandicootId=0,RichTextEditor=forwardRef((a,b)=>{function c(b){b.preventDefault(),b.stopPropagation();var c=k.sanitizeHTML((window.clipboardData||b.clipboardData).getData("text/html"),"pasteHTML"),d=a.pasteFn(c);!1!==d&&document.execCommand("insertHTML",null,d)}function d(){var a=document.createRange();a.selectNodeContents(l.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("removeFormat"),document.execCommand("delete")}function e(){if(o()){var a=window.getSelection();0<a.rangeCount&&(m.current=window.getSelection().getRangeAt(0)),k.fireSelectionChanged()}}function f(){var b=i();b!==t&&(u(b),a.save(b))}function g(){var a=l.current.innerHTML;if(0<k.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=k.serialize(b.body)}return a}function h(a){d(),l.current.innerHTML=k.sanitizeHTML(a,"setHTML"),j(),k.fireNewHTML()}function i(){return k.sanitizeHTML(g(),"getHTML")}function j(){l.current.focus(),p(!0)}var k=useContext(RichTextContext);k.sanitizeHTML=a.sanitizeHTML;var l=useRef(null),m=useRef(null),n=useSynchronousFocusState(),o=n.isFocused,p=n.setFocused,q=useRef(globalBandicootId++),r=useState(()=>k.sanitizeHTML(a.initialHTML,"initialSetLastSavedHTML")),s=_slicedToArray(r,2),t=s[0],u=s[1],v=useState(!1),w=_slicedToArray(v,2),x=w[0],y=w[1];b&&(b.current={setHTML:h,resetEditor:function(){h("")},getHTML:i,focus:j}),useEffect(()=>(l.current.addEventListener("paste",c),()=>l.current.removeEventListener("paste",c)),[a.pasteFn]),useEffect(()=>(document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e))),useEffect(()=>{if(a.save&&a.unchangedInterval&&l.current&&o()){var b,c=new MutationObserver(()=>{clearTimeout(b),b=setTimeout(f,a.unchangedInterval)});return c.observe(l.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{c.disconnect(),clearTimeout(b)}}},[a.unchangedInterval,a.save,l.current,o()]),useEffect(()=>{if(!1===o()){var a=setTimeout(()=>{k.fireBlur(),f()},100);return()=>{clearTimeout(a)}}},[o()]),useEffect(()=>{k.selectRangeFromBeforeBlur=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{usePreviousRange:!1};if(l.current&&document.activeElement!==l.current&&!l.current.contains(document.activeElement)){if(a.usePreviousRange&&m.current){var b=window.getSelection();b.removeAllRanges(),b.addRange(m.current)}else l.current.focus();p(!0),setTimeout(e)}},k.getRangeFromBeforeBlur=()=>m.current,k.isFocused=o,k.getContentEditableElement=()=>l.current}),useEffect(()=>{!x&&a.initialHTML&&(y(!0),h(a.initialHTML))},[x,h,k]),useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${q.current}:empty:before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,q.current]);var z=a.style||{};return React.createElement("div",{contentEditable:!0,onBlur:()=>p(!1),onFocus:function(){p(!0);var a=window.getSelection();0<a.rangeCount&&(m.current=a.getRangeAt(0))},ref:l,className:a.className+" bandicoot-id-"+q.current,style:_objectSpread({wordBreak:"break-word",wordWrap:"break-word",overflowWrap:"break-word"},z),"data-placeholder":a.placeholder})});function useSynchronousFocusState(){var a=useRef(null),b=useState(!1),c=_slicedToArray(b,2),d=c[0],e=c[1];return{isFocused:function(){return a.current},setFocused:function(b){a.current=b,e(!d)}}}RichTextEditor.defaultProps={className:"",initialHTML:"",save:noop$1,placeholder:"",placeholderColor:"#CFCFCF",pasteFn:noopWithReturn,sanitizeHTML:noopWithReturn};function useDocumentExecCommand(a){var b=useContext(RichTextContext);return{performCommand(){b.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(c){b.selectRangeFromBeforeBlur();document.execCommand(a,null,c)}}}function useFormatBlock(){var a=useDocumentExecCommand("formatBlock"),b=a.performCommandWithValue;return{formatBlock(a){a===document.queryCommandValue("formatBlock")?b("div"):b(a)}}}var defaultActiveInfo={isActive:!1,value:!1};function useDocumentQueryCommandState(a,b){function c(){var c=document.queryCommandValue(a),d=b?b===c:document.queryCommandState(a);(d!==g.isActive||c!==g.value)&&h({isActive:d,value:c})}function d(){h(defaultActiveInfo)}var e=useState(defaultActiveInfo),f=_slicedToArray(e,2),g=f[0],h=f[1],i=useContext(RichTextContext);return useEffect(()=>(i.addSelectionChangedListener(c),()=>i.removeSelectionChangedListener(c)),[g,h]),useEffect(()=>(i.addBlurListener(d),()=>i.removeBlurListener(d)),[g,h]),{isActive:g.isActive,activeValue:g.value}}function useFontSize(a){var b=a.defaultFontSize,c=void 0===b?"14px":b,d=a.fontSizes;if(7<d.length)throw Error(`Browsers only support up to 7 font sizes with document.execCommand('fontSize', null, size)`);var e=useState(c),f=_slicedToArray(e,2),g=f[0],h=f[1],i=useState(null),j=_slicedToArray(i,2),k=j[0],l=j[1],m=useDocumentExecCommand("fontSize"),n=m.performCommandWithValue,o=useContext(RichTextContext),p=function(){return useEffect(()=>{function a(){var a=window.getSelection();if((!k||a.anchorNode!==k.anchorNode||a.anchorOffset!==k.anchorOffset||a.focusNode!==k.focusNode||a.focusOffset!==k.focusOffset)&&(l({anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),0<a.rangeCount)){var b=a.getRangeAt(0).startContainer;1!==b.nodeType&&(b=b.parentElement);var c=window.getComputedStyle(b).fontSize,d=c;d!==g&&h(d)}}return o.addSelectionChangedListener(a),()=>o.removeSelectionChangedListener(a)},[g,h,k]),g}();return function(){useEffect(()=>{var a=d.reduce((a,b,c)=>`${a} font[size="${c+1}"] {font-size: ${b}}`,""),b=document.createElement("style");return b.textContent=a,document.head.appendChild(b),()=>document.head.removeChild(b)},[d]),useEffect(()=>{function a(a){for(var b=a.querySelectorAll("font"),c=0;c<b.length;c++){var e=b[c],f=+e.getAttribute("size");if(f>d.length)throw Error(`Cannot find fontSize for integer size '${f}'`);var g=d[f-1];e.removeAttribute("size"),e.style.fontSize=g,e.dataset.integerSize=f}}return o.addSerializer(a),()=>o.removeSerializer(a)},[d]),useEffect(()=>{function a(){for(var a=o.getContentEditableElement().querySelectorAll("font"),b=function(b){var c=a[b],e=c.style.fontSize,f=d.findIndex(a=>a===e)+1;0<f&&(c.style.fontSize="",c.setAttribute("size",f))},c=0;c<a.length;c++)b(c)}return o.addNewHTMLListener(a),()=>o.removeNewHTMLListener(a)},[d])}(),{currentlySelectedFontSize:p,setSize(a){var b=d.findIndex(b=>b===a)+1;if(0>=b)throw Error(`Cannot set font size since '${a}' was not passed in the fontSizes array`);h(a),n(b)}}}var noop$2=()=>{},defaultAcceptImgTypes=".jpg, .png, image/*",defaultOpts={processImgElement:noop$2,fileBlobToUrl:defaultFileBlobToUrl,acceptImgTypes:defaultAcceptImgTypes};function useImage(){function a(a){a.style.cursor="pointer",a.style.maxWidth="100%",e(a)}function b(a){a.querySelectorAll("img").forEach(a=>{n.current[a.src]&&(a.src=n.current[a.src])})}var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOpts,d=c.processImgElement,e=void 0===d?noop$2:d,f=c.fileBlobToUrl,g=void 0===f?defaultFileBlobToUrl:f,h=c.acceptImgTypes,i=void 0===h?defaultAcceptImgTypes:h,j=useDocumentExecCommand("insertImage"),k=j.performCommandWithValue,l=useContext(RichTextContext),m=useRef(null),n=React.useRef({});return function(){useEffect(()=>{function b(){var b=l.getContentEditableElement().querySelectorAll("img:not([data-text-as-image])");b.forEach(a)}return l.addNewHTMLListener(b),()=>l.removeNewHTMLListener(b)},[e])}(),function(){useEffect(()=>{m.current=document.createElement("input");var b=m.current;b.type="file",b.accept=i,b.multiple=!1,b.addEventListener("change",()=>{b.files&&0<b.files.length&&g(b.files[0],c=>{k(c);var d=document.querySelector(`img[src="${c}"]`);if(d.src&&d.src.startsWith("blob:")){var e=new FileReader;e.addEventListener("load",()=>{n.current[d.src]=e.result}),e.readAsDataURL(b.files[0])}a(d)})})},[g,e,i])}(),function(){useEffect(()=>(l.addSerializer(b),()=>l.removeSerializer(b)))}(),{chooseFile(){m.current.click()},removeImage(a){var b=document.createRange();b.selectNode(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b),document.execCommand("delete")}}}function defaultFileBlobToUrl(a,b){b(URL.createObjectURL(a))}var tempId=0,noop$3=()=>{},defaultOptions={processAnchorElement:noop$3};function useLink(){function a(a,b){e.selectRangeFromBeforeBlur({usePreviousRange:!0});var c=`rte-link-temp-id-${tempId++}`;i(`<a href="${a}" id="${c}" target="_blank" rel="noopener noreferrer">${b}</a>`);var f=document.getElementById(c);f.removeAttribute("id"),d(f)}var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOptions,c=b.processAnchorElement,d=void 0===c?noop$3:c,e=useContext(RichTextContext),f=useDocumentExecCommand("unlink"),g=f.performCommand,h=useDocumentExecCommand("insertHTML"),i=h.performCommandWithValue;return function(){useEffect(()=>{function a(){var a=e.getContentEditableElement().querySelectorAll("a");a.forEach(d)}return e.addNewHTMLListener(a),()=>e.removeNewHTMLListener(a)},[d])}(),{getTextFromBeforeBlur:function(){var a=e.getRangeFromBeforeBlur();return a?a.toString():null},selectEntireLink:function(a){var b=document.createRange();b.selectNodeContents(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)},unlink:function(){g(),(window.navigator.userAgent.includes("Edge/14")||window.navigator.userAgent.includes("Edge/15")||window.navigator.userAgent.includes("Edge/16")||window.navigator.userAgent.includes("Edge/17"))&&document.execCommand("removeFormat")},insertLink:a}}var tempId$1=0,noop$4=()=>{},defaultOptions$1={processContentEditableFalseElement:noop$4};function useContentEditableFalse(){function a(a){if(a.removeAttribute("id"),a.contentEditable=!1,a.addEventListener("click",()=>selectRangeAfterNode(a)),!a.previousSibling&&a.parentElement===g.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===g.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}selectRangeAfterNode(a),d(a)}var b=0<arguments.length&&arguments[0]!==void 0?arguments[0]:defaultOptions$1,c=b.processContentEditableFalseElement,d=void 0===c?noop$4:c,e=useDocumentExecCommand("insertHTML"),f=e.performCommandWithValue,g=useContext(RichTextContext);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+tempId$1++,d=`<span id="${c}">${g.sanitizeHTML(b,"insertContentEditableFalseHTML")}</span>`;f(d);var e=document.getElementById(c);a(e)}}}function selectRangeAfterNode(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}var noop$5=()=>{},defaultOptions$2={processSerializedElement:noop$5,fontFamily:null};function useTextAsImage(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOptions$2,b=a.processSerializedElement,c=void 0===b?noop$5:b,d=a.fontFamily,e=void 0===d?null:d,f=useDocumentExecCommand("insertImage"),g=f.performCommandWithValue,h=useContext(RichTextContext);return function(){useEffect(()=>{function a(){for(var a=h.getContentEditableElement().querySelectorAll("span[data-text-as-image]"),b=0;b<a.length;b++){var c=a[b],d=textToUrl(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement,e),f=document.createElement("img");f.src=d,processImgElement(f,c.dataset.textAsImage),c.parentNode.replaceChild(f,c)}}return h.addNewHTMLListener(a),()=>h.removeNewHTMLListener(a)},[])}(),function(){useEffect(()=>{function a(a){for(var b=a.querySelectorAll("img[data-text-as-image]"),d=0;d<b.length;d++){var e=b[d],f=document.createElement("span");f.dataset.textAsImage=e.dataset.textAsImage,c(f,f.dataset.textAsImage),e.parentNode.replaceChild(f,e)}}return h.addSerializer(a),()=>h.removeSerializer(a)},[])}(),{insertTextAsImage(a){h.selectRangeFromBeforeBlur({usePreviousRange:!0});var b=textToUrl(a,getSelectedElement(),e);g(b);var c=document.querySelector(`img[src="${b}"]`);processImgElement(c,a)}}}function textToUrl(a,b,d){var e=window.getComputedStyle(b),f=+e.fontSize.replace("px",""),g=+e.lineHeight.replace("px",""),h=d||e.fontFamily,i=`bold ${f}px ${h}`,j=document.createElement("div");j.style.font=i,j.style.position="absolute",j.style.visibility="hidden",j.style.whiteSpace="nowrap",j.textContent=a,document.body.appendChild(j);var k=document.createElement("canvas");k.width=j.clientWidth+1,k.height=g;var l=k.getContext("2d");return l.font=i,l.fillStyle="#00bf4b",l.textBaseline="bottom",l.fillText(a,0,g-3),document.body.removeChild(j),l.canvas.toDataURL()}function processImgElement(a,b){a.style.verticalAlign="bottom",a.dataset.textAsImage=b,a.addEventListener("click",b=>{var c=a.getBoundingClientRect(),d=c.left+c.width/2,e=document.createRange();b.x<d?e.setStartBefore(a):e.setStartAfter(a);var f=window.getSelection();f.removeAllRanges(),f.addRange(e)})}function getSelectedElement(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}function useElementDeletionDetection(a,b){var c=useContext(RichTextContext);useEffect(()=>{if(a){function d(){a.isConnected||a._bandicoot_delete_callback_called||(a._bandicoot_delete_callback_called=!0,b(a))}return c.addSelectionChangedListener(d),()=>c.removeSelectionChangedListener(d)}},[a,b])}export{RichTextEditor,RichTextContainer,RichTextContext,useDocumentExecCommand,useFormatBlock,useDocumentQueryCommandState,useFontSize,useImage,useLink,useContentEditableFalse,useTextAsImage,useElementDeletionDetection};
//# sourceMappingURL=bandicoot.esm.js.map

@@ -1,2 +0,2 @@

(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],b):(a=a||self,b(a.bandicoot={},a.React))})(this,function(a,b){"use strict";function c(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function d(a){for(var b=1;b<arguments.length;b++){var d=null==arguments[b]?{}:arguments[b],e=Object.keys(d);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(d).filter(function(a){return Object.getOwnPropertyDescriptor(d,a).enumerable}))),e.forEach(function(b){c(a,b,d[b])})}return a}function e(a,b){return f(a)||g(a,b)||h()}function f(a){if(Array.isArray(a))return a}function g(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function h(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function i(){var a=b.useRef(null),c=b.useState(!1),d=e(c,2),f=d[0],g=d[1];return{isFocused:function(){return a.current},setFocused:function(b){a.current=b,g(!f)}}}function j(a){var c=b.useContext(s);return{performCommand(){c.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(b){c.selectRangeFromBeforeBlur();document.execCommand(a,null,b)}}}function k(a,b){b(URL.createObjectURL(a))}function l(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}function m(a,b,d){var e=window.getComputedStyle(b),f=+e.fontSize.replace("px",""),g=+e.lineHeight.replace("px",""),h=d||e.fontFamily,i=`bold ${f}px ${h}`,j=document.createElement("div");j.style.font=i,j.style.position="absolute",j.style.visibility="hidden",j.style.whiteSpace="nowrap",j.textContent=a,document.body.appendChild(j);var k=document.createElement("canvas");k.width=j.clientWidth+1,k.height=g;var l=k.getContext("2d");return l.font=i,l.fillStyle="#00bf4b",l.textBaseline="bottom",l.fillText(a,0,g-3),document.body.removeChild(j),l.canvas.toDataURL()}function n(a,b){a.style.verticalAlign="bottom",a.dataset.textAsImage=b,a.addEventListener("click",b=>{var c=a.getBoundingClientRect(),d=c.left+c.width/2,e=document.createRange();b.x<d?e.setStartBefore(a):e.setStartAfter(a);var f=window.getSelection();f.removeAllRanges(),f.addRange(e)})}function o(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}var p="default"in b?b["default"]:b,q=()=>{},r={addSelectionChangedListener:q,removeSelectionChangedListener:q,fireSelectionChanged:q,selectRangeFromBeforeBlur:q,getRangeBeforeBlur:q,addBlurListener:q,removeBlurListener:q,fireBlur:q,addNewHTMLListener:q,removeNewHTMLListener:q,fireNewHTML:q,isFocused:q,getContentEditableElement:q,numSerializers:()=>0,addSerializer:q,removeSerializer:q,serialize:q,sanitizeHTML:q},s=p.createContext(r),t=a=>a,u=0,v=b.forwardRef((a,c)=>{function f(b){b.preventDefault(),b.stopPropagation();var c=o.sanitizeHTML((window.clipboardData||b.clipboardData).getData("text/html"),"pasteHTML"),d=a.pasteFn(c);!1!==d&&document.execCommand("insertHTML",null,d)}function g(){var a=document.createRange();a.selectNodeContents(q.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("removeFormat"),document.execCommand("delete")}function h(){if(v()){var a=window.getSelection();0<a.rangeCount&&(r.current=window.getSelection().getRangeAt(0)),o.fireSelectionChanged()}}function j(){var b=m();b!==A&&(B(b),a.save(b))}function k(){var a=q.current.innerHTML;if(0<o.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=o.serialize(b.body)}return a}function l(a){g(),q.current.innerHTML=o.sanitizeHTML(a,"setHTML"),n(),o.fireNewHTML()}function m(){return o.sanitizeHTML(k(),"getHTML")}function n(){q.current.focus(),w(!0)}var o=b.useContext(s);o.sanitizeHTML=a.sanitizeHTML;var q=b.useRef(null),r=b.useRef(null),t=i(),v=t.isFocused,w=t.setFocused,x=b.useRef(u++),y=b.useState(()=>o.sanitizeHTML(a.initialHTML,"initialSetLastSavedHTML")),z=e(y,2),A=z[0],B=z[1],C=b.useState(!1),D=e(C,2),E=D[0],F=D[1];c&&(c.current={setHTML:l,resetEditor:function(){l("")},getHTML:m,focus:n}),b.useEffect(()=>(q.current.addEventListener("paste",f),()=>q.current.removeEventListener("paste",f)),[a.pasteFn]),b.useEffect(()=>(document.addEventListener("selectionchange",h),()=>document.removeEventListener("selectionchange",h))),b.useEffect(()=>{if(a.save&&a.unchangedInterval&&q.current&&v()){var b,c=new MutationObserver(()=>{clearTimeout(b),b=setTimeout(j,a.unchangedInterval)});return c.observe(q.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{c.disconnect(),clearTimeout(b)}}},[a.unchangedInterval,a.save,q.current,v()]),b.useEffect(()=>{if(!1===v()){var a=setTimeout(()=>{o.fireBlur(),j()},100);return()=>{clearTimeout(a)}}},[v()]),b.useEffect(()=>{o.selectRangeFromBeforeBlur=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{usePreviousRange:!1};if(q.current&&document.activeElement!==q.current&&!q.current.contains(document.activeElement)){if(a.usePreviousRange&&r.current){var b=window.getSelection();b.removeAllRanges(),b.addRange(r.current)}else q.current.focus();w(!0),setTimeout(h)}},o.getRangeFromBeforeBlur=()=>r.current,o.isFocused=v,o.getContentEditableElement=()=>q.current}),b.useEffect(()=>{!E&&a.initialHTML&&(F(!0),l(a.initialHTML))},[E,l,o]),b.useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${x.current}:empty:before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,x.current]);var G=a.style||{};return p.createElement("div",{contentEditable:!0,onBlur:()=>w(!1),onFocus:function(){w(!0);var a=window.getSelection();0<a.rangeCount&&(r.current=a.getRangeAt(0))},ref:q,className:a.className+" bandicoot-id-"+x.current,style:d({wordBreak:"break-word",wordWrap:"break-word",overflowWrap:"break-word"},G),"data-placeholder":a.placeholder})});v.defaultProps={className:"",initialHTML:"",save:()=>{},placeholder:"",placeholderColor:"#CFCFCF",pasteFn:t,sanitizeHTML:t};var w={isActive:!1,value:!1},x=()=>{},y={processImgElement:x,fileBlobToUrl:k},z=0,A=()=>{},B={processAnchorElement:A},C=0,D=()=>{},E={processContentEditableFalseElement:D},F=()=>{},G={processSerializedElement:F,fontFamily:null};a.RichTextEditor=v,a.RichTextContainer=function(a){var c=b.useRef(Object.assign({},r)),d=c.current,e=b.useRef([]),f=b.useRef([]),g=b.useRef([]),h=b.useRef([]);return b.useEffect(()=>{var a=d.getContentEditableElement();a&&a.innerHTML&&d.fireNewHTML()},[d]),d.addSelectionChangedListener=a=>{e.current.push(a)},d.removeSelectionChangedListener=a=>{e.current=e.current.filter(b=>b!==a)},d.fireSelectionChanged=()=>{e.current.forEach(a=>a())},d.addBlurListener=a=>{f.current.push(a)},d.removeBlurListener=a=>{f.current=f.current.filter(b=>b!==a)},d.fireBlur=()=>{f.current.forEach(a=>a())},d.addNewHTMLListener=a=>{g.current.push(a)},d.removeNewHTMLListener=a=>{g.current=g.current.filter(b=>b!==a)},d.fireNewHTML=()=>{g.current.forEach(a=>a())},d.numSerializers=()=>h.current.length,d.addSerializer=a=>{h.current.push(a)},d.removeSerializer=a=>{h.current=h.current.filter(b=>b!==a)},d.serialize=a=>(h.current.forEach(b=>b(a)),a.innerHTML),p.createElement(s.Provider,{value:d},a.children)},a.RichTextContext=s,a.useDocumentExecCommand=j,a.useFormatBlock=function(){var a=j("formatBlock"),b=a.performCommandWithValue;return{formatBlock(a){a===document.queryCommandValue("formatBlock")?b("div"):b(a)}}},a.useDocumentQueryCommandState=function(a,c){function d(){var b=document.queryCommandValue(a),d=c?c===b:document.queryCommandState(a);(d!==i.isActive||b!==i.value)&&j({isActive:d,value:b})}function f(){j(w)}var g=b.useState(w),h=e(g,2),i=h[0],j=h[1],k=b.useContext(s);return b.useEffect(()=>(k.addSelectionChangedListener(d),()=>k.removeSelectionChangedListener(d)),[i,j]),b.useEffect(()=>(k.addBlurListener(f),()=>k.removeBlurListener(f)),[i,j]),{isActive:i.isActive,activeValue:i.value}},a.useFontSize=function(a){var c=a.defaultFontSize,d=void 0===c?"14px":c,f=a.fontSizes;if(7<f.length)throw Error(`Browsers only support up to 7 font sizes with document.execCommand('fontSize', null, size)`);var g=b.useState(d),h=e(g,2),i=h[0],k=h[1],l=b.useState(null),m=e(l,2),n=m[0],o=m[1],p=j("fontSize"),q=p.performCommandWithValue,r=b.useContext(s),t=function(){return b.useEffect(()=>{function a(){var a=window.getSelection();if((!n||a.anchorNode!==n.anchorNode||a.anchorOffset!==n.anchorOffset||a.focusNode!==n.focusNode||a.focusOffset!==n.focusOffset)&&(o({anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),0<a.rangeCount)){var b=a.getRangeAt(0).startContainer;1!==b.nodeType&&(b=b.parentElement);var c=window.getComputedStyle(b).fontSize,d=c;d!==i&&k(d)}}return r.addSelectionChangedListener(a),()=>r.removeSelectionChangedListener(a)},[i,k,n]),i}();return function(){b.useEffect(()=>{var a=f.reduce((a,b,c)=>`${a} font[size="${c+1}"] {font-size: ${b}}`,""),b=document.createElement("style");return b.textContent=a,document.head.appendChild(b),()=>document.head.removeChild(b)},[f]),b.useEffect(()=>{function a(a){for(var b=a.querySelectorAll("font"),c=0;c<b.length;c++){var d=b[c],e=+d.getAttribute("size");if(e>f.length)throw Error(`Cannot find fontSize for integer size '${e}'`);var g=f[e-1];d.removeAttribute("size"),d.style.fontSize=g,d.dataset.integerSize=e}}return r.addSerializer(a),()=>r.removeSerializer(a)},[f]),b.useEffect(()=>{function a(){for(var a=r.getContentEditableElement().querySelectorAll("font"),b=function(b){var c=a[b],d=c.style.fontSize,e=f.findIndex(a=>a===d)+1;0<e&&(c.style.fontSize="",c.setAttribute("size",e))},c=0;c<a.length;c++)b(c)}return r.addNewHTMLListener(a),()=>r.removeNewHTMLListener(a)},[f])}(),{currentlySelectedFontSize:t,setSize(a){var b=f.findIndex(b=>b===a)+1;if(0>=b)throw Error(`Cannot set font size since '${a}' was not passed in the fontSizes array`);k(a),q(b)}}},a.useImage=function(){function a(a){a.style.cursor="pointer",e(a)}var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:y,d=c.processImgElement,e=void 0===d?x:d,f=c.fileBlobToUrl,g=void 0===f?k:f,h=j("insertImage"),i=h.performCommandWithValue,l=b.useContext(s),m=b.useRef(null);return function(){b.useEffect(()=>{function b(){var b=l.getContentEditableElement().querySelectorAll("img:not([data-text-as-image])");b.forEach(a)}return l.addNewHTMLListener(b),()=>l.removeNewHTMLListener(b)},[e])}(),function(){b.useEffect(()=>{m.current=document.createElement("input");var b=m.current;b.type="file",b.accept=".jpg, .png, image/*",b.multiple=!1,b.addEventListener("change",()=>{b.files&&0<b.files.length&&g(b.files[0],b=>{i(b);var c=document.querySelector(`img[src="${b}"]`);a(c)})})},[g,e])}(),{chooseFile(){m.current.click()},removeImage(a){var b=document.createRange();b.selectNode(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b),document.execCommand("delete")}}},a.useLink=function(){function a(a,b){f.selectRangeFromBeforeBlur({usePreviousRange:!0});var c=`rte-link-temp-id-${z++}`;k(`<a href="${a}" id="${c}">${b}</a>`);var d=document.getElementById(c);d.removeAttribute("id"),e(d)}var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:B,d=c.processAnchorElement,e=void 0===d?A:d,f=b.useContext(s),g=j("unlink"),h=g.performCommand,i=j("insertHTML"),k=i.performCommandWithValue;return function(){b.useEffect(()=>{function a(){var a=f.getContentEditableElement().querySelectorAll("a");a.forEach(e)}return f.addNewHTMLListener(a),()=>f.removeNewHTMLListener(a)},[e])}(),{getTextFromBeforeBlur:function(){var a=f.getRangeFromBeforeBlur();return a?a.toString():null},selectEntireLink:function(a){var b=document.createRange();b.selectNodeContents(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)},unlink:function(){h(),(window.navigator.userAgent.includes("Edge/14")||window.navigator.userAgent.includes("Edge/15")||window.navigator.userAgent.includes("Edge/16")||window.navigator.userAgent.includes("Edge/17"))&&document.execCommand("removeFormat")},insertLink:a}},a.useContentEditableFalse=function(){function a(a){if(a.removeAttribute("id"),a.contentEditable=!1,a.addEventListener("click",()=>l(a)),!a.previousSibling&&a.parentElement===h.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===h.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}l(a),e(a)}var c=0<arguments.length&&arguments[0]!==void 0?arguments[0]:E,d=c.processContentEditableFalseElement,e=void 0===d?D:d,f=j("insertHTML"),g=f.performCommandWithValue,h=b.useContext(s);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+C++,d=`<span id="${c}">${h.sanitizeHTML(b,"insertContentEditableFalseHTML")}</span>`;g(d);var e=document.getElementById(c);a(e)}}},a.useTextAsImage=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:G,c=a.processSerializedElement,d=void 0===c?F:c,e=a.fontFamily,f=void 0===e?null:e,g=j("insertImage"),h=g.performCommandWithValue,k=b.useContext(s);return function(){b.useEffect(()=>{function a(){for(var a=k.getContentEditableElement().querySelectorAll("span[data-text-as-image]"),b=0;b<a.length;b++){var c=a[b],d=m(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement,f),e=document.createElement("img");e.src=d,n(e,c.dataset.textAsImage),c.parentNode.replaceChild(e,c)}}return k.addNewHTMLListener(a),()=>k.removeNewHTMLListener(a)},[])}(),function(){b.useEffect(()=>{function a(a){for(var b=a.querySelectorAll("img[data-text-as-image]"),c=0;c<b.length;c++){var e=b[c],f=document.createElement("span");f.dataset.textAsImage=e.dataset.textAsImage,d(f,f.dataset.textAsImage),e.parentNode.replaceChild(f,e)}}return k.addSerializer(a),()=>k.removeSerializer(a)},[])}(),{insertTextAsImage(a){k.selectRangeFromBeforeBlur({usePreviousRange:!0});var b=m(a,o(),f);h(b);var c=document.querySelector(`img[src="${b}"]`);n(c,a)}}},a.useElementDeletionDetection=function(a,c){var d=b.useContext(s);b.useEffect(()=>{if(a){function b(){a.isConnected||a._bandicoot_delete_callback_called||(a._bandicoot_delete_callback_called=!0,c(a))}return d.addSelectionChangedListener(b),()=>d.removeSelectionChangedListener(b)}},[a,c])},Object.defineProperty(a,"__esModule",{value:!0})});
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],b):(a=a||self,b(a.bandicoot={},a.React))})(this,function(a,b){"use strict";function c(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function d(a){for(var b=1;b<arguments.length;b++){var d=null==arguments[b]?{}:arguments[b],e=Object.keys(d);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(d).filter(function(a){return Object.getOwnPropertyDescriptor(d,a).enumerable}))),e.forEach(function(b){c(a,b,d[b])})}return a}function e(a,b){return f(a)||g(a,b)||h()}function f(a){if(Array.isArray(a))return a}function g(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function h(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function i(){var a=b.useRef(null),c=b.useState(!1),d=e(c,2),f=d[0],g=d[1];return{isFocused:function(){return a.current},setFocused:function(b){a.current=b,g(!f)}}}function j(a){var c=b.useContext(s);return{performCommand(){c.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(b){c.selectRangeFromBeforeBlur();document.execCommand(a,null,b)}}}function k(a,b){b(URL.createObjectURL(a))}function l(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}function m(a,b,d){var e=window.getComputedStyle(b),f=+e.fontSize.replace("px",""),g=+e.lineHeight.replace("px",""),h=d||e.fontFamily,i=`bold ${f}px ${h}`,j=document.createElement("div");j.style.font=i,j.style.position="absolute",j.style.visibility="hidden",j.style.whiteSpace="nowrap",j.textContent=a,document.body.appendChild(j);var k=document.createElement("canvas");k.width=j.clientWidth+1,k.height=g;var l=k.getContext("2d");return l.font=i,l.fillStyle="#00bf4b",l.textBaseline="bottom",l.fillText(a,0,g-3),document.body.removeChild(j),l.canvas.toDataURL()}function n(a,b){a.style.verticalAlign="bottom",a.dataset.textAsImage=b,a.addEventListener("click",b=>{var c=a.getBoundingClientRect(),d=c.left+c.width/2,e=document.createRange();b.x<d?e.setStartBefore(a):e.setStartAfter(a);var f=window.getSelection();f.removeAllRanges(),f.addRange(e)})}function o(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}var p="default"in b?b["default"]:b,q=()=>{},r={addSelectionChangedListener:q,removeSelectionChangedListener:q,fireSelectionChanged:q,selectRangeFromBeforeBlur:q,getRangeBeforeBlur:q,addBlurListener:q,removeBlurListener:q,fireBlur:q,addNewHTMLListener:q,removeNewHTMLListener:q,fireNewHTML:q,isFocused:q,getContentEditableElement:q,numSerializers:()=>0,addSerializer:q,removeSerializer:q,serialize:q,sanitizeHTML:q},s=p.createContext(r),t=a=>a,u=0,v=b.forwardRef((a,c)=>{function f(b){b.preventDefault(),b.stopPropagation();var c=o.sanitizeHTML((window.clipboardData||b.clipboardData).getData("text/html"),"pasteHTML"),d=a.pasteFn(c);!1!==d&&document.execCommand("insertHTML",null,d)}function g(){var a=document.createRange();a.selectNodeContents(q.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("removeFormat"),document.execCommand("delete")}function h(){if(v()){var a=window.getSelection();0<a.rangeCount&&(r.current=window.getSelection().getRangeAt(0)),o.fireSelectionChanged()}}function j(){var b=m();b!==A&&(B(b),a.save(b))}function k(){var a=q.current.innerHTML;if(0<o.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=o.serialize(b.body)}return a}function l(a){g(),q.current.innerHTML=o.sanitizeHTML(a,"setHTML"),n(),o.fireNewHTML()}function m(){return o.sanitizeHTML(k(),"getHTML")}function n(){q.current.focus(),w(!0)}var o=b.useContext(s);o.sanitizeHTML=a.sanitizeHTML;var q=b.useRef(null),r=b.useRef(null),t=i(),v=t.isFocused,w=t.setFocused,x=b.useRef(u++),y=b.useState(()=>o.sanitizeHTML(a.initialHTML,"initialSetLastSavedHTML")),z=e(y,2),A=z[0],B=z[1],C=b.useState(!1),D=e(C,2),E=D[0],F=D[1];c&&(c.current={setHTML:l,resetEditor:function(){l("")},getHTML:m,focus:n}),b.useEffect(()=>(q.current.addEventListener("paste",f),()=>q.current.removeEventListener("paste",f)),[a.pasteFn]),b.useEffect(()=>(document.addEventListener("selectionchange",h),()=>document.removeEventListener("selectionchange",h))),b.useEffect(()=>{if(a.save&&a.unchangedInterval&&q.current&&v()){var b,c=new MutationObserver(()=>{clearTimeout(b),b=setTimeout(j,a.unchangedInterval)});return c.observe(q.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{c.disconnect(),clearTimeout(b)}}},[a.unchangedInterval,a.save,q.current,v()]),b.useEffect(()=>{if(!1===v()){var a=setTimeout(()=>{o.fireBlur(),j()},100);return()=>{clearTimeout(a)}}},[v()]),b.useEffect(()=>{o.selectRangeFromBeforeBlur=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{usePreviousRange:!1};if(q.current&&document.activeElement!==q.current&&!q.current.contains(document.activeElement)){if(a.usePreviousRange&&r.current){var b=window.getSelection();b.removeAllRanges(),b.addRange(r.current)}else q.current.focus();w(!0),setTimeout(h)}},o.getRangeFromBeforeBlur=()=>r.current,o.isFocused=v,o.getContentEditableElement=()=>q.current}),b.useEffect(()=>{!E&&a.initialHTML&&(F(!0),l(a.initialHTML))},[E,l,o]),b.useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${x.current}:empty:before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,x.current]);var G=a.style||{};return p.createElement("div",{contentEditable:!0,onBlur:()=>w(!1),onFocus:function(){w(!0);var a=window.getSelection();0<a.rangeCount&&(r.current=a.getRangeAt(0))},ref:q,className:a.className+" bandicoot-id-"+x.current,style:d({wordBreak:"break-word",wordWrap:"break-word",overflowWrap:"break-word"},G),"data-placeholder":a.placeholder})});v.defaultProps={className:"",initialHTML:"",save:()=>{},placeholder:"",placeholderColor:"#CFCFCF",pasteFn:t,sanitizeHTML:t};var w={isActive:!1,value:!1},x=()=>{},y={processImgElement:x,fileBlobToUrl:k,acceptImgTypes:".jpg, .png, image/*"},z=0,A=()=>{},B={processAnchorElement:A},C=0,D=()=>{},E={processContentEditableFalseElement:D},F=()=>{},G={processSerializedElement:F,fontFamily:null};a.RichTextEditor=v,a.RichTextContainer=function(a){var c=b.useRef(Object.assign({},r)),d=c.current,e=b.useRef([]),f=b.useRef([]),g=b.useRef([]),h=b.useRef([]);return b.useEffect(()=>{var a=d.getContentEditableElement();a&&a.innerHTML&&d.fireNewHTML()},[d]),d.addSelectionChangedListener=a=>{e.current.push(a)},d.removeSelectionChangedListener=a=>{e.current=e.current.filter(b=>b!==a)},d.fireSelectionChanged=()=>{e.current.forEach(a=>a())},d.addBlurListener=a=>{f.current.push(a)},d.removeBlurListener=a=>{f.current=f.current.filter(b=>b!==a)},d.fireBlur=()=>{f.current.forEach(a=>a())},d.addNewHTMLListener=a=>{g.current.push(a)},d.removeNewHTMLListener=a=>{g.current=g.current.filter(b=>b!==a)},d.fireNewHTML=()=>{g.current.forEach(a=>a())},d.numSerializers=()=>h.current.length,d.addSerializer=a=>{h.current.push(a)},d.removeSerializer=a=>{h.current=h.current.filter(b=>b!==a)},d.serialize=a=>(h.current.forEach(b=>b(a)),a.innerHTML),p.createElement(s.Provider,{value:d},a.children)},a.RichTextContext=s,a.useDocumentExecCommand=j,a.useFormatBlock=function(){var a=j("formatBlock"),b=a.performCommandWithValue;return{formatBlock(a){a===document.queryCommandValue("formatBlock")?b("div"):b(a)}}},a.useDocumentQueryCommandState=function(a,c){function d(){var b=document.queryCommandValue(a),d=c?c===b:document.queryCommandState(a);(d!==i.isActive||b!==i.value)&&j({isActive:d,value:b})}function f(){j(w)}var g=b.useState(w),h=e(g,2),i=h[0],j=h[1],k=b.useContext(s);return b.useEffect(()=>(k.addSelectionChangedListener(d),()=>k.removeSelectionChangedListener(d)),[i,j]),b.useEffect(()=>(k.addBlurListener(f),()=>k.removeBlurListener(f)),[i,j]),{isActive:i.isActive,activeValue:i.value}},a.useFontSize=function(a){var c=a.defaultFontSize,d=void 0===c?"14px":c,f=a.fontSizes;if(7<f.length)throw Error(`Browsers only support up to 7 font sizes with document.execCommand('fontSize', null, size)`);var g=b.useState(d),h=e(g,2),i=h[0],k=h[1],l=b.useState(null),m=e(l,2),n=m[0],o=m[1],p=j("fontSize"),q=p.performCommandWithValue,r=b.useContext(s),t=function(){return b.useEffect(()=>{function a(){var a=window.getSelection();if((!n||a.anchorNode!==n.anchorNode||a.anchorOffset!==n.anchorOffset||a.focusNode!==n.focusNode||a.focusOffset!==n.focusOffset)&&(o({anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),0<a.rangeCount)){var b=a.getRangeAt(0).startContainer;1!==b.nodeType&&(b=b.parentElement);var c=window.getComputedStyle(b).fontSize,d=c;d!==i&&k(d)}}return r.addSelectionChangedListener(a),()=>r.removeSelectionChangedListener(a)},[i,k,n]),i}();return function(){b.useEffect(()=>{var a=f.reduce((a,b,c)=>`${a} font[size="${c+1}"] {font-size: ${b}}`,""),b=document.createElement("style");return b.textContent=a,document.head.appendChild(b),()=>document.head.removeChild(b)},[f]),b.useEffect(()=>{function a(a){for(var b=a.querySelectorAll("font"),c=0;c<b.length;c++){var d=b[c],e=+d.getAttribute("size");if(e>f.length)throw Error(`Cannot find fontSize for integer size '${e}'`);var g=f[e-1];d.removeAttribute("size"),d.style.fontSize=g,d.dataset.integerSize=e}}return r.addSerializer(a),()=>r.removeSerializer(a)},[f]),b.useEffect(()=>{function a(){for(var a=r.getContentEditableElement().querySelectorAll("font"),b=function(b){var c=a[b],d=c.style.fontSize,e=f.findIndex(a=>a===d)+1;0<e&&(c.style.fontSize="",c.setAttribute("size",e))},c=0;c<a.length;c++)b(c)}return r.addNewHTMLListener(a),()=>r.removeNewHTMLListener(a)},[f])}(),{currentlySelectedFontSize:t,setSize(a){var b=f.findIndex(b=>b===a)+1;if(0>=b)throw Error(`Cannot set font size since '${a}' was not passed in the fontSizes array`);k(a),q(b)}}},a.useImage=function(){function a(a){a.style.cursor="pointer",a.style.maxWidth="100%",f(a)}function c(a){a.querySelectorAll("img").forEach(a=>{r.current[a.src]&&(a.src=r.current[a.src])})}var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:y,e=d.processImgElement,f=void 0===e?x:e,g=d.fileBlobToUrl,h=void 0===g?k:g,i=d.acceptImgTypes,l=void 0===i?".jpg, .png, image/*":i,m=j("insertImage"),n=m.performCommandWithValue,o=b.useContext(s),q=b.useRef(null),r=p.useRef({});return function(){b.useEffect(()=>{function b(){var b=o.getContentEditableElement().querySelectorAll("img:not([data-text-as-image])");b.forEach(a)}return o.addNewHTMLListener(b),()=>o.removeNewHTMLListener(b)},[f])}(),function(){b.useEffect(()=>{q.current=document.createElement("input");var b=q.current;b.type="file",b.accept=l,b.multiple=!1,b.addEventListener("change",()=>{b.files&&0<b.files.length&&h(b.files[0],c=>{n(c);var d=document.querySelector(`img[src="${c}"]`);if(d.src&&d.src.startsWith("blob:")){var e=new FileReader;e.addEventListener("load",()=>{r.current[d.src]=e.result}),e.readAsDataURL(b.files[0])}a(d)})})},[h,f,l])}(),function(){b.useEffect(()=>(o.addSerializer(c),()=>o.removeSerializer(c)))}(),{chooseFile(){q.current.click()},removeImage(a){var b=document.createRange();b.selectNode(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b),document.execCommand("delete")}}},a.useLink=function(){function a(a,b){f.selectRangeFromBeforeBlur({usePreviousRange:!0});var c=`rte-link-temp-id-${z++}`;k(`<a href="${a}" id="${c}" target="_blank" rel="noopener noreferrer">${b}</a>`);var d=document.getElementById(c);d.removeAttribute("id"),e(d)}var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:B,d=c.processAnchorElement,e=void 0===d?A:d,f=b.useContext(s),g=j("unlink"),h=g.performCommand,i=j("insertHTML"),k=i.performCommandWithValue;return function(){b.useEffect(()=>{function a(){var a=f.getContentEditableElement().querySelectorAll("a");a.forEach(e)}return f.addNewHTMLListener(a),()=>f.removeNewHTMLListener(a)},[e])}(),{getTextFromBeforeBlur:function(){var a=f.getRangeFromBeforeBlur();return a?a.toString():null},selectEntireLink:function(a){var b=document.createRange();b.selectNodeContents(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)},unlink:function(){h(),(window.navigator.userAgent.includes("Edge/14")||window.navigator.userAgent.includes("Edge/15")||window.navigator.userAgent.includes("Edge/16")||window.navigator.userAgent.includes("Edge/17"))&&document.execCommand("removeFormat")},insertLink:a}},a.useContentEditableFalse=function(){function a(a){if(a.removeAttribute("id"),a.contentEditable=!1,a.addEventListener("click",()=>l(a)),!a.previousSibling&&a.parentElement===h.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===h.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}l(a),e(a)}var c=0<arguments.length&&arguments[0]!==void 0?arguments[0]:E,d=c.processContentEditableFalseElement,e=void 0===d?D:d,f=j("insertHTML"),g=f.performCommandWithValue,h=b.useContext(s);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+C++,d=`<span id="${c}">${h.sanitizeHTML(b,"insertContentEditableFalseHTML")}</span>`;g(d);var e=document.getElementById(c);a(e)}}},a.useTextAsImage=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:G,c=a.processSerializedElement,d=void 0===c?F:c,e=a.fontFamily,f=void 0===e?null:e,g=j("insertImage"),h=g.performCommandWithValue,k=b.useContext(s);return function(){b.useEffect(()=>{function a(){for(var a=k.getContentEditableElement().querySelectorAll("span[data-text-as-image]"),b=0;b<a.length;b++){var c=a[b],d=m(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement,f),e=document.createElement("img");e.src=d,n(e,c.dataset.textAsImage),c.parentNode.replaceChild(e,c)}}return k.addNewHTMLListener(a),()=>k.removeNewHTMLListener(a)},[])}(),function(){b.useEffect(()=>{function a(a){for(var b=a.querySelectorAll("img[data-text-as-image]"),c=0;c<b.length;c++){var e=b[c],f=document.createElement("span");f.dataset.textAsImage=e.dataset.textAsImage,d(f,f.dataset.textAsImage),e.parentNode.replaceChild(f,e)}}return k.addSerializer(a),()=>k.removeSerializer(a)},[])}(),{insertTextAsImage(a){k.selectRangeFromBeforeBlur({usePreviousRange:!0});var b=m(a,o(),f);h(b);var c=document.querySelector(`img[src="${b}"]`);n(c,a)}}},a.useElementDeletionDetection=function(a,c){var d=b.useContext(s);b.useEffect(()=>{if(a){function b(){a.isConnected||a._bandicoot_delete_callback_called||(a._bandicoot_delete_callback_called=!0,c(a))}return d.addSelectionChangedListener(b),()=>d.removeSelectionChangedListener(b)}},[a,c])},Object.defineProperty(a,"__esModule",{value:!0})});
//# sourceMappingURL=bandicoot.umd.js.map
{
"name": "bandicoot",
"version": "2.9.1",
"version": "2.10.0",
"description": "React rich text editor",

@@ -24,3 +24,3 @@ "main": "dist/bandicoot.umd.js",

"watch": "rollup -c --watch",
"prepare": "yarn build"
"prepublishOnly": "yarn build"
},

@@ -27,0 +27,0 @@ "browserslist": [

@@ -21,3 +21,3 @@ declare module "bandicoot" {

initialHTML?: any;
save?(): any;
save?(html: string): any;
sanitizeHTML?(html: string): string;

@@ -24,0 +24,0 @@ pasteFn?(paste: string): string;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc