@vizel/react 0.0.1-alpha.6 → 1.0.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.
package/dist/index33.js CHANGED
@@ -1,32 +1,33 @@
1
- import { createVizelEditorInstance as l, registerVizelUploadEventHandler as m } from "@vizel/core";
2
- import { useState as g, useRef as s, useEffect as a } from "react";
3
- import { createVizelSlashMenuRenderer as E } from "./index31.js";
4
- function z(u = {}) {
5
- const { features: r, extensions: c = [], ...d } = u, [e, f] = g(null), n = typeof r?.image == "object" ? r.image : {}, o = s(n);
6
- o.current = n;
7
- const p = s({
8
- features: r,
9
- additionalExtensions: c,
10
- editorOptions: d
11
- });
12
- return a(() => {
13
- const t = p.current, { editor: i } = l({
14
- ...t.editorOptions,
15
- ...t.features !== void 0 && { features: t.features },
16
- extensions: t.additionalExtensions,
17
- createSlashMenuRenderer: E
18
- });
19
- return f(i), () => {
20
- i.destroy();
21
- };
22
- }, []), a(() => {
23
- if (e)
24
- return m({
25
- getEditor: () => e,
26
- getImageOptions: () => o.current
27
- });
28
- }, [e]), e;
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
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)) });
29
30
  }
30
31
  export {
31
- z as useVizelEditor
32
+ $ as VizelToolbarDefault
32
33
  };
package/dist/index34.js CHANGED
@@ -1,10 +1,7 @@
1
- import { getVizelEditorState as r } from "@vizel/core";
2
- import { useMemo as i } from "react";
3
- import { useVizelState as u } from "./index36.js";
4
- function p(t) {
5
- const o = u(t), e = t() ?? null;
6
- return i(() => r(e), [e, o]);
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ function e({ className: r }) {
3
+ return /* @__PURE__ */ i("span", { className: `vizel-toolbar-divider ${r ?? ""}` });
7
4
  }
8
5
  export {
9
- p as useVizelEditorState
6
+ e as VizelToolbarDivider
10
7
  };
package/dist/index35.js CHANGED
@@ -1,55 +1,36 @@
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 { 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 = {}) {
46
6
  return {
47
- markdown: M,
48
- setMarkdown: h,
49
- isPending: p,
50
- flush: P
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
+ }
51
32
  };
52
33
  }
53
34
  export {
54
- R as useVizelMarkdown
35
+ z as createVizelSlashMenuRenderer
55
36
  };
package/dist/index36.js CHANGED
@@ -1,14 +1,53 @@
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);
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();
9
37
  };
10
- }), o;
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
+ };
11
50
  }
12
51
  export {
13
- s as useVizelState
52
+ M as useVizelAutoSave
14
53
  };
package/dist/index37.js CHANGED
@@ -1,17 +1,40 @@
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 { 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;
37
+ }
11
38
  export {
12
- t as createElement,
13
- t as h,
14
- t as jsx,
15
- t as jsxDEV,
16
- t as jsxs
39
+ V as useVizelEditor
17
40
  };
package/dist/index38.js CHANGED
@@ -1,5 +1,10 @@
1
- import { __require as r } from "./index39.js";
2
- var i = r();
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]);
7
+ }
3
8
  export {
4
- i as c
9
+ p as useVizelEditorState
5
10
  };
package/dist/index39.js CHANGED
@@ -1,23 +1,55 @@
1
- import { __module as e } from "./index40.js";
2
- import { __require as t } from "./index41.js";
3
- import { __require as i } from "./index42.js";
4
- var _;
5
- function O() {
6
- if (_) return e.exports;
7
- _ = 1;
8
- function r() {
9
- if (!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ > "u" || typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE != "function")) {
10
- if (process.env.NODE_ENV !== "production")
11
- throw new Error("^_^");
12
- try {
13
- __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(r);
14
- } catch (o) {
15
- console.error(o);
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);
16
15
  }
16
+ u.current = !0;
17
17
  }
18
- }
19
- return process.env.NODE_ENV === "production" ? (r(), e.exports = t()) : e.exports = i(), e.exports;
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
+ };
20
52
  }
21
53
  export {
22
- O as __require
54
+ R as useVizelMarkdown
23
55
  };
package/dist/index40.js CHANGED
@@ -1,4 +1,14 @@
1
- var e = { exports: {} };
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;
11
+ }
2
12
  export {
3
- e as __module
13
+ s as useVizelState
4
14
  };