dishui 0.0.105 → 0.0.108
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/.release-verified.json +2 -2
- package/dist/components/ChoicePicker/index.js +8 -6
- package/dist/components/ChoicePicker/index.js.map +1 -1
- package/dist/components/Column/index.d.ts +3 -2
- package/dist/components/Column/index.js +5 -17
- package/dist/components/Column/index.js.map +1 -1
- package/dist/components/ConfirmDialog/index.d.ts +20 -0
- package/dist/components/ConfirmDialog/index.js +84 -0
- package/dist/components/ConfirmDialog/index.js.map +1 -0
- package/dist/components/DateTimeInput/index.js +28 -26
- package/dist/components/DateTimeInput/index.js.map +1 -1
- package/dist/components/Input/index.js +1 -1
- package/dist/components/Input/index.js.map +1 -1
- package/dist/components/MultipleChoice/index.js +2 -1
- package/dist/components/MultipleChoice/index.js.map +1 -1
- package/dist/components/Row/index.d.ts +3 -2
- package/dist/components/Row/index.js +5 -17
- package/dist/components/Row/index.js.map +1 -1
- package/dist/components/Tab/index.js +80 -0
- package/dist/components/Tab/index.js.map +1 -0
- package/dist/components/Tabs/index.js +28 -33
- package/dist/components/Tabs/index.js.map +1 -1
- package/dist/components/Tabs/tabNavigation.d.ts +2 -0
- package/dist/components/Tabs/tabNavigation.js +14 -0
- package/dist/components/Tabs/tabNavigation.js.map +1 -0
- package/dist/components/pro/CodeEditor/editors/MarkdownEditor.d.ts +1 -1
- package/dist/components/pro/CodeEditor/editors/MarkdownEditor.js +25 -26
- package/dist/components/pro/CodeEditor/editors/MarkdownEditor.js.map +1 -1
- package/dist/components/pro/FileExplorer/Breadcrumb.js +8 -11
- package/dist/components/pro/FileExplorer/Breadcrumb.js.map +1 -1
- package/dist/components/pro/Flow/Flow.js +184 -182
- package/dist/components/pro/Flow/Flow.js.map +1 -1
- package/dist/components/pro/Flow/archify/convert.js +26 -26
- package/dist/components/pro/Flow/archify/convert.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useLayoutActions.js +13 -11
- package/dist/components/pro/Flow/hooks/useLayoutActions.js.map +1 -1
- package/dist/components/pro/RichTextEditor/AIRewrite.d.ts +1 -0
- package/dist/components/pro/RichTextEditor/AIRewrite.js +109 -88
- package/dist/components/pro/RichTextEditor/AIRewrite.js.map +1 -1
- package/dist/components/pro/RichTextEditor/BubbleToolbar.js +73 -83
- package/dist/components/pro/RichTextEditor/BubbleToolbar.js.map +1 -1
- package/dist/components/pro/RichTextEditor/RichTextEditor.js +133 -132
- package/dist/components/pro/RichTextEditor/RichTextEditor.js.map +1 -1
- package/dist/components/pro/RichTextEditor/Toolbar/ColorPicker.d.ts +2 -0
- package/dist/components/pro/RichTextEditor/Toolbar/ColorPicker.js +73 -49
- package/dist/components/pro/RichTextEditor/Toolbar/ColorPicker.js.map +1 -1
- package/dist/components/pro/RichTextEditor/Toolbar/SelectDropdown.d.ts +1 -0
- package/dist/components/pro/RichTextEditor/Toolbar/SelectDropdown.js +12 -14
- package/dist/components/pro/RichTextEditor/Toolbar/SelectDropdown.js.map +1 -1
- package/dist/components/pro/RichTextEditor/extensions/CodeBlockView.js +113 -113
- package/dist/components/pro/RichTextEditor/extensions/CodeBlockView.js.map +1 -1
- package/dist/components/pro/RichTextEditor/types.d.ts +2 -0
- package/dist/components/pro/RichTextEditor/types.js.map +1 -1
- package/dist/css.d.ts +1 -0
- package/dist/dishui.css +1 -1
- package/dist/index-nostyled.d.ts +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +113 -111
- package/dist/layouts/Sidebar.js +201 -107
- package/dist/layouts/Sidebar.js.map +1 -1
- package/dist/utils/flexLayout.d.ts +5 -0
- package/dist/utils/flexLayout.js +19 -0
- package/dist/utils/flexLayout.js.map +1 -0
- package/package.json +63 -57
|
@@ -11,45 +11,45 @@ import i from "./SlashMenu.js";
|
|
|
11
11
|
import a from "./BubbleToolbar.js";
|
|
12
12
|
import o from "./BlockHandle.js";
|
|
13
13
|
import { CodeBlockExtension as s } from "./extensions/CodeBlockView.js";
|
|
14
|
-
import
|
|
15
|
-
import { ResizableImage as
|
|
16
|
-
import { CommentMark as
|
|
14
|
+
import ae from "./extensions/FontSize.js";
|
|
15
|
+
import { ResizableImage as c } from "./extensions/ResizableImage.js";
|
|
16
|
+
import { CommentMark as oe } from "./extensions/CommentMark.js";
|
|
17
17
|
/* empty css */
|
|
18
|
-
import { useCallback as
|
|
19
|
-
import { jsx as
|
|
20
|
-
import { EditorContent as
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import { TextStyle as
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import { Table as
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import
|
|
38
|
-
import
|
|
18
|
+
import { useCallback as l, useEffect as u, useRef as se, useState as d } from "react";
|
|
19
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
20
|
+
import { EditorContent as ce, useEditor as le } from "@tiptap/react";
|
|
21
|
+
import m from "@tiptap/starter-kit";
|
|
22
|
+
import h from "@tiptap/extension-underline";
|
|
23
|
+
import { TextStyle as g } from "@tiptap/extension-text-style";
|
|
24
|
+
import ue from "@tiptap/extension-color";
|
|
25
|
+
import de from "@tiptap/extension-highlight";
|
|
26
|
+
import fe from "@tiptap/extension-text-align";
|
|
27
|
+
import pe from "@tiptap/extension-link";
|
|
28
|
+
import { Table as me } from "@tiptap/extension-table";
|
|
29
|
+
import _ from "@tiptap/extension-table-row";
|
|
30
|
+
import v from "@tiptap/extension-table-cell";
|
|
31
|
+
import y from "@tiptap/extension-table-header";
|
|
32
|
+
import b from "@tiptap/extension-placeholder";
|
|
33
|
+
import x from "@tiptap/extension-task-list";
|
|
34
|
+
import S from "@tiptap/extension-task-item";
|
|
35
|
+
import C from "@tiptap/extension-subscript";
|
|
36
|
+
import w from "@tiptap/extension-superscript";
|
|
37
|
+
import T from "@tiptap/extension-typography";
|
|
38
|
+
import E from "@tiptap/extension-font-family";
|
|
39
39
|
//#region src/components/pro/RichTextEditor/RichTextEditor.tsx
|
|
40
|
-
function
|
|
40
|
+
function D() {
|
|
41
41
|
return `c_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
42
42
|
}
|
|
43
|
-
var
|
|
44
|
-
let [be, xe] =
|
|
43
|
+
var O = ({ content: O, value: k, onChange: A, onChangeJSON: j, placeholder: M = "Start writing...", editable: N = !0, aiConfig: P, onRequestAIConfig: F, toolbarConfig: I, aiSelectionFollowsEditor: L = !1, minHeight: R = "200px", maxHeight: z, className: he = "", autofocus: ge = !1, labels: B, editorRef: V, showComments: _e = !1, commentThreads: ve, onCommentThreadsChange: ye, currentUser: H }) => {
|
|
44
|
+
let [be, xe] = d(!1), [Se, U] = d(!1), [Ce, we] = d(""), [Te, Ee] = d({
|
|
45
45
|
from: 0,
|
|
46
46
|
to: 0
|
|
47
|
-
}), [
|
|
47
|
+
}), [W, G] = d(_e), [De, Oe] = d([]), [ke, K] = d(!1), [q, Ae] = d({
|
|
48
48
|
from: 0,
|
|
49
49
|
to: 0
|
|
50
|
-
}),
|
|
50
|
+
}), J = se(null), Y = ve ?? De, X = ye ?? Oe, Z = le({
|
|
51
51
|
extensions: [
|
|
52
|
-
|
|
52
|
+
m.configure({
|
|
53
53
|
codeBlock: !1,
|
|
54
54
|
heading: { levels: [
|
|
55
55
|
1,
|
|
@@ -62,97 +62,97 @@ var D = ({ content: D, value: O, onChange: k, onChangeJSON: A, placeholder: j =
|
|
|
62
62
|
link: !1,
|
|
63
63
|
underline: !1
|
|
64
64
|
}),
|
|
65
|
-
|
|
65
|
+
h,
|
|
66
|
+
g,
|
|
66
67
|
ue,
|
|
67
|
-
de,
|
|
68
|
-
fe.configure({
|
|
69
|
-
pe.configure({
|
|
70
|
-
me.configure({
|
|
68
|
+
de.configure({ multicolor: !0 }),
|
|
69
|
+
fe.configure({ types: ["heading", "paragraph"] }),
|
|
70
|
+
pe.configure({
|
|
71
71
|
openOnClick: !1,
|
|
72
72
|
autolink: !0,
|
|
73
73
|
HTMLAttributes: { class: "rte-link" }
|
|
74
74
|
}),
|
|
75
|
-
|
|
75
|
+
c.configure({
|
|
76
76
|
inline: !1,
|
|
77
77
|
allowBase64: !0
|
|
78
78
|
}),
|
|
79
|
-
|
|
80
|
-
g,
|
|
79
|
+
me.configure({ resizable: !0 }),
|
|
81
80
|
_,
|
|
82
81
|
v,
|
|
83
|
-
y
|
|
82
|
+
y,
|
|
83
|
+
b.configure({ placeholder: M }),
|
|
84
84
|
s,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
S,
|
|
85
|
+
x,
|
|
86
|
+
S.configure({ nested: !0 }),
|
|
88
87
|
C,
|
|
89
88
|
w,
|
|
90
89
|
T,
|
|
91
|
-
|
|
90
|
+
E,
|
|
91
|
+
ae,
|
|
92
92
|
n,
|
|
93
93
|
t,
|
|
94
|
-
|
|
94
|
+
oe
|
|
95
95
|
],
|
|
96
|
-
content:
|
|
97
|
-
editable:
|
|
96
|
+
content: k || O || "",
|
|
97
|
+
editable: N,
|
|
98
98
|
autofocus: ge ? "end" : !1,
|
|
99
99
|
onUpdate: ({ editor: e }) => {
|
|
100
|
-
|
|
100
|
+
A?.(e.getHTML()), j?.(e.getJSON());
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}, [
|
|
106
|
-
|
|
107
|
-
}, [
|
|
108
|
-
|
|
109
|
-
}, [
|
|
110
|
-
let
|
|
111
|
-
if (!
|
|
112
|
-
let { from: e, to: t } =
|
|
103
|
+
u(() => {
|
|
104
|
+
V && Z && (V.current = Z);
|
|
105
|
+
}, [Z, V]), u(() => {
|
|
106
|
+
Z && k !== void 0 && k !== Z.getHTML() && Z.commands.setContent(k, { emitUpdate: !1 });
|
|
107
|
+
}, [Z, k]), u(() => {
|
|
108
|
+
Z && Z.setEditable(N);
|
|
109
|
+
}, [Z, N]);
|
|
110
|
+
let Q = l(() => {
|
|
111
|
+
if (!Z) return;
|
|
112
|
+
let { from: e, to: t } = Z.state.selection, n = e === t ? "" : Z.state.doc.textBetween(e, t, " ");
|
|
113
113
|
we(n), Ee({
|
|
114
114
|
from: e,
|
|
115
115
|
to: t
|
|
116
|
-
}),
|
|
117
|
-
}, [
|
|
118
|
-
if (!
|
|
119
|
-
let { from: e, to: t } =
|
|
116
|
+
}), U(!0);
|
|
117
|
+
}, [Z]), $ = l(() => {
|
|
118
|
+
if (!Z) return;
|
|
119
|
+
let { from: e, to: t } = Z.state.selection;
|
|
120
120
|
e !== t && (Ae({
|
|
121
121
|
from: e,
|
|
122
122
|
to: t
|
|
123
|
-
}),
|
|
124
|
-
}, [
|
|
125
|
-
if (!
|
|
126
|
-
let t =
|
|
123
|
+
}), K(!0));
|
|
124
|
+
}, [Z]), je = l((e) => {
|
|
125
|
+
if (!Z) return;
|
|
126
|
+
let t = D(), n = {
|
|
127
127
|
id: t,
|
|
128
128
|
resolved: !1,
|
|
129
129
|
comments: [{
|
|
130
|
-
id:
|
|
131
|
-
author:
|
|
130
|
+
id: D(),
|
|
131
|
+
author: H || "User",
|
|
132
132
|
text: e,
|
|
133
133
|
createdAt: Date.now()
|
|
134
134
|
}],
|
|
135
135
|
createdAt: Date.now()
|
|
136
136
|
};
|
|
137
|
-
|
|
137
|
+
Z.chain().focus().setTextSelection(q).setComment(t).run(), X([...Y, n]), K(!1);
|
|
138
138
|
}, [
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
J,
|
|
139
|
+
Z,
|
|
140
|
+
q,
|
|
142
141
|
Y,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
X,
|
|
143
|
+
H
|
|
144
|
+
]), Me = l((e) => {
|
|
145
|
+
J.current?.scrollToThread(e);
|
|
146
146
|
}, []);
|
|
147
|
-
if (!
|
|
148
|
-
let
|
|
147
|
+
if (!Z) return null;
|
|
148
|
+
let Ne = typeof R == "number" ? `${R}px` : R, Pe = z ? typeof z == "number" ? `${z}px` : z : void 0, Fe = e("rte-container", be && "rte-container--format-painter", he), Ie = Y.filter((e) => !e.resolved).length, Le = I?.buttons?.comments ?? !0 ? /* @__PURE__ */ f("div", {
|
|
149
149
|
className: "rte-toolbar__end",
|
|
150
|
-
children: /* @__PURE__ */
|
|
150
|
+
children: /* @__PURE__ */ p("button", {
|
|
151
151
|
type: "button",
|
|
152
|
-
className: `rte-toolbar__btn rte-toolbar__comment-btn ${
|
|
153
|
-
onClick: () =>
|
|
152
|
+
className: `rte-toolbar__btn rte-toolbar__comment-btn ${W ? "rte-toolbar__btn--active" : ""}`,
|
|
153
|
+
onClick: () => G(!W),
|
|
154
154
|
title: "Toggle comments",
|
|
155
|
-
children: [/* @__PURE__ */
|
|
155
|
+
children: [/* @__PURE__ */ f("svg", {
|
|
156
156
|
width: "16",
|
|
157
157
|
height: "16",
|
|
158
158
|
viewBox: "0 0 24 24",
|
|
@@ -161,91 +161,92 @@ var D = ({ content: D, value: O, onChange: k, onChangeJSON: A, placeholder: j =
|
|
|
161
161
|
strokeWidth: "2",
|
|
162
162
|
strokeLinecap: "round",
|
|
163
163
|
strokeLinejoin: "round",
|
|
164
|
-
children: /* @__PURE__ */
|
|
165
|
-
}),
|
|
164
|
+
children: /* @__PURE__ */ f("path", { d: "M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z" })
|
|
165
|
+
}), Ie > 0 && /* @__PURE__ */ f("span", { className: "rte-toolbar__comment-badge" })]
|
|
166
166
|
})
|
|
167
167
|
}) : null;
|
|
168
|
-
return /* @__PURE__ */
|
|
169
|
-
className:
|
|
168
|
+
return /* @__PURE__ */ p("div", {
|
|
169
|
+
className: Fe,
|
|
170
170
|
style: {
|
|
171
|
-
minHeight:
|
|
172
|
-
maxHeight:
|
|
171
|
+
minHeight: Ne,
|
|
172
|
+
maxHeight: Pe
|
|
173
173
|
},
|
|
174
174
|
children: [
|
|
175
|
-
|
|
176
|
-
editor:
|
|
177
|
-
config:
|
|
178
|
-
labels:
|
|
179
|
-
hasAI: !!
|
|
180
|
-
onAIClick:
|
|
181
|
-
onRequestAIConfig:
|
|
175
|
+
N && /* @__PURE__ */ f(ee, {
|
|
176
|
+
editor: Z,
|
|
177
|
+
config: I,
|
|
178
|
+
labels: B,
|
|
179
|
+
hasAI: !!P,
|
|
180
|
+
onAIClick: Q,
|
|
181
|
+
onRequestAIConfig: F,
|
|
182
182
|
onFormatPainterChange: xe,
|
|
183
|
-
children:
|
|
183
|
+
children: Le
|
|
184
184
|
}),
|
|
185
|
-
/* @__PURE__ */
|
|
185
|
+
/* @__PURE__ */ p("div", {
|
|
186
186
|
style: {
|
|
187
187
|
display: "flex",
|
|
188
188
|
flex: 1,
|
|
189
189
|
overflow: "hidden"
|
|
190
190
|
},
|
|
191
|
-
children: [/* @__PURE__ */
|
|
191
|
+
children: [/* @__PURE__ */ p("div", {
|
|
192
192
|
className: "rte-editor-wrapper",
|
|
193
193
|
style: { flex: 1 },
|
|
194
194
|
children: [
|
|
195
|
-
/* @__PURE__ */
|
|
196
|
-
editor:
|
|
195
|
+
/* @__PURE__ */ f(ce, {
|
|
196
|
+
editor: Z,
|
|
197
197
|
className: "rte-editor-content"
|
|
198
198
|
}),
|
|
199
|
-
|
|
200
|
-
editor:
|
|
201
|
-
labels:
|
|
202
|
-
onAIClick:
|
|
199
|
+
N && /* @__PURE__ */ f(ne, {
|
|
200
|
+
editor: Z,
|
|
201
|
+
labels: B,
|
|
202
|
+
onAIClick: P ? Q : void 0
|
|
203
203
|
}),
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
editor:
|
|
207
|
-
onAddComment:
|
|
204
|
+
N && /* @__PURE__ */ f(i, { editor: Z }),
|
|
205
|
+
N && /* @__PURE__ */ f(a, {
|
|
206
|
+
editor: Z,
|
|
207
|
+
onAddComment: $
|
|
208
208
|
}),
|
|
209
|
-
|
|
210
|
-
editor:
|
|
209
|
+
N && /* @__PURE__ */ f(o, {
|
|
210
|
+
editor: Z,
|
|
211
211
|
persistent: !0
|
|
212
212
|
}),
|
|
213
|
-
/* @__PURE__ */
|
|
214
|
-
editor:
|
|
215
|
-
threads:
|
|
216
|
-
onThreadsChange:
|
|
217
|
-
showPanel:
|
|
218
|
-
onOpenPanel: () =>
|
|
219
|
-
onScrollToThread:
|
|
220
|
-
currentUser:
|
|
213
|
+
/* @__PURE__ */ f(r, {
|
|
214
|
+
editor: Z,
|
|
215
|
+
threads: Y,
|
|
216
|
+
onThreadsChange: X,
|
|
217
|
+
showPanel: W,
|
|
218
|
+
onOpenPanel: () => G(!0),
|
|
219
|
+
onScrollToThread: Me,
|
|
220
|
+
currentUser: H
|
|
221
221
|
})
|
|
222
222
|
]
|
|
223
|
-
}),
|
|
224
|
-
ref:
|
|
225
|
-
editor:
|
|
226
|
-
threads:
|
|
227
|
-
onThreadsChange:
|
|
228
|
-
onRequestAddComment:
|
|
229
|
-
currentUser:
|
|
223
|
+
}), W && /* @__PURE__ */ f(re, {
|
|
224
|
+
ref: J,
|
|
225
|
+
editor: Z,
|
|
226
|
+
threads: Y,
|
|
227
|
+
onThreadsChange: X,
|
|
228
|
+
onRequestAddComment: $,
|
|
229
|
+
currentUser: H
|
|
230
230
|
})]
|
|
231
231
|
}),
|
|
232
|
-
|
|
233
|
-
editor:
|
|
234
|
-
aiConfig:
|
|
235
|
-
labels:
|
|
232
|
+
P && Se && /* @__PURE__ */ f(te, {
|
|
233
|
+
editor: Z,
|
|
234
|
+
aiConfig: P,
|
|
235
|
+
labels: B,
|
|
236
236
|
initialSelection: Ce,
|
|
237
237
|
selectionRange: Te,
|
|
238
|
-
|
|
238
|
+
followSelection: L,
|
|
239
|
+
onClose: () => U(!1)
|
|
239
240
|
}),
|
|
240
|
-
/* @__PURE__ */
|
|
241
|
+
/* @__PURE__ */ f(ie, {
|
|
241
242
|
open: ke,
|
|
242
|
-
onSubmit:
|
|
243
|
-
onClose: () =>
|
|
243
|
+
onSubmit: je,
|
|
244
|
+
onClose: () => K(!1)
|
|
244
245
|
})
|
|
245
246
|
]
|
|
246
247
|
});
|
|
247
248
|
};
|
|
248
249
|
//#endregion
|
|
249
|
-
export {
|
|
250
|
+
export { O as default };
|
|
250
251
|
|
|
251
252
|
//# sourceMappingURL=RichTextEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.js","names":[],"sources":["../../../../src/components/pro/RichTextEditor/RichTextEditor.tsx"],"sourcesContent":["import React, { useEffect, useCallback, useState, useRef } from 'react';\nimport { cn } from '../../../utils/cn';\nimport { useEditor, EditorContent } from '@tiptap/react';\nimport StarterKit from '@tiptap/starter-kit';\nimport Underline from '@tiptap/extension-underline';\nimport { TextStyle } from '@tiptap/extension-text-style';\nimport Color from '@tiptap/extension-color';\nimport Highlight from '@tiptap/extension-highlight';\nimport TextAlign from '@tiptap/extension-text-align';\nimport Link from '@tiptap/extension-link';\nimport { Table } from '@tiptap/extension-table';\nimport TableRow from '@tiptap/extension-table-row';\nimport TableCell from '@tiptap/extension-table-cell';\nimport TableHeader from '@tiptap/extension-table-header';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport TaskList from '@tiptap/extension-task-list';\nimport TaskItem from '@tiptap/extension-task-item';\nimport Subscript from '@tiptap/extension-subscript';\nimport Superscript from '@tiptap/extension-superscript';\nimport Typography from '@tiptap/extension-typography';\nimport FontFamily from '@tiptap/extension-font-family';\n\nimport Toolbar from './Toolbar';\nimport AIRewrite from './AIRewrite';\nimport ContextMenu from './ContextMenu';\nimport CommentPanel from './CommentPanel';\nimport type { CommentPanelHandle } from './CommentPanel';\nimport CommentDialog from './CommentDialog';\nimport CommentPopover from './CommentPopover';\nimport SlashMenu from './SlashMenu';\nimport BubbleToolbar from './BubbleToolbar';\nimport BlockHandle from './BlockHandle';\nimport { MarkdownBlockExtension } from './extensions/MarkdownBlock';\nimport { CodeBlockExtension } from './extensions/CodeBlockView';\nimport FontSize from './extensions/FontSize';\nimport { ResizableImage } from './extensions/ResizableImage';\nimport { FloatingDialogExtension } from './extensions/FloatingDialog';\nimport { CommentMark } from './extensions/CommentMark';\nimport type { CommentThread } from './extensions/CommentMark';\nimport type { RichTextEditorProps } from './types';\nimport './styles.css';\n\nfunction generateId() {\n return `c_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;\n}\n\nconst RichTextEditor: React.FC<RichTextEditorProps> = ({\n content,\n value,\n onChange,\n onChangeJSON,\n placeholder = 'Start writing...',\n editable = true,\n aiConfig,\n onRequestAIConfig,\n toolbarConfig,\n minHeight = '200px',\n maxHeight,\n className = '',\n autofocus = false,\n labels,\n editorRef,\n showComments: initialShowComments = false,\n commentThreads: externalThreads,\n onCommentThreadsChange,\n currentUser,\n}) => {\n const [formatPainterActive, setFormatPainterActive] = useState(false);\n const [showAIPanel, setShowAIPanel] = useState(false);\n const [aiSelection, setAiSelection] = useState('');\n const [aiSelectionRange, setAiSelectionRange] = useState({ from: 0, to: 0 });\n const [showComments, setShowComments] = useState(initialShowComments);\n const [internalThreads, setInternalThreads] = useState<CommentThread[]>([]);\n const [commentDialogOpen, setCommentDialogOpen] = useState(false);\n const [commentSelectionRange, setCommentSelectionRange] = useState({ from: 0, to: 0 });\n const commentPanelRef = useRef<CommentPanelHandle>(null);\n\n const threads = externalThreads ?? internalThreads;\n const setThreads = onCommentThreadsChange ?? setInternalThreads;\n\n const editor = useEditor({\n extensions: [\n StarterKit.configure({\n codeBlock: false,\n heading: { levels: [1, 2, 3, 4, 5, 6] },\n // v3 StarterKit bundles these; explicit extensions below stay in charge.\n link: false,\n underline: false,\n }),\n Underline,\n TextStyle,\n Color,\n Highlight.configure({ multicolor: true }),\n TextAlign.configure({\n types: ['heading', 'paragraph'],\n }),\n Link.configure({\n openOnClick: false,\n autolink: true,\n HTMLAttributes: { class: 'rte-link' },\n }),\n ResizableImage.configure({ inline: false, allowBase64: true }),\n Table.configure({ resizable: true }),\n TableRow,\n TableCell,\n TableHeader,\n Placeholder.configure({ placeholder }),\n CodeBlockExtension,\n TaskList,\n TaskItem.configure({ nested: true }),\n Subscript,\n Superscript,\n Typography,\n FontFamily,\n FontSize,\n FloatingDialogExtension,\n MarkdownBlockExtension,\n CommentMark,\n ],\n content: value || content || '',\n editable,\n autofocus: autofocus ? 'end' : false,\n onUpdate: ({ editor: e }) => {\n onChange?.(e.getHTML());\n onChangeJSON?.(e.getJSON() as Record<string, unknown>);\n },\n });\n\n useEffect(() => {\n if (editorRef && editor) {\n editorRef.current = editor;\n }\n }, [editor, editorRef]);\n\n useEffect(() => {\n if (editor && value !== undefined) {\n const currentHTML = editor.getHTML();\n if (value !== currentHTML) {\n editor.commands.setContent(value, { emitUpdate: false });\n }\n }\n }, [editor, value]);\n\n useEffect(() => {\n if (editor) {\n editor.setEditable(editable);\n }\n }, [editor, editable]);\n\n const handleAIClick = useCallback(() => {\n if (!editor) return;\n const { from, to } = editor.state.selection;\n const text = from !== to\n ? editor.state.doc.textBetween(from, to, ' ')\n : '';\n setAiSelection(text);\n setAiSelectionRange({ from, to });\n setShowAIPanel(true);\n }, [editor]);\n\n const requestAddComment = useCallback(() => {\n if (!editor) return;\n const { from, to } = editor.state.selection;\n if (from === to) return;\n setCommentSelectionRange({ from, to });\n setCommentDialogOpen(true);\n }, [editor]);\n\n const handleCommentSubmit = useCallback((text: string) => {\n if (!editor) return;\n const id = generateId();\n const thread: CommentThread = {\n id,\n resolved: false,\n comments: [{\n id: generateId(),\n author: currentUser || 'User',\n text,\n createdAt: Date.now(),\n }],\n createdAt: Date.now(),\n };\n editor.chain()\n .focus()\n .setTextSelection(commentSelectionRange)\n .setComment(id)\n .run();\n setThreads([...threads, thread]);\n setCommentDialogOpen(false);\n }, [editor, commentSelectionRange, threads, setThreads, currentUser]);\n\n const handleScrollToThread = useCallback((id: string) => {\n commentPanelRef.current?.scrollToThread(id);\n }, []);\n\n if (!editor) return null;\n\n const minH = typeof minHeight === 'number' ? `${minHeight}px` : minHeight;\n const maxH = maxHeight ? (typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight) : undefined;\n\n const containerClass = cn(\n 'rte-container',\n formatPainterActive && 'rte-container--format-painter',\n className,\n );\n\n const activeCommentCount = threads.filter((t) => !t.resolved).length;\n\n const showCommentButton = toolbarConfig?.buttons?.comments ?? true;\n const toolbarEnd = showCommentButton ? (\n <div className=\"rte-toolbar__end\">\n <button\n type=\"button\"\n className={`rte-toolbar__btn rte-toolbar__comment-btn ${showComments ? 'rte-toolbar__btn--active' : ''}`}\n onClick={() => setShowComments(!showComments)}\n title=\"Toggle comments\"\n >\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <path d=\"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z\" />\n </svg>\n {activeCommentCount > 0 && <span className=\"rte-toolbar__comment-badge\" />}\n </button>\n </div>\n ) : null;\n\n return (\n <div className={containerClass} style={{ minHeight: minH, maxHeight: maxH }}>\n {editable && (\n <Toolbar\n editor={editor}\n config={toolbarConfig}\n labels={labels}\n hasAI={!!aiConfig}\n onAIClick={handleAIClick}\n onRequestAIConfig={onRequestAIConfig}\n onFormatPainterChange={setFormatPainterActive}\n >\n {toolbarEnd}\n </Toolbar>\n )}\n\n\n <div style={{ display: 'flex', flex: 1, overflow: 'hidden' }}>\n <div className=\"rte-editor-wrapper\" style={{ flex: 1 }}>\n <EditorContent editor={editor} className=\"rte-editor-content\" />\n {editable && <ContextMenu editor={editor} labels={labels} onAIClick={aiConfig ? handleAIClick : undefined} />}\n {editable && <SlashMenu editor={editor} />}\n {editable && <BubbleToolbar editor={editor} onAddComment={requestAddComment} />}\n {editable && <BlockHandle editor={editor} persistent />}\n <CommentPopover\n editor={editor}\n threads={threads}\n onThreadsChange={setThreads}\n showPanel={showComments}\n onOpenPanel={() => setShowComments(true)}\n onScrollToThread={handleScrollToThread}\n currentUser={currentUser}\n />\n </div>\n\n {showComments && (\n <CommentPanel\n ref={commentPanelRef}\n editor={editor}\n threads={threads}\n onThreadsChange={setThreads}\n onRequestAddComment={requestAddComment}\n currentUser={currentUser}\n />\n )}\n </div>\n\n {aiConfig && showAIPanel && (\n <AIRewrite\n editor={editor}\n aiConfig={aiConfig}\n labels={labels}\n initialSelection={aiSelection}\n selectionRange={aiSelectionRange}\n onClose={() => setShowAIPanel(false)}\n />\n )}\n\n <CommentDialog\n open={commentDialogOpen}\n onSubmit={handleCommentSubmit}\n onClose={() => setCommentDialogOpen(false)}\n />\n </div>\n );\n};\n\nexport default RichTextEditor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAS,IAAa;CACpB,OAAO,KAAK,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;AACjE;AAEA,IAAM,KAAiD,EACrD,YACA,UACA,aACA,iBACA,iBAAc,oBACd,cAAW,IACX,aACA,sBACA,kBACA,eAAY,SACZ,cACA,eAAY,IACZ,gBAAY,IACZ,WACA,cACA,cAAc,KAAsB,IACpC,gBAAgB,IAChB,4BACA,qBACI;CACJ,IAAM,CAAC,IAAqB,MAA0B,EAAS,EAAK,GAC9D,CAAC,IAAa,KAAkB,EAAS,EAAK,GAC9C,CAAC,IAAa,MAAkB,EAAS,EAAE,GAC3C,CAAC,IAAkB,MAAuB,EAAS;EAAE,MAAM;EAAG,IAAI;CAAE,CAAC,GACrE,CAAC,GAAc,KAAmB,EAAS,EAAmB,GAC9D,CAAC,IAAiB,MAAsB,EAA0B,CAAC,CAAC,GACpE,CAAC,IAAmB,KAAwB,EAAS,EAAK,GAC1D,CAAC,GAAuB,MAA4B,EAAS;EAAE,MAAM;EAAG,IAAI;CAAE,CAAC,GAC/E,IAAkB,GAA2B,IAAI,GAEjD,IAAU,MAAmB,IAC7B,IAAa,MAA0B,IA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AAiB;KACjB,qBAAqB;KACR;IACd,CAAA,CAEA;;GAEJ,KAAY,MACX,kBAAC,IAAD;IACU;IACE;IACF;IACR,kBAAkB;IAClB,gBAAgB;IAChB,eAAe,EAAe,EAAK;GACpC,CAAA;GAGH,kBAAC,IAAD;IACE,MAAM;IACN,UAAU;IACV,eAAe,EAAqB,EAAK;GAC1C,CAAA;EACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"RichTextEditor.js","names":[],"sources":["../../../../src/components/pro/RichTextEditor/RichTextEditor.tsx"],"sourcesContent":["import React, { useEffect, useCallback, useState, useRef } from 'react';\nimport { cn } from '../../../utils/cn';\nimport { useEditor, EditorContent } from '@tiptap/react';\nimport StarterKit from '@tiptap/starter-kit';\nimport Underline from '@tiptap/extension-underline';\nimport { TextStyle } from '@tiptap/extension-text-style';\nimport Color from '@tiptap/extension-color';\nimport Highlight from '@tiptap/extension-highlight';\nimport TextAlign from '@tiptap/extension-text-align';\nimport Link from '@tiptap/extension-link';\nimport { Table } from '@tiptap/extension-table';\nimport TableRow from '@tiptap/extension-table-row';\nimport TableCell from '@tiptap/extension-table-cell';\nimport TableHeader from '@tiptap/extension-table-header';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport TaskList from '@tiptap/extension-task-list';\nimport TaskItem from '@tiptap/extension-task-item';\nimport Subscript from '@tiptap/extension-subscript';\nimport Superscript from '@tiptap/extension-superscript';\nimport Typography from '@tiptap/extension-typography';\nimport FontFamily from '@tiptap/extension-font-family';\n\nimport Toolbar from './Toolbar';\nimport AIRewrite from './AIRewrite';\nimport ContextMenu from './ContextMenu';\nimport CommentPanel from './CommentPanel';\nimport type { CommentPanelHandle } from './CommentPanel';\nimport CommentDialog from './CommentDialog';\nimport CommentPopover from './CommentPopover';\nimport SlashMenu from './SlashMenu';\nimport BubbleToolbar from './BubbleToolbar';\nimport BlockHandle from './BlockHandle';\nimport { MarkdownBlockExtension } from './extensions/MarkdownBlock';\nimport { CodeBlockExtension } from './extensions/CodeBlockView';\nimport FontSize from './extensions/FontSize';\nimport { ResizableImage } from './extensions/ResizableImage';\nimport { FloatingDialogExtension } from './extensions/FloatingDialog';\nimport { CommentMark } from './extensions/CommentMark';\nimport type { CommentThread } from './extensions/CommentMark';\nimport type { RichTextEditorProps } from './types';\nimport './styles.css';\n\nfunction generateId() {\n return `c_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;\n}\n\nconst RichTextEditor: React.FC<RichTextEditorProps> = ({\n content,\n value,\n onChange,\n onChangeJSON,\n placeholder = 'Start writing...',\n editable = true,\n aiConfig,\n onRequestAIConfig,\n toolbarConfig,\n aiSelectionFollowsEditor = false,\n minHeight = '200px',\n maxHeight,\n className = '',\n autofocus = false,\n labels,\n editorRef,\n showComments: initialShowComments = false,\n commentThreads: externalThreads,\n onCommentThreadsChange,\n currentUser,\n}) => {\n const [formatPainterActive, setFormatPainterActive] = useState(false);\n const [showAIPanel, setShowAIPanel] = useState(false);\n const [aiSelection, setAiSelection] = useState('');\n const [aiSelectionRange, setAiSelectionRange] = useState({ from: 0, to: 0 });\n const [showComments, setShowComments] = useState(initialShowComments);\n const [internalThreads, setInternalThreads] = useState<CommentThread[]>([]);\n const [commentDialogOpen, setCommentDialogOpen] = useState(false);\n const [commentSelectionRange, setCommentSelectionRange] = useState({ from: 0, to: 0 });\n const commentPanelRef = useRef<CommentPanelHandle>(null);\n\n const threads = externalThreads ?? internalThreads;\n const setThreads = onCommentThreadsChange ?? setInternalThreads;\n\n const editor = useEditor({\n extensions: [\n StarterKit.configure({\n codeBlock: false,\n heading: { levels: [1, 2, 3, 4, 5, 6] },\n // v3 StarterKit bundles these; explicit extensions below stay in charge.\n link: false,\n underline: false,\n }),\n Underline,\n TextStyle,\n Color,\n Highlight.configure({ multicolor: true }),\n TextAlign.configure({\n types: ['heading', 'paragraph'],\n }),\n Link.configure({\n openOnClick: false,\n autolink: true,\n HTMLAttributes: { class: 'rte-link' },\n }),\n ResizableImage.configure({ inline: false, allowBase64: true }),\n Table.configure({ resizable: true }),\n TableRow,\n TableCell,\n TableHeader,\n Placeholder.configure({ placeholder }),\n CodeBlockExtension,\n TaskList,\n TaskItem.configure({ nested: true }),\n Subscript,\n Superscript,\n Typography,\n FontFamily,\n FontSize,\n FloatingDialogExtension,\n MarkdownBlockExtension,\n CommentMark,\n ],\n content: value || content || '',\n editable,\n autofocus: autofocus ? 'end' : false,\n onUpdate: ({ editor: e }) => {\n onChange?.(e.getHTML());\n onChangeJSON?.(e.getJSON() as Record<string, unknown>);\n },\n });\n\n useEffect(() => {\n if (editorRef && editor) {\n editorRef.current = editor;\n }\n }, [editor, editorRef]);\n\n useEffect(() => {\n if (editor && value !== undefined) {\n const currentHTML = editor.getHTML();\n if (value !== currentHTML) {\n editor.commands.setContent(value, { emitUpdate: false });\n }\n }\n }, [editor, value]);\n\n useEffect(() => {\n if (editor) {\n editor.setEditable(editable);\n }\n }, [editor, editable]);\n\n const handleAIClick = useCallback(() => {\n if (!editor) return;\n const { from, to } = editor.state.selection;\n const text = from !== to\n ? editor.state.doc.textBetween(from, to, ' ')\n : '';\n setAiSelection(text);\n setAiSelectionRange({ from, to });\n setShowAIPanel(true);\n }, [editor]);\n\n const requestAddComment = useCallback(() => {\n if (!editor) return;\n const { from, to } = editor.state.selection;\n if (from === to) return;\n setCommentSelectionRange({ from, to });\n setCommentDialogOpen(true);\n }, [editor]);\n\n const handleCommentSubmit = useCallback((text: string) => {\n if (!editor) return;\n const id = generateId();\n const thread: CommentThread = {\n id,\n resolved: false,\n comments: [{\n id: generateId(),\n author: currentUser || 'User',\n text,\n createdAt: Date.now(),\n }],\n createdAt: Date.now(),\n };\n editor.chain()\n .focus()\n .setTextSelection(commentSelectionRange)\n .setComment(id)\n .run();\n setThreads([...threads, thread]);\n setCommentDialogOpen(false);\n }, [editor, commentSelectionRange, threads, setThreads, currentUser]);\n\n const handleScrollToThread = useCallback((id: string) => {\n commentPanelRef.current?.scrollToThread(id);\n }, []);\n\n if (!editor) return null;\n\n const minH = typeof minHeight === 'number' ? `${minHeight}px` : minHeight;\n const maxH = maxHeight ? (typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight) : undefined;\n\n const containerClass = cn(\n 'rte-container',\n formatPainterActive && 'rte-container--format-painter',\n className,\n );\n\n const activeCommentCount = threads.filter((t) => !t.resolved).length;\n\n const showCommentButton = toolbarConfig?.buttons?.comments ?? true;\n const toolbarEnd = showCommentButton ? (\n <div className=\"rte-toolbar__end\">\n <button\n type=\"button\"\n className={`rte-toolbar__btn rte-toolbar__comment-btn ${showComments ? 'rte-toolbar__btn--active' : ''}`}\n onClick={() => setShowComments(!showComments)}\n title=\"Toggle comments\"\n >\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <path d=\"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z\" />\n </svg>\n {activeCommentCount > 0 && <span className=\"rte-toolbar__comment-badge\" />}\n </button>\n </div>\n ) : null;\n\n return (\n <div className={containerClass} style={{ minHeight: minH, maxHeight: maxH }}>\n {editable && (\n <Toolbar\n editor={editor}\n config={toolbarConfig}\n labels={labels}\n hasAI={!!aiConfig}\n onAIClick={handleAIClick}\n onRequestAIConfig={onRequestAIConfig}\n onFormatPainterChange={setFormatPainterActive}\n >\n {toolbarEnd}\n </Toolbar>\n )}\n\n\n <div style={{ display: 'flex', flex: 1, overflow: 'hidden' }}>\n <div className=\"rte-editor-wrapper\" style={{ flex: 1 }}>\n <EditorContent editor={editor} className=\"rte-editor-content\" />\n {editable && <ContextMenu editor={editor} labels={labels} onAIClick={aiConfig ? handleAIClick : undefined} />}\n {editable && <SlashMenu editor={editor} />}\n {editable && <BubbleToolbar editor={editor} onAddComment={requestAddComment} />}\n {editable && <BlockHandle editor={editor} persistent />}\n <CommentPopover\n editor={editor}\n threads={threads}\n onThreadsChange={setThreads}\n showPanel={showComments}\n onOpenPanel={() => setShowComments(true)}\n onScrollToThread={handleScrollToThread}\n currentUser={currentUser}\n />\n </div>\n\n {showComments && (\n <CommentPanel\n ref={commentPanelRef}\n editor={editor}\n threads={threads}\n onThreadsChange={setThreads}\n onRequestAddComment={requestAddComment}\n currentUser={currentUser}\n />\n )}\n </div>\n\n {aiConfig && showAIPanel && (\n <AIRewrite\n editor={editor}\n aiConfig={aiConfig}\n labels={labels}\n initialSelection={aiSelection}\n selectionRange={aiSelectionRange}\n followSelection={aiSelectionFollowsEditor}\n onClose={() => setShowAIPanel(false)}\n />\n )}\n\n <CommentDialog\n open={commentDialogOpen}\n onSubmit={handleCommentSubmit}\n onClose={() => setCommentDialogOpen(false)}\n />\n </div>\n );\n};\n\nexport default RichTextEditor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAS,IAAa;CACpB,OAAO,KAAK,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;AACjE;AAEA,IAAM,KAAiD,EACrD,YACA,UACA,aACA,iBACA,iBAAc,oBACd,cAAW,IACX,aACA,sBACA,kBACA,8BAA2B,IAC3B,eAAY,SACZ,cACA,gBAAY,IACZ,gBAAY,IACZ,WACA,cACA,cAAc,KAAsB,IACpC,gBAAgB,IAChB,4BACA,qBACI;CACJ,IAAM,CAAC,IAAqB,MAA0B,EAAS,EAAK,GAC9D,CAAC,IAAa,KAAkB,EAAS,EAAK,GAC9C,CAAC,IAAa,MAAkB,EAAS,EAAE,GAC3C,CAAC,IAAkB,MAAuB,EAAS;EAAE,MAAM;EAAG,IAAI;CAAE,CAAC,GACrE,CAAC,GAAc,KAAmB,EAAS,EAAmB,GAC9D,CAAC,IAAiB,MAAsB,EAA0B,CAAC,CAAC,GACpE,CAAC,IAAmB,KAAwB,EAAS,EAAK,GAC1D,CAAC,GAAuB,MAA4B,EAAS;EAAE,MAAM;EAAG,IAAI;C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;MACd,CAAA;KACE;IAEJ,CAAA,GAAA,KACC,kBAAC,IAAD;KACE,KAAK;KACG;KACC;KACT,iBAAiB;KACjB,qBAAqB;KACR;IACd,CAAA,CAEA;;GAEJ,KAAY,MACX,kBAAC,IAAD;IACU;IACE;IACF;IACR,kBAAkB;IAClB,gBAAgB;IAChB,iBAAiB;IACjB,eAAe,EAAe,EAAK;GACpC,CAAA;GAGH,kBAAC,IAAD;IACE,MAAM;IACN,UAAU;IACV,eAAe,EAAqB,EAAK;GAC1C,CAAA;EACE;;AAET"}
|
|
@@ -7,6 +7,8 @@ interface ColorPickerProps {
|
|
|
7
7
|
kind?: 'text' | 'highlight';
|
|
8
8
|
/** Button class; defaults to the classic toolbar button. Bubble toolbar passes its own. */
|
|
9
9
|
buttonClassName?: string;
|
|
10
|
+
/** Portals the palette outside scroll-clipped bubble toolbars. */
|
|
11
|
+
portalOwner?: string;
|
|
10
12
|
}
|
|
11
13
|
export declare const ColorPicker: React.FC<ColorPickerProps>;
|
|
12
14
|
export {};
|
|
@@ -1,36 +1,88 @@
|
|
|
1
1
|
import { useAnchoredDropdown as e } from "./useAnchoredDropdown.js";
|
|
2
2
|
import { useEffect as t, useId as n, useRef as r, useState as i } from "react";
|
|
3
3
|
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
4
|
+
import { createPortal as s } from "react-dom";
|
|
4
5
|
//#region src/components/pro/RichTextEditor/Toolbar/ColorPicker.tsx
|
|
5
|
-
var
|
|
6
|
-
let [
|
|
7
|
-
|
|
6
|
+
var c = /* @__PURE__ */ "#000000.#434343.#666666.#999999.#cccccc.#eeeeee.#ffffff.#ff0000.#ff4500.#ff8c00.#ffd700.#32cd32.#00bfff.#8a2be2.#ff69b4.#dc143c.#ff6347.#ffa500.#9acd32.#20b2aa.#4169e1.#9370db.#db7093.#b22222.#d2691e.#daa520.#228b22.#008b8b.#191970.#4b0082".split("."), l = ({ value: l, onChange: u, title: d, icon: f, kind: p = "text", buttonClassName: m = "rte-toolbar__btn", portalOwner: h }) => {
|
|
7
|
+
let [g, _] = i(!1), [v, y] = i({}), b = r(null), x = r(null), S = r(null), C = n(), w = e(g, x, S), T = d || (p === "text" ? "Text color" : "Highlight color"), E = `${T}: ${l || (p === "text" ? "Default" : "None")}`;
|
|
8
|
+
t(() => {
|
|
8
9
|
let e = (e) => {
|
|
9
|
-
|
|
10
|
+
b.current && !b.current.contains(e.target) && !S.current?.contains(e.target) && _(!1);
|
|
10
11
|
};
|
|
11
12
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
12
|
-
}, [])
|
|
13
|
-
|
|
13
|
+
}, [b, S]);
|
|
14
|
+
let D = g && /* @__PURE__ */ o("div", {
|
|
15
|
+
ref: S,
|
|
16
|
+
id: C,
|
|
17
|
+
"data-rte-palette-owner": h,
|
|
18
|
+
className: "rte-toolbar__color-dropdown",
|
|
19
|
+
role: "group",
|
|
20
|
+
"aria-label": T,
|
|
21
|
+
style: {
|
|
22
|
+
...w,
|
|
23
|
+
...v
|
|
24
|
+
},
|
|
25
|
+
children: [c.map((e) => /* @__PURE__ */ a("button", {
|
|
26
|
+
type: "button",
|
|
27
|
+
className: `rte-toolbar__color-swatch ${e === l ? "rte-toolbar__color-swatch--active" : ""}`,
|
|
28
|
+
style: { backgroundColor: e },
|
|
29
|
+
onMouseDown: h ? (e) => e.preventDefault() : void 0,
|
|
30
|
+
onClick: () => {
|
|
31
|
+
u(e), _(!1);
|
|
32
|
+
},
|
|
33
|
+
title: `${T}: ${e}`,
|
|
34
|
+
"aria-label": `${T}: ${e}`,
|
|
35
|
+
"aria-pressed": e.toLowerCase() === l.toLowerCase()
|
|
36
|
+
}, e)), /* @__PURE__ */ a("button", {
|
|
37
|
+
type: "button",
|
|
38
|
+
className: "rte-toolbar__color-clear",
|
|
39
|
+
onMouseDown: h ? (e) => e.preventDefault() : void 0,
|
|
40
|
+
onClick: () => {
|
|
41
|
+
u(""), _(!1);
|
|
42
|
+
},
|
|
43
|
+
title: `Clear ${T}`,
|
|
44
|
+
"aria-label": `Clear ${T}`,
|
|
45
|
+
"aria-pressed": !l,
|
|
46
|
+
children: "Clear"
|
|
47
|
+
})]
|
|
48
|
+
});
|
|
49
|
+
return /* @__PURE__ */ o("div", {
|
|
50
|
+
ref: b,
|
|
14
51
|
className: "rte-toolbar__color-picker",
|
|
15
52
|
onBlur: (e) => {
|
|
16
|
-
e.currentTarget.contains(e.relatedTarget)
|
|
53
|
+
!e.currentTarget.contains(e.relatedTarget) && !S.current?.contains(e.relatedTarget) && _(!1);
|
|
17
54
|
},
|
|
18
55
|
onKeyDown: (e) => {
|
|
19
|
-
e.key === "Escape" &&
|
|
56
|
+
e.key === "Escape" && g && (e.preventDefault(), e.stopPropagation(), _(!1), x.current?.focus());
|
|
20
57
|
},
|
|
21
58
|
children: [/* @__PURE__ */ a("button", {
|
|
22
59
|
type: "button",
|
|
23
|
-
ref:
|
|
24
|
-
className: `${
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
60
|
+
ref: x,
|
|
61
|
+
className: `${m} rte-toolbar__color-trigger`,
|
|
62
|
+
onMouseDown: h ? (e) => e.preventDefault() : void 0,
|
|
63
|
+
onClick: (e) => {
|
|
64
|
+
if (h && !g) {
|
|
65
|
+
let t = getComputedStyle(e.currentTarget), n = {};
|
|
66
|
+
for (let e of [
|
|
67
|
+
"--rte-bg",
|
|
68
|
+
"--rte-text",
|
|
69
|
+
"--rte-border",
|
|
70
|
+
"--rte-placeholder",
|
|
71
|
+
"--rte-active-color",
|
|
72
|
+
"--rte-toolbar-btn-hover"
|
|
73
|
+
]) n[e] = t.getPropertyValue(e);
|
|
74
|
+
y(n);
|
|
75
|
+
}
|
|
76
|
+
_(!g);
|
|
77
|
+
},
|
|
78
|
+
title: E,
|
|
79
|
+
"aria-label": E,
|
|
80
|
+
"aria-expanded": g,
|
|
81
|
+
"aria-controls": g ? C : void 0,
|
|
30
82
|
children: /* @__PURE__ */ o("span", {
|
|
31
|
-
className: `rte-toolbar__color-icon rte-toolbar__color-icon--${
|
|
83
|
+
className: `rte-toolbar__color-icon rte-toolbar__color-icon--${p}`,
|
|
32
84
|
"aria-hidden": "true",
|
|
33
|
-
children: [
|
|
85
|
+
children: [f || (p === "text" ? /* @__PURE__ */ a("span", {
|
|
34
86
|
className: "rte-toolbar__color-letter",
|
|
35
87
|
children: "A"
|
|
36
88
|
}) : /* @__PURE__ */ a("svg", {
|
|
@@ -44,42 +96,14 @@ var s = /* @__PURE__ */ "#000000.#434343.#666666.#999999.#cccccc.#eeeeee.#ffffff
|
|
|
44
96
|
strokeLinejoin: "round",
|
|
45
97
|
children: /* @__PURE__ */ a("path", { d: "m14 3 7 7-9 9-7-7zM5 12l-2 7 2 2 7-2M14 7l3 3M3 21h6" })
|
|
46
98
|
})), /* @__PURE__ */ a("span", {
|
|
47
|
-
className: `rte-toolbar__color-indicator${
|
|
48
|
-
style: { backgroundColor:
|
|
99
|
+
className: `rte-toolbar__color-indicator${l ? "" : " rte-toolbar__color-indicator--empty"}`,
|
|
100
|
+
style: { backgroundColor: l || void 0 }
|
|
49
101
|
})]
|
|
50
102
|
})
|
|
51
|
-
}),
|
|
52
|
-
ref: v,
|
|
53
|
-
id: y,
|
|
54
|
-
className: "rte-toolbar__color-dropdown",
|
|
55
|
-
role: "group",
|
|
56
|
-
"aria-label": x,
|
|
57
|
-
style: b,
|
|
58
|
-
children: [s.map((e) => /* @__PURE__ */ a("button", {
|
|
59
|
-
type: "button",
|
|
60
|
-
className: `rte-toolbar__color-swatch ${e === c ? "rte-toolbar__color-swatch--active" : ""}`,
|
|
61
|
-
style: { backgroundColor: e },
|
|
62
|
-
onClick: () => {
|
|
63
|
-
l(e), h(!1);
|
|
64
|
-
},
|
|
65
|
-
title: `${x}: ${e}`,
|
|
66
|
-
"aria-label": `${x}: ${e}`,
|
|
67
|
-
"aria-pressed": e.toLowerCase() === c.toLowerCase()
|
|
68
|
-
}, e)), /* @__PURE__ */ a("button", {
|
|
69
|
-
type: "button",
|
|
70
|
-
className: "rte-toolbar__color-clear",
|
|
71
|
-
onClick: () => {
|
|
72
|
-
l(""), h(!1);
|
|
73
|
-
},
|
|
74
|
-
title: `Clear ${x}`,
|
|
75
|
-
"aria-label": `Clear ${x}`,
|
|
76
|
-
"aria-pressed": !c,
|
|
77
|
-
children: "Clear"
|
|
78
|
-
})]
|
|
79
|
-
})]
|
|
103
|
+
}), h && typeof document < "u" ? s(D, document.body) : D]
|
|
80
104
|
});
|
|
81
105
|
};
|
|
82
106
|
//#endregion
|
|
83
|
-
export {
|
|
107
|
+
export { l as ColorPicker };
|
|
84
108
|
|
|
85
109
|
//# sourceMappingURL=ColorPicker.js.map
|