@layers-app/editor 0.0.17 → 0.0.19

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.
@@ -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.C31Xdz2y.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;
@@ -1,10 +1,10 @@
1
1
  import { jsx as o, jsxs as G } from "react/jsx-runtime";
2
- import { useRef as V, useState as I, useContext as q, useEffect as v } from "react";
2
+ import { useRef as V, useState as I, useContext as q, useEffect as w } from "react";
3
3
  import { useTranslation as J } from "react-i18next";
4
- import { l as Q, u as X, C as Y, a as Z, b as K, c as C, $ as E, t as ee, I as te, E as ie, d as oe, R as ne, F as ae } from "./layers.BtDUR7c8.js";
5
- import { LoadingOverlay as T, Flex as se, Alert as re } from "@mantine/core";
4
+ import { l as Q, u as X, C as Y, a as Z, b as K, c as C, $ as E, t as ee, I as te, E as ie, d as oe, R as ne, F as ae } from "./layers.q72Rt2k1.js";
5
+ import { LoadingOverlay as H, Flex as se, Alert as re } from "@mantine/core";
6
6
  import { IconInfoCircle as le } from "@tabler/icons-react";
7
- const j = (t) => {
7
+ const T = (t) => {
8
8
  const {
9
9
  width: c,
10
10
  height: a,
@@ -13,8 +13,8 @@ const j = (t) => {
13
13
  src: g,
14
14
  id: f,
15
15
  altText: u,
16
- imageRef: w,
17
- maxWidth: b
16
+ imageRef: b,
17
+ maxWidth: v
18
18
  } = t;
19
19
  return /* @__PURE__ */ G(
20
20
  "div",
@@ -28,7 +28,7 @@ const j = (t) => {
28
28
  },
29
29
  children: [
30
30
  /* @__PURE__ */ o(
31
- T,
31
+ H,
32
32
  {
33
33
  visible: s,
34
34
  zIndex: 1e3,
@@ -37,7 +37,7 @@ const j = (t) => {
37
37
  }
38
38
  ),
39
39
  /* @__PURE__ */ o(
40
- T,
40
+ H,
41
41
  {
42
42
  visible: d,
43
43
  zIndex: 1e3,
@@ -62,10 +62,10 @@ const j = (t) => {
62
62
  className: null,
63
63
  src: g,
64
64
  altText: u,
65
- imageRef: w,
65
+ imageRef: b,
66
66
  width: "inherit",
67
67
  height: "inherit",
68
- maxWidth: b || "auto",
68
+ maxWidth: v || "auto",
69
69
  id: f
70
70
  }
71
71
  )
@@ -109,22 +109,22 @@ function pe({
109
109
  maxWidth: g,
110
110
  showCaption: f,
111
111
  caption: u,
112
- id: w,
113
- create: b,
114
- alignment: _
112
+ id: b,
113
+ create: v,
114
+ alignment: j
115
115
  }) {
116
- const z = V(null), [R, y] = I(!0), [k, D] = I(!1), { isCollabActive: A } = Q(), [h] = X(), [m, S] = I(!0), [r, W] = I({
116
+ const P = V(null), [z, y] = I(!0), [R, _] = I(!1), { isCollabActive: k } = Q(), [h] = X(), [m, S] = I(!0), [r, W] = I({
117
117
  width: 0,
118
118
  height: 0
119
- }), { fetchUploadImage: F, fetchDeleteImage: L } = q(Y), { t: N } = J();
120
- v(() => {
119
+ }), { fetchUploadMedia: A, fetchDeleteMedia: F } = q(Y), { t: M } = J();
120
+ w(() => {
121
121
  if (!t || t.startsWith("data:image/")) {
122
122
  y(!1);
123
123
  return;
124
124
  }
125
125
  const e = new Image();
126
126
  e.src = t, e.onload = () => y(!1), e.onerror = () => {
127
- y(!1), D(!0);
127
+ y(!1), _(!0);
128
128
  };
129
129
  }, [t]);
130
130
  const U = (e, n) => {
@@ -133,8 +133,8 @@ function pe({
133
133
  const l = C(a);
134
134
  E(l) && l.setWidthAndHeight(e, n);
135
135
  });
136
- }, { historyState: O } = Z(), {
137
- settings: { showNestedEditorTreeView: H }
136
+ }, { historyState: L } = Z(), {
137
+ settings: { showNestedEditorTreeView: O }
138
138
  } = K(), [x, p] = I(!1);
139
139
  function $(e) {
140
140
  return e.endsWith(".svg") || e.includes("image/svg+xml");
@@ -153,9 +153,9 @@ function pe({
153
153
  };
154
154
  });
155
155
  }
156
- return v(() => {
157
- b && p(!0);
158
- }, [b]), v(() => {
156
+ return w(() => {
157
+ v && p(!0);
158
+ }, [v]), w(() => {
159
159
  let e = s, n = d, l = 100;
160
160
  t && B(t).then((i) => {
161
161
  typeof e == "number" && e < l && i < l ? (S(!0), W({
@@ -169,36 +169,36 @@ function pe({
169
169
  height: i
170
170
  }), S(!1));
171
171
  });
172
- }, [t]), v(() => {
172
+ }, [t]), w(() => {
173
173
  r.width && r.height && m && h.update(() => {
174
174
  const e = C(a);
175
175
  E(e) && e.setWidthAndHeight(r.width, r.height);
176
176
  });
177
- }, [r.width, r.height, m]), v(() => {
177
+ }, [r.width, r.height, m]), w(() => {
178
178
  const e = document.documentElement;
179
179
  ee(x, e);
180
180
  }, [x]), t ? m ? /* @__PURE__ */ o(
181
- j,
181
+ T,
182
182
  {
183
183
  width: r.width,
184
184
  height: r.height,
185
- isLoading: R,
186
- isError: k,
185
+ isLoading: z,
186
+ isError: R,
187
187
  isIcon: m,
188
188
  src: t,
189
- id: w,
189
+ id: b,
190
190
  editor: h,
191
191
  nodeKey: a,
192
- fetchDeleteImage: L,
192
+ fetchDeleteMedia: F,
193
193
  altText: c,
194
- imageRef: z,
194
+ imageRef: P,
195
195
  maxWidth: g,
196
196
  showCaption: f,
197
197
  caption: u,
198
- isCollabActive: A,
199
- historyState: O,
200
- showNestedEditorTreeView: H,
201
- t: N
198
+ isCollabActive: k,
199
+ historyState: L,
200
+ showNestedEditorTreeView: O,
201
+ t: M
202
202
  }
203
203
  ) : /* @__PURE__ */ o(
204
204
  ne,
@@ -210,29 +210,29 @@ function pe({
210
210
  initialWidth: r.width || "",
211
211
  initialHeight: r.height || "",
212
212
  onResizeEnd: U,
213
- alignment: _,
213
+ alignment: j,
214
214
  children: /* @__PURE__ */ o(
215
- j,
215
+ T,
216
216
  {
217
217
  width: "inherit",
218
218
  height: "inherit",
219
- isLoading: R,
220
- isError: k,
219
+ isLoading: z,
220
+ isError: R,
221
221
  isIcon: m,
222
222
  src: t,
223
- id: w,
223
+ id: b,
224
224
  editor: h,
225
225
  nodeKey: a,
226
- fetchDeleteImage: L,
226
+ fetchDeleteMedia: F,
227
227
  altText: c,
228
- imageRef: z,
228
+ imageRef: P,
229
229
  maxWidth: g,
230
230
  showCaption: f,
231
231
  caption: u,
232
- isCollabActive: A,
233
- historyState: O,
234
- showNestedEditorTreeView: H,
235
- t: N
232
+ isCollabActive: k,
233
+ historyState: L,
234
+ showNestedEditorTreeView: O,
235
+ t: M
236
236
  }
237
237
  )
238
238
  }
@@ -241,15 +241,15 @@ function pe({
241
241
  {
242
242
  uploading: !1,
243
243
  onUpload: (e) => {
244
- !F || !e.length || (e.forEach((n, l) => {
245
- F(n, (i, M) => {
244
+ !A || !e.length || (e.forEach((n, l) => {
245
+ A(n, (i, D) => {
246
246
  l === 0 ? h.update(() => {
247
- const P = C(a);
248
- E(P) && (P.setSrc(i), P.setId(M));
247
+ const N = C(a);
248
+ E(N) && (N.setSrc(i), N.setId(D));
249
249
  }) : h.dispatchCommand(oe, {
250
250
  altText: "",
251
251
  src: i,
252
- id: M
252
+ id: D
253
253
  });
254
254
  });
255
255
  }), p(!1));
@@ -268,7 +268,7 @@ function pe({
268
268
  children: /* @__PURE__ */ o(
269
269
  ie,
270
270
  {
271
- title: N("editor.image.add_photo"),
271
+ title: M("editor.image.add_photo"),
272
272
  icon: "photo",
273
273
  onClick: () => p(!x)
274
274
  }
@@ -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.q72Rt2k1.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..." }),