@vizel/react 1.0.0 → 1.1.0

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.
Files changed (49) hide show
  1. package/README.md +38 -14
  2. package/dist/index.d.ts +225 -1
  3. package/dist/index.js +59 -51
  4. package/dist/index10.js +42 -40
  5. package/dist/index13.js +1 -1
  6. package/dist/index14.js +4 -4
  7. package/dist/index16.js +1 -1
  8. package/dist/index19.js +1 -1
  9. package/dist/index2.js +1 -1
  10. package/dist/index20.js +152 -8
  11. package/dist/index21.js +8 -10
  12. package/dist/index22.js +10 -78
  13. package/dist/index23.js +75 -112
  14. package/dist/index24.js +112 -32
  15. package/dist/index25.js +35 -5
  16. package/dist/index26.js +5 -68
  17. package/dist/index27.js +65 -88
  18. package/dist/index28.js +91 -4
  19. package/dist/index29.js +4 -36
  20. package/dist/index30.js +34 -51
  21. package/dist/index31.js +52 -11
  22. package/dist/index32.js +11 -24
  23. package/dist/index33.js +24 -29
  24. package/dist/index34.js +30 -4
  25. package/dist/index35.js +4 -33
  26. package/dist/index36.js +31 -48
  27. package/dist/index37.js +50 -37
  28. package/dist/index38.js +48 -7
  29. package/dist/index39.js +69 -50
  30. package/dist/index40.js +45 -11
  31. package/dist/index41.js +8 -15
  32. package/dist/index42.js +53 -3
  33. package/dist/index43.js +11 -20
  34. package/dist/index44.js +54 -2
  35. package/dist/index45.js +15 -9742
  36. package/dist/index46.js +3 -17016
  37. package/dist/index47.js +21 -2
  38. package/dist/index48.js +2 -8
  39. package/dist/index49.js +9742 -2
  40. package/dist/index50.js +17016 -2
  41. package/dist/index51.js +2 -222
  42. package/dist/index52.js +7 -224
  43. package/dist/index53.js +2 -2
  44. package/dist/index54.js +2 -2
  45. package/dist/index55.js +224 -0
  46. package/dist/index56.js +227 -0
  47. package/dist/index57.js +4 -0
  48. package/dist/index58.js +4 -0
  49. package/package.json +12 -12
