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.4.2 to 2.5.0

src/use-format-block.hook.js

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(){var a=b.useRef(null),d=b.useState(!1),e=c(d,2),f=e[0],g=e[1];return{isFocused:function(){return a.current},setFocused:function(b){a.current=b,g(!f)}}}function h(a){var c=b.useContext(q);return{performCommand(){c.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(b){c.selectRangeFromBeforeBlur();document.execCommand(a,null,b)}}}function i(a,b){b(URL.createObjectURL(a))}function j(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}function k(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 l(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 m(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}var n="default"in b?b["default"]:b,o=()=>{},p={addSelectionChangedListener:o,removeSelectionChangedListener:o,fireSelectionChanged:o,selectRangeFromBeforeBlur:o,getRangeBeforeBlur:o,addBlurListener:o,removeBlurListener:o,fireBlur:o,addNewHTMLListener:o,removeNewHTMLListener:o,fireNewHTML:o,isFocused:o,getContentEditableElement:o,numSerializers:()=>0,addSerializer:o,removeSerializer:o,serialize:o},q=n.createContext(p),r=0,s=b.forwardRef((a,d)=>{function e(b){b.preventDefault(),b.stopPropagation();var c=(window.clipboardData||b.clipboardData).getData("text/html"),d=a.pasteFn(c),e=window.getSelection();if(!e.rangeCount)return!1;var f=document.createRange().createContextualFragment(d);e.getRangeAt(0).insertNode(f)}function f(){var a=document.createRange();a.selectNodeContents(k.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("removeFormat"),document.execCommand("delete")}function h(){if(o()){var a=window.getSelection();0<a.rangeCount&&(l.current=window.getSelection().getRangeAt(0)),s.fireSelectionChanged()}}function i(){var b=j();b!==w&&(x(b),a.save(b))}function j(){var a=k.current.innerHTML;if(0<s.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=s.serialize(b.body)}return a}var k=b.useRef(null),l=b.useRef(null),m=g(),o=m.isFocused,p=m.setFocused,s=b.useContext(q),t=b.useRef(r++),u=b.useState(a.initialHTML),v=c(u,2),w=v[0],x=v[1];return d&&(d.current={setHTML(a){f(),k.current.innerHTML=a,k.current.focus(),s.fireNewHTML()},resetEditor(){d.current.setHTML("")},getHTML:j}),b.useEffect(()=>{if(a.pasteFn)return k.current.addEventListener("paste",e),()=>k.current.removeEventListener("paste",e)},[a.pasteFn]),b.useEffect(()=>(document.addEventListener("selectionchange",h),()=>document.removeEventListener("selectionchange",h))),b.useEffect(()=>{if(a.save&&a.unchangedInterval&&k.current&&o()){var b,c=new MutationObserver(()=>{clearTimeout(b),b=setTimeout(i,a.unchangedInterval)});return c.observe(k.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{c.disconnect(),clearTimeout(b)}}},[a.unchangedInterval,a.save,k.current,o()]),b.useEffect(()=>{if(!1===o()){var a=setTimeout(()=>{s.fireBlur(),i()},100);return()=>{clearTimeout(a)}}},[o()]),b.useEffect(()=>{s.selectRangeFromBeforeBlur=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{usePreviousRange:!1};if(k.current&&document.activeElement!==k.current&&!k.current.contains(document.activeElement)){if(a.usePreviousRange&&l.current){var b=window.getSelection();b.removeAllRanges(),b.addRange(l.current)}else k.current.focus();p(!0),setTimeout(h)}},s.getRangeFromBeforeBlur=()=>l.current,s.isFocused=o,s.getContentEditableElement=()=>k.current}),b.useEffect(()=>{a.initialHTML&&(k.current.innerHTML=a.initialHTML,s.fireNewHTML())},[]),b.useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${t.current}:empty:not(:focus):before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,t.current]),n.createElement("div",{contentEditable:!0,onBlur:()=>p(!1),onFocus:function(){p(!0);var a=window.getSelection();0<a.rangeCount&&(l.current=a.getRangeAt(0))},ref:k,className:a.className+" bandicoot-id-"+t.current,style:{wordBreak:"break-all"},"data-placeholder":a.placeholder})});s.defaultProps={className:"",initialHTML:"",save:()=>{},placeholder:"",placeholderColor:"#CFCFCF",pasteFn:null};var t={isActive:!1,value:!1},u=()=>{},v={processImgElement:u,fileBlobToUrl:i},w=0,x=()=>{},y={processAnchorElement:x},z=0,A=()=>{},B={processContentEditableFalseElement:A},C=()=>{},D={processSerializedElement:C};a.RichTextEditor=s,a.RichTextContainer=function(a){var c=b.useRef(Object.assign({},p)),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),n.createElement(q.Provider,{value:d},a.children)},a.RichTextContext=q,a.useDocumentExecCommand=h,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(t)}var f=b.useState(t),g=c(f,2),h=g[0],i=g[1],j=b.useContext(q);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 g=b.useState(e),i=c(g,2),j=i[0],k=i[1],l=h("fontSize"),m=l.performCommandWithValue,n=b.useContext(q),o=function(){return b.useEffect(()=>{function a(){var a=window.getSelection();if(0<a.rangeCount){var 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]:v,d=c.processImgElement,e=void 0===d?u:d,f=c.fileBlobToUrl,g=void 0===f?i:f,j=h("insertImage"),k=j.performCommandWithValue,l=b.useContext(q),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=>{k(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-${w++}`;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]:y,d=c.processAnchorElement,e=void 0===d?x:d,f=b.useContext(q),g=h("unlink"),i=g.performCommand,j=h("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",()=>j(a)),!a.previousSibling&&a.parentElement===i.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===i.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}j(a),e(a)}var c=0<arguments.length&&arguments[0]!==void 0?arguments[0]:B,d=c.processContentEditableFalseElement,e=void 0===d?A:d,f=h("insertHTML"),g=f.performCommandWithValue,i=b.useContext(q);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+z++;g(`<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]:D,c=a.processSerializedElement,d=void 0===c?C:c,e=h("insertImage"),f=e.performCommandWithValue,g=b.useContext(q);return function(){b.useEffect(()=>{function a(){for(var a=g.getContentEditableElement().querySelectorAll("span[data-text-as-image]"),b=0;b<a.length;b++){var c=a[b],d=k(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement),e=document.createElement("img");e.src=d,l(e,c.dataset.textAsImage),c.parentNode.replaceChild(e,c)}}return g.addNewHTMLListener(a),()=>g.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 g.addSerializer(a),()=>g.removeSerializer(a)},[])}(),{insertTextAsImage(a){g.selectRangeFromBeforeBlur({usePreviousRange:!0});var b=k(a,m());f(b);var c=document.querySelector(`img[src="${b}"]`);l(c,a)}}},a.useElementDeletionDetection=function(a,c){var d=b.useContext(q);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(){var a=b.useRef(null),d=b.useState(!1),e=c(d,2),f=e[0],g=e[1];return{isFocused:function(){return a.current},setFocused:function(b){a.current=b,g(!f)}}}function h(a){var c=b.useContext(q);return{performCommand(){c.selectRangeFromBeforeBlur(),document.execCommand(a)},performCommandWithValue(b){c.selectRangeFromBeforeBlur();document.execCommand(a,null,b)}}}function i(a,b){b(URL.createObjectURL(a))}function j(a){var b=document.createRange();b.setStartAfter(a);var c=window.getSelection();c.removeAllRanges(),c.addRange(b)}function k(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 l(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 m(){var a=getSelection().getRangeAt(0).commonAncestorContainer;return 1===a.nodeType?a:a.parentElement}var n="default"in b?b["default"]:b,o=()=>{},p={addSelectionChangedListener:o,removeSelectionChangedListener:o,fireSelectionChanged:o,selectRangeFromBeforeBlur:o,getRangeBeforeBlur:o,addBlurListener:o,removeBlurListener:o,fireBlur:o,addNewHTMLListener:o,removeNewHTMLListener:o,fireNewHTML:o,isFocused:o,getContentEditableElement:o,numSerializers:()=>0,addSerializer:o,removeSerializer:o,serialize:o},q=n.createContext(p),r=0,s=b.forwardRef((a,d)=>{function e(b){b.preventDefault(),b.stopPropagation();var c=(window.clipboardData||b.clipboardData).getData("text/html"),d=a.pasteFn(c),e=window.getSelection();if(!e.rangeCount)return!1;var f=document.createRange().createContextualFragment(d),g=e.getRangeAt(0);g.deleteContents(),g.insertNode(f)}function f(){var a=document.createRange();a.selectNodeContents(k.current);var b=window.getSelection();b.removeAllRanges(),b.addRange(a),document.execCommand("removeFormat"),document.execCommand("delete")}function h(){if(o()){var a=window.getSelection();0<a.rangeCount&&(l.current=window.getSelection().getRangeAt(0)),s.fireSelectionChanged()}}function i(){var b=j();b!==w&&(x(b),a.save(b))}function j(){var a=k.current.innerHTML;if(0<s.numSerializers()){var b=new DOMParser().parseFromString(a,"text/html");a=s.serialize(b.body)}return a}var k=b.useRef(null),l=b.useRef(null),m=g(),o=m.isFocused,p=m.setFocused,s=b.useContext(q),t=b.useRef(r++),u=b.useState(a.initialHTML),v=c(u,2),w=v[0],x=v[1];return d&&(d.current={setHTML(a){f(),k.current.innerHTML=a,k.current.focus(),s.fireNewHTML()},resetEditor(){d.current.setHTML("")},getHTML:j}),b.useEffect(()=>{if(a.pasteFn)return k.current.addEventListener("paste",e),()=>k.current.removeEventListener("paste",e)},[a.pasteFn]),b.useEffect(()=>(document.addEventListener("selectionchange",h),()=>document.removeEventListener("selectionchange",h))),b.useEffect(()=>{if(a.save&&a.unchangedInterval&&k.current&&o()){var b,c=new MutationObserver(()=>{clearTimeout(b),b=setTimeout(i,a.unchangedInterval)});return c.observe(k.current,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),()=>{c.disconnect(),clearTimeout(b)}}},[a.unchangedInterval,a.save,k.current,o()]),b.useEffect(()=>{if(!1===o()){var a=setTimeout(()=>{s.fireBlur(),i()},100);return()=>{clearTimeout(a)}}},[o()]),b.useEffect(()=>{s.selectRangeFromBeforeBlur=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{usePreviousRange:!1};if(k.current&&document.activeElement!==k.current&&!k.current.contains(document.activeElement)){if(a.usePreviousRange&&l.current){var b=window.getSelection();b.removeAllRanges(),b.addRange(l.current)}else k.current.focus();p(!0),setTimeout(h)}},s.getRangeFromBeforeBlur=()=>l.current,s.isFocused=o,s.getContentEditableElement=()=>k.current}),b.useEffect(()=>{a.initialHTML&&(k.current.innerHTML=a.initialHTML,s.fireNewHTML())},[]),b.useEffect(()=>{if(a.placeholder){var b=document.createElement("style");return b.textContent=`.bandicoot-id-${t.current}:empty:not(:focus):before { content: attr(data-placeholder); color: ${a.placeholderColor}; }`,document.head.appendChild(b),()=>b.parentNode.removeChild(b)}},[a.placeholder,a.placeholderColor,t.current]),n.createElement("div",{contentEditable:!0,onBlur:()=>p(!1),onFocus:function(){p(!0);var a=window.getSelection();0<a.rangeCount&&(l.current=a.getRangeAt(0))},ref:k,className:a.className+" bandicoot-id-"+t.current,style:{wordBreak:"break-all"},"data-placeholder":a.placeholder})});s.defaultProps={className:"",initialHTML:"",save:()=>{},placeholder:"",placeholderColor:"#CFCFCF",pasteFn:null};var t={isActive:!1,value:!1},u=()=>{},v={processImgElement:u,fileBlobToUrl:i},w=0,x=()=>{},y={processAnchorElement:x},z=0,A=()=>{},B={processContentEditableFalseElement:A},C=()=>{},D={processSerializedElement:C};a.RichTextEditor=s,a.RichTextContainer=function(a){var c=b.useRef(Object.assign({},p)),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),n.createElement(q.Provider,{value:d},a.children)},a.RichTextContext=q,a.useDocumentExecCommand=h,a.useFormatBlock=function(){var a=h("formatBlock"),b=a.performCommandWithValue;return{formatBlock(a){a===document.queryCommandValue("formatBlock")?b("div"):b(a)}}},a.useDocumentQueryCommandState=function(a,d){function e(){var b=document.queryCommandValue(a),c=d?d===b:document.queryCommandState(a);(c!==i.isActive||b!==i.value)&&j({isActive:c,value:b})}function f(){j(t)}var g=b.useState(t),h=c(g,2),i=h[0],j=h[1],k=b.useContext(q);return b.useEffect(()=>(k.addSelectionChangedListener(e),()=>k.removeSelectionChangedListener(e)),[i,j]),b.useEffect(()=>(k.addBlurListener(f),()=>k.removeBlurListener(f)),[i,j]),{isActive:i.isActive,activeValue:i.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 g=b.useState(e),i=c(g,2),j=i[0],k=i[1],l=h("fontSize"),m=l.performCommandWithValue,n=b.useContext(q),o=function(){return b.useEffect(()=>{function a(){var a=window.getSelection();if(0<a.rangeCount){var 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]:v,d=c.processImgElement,e=void 0===d?u:d,f=c.fileBlobToUrl,g=void 0===f?i:f,j=h("insertImage"),k=j.performCommandWithValue,l=b.useContext(q),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=>{k(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-${w++}`;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]:y,d=c.processAnchorElement,e=void 0===d?x:d,f=b.useContext(q),g=h("unlink"),i=g.performCommand,j=h("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",()=>j(a)),!a.previousSibling&&a.parentElement===i.getContentEditableElement()){var b=document.createElement("span");a.parentElement.insertBefore(b,a)}if(!a.nextSibling&&a.parentElement===i.getContentEditableElement()){var c=document.createElement("span");a.insertAdjacentElement("afterend",c)}j(a),e(a)}var c=0<arguments.length&&arguments[0]!==void 0?arguments[0]:B,d=c.processContentEditableFalseElement,e=void 0===d?A:d,f=h("insertHTML"),g=f.performCommandWithValue,i=b.useContext(q);return{insertContentEditableFalseElement(b){var c="rte-ce-false-temp-id-"+z++;g(`<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]:D,c=a.processSerializedElement,d=void 0===c?C:c,e=h("insertImage"),f=e.performCommandWithValue,g=b.useContext(q);return function(){b.useEffect(()=>{function a(){for(var a=g.getContentEditableElement().querySelectorAll("span[data-text-as-image]"),b=0;b<a.length;b++){var c=a[b],d=k(c.dataset.textAsImage,c.previousElementSibling||c.nextElementSibling||c.parentElement),e=document.createElement("img");e.src=d,l(e,c.dataset.textAsImage),c.parentNode.replaceChild(e,c)}}return g.addNewHTMLListener(a),()=>g.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 g.addSerializer(a),()=>g.removeSerializer(a)},[])}(),{insertTextAsImage(a){g.selectRangeFromBeforeBlur({usePreviousRange:!0});var b=k(a,m());f(b);var c=document.querySelector(`img[src="${b}"]`);l(c,a)}}},a.useElementDeletionDetection=function(a,c){var d=b.useContext(q);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.4.2",
"version": "2.5.0",
"description": "React rich text editor",

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

export {RichTextEditor} from './rich-text-editor.component.js'
export {RichTextContainer, RichTextContext} from './rich-text-container.component.js'
export {useDocumentExecCommand} from './use-document-exec-command.hook.js'
export {useFormatBlock} from './use-format-block.hook'
export {useDocumentQueryCommandState} from './use-document-query-command-state.hook.js'

@@ -5,0 +6,0 @@ export {useFontSize} from './use-font-size.hook.js'

@@ -34,8 +34,10 @@ import React, {useState, useEffect, useRef, useContext, forwardRef} from 'react'

event.stopPropagation()
let paste = (window.clipboardData || event.clipboardData).getData('text/html');
let paste = (window.clipboardData || event.clipboardData).getData('text/html')
let newPaste = props.pasteFn(paste)
const selection = window.getSelection();
if (!selection.rangeCount) return false;
const selection = window.getSelection()
if (!selection.rangeCount) return false
const pasteToDOMNode = document.createRange().createContextualFragment(newPaste)
selection.getRangeAt(0).insertNode(pasteToDOMNode);
const range = selection.getRangeAt(0)
range.deleteContents()
range.insertNode(pasteToDOMNode)
}

@@ -42,0 +44,0 @@

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

export function useDocumentQueryCommandState(commandName) {
export function useDocumentQueryCommandState(commandName, activeValueMatch) {
const [activeInfo, setActiveInfo] = useState(defaultActiveInfo)

@@ -22,4 +22,5 @@ const richTextContext = useContext(RichTextContext)

function recheckActive() {
const isActuallyActive = document.queryCommandState(commandName)
const actualActiveValue = document.queryCommandValue(commandName)
const isActuallyActive = activeValueMatch ? activeValueMatch === actualActiveValue : document.queryCommandState(commandName)
if (isActuallyActive !== activeInfo.isActive || actualActiveValue !== activeInfo.value) {

@@ -26,0 +27,0 @@ setActiveInfo({

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