@clevertask/scribe 0.0.7 → 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.
@@ -1,4 +1,4 @@
1
- import { N as fa, P as pa, a as va, m as ga } from "../../../index-o3ZWOEgq.js";
1
+ import { N as fa, P as pa, b as va, m as ga } from "../../../index-Gm-3o3nq.js";
2
2
  class u0 {
3
3
  // The + prefix indicates that these fields aren't writeable
4
4
  // Lexer holding the input string.
@@ -1,9 +1,13 @@
1
1
  import "react/jsx-runtime";
2
- import { S as s } from "../../../../SlashCommandList-DLPd43Tg.js";
2
+ import { g } from "../../../../index-NRgJVTH-.js";
3
3
  import "react";
4
4
  import "../../../../turndown.browser.es-BSoGafvq.js";
5
- import "../../../../browser-Ce149ePN.js";
5
+ import "../../../../browser-DEobZXxB.js";
6
6
  import "../../../../utils/is-in-viewport.js";
7
+ import "../extension-link.js";
8
+ import "./index.js";
9
+ import "../extension-selectedText.js";
10
+ import "../math-extension.js";
7
11
  export {
8
- s as SlashCommandList
12
+ g as SlashCommandList
9
13
  };
@@ -1,4 +1,4 @@
1
- import { a as F, P as T, D as U, b as j, e as z, E as G } from "../../../../index-o3ZWOEgq.js";
1
+ import { b as F, P as T, D as U, c as j, e as z, a as G } from "../../../../index-Gm-3o3nq.js";
2
2
  function H(f) {
3
3
  var s;
4
4
  const { char: g, allowSpaces: v, allowToIncludeChar: I, allowedPrefixes: m, startOfLine: R, $position: d } = f, P = v && !I, p = z(g), D = new RegExp(`\\s${p}$`), h = R ? "^" : "", C = I ? "" : p, K = P ? new RegExp(`${h}${p}.*?(?=\\s${C}|$)`, "gm") : new RegExp(`${h}(?:^)?${p}[^\\s${C}]*`, "gm"), r = ((s = d.nodeBefore) === null || s === void 0 ? void 0 : s.isText) && d.nodeBefore.text;
@@ -1,5 +1,5 @@
1
- import { R as l, t as c } from "../../../../index-dyNx8_Ul.js";
2
- import { l as a, S as d } from "../../../../SlashCommandList-DLPd43Tg.js";
1
+ import { R as l, t as c } from "../../../../index-C3_lI_rP.js";
2
+ import { l as a, g as d } from "../../../../index-NRgJVTH-.js";
3
3
  const m = () => {
4
4
  let n, t = [], r, i = !a.isEmpty(t);
5
5
  return {
@@ -1,15 +1,17 @@
1
- import { Content, Extension, JSONContent, UseEditorOptions } from '@tiptap/react';
2
- import { KeyboardEventHandler } from 'react';
3
1
  import { ClassValue } from 'clsx';
2
+ import { Content, Editor, Extension, JSONContent, UseEditorOptions } from '@tiptap/react';
3
+ import { KeyboardEventHandler } from 'react';
4
4
  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;
11
12
  getContent: (contentType: "html" | "json" | "markdown") => string | JSONContent | undefined;
12
13
  setContent: (content: Content) => void;
14
+ editor: Editor;
13
15
  }
14
16
  export interface ScribeProps {
15
17
  onContentChange?: (content: ScribeOnChangeContents) => void;
@@ -17,6 +19,7 @@ export interface ScribeProps {
17
19
  editable?: boolean;
18
20
  autoFocus?: boolean;
19
21
  extensions?: Extension[];
22
+ externalEditor?: Editor;
20
23
  editorProps?: UseEditorOptions;
21
24
  showBarMenu?: boolean;
22
25
  placeholderText?: string;
@@ -1,93 +1,100 @@
1
- import { jsx as i, jsxs as S } from "react/jsx-runtime";
2
- import { u as H, E as k } from "../../index-dyNx8_Ul.js";
3
- import { initExtensions as B } from "./extension/index.js";
4
- import { forwardRef as L, useCallback as f, useImperativeHandle as T, useEffect as u } from "react";
5
- import A from "../Menu/BarMenu.js";
1
+ import { jsx as l, jsxs as L } from "react/jsx-runtime";
2
+ import R from "../Menu/BarMenu.js";
6
3
  import { html2md as b } from "../../utils/html-to-markdown.js";
7
- import "../../browser-Ce149ePN.js";
8
- import '../../assets/index.css';function d(t) {
9
- var o, s, e = "";
10
- if (typeof t == "string" || typeof t == "number") e += t;
11
- else if (typeof t == "object") if (Array.isArray(t)) {
12
- var r = t.length;
13
- for (o = 0; o < r; o++) t[o] && (s = d(t[o])) && (e && (e += " "), e += s);
14
- } else for (s in t) t[s] && (e && (e += " "), e += s);
4
+ import "../../browser-DEobZXxB.js";
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
+ var r, s, e = "";
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);
15
16
  return e;
16
17
  }
17
- function p() {
18
- for (var t, o, s = 0, e = "", r = arguments.length; s < r; s++) (t = arguments[s]) && (o = d(t)) && (e && (e += " "), e += o);
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);
19
20
  return e;
20
21
  }
21
- const R = L((t, o) => {
22
+ const V = O((n, r) => {
22
23
  const {
23
24
  autoFocus: s = !1,
24
25
  content: e,
25
- editable: r = !0,
26
+ editable: o = !0,
26
27
  editorProps: c,
27
- extensions: h,
28
- onContentChange: C,
29
- showBarMenu: y = !0,
30
- editorContentStyle: w,
31
- editorContentClassName: x,
32
- mainContainerStyle: v,
33
- mainContainerClassName: E,
34
- onKeyDown: N
35
- } = t, n = H(
36
- {
37
- ...c,
38
- editable: r,
39
- extensions: [...B(t), ...h ?? []],
40
- onUpdate({ editor: a }) {
41
- const m = a.getHTML(), l = a.getJSON();
42
- C && C({
43
- jsonContent: l,
44
- htmlContent: m,
45
- markdownContent: b(m)
46
- });
47
- },
48
- editorProps: {
49
- attributes: {
50
- class: "scribe"
51
- },
52
- ...c == null ? void 0 : c.editorProps
53
- }
28
+ extensions: E,
29
+ onContentChange: p,
30
+ showBarMenu: w = !0,
31
+ editorContentStyle: x,
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"
45
+ });
54
46
  },
55
- []
56
- ), g = f(() => {
57
- n == null || n.commands.setContent("");
58
- }, []), j = f((a) => {
59
- var l;
47
+ [o, p]
48
+ );
49
+ C.current || (C.current = new T({
50
+ ...c,
51
+ editable: o,
52
+ extensions: [...A(n), ...E ?? []],
53
+ editorProps: {
54
+ attributes: {
55
+ class: "scribe"
56
+ },
57
+ ...c == null ? void 0 : c.editorProps
58
+ }
59
+ }));
60
+ const t = C.current, d = u(() => {
61
+ t == null || t.commands.setContent("");
62
+ }, []), H = u((a) => {
63
+ var i;
60
64
  const m = {
61
- html: () => n == null ? void 0 : n.getHTML(),
62
- json: () => n == null ? void 0 : n.getJSON(),
63
- 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()) || "")
64
68
  };
65
- return n != null && n.isEmpty ? "" : (l = m[a]) == null ? void 0 : l.call(m);
66
- }, []), M = f((a) => {
67
- 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);
68
72
  }, []);
69
- return T(o, () => ({
70
- resetContent: g,
71
- setContent: M,
72
- getContent: j
73
- }), [g]), u(() => {
74
- n == null || n.commands.setContent(e || "");
75
- }, [e]), u(() => {
76
- n == null || n.setEditable(!!r);
77
- }, [r]), u(() => {
78
- s && (n == null || n.commands.focus("end"));
79
- }, [s]), /* @__PURE__ */ i("div", { className: p("scribe-wrapper", E), style: v, id: "scribe-wrapper", children: /* @__PURE__ */ S("div", { className: p("bg-white", r && "rounded-lg border"), children: [
80
- n && y && /* @__PURE__ */ i(A, { editor: n }),
81
- /* @__PURE__ */ i(
73
+ return D(r, () => ({
74
+ resetContent: d,
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 }),
88
+ /* @__PURE__ */ l(
82
89
  "div",
83
90
  {
84
- className: p("prose max-w-none", r && "w-full p-[16px]", x),
85
- style: w,
86
- children: /* @__PURE__ */ i(k, { editor: n, onKeyDown: N })
91
+ className: y("prose max-w-none", o && "w-full p-[16px]", v),
92
+ style: x,
93
+ children: /* @__PURE__ */ l(J, { editor: t, onKeyDown: M })
87
94
  }
88
95
  )
89
96
  ] }) });
90
97
  });
91
98
  export {
92
- R as Scribe
99
+ V as Scribe
93
100
  };