@forgedevstack/ink 1.0.1 → 1.1.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +78 -122
  3. package/dist/components/InkEditor/InkEditor.cjs +1 -1
  4. package/dist/components/InkEditor/InkEditor.d.ts.map +1 -1
  5. package/dist/components/InkEditor/InkEditor.js +524 -172
  6. package/dist/components/InkEditor/components/AiPanel/AiPanel.cjs +1 -0
  7. package/dist/components/InkEditor/components/AiPanel/AiPanel.d.ts +11 -0
  8. package/dist/components/InkEditor/components/AiPanel/AiPanel.d.ts.map +1 -0
  9. package/dist/components/InkEditor/components/AiPanel/AiPanel.js +179 -0
  10. package/dist/components/InkEditor/components/AiPanel/index.d.ts +3 -0
  11. package/dist/components/InkEditor/components/AiPanel/index.d.ts.map +1 -0
  12. package/dist/components/InkEditor/components/BlockHandles/BlockHandles.cjs +1 -0
  13. package/dist/components/InkEditor/components/BlockHandles/BlockHandles.d.ts +9 -0
  14. package/dist/components/InkEditor/components/BlockHandles/BlockHandles.d.ts.map +1 -0
  15. package/dist/components/InkEditor/components/BlockHandles/BlockHandles.js +12 -0
  16. package/dist/components/InkEditor/components/BlockHandles/index.d.ts +3 -0
  17. package/dist/components/InkEditor/components/BlockHandles/index.d.ts.map +1 -0
  18. package/dist/components/InkEditor/components/CommentsPanel/CommentsPanel.cjs +1 -0
  19. package/dist/components/InkEditor/components/CommentsPanel/CommentsPanel.d.ts +11 -0
  20. package/dist/components/InkEditor/components/CommentsPanel/CommentsPanel.d.ts.map +1 -0
  21. package/dist/components/InkEditor/components/CommentsPanel/CommentsPanel.js +61 -0
  22. package/dist/components/InkEditor/components/CommentsPanel/index.d.ts +3 -0
  23. package/dist/components/InkEditor/components/CommentsPanel/index.d.ts.map +1 -0
  24. package/dist/components/InkEditor/components/SlashMenu/SlashMenu.cjs +1 -0
  25. package/dist/components/InkEditor/components/SlashMenu/SlashMenu.d.ts +10 -0
  26. package/dist/components/InkEditor/components/SlashMenu/SlashMenu.d.ts.map +1 -0
  27. package/dist/components/InkEditor/components/SlashMenu/SlashMenu.js +20 -0
  28. package/dist/components/InkEditor/components/SlashMenu/index.d.ts +3 -0
  29. package/dist/components/InkEditor/components/SlashMenu/index.d.ts.map +1 -0
  30. package/dist/components/InkEditor/components/ToolbarButton/ToolbarButton.cjs +1 -1
  31. package/dist/components/InkEditor/components/ToolbarButton/ToolbarButton.js +3 -2
  32. package/dist/components/InkEditor/components/TrackChangesBar/TrackChangesBar.cjs +1 -0
  33. package/dist/components/InkEditor/components/TrackChangesBar/TrackChangesBar.d.ts +11 -0
  34. package/dist/components/InkEditor/components/TrackChangesBar/TrackChangesBar.d.ts.map +1 -0
  35. package/dist/components/InkEditor/components/TrackChangesBar/TrackChangesBar.js +27 -0
  36. package/dist/components/InkEditor/components/TrackChangesBar/index.d.ts +3 -0
  37. package/dist/components/InkEditor/components/TrackChangesBar/index.d.ts.map +1 -0
  38. package/dist/components/InkEditor/components/index.d.ts +5 -0
  39. package/dist/components/InkEditor/components/index.d.ts.map +1 -1
  40. package/dist/constants/aiModels.const.cjs +1 -0
  41. package/dist/constants/aiModels.const.d.ts +5 -0
  42. package/dist/constants/aiModels.const.d.ts.map +1 -0
  43. package/dist/constants/aiModels.const.js +31 -0
  44. package/dist/constants/defaults.const.cjs +1 -1
  45. package/dist/constants/defaults.const.d.ts +32 -1
  46. package/dist/constants/defaults.const.d.ts.map +1 -1
  47. package/dist/constants/defaults.const.js +124 -20
  48. package/dist/constants/index.d.ts +2 -0
  49. package/dist/constants/index.d.ts.map +1 -1
  50. package/dist/constants/numbers.const.cjs +1 -1
  51. package/dist/constants/numbers.const.d.ts +13 -0
  52. package/dist/constants/numbers.const.d.ts.map +1 -1
  53. package/dist/constants/numbers.const.js +13 -3
  54. package/dist/constants/premium.const.cjs +1 -0
  55. package/dist/constants/premium.const.d.ts +8 -0
  56. package/dist/constants/premium.const.d.ts.map +1 -0
  57. package/dist/constants/premium.const.js +97 -0
  58. package/dist/index.cjs +1 -1
  59. package/dist/index.d.ts +3 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +43 -11
  62. package/dist/plugins/ai/aiPlugin.cjs +1 -1
  63. package/dist/plugins/ai/aiPlugin.d.ts.map +1 -1
  64. package/dist/plugins/ai/aiPlugin.js +40 -18
  65. package/dist/plugins/ai/demoProvider.cjs +1 -0
  66. package/dist/plugins/ai/demoProvider.d.ts +3 -0
  67. package/dist/plugins/ai/demoProvider.d.ts.map +1 -0
  68. package/dist/plugins/ai/demoProvider.js +130 -0
  69. package/dist/plugins/ai/index.cjs +1 -1
  70. package/dist/plugins/ai/index.d.ts +4 -1
  71. package/dist/plugins/ai/index.d.ts.map +1 -1
  72. package/dist/plugins/ai/index.js +15 -3
  73. package/dist/plugins/ai/stubs.cjs +1 -0
  74. package/dist/plugins/ai/stubs.d.ts +7 -0
  75. package/dist/plugins/ai/stubs.d.ts.map +1 -0
  76. package/dist/plugins/ai/stubs.js +23 -0
  77. package/dist/styles.css +486 -19
  78. package/dist/types/ai.types.d.ts +111 -2
  79. package/dist/types/ai.types.d.ts.map +1 -1
  80. package/dist/types/comments.types.d.ts +17 -0
  81. package/dist/types/comments.types.d.ts.map +1 -0
  82. package/dist/types/features.types.d.ts +5 -0
  83. package/dist/types/features.types.d.ts.map +1 -0
  84. package/dist/types/index.d.ts +6 -2
  85. package/dist/types/index.d.ts.map +1 -1
  86. package/dist/types/ink.types.d.ts +33 -1
  87. package/dist/types/ink.types.d.ts.map +1 -1
  88. package/dist/types/premium.types.d.ts +30 -0
  89. package/dist/types/premium.types.d.ts.map +1 -0
  90. package/dist/types/trackChanges.types.d.ts +12 -0
  91. package/dist/types/trackChanges.types.d.ts.map +1 -0
  92. package/dist/utils/blocks.utils.cjs +1 -0
  93. package/dist/utils/blocks.utils.d.ts +4 -0
  94. package/dist/utils/blocks.utils.d.ts.map +1 -0
  95. package/dist/utils/blocks.utils.js +41 -0
  96. package/dist/utils/comments.utils.cjs +1 -0
  97. package/dist/utils/comments.utils.d.ts +5 -0
  98. package/dist/utils/comments.utils.d.ts.map +1 -0
  99. package/dist/utils/comments.utils.js +32 -0
  100. package/dist/utils/history.utils.cjs +1 -0
  101. package/dist/utils/history.utils.d.ts +13 -0
  102. package/dist/utils/history.utils.d.ts.map +1 -0
  103. package/dist/utils/history.utils.js +29 -0
  104. package/dist/utils/id.utils.cjs +1 -0
  105. package/dist/utils/id.utils.d.ts +2 -0
  106. package/dist/utils/id.utils.d.ts.map +1 -0
  107. package/dist/utils/id.utils.js +4 -0
  108. package/dist/utils/index.d.ts +10 -0
  109. package/dist/utils/index.d.ts.map +1 -1
  110. package/dist/utils/license.utils.cjs +1 -0
  111. package/dist/utils/license.utils.d.ts +2 -0
  112. package/dist/utils/license.utils.d.ts.map +1 -0
  113. package/dist/utils/license.utils.js +16 -0
  114. package/dist/utils/paste.utils.cjs +1 -0
  115. package/dist/utils/paste.utils.d.ts +4 -0
  116. package/dist/utils/paste.utils.d.ts.map +1 -0
  117. package/dist/utils/paste.utils.js +31 -0
  118. package/dist/utils/premium.utils.cjs +1 -0
  119. package/dist/utils/premium.utils.d.ts +6 -0
  120. package/dist/utils/premium.utils.d.ts.map +1 -0
  121. package/dist/utils/premium.utils.js +30 -0
  122. package/dist/utils/slash.utils.cjs +1 -0
  123. package/dist/utils/slash.utils.d.ts +4 -0
  124. package/dist/utils/slash.utils.d.ts.map +1 -0
  125. package/dist/utils/slash.utils.js +13 -0
  126. package/dist/utils/table.utils.cjs +1 -0
  127. package/dist/utils/table.utils.d.ts +2 -0
  128. package/dist/utils/table.utils.d.ts.map +1 -0
  129. package/dist/utils/table.utils.js +13 -0
  130. package/dist/utils/trackChanges.utils.cjs +1 -0
  131. package/dist/utils/trackChanges.utils.d.ts +7 -0
  132. package/dist/utils/trackChanges.utils.d.ts.map +1 -0
  133. package/dist/utils/trackChanges.utils.js +34 -0
  134. package/package.json +2 -2
