dishui 0.0.104 → 0.0.106
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/Flow/nodes/MediaContent.d.ts +2 -1
- package/dist/components/pro/Flow/nodes/MediaContent.js +15 -15
- package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaOverlay.js +8 -7
- package/dist/components/pro/Flow/nodes/MediaOverlay.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/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/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
|
@@ -1,68 +1,65 @@
|
|
|
1
1
|
import { ColorPicker as e } from "./Toolbar/ColorPicker.js";
|
|
2
|
-
import { FONT_FAMILIES as t, FONT_SIZES as n } from "./Toolbar/SelectDropdown.js";
|
|
3
|
-
import { useEffect as
|
|
4
|
-
import { Fragment as
|
|
5
|
-
import { useEditorState as
|
|
6
|
-
import { TextSelection as
|
|
2
|
+
import { FONT_FAMILIES as t, FONT_SIZES as n, SelectDropdown as r } from "./Toolbar/SelectDropdown.js";
|
|
3
|
+
import { useCallback as i, useEffect as a, useId as o, useLayoutEffect as s, useRef as c, useState as l } from "react";
|
|
4
|
+
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
5
|
+
import { useEditorState as p } from "@tiptap/react";
|
|
6
|
+
import { TextSelection as m } from "@tiptap/pm/state";
|
|
7
7
|
//#region src/components/pro/RichTextEditor/BubbleToolbar.tsx
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
editor:
|
|
8
|
+
var h = ({ editor: h, onAddComment: g }) => {
|
|
9
|
+
p({
|
|
10
|
+
editor: h,
|
|
11
11
|
selector: ({ transactionNumber: e }) => e
|
|
12
12
|
});
|
|
13
|
-
let [
|
|
13
|
+
let [_, v] = l(!1), [y, b] = l({
|
|
14
14
|
x: 0,
|
|
15
15
|
y: 0
|
|
16
|
-
}),
|
|
17
|
-
if (
|
|
18
|
-
if (
|
|
19
|
-
let e =
|
|
16
|
+
}), x = c(null), S = o(), C = i((e) => e instanceof Element && e.closest(`[data-rte-palette-owner="${S}"]`) !== null, [S]);
|
|
17
|
+
if (a(() => {
|
|
18
|
+
if (h.isDestroyed) return;
|
|
19
|
+
let e = h.view.dom.ownerDocument, t = e.defaultView;
|
|
20
20
|
if (!t) return;
|
|
21
21
|
let n = null, r = () => {
|
|
22
|
-
n !== null && t.cancelAnimationFrame(n), n = null,
|
|
22
|
+
n !== null && t.cancelAnimationFrame(n), n = null, v(!1);
|
|
23
23
|
}, i = () => {
|
|
24
|
-
if (n = null,
|
|
24
|
+
if (n = null, h.isDestroyed) {
|
|
25
25
|
r();
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
let { from: t, to: i } =
|
|
29
|
-
if (!
|
|
30
|
-
|
|
28
|
+
let { from: t, to: i } = h.state.selection;
|
|
29
|
+
if (!h.isEditable || !(h.state.selection instanceof m) || t === i || !h.isFocused && !x.current?.contains(e.activeElement) && !C(e.activeElement)) {
|
|
30
|
+
v(!1);
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
let a =
|
|
33
|
+
let a = h.view.coordsAtPos(t), o = h.view.coordsAtPos(i), s = h.view.dom.closest(".rte-editor-wrapper");
|
|
34
34
|
if (!s) {
|
|
35
35
|
r();
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
let c = s.getBoundingClientRect(), l = (a.left + o.left) / 2 - c.left - s.clientLeft + s.scrollLeft, u = Math.min(a.top, o.top) - c.top - s.clientTop + s.scrollTop - 44;
|
|
39
|
-
|
|
39
|
+
b({
|
|
40
40
|
x: l,
|
|
41
41
|
y: u
|
|
42
|
-
}),
|
|
42
|
+
}), v(!0);
|
|
43
43
|
}, a = () => {
|
|
44
44
|
n !== null && t.cancelAnimationFrame(n), n = t.requestAnimationFrame(i);
|
|
45
45
|
}, o = ({ event: e }) => {
|
|
46
|
-
e.relatedTarget instanceof Node &&
|
|
46
|
+
e.relatedTarget instanceof Node && (x.current?.contains(e.relatedTarget) || C(e.relatedTarget)) || r();
|
|
47
47
|
};
|
|
48
|
-
return
|
|
49
|
-
n !== null && t.cancelAnimationFrame(n),
|
|
48
|
+
return h.on("transaction", a), h.on("selectionUpdate", a), h.on("focus", a), h.on("blur", o), h.on("destroy", r), e.addEventListener("scroll", a, !0), t.addEventListener("resize", a), i(), () => {
|
|
49
|
+
n !== null && t.cancelAnimationFrame(n), h.off("transaction", a), h.off("selectionUpdate", a), h.off("focus", a), h.off("blur", o), h.off("destroy", r), e.removeEventListener("scroll", a, !0), t.removeEventListener("resize", a);
|
|
50
50
|
};
|
|
51
|
-
}, [
|
|
52
|
-
if (!
|
|
53
|
-
let e =
|
|
51
|
+
}, [h, C]), s(() => {
|
|
52
|
+
if (!_ || !x.current) return;
|
|
53
|
+
let e = x.current, t = e.parentElement;
|
|
54
54
|
if (!t) return;
|
|
55
|
-
let n =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}));
|
|
60
|
-
}, [m, g.x]), !m || f.isDestroyed || !f.isEditable) return null;
|
|
61
|
-
let y = (e, t, n, r) => /* @__PURE__ */ c("button", {
|
|
55
|
+
let n = e.offsetWidth;
|
|
56
|
+
e.style.left = `${Math.max(0, Math.min(y.x - n / 2, t.clientWidth - n))}px`;
|
|
57
|
+
}, [_, y.x]), !_ || h.isDestroyed || !h.isEditable) return null;
|
|
58
|
+
let w = (e, t, n, r) => /* @__PURE__ */ d("button", {
|
|
62
59
|
type: "button",
|
|
63
60
|
className: `rte-bubble__btn ${n ? "rte-bubble__btn--active" : ""}`,
|
|
64
61
|
onClick: () => {
|
|
65
|
-
!
|
|
62
|
+
!h.isDestroyed && h.isEditable && e();
|
|
66
63
|
},
|
|
67
64
|
title: t,
|
|
68
65
|
"aria-label": t,
|
|
@@ -70,124 +67,117 @@ var f = ({ editor: f, onAddComment: p }) => {
|
|
|
70
67
|
onMouseDown: (e) => e.preventDefault(),
|
|
71
68
|
children: r
|
|
72
69
|
});
|
|
73
|
-
return /* @__PURE__ */
|
|
74
|
-
ref:
|
|
70
|
+
return /* @__PURE__ */ f("div", {
|
|
71
|
+
ref: x,
|
|
75
72
|
className: "rte-bubble",
|
|
76
73
|
role: "group",
|
|
77
74
|
"aria-label": "Selection formatting",
|
|
78
75
|
onBlur: (e) => {
|
|
79
|
-
!e.currentTarget.contains(e.relatedTarget) && !
|
|
76
|
+
!e.currentTarget.contains(e.relatedTarget) && !C(e.relatedTarget) && !h.isFocused && v(!1);
|
|
80
77
|
},
|
|
81
78
|
onKeyDown: (e) => {
|
|
82
|
-
e.key === "Escape" && (e.preventDefault(),
|
|
83
|
-
},
|
|
84
|
-
style: {
|
|
85
|
-
left: g.x,
|
|
86
|
-
top: g.y
|
|
79
|
+
e.key === "Escape" && (e.preventDefault(), h.commands.focus(), v(!1));
|
|
87
80
|
},
|
|
81
|
+
style: { top: y.y },
|
|
88
82
|
children: [
|
|
89
|
-
|
|
83
|
+
w(() => h.chain().focus().toggleBold().run(), "Bold", h.isActive("bold"), /* @__PURE__ */ d("strong", {
|
|
90
84
|
style: { fontSize: 13 },
|
|
91
85
|
children: "B"
|
|
92
86
|
})),
|
|
93
|
-
|
|
87
|
+
w(() => h.chain().focus().toggleItalic().run(), "Italic", h.isActive("italic"), /* @__PURE__ */ d("em", {
|
|
94
88
|
style: { fontSize: 13 },
|
|
95
89
|
children: "I"
|
|
96
90
|
})),
|
|
97
|
-
|
|
91
|
+
w(() => h.chain().focus().toggleUnderline().run(), "Underline", h.isActive("underline"), /* @__PURE__ */ d("span", {
|
|
98
92
|
style: {
|
|
99
93
|
fontSize: 13,
|
|
100
94
|
textDecoration: "underline"
|
|
101
95
|
},
|
|
102
96
|
children: "U"
|
|
103
97
|
})),
|
|
104
|
-
|
|
98
|
+
w(() => h.chain().focus().toggleStrike().run(), "Strike", h.isActive("strike"), /* @__PURE__ */ d("span", {
|
|
105
99
|
style: {
|
|
106
100
|
fontSize: 13,
|
|
107
101
|
textDecoration: "line-through"
|
|
108
102
|
},
|
|
109
103
|
children: "S"
|
|
110
104
|
})),
|
|
111
|
-
|
|
105
|
+
w(() => h.chain().focus().toggleCode().run(), "Code", h.isActive("code"), /* @__PURE__ */ d("span", {
|
|
112
106
|
style: {
|
|
113
107
|
fontSize: 11,
|
|
114
108
|
fontFamily: "monospace"
|
|
115
109
|
},
|
|
116
110
|
children: "</>"
|
|
117
111
|
})),
|
|
118
|
-
|
|
119
|
-
let e = window.prompt("URL:",
|
|
120
|
-
if (e === null ||
|
|
121
|
-
let t =
|
|
112
|
+
w(() => {
|
|
113
|
+
let e = window.prompt("URL:", h.getAttributes("link").href || "");
|
|
114
|
+
if (e === null || h.isDestroyed || !h.isEditable) return;
|
|
115
|
+
let t = h.chain().focus().extendMarkRange("link");
|
|
122
116
|
e.trim() === "" ? t.unsetLink().run() : t.setLink({ href: e.trim() }).run();
|
|
123
|
-
}, "Link",
|
|
117
|
+
}, "Link", h.isActive("link"), /* @__PURE__ */ f("svg", {
|
|
124
118
|
width: "14",
|
|
125
119
|
height: "14",
|
|
126
120
|
viewBox: "0 0 24 24",
|
|
127
121
|
fill: "none",
|
|
128
122
|
stroke: "currentColor",
|
|
129
123
|
strokeWidth: "2",
|
|
130
|
-
children: [/* @__PURE__ */
|
|
124
|
+
children: [/* @__PURE__ */ d("path", { d: "M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71" }), /* @__PURE__ */ d("path", { d: "M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71" })]
|
|
131
125
|
})),
|
|
132
|
-
/* @__PURE__ */
|
|
133
|
-
/* @__PURE__ */
|
|
134
|
-
value:
|
|
126
|
+
/* @__PURE__ */ d("div", { className: "rte-bubble__divider" }),
|
|
127
|
+
/* @__PURE__ */ d(e, {
|
|
128
|
+
value: h.getAttributes("textStyle").color || "",
|
|
135
129
|
onChange: (e) => {
|
|
136
|
-
!
|
|
130
|
+
!h.isDestroyed && h.isEditable && (e ? h.chain().focus().setColor(e).run() : h.chain().focus().unsetColor().run());
|
|
137
131
|
},
|
|
138
132
|
title: "Text color",
|
|
139
133
|
buttonClassName: "rte-bubble__btn",
|
|
134
|
+
portalOwner: S,
|
|
140
135
|
kind: "text"
|
|
141
136
|
}),
|
|
142
|
-
/* @__PURE__ */
|
|
143
|
-
value:
|
|
137
|
+
/* @__PURE__ */ d(e, {
|
|
138
|
+
value: h.getAttributes("highlight").color || "",
|
|
144
139
|
onChange: (e) => {
|
|
145
|
-
!
|
|
140
|
+
!h.isDestroyed && h.isEditable && (e ? h.chain().focus().toggleHighlight({ color: e }).run() : h.chain().focus().unsetHighlight().run());
|
|
146
141
|
},
|
|
147
142
|
title: "Highlight color",
|
|
148
143
|
buttonClassName: "rte-bubble__btn",
|
|
144
|
+
portalOwner: S,
|
|
149
145
|
kind: "highlight"
|
|
150
146
|
}),
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
147
|
+
/* @__PURE__ */ d("div", { className: "rte-bubble__divider" }),
|
|
148
|
+
/* @__PURE__ */ d(r, {
|
|
153
149
|
className: "rte-bubble__select",
|
|
154
|
-
|
|
150
|
+
width: 96,
|
|
151
|
+
value: h.getAttributes("textStyle").fontFamily || "",
|
|
152
|
+
options: t,
|
|
155
153
|
onChange: (e) => {
|
|
156
|
-
!
|
|
154
|
+
!h.isDestroyed && h.isEditable && (e ? h.chain().focus().setFontFamily(e).run() : h.chain().focus().unsetFontFamily().run());
|
|
157
155
|
},
|
|
158
|
-
title: "Font family"
|
|
159
|
-
"aria-label": "Font family",
|
|
160
|
-
children: t.map((e) => /* @__PURE__ */ c("option", {
|
|
161
|
-
value: e.value,
|
|
162
|
-
children: e.label
|
|
163
|
-
}, e.value))
|
|
156
|
+
title: "Font family"
|
|
164
157
|
}),
|
|
165
|
-
/* @__PURE__ */
|
|
158
|
+
/* @__PURE__ */ d(r, {
|
|
166
159
|
className: "rte-bubble__select rte-bubble__select--size",
|
|
167
|
-
|
|
160
|
+
width: 72,
|
|
161
|
+
value: h.getAttributes("textStyle").fontSize || "",
|
|
162
|
+
options: n,
|
|
168
163
|
onChange: (e) => {
|
|
169
|
-
!
|
|
164
|
+
!h.isDestroyed && h.isEditable && (e ? h.chain().focus().setFontSize(e).run() : h.chain().focus().unsetFontSize().run());
|
|
170
165
|
},
|
|
171
|
-
title: "Font size"
|
|
172
|
-
"aria-label": "Font size",
|
|
173
|
-
children: n.map((e) => /* @__PURE__ */ c("option", {
|
|
174
|
-
value: e.value,
|
|
175
|
-
children: e.label
|
|
176
|
-
}, e.value))
|
|
166
|
+
title: "Font size"
|
|
177
167
|
}),
|
|
178
|
-
|
|
168
|
+
g && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("div", { className: "rte-bubble__divider" }), w(g, "Comment", void 0, /* @__PURE__ */ d("svg", {
|
|
179
169
|
width: "14",
|
|
180
170
|
height: "14",
|
|
181
171
|
viewBox: "0 0 24 24",
|
|
182
172
|
fill: "none",
|
|
183
173
|
stroke: "currentColor",
|
|
184
174
|
strokeWidth: "2",
|
|
185
|
-
children: /* @__PURE__ */
|
|
175
|
+
children: /* @__PURE__ */ d("path", { d: "M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z" })
|
|
186
176
|
}))] })
|
|
187
177
|
]
|
|
188
178
|
});
|
|
189
179
|
};
|
|
190
180
|
//#endregion
|
|
191
|
-
export {
|
|
181
|
+
export { h as default };
|
|
192
182
|
|
|
193
183
|
//# sourceMappingURL=BubbleToolbar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BubbleToolbar.js","names":[],"sources":["../../../../src/components/pro/RichTextEditor/BubbleToolbar.tsx"],"sourcesContent":["import React, { useState, useEffect, useLayoutEffect, useRef } from 'react';\nimport { useEditorState, type Editor } from '@tiptap/react';\nimport { TextSelection } from '@tiptap/pm/state';\nimport { ColorPicker } from './Toolbar/ColorPicker';\nimport { FONT_FAMILIES, FONT_SIZES } from './Toolbar/SelectDropdown';\n\ninterface BubbleToolbarProps {\n editor: Editor;\n onAddComment?: () => void;\n}\n\nconst BubbleToolbar: React.FC<BubbleToolbarProps> = ({ editor, onAddComment }) => {\n useEditorState({ editor, selector: ({ transactionNumber }) => transactionNumber });\n const [visible, setVisible] = useState(false);\n const [pos, setPos] = useState({ x: 0, y: 0 });\n const ref = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (editor.isDestroyed) return;\n const doc = editor.view.dom.ownerDocument;\n const win = doc.defaultView;\n if (!win) return;\n let frame: number | null = null;\n const hide = () => {\n if (frame !== null) win.cancelAnimationFrame(frame);\n frame = null;\n setVisible(false);\n };\n const update = () => {\n frame = null;\n if (editor.isDestroyed) { hide(); return; }\n const { from, to } = editor.state.selection;\n if (!editor.isEditable || !(editor.state.selection instanceof TextSelection) || from === to || (!editor.isFocused && !ref.current?.contains(doc.activeElement))) {\n setVisible(false);\n return;\n }\n const coords = editor.view.coordsAtPos(from);\n const endCoords = editor.view.coordsAtPos(to);\n const wrapperEl = editor.view.dom.closest<HTMLElement>('.rte-editor-wrapper');\n if (!wrapperEl) { hide(); return; }\n const rect = wrapperEl.getBoundingClientRect();\n\n const centerX = (coords.left + endCoords.left) / 2 - rect.left - wrapperEl.clientLeft + wrapperEl.scrollLeft;\n const topY = Math.min(coords.top, endCoords.top) - rect.top - wrapperEl.clientTop + wrapperEl.scrollTop - 44;\n\n setPos({ x: centerX, y: topY });\n setVisible(true);\n };\n\n const scheduleUpdate = () => {\n if (frame !== null) win.cancelAnimationFrame(frame);\n frame = win.requestAnimationFrame(update);\n };\n const onBlur = ({ event }: { event: FocusEvent }) => {\n if (event.relatedTarget instanceof Node && ref.current?.contains(event.relatedTarget)) return;\n hide();\n };\n editor.on('transaction', scheduleUpdate);\n editor.on('selectionUpdate', scheduleUpdate);\n editor.on('focus', scheduleUpdate);\n editor.on('blur', onBlur);\n editor.on('destroy', hide);\n doc.addEventListener('scroll', scheduleUpdate, true);\n win.addEventListener('resize', scheduleUpdate);\n update();\n return () => {\n if (frame !== null) win.cancelAnimationFrame(frame);\n editor.off('transaction', scheduleUpdate);\n editor.off('selectionUpdate', scheduleUpdate);\n editor.off('focus', scheduleUpdate);\n editor.off('blur', onBlur);\n editor.off('destroy', hide);\n doc.removeEventListener('scroll', scheduleUpdate, true);\n win.removeEventListener('resize', scheduleUpdate);\n };\n }, [editor]);\n\n // Keep the bubble inside the wrapper horizontally: with the extra color /\n // font controls it can be wider than a phone-size editor, and transform:\n // translateX(-50%) would otherwise clip it at either edge.\n useLayoutEffect(() => {\n if (!visible || !ref.current) return;\n const el = ref.current;\n const wrapper = el.parentElement;\n if (!wrapper) return;\n const w = wrapper.clientWidth;\n const half = el.offsetWidth / 2;\n const min = Math.min(half + 4, w / 2);\n const max = Math.max(w - half - 4, w / 2);\n const clamped = Math.min(Math.max(pos.x, min), max);\n if (clamped !== pos.x) setPos((p) => ({ ...p, x: clamped }));\n }, [visible, pos.x]);\n\n if (!visible || editor.isDestroyed || !editor.isEditable) return null;\n\n const btn = (onClick: () => void, title: string, isActive: boolean | undefined, children: React.ReactNode) => (\n <button\n type=\"button\"\n className={`rte-bubble__btn ${isActive ? 'rte-bubble__btn--active' : ''}`}\n onClick={() => { if (!editor.isDestroyed && editor.isEditable) onClick(); }}\n title={title}\n aria-label={title}\n aria-pressed={isActive}\n onMouseDown={(e) => e.preventDefault()}\n >\n {children}\n </button>\n );\n\n return (\n <div ref={ref} className=\"rte-bubble\" role=\"group\" aria-label=\"Selection formatting\"\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget) && !editor.isFocused) setVisible(false);\n }}\n onKeyDown={(event) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n editor.commands.focus();\n setVisible(false);\n }\n }}\n style={{ left: pos.x, top: pos.y }}>\n {btn(() => editor.chain().focus().toggleBold().run(), 'Bold', editor.isActive('bold'),\n <strong style={{ fontSize: 13 }}>B</strong>)}\n {btn(() => editor.chain().focus().toggleItalic().run(), 'Italic', editor.isActive('italic'),\n <em style={{ fontSize: 13 }}>I</em>)}\n {btn(() => editor.chain().focus().toggleUnderline().run(), 'Underline', editor.isActive('underline'),\n <span style={{ fontSize: 13, textDecoration: 'underline' }}>U</span>)}\n {btn(() => editor.chain().focus().toggleStrike().run(), 'Strike', editor.isActive('strike'),\n <span style={{ fontSize: 13, textDecoration: 'line-through' }}>S</span>)}\n {btn(() => editor.chain().focus().toggleCode().run(), 'Code', editor.isActive('code'),\n <span style={{ fontSize: 11, fontFamily: 'monospace' }}></></span>)}\n {btn(() => {\n const url = window.prompt('URL:', editor.getAttributes('link').href || '');\n if (url === null || editor.isDestroyed || !editor.isEditable) return;\n const chain = editor.chain().focus().extendMarkRange('link');\n if (url.trim() === '') chain.unsetLink().run();\n else chain.setLink({ href: url.trim() }).run();\n }, 'Link', editor.isActive('link'),\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\"><path d=\"M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71\" /><path d=\"M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71\" /></svg>)}\n <div className=\"rte-bubble__divider\" />\n <ColorPicker\n value={editor.getAttributes('textStyle').color || ''}\n onChange={(color) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (color) editor.chain().focus().setColor(color).run();\n else editor.chain().focus().unsetColor().run();\n }}\n title=\"Text color\"\n buttonClassName=\"rte-bubble__btn\"\n kind=\"text\"\n />\n <ColorPicker\n value={editor.getAttributes('highlight').color || ''}\n onChange={(color) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (color) editor.chain().focus().toggleHighlight({ color }).run();\n else editor.chain().focus().unsetHighlight().run();\n }}\n title=\"Highlight color\"\n buttonClassName=\"rte-bubble__btn\"\n kind=\"highlight\"\n />\n <div className=\"rte-bubble__divider\" />\n <select\n className=\"rte-bubble__select\"\n value={editor.getAttributes('textStyle').fontFamily || ''}\n onChange={(e) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (e.target.value) editor.chain().focus().setFontFamily(e.target.value).run();\n else editor.chain().focus().unsetFontFamily().run();\n }}\n title=\"Font family\"\n aria-label=\"Font family\"\n >\n {FONT_FAMILIES.map((opt) => (\n <option key={opt.value} value={opt.value}>{opt.label}</option>\n ))}\n </select>\n <select\n className=\"rte-bubble__select rte-bubble__select--size\"\n value={editor.getAttributes('textStyle').fontSize || ''}\n onChange={(e) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (e.target.value) (editor.chain().focus() as any).setFontSize(e.target.value).run();\n else (editor.chain().focus() as any).unsetFontSize().run();\n }}\n title=\"Font size\"\n aria-label=\"Font size\"\n >\n {FONT_SIZES.map((opt) => (\n <option key={opt.value} value={opt.value}>{opt.label}</option>\n ))}\n </select>\n {onAddComment && (\n <>\n <div className=\"rte-bubble__divider\" />\n {btn(onAddComment, 'Comment', undefined,\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\"><path d=\"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z\" /></svg>)}\n </>\n )}\n </div>\n );\n};\n\nexport default BubbleToolbar;\n"],"mappings":";;;;;;;AAWA,IAAM,KAA+C,EAAE,WAAQ,sBAAmB;CAChF,EAAe;EAAE;EAAQ,WAAW,EAAE,2BAAwB;CAAkB,CAAC;CACjF,IAAM,CAAC,GAAS,KAAc,EAAS,EAAK,GACtC,CAAC,GAAK,KAAU,EAAS;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC,GACvC,IAAM,EAAuB,IAAI;CA8EvC,IA5EA,QAAgB;EACd,IAAI,EAAO,aAAa;EACxB,IAAM,IAAM,EAAO,KAAK,IAAI,eACtB,IAAM,EAAI;EAChB,IAAI,CAAC,GAAK;EACV,IAAI,IAAuB,MACrB,UAAa;GAGjB,AAFI,MAAU,QAAM,EAAI,qBAAqB,CAAK,GAClD,IAAQ,MACR,EAAW,EAAK;EAClB,GACM,UAAe;GAEnB,IADA,IAAQ,MACJ,EAAO,aAAa;IAAE,EAAK;IAAG;GAAQ;GAC1C,IAAM,EAAE,SAAM,UAAO,EAAO,MAAM;GAClC,IAAI,CAAC,EAAO,cAAc,EAAE,EAAO,MAAM,qBAAqB,MAAkB,MAAS,KAAO,CAAC,EAAO,aAAa,CAAC,EAAI,SAAS,SAAS,EAAI,aAAa,GAAI;IAC/J,EAAW,EAAK;IAChB;GACF;GACA,IAAM,IAAS,EAAO,KAAK,YAAY,CAAI,GACrC,IAAY,EAAO,KAAK,YAAY,CAAE,GACtC,IAAY,EAAO,KAAK,IAAI,QAAqB,qBAAqB;GAC5E,IAAI,CAAC,GAAW;IAAE,EAAK;IAAG;GAAQ;GAClC,IAAM,IAAO,EAAU,sBAAsB,GAEvC,KAAW,EAAO,OAAO,EAAU,QAAQ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AU;IACV,OAAO,EAAO,cAAc,WAAW,CAAC,CAAC,YAAY;IACrD,WAAW,MAAM;KACX,GAAO,eAAgB,EAAO,eAC9B,EAAE,OAAO,QAAO,EAAQ,MAAM,CAAC,CAAC,MAAM,CAAC,CAAS,YAAY,EAAE,OAAO,KAAK,CAAC,CAAC,IAAI,IAC/E,EAAQ,MAAM,CAAC,CAAC,MAAM,CAAC,CAAS,cAAc,CAAC,CAAC,IAAI;IAC3D;IACA,OAAM;IACN,cAAW;IAEV,UAAA,EAAW,KAAK,MACf,kBAAC,UAAD;KAAwB,OAAO,EAAI;KAAQ,UAAA,EAAI;IAAc,GAAhD,EAAI,KAA4C,CAC9D;GACK,CAAA;GACP,KACC,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,OAAD,EAAK,WAAU,sBAAuB,CAAA,GACrC,EAAI,GAAc,WAAW,KAAA,GAC5B,kBAAC,OAAD;IAAK,OAAM;IAAK,QAAO;IAAK,SAAQ;IAAY,MAAK;IAAO,QAAO;IAAe,aAAY;IAAI,UAAA,kBAAC,QAAD,EAAM,GAAE,2DAA4D,CAAA;GAAM,CAAA,CAAC,CAC/K,EAAA,CAAA;EAED;;AAET"}
|
|
1
|
+
{"version":3,"file":"BubbleToolbar.js","names":[],"sources":["../../../../src/components/pro/RichTextEditor/BubbleToolbar.tsx"],"sourcesContent":["import React, { useState, useEffect, useLayoutEffect, useRef, useId, useCallback } from 'react';\nimport { useEditorState, type Editor } from '@tiptap/react';\nimport { TextSelection } from '@tiptap/pm/state';\nimport { ColorPicker } from './Toolbar/ColorPicker';\nimport { SelectDropdown, FONT_FAMILIES, FONT_SIZES } from './Toolbar/SelectDropdown';\n\ninterface BubbleToolbarProps {\n editor: Editor;\n onAddComment?: () => void;\n}\n\nconst BubbleToolbar: React.FC<BubbleToolbarProps> = ({ editor, onAddComment }) => {\n useEditorState({ editor, selector: ({ transactionNumber }) => transactionNumber });\n const [visible, setVisible] = useState(false);\n const [pos, setPos] = useState({ x: 0, y: 0 });\n const ref = useRef<HTMLDivElement>(null);\n const bubbleId = useId();\n const ownsPalette = useCallback((target: EventTarget | null) =>\n target instanceof Element && target.closest(`[data-rte-palette-owner=\"${bubbleId}\"]`) !== null, [bubbleId]);\n\n useEffect(() => {\n if (editor.isDestroyed) return;\n const doc = editor.view.dom.ownerDocument;\n const win = doc.defaultView;\n if (!win) return;\n let frame: number | null = null;\n const hide = () => {\n if (frame !== null) win.cancelAnimationFrame(frame);\n frame = null;\n setVisible(false);\n };\n const update = () => {\n frame = null;\n if (editor.isDestroyed) { hide(); return; }\n const { from, to } = editor.state.selection;\n if (!editor.isEditable || !(editor.state.selection instanceof TextSelection) || from === to || (!editor.isFocused && !ref.current?.contains(doc.activeElement) && !ownsPalette(doc.activeElement))) {\n setVisible(false);\n return;\n }\n const coords = editor.view.coordsAtPos(from);\n const endCoords = editor.view.coordsAtPos(to);\n const wrapperEl = editor.view.dom.closest<HTMLElement>('.rte-editor-wrapper');\n if (!wrapperEl) { hide(); return; }\n const rect = wrapperEl.getBoundingClientRect();\n\n const centerX = (coords.left + endCoords.left) / 2 - rect.left - wrapperEl.clientLeft + wrapperEl.scrollLeft;\n const topY = Math.min(coords.top, endCoords.top) - rect.top - wrapperEl.clientTop + wrapperEl.scrollTop - 44;\n\n setPos({ x: centerX, y: topY });\n setVisible(true);\n };\n\n const scheduleUpdate = () => {\n if (frame !== null) win.cancelAnimationFrame(frame);\n frame = win.requestAnimationFrame(update);\n };\n const onBlur = ({ event }: { event: FocusEvent }) => {\n if (event.relatedTarget instanceof Node && (ref.current?.contains(event.relatedTarget) || ownsPalette(event.relatedTarget))) return;\n hide();\n };\n editor.on('transaction', scheduleUpdate);\n editor.on('selectionUpdate', scheduleUpdate);\n editor.on('focus', scheduleUpdate);\n editor.on('blur', onBlur);\n editor.on('destroy', hide);\n doc.addEventListener('scroll', scheduleUpdate, true);\n win.addEventListener('resize', scheduleUpdate);\n update();\n return () => {\n if (frame !== null) win.cancelAnimationFrame(frame);\n editor.off('transaction', scheduleUpdate);\n editor.off('selectionUpdate', scheduleUpdate);\n editor.off('focus', scheduleUpdate);\n editor.off('blur', onBlur);\n editor.off('destroy', hide);\n doc.removeEventListener('scroll', scheduleUpdate, true);\n win.removeEventListener('resize', scheduleUpdate);\n };\n }, [editor, ownsPalette]);\n\n // A transform here turns fixed-position color palettes into descendants of\n // the scrolling editor, where overflow clips them. Position the bubble's\n // left edge directly instead of centering it with translateX(-50%).\n useLayoutEffect(() => {\n if (!visible || !ref.current) return;\n const el = ref.current;\n const wrapper = el.parentElement;\n if (!wrapper) return;\n const width = el.offsetWidth;\n el.style.left = `${Math.max(0, Math.min(pos.x - width / 2, wrapper.clientWidth - width))}px`;\n }, [visible, pos.x]);\n\n if (!visible || editor.isDestroyed || !editor.isEditable) return null;\n\n const btn = (onClick: () => void, title: string, isActive: boolean | undefined, children: React.ReactNode) => (\n <button\n type=\"button\"\n className={`rte-bubble__btn ${isActive ? 'rte-bubble__btn--active' : ''}`}\n onClick={() => { if (!editor.isDestroyed && editor.isEditable) onClick(); }}\n title={title}\n aria-label={title}\n aria-pressed={isActive}\n onMouseDown={(e) => e.preventDefault()}\n >\n {children}\n </button>\n );\n\n return (\n <div ref={ref} className=\"rte-bubble\" role=\"group\" aria-label=\"Selection formatting\"\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget) && !ownsPalette(event.relatedTarget) && !editor.isFocused) setVisible(false);\n }}\n onKeyDown={(event) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n editor.commands.focus();\n setVisible(false);\n }\n }}\n style={{ top: pos.y }}>\n {btn(() => editor.chain().focus().toggleBold().run(), 'Bold', editor.isActive('bold'),\n <strong style={{ fontSize: 13 }}>B</strong>)}\n {btn(() => editor.chain().focus().toggleItalic().run(), 'Italic', editor.isActive('italic'),\n <em style={{ fontSize: 13 }}>I</em>)}\n {btn(() => editor.chain().focus().toggleUnderline().run(), 'Underline', editor.isActive('underline'),\n <span style={{ fontSize: 13, textDecoration: 'underline' }}>U</span>)}\n {btn(() => editor.chain().focus().toggleStrike().run(), 'Strike', editor.isActive('strike'),\n <span style={{ fontSize: 13, textDecoration: 'line-through' }}>S</span>)}\n {btn(() => editor.chain().focus().toggleCode().run(), 'Code', editor.isActive('code'),\n <span style={{ fontSize: 11, fontFamily: 'monospace' }}></></span>)}\n {btn(() => {\n const url = window.prompt('URL:', editor.getAttributes('link').href || '');\n if (url === null || editor.isDestroyed || !editor.isEditable) return;\n const chain = editor.chain().focus().extendMarkRange('link');\n if (url.trim() === '') chain.unsetLink().run();\n else chain.setLink({ href: url.trim() }).run();\n }, 'Link', editor.isActive('link'),\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\"><path d=\"M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71\" /><path d=\"M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71\" /></svg>)}\n <div className=\"rte-bubble__divider\" />\n <ColorPicker\n value={editor.getAttributes('textStyle').color || ''}\n onChange={(color) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (color) editor.chain().focus().setColor(color).run();\n else editor.chain().focus().unsetColor().run();\n }}\n title=\"Text color\"\n buttonClassName=\"rte-bubble__btn\"\n portalOwner={bubbleId}\n kind=\"text\"\n />\n <ColorPicker\n value={editor.getAttributes('highlight').color || ''}\n onChange={(color) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (color) editor.chain().focus().toggleHighlight({ color }).run();\n else editor.chain().focus().unsetHighlight().run();\n }}\n title=\"Highlight color\"\n buttonClassName=\"rte-bubble__btn\"\n portalOwner={bubbleId}\n kind=\"highlight\"\n />\n <div className=\"rte-bubble__divider\" />\n <SelectDropdown\n className=\"rte-bubble__select\"\n width={96}\n value={editor.getAttributes('textStyle').fontFamily || ''}\n options={FONT_FAMILIES}\n onChange={(value) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (value) editor.chain().focus().setFontFamily(value).run();\n else editor.chain().focus().unsetFontFamily().run();\n }}\n title=\"Font family\"\n />\n <SelectDropdown\n className=\"rte-bubble__select rte-bubble__select--size\"\n width={72}\n value={editor.getAttributes('textStyle').fontSize || ''}\n options={FONT_SIZES}\n onChange={(value) => {\n if (editor.isDestroyed || !editor.isEditable) return;\n if (value) (editor.chain().focus() as any).setFontSize(value).run();\n else (editor.chain().focus() as any).unsetFontSize().run();\n }}\n title=\"Font size\"\n />\n {onAddComment && (\n <>\n <div className=\"rte-bubble__divider\" />\n {btn(onAddComment, 'Comment', undefined,\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\"><path d=\"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z\" /></svg>)}\n </>\n )}\n </div>\n );\n};\n\nexport default BubbleToolbar;\n"],"mappings":";;;;;;;AAWA,IAAM,KAA+C,EAAE,WAAQ,sBAAmB;CAChF,EAAe;EAAE;EAAQ,WAAW,EAAE,2BAAwB;CAAkB,CAAC;CACjF,IAAM,CAAC,GAAS,KAAc,EAAS,EAAK,GACtC,CAAC,GAAK,KAAU,EAAS;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC,GACvC,IAAM,EAAuB,IAAI,GACjC,IAAW,EAAM,GACjB,IAAc,GAAa,MAC/B,aAAkB,WAAW,EAAO,QAAQ,4BAA4B,EAAS,GAAG,MAAM,MAAM,CAAC,CAAQ,CAAC;CA0E5G,IAxEA,QAAgB;EACd,IAAI,EAAO,aAAa;EACxB,IAAM,IAAM,EAAO,KAAK,IAAI,eACtB,IAAM,EAAI;EAChB,IAAI,CAAC,GAAK;EACV,IAAI,IAAuB,MACrB,UAAa;GAGjB,AAFI,MAAU,QAAM,EAAI,qBAAqB,CAAK,GAClD,IAAQ,MACR,EAAW,EAAK;EAClB,GACM,UAAe;GAEnB,IADA,IAAQ,MACJ,EAAO,aAAa;IAA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,CAAC,cAAc;IACvD,SAAS;IACT,WAAW,MAAU;KACf,GAAO,eAAgB,EAAO,eAC9B,IAAO,EAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,cAAc,CAAK,CAAC,CAAC,IAAI,IACtD,EAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CAAC,IAAI;IACpD;IACA,OAAM;GACP,CAAA;GACD,kBAAC,GAAD;IACE,WAAU;IACV,OAAO;IACP,OAAO,EAAO,cAAc,WAAW,CAAC,CAAC,YAAY;IACrD,SAAS;IACT,WAAW,MAAU;KACf,GAAO,eAAgB,EAAO,eAC9B,IAAO,EAAQ,MAAM,CAAC,CAAC,MAAM,CAAC,CAAS,YAAY,CAAK,CAAC,CAAC,IAAI,IAC7D,EAAQ,MAAM,CAAC,CAAC,MAAM,CAAC,CAAS,cAAc,CAAC,CAAC,IAAI;IAC3D;IACA,OAAM;GACP,CAAA;GACA,KACC,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,OAAD,EAAK,WAAU,sBAAuB,CAAA,GACrC,EAAI,GAAc,WAAW,KAAA,GAC5B,kBAAC,OAAD;IAAK,OAAM;IAAK,QAAO;IAAK,SAAQ;IAAY,MAAK;IAAO,QAAO;IAAe,aAAY;IAAI,UAAA,kBAAC,QAAD,EAAM,GAAE,2DAA4D,CAAA;GAAM,CAAA,CAAC,CAC/K,EAAA,CAAA;EAED;;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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorPicker.js","names":[],"sources":["../../../../../src/components/pro/RichTextEditor/Toolbar/ColorPicker.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useId } from 'react';\nimport { useAnchoredDropdown } from './useAnchoredDropdown';\n\ninterface ColorPickerProps {\n value: string;\n onChange: (color: string) => void;\n title?: string;\n icon?: React.ReactNode;\n kind?: 'text' | 'highlight';\n /** Button class; defaults to the classic toolbar button. Bubble toolbar passes its own. */\n buttonClassName?: string;\n}\n\nconst COLORS = [\n '#000000', '#434343', '#666666', '#999999', '#cccccc', '#eeeeee', '#ffffff',\n '#ff0000', '#ff4500', '#ff8c00', '#ffd700', '#32cd32', '#00bfff', '#8a2be2',\n '#ff69b4', '#dc143c', '#ff6347', '#ffa500', '#9acd32', '#20b2aa', '#4169e1',\n '#9370db', '#db7093', '#b22222', '#d2691e', '#daa520', '#228b22', '#008b8b',\n '#191970', '#4b0082',\n];\n\nexport const ColorPicker: React.FC<ColorPickerProps> = ({ value, onChange, title, icon, kind = 'text', buttonClassName = 'rte-toolbar__btn' }) => {\n const [isOpen, setIsOpen] = useState(false);\n const ref = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const paletteRef = useRef<HTMLDivElement>(null);\n const paletteId = useId();\n const dropdownStyle = useAnchoredDropdown(isOpen, triggerRef, paletteRef);\n const label = title || (kind === 'text' ? 'Text color' : 'Highlight color');\n const description = `${label}: ${value || (kind === 'text' ? 'Default' : 'None')}`;\n\n useEffect(() => {\n const handler = (e: MouseEvent) => {\n if (ref.current && !ref.current.contains(e.target as Node)) {\n setIsOpen(false);\n }\n };\n document.addEventListener('mousedown', handler);\n return () => document.removeEventListener('mousedown', handler);\n }, []);\n\n return (\n <div ref={ref} className=\"rte-toolbar__color-picker\"\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget)) setIsOpen(false);\n }}\n onKeyDown={(event) => {\n if (event.key === 'Escape' && isOpen) {\n event.preventDefault();\n event.stopPropagation();\n setIsOpen(false);\n triggerRef.current?.focus();\n }\n }}>\n <button\n type=\"button\"\n ref={triggerRef}\n className={`${buttonClassName} rte-toolbar__color-trigger`}\n
|
|
1
|
+
{"version":3,"file":"ColorPicker.js","names":[],"sources":["../../../../../src/components/pro/RichTextEditor/Toolbar/ColorPicker.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useId } from 'react';\nimport { createPortal } from 'react-dom';\nimport { useAnchoredDropdown } from './useAnchoredDropdown';\n\ninterface ColorPickerProps {\n value: string;\n onChange: (color: string) => void;\n title?: string;\n icon?: React.ReactNode;\n kind?: 'text' | 'highlight';\n /** Button class; defaults to the classic toolbar button. Bubble toolbar passes its own. */\n buttonClassName?: string;\n /** Portals the palette outside scroll-clipped bubble toolbars. */\n portalOwner?: string;\n}\n\nconst COLORS = [\n '#000000', '#434343', '#666666', '#999999', '#cccccc', '#eeeeee', '#ffffff',\n '#ff0000', '#ff4500', '#ff8c00', '#ffd700', '#32cd32', '#00bfff', '#8a2be2',\n '#ff69b4', '#dc143c', '#ff6347', '#ffa500', '#9acd32', '#20b2aa', '#4169e1',\n '#9370db', '#db7093', '#b22222', '#d2691e', '#daa520', '#228b22', '#008b8b',\n '#191970', '#4b0082',\n];\n\nexport const ColorPicker: React.FC<ColorPickerProps> = ({ value, onChange, title, icon, kind = 'text', buttonClassName = 'rte-toolbar__btn', portalOwner }) => {\n const [isOpen, setIsOpen] = useState(false);\n const [paletteTheme, setPaletteTheme] = useState<React.CSSProperties>({});\n const ref = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const paletteRef = useRef<HTMLDivElement>(null);\n const paletteId = useId();\n const dropdownStyle = useAnchoredDropdown(isOpen, triggerRef, paletteRef);\n const label = title || (kind === 'text' ? 'Text color' : 'Highlight color');\n const description = `${label}: ${value || (kind === 'text' ? 'Default' : 'None')}`;\n\n useEffect(() => {\n const handler = (e: MouseEvent) => {\n if (ref.current && !ref.current.contains(e.target as Node) && !paletteRef.current?.contains(e.target as Node)) {\n setIsOpen(false);\n }\n };\n document.addEventListener('mousedown', handler);\n return () => document.removeEventListener('mousedown', handler);\n }, [ref, paletteRef]);\n\n const palette = isOpen && (\n <div ref={paletteRef} id={paletteId} data-rte-palette-owner={portalOwner}\n className=\"rte-toolbar__color-dropdown\" role=\"group\" aria-label={label}\n style={{ ...dropdownStyle, ...paletteTheme }}>\n {COLORS.map((color) => (\n <button key={color} type=\"button\"\n className={`rte-toolbar__color-swatch ${color === value ? 'rte-toolbar__color-swatch--active' : ''}`}\n style={{ backgroundColor: color }}\n onMouseDown={portalOwner ? event => event.preventDefault() : undefined}\n onClick={() => { onChange(color); setIsOpen(false); }}\n title={`${label}: ${color}`} aria-label={`${label}: ${color}`}\n aria-pressed={color.toLowerCase() === value.toLowerCase()} />\n ))}\n <button type=\"button\" className=\"rte-toolbar__color-clear\"\n onMouseDown={portalOwner ? event => event.preventDefault() : undefined}\n onClick={() => { onChange(''); setIsOpen(false); }}\n title={`Clear ${label}`} aria-label={`Clear ${label}`} aria-pressed={!value}>Clear</button>\n </div>\n );\n\n return (\n <div ref={ref} className=\"rte-toolbar__color-picker\"\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget) && !paletteRef.current?.contains(event.relatedTarget)) setIsOpen(false);\n }}\n onKeyDown={(event) => {\n if (event.key === 'Escape' && isOpen) {\n event.preventDefault();\n event.stopPropagation();\n setIsOpen(false);\n triggerRef.current?.focus();\n }\n }}>\n <button\n type=\"button\"\n ref={triggerRef}\n className={`${buttonClassName} rte-toolbar__color-trigger`}\n onMouseDown={portalOwner ? event => event.preventDefault() : undefined}\n onClick={event => {\n if (portalOwner && !isOpen) {\n const computed = getComputedStyle(event.currentTarget);\n const variables: Record<string, string> = {};\n for (const name of ['--rte-bg', '--rte-text', '--rte-border', '--rte-placeholder', '--rte-active-color', '--rte-toolbar-btn-hover']) {\n variables[name] = computed.getPropertyValue(name);\n }\n setPaletteTheme(variables);\n }\n setIsOpen(!isOpen);\n }}\n title={description}\n aria-label={description}\n aria-expanded={isOpen}\n aria-controls={isOpen ? paletteId : undefined}\n >\n <span className={`rte-toolbar__color-icon rte-toolbar__color-icon--${kind}`} aria-hidden=\"true\">\n {icon || (kind === 'text' ? <span className=\"rte-toolbar__color-letter\">A</span> : (\n <svg width=\"18\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <path d=\"m14 3 7 7-9 9-7-7zM5 12l-2 7 2 2 7-2M14 7l3 3M3 21h6\" />\n </svg>\n ))}\n <span\n className={`rte-toolbar__color-indicator${value ? '' : ' rte-toolbar__color-indicator--empty'}`}\n style={{ backgroundColor: value || undefined }}\n />\n </span>\n </button>\n {portalOwner && typeof document !== 'undefined' ? createPortal(palette, document.body) : palette}\n </div>\n );\n};\n"],"mappings":";;;;;AAgBA,IAAM,IAAS,2QAMf,GAEa,KAA2C,EAAE,UAAO,aAAU,UAAO,SAAM,UAAO,QAAQ,qBAAkB,oBAAoB,qBAAkB;CAC7J,IAAM,CAAC,GAAQ,KAAa,EAAS,EAAK,GACpC,CAAC,GAAc,KAAmB,EAA8B,CAAC,CAAC,GAClE,IAAM,EAAuB,IAAI,GACjC,IAAa,EAA0B,IAAI,GAC3C,IAAa,EAAuB,IAAI,GACxC,IAAY,EAAM,GAClB,IAAgB,EAAoB,GAAQ,GAAY,CAAU,GAClE,IAAQ,MAAU,MAAS,SAAS,eAAe,oBACnD,IAAc,GAAG,EAAM,IAAI,MAAU,MAAS,SAAS,YAAY;CAEzE,QAAgB;EACd,IAAM,KAAW,MAAkB;GACjC,AAAI,EAAI,WAAW,CAAC,EAAI,QAAQ,SAAS,EAAE,MAAc,KAAK,CAAC,EAAW,SAAS,SAAS,EAAE,MAAc,KAC1G,EAAU,EAAK;EAEnB;EAEA,OADA,SAAS,iBAAiB,aAAa,CAAO,SACjC,SAAS,oBAAoB,aAAa,CAAO;CAChE,GAAG,CAAC,GAAK,CAAU,CAAC;CAEpB,IAAM,IAAU,KACd,kBAAC,OAAD;EAAK,KAAK;EAAY,IAAI;EAAW,0BAAwB;EAC3D,WAAU;EAA8B,MAAK;EAAQ,cAAY;EACjE,OAAO;GAAE,GAAG;GAAe,GAAG;EAAa;EAF7C,UAAA,CAGG,EAAO,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AQ,EAAS,iBAAiB,CAAI;KAElD,EAAgB,CAAS;IAC3B;IACA,EAAU,CAAC,CAAM;GACnB;GACA,OAAO;GACP,cAAY;GACZ,iBAAe;GACf,iBAAe,IAAS,IAAY,KAAA;GAEpC,UAAA,kBAAC,QAAD;IAAM,WAAW,oDAAoD;IAAQ,eAAY;IAAzF,UAAA,CACG,MAAS,MAAS,SAAS,kBAAC,QAAD;KAAM,WAAU;KAA4B,UAAA;IAAO,CAAA,IAC7E,kBAAC,OAAD;KAAK,OAAM;KAAK,QAAO;KAAK,SAAQ;KAAY,MAAK;KAAO,QAAO;KAAe,aAAY;KAAI,eAAc;KAAQ,gBAAe;KACrI,UAAA,kBAAC,QAAD,EAAM,GAAE,uDAAwD,CAAA;IAC7D,CAAA,IAEP,kBAAC,QAAD;KACE,WAAW,+BAA+B,IAAQ,KAAK;KACvD,OAAO,EAAE,iBAAiB,KAAS,KAAA,EAAU;IAC9C,CAAA,CACG;;EACA,CAAA,GACP,KAAe,OAAO,WAAa,MAAc,EAAa,GAAS,SAAS,IAAI,IAAI,CACtF;;AAET"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import e from "../../../Select/index.js";
|
|
1
2
|
import "react";
|
|
2
|
-
import { jsx as
|
|
3
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
3
4
|
//#region src/components/pro/RichTextEditor/Toolbar/SelectDropdown.tsx
|
|
4
|
-
var
|
|
5
|
+
var n = [
|
|
5
6
|
{
|
|
6
7
|
label: "Default",
|
|
7
8
|
value: ""
|
|
@@ -42,7 +43,7 @@ var t = [
|
|
|
42
43
|
label: "Comic Sans MS",
|
|
43
44
|
value: "Comic Sans MS, cursive"
|
|
44
45
|
}
|
|
45
|
-
],
|
|
46
|
+
], r = [
|
|
46
47
|
{
|
|
47
48
|
label: "Default",
|
|
48
49
|
value: ""
|
|
@@ -99,18 +100,15 @@ var t = [
|
|
|
99
100
|
label: "72px",
|
|
100
101
|
value: "72px"
|
|
101
102
|
}
|
|
102
|
-
],
|
|
103
|
-
className:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
value: t.value,
|
|
110
|
-
children: t.label
|
|
111
|
-
}, t.value))
|
|
103
|
+
], i = ({ value: n, options: r, onChange: i, title: a, width: o = 110, className: s = "rte-toolbar__select" }) => /* @__PURE__ */ t(e, {
|
|
104
|
+
className: s,
|
|
105
|
+
style: { width: o },
|
|
106
|
+
options: r,
|
|
107
|
+
value: n,
|
|
108
|
+
onChange: (e) => i(String(e)),
|
|
109
|
+
"aria-label": a ?? "Formatting option"
|
|
112
110
|
});
|
|
113
111
|
//#endregion
|
|
114
|
-
export {
|
|
112
|
+
export { n as FONT_FAMILIES, r as FONT_SIZES, i as SelectDropdown };
|
|
115
113
|
|
|
116
114
|
//# sourceMappingURL=SelectDropdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectDropdown.js","names":[],"sources":["../../../../../src/components/pro/RichTextEditor/Toolbar/SelectDropdown.tsx"],"sourcesContent":["import React from 'react';\n\nexport const FONT_FAMILIES = [\n { label: 'Default', value: '' },\n { label: 'Arial', value: 'Arial, sans-serif' },\n { label: 'Helvetica', value: 'Helvetica, sans-serif' },\n { label: 'Georgia', value: 'Georgia, serif' },\n { label: 'Times New Roman', value: 'Times New Roman, serif' },\n { label: 'Courier New', value: 'Courier New, monospace' },\n { label: 'Verdana', value: 'Verdana, sans-serif' },\n { label: 'Trebuchet MS', value: 'Trebuchet MS, sans-serif' },\n { label: 'Impact', value: 'Impact, sans-serif' },\n { label: 'Comic Sans MS', value: 'Comic Sans MS, cursive' },\n];\n\nexport const FONT_SIZES = [\n { label: 'Default', value: '' },\n { label: '10px', value: '10px' },\n { label: '12px', value: '12px' },\n { label: '14px', value: '14px' },\n { label: '16px', value: '16px' },\n { label: '18px', value: '18px' },\n { label: '20px', value: '20px' },\n { label: '24px', value: '24px' },\n { label: '28px', value: '28px' },\n { label: '32px', value: '32px' },\n { label: '36px', value: '36px' },\n { label: '48px', value: '48px' },\n { label: '64px', value: '64px' },\n { label: '72px', value: '72px' },\n];\n\ninterface SelectDropdownProps {\n value: string;\n options: { label: string; value: string }[];\n onChange: (value: string) => void;\n title?: string;\n width?: number;\n}\n\nexport const SelectDropdown: React.FC<SelectDropdownProps> = ({ value, options, onChange, title, width = 110 }) => (\n <
|
|
1
|
+
{"version":3,"file":"SelectDropdown.js","names":[],"sources":["../../../../../src/components/pro/RichTextEditor/Toolbar/SelectDropdown.tsx"],"sourcesContent":["import React from 'react';\nimport Select from '../../../Select';\n\nexport const FONT_FAMILIES = [\n { label: 'Default', value: '' },\n { label: 'Arial', value: 'Arial, sans-serif' },\n { label: 'Helvetica', value: 'Helvetica, sans-serif' },\n { label: 'Georgia', value: 'Georgia, serif' },\n { label: 'Times New Roman', value: 'Times New Roman, serif' },\n { label: 'Courier New', value: 'Courier New, monospace' },\n { label: 'Verdana', value: 'Verdana, sans-serif' },\n { label: 'Trebuchet MS', value: 'Trebuchet MS, sans-serif' },\n { label: 'Impact', value: 'Impact, sans-serif' },\n { label: 'Comic Sans MS', value: 'Comic Sans MS, cursive' },\n];\n\nexport const FONT_SIZES = [\n { label: 'Default', value: '' },\n { label: '10px', value: '10px' },\n { label: '12px', value: '12px' },\n { label: '14px', value: '14px' },\n { label: '16px', value: '16px' },\n { label: '18px', value: '18px' },\n { label: '20px', value: '20px' },\n { label: '24px', value: '24px' },\n { label: '28px', value: '28px' },\n { label: '32px', value: '32px' },\n { label: '36px', value: '36px' },\n { label: '48px', value: '48px' },\n { label: '64px', value: '64px' },\n { label: '72px', value: '72px' },\n];\n\ninterface SelectDropdownProps {\n value: string;\n options: { label: string; value: string }[];\n onChange: (value: string) => void;\n title?: string;\n width?: number;\n className?: string;\n}\n\nexport const SelectDropdown: React.FC<SelectDropdownProps> = ({ value, options, onChange, title, width = 110, className = 'rte-toolbar__select' }) => (\n <Select\n className={className}\n style={{ width }}\n options={options}\n value={value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