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

bandicoot

Package Overview
Dependencies
Maintainers
2
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.2.0 to 2.2.1

2

dist/bandicoot.umd.js

@@ -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){return d(a)||e(a,b)||f()}function d(a){if(Array.isArray(a))return a}function e(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 f(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function g(a){var c=b.useContext(p);return{performCommand(){c.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(b){c.selectRangeFromBeforeBlur();document.execCommand(a,null,b)}}}function h(a,b){b(URL.createObjectURL(a))}function i(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}function j(a,b){var d=window.getComputedStyle(b),e=+d.fontSize.replace("px",""),f=+d.lineHeight.replace("px",""),g=d.fontFamily,h=`bold ${e}px ${g}`,i=document.createElement("div");i.style.font=h,i.style.position="absolute",i.style.visibility="hidden",i.style.whiteSpace="nowrap",i.textContent=a,document.body.appendChild(i);var j=document.createElement("canvas");j.width=i.clientWidth+1,j.height=f;var k=j.getContext("2d");return k.font=h,k.fillStyle="#00bf4b",k.textBaseline="bottom",k.fillText(a,0,f-3),document.body.removeChild(i),k.canvas.toDataURL()}function k(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 l(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}var m="default"in b?b["default"]:b,n=()=>{},o={addSelectionChangedListener:n,removeSelectionChangedListener:n,fireSelectionChanged:n,selectRangeFromBeforeBlur:n,getRangeBeforeBlur:n,addBlurListener:n,removeBlurListener:n,fireBlur:n,addNewHTMLListener:n,removeNewHTMLListener:n,fireNewHTML:n,isFocused:n,getContentEditableElement:n,numSerializers:()=>0,addSerializer:n,removeSerializer:n,serialize:n},p=m.createContext(o),q=0,r=b.forwardRef((a,d)=>{function e(){var a=document.createRange();a.selectNodeContents(i.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("delete")}function f(){if(k.current){var a=window.getSelection();0<a.rangeCount&&(j.current=window.getSelection().getRangeAt(0)),l.fireSelectionChanged()}}function g(){var b=h();b!==t&&(u(b),a.save(b))}function h(){var a=i.current.innerHTML;if(0<l.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=l.serialize(b.body)}return a}var i=b.useRef(null),j=b.useRef(null),k=b.useRef(!1),l=b.useContext(p),n=b.useRef(null),o=b.useRef(q++),r=b.useState(a.initialHTML),s=c(r,2),t=s[0],u=s[1];return d&&(d.current={setHTML(a){e(),i.current.innerHTML=a,i.current.focus(),l.fireNewHTML()},resetEditor(){d.current.setHTML("")}}),b.useEffect(()=>(document.addEventListener("selectionchange",f),()=>document.removeEventListener("selectionchange",f))),b.useEffect(()=>{if(a.save&&a.unchangedInterval&&i.current&&k.current){setTimeout(g,a.unchangedInterval);var b=new MutationObserver(()=>{clearTimeout(n.current),n.current=setTimeout(g,a.unchangedInterval)});return b.observe(i.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{b.disconnect(),clearTimeout(n.current)}}},[a.unchangedInterval,a.save,i.current,k.current]),b.useEffect(()=>{l.selectRangeFromBeforeBlur=()=>{if(i.current&&document.activeElement!==i.current&&!i.current.contains(document.activeElement))if(j.current){var a=window.getSelection();a.removeAllRanges(),a.addRange(j.current)}else i.current.focus()},l.getRangeFromBeforeBlur=()=>j.current,l.isFocused=()=>k.current,l.getContentEditableElement=()=>i.current},[k.current]),b.useEffect(()=>{a.initialHTML&&(i.current.innerHTML=a.initialHTML,l.fireNewHTML())},[]),b.useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${o.current}:empty:not(:focus):before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,o.current]),m.createElement("div",{contentEditable:!0,onBlur:function(){k.current=!1,setTimeout(()=>{k.current||(l.fireBlur(),g())},100)},onFocus:function(){k.current=!0;var a=window.getSelection();0<a.rangeCount&&(j.current=a.getRangeAt(0))},ref:i,className:a.className+" bandicoot-id-"+o.current,"data-placeholder":a.placeholder})});r.defaultProps={className:"",initialHTML:"",save:()=>{},placeholder:"",placeholderColor:"#CFCFCF"};var s={isActive:!1,value:!1},t=()=>{},u={processImgElement:t,fileBlobToUrl:h},v=0,w=()=>{},x={processAnchorElement:w},y=0,z=()=>{},A={processContentEditableFalseElement:z},B=()=>{},C={processSerializedElement:B};a.RichTextEditor=r,a.RichTextContainer=function(a){var c=b.useRef(Object.assign({},o)),d=c.current,e=b.useRef([]),f=b.useRef([]),g=b.useRef([]),h=b.useRef([]);return 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),m.createElement(p.Provider,{value:d},a.children)},a.RichTextContext=p,a.useDocumentExecCommand=g,a.useDocumentQueryCommandState=function(a){function d(){var b=document.queryCommandState(a),c=document.queryCommandValue(a);(b!==h.isActive||c!==h.value)&&i({isActive:b,value:c})}function e(){i(s)}var f=b.useState(s),g=c(f,2),h=g[0],i=g[1],j=b.useContext(p);return b.useEffect(()=>(j.addSelectionChangedListener(d),()=>j.removeSelectionChangedListener(d)),[h,i]),b.useEffect(()=>(j.addBlurListener(e),()=>j.removeBlurListener(e)),[h,i]),{isActive:h.isActive,activeValue:h.value}},a.useFontSize=function(a){var d=a.defaultFontSize,e=void 0===d?"14px":d,f=a.fontSizes;if(7<f.length)throw Error(`Browsers only support up to 7 font sizes with document.execCommand('fontSize', null, size)`);var h=b.useState(e),i=c(h,2),j=i[0],k=i[1],l=g("fontSize"),m=l.performCommandWithValue,n=b.useContext(p),o=function(){return b.useEffect(()=>{function a(){var a=window.getSelection(),b=a.getRangeAt(0).startContainer;1!==b.nodeType&&(b=b.parentElement);var c=window.getComputedStyle(b).fontSize,d=c;d!==j&&k(d)}return n.addSelectionChangedListener(a),()=>n.removeSelectionChangedListener(a)},[j,k]),j}();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 n.addSerializer(a),()=>n.removeSerializer(a)},[f]),b.useEffect(()=>{function a(){for(var a=n.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 n.addNewHTMLListener(a),()=>n.removeNewHTMLListener(a)},[f])}(),{currentlySelectedFontSize:o,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`);m(b)}}},a.useImage=function(){function a(a){a.style.cursor="pointer",e(a)}var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:u,d=c.processImgElement,e=void 0===d?t:d,f=c.fileBlobToUrl,i=void 0===f?h:f,j=g("insertImage"),k=j.performCommandWithValue,l=b.useContext(p),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&&i(b.files[0],b=>{k(b);var c=document.querySelector(`img[src="${b}"]`);a(c)})})},[i,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){var c=`rte-link-temp-id-${v++}`;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]:x,d=c.processAnchorElement,e=void 0===d?w:d,f=b.useContext(p),h=g("unlink"),i=h.performCommand,j=g("insertHTML"),k=j.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:i,insertLink:a}},a.useContentEditableFalse=function(){function a(a){if(a.removeAttribute("id"),a.contentEditable=!1,a.addEventListener("click",()=>i(a)),!a.previousSibling&&a.parentElement===j.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===j.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}i(a),e(a)}var c=0<arguments.length&&arguments[0]!==void 0?arguments[0]:A,d=c.processContentEditableFalseElement,e=void 0===d?z:d,f=g("insertHTML"),h=f.performCommandWithValue,j=b.useContext(p);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+y++;h(`<span id="${c}">${b}</span>`);var d=document.getElementById(c);a(d)}}},a.useTextAsImage=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:C,c=a.processSerializedElement,d=void 0===c?B:c,e=g("insertImage"),f=e.performCommandWithValue,h=b.useContext(p);return function(){b.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=j(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement),e=document.createElement("img");e.src=d,k(e,c.dataset.textAsImage),c.parentNode.replaceChild(e,c)}}return h.addNewHTMLListener(a),()=>h.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 h.addSerializer(a),()=>h.removeSerializer(a)},[])}(),{insertTextAsImage(a){h.selectRangeFromBeforeBlur();var b=j(a,l());f(b);var c=document.querySelector(`img[src="${b}"]`);k(c,a)}}},a.useElementDeletionDetection=function(a,c){var d=b.useContext(p);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){return d(a)||e(a,b)||f()}function d(a){if(Array.isArray(a))return a}function e(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 f(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function g(a){var c=b.useContext(p);return{performCommand(){c.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(b){c.selectRangeFromBeforeBlur();document.execCommand(a,null,b)}}}function h(a,b){b(URL.createObjectURL(a))}function i(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}function j(a,b){var d=window.getComputedStyle(b),e=+d.fontSize.replace("px",""),f=+d.lineHeight.replace("px",""),g=d.fontFamily,h=`bold ${e}px ${g}`,i=document.createElement("div");i.style.font=h,i.style.position="absolute",i.style.visibility="hidden",i.style.whiteSpace="nowrap",i.textContent=a,document.body.appendChild(i);var j=document.createElement("canvas");j.width=i.clientWidth+1,j.height=f;var k=j.getContext("2d");return k.font=h,k.fillStyle="#00bf4b",k.textBaseline="bottom",k.fillText(a,0,f-3),document.body.removeChild(i),k.canvas.toDataURL()}function k(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 l(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}var m="default"in b?b["default"]:b,n=()=>{},o={addSelectionChangedListener:n,removeSelectionChangedListener:n,fireSelectionChanged:n,selectRangeFromBeforeBlur:n,getRangeBeforeBlur:n,addBlurListener:n,removeBlurListener:n,fireBlur:n,addNewHTMLListener:n,removeNewHTMLListener:n,fireNewHTML:n,isFocused:n,getContentEditableElement:n,numSerializers:()=>0,addSerializer:n,removeSerializer:n,serialize:n},p=m.createContext(o),q=0,r=b.forwardRef((a,d)=>{function e(){var a=document.createRange();a.selectNodeContents(i.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("delete")}function f(){if(k.current){var a=window.getSelection();0<a.rangeCount&&(j.current=window.getSelection().getRangeAt(0)),l.fireSelectionChanged()}}function g(){var b=h();b!==t&&(u(b),a.save(b))}function h(){var a=i.current.innerHTML;if(0<l.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=l.serialize(b.body)}return a}var i=b.useRef(null),j=b.useRef(null),k=b.useRef(!1),l=b.useContext(p),n=b.useRef(null),o=b.useRef(q++),r=b.useState(a.initialHTML),s=c(r,2),t=s[0],u=s[1];return d&&(d.current={setHTML(a){e(),i.current.innerHTML=a,i.current.focus(),l.fireNewHTML()},resetEditor(){d.current.setHTML("")}}),b.useEffect(()=>(document.addEventListener("selectionchange",f),()=>document.removeEventListener("selectionchange",f))),b.useEffect(()=>{if(a.save&&a.unchangedInterval&&i.current&&k.current){setTimeout(g,a.unchangedInterval);var b=new MutationObserver(()=>{clearTimeout(n.current),n.current=setTimeout(g,a.unchangedInterval)});return b.observe(i.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{b.disconnect(),clearTimeout(n.current)}}},[a.unchangedInterval,a.save,i.current,k.current]),b.useEffect(()=>{l.selectRangeFromBeforeBlur=()=>{if(i.current&&document.activeElement!==i.current&&!i.current.contains(document.activeElement))if(j.current){var a=window.getSelection();a.removeAllRanges(),a.addRange(j.current)}else i.current.focus()},l.getRangeFromBeforeBlur=()=>j.current,l.isFocused=()=>k.current,l.getContentEditableElement=()=>i.current},[k.current]),b.useEffect(()=>{a.initialHTML&&(i.current.innerHTML=a.initialHTML,l.fireNewHTML())},[]),b.useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${o.current}:empty:not(:focus):before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,o.current]),m.createElement("div",{contentEditable:!0,onBlur:function(){k.current=!1,setTimeout(()=>{k.current||(l.fireBlur(),g())},100)},onFocus:function(){k.current=!0;var a=window.getSelection();0<a.rangeCount&&(j.current=a.getRangeAt(0))},ref:i,className:a.className+" bandicoot-id-"+o.current,"data-placeholder":a.placeholder})});r.defaultProps={className:"",initialHTML:"",save:()=>{},placeholder:"",placeholderColor:"#CFCFCF"};var s={isActive:!1,value:!1},t=()=>{},u={processImgElement:t,fileBlobToUrl:h},v=0,w=()=>{},x={processAnchorElement:w},y=0,z=()=>{},A={processContentEditableFalseElement:z},B=()=>{},C={processSerializedElement:B};a.RichTextEditor=r,a.RichTextContainer=function(a){var c=b.useRef(Object.assign({},o)),d=c.current,e=b.useRef([]),f=b.useRef([]),g=b.useRef([]),h=b.useRef([]);return 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),m.createElement(p.Provider,{value:d},a.children)},a.RichTextContext=p,a.useDocumentExecCommand=g,a.useDocumentQueryCommandState=function(a){function d(){var b=document.queryCommandState(a),c=document.queryCommandValue(a);(b!==h.isActive||c!==h.value)&&i({isActive:b,value:c})}function e(){i(s)}var f=b.useState(s),g=c(f,2),h=g[0],i=g[1],j=b.useContext(p);return b.useEffect(()=>(j.addSelectionChangedListener(d),()=>j.removeSelectionChangedListener(d)),[h,i]),b.useEffect(()=>(j.addBlurListener(e),()=>j.removeBlurListener(e)),[h,i]),{isActive:h.isActive,activeValue:h.value}},a.useFontSize=function(a){var d=a.defaultFontSize,e=void 0===d?"14px":d,f=a.fontSizes;if(7<f.length)throw Error(`Browsers only support up to 7 font sizes with document.execCommand('fontSize', null, size)`);var h=b.useState(e),i=c(h,2),j=i[0],k=i[1],l=g("fontSize"),m=l.performCommandWithValue,n=b.useContext(p),o=function(){return b.useEffect(()=>{function a(){var a=window.getSelection(),b=a.getRangeAt(0).startContainer;1!==b.nodeType&&(b=b.parentElement);var c=window.getComputedStyle(b).fontSize,d=c;d!==j&&k(d)}return n.addSelectionChangedListener(a),()=>n.removeSelectionChangedListener(a)},[j,k]),j}();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 n.addSerializer(a),()=>n.removeSerializer(a)},[f]),b.useEffect(()=>{function a(){for(var a=n.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 n.addNewHTMLListener(a),()=>n.removeNewHTMLListener(a)},[f])}(),{currentlySelectedFontSize:o,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`);m(b)}}},a.useImage=function(){function a(a){a.style.cursor="pointer",e(a)}var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:u,d=c.processImgElement,e=void 0===d?t:d,f=c.fileBlobToUrl,i=void 0===f?h:f,j=g("insertImage"),k=j.performCommandWithValue,l=b.useContext(p),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&&i(b.files[0],b=>{k(b);var c=document.querySelector(`img[src="${b}"]`);a(c)})})},[i,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){var c=`rte-link-temp-id-${v++}`;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]:x,d=c.processAnchorElement,e=void 0===d?w:d,f=b.useContext(p),h=g("unlink"),i=h.performCommand,j=g("insertHTML"),k=j.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(){i(),(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",()=>i(a)),!a.previousSibling&&a.parentElement===j.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===j.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}i(a),e(a)}var c=0<arguments.length&&arguments[0]!==void 0?arguments[0]:A,d=c.processContentEditableFalseElement,e=void 0===d?z:d,f=g("insertHTML"),h=f.performCommandWithValue,j=b.useContext(p);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+y++;h(`<span id="${c}">${b}</span>`);var d=document.getElementById(c);a(d)}}},a.useTextAsImage=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:C,c=a.processSerializedElement,d=void 0===c?B:c,e=g("insertImage"),f=e.performCommandWithValue,h=b.useContext(p);return function(){b.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=j(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement),e=document.createElement("img");e.src=d,k(e,c.dataset.textAsImage),c.parentNode.replaceChild(e,c)}}return h.addNewHTMLListener(a),()=>h.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 h.addSerializer(a),()=>h.removeSerializer(a)},[])}(),{insertTextAsImage(a){h.selectRangeFromBeforeBlur();var b=j(a,l());f(b);var c=document.querySelector(`img[src="${b}"]`);k(c,a)}}},a.useElementDeletionDetection=function(a,c){var d=b.useContext(p);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.2.0",
"version": "2.2.1",
"description": "React rich text editor",

@@ -5,0 +5,0 @@ "main": "dist/bandicoot.umd.js",

@@ -18,3 +18,3 @@ import {useContext, useEffect} from 'react'

selectEntireLink,
unlink: performCommand,
unlink,
insertLink,

@@ -59,2 +59,17 @@ }

}
function unlink() {
performCommand()
if (
window.navigator.userAgent.includes('Edge/14') ||
window.navigator.userAgent.includes('Edge/15') ||
window.navigator.userAgent.includes('Edge/16') ||
window.navigator.userAgent.includes('Edge/17')
) {
// Older versions of Edge remove the <a> when you unlink, but keep the text blue and underlined so it looks like a link.
// Ideally we'd be super smart about working around this, but for now I'm just removing all rich text formatting from the
// text that used to be a link when you've got an older version of Edge.
document.execCommand('removeFormat')
}
}
}
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