@@ -1,225 +1,577 @@
1
- import { jsxs as k, jsx as s } from "react/jsx-runtime";
2
- import { useRef as nt, useState as d, useEffect as x } from "react";
3
- import { INK_MIN_HEIGHT as ot, INK_DEFAULT_TEXT_COLOR as it, INK_DEFAULT_HIGHLIGHT_COLOR as at } from "../../constants/numbers.const.js";
4
- import { INK_PLACEHOLDER_DEFAULT as lt, INK_DEFAULT_TOOLBAR as st, INK_CLASS_TOOLBAR as ct, INK_CLASS_CONTENT as ut, INK_CLASS_FOOTER as dt, INK_CLASS_DIVIDER as ft, INK_HEADING_OPTIONS as mt, INK_BUTTON_CONFIG as v, INK_CLASS_ROOT as ht } from "../../constants/defaults.const.js";
5
- import { cn as gt } from "../../utils/cn.utils.js";
6
- import { applyTypoAutoFix as pt } from "../../utils/typo.utils.js";
7
- import { setTextColor as Ct, setHighlightColor as It, getActiveFormats as Tt, queryCommandValue as Lt, fileToDataUrl as A, insertImage as O, execCommand as p, insertLink as _t } from "./helpers/format.utils.js";
1
+ import { jsxs as F, jsx as i } from "react/jsx-runtime";
2
+ import { useRef as ye, useState as m, useEffect as y } from "react";
3
+ import { INK_MIN_HEIGHT as Ot, INK_DEFAULT_TEXT_COLOR as Pt, INK_DEFAULT_HIGHLIGHT_COLOR as Ut } from "../../constants/numbers.const.js";
4
+ import { INK_PLACEHOLDER_DEFAULT as Kt, INK_DEFAULT_TOOLBAR as Ft, INK_DEFAULT_VARIANT as Mt, INK_DEFAULT_AUTHOR as Vt, INK_TABLE_DEFAULT_ROWS as jt, INK_TABLE_DEFAULT_COLS as Wt, INK_DEFAULT_FEATURES as $t, INK_CLASS_TOOLBAR as Gt, INK_CLASS_SHELL as qt, INK_CLASS_BODY as zt, INK_CLASS_CONTENT as Xt, INK_CLASS_FOOTER as Qt, INK_CLASS_DIVIDER as Yt, INK_HEADING_OPTIONS as Jt, INK_BUTTON_CONFIG as Ne, INK_CLASS_ROOT as Zt } from "../../constants/defaults.const.js";
5
+ import { INK_DEFAULT_ICONS as Se } from "../../constants/premium.const.js";
6
+ import { cn as en } from "../../utils/cn.utils.js";
7
+ import { applyTypoAutoFix as tn } from "../../utils/typo.utils.js";
8
+ import { createInkId as ve } from "../../utils/id.utils.js";
9
+ import { buildTableHtml as nn } from "../../utils/table.utils.js";
10
+ import { getBlockElement as _e, moveBlock as on, markActiveBlock as rn } from "../../utils/blocks.utils.js";
11
+ import { rejectTrackChangeInHtml as cn, acceptTrackChangeInHtml as sn, createTrackChange as Z, wrapInsertHtml as Ee, wrapDeleteHtml as an } from "../../utils/trackChanges.utils.js";
12
+ import { removeCommentMark as ln, wrapSelectionAsComment as un, createCommentThread as mn } from "../../utils/comments.utils.js";
13
+ import { InkHistoryStack as xe } from "../../utils/history.utils.js";
14
+ import { extractSlashQuery as dn, filterSlashCommands as fn } from "../../utils/slash.utils.js";
15
+ import { resolveInkPremium as hn, hasInkPremiumFeature as D, themeTokensToStyle as pn } from "../../utils/premium.utils.js";
16
+ import { extractClipboardHtml as gn, sanitizePastedHtml as Cn, extractClipboardText as kn } from "../../utils/paste.utils.js";
17
+ import { insertHTML as I, setTextColor as Tn, setHighlightColor as bn, getActiveFormats as In, queryCommandValue as wn, execCommand as g, insertLink as An, insertImage as Re, fileToDataUrl as Ln } from "./helpers/format.utils.js";
8
18
  import { ToolbarButton as C } from "./components/ToolbarButton/ToolbarButton.js";
