@alxgrn/prose-editor 0.0.37 → 0.0.39

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,8 +1,9 @@
1
1
  import { FC } from 'react';
2
2
  import { TEditorSaver, TImageUploader } from '../types';
3
3
  type Props = {
4
- content: string | null;
4
+ content?: string | null;
5
5
  onSave: TEditorSaver;
6
+ onView?: () => void;
6
7
  onChange?: (changed: boolean) => void;
7
8
  onUpload?: TImageUploader;
8
9
  };
@@ -4,6 +4,7 @@ import { TEditorSaver } from '../../types';
4
4
  type Props = {
5
5
  schema: Schema;
6
6
  onSave: TEditorSaver;
7
+ onView?: () => void;
7
8
  };
8
9
  export declare const MenuBar: FC<Props>;
9
10
  export default MenuBar;
@@ -17724,34 +17724,38 @@ const Tf = ({ schema: n }) => n.nodes.carousel ? /* @__PURE__ */ g.jsx(hr, { ite
17724
17724
  );
17725
17725
  }
17726
17726
  ), If = ({ onSave: n, disabled: e = !1, notEmpty: t = !0, wasChanged: r = !0 }) => {
17727
- const [s, o] = M(!0);
17728
- et((l) => {
17729
- let a = !1;
17730
- const c = l.state.doc, u = !!c.textBetween(0, c.content.size, void 0, " ").length, f = !!Uo(l.state);
17731
- r && t ? a = u && f : r ? a = f : t && (a = u), o(a);
17727
+ const [s, o] = M(!0), [i, l] = M(!1);
17728
+ et((c) => {
17729
+ let u = !1;
17730
+ const f = c.state.doc, d = !!f.textBetween(0, f.content.size, void 0, " ").length, p = !!Uo(c.state);
17731
+ r && t ? u = d && p : r ? u = p : t && (u = d), o(u);
17732
17732
  });
17733
- const i = se((l) => {
17733
+ const a = se(async (c) => {
17734
+ l(!0);
17734
17735
  try {
17735
- let a;
17736
- const c = mi(l.state);
17737
- if (c) {
17738
- const u = l.state.apply(c.setMeta("addToHistory", !1));
17739
- a = JSON.stringify(u.doc.toJSON());
17736
+ let u;
17737
+ const f = mi(c.state);
17738
+ if (f) {
17739
+ const p = c.state.apply(f.setMeta("addToHistory", !1));
17740
+ u = JSON.stringify(p.doc.toJSON());
17740
17741
  } else
17741
- a = JSON.stringify(l.state.doc.toJSON());
17742
- n({ content: a, format: "prose" });
17743
- } catch (a) {
17744
- console.error(`Can not save doc: ${a}`);
17745
- }
17742
+ u = JSON.stringify(c.state.doc.toJSON());
17743
+ const d = await n({ content: u, format: "prose" });
17744
+ if (d) throw new Error(d);
17745
+ c.focus();
17746
+ } catch (u) {
17747
+ console.error(`Can not save doc: ${u}`);
17748
+ }
17749
+ l(!1);
17746
17750
  });
17747
17751
  return /* @__PURE__ */ g.jsx(
17748
17752
  Hf,
17749
17753
  {
17750
17754
  type: "Accent",
17751
- disabled: e || !s,
17752
- label: "Сохранить",
17755
+ disabled: e || !s || i,
17756
+ label: i ? "Сохраняю" : "Сохранить",
17753
17757
  size: "Small",
17754
- onClick: i
17758
+ onClick: a
17755
17759
  }
17756
17760
  );
17757
17761
  }, d1 = ({ title: n = !1, content: e, onSave: t, onCancel: r, onChange: s, onUpload: o }) => {
@@ -17912,7 +17916,7 @@ const Tf = ({ schema: n }) => n.nodes.carousel ? /* @__PURE__ */ g.jsx(hr, { ite
17912
17916
  }
17913
17917
  )
17914
17918
  ] }) : null;
17915
- }, D0 = ({ schema: n, onSave: e }) => /* @__PURE__ */ g.jsxs("div", { className: "MenuBar", children: [
17919
+ }, D0 = ({ schema: n, onSave: e, onView: t }) => /* @__PURE__ */ g.jsxs("div", { className: "MenuBar", children: [
17916
17920
  /* @__PURE__ */ g.jsxs("div", { className: "MenuBlock", children: [
17917
17921
  /* @__PURE__ */ g.jsx(C0, { schema: n }),
17918
17922
  /* @__PURE__ */ g.jsx(wf, { schema: n })
@@ -17923,6 +17927,7 @@ const Tf = ({ schema: n }) => n.nodes.carousel ? /* @__PURE__ */ g.jsx(hr, { ite
17923
17927
  /* @__PURE__ */ g.jsx(N0, { schema: n }),
17924
17928
  /* @__PURE__ */ g.jsx(Tf, { schema: n }),
17925
17929
  /* @__PURE__ */ g.jsx(Nf, {}),
17930
+ t && /* @__PURE__ */ g.jsx("div", { className: "MenuItem", onClick: () => t(), children: /* @__PURE__ */ g.jsx(T.Eye, {}) }),
17926
17931
  /* @__PURE__ */ g.jsx("div", { className: "MenuBlock", children: /* @__PURE__ */ g.jsx(If, { onSave: e }) })
17927
17932
  ] }), O0 = 7, vf = 1, Bn = 50, E0 = ({ width: n, onChange: e, onWidth: t }) => {
17928
17933
  const [r, s] = M(!1), [o, i] = M(0), [l, a] = M(0), [c, u] = M(n), f = (h) => {
@@ -18311,30 +18316,30 @@ const Tf = ({ schema: n }) => n.nodes.carousel ? /* @__PURE__ */ g.jsx(hr, { ite
18311
18316
  /* @__PURE__ */ g.jsx(Of, { pos: d, isOpen: i, onClose: () => l(!1) })
18312
18317
  ] });
18313
18318
  }
18314
- ), h1 = ({ content: n, onSave: e, onChange: t, onUpload: r }) => {
18315
- const [s, o] = M();
18319
+ ), h1 = ({ content: n, onSave: e, onView: t, onChange: r, onUpload: s }) => {
18320
+ const [o, i] = M();
18316
18321
  return _(() => {
18317
- let i;
18322
+ let l;
18318
18323
  if (n)
18319
18324
  try {
18320
- i = Ne.fromJSON(Nt, JSON.parse(n));
18321
- } catch (c) {
18322
- console.error(`Can not parse Prose format: ${c}`);
18325
+ l = Ne.fromJSON(Nt, JSON.parse(n));
18326
+ } catch (u) {
18327
+ console.error(`Can not parse Prose format: ${u}`);
18323
18328
  }
18324
- let l = lt.create({
18325
- doc: i,
18329
+ let a = lt.create({
18330
+ doc: l,
18326
18331
  schema: Nt,
18327
- plugins: xf({ schema: Nt, upload: r })
18332
+ plugins: xf({ schema: Nt, upload: s })
18328
18333
  });
18329
- const a = mi(l);
18330
- a && (l = l.apply(a.setMeta("addToHistory", !1))), o(l);
18331
- }, [n]), s ? /* @__PURE__ */ g.jsx("div", { className: "ProseEditor", children: /* @__PURE__ */ g.jsxs(
18334
+ const c = mi(a);
18335
+ c && (a = a.apply(c.setMeta("addToHistory", !1))), i(a);
18336
+ }, [n]), o ? /* @__PURE__ */ g.jsx("div", { className: "ProseEditor", children: /* @__PURE__ */ g.jsxs(
18332
18337
  yf,
18333
18338
  {
18334
- state: s,
18335
- dispatchTransaction: (i) => o((l) => {
18336
- const a = l == null ? void 0 : l.apply(i);
18337
- return a && t && t(!!Uo(a)), a;
18339
+ state: o,
18340
+ dispatchTransaction: (l) => i((a) => {
18341
+ const c = a == null ? void 0 : a.apply(l);
18342
+ return c && r && r(!!Uo(c)), c;
18338
18343
  }),
18339
18344
  nodeViews: {
18340
18345
  image: Af,
@@ -18345,7 +18350,7 @@ const Tf = ({ schema: n }) => n.nodes.carousel ? /* @__PURE__ */ g.jsx(hr, { ite
18345
18350
  carousel: v0
18346
18351
  },
18347
18352
  children: [
18348
- /* @__PURE__ */ g.jsx(D0, { schema: Nt, onSave: e }),
18353
+ /* @__PURE__ */ g.jsx(D0, { schema: Nt, onSave: e, onView: t }),
18349
18354
  /* @__PURE__ */ g.jsx(gf, {})
18350
18355
  ]
18351
18356
  }