@vizel/react 0.0.1-alpha.1

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/index2.js ADDED
@@ -0,0 +1,26 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { useContext as r, createContext as i } from "react";
3
+ const t = i(null);
4
+ function x({ editor: e, children: n }) {
5
+ return /* @__PURE__ */ o(t.Provider, { value: { editor: e }, children: n });
6
+ }
7
+ function z() {
8
+ const e = r(t);
9
+ if (e === null)
10
+ throw new Error(
11
+ `[Vizel] useVizelContext must be used within <VizelProvider> or <Vizel>.
12
+ Example:
13
+ <VizelProvider editor={editor}>
14
+ <YourComponent />
15
+ </VizelProvider>`
16
+ );
17
+ return e;
18
+ }
19
+ function V() {
20
+ return r(t);
21
+ }
22
+ export {
23
+ x as VizelInternalProvider,
24
+ z as useVizelContext,
25
+ V as useVizelContextSafe
26
+ };
@@ -0,0 +1,94 @@
1
+ import { jsx as u, jsxs as E } from "react/jsx-runtime";
2
+ import { groupVizelSlashCommands as D } from "@vizel/core";
3
+ import { useState as N, useRef as j, useMemo as b, useEffect as p, useCallback as h, useImperativeHandle as A } from "react";
4
+ import { VizelSlashMenuEmpty as R } from "./index21.js";
5
+ import { VizelSlashMenuItem as $ } from "./index22.js";
6
+ function B({
7
+ ref: S,
8
+ items: m,
9
+ command: v,
10
+ className: x,
11
+ showGroups: z = !0,
12
+ renderItem: I,
13
+ renderEmpty: y,
14
+ groupOrder: k
15
+ }) {
16
+ const [i, f] = N(0), c = j([]), r = b(() => !z || m.length <= 5 ? [{ name: "", items: m }] : D(m, k), [m, z, k]), t = b(() => r.flatMap((e) => e.items), [r]);
17
+ p(() => {
18
+ c.current.length > t.length && (c.current.length = t.length);
19
+ }, [t.length]), p(() => {
20
+ const e = c.current[i];
21
+ e && e.scrollIntoView({ block: "nearest", behavior: "smooth" });
22
+ }, [i]);
23
+ const d = h(
24
+ (e) => {
25
+ const s = t[e];
26
+ s && v(s);
27
+ },
28
+ [t, v]
29
+ ), w = h(() => {
30
+ f((e) => (e + t.length - 1) % t.length);
31
+ }, [t.length]), H = h(() => {
32
+ f((e) => (e + 1) % t.length);
33
+ }, [t.length]), M = h(() => {
34
+ d(i);
35
+ }, [d, i]), V = h(() => {
36
+ if (r.length <= 1) return;
37
+ let e = 0, s = 0;
38
+ for (let n = 0; n < r.length; n++) {
39
+ const l = r[n];
40
+ if (l) {
41
+ if (i < s + l.items.length) {
42
+ e = n;
43
+ break;
44
+ }
45
+ s += l.items.length;
46
+ }
47
+ }
48
+ const a = (e + 1) % r.length;
49
+ let o = 0;
50
+ for (let n = 0; n < a; n++) {
51
+ const l = r[n];
52
+ l && (o += l.items.length);
53
+ }
54
+ f(o);
55
+ }, [r, i]);
56
+ if (p(() => {
57
+ f(0);
58
+ }, [r]), A(S, () => ({
59
+ onKeyDown: ({ event: e }) => e.key === "ArrowUp" ? (w(), !0) : e.key === "ArrowDown" ? (H(), !0) : e.key === "Enter" ? (M(), !0) : e.key === "Tab" ? (e.preventDefault(), V(), !0) : !1
60
+ })), t.length === 0)
61
+ return /* @__PURE__ */ u("div", { className: `vizel-slash-menu ${x ?? ""}`, "data-vizel-slash-menu": "", children: y?.() ?? /* @__PURE__ */ u(R, {}) });
62
+ let C = 0;
63
+ return /* @__PURE__ */ u("div", { className: `vizel-slash-menu ${x ?? ""}`, "data-vizel-slash-menu": "", children: r.map((e) => {
64
+ const s = e.items.map((a) => {
65
+ const o = C++, n = o === i, l = () => d(o);
66
+ return I ? /* @__PURE__ */ u(
67
+ "div",
68
+ {
69
+ ref: (g) => {
70
+ c.current[o] = g;
71
+ },
72
+ children: I({ item: a, isSelected: n, onClick: l })
73
+ },
74
+ a.title
75
+ ) : /* @__PURE__ */ u(
76
+ "div",
77
+ {
78
+ ref: (g) => {
79
+ c.current[o] = g;
80
+ },
81
+ children: /* @__PURE__ */ u($, { item: a, isSelected: n, onClick: l })
82
+ },
83
+ a.title
84
+ );
85
+ });
86
+ return e.name ? /* @__PURE__ */ E("div", { className: "vizel-slash-menu-group", "data-vizel-slash-menu-group": !0, children: [
87
+ /* @__PURE__ */ u("div", { className: "vizel-slash-menu-group-header", children: e.name }),
88
+ s
89
+ ] }, e.name) : s;
90
+ }) });
91
+ }
92
+ export {
93
+ B as VizelSlashMenu
94
+ };
@@ -0,0 +1,7 @@
1
+ import { jsx as l } from "react/jsx-runtime";
2
+ function m({ children: e, className: s }) {
3
+ return /* @__PURE__ */ l("div", { className: `vizel-slash-menu-empty ${s ?? ""}`, "data-vizel-slash-menu-empty": "", children: e ?? "No results" });
4
+ }
5
+ export {
6
+ m as VizelSlashMenuEmpty
7
+ };
@@ -0,0 +1,39 @@
1
+ import { jsxs as n, jsx as l } from "react/jsx-runtime";
2
+ import { splitVizelTextByMatches as c } from "@vizel/core";
3
+ import { VizelIcon as r } from "./index14.js";
4
+ const o = (e, t) => {
5
+ const a = c(e, t);
6
+ let i = 0;
7
+ return a.map((s) => {
8
+ const h = `${i}-${s.highlight}`;
9
+ return i += s.text.length, s.highlight ? /* @__PURE__ */ l("mark", { className: "vizel-slash-menu-highlight", children: s.text }, h) : s.text;
10
+ });
11
+ };
12
+ function p({
13
+ item: e,
14
+ isSelected: t = !1,
15
+ onClick: a,
16
+ className: i,
17
+ titleMatches: s
18
+ }) {
19
+ return /* @__PURE__ */ n(
20
+ "button",
21
+ {
22
+ type: "button",
23
+ className: `vizel-slash-menu-item ${t ? "is-selected" : ""} ${i ?? ""}`,
24
+ onClick: a,
25
+ "data-selected": t || void 0,
26
+ children: [
27
+ /* @__PURE__ */ l("span", { className: "vizel-slash-menu-icon", children: /* @__PURE__ */ l(r, { name: e.icon }) }),
28
+ /* @__PURE__ */ n("div", { className: "vizel-slash-menu-text", children: [
29
+ /* @__PURE__ */ l("span", { className: "vizel-slash-menu-title", children: o(e.title, s) }),
30
+ /* @__PURE__ */ l("span", { className: "vizel-slash-menu-description", children: e.description })
31
+ ] }),
32
+ e.shortcut && /* @__PURE__ */ l("span", { className: "vizel-slash-menu-shortcut", children: e.shortcut })
33
+ ]
34
+ }
35
+ );
36
+ }
37
+ export {
38
+ p as VizelSlashMenuItem
39
+ };
@@ -0,0 +1,36 @@
1
+ import { handleVizelSuggestionEscape as u, createVizelSuggestionContainer as m } from "@vizel/core";
2
+ import { createElement as c } from "react";
3
+ import { c as s } from "./index29.js";
4
+ import { VizelSlashMenu as d } from "./index20.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
+ };
33
+ }
34
+ export {
35
+ z as createVizelSlashMenuRenderer
36
+ };
@@ -0,0 +1,53 @@
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
+ };
50
+ }
51
+ export {
52
+ M as useVizelAutoSave
53
+ };
@@ -0,0 +1,32 @@
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 "./index23.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;
29
+ }
30
+ export {
31
+ z as useVizelEditor
32
+ };
@@ -0,0 +1,10 @@
1
+ import { getVizelEditorState as r } from "@vizel/core";
2
+ import { useMemo as i } from "react";
3
+ import { useVizelState as u } from "./index28.js";
4
+ function p(t) {
5
+ const o = u(t), e = t() ?? null;
6
+ return i(() => r(e), [e, o]);
7
+ }
8
+ export {
9
+ p as useVizelEditorState
10
+ };
@@ -0,0 +1,55 @@
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
+ }
53
+ export {
54
+ R as useVizelMarkdown
55
+ };
@@ -0,0 +1,14 @@
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
+ }
12
+ export {
13
+ s as useVizelState
14
+ };
@@ -0,0 +1,5 @@
1
+ import { __require as r } from "./index30.js";
2
+ var i = r();
3
+ export {
4
+ i as c
5
+ };
package/dist/index3.js ADDED
@@ -0,0 +1,13 @@
1
+ import { jsx as n } from "react/jsx-runtime";
2
+ import { useContext as r, createContext as c } from "react";
3
+ const o = c({});
4
+ function s({ icons: t, children: e }) {
5
+ return /* @__PURE__ */ n(o.Provider, { value: { customIcons: t }, children: e });
6
+ }
7
+ function x() {
8
+ return r(o);
9
+ }
10
+ export {
11
+ s as VizelIconProvider,
12
+ x as useVizelIconContext
13
+ };
@@ -0,0 +1,23 @@
1
+ import { __module as e } from "./index31.js";
2
+ import { __require as t } from "./index32.js";
3
+ import { __require as i } from "./index33.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);
16
+ }
17
+ }
18
+ }
19
+ return process.env.NODE_ENV === "production" ? (r(), e.exports = t()) : e.exports = i(), e.exports;
20
+ }
21
+ export {
22
+ O as __require
23
+ };
@@ -0,0 +1,4 @@
1
+ var e = { exports: {} };
2
+ export {
3
+ e as __module
4
+ };