@yoopta/image 1.9.11-rc → 1.9.12-rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1468 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1,1468 @@
|
|
|
1
|
-
import{getElementClassname as t,UI_HELPERS as e,cx as i,createYooptaPlugin as o,getElementByPath as n,generateId as s}from"@yoopta/editor";import{Transforms as r,Element as a}from"slate";import{jsx as h,jsxs as d}from"react/jsx-runtime";import*as l from"react";import{useState as p,useRef as c,useEffect as u,useMemo as g}from"react";import{flushSync as m}from"react-dom";import{ReactEditor as f,useSelected as v,useReadOnly as b}from"slate-react";function w(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&o.firstChild?o.insertBefore(n,o.firstChild):o.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}var y="qpZJDBGn",x="uotJ3YDO",z="nbRzyNn-",S="w4fOLmqq";w(".qpZJDBGn{margin:20px 0 10px;position:relative}.uotJ3YDO{border-radius:1px;display:block;margin:0 auto;max-width:100%;object-fit:cover;pointer-events:auto}.nbRzyNn-{height:100%;margin:0}.w4fOLmqq{caret-color:#37352f;color:rgba(55,53,47,.65);font-size:14px;line-height:1.4;max-width:100%;padding-bottom:6px;padding-left:2px;padding-top:6px;white-space:pre-wrap;width:100%;word-break:break-word}");var O,N,R=(O=function(t,e){return O=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},O(t,e)},function(t,e){function i(){this.constructor=t}O(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),W=function(){return W=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},W.apply(this,arguments)},j={width:"100%",height:"10px",top:"0px",left:"0px",cursor:"row-resize"},E={width:"10px",height:"100%",top:"0px",left:"0px",cursor:"col-resize"},k={width:"20px",height:"20px",position:"absolute"},M={top:W(W({},j),{top:"-5px"}),right:W(W({},E),{left:void 0,right:"-5px"}),bottom:W(W({},j),{top:void 0,bottom:"-5px"}),left:W(W({},E),{left:"-5px"}),topRight:W(W({},k),{right:"-10px",top:"-10px",cursor:"ne-resize"}),bottomRight:W(W({},k),{right:"-10px",bottom:"-10px",cursor:"se-resize"}),bottomLeft:W(W({},k),{left:"-10px",bottom:"-10px",cursor:"sw-resize"}),topLeft:W(W({},k),{left:"-10px",top:"-10px",cursor:"nw-resize"})},A=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.onMouseDown=function(t){e.props.onResizeStart(t,e.props.direction)},e.onTouchStart=function(t){e.props.onResizeStart(t,e.props.direction)},e}return R(e,t),e.prototype.render=function(){return l.createElement("div",{className:this.props.className||"",style:W(W({position:"absolute",userSelect:"none"},M[this.props.direction]),this.props.replaceStyles||{}),onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart},this.props.children)},e}(l.PureComponent),C=function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){function o(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}}(),H=function(){return H=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},H.apply(this,arguments)},P={width:"auto",height:"auto"},B=function(t,e,i){return Math.max(Math.min(t,i),e)},L=function(t,e){return Math.round(t/e)*e},T=function(t,e){return new RegExp(t,"i").test(e)},D=function(t){return Boolean(t.touches&&t.touches.length)},_=function(t,e,i){void 0===i&&(i=0);var o=e.reduce((function(i,o,n){return Math.abs(o-t)<Math.abs(e[i]-t)?n:i}),0),n=Math.abs(e[o]-t);return 0===i||n<i?e[o]:t},F=function(t){return"auto"===(t=t.toString())||t.endsWith("px")||t.endsWith("%")||t.endsWith("vh")||t.endsWith("vw")||t.endsWith("vmax")||t.endsWith("vmin")?t:t+"px"},Y=function(t,e,i,o){if(t&&"string"==typeof t){if(t.endsWith("px"))return Number(t.replace("px",""));if(t.endsWith("%"))return e*(Number(t.replace("%",""))/100);if(t.endsWith("vw"))return i*(Number(t.replace("vw",""))/100);if(t.endsWith("vh"))return o*(Number(t.replace("vh",""))/100)}return t},U=["as","style","className","grid","snap","bounds","boundsByDirection","size","defaultSize","minWidth","minHeight","maxWidth","maxHeight","lockAspectRatio","lockAspectRatioExtraWidth","lockAspectRatioExtraHeight","enable","handleStyles","handleClasses","handleWrapperStyle","handleWrapperClass","children","onResizeStart","onResize","onResizeStop","handleComponent","scale","resizeRatio","snapGap"],G="__resizable_base__",I=function(t){function e(e){var i=t.call(this,e)||this;return i.ratio=1,i.resizable=null,i.parentLeft=0,i.parentTop=0,i.resizableLeft=0,i.resizableRight=0,i.resizableTop=0,i.resizableBottom=0,i.targetLeft=0,i.targetTop=0,i.appendBase=function(){if(!i.resizable||!i.window)return null;var t=i.parentNode;if(!t)return null;var e=i.window.document.createElement("div");return e.style.width="100%",e.style.height="100%",e.style.position="absolute",e.style.transform="scale(0, 0)",e.style.left="0",e.style.flex="0 0 100%",e.classList?e.classList.add(G):e.className+=G,t.appendChild(e),e},i.removeBase=function(t){var e=i.parentNode;e&&e.removeChild(t)},i.ref=function(t){t&&(i.resizable=t)},i.state={isResizing:!1,width:void 0===(i.propsSize&&i.propsSize.width)?"auto":i.propsSize&&i.propsSize.width,height:void 0===(i.propsSize&&i.propsSize.height)?"auto":i.propsSize&&i.propsSize.height,direction:"right",original:{x:0,y:0,width:0,height:0},backgroundStyle:{height:"100%",width:"100%",backgroundColor:"rgba(0,0,0,0)",cursor:"auto",opacity:0,position:"fixed",zIndex:9999,top:"0",left:"0",bottom:"0",right:"0"},flexBasis:void 0},i.onResizeStart=i.onResizeStart.bind(i),i.onMouseMove=i.onMouseMove.bind(i),i.onMouseUp=i.onMouseUp.bind(i),i}return C(e,t),Object.defineProperty(e.prototype,"parentNode",{get:function(){return this.resizable?this.resizable.parentNode:null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"window",{get:function(){return this.resizable&&this.resizable.ownerDocument?this.resizable.ownerDocument.defaultView:null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"propsSize",{get:function(){return this.props.size||this.props.defaultSize||P},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){var t=0,e=0;if(this.resizable&&this.window){var i=this.resizable.offsetWidth,o=this.resizable.offsetHeight,n=this.resizable.style.position;"relative"!==n&&(this.resizable.style.position="relative"),t="auto"!==this.resizable.style.width?this.resizable.offsetWidth:i,e="auto"!==this.resizable.style.height?this.resizable.offsetHeight:o,this.resizable.style.position=n}return{width:t,height:e}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeStyle",{get:function(){var t=this,e=this.props.size,i=function(e){if(void 0===t.state[e]||"auto"===t.state[e])return"auto";if(t.propsSize&&t.propsSize[e]&&t.propsSize[e].toString().endsWith("%")){if(t.state[e].toString().endsWith("%"))return t.state[e].toString();var i=t.getParentSize();return Number(t.state[e].toString().replace("px",""))/i[e]*100+"%"}return F(t.state[e])};return{width:e&&void 0!==e.width&&!this.state.isResizing?F(e.width):i("width"),height:e&&void 0!==e.height&&!this.state.isResizing?F(e.height):i("height")}},enumerable:!1,configurable:!0}),e.prototype.getParentSize=function(){if(!this.parentNode)return this.window?{width:this.window.innerWidth,height:this.window.innerHeight}:{width:0,height:0};var t=this.appendBase();if(!t)return{width:0,height:0};var e=!1,i=this.parentNode.style.flexWrap;"wrap"!==i&&(e=!0,this.parentNode.style.flexWrap="wrap"),t.style.position="relative",t.style.minWidth="100%",t.style.minHeight="100%";var o={width:t.offsetWidth,height:t.offsetHeight};return e&&(this.parentNode.style.flexWrap=i),this.removeBase(t),o},e.prototype.bindEvents=function(){this.window&&(this.window.addEventListener("mouseup",this.onMouseUp),this.window.addEventListener("mousemove",this.onMouseMove),this.window.addEventListener("mouseleave",this.onMouseUp),this.window.addEventListener("touchmove",this.onMouseMove,{capture:!0,passive:!1}),this.window.addEventListener("touchend",this.onMouseUp))},e.prototype.unbindEvents=function(){this.window&&(this.window.removeEventListener("mouseup",this.onMouseUp),this.window.removeEventListener("mousemove",this.onMouseMove),this.window.removeEventListener("mouseleave",this.onMouseUp),this.window.removeEventListener("touchmove",this.onMouseMove,!0),this.window.removeEventListener("touchend",this.onMouseUp))},e.prototype.componentDidMount=function(){if(this.resizable&&this.window){var t=this.window.getComputedStyle(this.resizable);this.setState({width:this.state.width||this.size.width,height:this.state.height||this.size.height,flexBasis:"auto"!==t.flexBasis?t.flexBasis:void 0})}},e.prototype.componentWillUnmount=function(){this.window&&this.unbindEvents()},e.prototype.createSizeForCssProperty=function(t,e){var i=this.propsSize&&this.propsSize[e];return"auto"!==this.state[e]||this.state.original[e]!==t||void 0!==i&&"auto"!==i?t:"auto"},e.prototype.calculateNewMaxFromBoundary=function(t,e){var i,o,n=this.props.boundsByDirection,s=this.state.direction,r=n&&T("left",s),a=n&&T("top",s);if("parent"===this.props.bounds){var h=this.parentNode;h&&(i=r?this.resizableRight-this.parentLeft:h.offsetWidth+(this.parentLeft-this.resizableLeft),o=a?this.resizableBottom-this.parentTop:h.offsetHeight+(this.parentTop-this.resizableTop))}else"window"===this.props.bounds?this.window&&(i=r?this.resizableRight:this.window.innerWidth-this.resizableLeft,o=a?this.resizableBottom:this.window.innerHeight-this.resizableTop):this.props.bounds&&(i=r?this.resizableRight-this.targetLeft:this.props.bounds.offsetWidth+(this.targetLeft-this.resizableLeft),o=a?this.resizableBottom-this.targetTop:this.props.bounds.offsetHeight+(this.targetTop-this.resizableTop));return i&&Number.isFinite(i)&&(t=t&&t<i?t:i),o&&Number.isFinite(o)&&(e=e&&e<o?e:o),{maxWidth:t,maxHeight:e}},e.prototype.calculateNewSizeFromDirection=function(t,e){var i=this.props.scale||1,o=this.props.resizeRatio||1,n=this.state,s=n.direction,r=n.original,a=this.props,h=a.lockAspectRatio,d=a.lockAspectRatioExtraHeight,l=a.lockAspectRatioExtraWidth,p=r.width,c=r.height,u=d||0,g=l||0;return T("right",s)&&(p=r.width+(t-r.x)*o/i,h&&(c=(p-g)/this.ratio+u)),T("left",s)&&(p=r.width-(t-r.x)*o/i,h&&(c=(p-g)/this.ratio+u)),T("bottom",s)&&(c=r.height+(e-r.y)*o/i,h&&(p=(c-u)*this.ratio+g)),T("top",s)&&(c=r.height-(e-r.y)*o/i,h&&(p=(c-u)*this.ratio+g)),{newWidth:p,newHeight:c}},e.prototype.calculateNewSizeFromAspectRatio=function(t,e,i,o){var n=this.props,s=n.lockAspectRatio,r=n.lockAspectRatioExtraHeight,a=n.lockAspectRatioExtraWidth,h=void 0===o.width?10:o.width,d=void 0===i.width||i.width<0?t:i.width,l=void 0===o.height?10:o.height,p=void 0===i.height||i.height<0?e:i.height,c=r||0,u=a||0;if(s){var g=(l-c)*this.ratio+u,m=(p-c)*this.ratio+u,f=(h-u)/this.ratio+c,v=(d-u)/this.ratio+c,b=Math.max(h,g),w=Math.min(d,m),y=Math.max(l,f),x=Math.min(p,v);t=B(t,b,w),e=B(e,y,x)}else t=B(t,h,d),e=B(e,l,p);return{newWidth:t,newHeight:e}},e.prototype.setBoundingClientRect=function(){if("parent"===this.props.bounds){var t=this.parentNode;if(t){var e=t.getBoundingClientRect();this.parentLeft=e.left,this.parentTop=e.top}}if(this.props.bounds&&"string"!=typeof this.props.bounds){var i=this.props.bounds.getBoundingClientRect();this.targetLeft=i.left,this.targetTop=i.top}if(this.resizable){var o=this.resizable.getBoundingClientRect(),n=o.left,s=o.top,r=o.right,a=o.bottom;this.resizableLeft=n,this.resizableRight=r,this.resizableTop=s,this.resizableBottom=a}},e.prototype.onResizeStart=function(t,e){if(this.resizable&&this.window){var i,o=0,n=0;if(t.nativeEvent&&function(t){return Boolean((t.clientX||0===t.clientX)&&(t.clientY||0===t.clientY))}(t.nativeEvent)?(o=t.nativeEvent.clientX,n=t.nativeEvent.clientY):t.nativeEvent&&D(t.nativeEvent)&&(o=t.nativeEvent.touches[0].clientX,n=t.nativeEvent.touches[0].clientY),this.props.onResizeStart)if(this.resizable)if(!1===this.props.onResizeStart(t,e,this.resizable))return;this.props.size&&(void 0!==this.props.size.height&&this.props.size.height!==this.state.height&&this.setState({height:this.props.size.height}),void 0!==this.props.size.width&&this.props.size.width!==this.state.width&&this.setState({width:this.props.size.width})),this.ratio="number"==typeof this.props.lockAspectRatio?this.props.lockAspectRatio:this.size.width/this.size.height;var s=this.window.getComputedStyle(this.resizable);if("auto"!==s.flexBasis){var r=this.parentNode;if(r){var a=this.window.getComputedStyle(r).flexDirection;this.flexDir=a.startsWith("row")?"row":"column",i=s.flexBasis}}this.setBoundingClientRect(),this.bindEvents();var h={original:{x:o,y:n,width:this.size.width,height:this.size.height},isResizing:!0,backgroundStyle:H(H({},this.state.backgroundStyle),{cursor:this.window.getComputedStyle(t.target).cursor||"auto"}),direction:e,flexBasis:i};this.setState(h)}},e.prototype.onMouseMove=function(t){var e=this;if(this.state.isResizing&&this.resizable&&this.window){if(this.window.TouchEvent&&D(t))try{t.preventDefault(),t.stopPropagation()}catch(t){}var i=this.props,o=i.maxWidth,n=i.maxHeight,s=i.minWidth,r=i.minHeight,a=D(t)?t.touches[0].clientX:t.clientX,h=D(t)?t.touches[0].clientY:t.clientY,d=this.state,l=d.direction,p=d.original,c=d.width,u=d.height,g=this.getParentSize(),f=function(t,e,i,o,n,s,r){return o=Y(o,t.width,e,i),n=Y(n,t.height,e,i),s=Y(s,t.width,e,i),r=Y(r,t.height,e,i),{maxWidth:void 0===o?void 0:Number(o),maxHeight:void 0===n?void 0:Number(n),minWidth:void 0===s?void 0:Number(s),minHeight:void 0===r?void 0:Number(r)}}(g,this.window.innerWidth,this.window.innerHeight,o,n,s,r);o=f.maxWidth,n=f.maxHeight,s=f.minWidth,r=f.minHeight;var v=this.calculateNewSizeFromDirection(a,h),b=v.newHeight,w=v.newWidth,y=this.calculateNewMaxFromBoundary(o,n);this.props.snap&&this.props.snap.x&&(w=_(w,this.props.snap.x,this.props.snapGap)),this.props.snap&&this.props.snap.y&&(b=_(b,this.props.snap.y,this.props.snapGap));var x=this.calculateNewSizeFromAspectRatio(w,b,{width:y.maxWidth,height:y.maxHeight},{width:s,height:r});if(w=x.newWidth,b=x.newHeight,this.props.grid){var z=L(w,this.props.grid[0]),S=L(b,this.props.grid[1]),O=this.props.snapGap||0;w=0===O||Math.abs(z-w)<=O?z:w,b=0===O||Math.abs(S-b)<=O?S:b}var N={width:w-p.width,height:b-p.height};if(c&&"string"==typeof c)if(c.endsWith("%"))w=w/g.width*100+"%";else if(c.endsWith("vw")){w=w/this.window.innerWidth*100+"vw"}else if(c.endsWith("vh")){w=w/this.window.innerHeight*100+"vh"}if(u&&"string"==typeof u)if(u.endsWith("%"))b=b/g.height*100+"%";else if(u.endsWith("vw")){b=b/this.window.innerWidth*100+"vw"}else if(u.endsWith("vh")){b=b/this.window.innerHeight*100+"vh"}var R={width:this.createSizeForCssProperty(w,"width"),height:this.createSizeForCssProperty(b,"height")};"row"===this.flexDir?R.flexBasis=R.width:"column"===this.flexDir&&(R.flexBasis=R.height),m((function(){e.setState(R)})),this.props.onResize&&this.props.onResize(t,l,this.resizable,N)}},e.prototype.onMouseUp=function(t){var e=this.state,i=e.isResizing,o=e.direction,n=e.original;if(i&&this.resizable){var s={width:this.size.width-n.width,height:this.size.height-n.height};this.props.onResizeStop&&this.props.onResizeStop(t,o,this.resizable,s),this.props.size&&this.setState(this.props.size),this.unbindEvents(),this.setState({isResizing:!1,backgroundStyle:H(H({},this.state.backgroundStyle),{cursor:"auto"})})}},e.prototype.updateSize=function(t){this.setState({width:t.width,height:t.height})},e.prototype.renderResizer=function(){var t=this,e=this.props,i=e.enable,o=e.handleStyles,n=e.handleClasses,s=e.handleWrapperStyle,r=e.handleWrapperClass,a=e.handleComponent;if(!i)return null;var h=Object.keys(i).map((function(e){return!1!==i[e]?l.createElement(A,{key:e,direction:e,onResizeStart:t.onResizeStart,replaceStyles:o&&o[e],className:n&&n[e]},a&&a[e]?a[e]:null):null}));return l.createElement("div",{className:r,style:s},h)},e.prototype.render=function(){var t=this,e=Object.keys(this.props).reduce((function(e,i){return-1!==U.indexOf(i)||(e[i]=t.props[i]),e}),{}),i=H(H(H({position:"relative",userSelect:this.state.isResizing?"none":"auto"},this.props.style),this.sizeStyle),{maxWidth:this.props.maxWidth,maxHeight:this.props.maxHeight,minWidth:this.props.minWidth,minHeight:this.props.minHeight,boxSizing:"border-box",flexShrink:0});this.state.flexBasis&&(i.flexBasis=this.state.flexBasis);var o=this.props.as||"div";return l.createElement(o,H({ref:this.ref,style:i,className:this.props.className},e),this.state.isResizing&&l.createElement("div",{style:this.state.backgroundStyle}),this.props.children,this.renderResizer())},e.defaultProps={as:"div",onResizeStart:function(){},onResize:function(){},onResizeStop:function(){},enable:{top:!0,right:!0,bottom:!0,left:!0,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},style:{},grid:[1,1],lockAspectRatio:!1,lockAspectRatioExtraWidth:0,lockAspectRatioExtraHeight:0,scale:1,resizeRatio:1,snapGap:0},e}(l.PureComponent);function Q(t,e,i,o){return new(i||(i=Promise))((function(n,s){function r(t){try{h(o.next(t))}catch(t){s(t)}}function a(t){try{h(o.throw(t))}catch(t){s(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((o=o.apply(t,e||[])).next())}))}function X(){return X=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},X.apply(this,arguments)}var q=function(t){return l.createElement("svg",X({fill:"currentColor","aria-hidden":"true",viewBox:"0 0 24 24","data-testid":"uploadImage"},t),N||(N=l.createElement("path",{d:"M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"})))},V="CbnZQqyl",Z="_78mDlVh1",K="oZAAa6di",J="tLysgc7u",$="_1TmPKlXh",tt="LZ2yXrRk",et="_7ZO4VxhR",it="_71hAm-SR _7ZO4VxhR",ot="gZazwh5A",nt="woGPvDjG",st="DjdM6pfv",rt="xlH5R22X";w('.CbnZQqyl{position:fixed}._78mDlVh1{background:#fff;box-shadow:0 0 0 1px hsla(0,0%,6%,.05),0 3px 6px hsla(0,0%,6%,.1),0 9px 24px hsla(0,0%,6%,.2);display:flex;flex-direction:column;height:100%;max-height:420px;max-width:calc(100vw - 24px);min-width:540px}.oZAAa6di{box-shadow:inset 0 -1px 0 rgba(55,53,47,.09);display:flex;height:40px;padding:0 8px;width:100%;z-index:1}.oZAAa6di,.tLysgc7u{font-size:14px;position:relative}.tLysgc7u{align-items:center;background-color:inherit;border:none;border-radius:4px;color:#37352f;cursor:pointer;display:inline-flex;flex-shrink:0;height:100%;line-height:1.2;min-width:0;padding:6px 8px;transition:height 20ms ease-in 0s;user-select:none;white-space:nowrap}._1TmPKlXh:after{background-color:#37352f;bottom:0;content:"";height:2px;left:0;position:absolute;width:100%}.LZ2yXrRk{display:flex;justify-content:center;margin-left:12px;margin-right:12px;margin-top:4px;padding-bottom:6px;padding-top:6px}._7ZO4VxhR{border:1px solid rgba(55,53,47,.16);border-radius:4px;cursor:pointer;height:32px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap;width:100%}._71hAm-SR{border:none!important;cursor:pointer!important;height:auto!important;padding-left:0!important;padding-right:0!important}.gZazwh5A{align-items:center;cursor:pointer;display:inline-flex;font-size:14px;font-weight:500;height:100%;justify-content:center;line-height:1.2;width:100%}.woGPvDjG{left:0;position:absolute;top:0;visibility:hidden}.DjdM6pfv{background:hsla(45,13%,94%,.6);box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1);cursor:text;height:32px;line-height:20px;padding:3px 6px;position:relative}.DjdM6pfv,.xlH5R22X{align-items:center;border:none;border-radius:4px;display:flex;font-size:14px;width:100%}.xlH5R22X{fill:#fff;background:#2383e2;box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1),0 1px 2px hsla(0,0%,6%,.1);color:#fff;cursor:pointer;flex-shrink:0;font-weight:500;height:28px;justify-content:center;line-height:1.2;margin:12px auto 6px;max-width:300px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap}');const at=({onChange:t,accept:e="image/*"})=>h("div",Object.assign({className:et},{children:d("label",Object.assign({htmlFor:"image-uploader",className:ot},{children:[h("input",{type:"file",id:"image-uploader",className:nt,accept:e,onChange:e=>{const i=e.currentTarget.files;i&&i.length>0&&t(i[0])},multiple:!1}),"Upload image"]}))})),ht=({onEmbed:t})=>{const[e,i]=p("");return d("div",Object.assign({className:it},{children:[h("input",{type:"text",placeholder:"Paste image link",value:e,className:st,onChange:t=>i(t.target.value)}),h("button",Object.assign({type:"button",className:rt,onClick:()=>t(e)},{children:"Embed image"}))]}))},dt=({activeTab:t="upload",style:o,switchTab:n,onChange:s,onEmbed:r,accept:a,onClose:l})=>{const p="upload"===t,c="embed"===t;return d(e.Overlay,Object.assign({onClose:l},{children:[h("div",Object.assign({className:V,style:o},{children:d("div",Object.assign({className:Z},{children:[d("div",Object.assign({className:K},{children:[h("button",Object.assign({type:"button",onClick:()=>n("upload"),className:i(J,{[$]:p})},{children:"Upload"})),h("button",Object.assign({type:"button",onClick:()=>n("embed"),className:i(J,{[$]:c})},{children:"Image link"}))]})),d("div",Object.assign({className:tt},{children:[p&&h(at,{onChange:s,accept:a}),c&&h(ht,{onEmbed:r})]}))]}))})),h("div",{})]}))},lt=(t,e,i,o)=>{if(!t||!e)return{};const n=Math.min(i/t,o/e);return{width:t*n,height:e*n}};var pt=!1;if("undefined"!=typeof window){var ct={get passive(){pt=!0}};window.addEventListener("testPassive",null,ct),window.removeEventListener("testPassive",null,ct)}var ut="undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),gt=[],mt=!1,ft=-1,vt=void 0,bt=void 0,wt=void 0,yt=function(t){return gt.some((function(e){return!(!e.options.allowTouchMove||!e.options.allowTouchMove(t))}))},xt=function(t){var e=t||window.event;return!!yt(e.target)||(e.touches.length>1||(e.preventDefault&&e.preventDefault(),!1))},zt=function(t,e){if(t){if(!gt.some((function(e){return e.targetElement===t}))){var i={targetElement:t,options:e||{}};gt=[].concat(function(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e<t.length;e++)i[e]=t[e];return i}return Array.from(t)}(gt),[i]),ut?window.requestAnimationFrame((function(){if(void 0===bt){bt={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left};var t=window,e=t.scrollY,i=t.scrollX,o=t.innerHeight;document.body.style.position="fixed",document.body.style.top=-e,document.body.style.left=-i,setTimeout((function(){return window.requestAnimationFrame((function(){var t=o-window.innerHeight;t&&e>=o&&(document.body.style.top=-(e+t))}))}),300)}})):function(t){if(void 0===wt){var e=!!t&&!0===t.reserveScrollBarGap,i=window.innerWidth-document.documentElement.clientWidth;if(e&&i>0){var o=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);wt=document.body.style.paddingRight,document.body.style.paddingRight=o+i+"px"}}void 0===vt&&(vt=document.body.style.overflow,document.body.style.overflow="hidden")}(e),ut&&(t.ontouchstart=function(t){1===t.targetTouches.length&&(ft=t.targetTouches[0].clientY)},t.ontouchmove=function(e){1===e.targetTouches.length&&function(t,e){var i=t.targetTouches[0].clientY-ft;!yt(t.target)&&(e&&0===e.scrollTop&&i>0||function(t){return!!t&&t.scrollHeight-t.scrollTop<=t.clientHeight}(e)&&i<0?xt(t):t.stopPropagation())}(e,t)},mt||(document.addEventListener("touchmove",xt,pt?{passive:!1}:void 0),mt=!0))}}else console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.")},St=function(t){t?(gt=gt.filter((function(e){return e.targetElement!==t})),ut&&(t.ontouchstart=null,t.ontouchmove=null,mt&&0===gt.length&&(document.removeEventListener("touchmove",xt,pt?{passive:!1}:void 0),mt=!1)),ut?function(){if(void 0!==bt){var t=-parseInt(document.body.style.top,10),e=-parseInt(document.body.style.left,10);document.body.style.position=bt.position,document.body.style.top=bt.top,document.body.style.left=bt.left,window.scrollTo(e,t),bt=void 0}}():(void 0!==wt&&(document.body.style.paddingRight=wt,wt=void 0),void 0!==vt&&(document.body.style.overflow=vt,vt=void 0))):console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.")},Ot="ohhtqDdT",Nt="S-yQxAMd",Rt="DN1BWl71";function Wt(t){return new Promise(((e,i)=>{const o=new Image;o.src=t,o.onload=()=>e({width:o.width,height:o.height}),o.onerror=t=>i(t)}))}w(".ohhtqDdT{margin:20px 0 10px;user-select:none}.S-yQxAMd,.ohhtqDdT{position:relative;width:100%}.S-yQxAMd{align-items:center;background-color:#efefef;border:none;border-radius:3px;color:rgba(55,53,47,.65);cursor:pointer;display:flex;font-size:14px;overflow:hidden;padding:12px 36px 12px 12px;text-align:left;transition:background-color .1s ease-in}.S-yQxAMd:hover{background-color:#e3e3e3}.DN1BWl71{margin-right:8px;user-select:none}");const jt=({element:t,accept:e,attributes:i,maxSizes:o,children:n,editor:s,onUpload:l})=>{const[u,g]=p(null),[m,v]=p("upload"),b=c(null),w=t=>{var e;if(t.stopPropagation(),null!==u)return St(document.body),void g(null);const i=null===(e=b.current)||void 0===e?void 0:e.getBoundingClientRect();if(i){const t=i.top+i.height+88+20>window.innerHeight,e=!t;console.log({showAtTop:t,showAtBottom:e}),zt(document.body,{reserveScrollBarGap:!0}),g({left:i.left,top:t?i.top-88-5:i.top+i.height+5})}};return d("div",Object.assign({className:Ot},i,{contentEditable:!1},{children:[d("div",Object.assign({ref:b},{children:[d("button",Object.assign({className:Nt,onClick:w},{children:[h(q,{className:Rt,width:24,height:24}),h("span",{children:"Click to add image"})]})),null!==u&&h(dt,{onChange:e=>Q(void 0,void 0,void 0,(function*(){const i=yield function(t){return new Promise(((e,i)=>{const o=new FileReader;o.readAsDataURL(t),o.onload=()=>e(o.result),o.onerror=t=>i(t)}))}(e);i.substring("data:image/".length,i.indexOf(";base64"));const n=yield Wt(i),h=lt(n.width,n.height,o.maxWidth,o.maxHeight);St(document.body),g(null);const d={data:Object.assign(Object.assign({},t.data),{"data-src":i,size:{width:h.width||t.data.size.width,height:h.height||t.data.size.height}})};if(console.log("optimistic image uploader",f.findPath(s,t)),r.setNodes(s,d,{at:f.findPath(s,t),match:t=>a.isElement(t)&&"image"===t.type}),!l)return console.error("Provide `onUpload` handler in Image options");const p=yield l(e),{width:c,height:u}=lt(p.width,p.height,o.maxWidth,o.maxHeight),m={data:Object.assign(Object.assign({},t.data),{url:p.url,"data-src":void 0,size:{width:c||t.data.size.width,height:u||t.data.size.height}})};r.setNodes(s,m,{at:f.findPath(s,t),match:t=>a.isElement(t)&&"image"===t.type})})),onEmbed:e=>Q(void 0,void 0,void 0,(function*(){try{const{width:i,height:o}=yield Wt(e);St(document.body),g(null);const n={data:Object.assign(Object.assign({},t.data),{url:e,"data-src":void 0,size:{width:i,height:o}})};r.setNodes(s,n,{at:f.findPath(s,t),match:t=>a.isElement(t)&&"image"===t.type})}catch(t){St(document.body),g(null)}})),onClose:w,activeTab:m,switchTab:t=>v(t),style:u,accept:e})]})),n]}))};var Et="zpY1mpQ8",kt="pjA59tdv";w(".zpY1mpQ8{height:100%;position:relative;width:100%}.zpY1mpQ8 .pjA59tdv{background-color:#909090;border-radius:5rem;height:10px;position:absolute;top:50%;transform:translate(-50%,-50%);width:10px}.zpY1mpQ8 .pjA59tdv:first-child{animation:OPSfFOxt 2s,_9uGMErwK 2s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% - 60px)}.zpY1mpQ8 .pjA59tdv:nth-child(2){animation:OPSfFOxt 2s,L7daPOmF 2s;animation-delay:.15s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% - 30px)}.zpY1mpQ8 .pjA59tdv:nth-child(3){animation:OPSfFOxt 2s,_9uGMErwK 2s;animation-delay:.3s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:50%}.zpY1mpQ8 .pjA59tdv:nth-child(4){animation:OPSfFOxt 2s,L7daPOmF 2s;animation-delay:.45s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% + 30px)}.zpY1mpQ8 .pjA59tdv:nth-child(5){animation:OPSfFOxt 2s,_9uGMErwK 2s;animation-delay:.6s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% + 60px)}@keyframes OPSfFOxt{0%,15%{top:50%}45%,65%{top:42.5%}85%,to{top:50%}}@keyframes _9uGMErwK{0%,8%{background-color:#909090;height:10px}14%,34%{background-color:#f8f8f8;height:17.5px}46%,to{background-color:#909090;height:10px}}@keyframes L7daPOmF{0%,8%{background-color:#909090;height:10px}14%,34%{background-color:#f8f8f8;height:32.5px}46%,to{background-color:#909090;height:10px}}");const Mt=()=>d("div",Object.assign({className:Et},{children:[h("div",{className:kt}),h("div",{className:kt}),h("div",{className:kt}),h("div",{className:kt}),h("div",{className:kt})]}));var At={root:"CRjYe3V4",resizer:"NWmUovsc",dotsOptions:"namnQRMs",loadingState:"_0b2-YE4H",extraMargin:"SOfqAbJv",resizeLib:"EO3--Gbu",leftResizer:"TN-K0WnG NWmUovsc",rightResizer:"KhDmzJ88 NWmUovsc",resizeItem:"-FTiIzUC",selectImg:"KIB4WerX",selected:"_1Ab-jkHE",loader:"PRWt-7ci",dot:"g9fWS1Hn"};w(".CRjYe3V4{cursor:pointer;display:block;position:relative}.CRjYe3V4:hover .NWmUovsc,.CRjYe3V4:hover .namnQRMs{opacity:1}._0b2-YE4H{pointer-events:none}.SOfqAbJv{margin:20px 0 30px}.EO3--Gbu{margin:0 auto}.NWmUovsc{align-items:center;cursor:col-resize;display:flex;height:100%;justify-content:center;opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;width:15px;z-index:1}.TN-K0WnG{left:0;top:0}.KhDmzJ88{right:0;top:0}.-FTiIzUC{background:hsla(0,0%,6%,.6);border:1px solid hsla(0,0%,100%,.9);border-radius:20px;box-shadow:0 0 0 .5px #fff;height:48px;max-height:50%;opacity:1;transition:opacity .3s ease-in 0s;width:6px}.KIB4WerX{opacity:0}._1Ab-jkHE{background:rgba(35,131,226,.14);border-radius:3px;inset:0;opacity:1;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;z-index:81}.PRWt-7ci{left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}.namnQRMs{align-items:center;background-color:#eee;border:none;border-radius:2px;cursor:pointer;display:flex;height:22px;justify-content:space-between;opacity:0;padding:0 4px;position:absolute;right:10px;top:10px;transition:opacity .15s ease-in 0s;width:22px;z-index:1}.g9fWS1Hn{background-color:gray;border-radius:50%;min-height:3px;min-width:3px}");const Ct=265;function Ht(t){var o,n,s,l,c,m,w,y;const{element:x,editor:z,plugin:S}=t,O=v(),N=b(),[R,W]=p(null),[j,E]=p({width:(null===(n=null===(o=x.data)||void 0===o?void 0:o.size)||void 0===n?void 0:n.width)||750,height:(null===(l=null===(s=x.data)||void 0===s?void 0:s.size)||void 0===l?void 0:l.height)||440});u((()=>{var t,e,i,o;x.data&&E({width:(null===(e=null===(t=x.data)||void 0===t?void 0:t.size)||void 0===e?void 0:e.width)||750,height:(null===(o=null===(i=x.data)||void 0===i?void 0:i.size)||void 0===o?void 0:o.height)||440})}),[null===(c=x.data)||void 0===c?void 0:c.size]);const k=g((()=>{var t,e;return{minWidth:300,size:{width:j.width,height:j.height},maxWidth:(null===(t=S.options)||void 0===t?void 0:t.maxWidth)||800,maxHeight:(null===(e=S.options)||void 0===e?void 0:e.maxHeight)||720,lockAspectRatio:!0,resizeRatio:2,enable:{left:!N,right:!N},handleStyles:{left:{left:0},right:{right:0}},onResize:(t,e,i)=>{E({width:i.offsetWidth,height:i.offsetHeight})},onResizeStop:(t,e,i)=>{r.setNodes(z,{data:Object.assign(Object.assign({},x.data),{size:{width:i.offsetWidth,height:i.offsetHeight}})},{at:f.findPath(z,x),match:t=>a.isElement(t)&&"image"===t.type})},handleComponent:{left:h("div",Object.assign({contentEditable:!1,className:At.leftResizer},{children:h("div",{className:At.resizeItem})})),right:h("div",Object.assign({contentEditable:!1,className:At.rightResizer},{children:h("div",{className:At.resizeItem})}))}}}),[j.width,j.height,z]),M=!!(null===(m=x.data)||void 0===m?void 0:m.caption),A=!!x.data["data-src"]&&!x.data.url,C=()=>{St(document.body),W(null)},H=t=>{var e;if(null==t||t.stopPropagation(),null!==R)return C();const i=null===(e=null==t?void 0:t.currentTarget)||void 0===e?void 0:e.getBoundingClientRect();if(i){const t=i.top+i.height+164+20>window.innerHeight;zt(document.body,{reserveScrollBarGap:!0}),W({left:i.right-i.width+Ct>window.innerWidth?window.innerWidth-Ct-i.width:i.right-i.width,top:t?i.top-82-i.height:i.top+i.height+5})}};if(!x.data.url&&!x.data["data-src"]){const{maxWidth:o=750,maxHeight:n=800}=S.options||{};return d("div",Object.assign({className:At.root,contentEditable:!1,draggable:!1},{children:[h("div",{className:i(At.selectImg,{[At.selected]:O})}),h(jt,Object.assign({attributes:t.attributes,element:x,editor:z,maxSizes:{maxWidth:o,maxHeight:n},onUpload:null===(w=S.options)||void 0===w?void 0:w.onUpload,accept:null===(y=S.options)||void 0===y?void 0:y.accept},{children:!N&&d("div",{children:[d("button",Object.assign({type:"button",className:At.dotsOptions,onClick:H},{children:[h("span",{className:At.dot}),h("span",{className:At.dot}),h("span",{className:At.dot})]})),null!==R&&h(e.ElementOptions,{onClose:C,style:R,element:x,onCopy:C,onDelete:C,onDuplicate:C},x.id)]})})),t.children]}),x.id)}return h("div",Object.assign({contentEditable:!1,draggable:!1,className:i(At.root,{[At.extraMargin]:M,[At.loadingState]:A})},{children:d(I,Object.assign({},k,{className:At.resizeLib},{children:[S.renderer.render(Object.assign(Object.assign({},t),{size:j})),h("div",{className:i(At.selectImg,{[At.selected]:O})}),A&&h("div",Object.assign({className:At.loader},{children:h(Mt,{})})),!N&&d("div",{children:[d("button",Object.assign({type:"button",className:At.dotsOptions,onClick:H},{children:[h("span",{className:At.dot}),h("span",{className:At.dot}),h("span",{className:At.dot})]})),null!==R&&h(e.ElementOptions,{onClose:C,style:R,element:x,onCopy:C,onDelete:C,onDuplicate:C},x.id)]})]}))}),x.id)}const Pt=o({type:"image",shortcut:"image",renderer:{editor:(t,e)=>i=>h(Ht,Object.assign({editor:t,plugin:e},i)),render:({attributes:e,element:i,children:o,size:n,HTMLAttributes:s})=>{var r,a,l,p,c;const u=(null==n?void 0:n.width)||(null===(a=null===(r=i.data)||void 0===r?void 0:r.size)||void 0===a?void 0:a.width)||"100%",g=(null==n?void 0:n.height)||(null===(p=null===(l=i.data)||void 0===l?void 0:l.size)||void 0===p?void 0:p.height)||400,m=null===(c=i.data)||void 0===c?void 0:c.caption;return i.data.url||i.data["data-src"]?d("div",Object.assign({},e,{className:y,contentEditable:!1,draggable:!1},{children:[d("figure",Object.assign({className:z,onDragStart:t=>t.preventDefault()},{children:[h("img",Object.assign({src:i.data.url||i.data["data-src"]||"",alt:m,width:u,height:g,loading:"lazy",decoding:"async"},s,{className:t({element:i,HTMLAttributes:s,className:x})})),m&&h("figcaption",Object.assign({className:S},{children:m}))]})),o]})):h("div",{})}},extendEditor(t){const{isVoid:e}=t;return t.isVoid=t=>t.type===Pt.getPlugin.type||e(t),t},events:{onKeyDown:(t,{defaultNode:e,hotkeys:i})=>o=>{var s;if("image"===n(t,null===(s=t.selection)||void 0===s?void 0:s.anchor.path,"highest").type&&t.selection)return i.isEnter(o)?(o.preventDefault(),void r.insertNodes(t,e,{mode:"highest"})):void 0}},defineElement:()=>({id:s(),type:"image",nodeType:"void",data:{url:null,size:{width:"auto",height:"auto"}},children:[{text:""}]}),createElement:(t,e)=>{var i;const o=Object.assign(Object.assign({},Pt.getPlugin.defineElement()),e);r.setNodes(t,o,{at:null===(i=t.selection)||void 0===i?void 0:i.anchor})},exports:{markdown:{serialize:(t,e)=>`\n`},html:{serialize:(t,e)=>{var i,o;return`<img src="${t.data.url}" width="${null===(i=t.data.size)||void 0===i?void 0:i.width}" height="${null===(o=t.data.size)||void 0===o?void 0:o.height}" decoding="async" loading="lazy" alt="${t.data.caption||"yoopta-html-image"}" />`},deserialize:{nodeName:"IMG",parse:t=>({url:t.getAttribute("src"),size:{height:"string"==typeof t.getAttribute("height")?Number(t.getAttribute("height")):"auto",width:"string"==typeof t.getAttribute("width")?Number(t.getAttribute("width")):"auto"}})}}},options:{searchString:"image picture",displayLabel:"Image"}});export{Pt as default};
|
|
1
|
+
import { getElementClassname, UI_HELPERS, cx, createYooptaPlugin, getElementByPath, generateId } from '@yoopta/editor';
|
|
2
|
+
import { Transforms, Element } from 'slate';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useState, useRef, useEffect, useMemo } from 'react';
|
|
6
|
+
import { flushSync } from 'react-dom';
|
|
7
|
+
import { ReactEditor, useSelected, useReadOnly } from 'slate-react';
|
|
8
|
+
|
|
9
|
+
function styleInject(css, ref) {
|
|
10
|
+
if ( ref === void 0 ) ref = {};
|
|
11
|
+
var insertAt = ref.insertAt;
|
|
12
|
+
|
|
13
|
+
if (!css || typeof document === 'undefined') { return; }
|
|
14
|
+
|
|
15
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
16
|
+
var style = document.createElement('style');
|
|
17
|
+
style.type = 'text/css';
|
|
18
|
+
|
|
19
|
+
if (insertAt === 'top') {
|
|
20
|
+
if (head.firstChild) {
|
|
21
|
+
head.insertBefore(style, head.firstChild);
|
|
22
|
+
} else {
|
|
23
|
+
head.appendChild(style);
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
head.appendChild(style);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (style.styleSheet) {
|
|
30
|
+
style.styleSheet.cssText = css;
|
|
31
|
+
} else {
|
|
32
|
+
style.appendChild(document.createTextNode(css));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var css_248z$4 = ".Image-module_imgElement{margin:20px 0 10px;position:relative}.Image-module_img{border-radius:1px;display:block;margin:0 auto;max-width:100%;object-fit:cover;pointer-events:auto}.Image-module_figure{height:100%;margin:0}.Image-module_caption{caret-color:#37352f;color:rgba(55,53,47,.65);font-size:14px;line-height:1.4;max-width:100%;padding-bottom:6px;padding-left:2px;padding-top:6px;white-space:pre-wrap;width:100%;word-break:break-word}";
|
|
37
|
+
var s$4 = {"imgElement":"Image-module_imgElement","img":"Image-module_img","figure":"Image-module_figure","caption":"Image-module_caption"};
|
|
38
|
+
styleInject(css_248z$4);
|
|
39
|
+
|
|
40
|
+
const Image$2 = ({ attributes, element, children, size, HTMLAttributes }) => {
|
|
41
|
+
var _a, _b, _c, _d, _e;
|
|
42
|
+
const width = (size === null || size === void 0 ? void 0 : size.width) || ((_b = (_a = element.data) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.width) || '100%';
|
|
43
|
+
const height = (size === null || size === void 0 ? void 0 : size.height) || ((_d = (_c = element.data) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.height) || 400;
|
|
44
|
+
const caption = (_e = element.data) === null || _e === void 0 ? void 0 : _e.caption;
|
|
45
|
+
if (!element.data.url && !element.data['data-src'])
|
|
46
|
+
return jsx("div", {});
|
|
47
|
+
return (jsxs("div", Object.assign({}, attributes, { className: s$4.imgElement, contentEditable: false, draggable: false }, { children: [jsxs("figure", Object.assign({ className: s$4.figure, onDragStart: (e) => e.preventDefault() }, { children: [jsx("img", Object.assign({ src: element.data.url || element.data['data-src'] || '', alt: caption, width: width, height: height, loading: "lazy", decoding: "async" }, HTMLAttributes, { className: getElementClassname({ element, HTMLAttributes, className: s$4.img }) })), caption && jsx("figcaption", Object.assign({ className: s$4.caption }, { children: caption }))] })), children] })));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var __extends$1 = (undefined && undefined.__extends) || (function () {
|
|
51
|
+
var extendStatics = function (d, b) {
|
|
52
|
+
extendStatics = Object.setPrototypeOf ||
|
|
53
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
54
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
55
|
+
return extendStatics(d, b);
|
|
56
|
+
};
|
|
57
|
+
return function (d, b) {
|
|
58
|
+
extendStatics(d, b);
|
|
59
|
+
function __() { this.constructor = d; }
|
|
60
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
61
|
+
};
|
|
62
|
+
})();
|
|
63
|
+
var __assign$1 = (undefined && undefined.__assign) || function () {
|
|
64
|
+
__assign$1 = Object.assign || function(t) {
|
|
65
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
66
|
+
s = arguments[i];
|
|
67
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
68
|
+
t[p] = s[p];
|
|
69
|
+
}
|
|
70
|
+
return t;
|
|
71
|
+
};
|
|
72
|
+
return __assign$1.apply(this, arguments);
|
|
73
|
+
};
|
|
74
|
+
var rowSizeBase = {
|
|
75
|
+
width: '100%',
|
|
76
|
+
height: '10px',
|
|
77
|
+
top: '0px',
|
|
78
|
+
left: '0px',
|
|
79
|
+
cursor: 'row-resize',
|
|
80
|
+
};
|
|
81
|
+
var colSizeBase = {
|
|
82
|
+
width: '10px',
|
|
83
|
+
height: '100%',
|
|
84
|
+
top: '0px',
|
|
85
|
+
left: '0px',
|
|
86
|
+
cursor: 'col-resize',
|
|
87
|
+
};
|
|
88
|
+
var edgeBase = {
|
|
89
|
+
width: '20px',
|
|
90
|
+
height: '20px',
|
|
91
|
+
position: 'absolute',
|
|
92
|
+
};
|
|
93
|
+
var styles = {
|
|
94
|
+
top: __assign$1(__assign$1({}, rowSizeBase), { top: '-5px' }),
|
|
95
|
+
right: __assign$1(__assign$1({}, colSizeBase), { left: undefined, right: '-5px' }),
|
|
96
|
+
bottom: __assign$1(__assign$1({}, rowSizeBase), { top: undefined, bottom: '-5px' }),
|
|
97
|
+
left: __assign$1(__assign$1({}, colSizeBase), { left: '-5px' }),
|
|
98
|
+
topRight: __assign$1(__assign$1({}, edgeBase), { right: '-10px', top: '-10px', cursor: 'ne-resize' }),
|
|
99
|
+
bottomRight: __assign$1(__assign$1({}, edgeBase), { right: '-10px', bottom: '-10px', cursor: 'se-resize' }),
|
|
100
|
+
bottomLeft: __assign$1(__assign$1({}, edgeBase), { left: '-10px', bottom: '-10px', cursor: 'sw-resize' }),
|
|
101
|
+
topLeft: __assign$1(__assign$1({}, edgeBase), { left: '-10px', top: '-10px', cursor: 'nw-resize' }),
|
|
102
|
+
};
|
|
103
|
+
var Resizer = /** @class */ (function (_super) {
|
|
104
|
+
__extends$1(Resizer, _super);
|
|
105
|
+
function Resizer() {
|
|
106
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
107
|
+
_this.onMouseDown = function (e) {
|
|
108
|
+
_this.props.onResizeStart(e, _this.props.direction);
|
|
109
|
+
};
|
|
110
|
+
_this.onTouchStart = function (e) {
|
|
111
|
+
_this.props.onResizeStart(e, _this.props.direction);
|
|
112
|
+
};
|
|
113
|
+
return _this;
|
|
114
|
+
}
|
|
115
|
+
Resizer.prototype.render = function () {
|
|
116
|
+
return (React.createElement("div", { className: this.props.className || '', style: __assign$1(__assign$1({ position: 'absolute', userSelect: 'none' }, styles[this.props.direction]), (this.props.replaceStyles || {})), onMouseDown: this.onMouseDown, onTouchStart: this.onTouchStart }, this.props.children));
|
|
117
|
+
};
|
|
118
|
+
return Resizer;
|
|
119
|
+
}(React.PureComponent));
|
|
120
|
+
|
|
121
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
|
122
|
+
var extendStatics = function (d, b) {
|
|
123
|
+
extendStatics = Object.setPrototypeOf ||
|
|
124
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
125
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
126
|
+
return extendStatics(d, b);
|
|
127
|
+
};
|
|
128
|
+
return function (d, b) {
|
|
129
|
+
extendStatics(d, b);
|
|
130
|
+
function __() { this.constructor = d; }
|
|
131
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
132
|
+
};
|
|
133
|
+
})();
|
|
134
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
135
|
+
__assign = Object.assign || function(t) {
|
|
136
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
137
|
+
s = arguments[i];
|
|
138
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
139
|
+
t[p] = s[p];
|
|
140
|
+
}
|
|
141
|
+
return t;
|
|
142
|
+
};
|
|
143
|
+
return __assign.apply(this, arguments);
|
|
144
|
+
};
|
|
145
|
+
var DEFAULT_SIZE = {
|
|
146
|
+
width: 'auto',
|
|
147
|
+
height: 'auto',
|
|
148
|
+
};
|
|
149
|
+
var clamp = function (n, min, max) { return Math.max(Math.min(n, max), min); };
|
|
150
|
+
var snap = function (n, size) { return Math.round(n / size) * size; };
|
|
151
|
+
var hasDirection = function (dir, target) {
|
|
152
|
+
return new RegExp(dir, 'i').test(target);
|
|
153
|
+
};
|
|
154
|
+
// INFO: In case of window is a Proxy and does not porxy Events correctly, use isTouchEvent & isMouseEvent to distinguish event type instead of `instanceof`.
|
|
155
|
+
var isTouchEvent = function (event) {
|
|
156
|
+
return Boolean(event.touches && event.touches.length);
|
|
157
|
+
};
|
|
158
|
+
var isMouseEvent = function (event) {
|
|
159
|
+
return Boolean((event.clientX || event.clientX === 0) &&
|
|
160
|
+
(event.clientY || event.clientY === 0));
|
|
161
|
+
};
|
|
162
|
+
var findClosestSnap = function (n, snapArray, snapGap) {
|
|
163
|
+
if (snapGap === void 0) { snapGap = 0; }
|
|
164
|
+
var closestGapIndex = snapArray.reduce(function (prev, curr, index) { return (Math.abs(curr - n) < Math.abs(snapArray[prev] - n) ? index : prev); }, 0);
|
|
165
|
+
var gap = Math.abs(snapArray[closestGapIndex] - n);
|
|
166
|
+
return snapGap === 0 || gap < snapGap ? snapArray[closestGapIndex] : n;
|
|
167
|
+
};
|
|
168
|
+
var getStringSize = function (n) {
|
|
169
|
+
n = n.toString();
|
|
170
|
+
if (n === 'auto') {
|
|
171
|
+
return n;
|
|
172
|
+
}
|
|
173
|
+
if (n.endsWith('px')) {
|
|
174
|
+
return n;
|
|
175
|
+
}
|
|
176
|
+
if (n.endsWith('%')) {
|
|
177
|
+
return n;
|
|
178
|
+
}
|
|
179
|
+
if (n.endsWith('vh')) {
|
|
180
|
+
return n;
|
|
181
|
+
}
|
|
182
|
+
if (n.endsWith('vw')) {
|
|
183
|
+
return n;
|
|
184
|
+
}
|
|
185
|
+
if (n.endsWith('vmax')) {
|
|
186
|
+
return n;
|
|
187
|
+
}
|
|
188
|
+
if (n.endsWith('vmin')) {
|
|
189
|
+
return n;
|
|
190
|
+
}
|
|
191
|
+
return n + "px";
|
|
192
|
+
};
|
|
193
|
+
var getPixelSize = function (size, parentSize, innerWidth, innerHeight) {
|
|
194
|
+
if (size && typeof size === 'string') {
|
|
195
|
+
if (size.endsWith('px')) {
|
|
196
|
+
return Number(size.replace('px', ''));
|
|
197
|
+
}
|
|
198
|
+
if (size.endsWith('%')) {
|
|
199
|
+
var ratio = Number(size.replace('%', '')) / 100;
|
|
200
|
+
return parentSize * ratio;
|
|
201
|
+
}
|
|
202
|
+
if (size.endsWith('vw')) {
|
|
203
|
+
var ratio = Number(size.replace('vw', '')) / 100;
|
|
204
|
+
return innerWidth * ratio;
|
|
205
|
+
}
|
|
206
|
+
if (size.endsWith('vh')) {
|
|
207
|
+
var ratio = Number(size.replace('vh', '')) / 100;
|
|
208
|
+
return innerHeight * ratio;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return size;
|
|
212
|
+
};
|
|
213
|
+
var calculateNewMax = function (parentSize, innerWidth, innerHeight, maxWidth, maxHeight, minWidth, minHeight) {
|
|
214
|
+
maxWidth = getPixelSize(maxWidth, parentSize.width, innerWidth, innerHeight);
|
|
215
|
+
maxHeight = getPixelSize(maxHeight, parentSize.height, innerWidth, innerHeight);
|
|
216
|
+
minWidth = getPixelSize(minWidth, parentSize.width, innerWidth, innerHeight);
|
|
217
|
+
minHeight = getPixelSize(minHeight, parentSize.height, innerWidth, innerHeight);
|
|
218
|
+
return {
|
|
219
|
+
maxWidth: typeof maxWidth === 'undefined' ? undefined : Number(maxWidth),
|
|
220
|
+
maxHeight: typeof maxHeight === 'undefined' ? undefined : Number(maxHeight),
|
|
221
|
+
minWidth: typeof minWidth === 'undefined' ? undefined : Number(minWidth),
|
|
222
|
+
minHeight: typeof minHeight === 'undefined' ? undefined : Number(minHeight),
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
var definedProps = [
|
|
226
|
+
'as',
|
|
227
|
+
'style',
|
|
228
|
+
'className',
|
|
229
|
+
'grid',
|
|
230
|
+
'snap',
|
|
231
|
+
'bounds',
|
|
232
|
+
'boundsByDirection',
|
|
233
|
+
'size',
|
|
234
|
+
'defaultSize',
|
|
235
|
+
'minWidth',
|
|
236
|
+
'minHeight',
|
|
237
|
+
'maxWidth',
|
|
238
|
+
'maxHeight',
|
|
239
|
+
'lockAspectRatio',
|
|
240
|
+
'lockAspectRatioExtraWidth',
|
|
241
|
+
'lockAspectRatioExtraHeight',
|
|
242
|
+
'enable',
|
|
243
|
+
'handleStyles',
|
|
244
|
+
'handleClasses',
|
|
245
|
+
'handleWrapperStyle',
|
|
246
|
+
'handleWrapperClass',
|
|
247
|
+
'children',
|
|
248
|
+
'onResizeStart',
|
|
249
|
+
'onResize',
|
|
250
|
+
'onResizeStop',
|
|
251
|
+
'handleComponent',
|
|
252
|
+
'scale',
|
|
253
|
+
'resizeRatio',
|
|
254
|
+
'snapGap',
|
|
255
|
+
];
|
|
256
|
+
// HACK: This class is used to calculate % size.
|
|
257
|
+
var baseClassName = '__resizable_base__';
|
|
258
|
+
var Resizable = /** @class */ (function (_super) {
|
|
259
|
+
__extends(Resizable, _super);
|
|
260
|
+
function Resizable(props) {
|
|
261
|
+
var _this = _super.call(this, props) || this;
|
|
262
|
+
_this.ratio = 1;
|
|
263
|
+
_this.resizable = null;
|
|
264
|
+
// For parent boundary
|
|
265
|
+
_this.parentLeft = 0;
|
|
266
|
+
_this.parentTop = 0;
|
|
267
|
+
// For boundary
|
|
268
|
+
_this.resizableLeft = 0;
|
|
269
|
+
_this.resizableRight = 0;
|
|
270
|
+
_this.resizableTop = 0;
|
|
271
|
+
_this.resizableBottom = 0;
|
|
272
|
+
// For target boundary
|
|
273
|
+
_this.targetLeft = 0;
|
|
274
|
+
_this.targetTop = 0;
|
|
275
|
+
_this.appendBase = function () {
|
|
276
|
+
if (!_this.resizable || !_this.window) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
var parent = _this.parentNode;
|
|
280
|
+
if (!parent) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
var element = _this.window.document.createElement('div');
|
|
284
|
+
element.style.width = '100%';
|
|
285
|
+
element.style.height = '100%';
|
|
286
|
+
element.style.position = 'absolute';
|
|
287
|
+
element.style.transform = 'scale(0, 0)';
|
|
288
|
+
element.style.left = '0';
|
|
289
|
+
element.style.flex = '0 0 100%';
|
|
290
|
+
if (element.classList) {
|
|
291
|
+
element.classList.add(baseClassName);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
element.className += baseClassName;
|
|
295
|
+
}
|
|
296
|
+
parent.appendChild(element);
|
|
297
|
+
return element;
|
|
298
|
+
};
|
|
299
|
+
_this.removeBase = function (base) {
|
|
300
|
+
var parent = _this.parentNode;
|
|
301
|
+
if (!parent) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
parent.removeChild(base);
|
|
305
|
+
};
|
|
306
|
+
_this.ref = function (c) {
|
|
307
|
+
if (c) {
|
|
308
|
+
_this.resizable = c;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
_this.state = {
|
|
312
|
+
isResizing: false,
|
|
313
|
+
width: typeof (_this.propsSize && _this.propsSize.width) === 'undefined'
|
|
314
|
+
? 'auto'
|
|
315
|
+
: _this.propsSize && _this.propsSize.width,
|
|
316
|
+
height: typeof (_this.propsSize && _this.propsSize.height) === 'undefined'
|
|
317
|
+
? 'auto'
|
|
318
|
+
: _this.propsSize && _this.propsSize.height,
|
|
319
|
+
direction: 'right',
|
|
320
|
+
original: {
|
|
321
|
+
x: 0,
|
|
322
|
+
y: 0,
|
|
323
|
+
width: 0,
|
|
324
|
+
height: 0,
|
|
325
|
+
},
|
|
326
|
+
backgroundStyle: {
|
|
327
|
+
height: '100%',
|
|
328
|
+
width: '100%',
|
|
329
|
+
backgroundColor: 'rgba(0,0,0,0)',
|
|
330
|
+
cursor: 'auto',
|
|
331
|
+
opacity: 0,
|
|
332
|
+
position: 'fixed',
|
|
333
|
+
zIndex: 9999,
|
|
334
|
+
top: '0',
|
|
335
|
+
left: '0',
|
|
336
|
+
bottom: '0',
|
|
337
|
+
right: '0',
|
|
338
|
+
},
|
|
339
|
+
flexBasis: undefined,
|
|
340
|
+
};
|
|
341
|
+
_this.onResizeStart = _this.onResizeStart.bind(_this);
|
|
342
|
+
_this.onMouseMove = _this.onMouseMove.bind(_this);
|
|
343
|
+
_this.onMouseUp = _this.onMouseUp.bind(_this);
|
|
344
|
+
return _this;
|
|
345
|
+
}
|
|
346
|
+
Object.defineProperty(Resizable.prototype, "parentNode", {
|
|
347
|
+
get: function () {
|
|
348
|
+
if (!this.resizable) {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
return this.resizable.parentNode;
|
|
352
|
+
},
|
|
353
|
+
enumerable: false,
|
|
354
|
+
configurable: true
|
|
355
|
+
});
|
|
356
|
+
Object.defineProperty(Resizable.prototype, "window", {
|
|
357
|
+
get: function () {
|
|
358
|
+
if (!this.resizable) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
if (!this.resizable.ownerDocument) {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
return this.resizable.ownerDocument.defaultView;
|
|
365
|
+
},
|
|
366
|
+
enumerable: false,
|
|
367
|
+
configurable: true
|
|
368
|
+
});
|
|
369
|
+
Object.defineProperty(Resizable.prototype, "propsSize", {
|
|
370
|
+
get: function () {
|
|
371
|
+
return this.props.size || this.props.defaultSize || DEFAULT_SIZE;
|
|
372
|
+
},
|
|
373
|
+
enumerable: false,
|
|
374
|
+
configurable: true
|
|
375
|
+
});
|
|
376
|
+
Object.defineProperty(Resizable.prototype, "size", {
|
|
377
|
+
get: function () {
|
|
378
|
+
var width = 0;
|
|
379
|
+
var height = 0;
|
|
380
|
+
if (this.resizable && this.window) {
|
|
381
|
+
var orgWidth = this.resizable.offsetWidth;
|
|
382
|
+
var orgHeight = this.resizable.offsetHeight;
|
|
383
|
+
// HACK: Set position `relative` to get parent size.
|
|
384
|
+
// This is because when re-resizable set `absolute`, I can not get base width correctly.
|
|
385
|
+
var orgPosition = this.resizable.style.position;
|
|
386
|
+
if (orgPosition !== 'relative') {
|
|
387
|
+
this.resizable.style.position = 'relative';
|
|
388
|
+
}
|
|
389
|
+
// INFO: Use original width or height if set auto.
|
|
390
|
+
width = this.resizable.style.width !== 'auto' ? this.resizable.offsetWidth : orgWidth;
|
|
391
|
+
height = this.resizable.style.height !== 'auto' ? this.resizable.offsetHeight : orgHeight;
|
|
392
|
+
// Restore original position
|
|
393
|
+
this.resizable.style.position = orgPosition;
|
|
394
|
+
}
|
|
395
|
+
return { width: width, height: height };
|
|
396
|
+
},
|
|
397
|
+
enumerable: false,
|
|
398
|
+
configurable: true
|
|
399
|
+
});
|
|
400
|
+
Object.defineProperty(Resizable.prototype, "sizeStyle", {
|
|
401
|
+
get: function () {
|
|
402
|
+
var _this = this;
|
|
403
|
+
var size = this.props.size;
|
|
404
|
+
var getSize = function (key) {
|
|
405
|
+
if (typeof _this.state[key] === 'undefined' || _this.state[key] === 'auto') {
|
|
406
|
+
return 'auto';
|
|
407
|
+
}
|
|
408
|
+
if (_this.propsSize && _this.propsSize[key] && _this.propsSize[key].toString().endsWith('%')) {
|
|
409
|
+
if (_this.state[key].toString().endsWith('%')) {
|
|
410
|
+
return _this.state[key].toString();
|
|
411
|
+
}
|
|
412
|
+
var parentSize = _this.getParentSize();
|
|
413
|
+
var value = Number(_this.state[key].toString().replace('px', ''));
|
|
414
|
+
var percent = (value / parentSize[key]) * 100;
|
|
415
|
+
return percent + "%";
|
|
416
|
+
}
|
|
417
|
+
return getStringSize(_this.state[key]);
|
|
418
|
+
};
|
|
419
|
+
var width = size && typeof size.width !== 'undefined' && !this.state.isResizing
|
|
420
|
+
? getStringSize(size.width)
|
|
421
|
+
: getSize('width');
|
|
422
|
+
var height = size && typeof size.height !== 'undefined' && !this.state.isResizing
|
|
423
|
+
? getStringSize(size.height)
|
|
424
|
+
: getSize('height');
|
|
425
|
+
return { width: width, height: height };
|
|
426
|
+
},
|
|
427
|
+
enumerable: false,
|
|
428
|
+
configurable: true
|
|
429
|
+
});
|
|
430
|
+
Resizable.prototype.getParentSize = function () {
|
|
431
|
+
if (!this.parentNode) {
|
|
432
|
+
if (!this.window) {
|
|
433
|
+
return { width: 0, height: 0 };
|
|
434
|
+
}
|
|
435
|
+
return { width: this.window.innerWidth, height: this.window.innerHeight };
|
|
436
|
+
}
|
|
437
|
+
var base = this.appendBase();
|
|
438
|
+
if (!base) {
|
|
439
|
+
return { width: 0, height: 0 };
|
|
440
|
+
}
|
|
441
|
+
// INFO: To calculate parent width with flex layout
|
|
442
|
+
var wrapChanged = false;
|
|
443
|
+
var wrap = this.parentNode.style.flexWrap;
|
|
444
|
+
if (wrap !== 'wrap') {
|
|
445
|
+
wrapChanged = true;
|
|
446
|
+
this.parentNode.style.flexWrap = 'wrap';
|
|
447
|
+
// HACK: Use relative to get parent padding size
|
|
448
|
+
}
|
|
449
|
+
base.style.position = 'relative';
|
|
450
|
+
base.style.minWidth = '100%';
|
|
451
|
+
base.style.minHeight = '100%';
|
|
452
|
+
var size = {
|
|
453
|
+
width: base.offsetWidth,
|
|
454
|
+
height: base.offsetHeight,
|
|
455
|
+
};
|
|
456
|
+
if (wrapChanged) {
|
|
457
|
+
this.parentNode.style.flexWrap = wrap;
|
|
458
|
+
}
|
|
459
|
+
this.removeBase(base);
|
|
460
|
+
return size;
|
|
461
|
+
};
|
|
462
|
+
Resizable.prototype.bindEvents = function () {
|
|
463
|
+
if (this.window) {
|
|
464
|
+
this.window.addEventListener('mouseup', this.onMouseUp);
|
|
465
|
+
this.window.addEventListener('mousemove', this.onMouseMove);
|
|
466
|
+
this.window.addEventListener('mouseleave', this.onMouseUp);
|
|
467
|
+
this.window.addEventListener('touchmove', this.onMouseMove, {
|
|
468
|
+
capture: true,
|
|
469
|
+
passive: false,
|
|
470
|
+
});
|
|
471
|
+
this.window.addEventListener('touchend', this.onMouseUp);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
Resizable.prototype.unbindEvents = function () {
|
|
475
|
+
if (this.window) {
|
|
476
|
+
this.window.removeEventListener('mouseup', this.onMouseUp);
|
|
477
|
+
this.window.removeEventListener('mousemove', this.onMouseMove);
|
|
478
|
+
this.window.removeEventListener('mouseleave', this.onMouseUp);
|
|
479
|
+
this.window.removeEventListener('touchmove', this.onMouseMove, true);
|
|
480
|
+
this.window.removeEventListener('touchend', this.onMouseUp);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
Resizable.prototype.componentDidMount = function () {
|
|
484
|
+
if (!this.resizable || !this.window) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
var computedStyle = this.window.getComputedStyle(this.resizable);
|
|
488
|
+
this.setState({
|
|
489
|
+
width: this.state.width || this.size.width,
|
|
490
|
+
height: this.state.height || this.size.height,
|
|
491
|
+
flexBasis: computedStyle.flexBasis !== 'auto' ? computedStyle.flexBasis : undefined,
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
Resizable.prototype.componentWillUnmount = function () {
|
|
495
|
+
if (this.window) {
|
|
496
|
+
this.unbindEvents();
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
Resizable.prototype.createSizeForCssProperty = function (newSize, kind) {
|
|
500
|
+
var propsSize = this.propsSize && this.propsSize[kind];
|
|
501
|
+
return this.state[kind] === 'auto' &&
|
|
502
|
+
this.state.original[kind] === newSize &&
|
|
503
|
+
(typeof propsSize === 'undefined' || propsSize === 'auto')
|
|
504
|
+
? 'auto'
|
|
505
|
+
: newSize;
|
|
506
|
+
};
|
|
507
|
+
Resizable.prototype.calculateNewMaxFromBoundary = function (maxWidth, maxHeight) {
|
|
508
|
+
var boundsByDirection = this.props.boundsByDirection;
|
|
509
|
+
var direction = this.state.direction;
|
|
510
|
+
var widthByDirection = boundsByDirection && hasDirection('left', direction);
|
|
511
|
+
var heightByDirection = boundsByDirection && hasDirection('top', direction);
|
|
512
|
+
var boundWidth;
|
|
513
|
+
var boundHeight;
|
|
514
|
+
if (this.props.bounds === 'parent') {
|
|
515
|
+
var parent_1 = this.parentNode;
|
|
516
|
+
if (parent_1) {
|
|
517
|
+
boundWidth = widthByDirection
|
|
518
|
+
? this.resizableRight - this.parentLeft
|
|
519
|
+
: parent_1.offsetWidth + (this.parentLeft - this.resizableLeft);
|
|
520
|
+
boundHeight = heightByDirection
|
|
521
|
+
? this.resizableBottom - this.parentTop
|
|
522
|
+
: parent_1.offsetHeight + (this.parentTop - this.resizableTop);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
else if (this.props.bounds === 'window') {
|
|
526
|
+
if (this.window) {
|
|
527
|
+
boundWidth = widthByDirection ? this.resizableRight : this.window.innerWidth - this.resizableLeft;
|
|
528
|
+
boundHeight = heightByDirection ? this.resizableBottom : this.window.innerHeight - this.resizableTop;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else if (this.props.bounds) {
|
|
532
|
+
boundWidth = widthByDirection
|
|
533
|
+
? this.resizableRight - this.targetLeft
|
|
534
|
+
: this.props.bounds.offsetWidth + (this.targetLeft - this.resizableLeft);
|
|
535
|
+
boundHeight = heightByDirection
|
|
536
|
+
? this.resizableBottom - this.targetTop
|
|
537
|
+
: this.props.bounds.offsetHeight + (this.targetTop - this.resizableTop);
|
|
538
|
+
}
|
|
539
|
+
if (boundWidth && Number.isFinite(boundWidth)) {
|
|
540
|
+
maxWidth = maxWidth && maxWidth < boundWidth ? maxWidth : boundWidth;
|
|
541
|
+
}
|
|
542
|
+
if (boundHeight && Number.isFinite(boundHeight)) {
|
|
543
|
+
maxHeight = maxHeight && maxHeight < boundHeight ? maxHeight : boundHeight;
|
|
544
|
+
}
|
|
545
|
+
return { maxWidth: maxWidth, maxHeight: maxHeight };
|
|
546
|
+
};
|
|
547
|
+
Resizable.prototype.calculateNewSizeFromDirection = function (clientX, clientY) {
|
|
548
|
+
var scale = this.props.scale || 1;
|
|
549
|
+
var resizeRatio = this.props.resizeRatio || 1;
|
|
550
|
+
var _a = this.state, direction = _a.direction, original = _a.original;
|
|
551
|
+
var _b = this.props, lockAspectRatio = _b.lockAspectRatio, lockAspectRatioExtraHeight = _b.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _b.lockAspectRatioExtraWidth;
|
|
552
|
+
var newWidth = original.width;
|
|
553
|
+
var newHeight = original.height;
|
|
554
|
+
var extraHeight = lockAspectRatioExtraHeight || 0;
|
|
555
|
+
var extraWidth = lockAspectRatioExtraWidth || 0;
|
|
556
|
+
if (hasDirection('right', direction)) {
|
|
557
|
+
newWidth = original.width + ((clientX - original.x) * resizeRatio) / scale;
|
|
558
|
+
if (lockAspectRatio) {
|
|
559
|
+
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (hasDirection('left', direction)) {
|
|
563
|
+
newWidth = original.width - ((clientX - original.x) * resizeRatio) / scale;
|
|
564
|
+
if (lockAspectRatio) {
|
|
565
|
+
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (hasDirection('bottom', direction)) {
|
|
569
|
+
newHeight = original.height + ((clientY - original.y) * resizeRatio) / scale;
|
|
570
|
+
if (lockAspectRatio) {
|
|
571
|
+
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (hasDirection('top', direction)) {
|
|
575
|
+
newHeight = original.height - ((clientY - original.y) * resizeRatio) / scale;
|
|
576
|
+
if (lockAspectRatio) {
|
|
577
|
+
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return { newWidth: newWidth, newHeight: newHeight };
|
|
581
|
+
};
|
|
582
|
+
Resizable.prototype.calculateNewSizeFromAspectRatio = function (newWidth, newHeight, max, min) {
|
|
583
|
+
var _a = this.props, lockAspectRatio = _a.lockAspectRatio, lockAspectRatioExtraHeight = _a.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _a.lockAspectRatioExtraWidth;
|
|
584
|
+
var computedMinWidth = typeof min.width === 'undefined' ? 10 : min.width;
|
|
585
|
+
var computedMaxWidth = typeof max.width === 'undefined' || max.width < 0 ? newWidth : max.width;
|
|
586
|
+
var computedMinHeight = typeof min.height === 'undefined' ? 10 : min.height;
|
|
587
|
+
var computedMaxHeight = typeof max.height === 'undefined' || max.height < 0 ? newHeight : max.height;
|
|
588
|
+
var extraHeight = lockAspectRatioExtraHeight || 0;
|
|
589
|
+
var extraWidth = lockAspectRatioExtraWidth || 0;
|
|
590
|
+
if (lockAspectRatio) {
|
|
591
|
+
var extraMinWidth = (computedMinHeight - extraHeight) * this.ratio + extraWidth;
|
|
592
|
+
var extraMaxWidth = (computedMaxHeight - extraHeight) * this.ratio + extraWidth;
|
|
593
|
+
var extraMinHeight = (computedMinWidth - extraWidth) / this.ratio + extraHeight;
|
|
594
|
+
var extraMaxHeight = (computedMaxWidth - extraWidth) / this.ratio + extraHeight;
|
|
595
|
+
var lockedMinWidth = Math.max(computedMinWidth, extraMinWidth);
|
|
596
|
+
var lockedMaxWidth = Math.min(computedMaxWidth, extraMaxWidth);
|
|
597
|
+
var lockedMinHeight = Math.max(computedMinHeight, extraMinHeight);
|
|
598
|
+
var lockedMaxHeight = Math.min(computedMaxHeight, extraMaxHeight);
|
|
599
|
+
newWidth = clamp(newWidth, lockedMinWidth, lockedMaxWidth);
|
|
600
|
+
newHeight = clamp(newHeight, lockedMinHeight, lockedMaxHeight);
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
newWidth = clamp(newWidth, computedMinWidth, computedMaxWidth);
|
|
604
|
+
newHeight = clamp(newHeight, computedMinHeight, computedMaxHeight);
|
|
605
|
+
}
|
|
606
|
+
return { newWidth: newWidth, newHeight: newHeight };
|
|
607
|
+
};
|
|
608
|
+
Resizable.prototype.setBoundingClientRect = function () {
|
|
609
|
+
// For parent boundary
|
|
610
|
+
if (this.props.bounds === 'parent') {
|
|
611
|
+
var parent_2 = this.parentNode;
|
|
612
|
+
if (parent_2) {
|
|
613
|
+
var parentRect = parent_2.getBoundingClientRect();
|
|
614
|
+
this.parentLeft = parentRect.left;
|
|
615
|
+
this.parentTop = parentRect.top;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
// For target(html element) boundary
|
|
619
|
+
if (this.props.bounds && typeof this.props.bounds !== 'string') {
|
|
620
|
+
var targetRect = this.props.bounds.getBoundingClientRect();
|
|
621
|
+
this.targetLeft = targetRect.left;
|
|
622
|
+
this.targetTop = targetRect.top;
|
|
623
|
+
}
|
|
624
|
+
// For boundary
|
|
625
|
+
if (this.resizable) {
|
|
626
|
+
var _a = this.resizable.getBoundingClientRect(), left = _a.left, top_1 = _a.top, right = _a.right, bottom = _a.bottom;
|
|
627
|
+
this.resizableLeft = left;
|
|
628
|
+
this.resizableRight = right;
|
|
629
|
+
this.resizableTop = top_1;
|
|
630
|
+
this.resizableBottom = bottom;
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
Resizable.prototype.onResizeStart = function (event, direction) {
|
|
634
|
+
if (!this.resizable || !this.window) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
var clientX = 0;
|
|
638
|
+
var clientY = 0;
|
|
639
|
+
if (event.nativeEvent && isMouseEvent(event.nativeEvent)) {
|
|
640
|
+
clientX = event.nativeEvent.clientX;
|
|
641
|
+
clientY = event.nativeEvent.clientY;
|
|
642
|
+
}
|
|
643
|
+
else if (event.nativeEvent && isTouchEvent(event.nativeEvent)) {
|
|
644
|
+
clientX = event.nativeEvent.touches[0].clientX;
|
|
645
|
+
clientY = event.nativeEvent.touches[0].clientY;
|
|
646
|
+
}
|
|
647
|
+
if (this.props.onResizeStart) {
|
|
648
|
+
if (this.resizable) {
|
|
649
|
+
var startResize = this.props.onResizeStart(event, direction, this.resizable);
|
|
650
|
+
if (startResize === false) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
// Fix #168
|
|
656
|
+
if (this.props.size) {
|
|
657
|
+
if (typeof this.props.size.height !== 'undefined' && this.props.size.height !== this.state.height) {
|
|
658
|
+
this.setState({ height: this.props.size.height });
|
|
659
|
+
}
|
|
660
|
+
if (typeof this.props.size.width !== 'undefined' && this.props.size.width !== this.state.width) {
|
|
661
|
+
this.setState({ width: this.props.size.width });
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
// For lockAspectRatio case
|
|
665
|
+
this.ratio =
|
|
666
|
+
typeof this.props.lockAspectRatio === 'number' ? this.props.lockAspectRatio : this.size.width / this.size.height;
|
|
667
|
+
var flexBasis;
|
|
668
|
+
var computedStyle = this.window.getComputedStyle(this.resizable);
|
|
669
|
+
if (computedStyle.flexBasis !== 'auto') {
|
|
670
|
+
var parent_3 = this.parentNode;
|
|
671
|
+
if (parent_3) {
|
|
672
|
+
var dir = this.window.getComputedStyle(parent_3).flexDirection;
|
|
673
|
+
this.flexDir = dir.startsWith('row') ? 'row' : 'column';
|
|
674
|
+
flexBasis = computedStyle.flexBasis;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
// For boundary
|
|
678
|
+
this.setBoundingClientRect();
|
|
679
|
+
this.bindEvents();
|
|
680
|
+
var state = {
|
|
681
|
+
original: {
|
|
682
|
+
x: clientX,
|
|
683
|
+
y: clientY,
|
|
684
|
+
width: this.size.width,
|
|
685
|
+
height: this.size.height,
|
|
686
|
+
},
|
|
687
|
+
isResizing: true,
|
|
688
|
+
backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: this.window.getComputedStyle(event.target).cursor || 'auto' }),
|
|
689
|
+
direction: direction,
|
|
690
|
+
flexBasis: flexBasis,
|
|
691
|
+
};
|
|
692
|
+
this.setState(state);
|
|
693
|
+
};
|
|
694
|
+
Resizable.prototype.onMouseMove = function (event) {
|
|
695
|
+
var _this = this;
|
|
696
|
+
if (!this.state.isResizing || !this.resizable || !this.window) {
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (this.window.TouchEvent && isTouchEvent(event)) {
|
|
700
|
+
try {
|
|
701
|
+
event.preventDefault();
|
|
702
|
+
event.stopPropagation();
|
|
703
|
+
}
|
|
704
|
+
catch (e) {
|
|
705
|
+
// Ignore on fail
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
var _a = this.props, maxWidth = _a.maxWidth, maxHeight = _a.maxHeight, minWidth = _a.minWidth, minHeight = _a.minHeight;
|
|
709
|
+
var clientX = isTouchEvent(event) ? event.touches[0].clientX : event.clientX;
|
|
710
|
+
var clientY = isTouchEvent(event) ? event.touches[0].clientY : event.clientY;
|
|
711
|
+
var _b = this.state, direction = _b.direction, original = _b.original, width = _b.width, height = _b.height;
|
|
712
|
+
var parentSize = this.getParentSize();
|
|
713
|
+
var max = calculateNewMax(parentSize, this.window.innerWidth, this.window.innerHeight, maxWidth, maxHeight, minWidth, minHeight);
|
|
714
|
+
maxWidth = max.maxWidth;
|
|
715
|
+
maxHeight = max.maxHeight;
|
|
716
|
+
minWidth = max.minWidth;
|
|
717
|
+
minHeight = max.minHeight;
|
|
718
|
+
// Calculate new size
|
|
719
|
+
var _c = this.calculateNewSizeFromDirection(clientX, clientY), newHeight = _c.newHeight, newWidth = _c.newWidth;
|
|
720
|
+
// Calculate max size from boundary settings
|
|
721
|
+
var boundaryMax = this.calculateNewMaxFromBoundary(maxWidth, maxHeight);
|
|
722
|
+
if (this.props.snap && this.props.snap.x) {
|
|
723
|
+
newWidth = findClosestSnap(newWidth, this.props.snap.x, this.props.snapGap);
|
|
724
|
+
}
|
|
725
|
+
if (this.props.snap && this.props.snap.y) {
|
|
726
|
+
newHeight = findClosestSnap(newHeight, this.props.snap.y, this.props.snapGap);
|
|
727
|
+
}
|
|
728
|
+
// Calculate new size from aspect ratio
|
|
729
|
+
var newSize = this.calculateNewSizeFromAspectRatio(newWidth, newHeight, { width: boundaryMax.maxWidth, height: boundaryMax.maxHeight }, { width: minWidth, height: minHeight });
|
|
730
|
+
newWidth = newSize.newWidth;
|
|
731
|
+
newHeight = newSize.newHeight;
|
|
732
|
+
if (this.props.grid) {
|
|
733
|
+
var newGridWidth = snap(newWidth, this.props.grid[0]);
|
|
734
|
+
var newGridHeight = snap(newHeight, this.props.grid[1]);
|
|
735
|
+
var gap = this.props.snapGap || 0;
|
|
736
|
+
newWidth = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth;
|
|
737
|
+
newHeight = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight;
|
|
738
|
+
}
|
|
739
|
+
var delta = {
|
|
740
|
+
width: newWidth - original.width,
|
|
741
|
+
height: newHeight - original.height,
|
|
742
|
+
};
|
|
743
|
+
if (width && typeof width === 'string') {
|
|
744
|
+
if (width.endsWith('%')) {
|
|
745
|
+
var percent = (newWidth / parentSize.width) * 100;
|
|
746
|
+
newWidth = percent + "%";
|
|
747
|
+
}
|
|
748
|
+
else if (width.endsWith('vw')) {
|
|
749
|
+
var vw = (newWidth / this.window.innerWidth) * 100;
|
|
750
|
+
newWidth = vw + "vw";
|
|
751
|
+
}
|
|
752
|
+
else if (width.endsWith('vh')) {
|
|
753
|
+
var vh = (newWidth / this.window.innerHeight) * 100;
|
|
754
|
+
newWidth = vh + "vh";
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (height && typeof height === 'string') {
|
|
758
|
+
if (height.endsWith('%')) {
|
|
759
|
+
var percent = (newHeight / parentSize.height) * 100;
|
|
760
|
+
newHeight = percent + "%";
|
|
761
|
+
}
|
|
762
|
+
else if (height.endsWith('vw')) {
|
|
763
|
+
var vw = (newHeight / this.window.innerWidth) * 100;
|
|
764
|
+
newHeight = vw + "vw";
|
|
765
|
+
}
|
|
766
|
+
else if (height.endsWith('vh')) {
|
|
767
|
+
var vh = (newHeight / this.window.innerHeight) * 100;
|
|
768
|
+
newHeight = vh + "vh";
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
var newState = {
|
|
772
|
+
width: this.createSizeForCssProperty(newWidth, 'width'),
|
|
773
|
+
height: this.createSizeForCssProperty(newHeight, 'height'),
|
|
774
|
+
};
|
|
775
|
+
if (this.flexDir === 'row') {
|
|
776
|
+
newState.flexBasis = newState.width;
|
|
777
|
+
}
|
|
778
|
+
else if (this.flexDir === 'column') {
|
|
779
|
+
newState.flexBasis = newState.height;
|
|
780
|
+
}
|
|
781
|
+
// For v18, update state sync
|
|
782
|
+
flushSync(function () {
|
|
783
|
+
_this.setState(newState);
|
|
784
|
+
});
|
|
785
|
+
if (this.props.onResize) {
|
|
786
|
+
this.props.onResize(event, direction, this.resizable, delta);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
Resizable.prototype.onMouseUp = function (event) {
|
|
790
|
+
var _a = this.state, isResizing = _a.isResizing, direction = _a.direction, original = _a.original;
|
|
791
|
+
if (!isResizing || !this.resizable) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
var delta = {
|
|
795
|
+
width: this.size.width - original.width,
|
|
796
|
+
height: this.size.height - original.height,
|
|
797
|
+
};
|
|
798
|
+
if (this.props.onResizeStop) {
|
|
799
|
+
this.props.onResizeStop(event, direction, this.resizable, delta);
|
|
800
|
+
}
|
|
801
|
+
if (this.props.size) {
|
|
802
|
+
this.setState(this.props.size);
|
|
803
|
+
}
|
|
804
|
+
this.unbindEvents();
|
|
805
|
+
this.setState({
|
|
806
|
+
isResizing: false,
|
|
807
|
+
backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: 'auto' }),
|
|
808
|
+
});
|
|
809
|
+
};
|
|
810
|
+
Resizable.prototype.updateSize = function (size) {
|
|
811
|
+
this.setState({ width: size.width, height: size.height });
|
|
812
|
+
};
|
|
813
|
+
Resizable.prototype.renderResizer = function () {
|
|
814
|
+
var _this = this;
|
|
815
|
+
var _a = this.props, enable = _a.enable, handleStyles = _a.handleStyles, handleClasses = _a.handleClasses, handleWrapperStyle = _a.handleWrapperStyle, handleWrapperClass = _a.handleWrapperClass, handleComponent = _a.handleComponent;
|
|
816
|
+
if (!enable) {
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
819
|
+
var resizers = Object.keys(enable).map(function (dir) {
|
|
820
|
+
if (enable[dir] !== false) {
|
|
821
|
+
return (React.createElement(Resizer, { key: dir, direction: dir, onResizeStart: _this.onResizeStart, replaceStyles: handleStyles && handleStyles[dir], className: handleClasses && handleClasses[dir] }, handleComponent && handleComponent[dir] ? handleComponent[dir] : null));
|
|
822
|
+
}
|
|
823
|
+
return null;
|
|
824
|
+
});
|
|
825
|
+
// #93 Wrap the resize box in span (will not break 100% width/height)
|
|
826
|
+
return (React.createElement("div", { className: handleWrapperClass, style: handleWrapperStyle }, resizers));
|
|
827
|
+
};
|
|
828
|
+
Resizable.prototype.render = function () {
|
|
829
|
+
var _this = this;
|
|
830
|
+
var extendsProps = Object.keys(this.props).reduce(function (acc, key) {
|
|
831
|
+
if (definedProps.indexOf(key) !== -1) {
|
|
832
|
+
return acc;
|
|
833
|
+
}
|
|
834
|
+
acc[key] = _this.props[key];
|
|
835
|
+
return acc;
|
|
836
|
+
}, {});
|
|
837
|
+
var style = __assign(__assign(__assign({ position: 'relative', userSelect: this.state.isResizing ? 'none' : 'auto' }, this.props.style), this.sizeStyle), { maxWidth: this.props.maxWidth, maxHeight: this.props.maxHeight, minWidth: this.props.minWidth, minHeight: this.props.minHeight, boxSizing: 'border-box', flexShrink: 0 });
|
|
838
|
+
if (this.state.flexBasis) {
|
|
839
|
+
style.flexBasis = this.state.flexBasis;
|
|
840
|
+
}
|
|
841
|
+
var Wrapper = this.props.as || 'div';
|
|
842
|
+
return (React.createElement(Wrapper, __assign({ ref: this.ref, style: style, className: this.props.className }, extendsProps),
|
|
843
|
+
this.state.isResizing && React.createElement("div", { style: this.state.backgroundStyle }),
|
|
844
|
+
this.props.children,
|
|
845
|
+
this.renderResizer()));
|
|
846
|
+
};
|
|
847
|
+
Resizable.defaultProps = {
|
|
848
|
+
as: 'div',
|
|
849
|
+
onResizeStart: function () { },
|
|
850
|
+
onResize: function () { },
|
|
851
|
+
onResizeStop: function () { },
|
|
852
|
+
enable: {
|
|
853
|
+
top: true,
|
|
854
|
+
right: true,
|
|
855
|
+
bottom: true,
|
|
856
|
+
left: true,
|
|
857
|
+
topRight: true,
|
|
858
|
+
bottomRight: true,
|
|
859
|
+
bottomLeft: true,
|
|
860
|
+
topLeft: true,
|
|
861
|
+
},
|
|
862
|
+
style: {},
|
|
863
|
+
grid: [1, 1],
|
|
864
|
+
lockAspectRatio: false,
|
|
865
|
+
lockAspectRatioExtraWidth: 0,
|
|
866
|
+
lockAspectRatioExtraHeight: 0,
|
|
867
|
+
scale: 1,
|
|
868
|
+
resizeRatio: 1,
|
|
869
|
+
snapGap: 0,
|
|
870
|
+
};
|
|
871
|
+
return Resizable;
|
|
872
|
+
}(React.PureComponent));
|
|
873
|
+
|
|
874
|
+
/******************************************************************************
|
|
875
|
+
Copyright (c) Microsoft Corporation.
|
|
876
|
+
|
|
877
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
878
|
+
purpose with or without fee is hereby granted.
|
|
879
|
+
|
|
880
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
881
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
882
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
883
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
884
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
885
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
886
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
887
|
+
***************************************************************************** */
|
|
888
|
+
|
|
889
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
890
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
891
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
892
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
893
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
894
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
895
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
var _path;
|
|
900
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
901
|
+
var SvgUpload = function SvgUpload(props) {
|
|
902
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
903
|
+
fill: "currentColor",
|
|
904
|
+
"aria-hidden": "true",
|
|
905
|
+
viewBox: "0 0 24 24",
|
|
906
|
+
"data-testid": "uploadImage"
|
|
907
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
908
|
+
d: "M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"
|
|
909
|
+
})));
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
var css_248z$3 = ".EditorUploader-module_container{position:fixed}.EditorUploader-module_content{background:#fff;box-shadow:0 0 0 1px hsla(0,0%,6%,.05),0 3px 6px hsla(0,0%,6%,.1),0 9px 24px hsla(0,0%,6%,.2);display:flex;flex-direction:column;height:100%;max-height:420px;max-width:calc(100vw - 24px);min-width:540px}.EditorUploader-module_tabs{box-shadow:inset 0 -1px 0 rgba(55,53,47,.09);display:flex;font-size:14px;height:40px;padding:0 8px;position:relative;width:100%;z-index:1}.EditorUploader-module_tab{align-items:center;background-color:inherit;border:none;border-radius:4px;color:#37352f;cursor:pointer;display:inline-flex;flex-shrink:0;font-size:14px;height:100%;line-height:1.2;min-width:0;padding:6px 8px;position:relative;transition:height 20ms ease-in 0s;user-select:none;white-space:nowrap}.EditorUploader-module_activeTab:after{background-color:#37352f;bottom:0;content:\"\";height:2px;left:0;position:absolute;width:100%}.EditorUploader-module_uploadContent{display:flex;justify-content:center;margin-left:12px;margin-right:12px;margin-top:4px;padding-bottom:6px;padding-top:6px}.EditorUploader-module_uploader{border:1px solid rgba(55,53,47,.16);border-radius:4px;cursor:pointer;height:32px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap;width:100%}.EditorUploader-module_embed{border:none!important;cursor:pointer!important;height:auto!important;padding-left:0!important;padding-right:0!important}.EditorUploader-module_uploaderLabel{align-items:center;cursor:pointer;display:inline-flex;font-size:14px;font-weight:500;height:100%;justify-content:center;line-height:1.2;width:100%}.EditorUploader-module_uploaderInput{left:0;position:absolute;top:0;visibility:hidden}.EditorUploader-module_embedInput{background:hsla(45,13%,94%,.6);box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1);cursor:text;height:32px;line-height:20px;padding:3px 6px;position:relative}.EditorUploader-module_embedButton,.EditorUploader-module_embedInput{align-items:center;border:none;border-radius:4px;display:flex;font-size:14px;width:100%}.EditorUploader-module_embedButton{fill:#fff;background:#2383e2;box-shadow:inset 0 0 0 1px hsla(0,0%,6%,.1),0 1px 2px hsla(0,0%,6%,.1);color:#fff;cursor:pointer;flex-shrink:0;font-weight:500;height:28px;justify-content:center;line-height:1.2;margin:12px auto 6px;max-width:300px;padding-left:12px;padding-right:12px;transition:background 20ms ease-in 0s;user-select:none;white-space:nowrap}";
|
|
913
|
+
var s$3 = {"container":"EditorUploader-module_container","content":"EditorUploader-module_content","tabs":"EditorUploader-module_tabs","tab":"EditorUploader-module_tab","activeTab":"EditorUploader-module_activeTab","uploadContent":"EditorUploader-module_uploadContent","uploader":"EditorUploader-module_uploader","embed":"EditorUploader-module_embed EditorUploader-module_uploader","uploaderLabel":"EditorUploader-module_uploaderLabel","uploaderInput":"EditorUploader-module_uploaderInput","embedInput":"EditorUploader-module_embedInput","embedButton":"EditorUploader-module_embedButton"};
|
|
914
|
+
styleInject(css_248z$3);
|
|
915
|
+
|
|
916
|
+
const Uploader = ({ onChange, accept = 'image/*' }) => {
|
|
917
|
+
const onChangeFile = (e) => {
|
|
918
|
+
const files = e.currentTarget.files;
|
|
919
|
+
if (files && files.length > 0) {
|
|
920
|
+
onChange(files[0]);
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
return (jsx("div", Object.assign({ className: s$3.uploader }, { children: jsxs("label", Object.assign({ htmlFor: "image-uploader", className: s$3.uploaderLabel }, { children: [jsx("input", { type: "file", id: "image-uploader", className: s$3.uploaderInput, accept: accept, onChange: onChangeFile, multiple: false }), "Upload image"] })) })));
|
|
924
|
+
};
|
|
925
|
+
const EmbedLink = ({ onEmbed }) => {
|
|
926
|
+
const [value, setValue] = useState('');
|
|
927
|
+
const onChange = (e) => setValue(e.target.value);
|
|
928
|
+
const onEmbedLink = () => onEmbed(value);
|
|
929
|
+
return (jsxs("div", Object.assign({ className: s$3.embed }, { children: [jsx("input", { type: "text", placeholder: "Paste image link", value: value, className: s$3.embedInput, onChange: onChange }), jsx("button", Object.assign({ type: "button", className: s$3.embedButton, onClick: onEmbedLink }, { children: "Embed image" }))] })));
|
|
930
|
+
};
|
|
931
|
+
const EditorUploader = ({ activeTab = 'upload', style, switchTab, onChange, onEmbed, accept, onClose }) => {
|
|
932
|
+
const isUploader = activeTab === 'upload';
|
|
933
|
+
const isEmbed = activeTab === 'embed';
|
|
934
|
+
return (jsxs(UI_HELPERS.Overlay, Object.assign({ onClose: onClose }, { children: [jsx("div", Object.assign({ className: s$3.container, style: style }, { children: jsxs("div", Object.assign({ className: s$3.content }, { children: [jsxs("div", Object.assign({ className: s$3.tabs }, { children: [jsx("button", Object.assign({ type: "button", onClick: () => switchTab('upload'), className: cx(s$3.tab, { [s$3.activeTab]: isUploader }) }, { children: "Upload" })), jsx("button", Object.assign({ type: "button", onClick: () => switchTab('embed'), className: cx(s$3.tab, { [s$3.activeTab]: isEmbed }) }, { children: "Image link" }))] })), jsxs("div", Object.assign({ className: s$3.uploadContent }, { children: [isUploader && jsx(Uploader, { onChange: onChange, accept: accept }), isEmbed && jsx(EmbedLink, { onEmbed: onEmbed })] }))] })) })), jsx("div", {})] })));
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
const getAspectRatio = (srcWidth, srcHeight, maxWidth, maxHeight) => {
|
|
938
|
+
if (!srcWidth || !srcHeight)
|
|
939
|
+
return {};
|
|
940
|
+
const ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight);
|
|
941
|
+
return { width: srcWidth * ratio, height: srcHeight * ratio };
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
945
|
+
|
|
946
|
+
// Older browsers don't support event options, feature detect it.
|
|
947
|
+
|
|
948
|
+
// Adopted and modified solution from Bohdan Didukh (2017)
|
|
949
|
+
// https://stackoverflow.com/questions/41594997/ios-10-safari-prevent-scrolling-behind-a-fixed-overlay-and-maintain-scroll-posi
|
|
950
|
+
|
|
951
|
+
var hasPassiveEvents = false;
|
|
952
|
+
if (typeof window !== 'undefined') {
|
|
953
|
+
var passiveTestOptions = {
|
|
954
|
+
get passive() {
|
|
955
|
+
hasPassiveEvents = true;
|
|
956
|
+
return undefined;
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
window.addEventListener('testPassive', null, passiveTestOptions);
|
|
960
|
+
window.removeEventListener('testPassive', null, passiveTestOptions);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
var isIosDevice = typeof window !== 'undefined' && window.navigator && window.navigator.platform && (/iP(ad|hone|od)/.test(window.navigator.platform) || window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1);
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
var locks = [];
|
|
967
|
+
var documentListenerAdded = false;
|
|
968
|
+
var initialClientY = -1;
|
|
969
|
+
var previousBodyOverflowSetting = void 0;
|
|
970
|
+
var previousBodyPosition = void 0;
|
|
971
|
+
var previousBodyPaddingRight = void 0;
|
|
972
|
+
|
|
973
|
+
// returns true if `el` should be allowed to receive touchmove events.
|
|
974
|
+
var allowTouchMove = function allowTouchMove(el) {
|
|
975
|
+
return locks.some(function (lock) {
|
|
976
|
+
if (lock.options.allowTouchMove && lock.options.allowTouchMove(el)) {
|
|
977
|
+
return true;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
return false;
|
|
981
|
+
});
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
var preventDefault = function preventDefault(rawEvent) {
|
|
985
|
+
var e = rawEvent || window.event;
|
|
986
|
+
|
|
987
|
+
// For the case whereby consumers adds a touchmove event listener to document.
|
|
988
|
+
// Recall that we do document.addEventListener('touchmove', preventDefault, { passive: false })
|
|
989
|
+
// in disableBodyScroll - so if we provide this opportunity to allowTouchMove, then
|
|
990
|
+
// the touchmove event on document will break.
|
|
991
|
+
if (allowTouchMove(e.target)) {
|
|
992
|
+
return true;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).
|
|
996
|
+
if (e.touches.length > 1) return true;
|
|
997
|
+
|
|
998
|
+
if (e.preventDefault) e.preventDefault();
|
|
999
|
+
|
|
1000
|
+
return false;
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
var setOverflowHidden = function setOverflowHidden(options) {
|
|
1004
|
+
// If previousBodyPaddingRight is already set, don't set it again.
|
|
1005
|
+
if (previousBodyPaddingRight === undefined) {
|
|
1006
|
+
var _reserveScrollBarGap = !!options && options.reserveScrollBarGap === true;
|
|
1007
|
+
var scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
|
|
1008
|
+
|
|
1009
|
+
if (_reserveScrollBarGap && scrollBarGap > 0) {
|
|
1010
|
+
var computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10);
|
|
1011
|
+
previousBodyPaddingRight = document.body.style.paddingRight;
|
|
1012
|
+
document.body.style.paddingRight = computedBodyPaddingRight + scrollBarGap + 'px';
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// If previousBodyOverflowSetting is already set, don't set it again.
|
|
1017
|
+
if (previousBodyOverflowSetting === undefined) {
|
|
1018
|
+
previousBodyOverflowSetting = document.body.style.overflow;
|
|
1019
|
+
document.body.style.overflow = 'hidden';
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
var restoreOverflowSetting = function restoreOverflowSetting() {
|
|
1024
|
+
if (previousBodyPaddingRight !== undefined) {
|
|
1025
|
+
document.body.style.paddingRight = previousBodyPaddingRight;
|
|
1026
|
+
|
|
1027
|
+
// Restore previousBodyPaddingRight to undefined so setOverflowHidden knows it
|
|
1028
|
+
// can be set again.
|
|
1029
|
+
previousBodyPaddingRight = undefined;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
if (previousBodyOverflowSetting !== undefined) {
|
|
1033
|
+
document.body.style.overflow = previousBodyOverflowSetting;
|
|
1034
|
+
|
|
1035
|
+
// Restore previousBodyOverflowSetting to undefined
|
|
1036
|
+
// so setOverflowHidden knows it can be set again.
|
|
1037
|
+
previousBodyOverflowSetting = undefined;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
var setPositionFixed = function setPositionFixed() {
|
|
1042
|
+
return window.requestAnimationFrame(function () {
|
|
1043
|
+
// If previousBodyPosition is already set, don't set it again.
|
|
1044
|
+
if (previousBodyPosition === undefined) {
|
|
1045
|
+
previousBodyPosition = {
|
|
1046
|
+
position: document.body.style.position,
|
|
1047
|
+
top: document.body.style.top,
|
|
1048
|
+
left: document.body.style.left
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
// Update the dom inside an animation frame
|
|
1052
|
+
var _window = window,
|
|
1053
|
+
scrollY = _window.scrollY,
|
|
1054
|
+
scrollX = _window.scrollX,
|
|
1055
|
+
innerHeight = _window.innerHeight;
|
|
1056
|
+
|
|
1057
|
+
document.body.style.position = 'fixed';
|
|
1058
|
+
document.body.style.top = -scrollY;
|
|
1059
|
+
document.body.style.left = -scrollX;
|
|
1060
|
+
|
|
1061
|
+
setTimeout(function () {
|
|
1062
|
+
return window.requestAnimationFrame(function () {
|
|
1063
|
+
// Attempt to check if the bottom bar appeared due to the position change
|
|
1064
|
+
var bottomBarHeight = innerHeight - window.innerHeight;
|
|
1065
|
+
if (bottomBarHeight && scrollY >= innerHeight) {
|
|
1066
|
+
// Move the content further up so that the bottom bar doesn't hide it
|
|
1067
|
+
document.body.style.top = -(scrollY + bottomBarHeight);
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
}, 300);
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
var restorePositionSetting = function restorePositionSetting() {
|
|
1076
|
+
if (previousBodyPosition !== undefined) {
|
|
1077
|
+
// Convert the position from "px" to Int
|
|
1078
|
+
var y = -parseInt(document.body.style.top, 10);
|
|
1079
|
+
var x = -parseInt(document.body.style.left, 10);
|
|
1080
|
+
|
|
1081
|
+
// Restore styles
|
|
1082
|
+
document.body.style.position = previousBodyPosition.position;
|
|
1083
|
+
document.body.style.top = previousBodyPosition.top;
|
|
1084
|
+
document.body.style.left = previousBodyPosition.left;
|
|
1085
|
+
|
|
1086
|
+
// Restore scroll
|
|
1087
|
+
window.scrollTo(x, y);
|
|
1088
|
+
|
|
1089
|
+
previousBodyPosition = undefined;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
|
|
1094
|
+
var isTargetElementTotallyScrolled = function isTargetElementTotallyScrolled(targetElement) {
|
|
1095
|
+
return targetElement ? targetElement.scrollHeight - targetElement.scrollTop <= targetElement.clientHeight : false;
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
var handleScroll = function handleScroll(event, targetElement) {
|
|
1099
|
+
var clientY = event.targetTouches[0].clientY - initialClientY;
|
|
1100
|
+
|
|
1101
|
+
if (allowTouchMove(event.target)) {
|
|
1102
|
+
return false;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
if (targetElement && targetElement.scrollTop === 0 && clientY > 0) {
|
|
1106
|
+
// element is at the top of its scroll.
|
|
1107
|
+
return preventDefault(event);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
if (isTargetElementTotallyScrolled(targetElement) && clientY < 0) {
|
|
1111
|
+
// element is at the bottom of its scroll.
|
|
1112
|
+
return preventDefault(event);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
event.stopPropagation();
|
|
1116
|
+
return true;
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
var disableBodyScroll = function disableBodyScroll(targetElement, options) {
|
|
1120
|
+
// targetElement must be provided
|
|
1121
|
+
if (!targetElement) {
|
|
1122
|
+
// eslint-disable-next-line no-console
|
|
1123
|
+
console.error('disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.');
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// disableBodyScroll must not have been called on this targetElement before
|
|
1128
|
+
if (locks.some(function (lock) {
|
|
1129
|
+
return lock.targetElement === targetElement;
|
|
1130
|
+
})) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
var lock = {
|
|
1135
|
+
targetElement: targetElement,
|
|
1136
|
+
options: options || {}
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
locks = [].concat(_toConsumableArray(locks), [lock]);
|
|
1140
|
+
|
|
1141
|
+
if (isIosDevice) {
|
|
1142
|
+
setPositionFixed();
|
|
1143
|
+
} else {
|
|
1144
|
+
setOverflowHidden(options);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
if (isIosDevice) {
|
|
1148
|
+
targetElement.ontouchstart = function (event) {
|
|
1149
|
+
if (event.targetTouches.length === 1) {
|
|
1150
|
+
// detect single touch.
|
|
1151
|
+
initialClientY = event.targetTouches[0].clientY;
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
targetElement.ontouchmove = function (event) {
|
|
1155
|
+
if (event.targetTouches.length === 1) {
|
|
1156
|
+
// detect single touch.
|
|
1157
|
+
handleScroll(event, targetElement);
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
|
|
1161
|
+
if (!documentListenerAdded) {
|
|
1162
|
+
document.addEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);
|
|
1163
|
+
documentListenerAdded = true;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
|
|
1168
|
+
var enableBodyScroll = function enableBodyScroll(targetElement) {
|
|
1169
|
+
if (!targetElement) {
|
|
1170
|
+
// eslint-disable-next-line no-console
|
|
1171
|
+
console.error('enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.');
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
locks = locks.filter(function (lock) {
|
|
1176
|
+
return lock.targetElement !== targetElement;
|
|
1177
|
+
});
|
|
1178
|
+
|
|
1179
|
+
if (isIosDevice) {
|
|
1180
|
+
targetElement.ontouchstart = null;
|
|
1181
|
+
targetElement.ontouchmove = null;
|
|
1182
|
+
|
|
1183
|
+
if (documentListenerAdded && locks.length === 0) {
|
|
1184
|
+
document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);
|
|
1185
|
+
documentListenerAdded = false;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
if (isIosDevice) {
|
|
1190
|
+
restorePositionSetting();
|
|
1191
|
+
} else {
|
|
1192
|
+
restoreOverflowSetting();
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
var css_248z$2 = ".EditorPlaceholder-module_editor{margin:20px 0 10px;position:relative;user-select:none;width:100%}.EditorPlaceholder-module_content{align-items:center;background-color:#efefef;border:none;border-radius:3px;color:rgba(55,53,47,.65);cursor:pointer;display:flex;font-size:14px;overflow:hidden;padding:12px 36px 12px 12px;position:relative;text-align:left;transition:background-color .1s ease-in;width:100%}.EditorPlaceholder-module_content:hover{background-color:#e3e3e3}.EditorPlaceholder-module_icon{margin-right:8px;user-select:none}";
|
|
1197
|
+
var s$2 = {"editor":"EditorPlaceholder-module_editor","content":"EditorPlaceholder-module_content","icon":"EditorPlaceholder-module_icon"};
|
|
1198
|
+
styleInject(css_248z$2);
|
|
1199
|
+
|
|
1200
|
+
function toBase64(file) {
|
|
1201
|
+
return new Promise((resolve, reject) => {
|
|
1202
|
+
const reader = new FileReader();
|
|
1203
|
+
reader.readAsDataURL(file);
|
|
1204
|
+
reader.onload = () => resolve(reader.result);
|
|
1205
|
+
reader.onerror = (error) => reject(error);
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
function getImageSizes(src) {
|
|
1210
|
+
return new Promise((resolve, reject) => {
|
|
1211
|
+
const img = new Image();
|
|
1212
|
+
img.src = src;
|
|
1213
|
+
img.onload = () => {
|
|
1214
|
+
return resolve({ width: img.width, height: img.height });
|
|
1215
|
+
};
|
|
1216
|
+
img.onerror = (e) => {
|
|
1217
|
+
return reject(e);
|
|
1218
|
+
};
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
const UPLOADER_HEIGHT = 88;
|
|
1223
|
+
const EditorPlaceholder = ({ element, accept, attributes, maxSizes, children, editor, onUpload }) => {
|
|
1224
|
+
const [uploaderPos, setUploaderPos] = useState(null);
|
|
1225
|
+
const [activeTab, setActiveTab] = useState('upload');
|
|
1226
|
+
const imageEditorRef = useRef(null);
|
|
1227
|
+
const toggleUploaderOpen = (e) => {
|
|
1228
|
+
var _a;
|
|
1229
|
+
e.stopPropagation();
|
|
1230
|
+
if (uploaderPos !== null) {
|
|
1231
|
+
enableBodyScroll(document.body);
|
|
1232
|
+
setUploaderPos(null);
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
const imageEditorRect = (_a = imageEditorRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
1236
|
+
if (imageEditorRect) {
|
|
1237
|
+
const showAtTop = imageEditorRect.top + imageEditorRect.height + UPLOADER_HEIGHT + 20 > window.innerHeight;
|
|
1238
|
+
const showAtBottom = !showAtTop;
|
|
1239
|
+
console.log({ showAtTop, showAtBottom });
|
|
1240
|
+
disableBodyScroll(document.body, { reserveScrollBarGap: true });
|
|
1241
|
+
setUploaderPos({
|
|
1242
|
+
left: imageEditorRect.left,
|
|
1243
|
+
top: showAtTop ? imageEditorRect.top - UPLOADER_HEIGHT - 5 : imageEditorRect.top + imageEditorRect.height + 5,
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
const onEmbed = (src) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1248
|
+
try {
|
|
1249
|
+
const { width, height } = yield getImageSizes(src);
|
|
1250
|
+
enableBodyScroll(document.body);
|
|
1251
|
+
setUploaderPos(null);
|
|
1252
|
+
const updatedImageNode = {
|
|
1253
|
+
data: Object.assign(Object.assign({}, element.data), { url: src, 'data-src': undefined, size: { width, height } }),
|
|
1254
|
+
};
|
|
1255
|
+
Transforms.setNodes(editor, updatedImageNode, {
|
|
1256
|
+
at: ReactEditor.findPath(editor, element),
|
|
1257
|
+
match: (n) => Element.isElement(n) && n.type === 'image',
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
catch (error) {
|
|
1261
|
+
enableBodyScroll(document.body);
|
|
1262
|
+
setUploaderPos(null);
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
const onChangeFile = (file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1266
|
+
const base64 = yield toBase64(file);
|
|
1267
|
+
base64.substring('data:image/'.length, base64.indexOf(';base64'));
|
|
1268
|
+
const optimisticImage = yield getImageSizes(base64);
|
|
1269
|
+
const aspectSizes = getAspectRatio(optimisticImage.width, optimisticImage.height, maxSizes.maxWidth, maxSizes.maxHeight);
|
|
1270
|
+
enableBodyScroll(document.body);
|
|
1271
|
+
setUploaderPos(null);
|
|
1272
|
+
const imageNode = {
|
|
1273
|
+
data: Object.assign(Object.assign({}, element.data), { 'data-src': base64, size: {
|
|
1274
|
+
width: aspectSizes.width || element.data.size.width,
|
|
1275
|
+
height: aspectSizes.height || element.data.size.height,
|
|
1276
|
+
} }),
|
|
1277
|
+
};
|
|
1278
|
+
console.log('optimistic image uploader', ReactEditor.findPath(editor, element));
|
|
1279
|
+
Transforms.setNodes(editor, imageNode, {
|
|
1280
|
+
at: ReactEditor.findPath(editor, element),
|
|
1281
|
+
match: (n) => Element.isElement(n) && n.type === 'image',
|
|
1282
|
+
});
|
|
1283
|
+
if (!onUpload)
|
|
1284
|
+
return console.error('Provide `onUpload` handler in Image options');
|
|
1285
|
+
const response = yield onUpload(file);
|
|
1286
|
+
const { width, height } = getAspectRatio(response.width, response.height, maxSizes.maxWidth, maxSizes.maxHeight);
|
|
1287
|
+
const updatedImageNode = {
|
|
1288
|
+
data: Object.assign(Object.assign({}, element.data), { url: response.url, 'data-src': undefined, size: { width: width || element.data.size.width, height: height || element.data.size.height } }),
|
|
1289
|
+
};
|
|
1290
|
+
Transforms.setNodes(editor, updatedImageNode, {
|
|
1291
|
+
at: ReactEditor.findPath(editor, element),
|
|
1292
|
+
match: (n) => Element.isElement(n) && n.type === 'image',
|
|
1293
|
+
});
|
|
1294
|
+
});
|
|
1295
|
+
return (jsxs("div", Object.assign({ className: s$2.editor }, attributes, { contentEditable: false }, { children: [jsxs("div", Object.assign({ ref: imageEditorRef }, { children: [jsxs("button", Object.assign({ className: s$2.content, onClick: toggleUploaderOpen }, { children: [jsx(SvgUpload, { className: s$2.icon, width: 24, height: 24 }), jsx("span", { children: "Click to add image" })] })), uploaderPos !== null && (jsx(EditorUploader, { onChange: onChangeFile, onEmbed: onEmbed, onClose: toggleUploaderOpen, activeTab: activeTab, switchTab: (tab) => setActiveTab(tab), style: uploaderPos, accept: accept }))] })), children] })));
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
var css_248z$1 = ".Loader-module_container{height:100%;position:relative;width:100%}.Loader-module_container .Loader-module_dot{background-color:#909090;border-radius:5rem;height:10px;position:absolute;top:50%;transform:translate(-50%,-50%);width:10px}.Loader-module_container .Loader-module_dot:first-child{animation:Loader-module_waveUp 2s,Loader-module_smallExtend 2s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% - 60px)}.Loader-module_container .Loader-module_dot:nth-child(2){animation:Loader-module_waveUp 2s,Loader-module_largeExtend 2s;animation-delay:.15s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% - 30px)}.Loader-module_container .Loader-module_dot:nth-child(3){animation:Loader-module_waveUp 2s,Loader-module_smallExtend 2s;animation-delay:.3s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:50%}.Loader-module_container .Loader-module_dot:nth-child(4){animation:Loader-module_waveUp 2s,Loader-module_largeExtend 2s;animation-delay:.45s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% + 30px)}.Loader-module_container .Loader-module_dot:nth-child(5){animation:Loader-module_waveUp 2s,Loader-module_smallExtend 2s;animation-delay:.6s;animation-iteration-count:infinite;animation-timing-function:ease-in-out;left:calc(50% + 60px)}@keyframes Loader-module_waveUp{0%,15%{top:50%}45%,65%{top:42.5%}85%,to{top:50%}}@keyframes Loader-module_smallExtend{0%,8%{background-color:#909090;height:10px}14%,34%{background-color:#f8f8f8;height:17.5px}46%,to{background-color:#909090;height:10px}}@keyframes Loader-module_largeExtend{0%,8%{background-color:#909090;height:10px}14%,34%{background-color:#f8f8f8;height:32.5px}46%,to{background-color:#909090;height:10px}}";
|
|
1299
|
+
var s$1 = {"container":"Loader-module_container","dot":"Loader-module_dot","waveUp":"Loader-module_waveUp","smallExtend":"Loader-module_smallExtend","largeExtend":"Loader-module_largeExtend"};
|
|
1300
|
+
styleInject(css_248z$1);
|
|
1301
|
+
|
|
1302
|
+
const Loader = () => {
|
|
1303
|
+
return (jsxs("div", Object.assign({ className: s$1.container }, { children: [jsx("div", { className: s$1.dot }), jsx("div", { className: s$1.dot }), jsx("div", { className: s$1.dot }), jsx("div", { className: s$1.dot }), jsx("div", { className: s$1.dot })] })));
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
var css_248z = ".ImageEditor-module_root{cursor:pointer;display:block;position:relative}.ImageEditor-module_root:hover .ImageEditor-module_dotsOptions,.ImageEditor-module_root:hover .ImageEditor-module_resizer{opacity:1}.ImageEditor-module_loadingState{pointer-events:none}.ImageEditor-module_extraMargin{margin:20px 0 30px}.ImageEditor-module_resizeLib{margin:0 auto}.ImageEditor-module_resizer{align-items:center;cursor:col-resize;display:flex;height:100%;justify-content:center;opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;width:15px;z-index:1}.ImageEditor-module_leftResizer{left:0;top:0}.ImageEditor-module_rightResizer{right:0;top:0}.ImageEditor-module_resizeItem{background:hsla(0,0%,6%,.6);border:1px solid hsla(0,0%,100%,.9);border-radius:20px;box-shadow:0 0 0 .5px #fff;height:48px;max-height:50%;opacity:1;transition:opacity .3s ease-in 0s;width:6px}.ImageEditor-module_selectImg{opacity:0}.ImageEditor-module_selected{background:rgba(35,131,226,.14);border-radius:3px;inset:0;opacity:1;pointer-events:none;position:absolute;transition:opacity .15s ease-in 0s;z-index:81}.ImageEditor-module_loader{left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}.ImageEditor-module_dotsOptions{align-items:center;background-color:#eee;border:none;border-radius:2px;cursor:pointer;display:flex;height:22px;justify-content:space-between;opacity:0;padding:0 4px;position:absolute;right:10px;top:10px;transition:opacity .15s ease-in 0s;width:22px;z-index:1}.ImageEditor-module_dot{background-color:gray;border-radius:50%;min-height:3px;min-width:3px}";
|
|
1307
|
+
var s = {"root":"ImageEditor-module_root","resizer":"ImageEditor-module_resizer","dotsOptions":"ImageEditor-module_dotsOptions","loadingState":"ImageEditor-module_loadingState","extraMargin":"ImageEditor-module_extraMargin","resizeLib":"ImageEditor-module_resizeLib","leftResizer":"ImageEditor-module_leftResizer ImageEditor-module_resizer","rightResizer":"ImageEditor-module_rightResizer ImageEditor-module_resizer","resizeItem":"ImageEditor-module_resizeItem","selectImg":"ImageEditor-module_selectImg","selected":"ImageEditor-module_selected","loader":"ImageEditor-module_loader","dot":"ImageEditor-module_dot"};
|
|
1308
|
+
styleInject(css_248z);
|
|
1309
|
+
|
|
1310
|
+
const OPTIONS_WIDTH = 265;
|
|
1311
|
+
const ImageEditorFactory = (editor, plugin) => (props) => jsx(ImageEditor, Object.assign({ editor: editor, plugin: plugin }, props));
|
|
1312
|
+
function ImageEditor(props) {
|
|
1313
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1314
|
+
const { element, editor, plugin } = props;
|
|
1315
|
+
const selected = useSelected();
|
|
1316
|
+
const readOnly = useReadOnly();
|
|
1317
|
+
const [optionsPos, setOptionsPos] = useState(null);
|
|
1318
|
+
const [size, setSize] = useState({
|
|
1319
|
+
width: ((_b = (_a = element.data) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.width) || 750,
|
|
1320
|
+
height: ((_d = (_c = element.data) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.height) || 440,
|
|
1321
|
+
});
|
|
1322
|
+
useEffect(() => {
|
|
1323
|
+
var _a, _b, _c, _d;
|
|
1324
|
+
if (element.data) {
|
|
1325
|
+
setSize({
|
|
1326
|
+
width: ((_b = (_a = element.data) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.width) || 750,
|
|
1327
|
+
height: ((_d = (_c = element.data) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.height) || 440,
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
}, [(_e = element.data) === null || _e === void 0 ? void 0 : _e.size]);
|
|
1331
|
+
const resizeProps = useMemo(() => {
|
|
1332
|
+
var _a, _b;
|
|
1333
|
+
return ({
|
|
1334
|
+
minWidth: 300,
|
|
1335
|
+
size: { width: size.width, height: size.height },
|
|
1336
|
+
maxWidth: ((_a = plugin.options) === null || _a === void 0 ? void 0 : _a.maxWidth) || 800,
|
|
1337
|
+
maxHeight: ((_b = plugin.options) === null || _b === void 0 ? void 0 : _b.maxHeight) || 720,
|
|
1338
|
+
lockAspectRatio: true,
|
|
1339
|
+
resizeRatio: 2,
|
|
1340
|
+
enable: {
|
|
1341
|
+
left: !readOnly,
|
|
1342
|
+
right: !readOnly,
|
|
1343
|
+
},
|
|
1344
|
+
handleStyles: {
|
|
1345
|
+
left: { left: 0 },
|
|
1346
|
+
right: { right: 0 },
|
|
1347
|
+
},
|
|
1348
|
+
onResize: (e, direction, ref) => {
|
|
1349
|
+
setSize({ width: ref.offsetWidth, height: ref.offsetHeight });
|
|
1350
|
+
},
|
|
1351
|
+
onResizeStop: (e, direction, ref) => {
|
|
1352
|
+
Transforms.setNodes(editor, { data: Object.assign(Object.assign({}, element.data), { size: { width: ref.offsetWidth, height: ref.offsetHeight } }) }, {
|
|
1353
|
+
at: ReactEditor.findPath(editor, element),
|
|
1354
|
+
match: (n) => Element.isElement(n) && n.type === 'image',
|
|
1355
|
+
});
|
|
1356
|
+
},
|
|
1357
|
+
handleComponent: {
|
|
1358
|
+
left: (jsx("div", Object.assign({ contentEditable: false, className: s.leftResizer }, { children: jsx("div", { className: s.resizeItem }) }))),
|
|
1359
|
+
right: (jsx("div", Object.assign({ contentEditable: false, className: s.rightResizer }, { children: jsx("div", { className: s.resizeItem }) }))),
|
|
1360
|
+
},
|
|
1361
|
+
});
|
|
1362
|
+
}, [size.width, size.height, editor]);
|
|
1363
|
+
const hasCaption = !!((_f = element.data) === null || _f === void 0 ? void 0 : _f.caption);
|
|
1364
|
+
const isLoading = !!element.data['data-src'] && !element.data.url;
|
|
1365
|
+
const closeOptions = () => {
|
|
1366
|
+
enableBodyScroll(document.body);
|
|
1367
|
+
setOptionsPos(null);
|
|
1368
|
+
};
|
|
1369
|
+
const toggleOptionsOpen = (e) => {
|
|
1370
|
+
var _a;
|
|
1371
|
+
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
1372
|
+
if (optionsPos !== null) {
|
|
1373
|
+
return closeOptions();
|
|
1374
|
+
}
|
|
1375
|
+
const optionsButtonRect = (_a = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
1376
|
+
const UPLOADER_HEIGHT = 164;
|
|
1377
|
+
if (optionsButtonRect) {
|
|
1378
|
+
const showAtTop = optionsButtonRect.top + optionsButtonRect.height + UPLOADER_HEIGHT + 20 > window.innerHeight;
|
|
1379
|
+
disableBodyScroll(document.body, { reserveScrollBarGap: true });
|
|
1380
|
+
setOptionsPos({
|
|
1381
|
+
left: optionsButtonRect.right - optionsButtonRect.width + OPTIONS_WIDTH > window.innerWidth
|
|
1382
|
+
? window.innerWidth - OPTIONS_WIDTH - optionsButtonRect.width
|
|
1383
|
+
: optionsButtonRect.right - optionsButtonRect.width,
|
|
1384
|
+
top: showAtTop
|
|
1385
|
+
? optionsButtonRect.top - UPLOADER_HEIGHT / 2 - optionsButtonRect.height
|
|
1386
|
+
: optionsButtonRect.top + optionsButtonRect.height + 5,
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
if (!element.data.url && !element.data['data-src']) {
|
|
1391
|
+
const { maxWidth = 750, maxHeight = 800 } = plugin.options || {};
|
|
1392
|
+
return (jsxs("div", Object.assign({ className: s.root, contentEditable: false, draggable: false }, { children: [jsx("div", { className: cx(s.selectImg, { [s.selected]: selected }) }), jsx(EditorPlaceholder, Object.assign({ attributes: props.attributes, element: element, editor: editor, maxSizes: { maxWidth, maxHeight }, onUpload: (_g = plugin.options) === null || _g === void 0 ? void 0 : _g.onUpload, accept: (_h = plugin.options) === null || _h === void 0 ? void 0 : _h.accept }, { children: !readOnly && (jsxs("div", { children: [jsxs("button", Object.assign({ type: "button", className: s.dotsOptions, onClick: toggleOptionsOpen }, { children: [jsx("span", { className: s.dot }), jsx("span", { className: s.dot }), jsx("span", { className: s.dot })] })), optionsPos !== null && (jsx(UI_HELPERS.ElementOptions, { onClose: closeOptions, style: optionsPos, element: element, onCopy: closeOptions, onDelete: closeOptions, onDuplicate: closeOptions }, element.id))] })) })), props.children] }), element.id));
|
|
1393
|
+
}
|
|
1394
|
+
return (jsx("div", Object.assign({ contentEditable: false, draggable: false, className: cx(s.root, { [s.extraMargin]: hasCaption, [s.loadingState]: isLoading }) }, { children: jsxs(Resizable, Object.assign({}, resizeProps, { className: s.resizeLib }, { children: [plugin.renderer.render(Object.assign(Object.assign({}, props), { size })), jsx("div", { className: cx(s.selectImg, { [s.selected]: selected }) }), isLoading && (jsx("div", Object.assign({ className: s.loader }, { children: jsx(Loader, {}) }))), !readOnly && (jsxs("div", { children: [jsxs("button", Object.assign({ type: "button", className: s.dotsOptions, onClick: toggleOptionsOpen }, { children: [jsx("span", { className: s.dot }), jsx("span", { className: s.dot }), jsx("span", { className: s.dot })] })), optionsPos !== null && (jsx(UI_HELPERS.ElementOptions, { onClose: closeOptions, style: optionsPos, element: element, onCopy: closeOptions, onDelete: closeOptions, onDuplicate: closeOptions }, element.id))] }))] })) }), element.id));
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
const Image$1 = createYooptaPlugin({
|
|
1398
|
+
type: 'image',
|
|
1399
|
+
shortcut: 'image',
|
|
1400
|
+
renderer: {
|
|
1401
|
+
// @ts-ignore [TODO: fix types]
|
|
1402
|
+
editor: ImageEditorFactory,
|
|
1403
|
+
render: Image$2,
|
|
1404
|
+
},
|
|
1405
|
+
extendEditor(editor) {
|
|
1406
|
+
const { isVoid } = editor;
|
|
1407
|
+
editor.isVoid = (element) => {
|
|
1408
|
+
return element.type === Image$1.getPlugin.type ? true : isVoid(element);
|
|
1409
|
+
};
|
|
1410
|
+
return editor;
|
|
1411
|
+
},
|
|
1412
|
+
events: {
|
|
1413
|
+
onKeyDown: (editor, { defaultNode, hotkeys }) => (event) => {
|
|
1414
|
+
var _a;
|
|
1415
|
+
const currentNode = getElementByPath(editor, (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor.path, 'highest');
|
|
1416
|
+
if (currentNode.type !== 'image' || !editor.selection)
|
|
1417
|
+
return;
|
|
1418
|
+
if (hotkeys.isEnter(event)) {
|
|
1419
|
+
event.preventDefault();
|
|
1420
|
+
Transforms.insertNodes(editor, defaultNode, { mode: 'highest' });
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
},
|
|
1424
|
+
},
|
|
1425
|
+
defineElement: () => ({
|
|
1426
|
+
id: generateId(),
|
|
1427
|
+
type: 'image',
|
|
1428
|
+
nodeType: 'void',
|
|
1429
|
+
data: { url: null, size: { width: 'auto', height: 'auto' } },
|
|
1430
|
+
children: [{ text: '' }],
|
|
1431
|
+
}),
|
|
1432
|
+
createElement: (editor, elementData) => {
|
|
1433
|
+
var _a;
|
|
1434
|
+
const node = Object.assign(Object.assign({}, Image$1.getPlugin.defineElement()), elementData);
|
|
1435
|
+
Transforms.setNodes(editor, node, {
|
|
1436
|
+
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
|
|
1437
|
+
});
|
|
1438
|
+
},
|
|
1439
|
+
exports: {
|
|
1440
|
+
markdown: {
|
|
1441
|
+
serialize: (node, children) => {
|
|
1442
|
+
return `\n`;
|
|
1443
|
+
},
|
|
1444
|
+
},
|
|
1445
|
+
html: {
|
|
1446
|
+
serialize: (node, children) => {
|
|
1447
|
+
var _a, _b;
|
|
1448
|
+
return `<img src="${node.data.url}" width="${(_a = node.data.size) === null || _a === void 0 ? void 0 : _a.width}" height="${(_b = node.data.size) === null || _b === void 0 ? void 0 : _b.height}" decoding="async" loading="lazy" alt="${node.data.caption || 'yoopta-html-image'}" />`;
|
|
1449
|
+
},
|
|
1450
|
+
deserialize: {
|
|
1451
|
+
nodeName: 'IMG',
|
|
1452
|
+
parse: (el) => ({
|
|
1453
|
+
url: el.getAttribute('src'),
|
|
1454
|
+
size: {
|
|
1455
|
+
height: typeof el.getAttribute('height') === 'string' ? Number(el.getAttribute('height')) : 'auto',
|
|
1456
|
+
width: typeof el.getAttribute('width') === 'string' ? Number(el.getAttribute('width')) : 'auto',
|
|
1457
|
+
},
|
|
1458
|
+
}),
|
|
1459
|
+
},
|
|
1460
|
+
},
|
|
1461
|
+
},
|
|
1462
|
+
options: {
|
|
1463
|
+
searchString: 'image picture',
|
|
1464
|
+
displayLabel: 'Image',
|
|
1465
|
+
},
|
|
1466
|
+
});
|
|
1467
|
+
|
|
1468
|
+
export { Image$1 as default };
|