@layers-app/editor 0.0.10 → 0.0.12

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,111 +1,111 @@
1
1
  import { jsx as g, jsxs as $, Fragment as F } from "react/jsx-runtime";
2
- import { useState as U, useMemo as V, useLayoutEffect as Y, useEffect as b, Suspense as q, useRef as W } from "react";
3
- import { N as T, D as G, R as a, o as c, p as u, q as J, s as Q, v as A, x as Z, A as ee, z as te, H as ne, d as re, y as M, e as oe, E as S, k as se, G as ie, I as O, J as X, M as ae, O as ce, P as le, Q as ue, S as de, T as fe, U as me, V as ge, b as B, W as pe, X as Ce, Y as he, Z as ye, _ as ve, a0 as Ee, a1 as we, n as ke, a2 as De, a3 as be, a4 as Le, g as Re, i as Se, C as x, a5 as P } from "./DSD.CLhKx58f.js";
4
- import { d as xe, P as Pe } from "./DSD.AwtUbg5v.js";
2
+ import { useState as Y, useMemo as V, useLayoutEffect as I, useEffect as b, Suspense as q, useRef as A } from "react";
3
+ import { N as T, D as G, g as i, z as c, A as u, G as J, H as Q, J as W, M as Z, O as ee, P as te, Q as ne, j as re, S as z, m as oe, T as S, k as se, U as ae, V as M, W as O, X as ie, Y as ce, Z as le, _ as ue, a0 as de, a1 as fe, a2 as me, a3 as ge, u as B, a4 as pe, a5 as Ce, a6 as he, a7 as ye, a8 as ve, a9 as Ee, aa as we, l as ke, a as De, ab as be, ac as Le, q as Re, s as Se, c as x, ad as P } from "./layers.D0SxWFme.js";
4
+ import { d as xe, P as Pe } from "./layers.CJQEaaIH.js";
5
5
  import { flushSync as $e, createPortal as Ne } from "react-dom";
