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