9
- import { ToolbarDropdown as bt } from "./components/ToolbarDropdown/ToolbarDropdown.js";
10
- import { ToolbarColorPicker as E } from "./components/ToolbarColorPicker/ToolbarColorPicker.js";
11
- const I = {
12
- bold: "B",
13
- italic: "I",
14
- underline: "U",
15
- strikethrough: "S",
16
- bulletList: "•",
17
- orderedList: "1.",
18
- link: "🔗",
19
- image: "🖼",
20
- clearFormat: "⌫",
21
- alignLeft: "⫷",
22
- alignCenter: "☰",
23
- alignRight: "⫸",
24
- alignJustify: "≡",
25
- indent: "→",
26
- outdent: "←",
27
- blockquote: "“",
28
- code: "</>"
29
- }, St = (y) => {
19
+ import { ToolbarDropdown as Hn } from "./components/ToolbarDropdown/ToolbarDropdown.js";
20
+ import { ToolbarColorPicker as Be } from "./components/ToolbarColorPicker/ToolbarColorPicker.js";
21
+ import { CommentsPanel as yn } from "./components/CommentsPanel/CommentsPanel.js";
22
+ import { AiPanel as Nn } from "./components/AiPanel/AiPanel.js";
23
+ import { BlockHandles as Sn } from "./components/BlockHandles/BlockHandles.js";
24
+ import { SlashMenu as vn } from "./components/SlashMenu/SlashMenu.js";
25
+ import { TrackChangesBar as _n } from "./components/TrackChangesBar/TrackChangesBar.js";
26
+ const ee = () => {
27
+ const N = window.getSelection();
28
+ if (!N || N.rangeCount === 0) return "";
29
+ const h = N.getRangeAt(0), b = document.createElement("div");
30
+ return b.appendChild(h.cloneContents()), b.innerHTML;
31
+ }, no = (N) => {
32
+ var He;
30
33
  const {
31
- value: u,
32
- defaultValue: T = "",
33
- onChange: f,
34
- placeholder: L = lt,
35
- disabled: n = !1,
36
- readOnly: o = !1,
37
- minHeight: m = ot,
38
- maxHeight: h,
39
- toolbar: F = st,
40
- className: S = "",
41
- testId: D,
42
- allowImagePaste: K = !0,
43
- showCharCount: _ = !1,
44
- charCountMax: b,
45
- typoAutoFix: U = !0,
46
- ...B
47
- } = y, r = nt(null), [R, w] = d(/* @__PURE__ */ new Set()), [M, N] = d("p"), [V, P] = d(0), [G, $] = d(it), [j, q] = d(at);
48
- x(() => {
49
- !r.current || u === void 0 || r.current.innerHTML !== u && (r.current.innerHTML = u);
50
- }, [u]), x(() => {
51
- !r.current || u || !T || (r.current.innerHTML = T);
34
+ value: h,
35
+ defaultValue: b = "",
36
+ onChange: M,
37
+ placeholder: te = Kt,
38
+ disabled: s = !1,
39
+ readOnly: a = !1,
40
+ minHeight: V = Ot,
41
+ maxHeight: j,
42
+ toolbar: De = Ft,
43
+ className: Oe = "",
44
+ testId: Pe,
45
+ allowImagePaste: ne = !0,
46
+ showCharCount: oe = !1,
47
+ charCountMax: re,
48
+ typoAutoFix: Ue = !0,
49
+ variant: Ke = Mt,
50
+ features: Fe,
51
+ author: w = Vt,
52
+ trackChanges: S,
53
+ onTrackChangesChange: W,
54
+ trackChangesEnabled: O,
55
+ onTrackChangesEnabledChange: $,
56
+ comments: v,
57
+ onCommentsChange: G,
58
+ showCommentsPanel: _,
59
+ onShowCommentsPanelChange: q,
60
+ ai: d,
61
+ slashCommands: Me,
62
+ tableRows: Ve = jt,
63
+ tableCols: je = Wt,
64
+ premium: We,
65
+ theme: $e,
66
+ icons: ce,
67
+ pasteMode: Ge = "plain",
68
+ onImageUpload: se,
69
+ wysiwyg: qe = !1,
70
+ style: ze,
71
+ ...Xe
72
+ } = N, u = { ...$t, ...Fe }, A = hn(We), Qe = D(A, "icons"), Ye = D(A, "theme"), Je = D(A, "richPaste"), Ze = D(A, "imageUpload"), et = D(A, "wysiwyg") && qe, p = Qe && ce ? { ...Se, ...ce } : Se, tt = Ye ? pn($e) : {}, nt = Je && Ge === "rich", o = ye(null), P = ye(new xe(h ?? b)), [ot, rt] = m(/* @__PURE__ */ new Set()), [ct, ae] = m("p"), [st, at] = m(0), [it, lt] = m(Pt), [ut, mt] = m(Ut), [L, ie] = m(O ?? !1), [dt, le] = m(S ?? []), [ft, ue] = m(v ?? []), [ht, me] = m(_ ?? !1), [de, z] = m(!!(d != null && d.enabled && d.openOnInit)), [fe, pt] = m(""), [gt, Ct] = m(0), [kt, he] = m(!1), [Tt, U] = m([]), [pe, bt] = m({ top: 0, left: 0 }), k = S ?? dt, E = v ?? ft, X = _ ?? ht, ge = Me ?? u.slash;
73
+ y(() => {
74
+ O !== void 0 && ie(O);
75
+ }, [O]), y(() => {
76
+ S && le(S);
77
+ }, [S]), y(() => {
78
+ v && ue(v);
79
+ }, [v]), y(() => {
80
+ _ !== void 0 && me(_);
81
+ }, [_]), y(() => {
82
+ !o.current || h === void 0 || o.current.innerHTML !== h && (o.current.innerHTML = h);
83
+ }, [h]), y(() => {
84
+ !o.current || h || !b || (o.current.innerHTML = b, P.current = new xe(b));
52
85
  }, []);
53
- const H = (t) => {
54
- var e;
55
- f == null || f(t), _ && r.current && P(((e = r.current.textContent) == null ? void 0 : e.length) ?? 0);
56
- }, g = () => {
57
- w(Tt());
58
- const t = Lt("formatBlock");
59
- t && N(t.toLowerCase().replace(/[<>]/g, ""));
60
- }, c = () => {
61
- r.current && (H(r.current.innerHTML), g());
62
- }, W = () => {
63
- if (!r.current || !U || n || o) return;
64
- const t = r.current.innerHTML, e = pt(t);
65
- e.html !== t && (r.current.innerHTML = e.html, H(e.html));
66
- }, J = (t) => {
67
- var l;
68
- if (n || o) return;
69
- (l = r.current) == null || l.focus();
70
- const e = v[t];
71
- e && (e.value ? p(e.command, e.value) : p(e.command), c());
72
- }, X = (t) => {
73
- var e;
74
- n || o || ((e = r.current) == null || e.focus(), p("formatBlock", t), N(t), c());
75
- }, z = () => {
76
- var e;
77
- if (n || o) return;
78
- const t = window.prompt("Enter URL:", "https://");
79
- t && ((e = r.current) == null || e.focus(), _t(t), c());
80
- }, Q = async () => {
81
- if (n || o) return;
82
- const t = document.createElement("input");
83
- t.type = "file", t.accept = "image/*", t.onchange = async () => {
84
- var i, a;
85
- const e = (i = t.files) == null ? void 0 : i[0];
86
- if (!e) return;
87
- const l = await A(e);
88
- (a = r.current) == null || a.focus(), O(l, e.name), c();
89
- }, t.click();
90
- }, Y = async (t) => {
91
- var l;
92
- if (!K || n || o) return;
93
- const e = (l = t.clipboardData) == null ? void 0 : l.items;
94
- if (e)
95
- for (const i of Array.from(e)) {
96
- if (!i.type.startsWith("image/")) continue;
97
- t.preventDefault();
98
- const a = i.getAsFile();
99
- if (!a) continue;
100
- const rt = await A(a);
101
- O(rt), c();
86
+ const Q = (e) => {
87
+ var t;
88
+ P.current.push(e), M == null || M(e), oe && o.current && at(((t = o.current.textContent) == null ? void 0 : t.length) ?? 0);
89
+ }, H = (e) => {
90
+ o.current && (o.current.innerHTML = e, Q(e));
91
+ }, x = (e) => {
92
+ le(e), W == null || W(e);
93
+ }, Y = (e) => {
94
+ ue(e), G == null || G(e);
95
+ }, J = (e) => {
96
+ me(e), q == null || q(e);
97
+ }, It = (e) => {
98
+ ie(e), $ == null || $(e);
99
+ }, K = () => {
100
+ rt(In());
101
+ const e = wn("formatBlock");
102
+ if (e && ae(e.toLowerCase().replace(/[<>]/g, "")), pt(ee()), !o.current || !u.blocks) return;
103
+ const t = window.getSelection(), n = (t == null ? void 0 : t.anchorNode) ?? null, r = _e(n, o.current);
104
+ if (rn(o.current, r), r) {
105
+ const c = o.current.getBoundingClientRect(), f = r.getBoundingClientRect();
106
+ Ct(f.top - c.top + o.current.scrollTop), he(!0);
107
+ } else
108
+ he(!1);
109
+ }, l = () => {
110
+ var t, n, r;
111
+ if (!o.current) return;
112
+ let e = o.current.innerHTML;
113
+ if (L && u.trackChanges) {
114
+ const c = window.getSelection();
115
+ if (c && !c.isCollapsed) {
116
+ const f = ee();
117
+ if (f) {
118
+ const T = Z("delete", f, w);
119
+ x([...k, T]), wt(T.id), e = o.current.innerHTML;
120
+ }
102
121
  }
103
- }, Z = (t, e) => {
104
- if (t === "divider")
105
- return /* @__PURE__ */ s("span", { className: ft }, `divider-${e}`);
106
- if (t === "headingDropdown")
107
- return /* @__PURE__ */ s(
108
- bt,
122
+ }
123
+ if (Q(e), K(), ge && o.current) {
124
+ const c = ((n = (t = window.getSelection()) == null ? void 0 : t.anchorNode) == null ? void 0 : n.textContent) ?? "", f = dn(c);
125
+ if (f !== null) {
126
+ U(fn(f));
127
+ const T = (r = window.getSelection()) == null ? void 0 : r.getRangeAt(0);
128
+ if (T && o.current) {
129
+ const R = T.getBoundingClientRect(), B = o.current.getBoundingClientRect();
130
+ bt({
131
+ top: R.bottom - B.top + 8,
132
+ left: R.left - B.left
133
+ });
134
+ }
135
+ } else
136
+ U([]);
137
+ }
138
+ }, wt = (e) => {
139
+ const t = window.getSelection();
140
+ if (!t || t.rangeCount === 0) return;
141
+ const n = ee();
142
+ n && I(an(n, e));
143
+ }, At = () => {
144
+ if (!o.current || !Ue || !u.typoAutoFix || s || a) return;
145
+ const e = o.current.innerHTML, t = tn(e);
146
+ t.html !== e && (o.current.innerHTML = t.html, Q(t.html));
147
+ }, Lt = (e) => {
148
+ var n;
149
+ if (s || a) return;
150
+ (n = o.current) == null || n.focus();
151
+ const t = Ne[e];
152
+ t && (t.value ? g(t.command, t.value) : g(t.command), l());
153
+ }, Ht = (e) => {
154
+ var t;
155
+ s || a || ((t = o.current) == null || t.focus(), g("formatBlock", e), ae(e), l());
156
+ }, yt = () => {
157
+ var t;
158
+ if (s || a) return;
159
+ const e = window.prompt("Enter URL:", "https://");
160
+ e && ((t = o.current) == null || t.focus(), An(e), l());
161
+ }, Ce = async (e) => Ze && se ? se(e) : Ln(e), Nt = async () => {
162
+ if (s || a) return;
163
+ const e = document.createElement("input");
164
+ e.type = "file", e.accept = "image/*", e.onchange = async () => {
165
+ var r, c;
166
+ const t = (r = e.files) == null ? void 0 : r[0];
167
+ if (!t) return;
168
+ const n = await Ce(t);
169
+ (c = o.current) == null || c.focus(), Re(n, t.name), l();
170
+ }, e.click();
171
+ }, ke = () => {
172
+ var t;
173
+ if (s || a || !u.table) return;
174
+ (t = o.current) == null || t.focus();
175
+ const e = nn(Ve, je);
176
+ if (L && u.trackChanges) {
177
+ const n = Z("insert", e, w);
178
+ x([...k, n]), I(Ee(e, n.id));
179
+ } else
180
+ I(e);
181
+ l();
182
+ }, Te = () => {
183
+ const e = P.current.undo();
184
+ if (e === null || !o.current) {
185
+ g("undo"), l();
186
+ return;
187
+ }
188
+ H(e);
189
+ }, be = () => {
190
+ const e = P.current.redo();
191
+ if (e === null || !o.current) {
192
+ g("redo"), l();
193
+ return;
194
+ }
195
+ H(e);
196
+ }, St = () => {
197
+ var c;
198
+ if (s || a || !u.comments) return;
199
+ const e = window.prompt("Comment:");
200
+ if (!(e != null && e.trim())) return;
201
+ const t = ve("hl");
202
+ if ((c = o.current) == null || c.focus(), !un(t)) return;
203
+ const r = mn(w, e.trim(), t);
204
+ Y([r, ...E]), J(!0), l();
205
+ }, Ie = (e) => {
206
+ if (!o.current) return;
207
+ const t = sn(o.current.innerHTML, e);
208
+ H(t), x(
209
+ k.map((n) => n.id === e ? { ...n, accepted: !0 } : n)
210
+ );
211
+ }, we = (e) => {
212
+ if (!o.current) return;
213
+ const t = cn(o.current.innerHTML, e);
214
+ H(t), x(
215
+ k.map((n) => n.id === e ? { ...n, rejected: !0 } : n)
216
+ );
217
+ }, Ae = async (e) => {
218
+ const t = await Ce(e), n = `<img src="${t}" alt="" style="max-width:100%;height:auto;" />`;
219
+ if (L && u.trackChanges) {
220
+ const r = Z("insert", n, w);
221
+ x([...k, r]), I(Ee(n, r.id));
222
+ } else
223
+ Re(t);
224
+ l();
225
+ }, vt = async (e) => {
226
+ if (s || a) return;
227
+ const t = e.clipboardData;
228
+ if (!t) return;
229
+ if (nt) {
230
+ const r = gn(t);
231
+ if (r) {
232
+ e.preventDefault();
233
+ const f = Cn(r);
234
+ f && (I(f), l());
235
+ const T = t.items;
236
+ if (ne && T)
237
+ for (const R of Array.from(T)) {
238
+ if (!R.type.startsWith("image/")) continue;
239
+ const B = R.getAsFile();
240
+ B && await Ae(B);
241
+ }
242
+ return;
243
+ }
244
+ const c = kn(t);
245
+ if (c) {
246
+ e.preventDefault(), I(c.replace(/\n/g, "<br />")), l();
247
+ return;
248
+ }
249
+ }
250
+ if (!ne) return;
251
+ const n = t.items;
252
+ if (n)
253
+ for (const r of Array.from(n)) {
254
+ if (!r.type.startsWith("image/")) continue;
255
+ e.preventDefault();
256
+ const c = r.getAsFile();
257
+ c && await Ae(c);
258
+ }
259
+ }, _t = (e) => {
260
+ e.key === "Escape" && U([]), (e.metaKey || e.ctrlKey) && e.key === "z" && (e.preventDefault(), e.shiftKey ? be() : Te());
261
+ }, Et = (e) => {
262
+ var n, r;
263
+ (n = o.current) == null || n.focus();
264
+ const t = window.getSelection();
265
+ if ((r = t == null ? void 0 : t.anchorNode) != null && r.textContent) {
266
+ const f = t.anchorNode.textContent.replace(/(?:^|\s)\/[^\s]*$/, " ");
267
+ t.anchorNode.nodeType === Node.TEXT_NODE && (t.anchorNode.textContent = f);
268
+ }
269
+ switch (U([]), e.insert) {
270
+ case "heading1":
271
+ g("formatBlock", "h1");
272
+ break;
273
+ case "heading2":
274
+ g("formatBlock", "h2");
275
+ break;
276
+ case "bulletList":
277
+ g("insertUnorderedList");
278
+ break;
279
+ case "orderedList":
280
+ g("insertOrderedList");
281
+ break;
282
+ case "table":
283
+ ke();
284
+ return;
285
+ case "ai":
286
+ z(!0);
287
+ break;
288
+ }
289
+ l();
290
+ }, Le = (e) => {
291
+ if (!o.current) return;
292
+ const t = window.getSelection(), n = _e((t == null ? void 0 : t.anchorNode) ?? null, o.current);
293
+ n && on(n, e) && (l(), K());
294
+ }, xt = (e, t) => {
295
+ if (e === "divider")
296
+ return /* @__PURE__ */ i("span", { className: Yt }, `divider-${t}`);
297
+ if (e === "headingDropdown")
298
+ return /* @__PURE__ */ i(
299
+ Hn,
109
300
  {
110
301
  title: "Heading",
111
- options: mt,
112
- value: M || "p",
113
- disabled: n || o,
114
- onChange: X
302
+ options: Jt,
303
+ value: ct || "p",
304
+ disabled: s || a,
305
+ onChange: Ht
115
306
  },
116
307
  "heading"
117
308
  );
118
- if (t === "textColor")
119
- return /* @__PURE__ */ s(
120
- E,
309
+ if (e === "textColor")
310
+ return /* @__PURE__ */ i(
311
+ Be,
121
312
  {
122
313
  title: "Text color",
123
314
  type: "text",
124
- value: G,
125
- disabled: n || o,
126
- onChange: (i) => {
127
- var a;
128
- (a = r.current) == null || a.focus(), Ct(i), $(i), c();
315
+ value: it,
316
+ disabled: s || a,
317
+ onChange: (r) => {
318
+ var c;
319
+ (c = o.current) == null || c.focus(), Tn(r), lt(r), l();
129
320
  }
130
321
  },
131
322
  "textColor"
132
323
  );
133
- if (t === "highlightColor")
134
- return /* @__PURE__ */ s(
135
- E,
324
+ if (e === "highlightColor")
325
+ return /* @__PURE__ */ i(
326
+ Be,
136
327
  {
137
328
  title: "Highlight color",
138
329
  type: "highlight",
139
- value: j,
140
- disabled: n || o,
141
- onChange: (i) => {
142
- var a;
143
- (a = r.current) == null || a.focus(), It(i), q(i), c();
330
+ value: ut,
331
+ disabled: s || a,
332
+ onChange: (r) => {
333
+ var c;
334
+ (c = o.current) == null || c.focus(), bn(r), mt(r), l();
144
335
  }
145
336
  },
146
337
  "highlightColor"
147
338
  );
148
- if (t === "link")
149
- return /* @__PURE__ */ s(
339
+ if (e === "link")
340
+ return /* @__PURE__ */ i(
150
341
  C,
151
342
  {
152
- icon: I.link,
343
+ icon: p.link,
153
344
  title: "Insert link",
154
- disabled: n || o,
155
- onClick: z
345
+ disabled: s || a,
346
+ onClick: yt
156
347
  },
157
348
  "link"
158
349
  );
159
- if (t === "image")
160
- return /* @__PURE__ */ s(
350
+ if (e === "image")
351
+ return /* @__PURE__ */ i(
161
352
  C,
162
353
  {
163
- icon: I.image,
354
+ icon: p.image,
164
355
  title: "Insert image",
165
- disabled: n || o,
356
+ disabled: s || a,
166
357
  onClick: () => {
167
- Q();
358
+ Nt();
168
359
  }
169
360
  },
170
361
  "image"
171
362
  );
172
- const l = v[t];
173
- return l ? /* @__PURE__ */ s(
363
+ if (e === "table")
364
+ return u.table ? /* @__PURE__ */ i(
365
+ C,
366
+ {
367
+ icon: p.table,
368
+ title: "Insert table",
369
+ disabled: s || a,
370
+ onClick: ke
371
+ },
372
+ "table"
373
+ ) : null;
374
+ if (e === "undo")
375
+ return /* @__PURE__ */ i(
376
+ C,
377
+ {
378
+ icon: p.undo,
379
+ title: "Undo",
380
+ disabled: s || a,
381
+ onClick: Te
382
+ },
383
+ "undo"
384
+ );
385
+ if (e === "redo")
386
+ return /* @__PURE__ */ i(
387
+ C,
388
+ {
389
+ icon: p.redo,
390
+ title: "Redo",
391
+ disabled: s || a,
392
+ onClick: be
393
+ },
394
+ "redo"
395
+ );
396
+ if (e === "trackChanges")
397
+ return u.trackChanges ? /* @__PURE__ */ i(
398
+ C,
399
+ {
400
+ icon: p.trackChanges,
401
+ title: "Track changes",
402
+ active: L,
403
+ disabled: s || a,
404
+ onClick: () => It(!L)
405
+ },
406
+ "trackChanges"
407
+ ) : null;
408
+ if (e === "comments")
409
+ return u.comments ? /* @__PURE__ */ i(
410
+ C,
411
+ {
412
+ icon: p.comments,
413
+ title: "Comments",
414
+ active: X,
415
+ disabled: s || a,
416
+ onClick: () => {
417
+ X ? J(!1) : St();
418
+ }
419
+ },
420
+ "comments"
421
+ ) : null;
422
+ if (e === "ai")
423
+ return !u.ai || !(d != null && d.enabled) ? null : /* @__PURE__ */ i(
424
+ C,
425
+ {
426
+ icon: p.ai,
427
+ title: "Ink AI",
428
+ active: de,
429
+ disabled: s || a,
430
+ onClick: () => z((r) => !r)
431
+ },
432
+ "ai"
433
+ );
434
+ const n = Ne[e];
435
+ return n ? /* @__PURE__ */ i(
174
436
  C,
175
437
  {
176
- icon: I[t] ?? t.slice(0, 1).toUpperCase(),
177
- title: l.title,
178
- active: R.has(t),
179
- disabled: n || o,
180
- onClick: () => J(t)
438
+ icon: p[e] ?? e.slice(0, 1).toUpperCase(),
439
+ title: n.title,
440
+ active: ot.has(e),
441
+ disabled: s || a,
442
+ onClick: () => Lt(e)
181
443
  },
182
- t
444
+ e
183
445
  ) : null;
184
- }, tt = typeof m == "number" ? `${m}px` : m, et = typeof h == "number" ? `${h}px` : h;
185
- return /* @__PURE__ */ k(
446
+ }, Rt = typeof V == "number" ? `${V}px` : V, Bt = typeof j == "number" ? `${j}px` : j, Dt = !!(d != null && d.enabled && de);
447
+ return /* @__PURE__ */ F(
186
448
  "div",
187
449
  {
188
- className: gt(ht, S),
189
- "data-testid": D,
190
- "data-disabled": n || void 0,
191
- ...B,
450
+ className: en(Zt, Oe),
451
+ "data-testid": Pe,
452
+ "data-disabled": s || void 0,
453
+ "data-variant": Ke,
454
+ "data-premium": A.active || void 0,
455
+ "data-wysiwyg": et || void 0,
456
+ style: { ...tt, ...ze },
457
+ ...Xe,
192
458
  children: [
193
- /* @__PURE__ */ s("div", { className: ct, role: "toolbar", "aria-label": "Ink formatting toolbar", children: F.map(Z) }),
194
- /* @__PURE__ */ s(
195
- "div",
459
+ /* @__PURE__ */ i("div", { className: Gt, role: "toolbar", "aria-label": "Ink formatting toolbar", children: De.map(xt) }),
460
+ L && u.trackChanges ? /* @__PURE__ */ i(
461
+ _n,
196
462
  {
197
- ref: r,
198
- className: ut,
199
- contentEditable: !n && !o,
200
- role: "textbox",
201
- "aria-multiline": "true",
202
- "aria-placeholder": L,
203
- "data-placeholder": L,
204
- suppressContentEditableWarning: !0,
205
- style: { minHeight: tt, maxHeight: et },
206
- onInput: c,
207
- onBlur: W,
208
- onKeyUp: g,
209
- onMouseUp: g,
210
- onPaste: (t) => {
211
- Y(t);
212
- }
463
+ changes: k,
464
+ onAccept: Ie,
465
+ onReject: we,
466
+ onAcceptAll: () => k.forEach((e) => Ie(e.id)),
467
+ onRejectAll: () => k.forEach((e) => we(e.id))
213
468
  }
214
- ),
215
- _ ? /* @__PURE__ */ k("div", { className: dt, children: [
216
- V,
217
- b ? ` / ${b}` : ""
469
+ ) : null,
470
+ /* @__PURE__ */ F("div", { className: qt, children: [
471
+ /* @__PURE__ */ F("div", { className: zt, children: [
472
+ u.blocks ? /* @__PURE__ */ i(
473
+ Sn,
474
+ {
475
+ visible: kt && !s && !a,
476
+ top: gt,
477
+ onMoveUp: () => Le("up"),
478
+ onMoveDown: () => Le("down")
479
+ }
480
+ ) : null,
481
+ /* @__PURE__ */ i(
482
+ "div",
483
+ {
484
+ ref: o,
485
+ className: Xt,
486
+ contentEditable: !s && !a,
487
+ role: "textbox",
488
+ "aria-multiline": "true",
489
+ "aria-placeholder": te,
490
+ "data-placeholder": te,
491
+ suppressContentEditableWarning: !0,
492
+ style: { minHeight: Rt, maxHeight: Bt },
493
+ onInput: l,
494
+ onBlur: At,
495
+ onKeyUp: K,
496
+ onKeyDown: _t,
497
+ onMouseUp: K,
498
+ onPaste: (e) => {
499
+ vt(e);
500
+ }
501
+ }
502
+ ),
503
+ ge ? /* @__PURE__ */ i(
504
+ vn,
505
+ {
506
+ items: Tt,
507
+ top: pe.top,
508
+ left: pe.left,
509
+ onSelect: Et
510
+ }
511
+ ) : null
512
+ ] }),
513
+ X && u.comments ? /* @__PURE__ */ i(
514
+ yn,
515
+ {
516
+ comments: E,
517
+ author: w,
518
+ onClose: () => J(!1),
519
+ onResolve: (e) => {
520
+ const t = E.find((n) => n.id === e);
521
+ Y(
522
+ E.map(
523
+ (n) => n.id === e ? { ...n, resolved: !0 } : n
524
+ )
525
+ ), t && o.current && H(ln(o.current.innerHTML, t.highlightId));
526
+ },
527
+ onAddReply: (e, t) => {
528
+ Y(
529
+ E.map(
530
+ (n) => n.id === e ? {
531
+ ...n,
532
+ replies: [
533
+ ...n.replies,
534
+ {
535
+ id: ve("reply"),
536
+ author: w,
537
+ body: t,
538
+ timestamp: Date.now()
539
+ }
540
+ ]
541
+ } : n
542
+ )
543
+ );
544
+ }
545
+ }
546
+ ) : null,
547
+ Dt && d ? /* @__PURE__ */ i(
548
+ Nn,
549
+ {
550
+ config: d,
551
+ documentHtml: ((He = o.current) == null ? void 0 : He.innerHTML) ?? h ?? "",
552
+ selectionHtml: fe,
553
+ onClose: () => z(!1),
554
+ onApplyHtml: (e) => {
555
+ var t;
556
+ if ((t = o.current) == null || t.focus(), fe)
557
+ I(e);
558
+ else {
559
+ H(e);
560
+ return;
561
+ }
562
+ l();
563
+ }
564
+ }
565
+ ) : null
566
+ ] }),
567
+ oe ? /* @__PURE__ */ F("div", { className: Qt, children: [
568
+ st,
569
+ re ? ` / ${re}` : ""
218
570
  ] }) : null
219
571
  ]
220
572
  }
221
573
  );
222
574
  };
223
575
  export {
224
- St as InkEditor
576
+ no as InkEditor
225
577
  };