6
- const E = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0, Te = E && "documentMode" in document ? document.documentMode : null, Be = !(!E || !("InputEvent" in window) || Te) && "getTargetRanges" in new window.InputEvent("input"), _e = E && /Version\/[\d.]+.*Safari/.test(navigator.userAgent), z = E && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, We = E && /^(?=.*Chrome).*/i.test(navigator.userAgent), Ae = E && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !We;
7
- function I(n, t) {
6
+ const E = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0, Te = E && "documentMode" in document ? document.documentMode : null, Be = !(!E || !("InputEvent" in window) || Te) && "getTargetRanges" in new window.InputEvent("input"), _e = E && /Version\/[\d.]+.*Safari/.test(navigator.userAgent), X = E && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, Ae = E && /^(?=.*Chrome).*/i.test(navigator.userAgent), We = E && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !Ae;
7
+ function K(n, t) {
8
8
  t.update(() => {
9
9
  if (n !== null) {
10
- const e = me(n, KeyboardEvent) ? null : n.clipboardData, s = a();
10
+ const e = me(n, KeyboardEvent) ? null : n.clipboardData, s = i();
11
11
  if (s !== null && e != null) {
12
12
  n.preventDefault();
13
- const i = ge(t);
14
- i !== null && e.setData("text/html", i), e.setData("text/plain", s.getTextContent());
13
+ const a = ge(t);
14
+ a !== null && e.setData("text/html", a), e.setData("text/plain", s.getTextContent());
15
15
  }
16
16
  }
17
17
  });
18
18
  }
19
- function Me(n) {
19
+ function ze(n) {
20
20
  return T(n.registerCommand(S, (t) => {
21
- const e = a();
21
+ const e = i();
22
22
  return !!c(e) && (e.deleteCharacter(t), !0);
23
23
  }, u), n.registerCommand(fe, (t) => {
24
- const e = a();
24
+ const e = i();
25
25
  return !!c(e) && (e.deleteWord(t), !0);
26
26
  }, u), n.registerCommand(de, (t) => {
27
- const e = a();
27
+ const e = i();
28
28
  return !!c(e) && (e.deleteLine(t), !0);
29
29
  }, u), n.registerCommand(ue, (t) => {
30
- const e = a();
30
+ const e = i();
31
31
  if (!c(e)) return !1;
32
32
  if (typeof t == "string") e.insertText(t);
33
33
  else {
34
34
  const s = t.dataTransfer;
35
- if (s != null) A(s, e);
35
+ if (s != null) W(s, e);
36
36
  else {
37
- const i = t.data;
38
- i && e.insertText(i);
37
+ const a = t.data;
38
+ a && e.insertText(a);
39
39
  }
40
40
  }
41
41
  return !0;
42
42
  }, u), n.registerCommand(le, () => {
43
- const t = a();
43
+ const t = i();
44
44
  return !!c(t) && (t.removeText(), !0);
45
- }, u), n.registerCommand(M, (t) => {
46
- const e = a();
45
+ }, u), n.registerCommand(z, (t) => {
46
+ const e = i();
47
47
  return !!c(e) && (e.insertLineBreak(t), !0);
48
48
  }, u), n.registerCommand(ce, () => {
49
- const t = a();
49
+ const t = i();
50
50
  return !!c(t) && (t.insertLineBreak(), !0);
51
- }, u), n.registerCommand(ae, (t) => {
52
- const e = a();
53
- if (!c(e)) return !1;
54
- const s = t, i = s.shiftKey;
55
- return !!O(e, !0) && (s.preventDefault(), X(e, i, !0), !0);
56
51
  }, u), n.registerCommand(ie, (t) => {
57
- const e = a();
52
+ const e = i();
53
+ if (!c(e)) return !1;
54
+ const s = t, a = s.shiftKey;
55
+ return !!M(e, !0) && (s.preventDefault(), O(e, a, !0), !0);
56
+ }, u), n.registerCommand(ae, (t) => {
57
+ const e = i();
58
58
  if (!c(e)) return !1;
59
- const s = t, i = s.shiftKey;
60
- return !!O(e, !1) && (s.preventDefault(), X(e, i, !1), !0);
59
+ const s = t, a = s.shiftKey;
60
+ return !!M(e, !1) && (s.preventDefault(), O(e, a, !1), !0);
61
61
  }, u), n.registerCommand(se, (t) => {
62
- const e = a();
63
- return !!c(e) && (!z || navigator.language !== "ko-KR") && (t.preventDefault(), n.dispatchCommand(S, !0));
62
+ const e = i();
63
+ return !!c(e) && (!X || navigator.language !== "ko-KR") && (t.preventDefault(), n.dispatchCommand(S, !0));
64
64
  }, u), n.registerCommand(oe, (t) => {
65
- const e = a();
65
+ const e = i();
66
66
  return !!c(e) && (t.preventDefault(), n.dispatchCommand(S, !1));
67
67
  }, u), n.registerCommand(re, (t) => {
68
- const e = a();
68
+ const e = i();
69
69
  if (!c(e)) return !1;
70
70
  if (t !== null) {
71
- if ((z || _e || Ae) && Be) return !1;
71
+ if ((X || _e || We) && Be) return !1;
72
72
  t.preventDefault();
73
73
  }
74
- return n.dispatchCommand(M, !1);
74
+ return n.dispatchCommand(z, !1);
75
75
  }, u), n.registerCommand(te, () => (ne(), !0), u), n.registerCommand(ee, (t) => {
76
- const e = a();
77
- return !!c(e) && (I(t, n), !0);
76
+ const e = i();
77
+ return !!c(e) && (K(t, n), !0);
78
78
  }, u), n.registerCommand(Z, (t) => {
79
- const e = a();
80
- return !!c(e) && (function(s, i) {
81
- I(s, i), i.update(() => {
82
- const o = a();
79
+ const e = i();
80
+ return !!c(e) && (function(s, a) {
81
+ K(s, a), a.update(() => {
82
+ const o = i();
83
83
  c(o) && o.removeText();
84
84
  });
85
85
  }(t, n), !0);
86
86
  }, u), n.registerCommand(Q, (t) => {
87
- const e = a();
88
- return !!c(e) && (function(s, i) {
89
- s.preventDefault(), i.update(() => {
90
- const o = a(), { clipboardData: d } = s;
91
- d != null && c(o) && A(d, o);
87
+ const e = i();
88
+ return !!c(e) && (function(s, a) {
89
+ s.preventDefault(), a.update(() => {
90
+ const o = i(), { clipboardData: d } = s;
91
+ d != null && c(o) && W(d, o);
92
92
  }, { tag: "paste" });
93
93
  }(t, n), !0);
94
94
  }, u), n.registerCommand(J, (t) => {
95
- const e = a();
95
+ const e = i();
96
96
  return !!c(e) && (t.preventDefault(), !0);
97
97
  }, u), n.registerCommand(G, (t) => {
98
- const e = a();
98
+ const e = i();
99
99
  return !!c(e) && (t.preventDefault(), !0);
100
100
  }, u));
101
101
  }
102
- const N = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? Y : b;
103
- function K(n) {
102
+ const N = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? I : b;
103
+ function U(n) {
104
104
  return n.getEditorState().read(he(n.isComposing()));
105
105
  }
106
- function Oe({ contentEditable: n, placeholder: t = null, ErrorBoundary: e }) {
107
- const [s] = B(), i = function(o, d) {
108
- const [m, v] = U(() => o.getDecorators());
106
+ function Me({ contentEditable: n, placeholder: t = null, ErrorBoundary: e }) {
107
+ const [s] = B(), a = function(o, d) {
108
+ const [m, v] = Y(() => o.getDecorators());
109
109
  return N(() => o.registerDecoratorListener((y) => {
110
110
  $e(() => {
111
111
  v(y);
@@ -122,51 +122,51 @@ function Oe({ contentEditable: n, placeholder: t = null, ErrorBoundary: e }) {
122
122
  }, [d, m, o]);
123
123
  }(s, e);
124
124
  return function(o) {
125
- N(() => T(Me(o), pe(o)), [o]);
126
- }(s), $(F, { children: [n, g(Xe, { content: t }), i] });
125
+ N(() => T(ze(o), pe(o)), [o]);
126
+ }(s), $(F, { children: [n, g(Oe, { content: t }), a] });
127
127
  }
128
- function Xe({ content: n }) {
129
- const [t] = B(), e = function(i) {
130
- const [o, d] = U(() => K(i));
128
+ function Oe({ content: n }) {
129
+ const [t] = B(), e = function(a) {
130
+ const [o, d] = Y(() => U(a));
131
131
  return N(() => {
132
132
  function m() {
133
- const v = K(i);
133
+ const v = U(a);
134
134
  d(v);
135
135
  }
136
- return m(), T(i.registerUpdateListener(() => {
136
+ return m(), T(a.registerUpdateListener(() => {
137
137
  m();
138
- }), i.registerEditableListener(() => {
138
+ }), a.registerEditableListener(() => {
139
139
  m();
140
140
  }));
141
- }, [i]), o;
141
+ }, [a]), o;
142
142
  }(t), s = Ce();
143
143
  return e ? typeof n == "function" ? n(s) : n : null;
144
144
  }
145
- const ze = new URL(window.location.href);
146
- new URLSearchParams(ze.search);
147
- const Ie = "https://wss.dudoc.io";
148
- function Ke(n, t) {
145
+ const Xe = new URL(window.location.href);
146
+ new URLSearchParams(Xe.search);
147
+ const Ke = "https://wss.dudoc.io";
148
+ function Ue(n, t) {
149
149
  let e = t.get(n);
150
- return e === void 0 ? (e = new ye(), t.set(n, e)) : e.load(), new ve(Ie, "/" + n, e, {
150
+ return e === void 0 ? (e = new ye(), t.set(n, e)) : e.load(), new ve(Ke, "/" + n, e, {
151
151
  connect: !1
152
152
  });
153
153
  }
154
- const Ue = Ee ? Y : b, Ye = {
154
+ const Ye = Ee ? I : b, Ie = {
155
155
  ...we,
156
156
  paragraph: "StickyEditorTheme__paragraph"
157
157
  };
158
158
  function L(n, t) {
159
- const e = n.style, s = t.rootElementRect, i = s !== null ? s.left : 0, o = s !== null ? s.top : 0;
160
- e.top = o + t.y + "px", e.left = i + t.x + "px";
159
+ const e = n.style, s = t.rootElementRect, a = s !== null ? s.left : 0, o = s !== null ? s.top : 0;
160
+ e.top = o + t.y + "px", e.left = a + t.x + "px";
161
161
  }
162
162
  function Ge({
163
163
  x: n,
164
164
  y: t,
165
165
  nodeKey: e,
166
166
  color: s,
167
- caption: i
167
+ caption: a
168
168
  }) {
169
- const [o] = B(), d = W(null), m = W({
169
+ const [o] = B(), d = A(null), m = A({
170
170
  isDragging: !1,
171
171
  offsetX: 0,
172
172
  offsetY: 0,
@@ -179,7 +179,7 @@ function Ge({
179
179
  r.x = n, r.y = t;
180
180
  const l = d.current;
181
181
  l !== null && L(l, r);
182
- }, [n, t]), Ue(() => {
182
+ }, [n, t]), Ye(() => {
183
183
  const r = m.current, l = new ResizeObserver((h) => {
184
184
  for (let p = 0; p < h.length; p++) {
185
185
  const H = h[p], { target: j } = H;
@@ -262,17 +262,17 @@ function Ge({
262
262
  children: /* @__PURE__ */ g("i", { className: "bucket" })
263
263
  }
264
264
  ),
265
- /* @__PURE__ */ $(xe, { initialEditor: i, initialTheme: Ye, children: [
265
+ /* @__PURE__ */ $(xe, { initialEditor: a, initialTheme: Ie, children: [
266
266
  v ? /* @__PURE__ */ g(
267
267
  be,
268
268
  {
269
- id: i.getKey(),
270
- providerFactory: Ke,
269
+ id: a.getKey(),
270
+ providerFactory: Ue,
271
271
  shouldBootstrap: !0
272
272
  }
273
273
  ) : /* @__PURE__ */ g(Le, { externalHistoryState: R }),
274
274
  /* @__PURE__ */ g(
275
- Oe,
275
+ Me,
276
276
  {
277
277
  contentEditable: /* @__PURE__ */ g(Se, { className: "StickyNode__contentEditable" }),
278
278
  placeholder: /* @__PURE__ */ g(Pe, { className: "StickyNode__placeholder", children: "What's up?" }),
@@ -0,0 +1,281 @@
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 w } from "react";
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.D0SxWFme.js";
5
+ import { LoadingOverlay as T, Flex as se, Alert as re } from "@mantine/core";
6
+ import { IconInfoCircle as le } from "@tabler/icons-react";
7
+ const j = (t) => {
8
+ const {
9
+ width: c,
10
+ height: a,
11
+ isLoading: s,
12
+ isError: d,
13
+ src: g,
14
+ id: f,
15
+ altText: u,
16
+ imageRef: b,
17
+ maxWidth: v
18
+ } = t;
19
+ return /* @__PURE__ */ G(
20
+ "div",
21
+ {
22
+ className: "media-wrapper",
23
+ style: {
24
+ width: c,
25
+ height: a,
26
+ display: "inline-flex",
27
+ position: "relative"
28
+ },
29
+ children: [
30
+ /* @__PURE__ */ o(
31
+ T,
32
+ {
33
+ visible: s,
34
+ zIndex: 1e3,
35
+ overlayProps: { backgroundOpacity: 0.5 },
36
+ loaderProps: { size: 24, color: "black" }
37
+ }
38
+ ),
39
+ /* @__PURE__ */ o(
40
+ T,
41
+ {
42
+ visible: d,
43
+ zIndex: 1e3,
44
+ overlayProps: { backgroundOpacity: 0.5 },
45
+ loaderProps: {
46
+ children: /* @__PURE__ */ o(se, { bg: "white", maw: 300, justify: "center", children: /* @__PURE__ */ o(
47
+ re,
48
+ {
49
+ variant: "light",
50
+ color: "red",
51
+ title: "Ошибка загрузки",
52
+ icon: /* @__PURE__ */ o(le, {}),
53
+ children: "Попробуйте загрузить заново."
54
+ }
55
+ ) })
56
+ }
57
+ }
58
+ ),
59
+ /* @__PURE__ */ o(
60
+ de,
61
+ {
62
+ className: null,
63
+ src: g,
64
+ altText: u,
65
+ imageRef: b,
66
+ width: "inherit",
67
+ height: "inherit",
68
+ maxWidth: v || "auto",
69
+ id: f
70
+ }
71
+ )
72
+ ]
73
+ }
74
+ );
75
+ };
76
+ function de({
77
+ altText: t,
78
+ className: c,
79
+ imageRef: a,
80
+ src: s,
81
+ width: d,
82
+ height: g,
83
+ maxWidth: f,
84
+ id: u
85
+ }) {
86
+ return /* @__PURE__ */ o(
87
+ "img",
88
+ {
89
+ className: c || void 0,
90
+ src: s,
91
+ alt: t,
92
+ ref: a,
93
+ style: {
94
+ height: g,
95
+ maxWidth: f,
96
+ width: d
97
+ },
98
+ draggable: "false",
99
+ "data-id": u
100
+ }
101
+ );
102
+ }
103
+ function pe({
104
+ src: t,
105
+ altText: c,
106
+ nodeKey: a,
107
+ width: s,
108
+ height: d,
109
+ maxWidth: g,
110
+ showCaption: f,
111
+ caption: u,
112
+ id: b,
113
+ create: v,
114
+ alignment: _
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({
117
+ width: 0,
118
+ height: 0
119
+ }), { fetchUploadImage: F, fetchDeleteImage: L } = q(Y), { t: N } = J();
120
+ w(() => {
121
+ if (!t || t.startsWith("data:image/")) {
122
+ y(!1);
123
+ return;
124
+ }
125
+ const e = new Image();
126
+ e.src = t, e.onload = () => y(!1), e.onerror = () => {
127
+ y(!1), D(!0);
128
+ };
129
+ }, [t]);
130
+ const U = (e, n) => {
131
+ h.update(() => {
132
+ ae(null);
133
+ const l = C(a);
134
+ E(l) && l.setWidthAndHeight(e, n);
135
+ });
136
+ }, { historyState: O } = Z(), {
137
+ settings: { showNestedEditorTreeView: H }
138
+ } = K(), [x, p] = I(!1);
139
+ function $(e) {
140
+ return e.endsWith(".svg") || e.includes("image/svg+xml");
141
+ }
142
+ function B(e) {
143
+ return new Promise((n, l) => {
144
+ if ($(e)) {
145
+ n(0);
146
+ return;
147
+ }
148
+ const i = new Image();
149
+ i.src = e, i.onload = () => {
150
+ n(i.width);
151
+ }, i.onerror = () => {
152
+ l(new Error("Failed to load image"));
153
+ };
154
+ });
155
+ }
156
+ return w(() => {
157
+ v && p(!0);
158
+ }, [v]), w(() => {
159
+ let e = s, n = d, l = 100;
160
+ t && B(t).then((i) => {
161
+ typeof e == "number" && e < l && i < l ? (S(!0), W({
162
+ width: e,
163
+ height: n
164
+ })) : i < l ? (S(!0), W({
165
+ width: "auto",
166
+ height: "auto"
167
+ })) : (W({
168
+ width: i,
169
+ height: i
170
+ }), S(!1));
171
+ });
172
+ }, [t]), w(() => {
173
+ r.width && r.height && m && h.update(() => {
174
+ const e = C(a);
175
+ E(e) && e.setWidthAndHeight(r.width, r.height);
176
+ });
177
+ }, [r.width, r.height, m]), w(() => {
178
+ const e = document.documentElement;
179
+ ee(x, e);
180
+ }, [x]), t ? m ? /* @__PURE__ */ o(
181
+ j,
182
+ {
183
+ width: r.width,
184
+ height: r.height,
185
+ isLoading: R,
186
+ isError: k,
187
+ isIcon: m,
188
+ src: t,
189
+ id: b,
190
+ editor: h,
191
+ nodeKey: a,
192
+ fetchDeleteImage: L,
193
+ altText: c,
194
+ imageRef: z,
195
+ maxWidth: g,
196
+ showCaption: f,
197
+ caption: u,
198
+ isCollabActive: A,
199
+ historyState: O,
200
+ showNestedEditorTreeView: H,
201
+ t: N
202
+ }
203
+ ) : /* @__PURE__ */ o(
204
+ ne,
205
+ {
206
+ editor: h,
207
+ isIcon: m,
208
+ width: typeof s == "string" && s.includes("%") ? parseFloat(s) : s,
209
+ height: typeof d == "string" && d.includes("%") ? parseFloat(d) : s,
210
+ initialWidth: r.width || "",
211
+ initialHeight: r.height || "",
212
+ onResizeEnd: U,
213
+ alignment: _,
214
+ children: /* @__PURE__ */ o(
215
+ j,
216
+ {
217
+ width: "inherit",
218
+ height: "inherit",
219
+ isLoading: R,
220
+ isError: k,
221
+ isIcon: m,
222
+ src: t,
223
+ id: b,
224
+ editor: h,
225
+ nodeKey: a,
226
+ fetchDeleteImage: L,
227
+ altText: c,
228
+ imageRef: z,
229
+ maxWidth: g,
230
+ showCaption: f,
231
+ caption: u,
232
+ isCollabActive: A,
233
+ historyState: O,
234
+ showNestedEditorTreeView: H,
235
+ t: N
236
+ }
237
+ )
238
+ }
239
+ ) : /* @__PURE__ */ o(
240
+ te,
241
+ {
242
+ uploading: !1,
243
+ onUpload: (e) => {
244
+ !F || !e.length || (e.forEach((n, l) => {
245
+ F(n, (i, M) => {
246
+ l === 0 ? h.update(() => {
247
+ const P = C(a);
248
+ E(P) && (P.setSrc(i), P.setId(M));
249
+ }) : h.dispatchCommand(oe, {
250
+ altText: "",
251
+ src: i,
252
+ id: M
253
+ });
254
+ });
255
+ }), p(!1));
256
+ },
257
+ popoverProps: {
258
+ opened: x,
259
+ position: "bottom",
260
+ onChange: p
261
+ },
262
+ onChange: (e) => {
263
+ p(!1), h.update(() => {
264
+ const n = C(a);
265
+ E(n) && n.setSrc(e);
266
+ });
267
+ },
268
+ children: /* @__PURE__ */ o(
269
+ ie,
270
+ {
271
+ title: N("editor.image.add_photo"),
272
+ icon: "photo",
273
+ onClick: () => p(!x)
274
+ }
275
+ )
276
+ }
277
+ );
278
+ }
279
+ export {
280
+ pe as default
281
+ };