package/dist/index33.js CHANGED
@@ -1,33 +1,28 @@
1
- import { jsx as r, jsxs as a } from "react/jsx-runtime";
2
- import { groupVizelToolbarActions as b, vizelDefaultToolbarActions as p } from "@vizel/core";
3
- import { Fragment as f } from "react";
4
- import { useVizelState as n } from "./index40.js";
5
- import { VizelIcon as u } from "./index20.js";
6
- import { VizelToolbarButton as z } from "./index32.js";
7
- import { VizelToolbarDivider as c } from "./index34.js";
8
- function $({
9
- editor: o,
10
- className: t,
11
- actions: m = p
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ function u({
3
+ onClick: a,
4
+ isActive: t = !1,
5
+ disabled: o = !1,
6
+ children: e,
7
+ title: r,
8
+ className: n,
9
+ action: l
12
10
  }) {
13
- n(() => o);
14
- const s = b(m);
15
- return /* @__PURE__ */ r("div", { className: `vizel-toolbar-content ${t ?? ""}`, "data-vizel-toolbar": "", children: s.map((e, i) => /* @__PURE__ */ a(f, { children: [
16
- i > 0 && /* @__PURE__ */ r(c, {}),
17
- e.map((l) => /* @__PURE__ */ r(
18
- z,
19
- {
20
- action: l.id,
21
- onClick: () => l.run(o),
22
- isActive: l.isActive(o),
23
- disabled: !l.isEnabled(o),
24
- title: l.shortcut ? `${l.label} (${l.shortcut})` : l.label,
25
- children: /* @__PURE__ */ r(u, { name: l.icon })
26
- },
27
- l.id
28
- ))
29
- ] }, e[0]?.group ?? i)) });
11
+ return /* @__PURE__ */ i(
12
+ "button",
13
+ {
14
+ type: "button",
15
+ onClick: a,
16
+ disabled: o,
17
+ "aria-pressed": t,
18
+ className: `vizel-toolbar-button ${t ? "is-active" : ""} ${n ?? ""}`,
19
+ title: r,
20
+ "data-active": t || void 0,
21
+ "data-action": l,
22
+ children: e
23
+ }
24
+ );
30
25
  }
31
26
  export {
32
- $ as VizelToolbarDefault
27
+ u as VizelToolbarButton
33
28
  };
package/dist/index34.js CHANGED
@@ -1,7 +1,33 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- function e({ className: r }) {
3
- return /* @__PURE__ */ i("span", { className: `vizel-toolbar-divider ${r ?? ""}` });
1
+ import { jsx as r, jsxs as a } from "react/jsx-runtime";
2
+ import { groupVizelToolbarActions as b, vizelDefaultToolbarActions as p } from "@vizel/core";
3
+ import { Fragment as f } from "react";
4
+ import { useVizelState as n } from "./index43.js";
5
+ import { VizelIcon as u } from "./index21.js";
6
+ import { VizelToolbarButton as z } from "./index33.js";
7
+ import { VizelToolbarDivider as c } from "./index35.js";
8
+ function $({
9
+ editor: o,
10
+ className: t,
11
+ actions: m = p
12
+ }) {
13
+ n(() => o);
14
+ const s = b(m);
15
+ return /* @__PURE__ */ r("div", { className: `vizel-toolbar-content ${t ?? ""}`, "data-vizel-toolbar": "", children: s.map((e, i) => /* @__PURE__ */ a(f, { children: [
16
+ i > 0 && /* @__PURE__ */ r(c, {}),
17
+ e.map((l) => /* @__PURE__ */ r(
18
+ z,
19
+ {
20
+ action: l.id,
21
+ onClick: () => l.run(o),
22
+ isActive: l.isActive(o),
23
+ disabled: !l.isEnabled(o),
24
+ title: l.shortcut ? `${l.label} (${l.shortcut})` : l.label,
25
+ children: /* @__PURE__ */ r(u, { name: l.icon })
26
+ },
27
+ l.id
28
+ ))
29
+ ] }, e[0]?.group ?? i)) });
4
30
  }
5
31
  export {
6
- e as VizelToolbarDivider
32
+ $ as VizelToolbarDefault
7
33
  };
package/dist/index35.js CHANGED
@@ -1,36 +1,7 @@
1
- import { handleVizelSuggestionEscape as u, createVizelSuggestionContainer as m } from "@vizel/core";
2
- import { createElement as c } from "react";
3
- import { c as s } from "./index42.js";
4
- import { VizelSlashMenu as d } from "./index27.js";
5
- function z(l = {}) {
6
- return {
7
- render: () => {
8
- let t = null, n = null, o = [], r = null;
9
- const i = { current: null }, a = () => {
10
- t && r && t.render(
11
- c(d, {
12
- items: o,
13
- command: r,
14
- ...l.className !== void 0 && { className: l.className },
15
- ref: i
16
- })
17
- );
18
- };
19
- return {
20
- onStart: (e) => {
21
- o = e.items, r = e.command, n = m(), t = s.createRoot(n.menuContainer), a(), n.updatePosition(e.clientRect);
22
- },
23
- onUpdate: (e) => {
24
- o = e.items, r = e.command, a(), n?.updatePosition(e.clientRect);
25
- },
26
- onKeyDown: (e) => u(e.event) ? !0 : i.current?.onKeyDown(e) ?? !1,
27
- onExit: () => {
28
- t?.unmount(), n?.destroy(), t = null, n = null;
29
- }
30
- };
31
- }
32
- };
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ function e({ className: r }) {
3
+ return /* @__PURE__ */ i("span", { className: `vizel-toolbar-divider ${r ?? ""}` });
33
4
  }
34
5
  export {
35
- z as createVizelSlashMenuRenderer
6
+ e as VizelToolbarDivider
36
7
  };
package/dist/index36.js CHANGED
@@ -1,53 +1,36 @@
1
- import { VIZEL_DEFAULT_AUTO_SAVE_OPTIONS as c, createVizelAutoSaveHandlers as y } from "@vizel/core";
2
- import { useRef as h, useState as A, useCallback as u, useMemo as C, useEffect as R } from "react";
3
- function M(s, t = {}) {
4
- const r = h(t);
5
- r.current = t;
6
- const n = t.enabled ?? c.enabled, d = t.debounceMs ?? c.debounceMs, l = t.storage ?? c.storage, v = t.key ?? c.key, [o, b] = A({
7
- status: "saved",
8
- hasUnsavedChanges: !1,
9
- lastSaved: null,
10
- error: null
11
- }), f = h(s);
12
- f.current = s;
13
- const S = u((e) => {
14
- b((m) => ({ ...m, ...e }));
15
- }, []), a = C(
16
- () => y(
17
- () => f.current(),
18
- {
19
- enabled: n,
20
- debounceMs: d,
21
- storage: l,
22
- key: v,
23
- // Access callbacks through ref to avoid dependency on them
24
- onSave: (e) => r.current.onSave?.(e),
25
- onError: (e) => r.current.onError?.(e),
26
- onRestore: (e) => r.current.onRestore?.(e)
27
- },
28
- S
29
- ),
30
- [n, d, l, v, S]
31
- );
32
- R(() => {
33
- const e = s();
34
- if (e && n)
35
- return e.on("update", a.handleUpdate), () => {
36
- e.off("update", a.handleUpdate), a.cancel();
37
- };
38
- }, [s, n, a]);
39
- const U = u(async () => {
40
- await a.saveNow();
41
- }, [a]), g = u(async () => await a.restore(), [a]);
1
+ import { handleVizelSuggestionEscape as u, createVizelSuggestionContainer as m } from "@vizel/core";
2
+ import { createElement as c } from "react";
3
+ import { c as s } from "./index46.js";
4
+ import { VizelSlashMenu as d } from "./index28.js";
5
+ function z(l = {}) {
42
6
  return {
43
- status: o.status,
44
- hasUnsavedChanges: o.hasUnsavedChanges,
45
- lastSaved: o.lastSaved,
46
- error: o.error,
47
- save: U,
48
- restore: g
7
+ render: () => {
8
+ let t = null, n = null, o = [], r = null;
9
+ const i = { current: null }, a = () => {
10
+ t && r && t.render(
11
+ c(d, {
12
+ items: o,
13
+ command: r,
14
+ ...l.className !== void 0 && { className: l.className },
15
+ ref: i
16
+ })
17
+ );
18
+ };
19
+ return {
20
+ onStart: (e) => {
21
+ o = e.items, r = e.command, n = m(), t = s.createRoot(n.menuContainer), a(), n.updatePosition(e.clientRect);
22
+ },
23
+ onUpdate: (e) => {
24
+ o = e.items, r = e.command, a(), n?.updatePosition(e.clientRect);
25
+ },
26
+ onKeyDown: (e) => u(e.event) ? !0 : i.current?.onKeyDown(e) ?? !1,
27
+ onExit: () => {
28
+ t?.unmount(), n?.destroy(), t = null, n = null;
29
+ }
30
+ };
31
+ }
49
32
  };
50
33
  }
51
34
  export {
52
- M as useVizelAutoSave
35
+ z as createVizelSlashMenuRenderer
53
36
  };
package/dist/index37.js CHANGED
@@ -1,40 +1,53 @@
1
- import { createVizelEditorInstance as g, registerVizelUploadEventHandler as E } from "@vizel/core";
2
- import { useState as x, useRef as d, useEffect as u } from "react";
3
- import { createVizelSlashMenuRenderer as O } from "./index35.js";
4
- function V(c = {}) {
5
- const { features: r, extensions: l = [], ...f } = c, [e, p] = x(null), n = typeof r?.image == "object" ? r.image : {}, i = d(n);
6
- i.current = n;
7
- const m = d({
8
- features: r,
9
- additionalExtensions: l,
10
- editorOptions: f
11
- });
12
- return u(() => {
13
- const t = m.current;
14
- let s = !0, a = null;
15
- return (async () => {
16
- const o = await g({
17
- ...t.editorOptions,
18
- ...t.features !== void 0 && { features: t.features },
19
- extensions: t.additionalExtensions,
20
- createSlashMenuRenderer: O
21
- });
22
- if (!s) {
23
- o.editor.destroy();
24
- return;
25
- }
26
- a = o.editor, p(o.editor);
27
- })(), () => {
28
- s = !1, a?.destroy();
29
- };
30
- }, []), u(() => {
31
- if (e)
32
- return E({
33
- getEditor: () => e,
34
- getImageOptions: () => i.current
35
- });
36
- }, [e]), e;
1
+ import { VIZEL_DEFAULT_AUTO_SAVE_OPTIONS as c, createVizelAutoSaveHandlers as y } from "@vizel/core";
2
+ import { useRef as h, useState as A, useCallback as u, useMemo as C, useEffect as R } from "react";
3
+ function M(s, t = {}) {
4
+ const r = h(t);
5
+ r.current = t;
6
+ const n = t.enabled ?? c.enabled, d = t.debounceMs ?? c.debounceMs, l = t.storage ?? c.storage, v = t.key ?? c.key, [o, b] = A({
7
+ status: "saved",
8
+ hasUnsavedChanges: !1,
9
+ lastSaved: null,
10
+ error: null
11
+ }), f = h(s);
12
+ f.current = s;
13
+ const S = u((e) => {
14
+ b((m) => ({ ...m, ...e }));
15
+ }, []), a = C(
16
+ () => y(
17
+ () => f.current(),
18
+ {
19
+ enabled: n,
20
+ debounceMs: d,
21
+ storage: l,
22
+ key: v,
23
+ // Access callbacks through ref to avoid dependency on them
24
+ onSave: (e) => r.current.onSave?.(e),
25
+ onError: (e) => r.current.onError?.(e),
26
+ onRestore: (e) => r.current.onRestore?.(e)
27
+ },
28
+ S
29
+ ),
30
+ [n, d, l, v, S]
31
+ );
32
+ R(() => {
33
+ const e = s();
34
+ if (e && n)
35
+ return e.on("update", a.handleUpdate), () => {
36
+ e.off("update", a.handleUpdate), a.cancel();
37
+ };
38
+ }, [s, n, a]);
39
+ const U = u(async () => {
40
+ await a.saveNow();
41
+ }, [a]), g = u(async () => await a.restore(), [a]);
42
+ return {
43
+ status: o.status,
44
+ hasUnsavedChanges: o.hasUnsavedChanges,
45
+ lastSaved: o.lastSaved,
46
+ error: o.error,
47
+ save: U,
48
+ restore: g
49
+ };
37
50
  }
38
51
  export {
39
- V as useVizelEditor
52
+ M as useVizelAutoSave
40
53
  };
package/dist/index38.js CHANGED
@@ -1,10 +1,51 @@
1
- import { getVizelEditorState as r } from "@vizel/core";
2
- import { useMemo as i } from "react";
3
- import { useVizelState as u } from "./index40.js";
4
- function p(t) {
5
- const o = u(t), e = t() ?? null;
6
- return i(() => r(e), [e, o]);
1
+ import { VIZEL_DEFAULT_COLLABORATION_OPTIONS as m, createVizelCollaborationHandlers as p } from "@vizel/core";
2
+ import { useRef as d, useState as y, useCallback as u, useMemo as h, useEffect as E } from "react";
3
+ function L(t, o = { user: { name: "Anonymous", color: "#6366f1" } }) {
4
+ const r = d(o);
5
+ r.current = o;
6
+ const c = o.enabled ?? m.enabled, [s, i] = y({
7
+ isConnected: !1,
8
+ isSynced: !1,
9
+ peerCount: 0,
10
+ error: null
11
+ }), a = d(t);
12
+ a.current = t;
13
+ const l = u((n) => {
14
+ i((b) => ({ ...b, ...n }));
15
+ }, []), e = h(
16
+ () => p(
17
+ () => a.current(),
18
+ {
19
+ enabled: c,
20
+ user: o.user,
21
+ onConnect: () => r.current.onConnect?.(),
22
+ onDisconnect: () => r.current.onDisconnect?.(),
23
+ onSynced: () => r.current.onSynced?.(),
24
+ onError: (n) => r.current.onError?.(n),
25
+ onPeersChange: (n) => r.current.onPeersChange?.(n)
26
+ },
27
+ l
28
+ ),
29
+ [c, o.user, l]
30
+ );
31
+ E(() => {
32
+ if (t() && c)
33
+ return e.subscribe();
34
+ }, [t, c, e]);
35
+ const C = u(() => e.connect(), [e]), f = u(() => e.disconnect(), [e]), S = u(
36
+ (n) => e.updateUser(n),
37
+ [e]
38
+ );
39
+ return {
40
+ isConnected: s.isConnected,
41
+ isSynced: s.isSynced,
42
+ peerCount: s.peerCount,
43
+ error: s.error,
44
+ connect: C,
45
+ disconnect: f,
46
+ updateUser: S
47
+ };
7
48
  }
8
49
  export {
9
- p as useVizelEditorState
50
+ L as useVizelCollaboration
10
51
  };
package/dist/index39.js CHANGED
@@ -1,55 +1,74 @@
1
- import { createVizelMarkdownSyncHandlers as S, getVizelMarkdown as V } from "@vizel/core";
2
- import { useState as l, useRef as d, useEffect as c, useCallback as k } from "react";
3
- function R(r, m = {}) {
4
- const { initialValue: s, ...w } = m, [M, a] = l(() => s ?? ""), [p, o] = l(!1), t = d(null);
5
- t.current || (t.current = S(w));
6
- const u = d(!1);
7
- c(() => {
8
- const e = r();
9
- if (!(!e || u.current)) {
10
- if (s !== void 0)
11
- t.current?.setMarkdown(e, s), a(s);
12
- else {
13
- const n = V(e);
14
- a(n);
15
- }
16
- u.current = !0;
17
- }
18
- }, [r, s]), c(() => {
19
- const e = r();
20
- if (!e) return;
21
- const n = t.current;
22
- if (!n) return;
23
- const i = () => {
24
- n.handleUpdate(e), o(n.isPending());
25
- const f = () => {
26
- n.isPending() ? requestAnimationFrame(f) : (a(n.getMarkdown()), o(!1));
27
- };
28
- requestAnimationFrame(f);
29
- };
30
- return e.on("update", i), () => {
31
- e.off("update", i);
32
- };
33
- }, [r]), c(() => () => {
34
- t.current?.destroy();
35
- }, []);
36
- const h = k(
37
- (e) => {
38
- const n = r();
39
- n && (t.current?.setMarkdown(n, e), a(e), o(!1));
40
- },
41
- [r]
42
- ), P = k(() => {
43
- const e = r();
44
- e && (t.current?.flush(e), a(t.current?.getMarkdown() ?? ""), o(!1));
45
- }, [r]);
1
+ import { VIZEL_DEFAULT_COMMENT_OPTIONS as d, createVizelCommentHandlers as k } from "@vizel/core";
2
+ import { useRef as v, useState as E, useCallback as n, useMemo as S, useEffect as h } from "react";
3
+ function V(s, m = {}) {
4
+ const t = v(m);
5
+ t.current = m;
6
+ const c = m.enabled ?? d.enabled, C = m.storage ?? d.storage, l = m.key ?? d.key, [a, f] = E({
7
+ comments: [],
8
+ activeCommentId: null,
9
+ isLoading: !1,
10
+ error: null
11
+ }), u = v(s);
12
+ u.current = s;
13
+ const i = n((e) => {
14
+ f((r) => ({ ...r, ...e }));
15
+ }, []), o = S(
16
+ () => k(
17
+ () => u.current(),
18
+ {
19
+ enabled: c,
20
+ storage: C,
21
+ key: l,
22
+ onAdd: (e) => t.current.onAdd?.(e),
23
+ onRemove: (e) => t.current.onRemove?.(e),
24
+ onResolve: (e) => t.current.onResolve?.(e),
25
+ onReopen: (e) => t.current.onReopen?.(e),
26
+ onError: (e) => t.current.onError?.(e)
27
+ },
28
+ i
29
+ ),
30
+ [c, C, l, i]
31
+ );
32
+ h(() => {
33
+ s() && c && o.loadComments();
34
+ }, [s, c, o]);
35
+ const R = n(
36
+ (e, r) => o.addComment(e, r),
37
+ [o]
38
+ ), g = n(
39
+ (e) => o.removeComment(e),
40
+ [o]
41
+ ), y = n(
42
+ (e) => o.resolveComment(e),
43
+ [o]
44
+ ), I = n(
45
+ (e) => o.reopenComment(e),
46
+ [o]
47
+ ), p = n(
48
+ (e, r, b) => o.replyToComment(e, r, b),
49
+ [o]
50
+ ), A = n(
51
+ (e) => o.setActiveComment(e),
52
+ [o]
53
+ ), L = n(() => o.loadComments(), [o]), T = n(
54
+ (e) => o.getCommentById(e),
55
+ [o]
56
+ );
46
57
  return {
47
- markdown: M,
48
- setMarkdown: h,
49
- isPending: p,
50
- flush: P
58
+ comments: a.comments,
59
+ activeCommentId: a.activeCommentId,
60
+ isLoading: a.isLoading,
61
+ error: a.error,
62
+ addComment: R,
63
+ removeComment: g,
64
+ resolveComment: y,
65
+ reopenComment: I,
66
+ replyToComment: p,
67
+ setActiveComment: A,
68
+ loadComments: L,
69
+ getCommentById: T
51
70
  };
52
71
  }
53
72
  export {
54
- R as useVizelMarkdown
73
+ V as useVizelComment
55
74
  };
package/dist/index40.js CHANGED
@@ -1,14 +1,48 @@
1
- import { useReducer as u, useRef as c, useEffect as f } from "react";
2
- function s(n) {
3
- const [o, r] = u((t) => t + 1, 0), e = c(null);
4
- return f(() => {
5
- const t = n() ?? null;
6
- if (e.current && e.current !== t && e.current.off("transaction", r), e.current = t, !!t)
7
- return t.on("transaction", r), () => {
8
- t.off("transaction", r);
9
- };
10
- }), o;
1
+ import { createVizelEditorInstance as g, wrapAsVizelError as z, registerVizelUploadEventHandler as I } from "@vizel/core";
2
+ import { useState as O, useRef as c, useEffect as u } from "react";
3
+ import { createVizelSlashMenuRenderer as x } from "./index36.js";
4
+ function h(l = {}) {
5
+ const { features: o, extensions: f = [], ...p } = l, [r, E] = O(null), i = typeof o?.image == "object" ? o.image : {}, n = c(i);
6
+ n.current = i;
7
+ const m = c({
8
+ features: o,
9
+ additionalExtensions: f,
10
+ editorOptions: p
11
+ });
12
+ return u(() => {
13
+ const e = m.current;
14
+ let s = !0, a = null;
15
+ return (async () => {
16
+ try {
17
+ const t = await g({
18
+ ...e.editorOptions,
19
+ ...e.features !== void 0 && { features: e.features },
20
+ extensions: e.additionalExtensions,
21
+ createSlashMenuRenderer: x
22
+ });
23
+ if (!s) {
24
+ t.editor.destroy();
25
+ return;
26
+ }
27
+ a = t.editor, E(t.editor);
28
+ } catch (t) {
29
+ const d = z(t, {
30
+ context: "Editor initialization failed",
31
+ code: "EDITOR_INIT_FAILED"
32
+ });
33
+ throw e.editorOptions.onError?.(d), d;
34
+ }
35
+ })(), () => {
36
+ s = !1, a?.destroy();
37
+ };
38
+ }, []), u(() => {
39
+ if (r)
40
+ return I({
41
+ getEditor: () => r,
42
+ getImageOptions: () => n.current
43
+ });
44
+ }, [r]), r;
11
45
  }
12
46
  export {
13
- s as useVizelState
47
+ h as useVizelEditor
14
48
  };
package/dist/index41.js CHANGED
@@ -1,17 +1,10 @@
1
- var t = (e, n) => {
2
- if (e === "slot")
3
- return 0;
4
- if (e instanceof Function)
5
- return e(n);
6
- const { children: r, ...s } = n ?? {};
7
- if (e === "svg")
8
- throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");
9
- return [e, s, r];
10
- };
1
+ import { getVizelEditorState as r } from "@vizel/core";
2
+ import { useMemo as i } from "react";
3
+ import { useVizelState as u } from "./index43.js";
4
+ function p(t) {
5
+ const o = u(t), e = t() ?? null;
6
+ return i(() => r(e), [e, o]);
7
+ }
11
8
  export {
12
- t as createElement,
13
- t as h,
14
- t as jsx,
15
- t as jsxDEV,
16
- t as jsxs
9
+ p as useVizelEditorState
17
10
  };
package/dist/index42.js CHANGED
@@ -1,5 +1,55 @@
1
- import { __require as r } from "./index43.js";
2
- var i = r();
1
+ import { createVizelMarkdownSyncHandlers as S, getVizelMarkdown as V } from "@vizel/core";
2
+ import { useState as l, useRef as d, useEffect as c, useCallback as k } from "react";
3
+ function R(r, m = {}) {
4
+ const { initialValue: s, ...w } = m, [M, a] = l(() => s ?? ""), [p, o] = l(!1), t = d(null);
5
+ t.current || (t.current = S(w));
6
+ const u = d(!1);
7
+ c(() => {
8
+ const e = r();
9
+ if (!(!e || u.current)) {
10
+ if (s !== void 0)
11
+ t.current?.setMarkdown(e, s), a(s);
12
+ else {
13
+ const n = V(e);
14
+ a(n);
15
+ }
16
+ u.current = !0;
17
+ }
18
+ }, [r, s]), c(() => {
19
+ const e = r();
20
+ if (!e) return;
21
+ const n = t.current;
22
+ if (!n) return;
23
+ const i = () => {
24
+ n.handleUpdate(e), o(n.isPending());
25
+ const f = () => {
26
+ n.isPending() ? requestAnimationFrame(f) : (a(n.getMarkdown()), o(!1));
27
+ };
28
+ requestAnimationFrame(f);
29
+ };
30
+ return e.on("update", i), () => {
31
+ e.off("update", i);
32
+ };
33
+ }, [r]), c(() => () => {
34
+ t.current?.destroy();
35
+ }, []);
36
+ const h = k(
37
+ (e) => {
38
+ const n = r();
39
+ n && (t.current?.setMarkdown(n, e), a(e), o(!1));
40
+ },
41
+ [r]
42
+ ), P = k(() => {
43
+ const e = r();
44
+ e && (t.current?.flush(e), a(t.current?.getMarkdown() ?? ""), o(!1));
45
+ }, [r]);
46
+ return {
47
+ markdown: M,
48
+ setMarkdown: h,
49
+ isPending: p,
50
+ flush: P
51
+ };
52
+ }
3
53
  export {
4
- i as c
54
+ R as useVizelMarkdown
5
55
  };