@clevertask/scribe 0.0.8 → 0.0.9

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.
@@ -5,6 +5,7 @@ export type ScribeOnChangeContents = {
5
5
  jsonContent: Content;
6
6
  htmlContent: Content;
7
7
  markdownContent: string;
8
+ source: "user" | "programmatic";
8
9
  };
9
10
  export interface ScribeRef {
10
11
  resetContent: () => void;
@@ -1,52 +1,55 @@
1
- import { jsx as l, jsxs as k } from "react/jsx-runtime";
2
- import B from "../Menu/BarMenu.js";
1
+ import { jsx as l, jsxs as L } from "react/jsx-runtime";
2
+ import R from "../Menu/BarMenu.js";
3
3
  import { html2md as b } from "../../utils/html-to-markdown.js";
4
4
  import "../../browser-DEobZXxB.js";
5
- import { E as L } from "../../index-Gm-3o3nq.js";
6
- import { initExtensions as R } from "./extension/index.js";
7
- import { E as T } from "../../index-C3_lI_rP.js";
8
- import { forwardRef as A, useRef as J, useCallback as u, useImperativeHandle as O, useEffect as p } from "react";
9
- import '../../assets/index.css';function h(t) {
5
+ import { E as T } from "../../index-Gm-3o3nq.js";
6
+ import { initExtensions as A } from "./extension/index.js";
7
+ import { E as J } from "../../index-C3_lI_rP.js";
8
+ import { forwardRef as O, useRef as P, useCallback as u, useImperativeHandle as D, useEffect as f } from "react";
9
+ import '../../assets/index.css';function h(n) {
10
10
  var r, s, e = "";
11
- if (typeof t == "string" || typeof t == "number") e += t;
12
- else if (typeof t == "object") if (Array.isArray(t)) {
13
- var o = t.length;
14
- for (r = 0; r < o; r++) t[r] && (s = h(t[r])) && (e && (e += " "), e += s);
15
- } else for (s in t) t[s] && (e && (e += " "), e += s);
11
+ if (typeof n == "string" || typeof n == "number") e += n;
12
+ else if (typeof n == "object") if (Array.isArray(n)) {
13
+ var o = n.length;
14
+ for (r = 0; r < o; r++) n[r] && (s = h(n[r])) && (e && (e += " "), e += s);
15
+ } else for (s in n) n[s] && (e && (e += " "), e += s);
16
16
  return e;
17
17
  }
18
- function C() {
19
- for (var t, r, s = 0, e = "", o = arguments.length; s < o; s++) (t = arguments[s]) && (r = h(t)) && (e && (e += " "), e += r);
18
+ function y() {
19
+ for (var n, r, s = 0, e = "", o = arguments.length; s < o; s++) (n = arguments[s]) && (r = h(n)) && (e && (e += " "), e += r);
20
20
  return e;
21
21
  }
22
- const G = A((t, r) => {
22
+ const V = O((n, r) => {
23
23
  const {
24
24
  autoFocus: s = !1,
25
25
  content: e,
26
26
  editable: o = !0,
27
27
  editorProps: c,
28
- extensions: w,
29
- onContentChange: g,
30
- showBarMenu: y = !0,
28
+ extensions: E,
29
+ onContentChange: p,
30
+ showBarMenu: w = !0,
31
31
  editorContentStyle: x,
32
- editorContentClassName: E,
33
- mainContainerStyle: v,
34
- mainContainerClassName: N,
35
- onKeyDown: j,
36
- externalEditor: M
37
- } = t, f = J(M || null);
38
- f.current || (f.current = new L({
39
- ...c,
40
- editable: o,
41
- extensions: [...R(t), ...w ?? []],
42
- onUpdate({ editor: a }) {
43
- const m = a.getHTML(), i = a.getJSON();
44
- g && g({
45
- jsonContent: i,
46
- htmlContent: m,
47
- markdownContent: b(m)
32
+ editorContentClassName: v,
33
+ mainContainerStyle: N,
34
+ mainContainerClassName: j,
35
+ onKeyDown: M,
36
+ externalEditor: S
37
+ } = n, C = P(S || null), g = u(
38
+ ({ editor: a }) => {
39
+ const m = a.getHTML(), i = a.getJSON(), B = !o;
40
+ p && p({
41
+ jsonContent: a.isEmpty ? "" : i,
42
+ htmlContent: a.isEmpty ? "" : m,
43
+ markdownContent: a.isEmpty ? "" : b(m),
44
+ source: B ? "programmatic" : "user"
48
45
  });
49
46
  },
47
+ [o, p]
48
+ );
49
+ C.current || (C.current = new T({
50
+ ...c,
51
+ editable: o,
52
+ extensions: [...A(n), ...E ?? []],
50
53
  editorProps: {
51
54
  attributes: {
52
55
  class: "scribe"
@@ -54,42 +57,44 @@ const G = A((t, r) => {
54
57
  ...c == null ? void 0 : c.editorProps
55
58
  }
56
59
  }));
57
- const n = f.current, d = u(() => {
58
- n == null || n.commands.setContent("");
59
- }, []), S = u((a) => {
60
+ const t = C.current, d = u(() => {
61
+ t == null || t.commands.setContent("");
62
+ }, []), H = u((a) => {
60
63
  var i;
61
64
  const m = {
62
- html: () => n == null ? void 0 : n.getHTML(),
63
- json: () => n == null ? void 0 : n.getJSON(),
64
- markdown: () => b((n == null ? void 0 : n.getHTML()) || "")
65
+ html: () => t == null ? void 0 : t.getHTML(),
66
+ json: () => t == null ? void 0 : t.getJSON(),
67
+ markdown: () => b((t == null ? void 0 : t.getHTML()) || "")
65
68
  };
66
- return n != null && n.isEmpty ? "" : (i = m[a]) == null ? void 0 : i.call(m);
67
- }, []), H = u((a) => {
68
- n == null || n.commands.setContent(a);
69
+ return t != null && t.isEmpty ? "" : (i = m[a]) == null ? void 0 : i.call(m);
70
+ }, []), k = u((a) => {
71
+ t == null || t.commands.setContent(a);
69
72
  }, []);
70
- return O(r, () => ({
73
+ return D(r, () => ({
71
74
  resetContent: d,
72
- setContent: H,
73
- getContent: S,
74
- editor: n
75
- }), [d]), p(() => {
76
- n == null || n.commands.setContent(e || "");
77
- }, [e]), p(() => {
78
- n == null || n.setEditable(!!o);
79
- }, [o]), p(() => {
80
- s && (n == null || n.commands.focus("end"));
81
- }, [s]), /* @__PURE__ */ l("div", { className: C("scribe-wrapper", N), style: v, id: "scribe-wrapper", children: /* @__PURE__ */ k("div", { className: C("bg-white", o && "rounded-lg border"), children: [
82
- n && y && /* @__PURE__ */ l(B, { editor: n }),
75
+ setContent: k,
76
+ getContent: H,
77
+ editor: t
78
+ }), [d]), f(() => {
79
+ t == null || t.commands.setContent(e || "");
80
+ }, [e]), f(() => {
81
+ t == null || t.setEditable(!!o);
82
+ }, [o]), f(() => (t.off("update"), t.on("update", g), () => {
83
+ t.off("update", g);
84
+ }), [g]), f(() => {
85
+ s && (t == null || t.commands.focus("end"));
86
+ }, [s]), /* @__PURE__ */ l("div", { className: y("scribe-wrapper", j), style: N, id: "scribe-wrapper", children: /* @__PURE__ */ L("div", { className: y("bg-white", o && "rounded-lg border"), children: [
87
+ t && w && /* @__PURE__ */ l(R, { editor: t }),
83
88
  /* @__PURE__ */ l(
84
89
  "div",
85
90
  {
86
- className: C("prose max-w-none", o && "w-full p-[16px]", E),
91
+ className: y("prose max-w-none", o && "w-full p-[16px]", v),
87
92
  style: x,
88
- children: /* @__PURE__ */ l(T, { editor: n, onKeyDown: j })
93
+ children: /* @__PURE__ */ l(J, { editor: t, onKeyDown: M })
89
94
  }
90
95
  )
91
96
  ] }) });
92
97
  });
93
98
  export {
94
- G as Scribe
99
+ V as Scribe
95
100
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A Tiptap-based rich text editor with a Notion-style block interface for viewing and creating content. Perfect for diverse needs like notes, documents, AI chat, Markdown parsing, and comments.",
4
4
  "author": "CleverTask",
5
5
  "private": false,
6
- "version": "0.0.8",
6
+ "version": "0.0.9",
7
7
  "type": "module",
8
8
  "main": "dist/main.js",
9
9
  "types": "dist/main.d.ts",