@layers-app/editor 0.0.17 → 0.0.18

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,6 +1,6 @@
1
1
  import { jsx as a, jsxs as v, Fragment as j } from "react/jsx-runtime";
2
2
  import { useRef as k, useContext as K, useMemo as U, useEffect as P, useState as T, useCallback as y, Suspense as W } from "react";
3
- import { e as R, o as q, l as z, f as G, g as H, u as J, w as M, h as D, c as A, i as Q, F as $, N as V, j as X, K as w, k as Y, m as Z, n as ee, D as te, r as ne, p as ae, L as le, q as oe, s as re, v as ie, x as se } from "./layers.BtDUR7c8.js";
3
+ import { e as R, o as q, l as z, f as G, g as H, u as J, w as M, h as D, c as A, i as Q, F as $, N as V, j as X, K as w, k as Y, m as Z, n as ee, D as te, r as ne, p as ae, L as le, q as re, s as oe, v as ie, x as se } from "./layers.Cnf8ktNm.js";
4
4
  import { Button as ce, TextInput as ue } from "@mantine/core";
5
5
  function de(e) {
6
6
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
@@ -15,11 +15,11 @@ function O(e) {
15
15
  const t = e.transform();
16
16
  return t !== null ? /* @__PURE__ */ new Set([t]) : /* @__PURE__ */ new Set();
17
17
  }
18
- function fe({ initialEditor: e, children: t, initialNodes: n, initialTheme: c, skipCollabChecks: r }) {
19
- const i = k(!1), o = K(R);
20
- o == null && me(9);
21
- const [m, { getTheme: E }] = o, x = U(() => {
22
- const d = c || E() || void 0, p = q(o, d);
18
+ function fe({ initialEditor: e, children: t, initialNodes: n, initialTheme: c, skipCollabChecks: o }) {
19
+ const i = k(!1), r = K(R);
20
+ r == null && me(9);
21
+ const [m, { getTheme: E }] = r, x = U(() => {
22
+ const d = c || E() || void 0, p = q(r, d);
23
23
  if (d !== void 0 && (e._config.theme = d), e._parentEditor = m, n) for (let l of n) {
24
24
  let I = null, g = null;
25
25
  if (typeof l != "function") {
@@ -34,7 +34,7 @@ function fe({ initialEditor: e, children: t, initialNodes: n, initialTheme: c, s
34
34
  for (const [I, g] of l) e._nodes.set(I, { exportDOM: g.exportDOM, klass: g.klass, replace: g.replace, replaceWithKlass: g.replaceWithKlass, transforms: O(g.klass) });
35
35
  }
36
36
  return e._config.namespace = m._config.namespace, e._editable = m._editable, [e, p];
37
- }, []), { isCollabActive: b, yjsDocMap: C } = z(), u = r || i.current || C.has(e.getKey());
37
+ }, []), { isCollabActive: b, yjsDocMap: C } = z(), u = o || i.current || C.has(e.getKey());
38
38
  return P(() => {
39
39
  u && (i.current = !0);
40
40
  }, [u]), P(() => m.registerEditableListener((d) => {
@@ -46,11 +46,11 @@ function pe({
46
46
  children: t,
47
47
  className: n,
48
48
  onClick: c,
49
- disabled: r,
49
+ disabled: o,
50
50
  small: i,
51
- title: o
51
+ title: r
52
52
  }) {
53
- return /* @__PURE__ */ a(ce, { onClick: c, disabled: r, variant: "filled", children: t });
53
+ return /* @__PURE__ */ a(ce, { onClick: c, disabled: o, variant: "filled", children: t });
54
54
  }
55
55
  function ge({
56
56
  children: e,
@@ -74,7 +74,7 @@ function ve({
74
74
  value: t,
75
75
  onChange: n,
76
76
  placeholder: c = "",
77
- "data-test-id": r,
77
+ "data-test-id": o,
78
78
  type: i = "text"
79
79
  }) {
80
80
  return /* @__PURE__ */ a(
@@ -83,11 +83,11 @@ function ve({
83
83
  type: i,
84
84
  placeholder: c,
85
85
  value: t,
86
- onChange: (o) => {
87
- n(o.target.value);
86
+ onChange: (r) => {
87
+ n(r.target.value);
88
88
  },
89
89
  label: e,
90
- "data-test-id": r,
90
+ "data-test-id": o,
91
91
  mb: 10
92
92
  }
93
93
  );
@@ -107,9 +107,9 @@ function Ce({
107
107
  className: t,
108
108
  imageRef: n,
109
109
  src: c,
110
- width: r,
110
+ width: o,
111
111
  height: i,
112
- position: o
112
+ position: r
113
113
  }) {
114
114
  return be(c), /* @__PURE__ */ a(
115
115
  "img",
@@ -118,11 +118,11 @@ function Ce({
118
118
  src: c,
119
119
  alt: e,
120
120
  ref: n,
121
- "data-position": o,
121
+ "data-position": r,
122
122
  style: {
123
123
  display: "block",
124
124
  height: i,
125
- width: r
125
+ width: o
126
126
  },
127
127
  draggable: "false"
128
128
  }
@@ -133,16 +133,16 @@ function _e({
133
133
  nodeKey: t,
134
134
  onClose: n
135
135
  }) {
136
- const r = e.getEditorState().read(
136
+ const o = e.getEditorState().read(
137
137
  () => A(t)
138
- ), [i, o] = T(r.getAltText()), [m, E] = T(r.getShowCaption()), [x, b] = T(r.getPosition()), C = (p) => {
138
+ ), [i, r] = T(o.getAltText()), [m, E] = T(o.getShowCaption()), [x, b] = T(o.getPosition()), C = (p) => {
139
139
  E(p.target.checked);
140
140
  }, u = (p) => {
141
141
  b(p.target.value);
142
142
  }, d = () => {
143
143
  const p = { altText: i, position: x, showCaption: m };
144
- r && e.update(() => {
145
- r.update(p);
144
+ o && e.update(() => {
145
+ o.update(p);
146
146
  }), n();
147
147
  };
148
148
  return /* @__PURE__ */ v(j, { children: [
@@ -151,7 +151,7 @@ function _e({
151
151
  {
152
152
  label: "Alt-текст",
153
153
  placeholder: "Альтернативный текст",
154
- onChange: o,
154
+ onChange: r,
155
155
  value: i,
156
156
  "data-test-id": "image-modal-alt-text-input"
157
157
  }
@@ -199,9 +199,9 @@ function Ne({
199
199
  altText: t,
200
200
  nodeKey: n,
201
201
  width: c,
202
- height: r,
202
+ height: o,
203
203
  showCaption: i,
204
- caption: o,
204
+ caption: r,
205
205
  position: m
206
206
  }) {
207
207
  const [E, x] = G(), b = k(null), C = k(null), [u, d, p] = H(n), [l] = J(), [I, g] = T(null), S = k(null), _ = y(
@@ -219,20 +219,20 @@ function Ne({
219
219
  const h = D(), s = C.current;
220
220
  if (u && M(h) && h.getNodes().length === 1) {
221
221
  if (i)
222
- return $(null), f.preventDefault(), o.focus(), !0;
222
+ return $(null), f.preventDefault(), r.focus(), !0;
223
223
  if (s !== null && s !== document.activeElement)
224
224
  return f.preventDefault(), s.focus(), !0;
225
225
  }
226
226
  return !1;
227
227
  },
228
- [o, u, i]
228
+ [r, u, i]
229
229
  ), L = y(
230
- (f) => S.current === o || C.current === f.target ? ($(null), l.update(() => {
230
+ (f) => S.current === r || C.current === f.target ? ($(null), l.update(() => {
231
231
  d(!0);
232
232
  const h = l.getRootElement();
233
233
  h !== null && h.focus();
234
234
  }), !0) : !1,
235
- [o, l, d]
235
+ [r, l, d]
236
236
  );
237
237
  return P(() => {
238
238
  let f = !0;
@@ -316,16 +316,16 @@ function Ne({
316
316
  altText: t,
317
317
  imageRef: b,
318
318
  width: c,
319
- height: r,
319
+ height: o,
320
320
  position: m
321
321
  }
322
322
  )
323
323
  ] }),
324
- i && /* @__PURE__ */ a("div", { className: "image-caption-container", children: /* @__PURE__ */ v(fe, { initialEditor: o, children: [
324
+ i && /* @__PURE__ */ a("div", { className: "image-caption-container", children: /* @__PURE__ */ v(fe, { initialEditor: r, children: [
325
325
  /* @__PURE__ */ a(le, {}),
326
- /* @__PURE__ */ a(oe, {}),
326
+ /* @__PURE__ */ a(re, {}),
327
327
  /* @__PURE__ */ a(
328
- re,
328
+ oe,
329
329
  {
330
330
  contentEditable: /* @__PURE__ */ a(se, { className: "InlineImageNode__contentEditable" }),
331
331
  placeholder: /* @__PURE__ */ a(ge, { className: "InlineImageNode__placeholder", children: "Enter a caption..." }),
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("react"),t=require("./layers.O3pZNIRN.js"),M=require("@mantine/core");function P(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var F=P(function(e){const l=new URLSearchParams;l.append("code",e);for(let a=1;a<arguments.length;a++)l.append("v",arguments[a]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${l} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)});function R(e){const l=e.transform();return l!==null?new Set([l]):new Set}function K({initialEditor:e,children:l,initialNodes:a,initialTheme:d,skipCollabChecks:i}){const c=r.useRef(!1),o=r.useContext(t.l$1);o==null&&F(9);const[g,{getTheme:S}]=o,_=r.useMemo(()=>{const m=d||S()||void 0,h=t.o(o,m);if(m!==void 0&&(e._config.theme=m),e._parentEditor=g,a)for(let s of a){let w=null,x=null;if(typeof s!="function"){const C=s;s=C.replace,w=C.with,x=C.withKlass||null}const E=e._nodes.get(s.getType());e._nodes.set(s.getType(),{exportDOM:E?E.exportDOM:void 0,klass:s,replace:w,replaceWithKlass:x,transforms:R(s)})}else{const s=e._nodes=new Map(g._nodes);for(const[w,x]of s)e._nodes.set(w,{exportDOM:x.exportDOM,klass:x.klass,replace:x.replace,replaceWithKlass:x.replaceWithKlass,transforms:R(x.klass)})}return e._config.namespace=g._config.namespace,e._editable=g._editable,[e,h]},[]),{isCollabActive:j,yjsDocMap:b}=t.l(),f=i||c.current||b.has(e.getKey());return r.useEffect(()=>{f&&(c.current=!0)},[f]),r.useEffect(()=>g.registerEditableListener(m=>{e.setEditable(m)}),[e,g]),n.jsx(t.l$1.Provider,{value:_,children:!j||f?l:null})}function L({"data-test-id":e,children:l,className:a,onClick:d,disabled:i,small:c,title:o}){return n.jsx(M.Button,{onClick:d,disabled:i,variant:"filled",children:l})}function O({children:e,className:l}){return n.jsx("div",{className:l||"Placeholder__root",children:e})}function $({children:e,label:l,className:a,...d}){return n.jsxs("div",{className:"Input__wrapper",children:[n.jsx("label",{style:{marginTop:"-1em"},className:"Input__label",children:l}),n.jsx("select",{...d,className:a||"select",children:e})]})}function B({label:e,value:l,onChange:a,placeholder:d="","data-test-id":i,type:c="text"}){return n.jsx(M.TextInput,{type:c,placeholder:d,value:l,onChange:o=>{a(o.target.value)},label:e,"data-test-id":i,mb:10})}const y=new Set;function U(e){if(!y.has(e))throw new Promise(l=>{const a=new Image;a.src=e,a.onload=()=>{y.add(e),l(null)}})}function q({altText:e,className:l,imageRef:a,src:d,width:i,height:c,position:o}){return U(d),n.jsx("img",{className:l||void 0,src:d,alt:e,ref:a,"data-position":o,style:{display:"block",height:c,width:i},draggable:"false"})}function T({activeEditor:e,nodeKey:l,onClose:a}){const i=e.getEditorState().read(()=>t.Ct(l)),[c,o]=r.useState(i.getAltText()),[g,S]=r.useState(i.getShowCaption()),[_,j]=r.useState(i.getPosition()),b=h=>{S(h.target.checked)},f=h=>{j(h.target.value)},m=()=>{const h={altText:c,position:_,showCaption:g};i&&e.update(()=>{i.update(h)}),a()};return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{marginBottom:"1em"},children:n.jsx(B,{label:"Alt-текст",placeholder:"Альтернативный текст",onChange:o,value:c,"data-test-id":"image-modal-alt-text-input"})}),n.jsxs($,{style:{marginBottom:"1em",width:"208px"},value:_,label:"Position",name:"position",id:"position-select",onChange:f,children:[n.jsx("option",{value:"left",children:"Left"}),n.jsx("option",{value:"right",children:"Right"}),n.jsx("option",{value:"full",children:"Full Width"})]}),n.jsxs("div",{className:"Input__wrapper",children:[n.jsx("input",{id:"caption",type:"checkbox",checked:g,onChange:b}),n.jsx("label",{htmlFor:"caption",children:"Show Caption"})]}),n.jsx(L,{"data-test-id":"image-modal-file-upload-btn",onClick:()=>m(),children:"Применить"})]})}function A({src:e,altText:l,nodeKey:a,width:d,height:i,showCaption:c,caption:o,position:g}){const[S,_]=t.useModal(),j=r.useRef(null),b=r.useRef(null),[f,m,h]=t.u$1(a),[s]=t.u(),[w,x]=r.useState(null),E=r.useRef(null),C=r.useCallback(p=>{if(f&&t.wi(t.Ri())){p.preventDefault();const u=t.Ct(a);t.$isInlineImageNode(u)&&u.remove()}return!1},[f,a]),k=r.useCallback(p=>{const v=t.Ri(),u=b.current;if(f&&t.wi(v)&&v.getNodes().length===1){if(c)return t.Ft(null),p.preventDefault(),o.focus(),!0;if(u!==null&&u!==document.activeElement)return p.preventDefault(),u.focus(),!0}return!1},[o,f,c]),N=r.useCallback(p=>E.current===o||b.current===p.target?(t.Ft(null),s.update(()=>{m(!0);const v=s.getRootElement();v!==null&&v.focus()}),!0):!1,[o,s,m]);r.useEffect(()=>{let p=!0;const v=t.N(s.registerUpdateListener(({editorState:u})=>{p&&x(u.read(()=>t.Ri()))}),s.registerCommand(t.t,(u,I)=>(E.current=I,!1),t.Ks),s.registerCommand(t.r,u=>{const I=u;return I.target===j.current?(I.shiftKey?m(!f):(h(),m(!0)),!0):!1},t.Ks),s.registerCommand(t.D,u=>u.target===j.current?(u.preventDefault(),!0):!1,t.Ks),s.registerCommand(t.w,C,t.Ks),s.registerCommand(t.k,C,t.Ks),s.registerCommand(t.C,k,t.Ks),s.registerCommand(t.b,N,t.Ks));return()=>{p=!1,v()}},[h,s,f,a,C,k,N,m]);const D=f;return n.jsxs(r.Suspense,{fallback:null,children:[n.jsxs(n.Fragment,{children:[n.jsxs("div",{draggable:!1,children:[n.jsx("button",{className:"image-edit-button",ref:b,onClick:()=>{_("Update Inline Image",p=>n.jsx(T,{activeEditor:s,nodeKey:a,onClose:p}))},children:"Edit"}),n.jsx(q,{className:D?`focused ${t.wi(w)?"draggable":""}`:null,src:e,altText:l,imageRef:j,width:d,height:i,position:g})]}),c&&n.jsx("div",{className:"image-caption-container",children:n.jsxs(K,{initialEditor:o,children:[n.jsx(t.LinkPlugin,{}),n.jsx(t.FloatingTextFormatToolbarPlugin,{}),n.jsx(t.h,{contentEditable:n.jsx(t.LexicalContentEditable,{className:"InlineImageNode__contentEditable"}),placeholder:n.jsx(O,{className:"InlineImageNode__placeholder",children:"Enter a caption..."}),ErrorBoundary:t.a})]})})]}),S]})}exports.UpdateInlineImageDialog=T;exports.default=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("react"),t=require("./layers.Crl1Kzhp.js"),M=require("@mantine/core");function P(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var F=P(function(e){const l=new URLSearchParams;l.append("code",e);for(let a=1;a<arguments.length;a++)l.append("v",arguments[a]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${l} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)});function R(e){const l=e.transform();return l!==null?new Set([l]):new Set}function K({initialEditor:e,children:l,initialNodes:a,initialTheme:d,skipCollabChecks:i}){const c=r.useRef(!1),o=r.useContext(t.l$1);o==null&&F(9);const[g,{getTheme:S}]=o,_=r.useMemo(()=>{const m=d||S()||void 0,h=t.o(o,m);if(m!==void 0&&(e._config.theme=m),e._parentEditor=g,a)for(let s of a){let w=null,x=null;if(typeof s!="function"){const C=s;s=C.replace,w=C.with,x=C.withKlass||null}const E=e._nodes.get(s.getType());e._nodes.set(s.getType(),{exportDOM:E?E.exportDOM:void 0,klass:s,replace:w,replaceWithKlass:x,transforms:R(s)})}else{const s=e._nodes=new Map(g._nodes);for(const[w,x]of s)e._nodes.set(w,{exportDOM:x.exportDOM,klass:x.klass,replace:x.replace,replaceWithKlass:x.replaceWithKlass,transforms:R(x.klass)})}return e._config.namespace=g._config.namespace,e._editable=g._editable,[e,h]},[]),{isCollabActive:b,yjsDocMap:v}=t.l(),f=i||c.current||v.has(e.getKey());return r.useEffect(()=>{f&&(c.current=!0)},[f]),r.useEffect(()=>g.registerEditableListener(m=>{e.setEditable(m)}),[e,g]),n.jsx(t.l$1.Provider,{value:_,children:!b||f?l:null})}function L({"data-test-id":e,children:l,className:a,onClick:d,disabled:i,small:c,title:o}){return n.jsx(M.Button,{onClick:d,disabled:i,variant:"filled",children:l})}function O({children:e,className:l}){return n.jsx("div",{className:l||"Placeholder__root",children:e})}function $({children:e,label:l,className:a,...d}){return n.jsxs("div",{className:"Input__wrapper",children:[n.jsx("label",{style:{marginTop:"-1em"},className:"Input__label",children:l}),n.jsx("select",{...d,className:a||"select",children:e})]})}function B({label:e,value:l,onChange:a,placeholder:d="","data-test-id":i,type:c="text"}){return n.jsx(M.TextInput,{type:c,placeholder:d,value:l,onChange:o=>{a(o.target.value)},label:e,"data-test-id":i,mb:10})}const y=new Set;function U(e){if(!y.has(e))throw new Promise(l=>{const a=new Image;a.src=e,a.onload=()=>{y.add(e),l(null)}})}function q({altText:e,className:l,imageRef:a,src:d,width:i,height:c,position:o}){return U(d),n.jsx("img",{className:l||void 0,src:d,alt:e,ref:a,"data-position":o,style:{display:"block",height:c,width:i},draggable:"false"})}function T({activeEditor:e,nodeKey:l,onClose:a}){const i=e.getEditorState().read(()=>t.Ct(l)),[c,o]=r.useState(i.getAltText()),[g,S]=r.useState(i.getShowCaption()),[_,b]=r.useState(i.getPosition()),v=h=>{S(h.target.checked)},f=h=>{b(h.target.value)},m=()=>{const h={altText:c,position:_,showCaption:g};i&&e.update(()=>{i.update(h)}),a()};return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{marginBottom:"1em"},children:n.jsx(B,{label:"Alt-текст",placeholder:"Альтернативный текст",onChange:o,value:c,"data-test-id":"image-modal-alt-text-input"})}),n.jsxs($,{style:{marginBottom:"1em",width:"208px"},value:_,label:"Position",name:"position",id:"position-select",onChange:f,children:[n.jsx("option",{value:"left",children:"Left"}),n.jsx("option",{value:"right",children:"Right"}),n.jsx("option",{value:"full",children:"Full Width"})]}),n.jsxs("div",{className:"Input__wrapper",children:[n.jsx("input",{id:"caption",type:"checkbox",checked:g,onChange:v}),n.jsx("label",{htmlFor:"caption",children:"Show Caption"})]}),n.jsx(L,{"data-test-id":"image-modal-file-upload-btn",onClick:()=>m(),children:"Применить"})]})}function A({src:e,altText:l,nodeKey:a,width:d,height:i,showCaption:c,caption:o,position:g}){const[S,_]=t.useModal(),b=r.useRef(null),v=r.useRef(null),[f,m,h]=t.u$1(a),[s]=t.u(),[w,x]=r.useState(null),E=r.useRef(null),C=r.useCallback(p=>{if(f&&t.wi(t.Ri())){p.preventDefault();const u=t.Ct(a);t.$isInlineImageNode(u)&&u.remove()}return!1},[f,a]),k=r.useCallback(p=>{const j=t.Ri(),u=v.current;if(f&&t.wi(j)&&j.getNodes().length===1){if(c)return t.Ft(null),p.preventDefault(),o.focus(),!0;if(u!==null&&u!==document.activeElement)return p.preventDefault(),u.focus(),!0}return!1},[o,f,c]),N=r.useCallback(p=>E.current===o||v.current===p.target?(t.Ft(null),s.update(()=>{m(!0);const j=s.getRootElement();j!==null&&j.focus()}),!0):!1,[o,s,m]);r.useEffect(()=>{let p=!0;const j=t.N(s.registerUpdateListener(({editorState:u})=>{p&&x(u.read(()=>t.Ri()))}),s.registerCommand(t.t,(u,I)=>(E.current=I,!1),t.Ks),s.registerCommand(t.r,u=>{const I=u;return I.target===b.current?(I.shiftKey?m(!f):(h(),m(!0)),!0):!1},t.Ks),s.registerCommand(t.D,u=>u.target===b.current?(u.preventDefault(),!0):!1,t.Ks),s.registerCommand(t.w,C,t.Ks),s.registerCommand(t.k,C,t.Ks),s.registerCommand(t.C,k,t.Ks),s.registerCommand(t.b,N,t.Ks));return()=>{p=!1,j()}},[h,s,f,a,C,k,N,m]);const D=f;return n.jsxs(r.Suspense,{fallback:null,children:[n.jsxs(n.Fragment,{children:[n.jsxs("div",{draggable:!1,children:[n.jsx("button",{className:"image-edit-button",ref:v,onClick:()=>{_("Update Inline Image",p=>n.jsx(T,{activeEditor:s,nodeKey:a,onClose:p}))},children:"Edit"}),n.jsx(q,{className:D?`focused ${t.wi(w)?"draggable":""}`:null,src:e,altText:l,imageRef:b,width:d,height:i,position:g})]}),c&&n.jsx("div",{className:"image-caption-container",children:n.jsxs(K,{initialEditor:o,children:[n.jsx(t.LinkPlugin,{}),n.jsx(t.FloatingTextFormatToolbarPlugin,{}),n.jsx(t.h,{contentEditable:n.jsx(t.LexicalContentEditable,{className:"InlineImageNode__contentEditable"}),placeholder:n.jsx(O,{className:"InlineImageNode__placeholder",children:"Enter a caption..."}),ErrorBoundary:t.a})]})})]}),S]})}exports.UpdateInlineImageDialog=T;exports.default=A;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),s=require("react"),_=require("react-i18next"),t=require("./layers.Crl1Kzhp.js"),E=require("@mantine/core"),U=require("@tabler/icons-react"),A=i=>{const{width:g,height:r,isLoading:l,isError:h,src:f,id:m,altText:p,imageRef:j,maxWidth:v}=i;return n.jsxs("div",{className:"media-wrapper",style:{width:g,height:r,display:"inline-flex",position:"relative"},children:[n.jsx(E.LoadingOverlay,{visible:l,zIndex:1e3,overlayProps:{backgroundOpacity:.5},loaderProps:{size:24,color:"black"}}),n.jsx(E.LoadingOverlay,{visible:h,zIndex:1e3,overlayProps:{backgroundOpacity:.5},loaderProps:{children:n.jsx(E.Flex,{bg:"white",maw:300,justify:"center",children:n.jsx(E.Alert,{variant:"light",color:"red",title:"Ошибка загрузки",icon:n.jsx(U.IconInfoCircle,{}),children:"Попробуйте загрузить заново."})})}}),n.jsx(B,{className:null,src:f,altText:p,imageRef:j,width:"inherit",height:"inherit",maxWidth:v||"auto",id:m})]})};function B({altText:i,className:g,imageRef:r,src:l,width:h,height:f,maxWidth:m,id:p}){return n.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:j,create:v,alignment:D}){const M=s.useRef(null),[W,S]=s.useState(!0),[P,F]=s.useState(!1),{isCollabActive:R}=t.l(),[u]=t.u(),[x,b]=s.useState(!0),[d,w]=s.useState({width:0,height:0}),{fetchUploadMedia:O,fetchDeleteMedia:z}=s.useContext(t.Context),{t:y}=_.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),F(!0)}},[i]);const H=(e,a)=>{u.update(()=>{t.Ft(null);const c=t.Ct(r);t.$isImageNode(c)&&c.setWidthAndHeight(e,a)})},{historyState:L}=t.useSharedHistoryContext(),{settings:{showNestedEditorTreeView:k}}=t.useSettings(),[C,I]=s.useState(!1);function T(e){return e.endsWith(".svg")||e.includes("image/svg+xml")}function $(e){return new Promise((a,c)=>{if(T(e)){a(0);return}const o=new Image;o.src=e,o.onload=()=>{a(o.width)},o.onerror=()=>{c(new Error("Failed to load image"))}})}return s.useEffect(()=>{v&&I(!0)},[v]),s.useEffect(()=>{let e=l,a=h,c=100;i&&$(i).then(o=>{typeof e=="number"&&e<c&&o<c?(b(!0),w({width:e,height:a})):o<c?(b(!0),w({width:"auto",height:"auto"})):(w({width:o,height:o}),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?n.jsx(A,{width:d.width,height:d.height,isLoading:W,isError:P,isIcon:x,src:i,id:j,editor:u,nodeKey:r,fetchDeleteMedia:z,altText:g,imageRef:M,maxWidth:f,showCaption:m,caption:p,isCollabActive:R,historyState:L,showNestedEditorTreeView:k,t:y}):n.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:H,alignment:D,children:n.jsx(A,{width:"inherit",height:"inherit",isLoading:W,isError:P,isIcon:x,src:i,id:j,editor:u,nodeKey:r,fetchDeleteMedia:z,altText:g,imageRef:M,maxWidth:f,showCaption:m,caption:p,isCollabActive:R,historyState:L,showNestedEditorTreeView:k,t:y})}):n.jsx(t.ImagePicker,{uploading:!1,onUpload:e=>{!O||!e.length||(e.forEach((a,c)=>{O(a,(o,q)=>{c===0?u.update(()=>{const N=t.Ct(r);t.$isImageNode(N)&&(N.setSrc(o),N.setId(q))}):u.dispatchCommand(t.INSERT_IMAGE_COMMAND,{altText:"",src:o,id:q})})}),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:n.jsx(t.EmptyNodeButton,{title:y("editor.image.add_photo"),icon:"photo",onClick:()=>I(!C)})})}exports.default=G;