@layers-app/editor 0.0.17-editor → 0.0.17

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),s=require("react"),D=require("react-i18next"),t=require("./layers.BGNmu1a1.js"),E=require("@mantine/core"),U=require("@tabler/icons-react"),F=i=>{const{width:g,height:r,isLoading:l,isError:h,src:f,id:m,altText:p,imageRef:v,maxWidth:j}=i;return o.jsxs("div",{className:"media-wrapper",style:{width:g,height:r,display:"inline-flex",position:"relative"},children:[o.jsx(E.LoadingOverlay,{visible:l,zIndex:1e3,overlayProps:{backgroundOpacity:.5},loaderProps:{size:24,color:"black"}}),o.jsx(E.LoadingOverlay,{visible:h,zIndex:1e3,overlayProps:{backgroundOpacity:.5},loaderProps:{children:o.jsx(E.Flex,{bg:"white",maw:300,justify:"center",children:o.jsx(E.Alert,{variant:"light",color:"red",title:"Ошибка загрузки",icon:o.jsx(U.IconInfoCircle,{}),children:"Попробуйте загрузить заново."})})}}),o.jsx(B,{className:null,src:f,altText:p,imageRef:v,width:"inherit",height:"inherit",maxWidth:j||"auto",id:m})]})};function B({altText:i,className:g,imageRef:r,src:l,width:h,height:f,maxWidth:m,id:p}){return o.jsx("img",{className:g||void 0,src:l,alt:i,ref:r,style:{height:f,maxWidth:m,width:h},draggable:"false","data-id":p})}function G({src:i,altText:g,nodeKey:r,width:l,height:h,maxWidth:f,showCaption:m,caption:p,id:v,create:j,alignment:H}){const W=s.useRef(null),[P,S]=s.useState(!0),[R,M]=s.useState(!1),{isCollabActive:O}=t.l(),[u]=t.u(),[x,b]=s.useState(!0),[d,w]=s.useState({width:0,height:0}),{fetchUploadImage:z,fetchDeleteImage:L}=s.useContext(t.Context),{t:y}=D.useTranslation();s.useEffect(()=>{if(!i||i.startsWith("data:image/")){S(!1);return}const e=new Image;e.src=i,e.onload=()=>S(!1),e.onerror=()=>{S(!1),M(!0)}},[i]);const T=(e,a)=>{u.update(()=>{t.Ft(null);const c=t.Ct(r);t.$isImageNode(c)&&c.setWidthAndHeight(e,a)})},{historyState:k}=t.useSharedHistoryContext(),{settings:{showNestedEditorTreeView:q}}=t.useSettings(),[C,I]=s.useState(!1);function $(e){return e.endsWith(".svg")||e.includes("image/svg+xml")}function _(e){return new Promise((a,c)=>{if($(e)){a(0);return}const n=new Image;n.src=e,n.onload=()=>{a(n.width)},n.onerror=()=>{c(new Error("Failed to load image"))}})}return s.useEffect(()=>{j&&I(!0)},[j]),s.useEffect(()=>{let e=l,a=h,c=100;i&&_(i).then(n=>{typeof e=="number"&&e<c&&n<c?(b(!0),w({width:e,height:a})):n<c?(b(!0),w({width:"auto",height:"auto"})):(w({width:n,height:n}),b(!1))})},[i]),s.useEffect(()=>{d.width&&d.height&&x&&u.update(()=>{const e=t.Ct(r);t.$isImageNode(e)&&e.setWidthAndHeight(d.width,d.height)})},[d.width,d.height,x]),s.useEffect(()=>{const e=document.documentElement;t.toggleLockScroll(C,e)},[C]),i?x?o.jsx(F,{width:d.width,height:d.height,isLoading:P,isError:R,isIcon:x,src:i,id:v,editor:u,nodeKey:r,fetchDeleteImage:L,altText:g,imageRef:W,maxWidth:f,showCaption:m,caption:p,isCollabActive:O,historyState:k,showNestedEditorTreeView:q,t:y}):o.jsx(t.ResizableContainer,{editor:u,isIcon:x,width:typeof l=="string"&&l.includes("%")?parseFloat(l):l,height:typeof h=="string"&&h.includes("%")?parseFloat(h):l,initialWidth:d.width||"",initialHeight:d.height||"",onResizeEnd:T,alignment:H,children:o.jsx(F,{width:"inherit",height:"inherit",isLoading:P,isError:R,isIcon:x,src:i,id:v,editor:u,nodeKey:r,fetchDeleteImage:L,altText:g,imageRef:W,maxWidth:f,showCaption:m,caption:p,isCollabActive:O,historyState:k,showNestedEditorTreeView:q,t:y})}):o.jsx(t.ImagePicker,{uploading:!1,onUpload:e=>{!z||!e.length||(e.forEach((a,c)=>{z(a,(n,A)=>{c===0?u.update(()=>{const N=t.Ct(r);t.$isImageNode(N)&&(N.setSrc(n),N.setId(A))}):u.dispatchCommand(t.INSERT_IMAGE_COMMAND,{altText:"",src:n,id:A})})}),I(!1))},popoverProps:{opened:C,position:"bottom",onChange:I},onChange:e=>{I(!1),u.update(()=>{const a=t.Ct(r);t.$isImageNode(a)&&a.setSrc(e)})},children:o.jsx(t.EmptyNodeButton,{title:y("editor.image.add_photo"),icon:"photo",onClick:()=>I(!C)})})}exports.default=G;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),s=require("react"),D=require("react-i18next"),t=require("./layers.O3pZNIRN.js"),E=require("@mantine/core"),U=require("@tabler/icons-react"),F=i=>{const{width:g,height:r,isLoading:l,isError:h,src:f,id:m,altText:p,imageRef:v,maxWidth:j}=i;return o.jsxs("div",{className:"media-wrapper",style:{width:g,height:r,display:"inline-flex",position:"relative"},children:[o.jsx(E.LoadingOverlay,{visible:l,zIndex:1e3,overlayProps:{backgroundOpacity:.5},loaderProps:{size:24,color:"black"}}),o.jsx(E.LoadingOverlay,{visible:h,zIndex:1e3,overlayProps:{backgroundOpacity:.5},loaderProps:{children:o.jsx(E.Flex,{bg:"white",maw:300,justify:"center",children:o.jsx(E.Alert,{variant:"light",color:"red",title:"Ошибка загрузки",icon:o.jsx(U.IconInfoCircle,{}),children:"Попробуйте загрузить заново."})})}}),o.jsx(B,{className:null,src:f,altText:p,imageRef:v,width:"inherit",height:"inherit",maxWidth:j||"auto",id:m})]})};function B({altText:i,className:g,imageRef:r,src:l,width:h,height:f,maxWidth:m,id:p}){return o.jsx("img",{className:g||void 0,src:l,alt:i,ref:r,style:{height:f,maxWidth:m,width:h},draggable:"false","data-id":p})}function G({src:i,altText:g,nodeKey:r,width:l,height:h,maxWidth:f,showCaption:m,caption:p,id:v,create:j,alignment:H}){const W=s.useRef(null),[P,S]=s.useState(!0),[R,M]=s.useState(!1),{isCollabActive:O}=t.l(),[u]=t.u(),[x,b]=s.useState(!0),[d,w]=s.useState({width:0,height:0}),{fetchUploadImage:z,fetchDeleteImage:L}=s.useContext(t.Context),{t:y}=D.useTranslation();s.useEffect(()=>{if(!i||i.startsWith("data:image/")){S(!1);return}const e=new Image;e.src=i,e.onload=()=>S(!1),e.onerror=()=>{S(!1),M(!0)}},[i]);const T=(e,a)=>{u.update(()=>{t.Ft(null);const c=t.Ct(r);t.$isImageNode(c)&&c.setWidthAndHeight(e,a)})},{historyState:k}=t.useSharedHistoryContext(),{settings:{showNestedEditorTreeView:q}}=t.useSettings(),[C,I]=s.useState(!1);function $(e){return e.endsWith(".svg")||e.includes("image/svg+xml")}function _(e){return new Promise((a,c)=>{if($(e)){a(0);return}const n=new Image;n.src=e,n.onload=()=>{a(n.width)},n.onerror=()=>{c(new Error("Failed to load image"))}})}return s.useEffect(()=>{j&&I(!0)},[j]),s.useEffect(()=>{let e=l,a=h,c=100;i&&_(i).then(n=>{typeof e=="number"&&e<c&&n<c?(b(!0),w({width:e,height:a})):n<c?(b(!0),w({width:"auto",height:"auto"})):(w({width:n,height:n}),b(!1))})},[i]),s.useEffect(()=>{d.width&&d.height&&x&&u.update(()=>{const e=t.Ct(r);t.$isImageNode(e)&&e.setWidthAndHeight(d.width,d.height)})},[d.width,d.height,x]),s.useEffect(()=>{const e=document.documentElement;t.toggleLockScroll(C,e)},[C]),i?x?o.jsx(F,{width:d.width,height:d.height,isLoading:P,isError:R,isIcon:x,src:i,id:v,editor:u,nodeKey:r,fetchDeleteImage:L,altText:g,imageRef:W,maxWidth:f,showCaption:m,caption:p,isCollabActive:O,historyState:k,showNestedEditorTreeView:q,t:y}):o.jsx(t.ResizableContainer,{editor:u,isIcon:x,width:typeof l=="string"&&l.includes("%")?parseFloat(l):l,height:typeof h=="string"&&h.includes("%")?parseFloat(h):l,initialWidth:d.width||"",initialHeight:d.height||"",onResizeEnd:T,alignment:H,children:o.jsx(F,{width:"inherit",height:"inherit",isLoading:P,isError:R,isIcon:x,src:i,id:v,editor:u,nodeKey:r,fetchDeleteImage:L,altText:g,imageRef:W,maxWidth:f,showCaption:m,caption:p,isCollabActive:O,historyState:k,showNestedEditorTreeView:q,t:y})}):o.jsx(t.ImagePicker,{uploading:!1,onUpload:e=>{!z||!e.length||(e.forEach((a,c)=>{z(a,(n,A)=>{c===0?u.update(()=>{const N=t.Ct(r);t.$isImageNode(N)&&(N.setSrc(n),N.setId(A))}):u.dispatchCommand(t.INSERT_IMAGE_COMMAND,{altText:"",src:n,id:A})})}),I(!1))},popoverProps:{opened:C,position:"bottom",onChange:I},onChange:e=>{I(!1),u.update(()=>{const a=t.Ct(r);t.$isImageNode(a)&&a.setSrc(e)})},children:o.jsx(t.EmptyNodeButton,{title:y("editor.image.add_photo"),icon:"photo",onClick:()=>I(!C)})})}exports.default=G;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@layers-app/editor",
3
3
  "private": false,
4
- "version": "0.0.17-editor",
4
+ "version": "0.0.17",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "vite --mode full",
@@ -25,7 +25,7 @@
25
25
  "main": "dist/index.js",
26
26
  "types": "dist/index.d.ts",
27
27
  "dependencies": {
28
- "@layers-app/shared": "^0.0.23",
28
+ "@layers-app/shared": "^0.0.24",
29
29
  "@lexical/headless": "0.21.0",
30
30
  "@lexical/markdown": "0.21.0",
31
31
  "@lexical/react": "0.21.0",