@logora/debate 0.4.19 → 0.4.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,100 +1,99 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as x, jsx as o } from "react/jsx-runtime";
|
|
2
2
|
import { $isListNode as $, ListNode as q, INSERT_ORDERED_LIST_COMMAND as K, REMOVE_LIST_COMMAND as F } from "@lexical/list";
|
|
3
3
|
import { useLexicalComposerContext as U } from "@lexical/react/LexicalComposerContext";
|
|
4
|
-
import { $isHeadingNode as P, $createQuoteNode as
|
|
5
|
-
import { $setBlocksType as
|
|
4
|
+
import { $isHeadingNode as P, $createQuoteNode as I } from "@lexical/rich-text";
|
|
5
|
+
import { $setBlocksType as E } from "@lexical/selection";
|
|
6
6
|
import { $getNearestNodeOfType as j, mergeRegister as H } from "@lexical/utils";
|
|
7
7
|
import a from "classnames";
|
|
8
8
|
import { $getSelection as p, $isRangeSelection as N, SELECTION_CHANGE_COMMAND as Q, FORMAT_TEXT_COMMAND as G, $createParagraphNode as V } from "lexical";
|
|
9
|
-
import { useRef as X, useState as
|
|
9
|
+
import { useRef as X, useState as u, useCallback as z, useEffect as J } from "react";
|
|
10
10
|
import { useIntl as W } from "react-intl";
|
|
11
11
|
import e from "./ToolbarPlugin.module.scss.js";
|
|
12
|
-
import { Icon as
|
|
12
|
+
import { Icon as c } from "../../../icons/icon/Icon.js";
|
|
13
13
|
import { Button as Y } from "../../../action/button/Button.js";
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const ge = (i) => {
|
|
15
|
+
const r = W(), S = 1, [l] = U(), A = X(null), [b, M] = u("paragraph"), [Z, v] = u(null), [w, _] = u(!1), [D, T] = u(!1), [L, y] = u(!1), C = i.hideSubmit && i.hideSourceAction && i.disableRichText, g = z(() => {
|
|
16
16
|
const t = p();
|
|
17
17
|
if (N(t)) {
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
if (v(
|
|
21
|
-
const
|
|
18
|
+
const n = t.anchor.getNode(), s = n.getKey() === "root" ? n : n.getTopLevelElementOrThrow(), m = s.getKey();
|
|
19
|
+
if (l.getElementByKey(m) !== null)
|
|
20
|
+
if (v(m), $(s)) {
|
|
21
|
+
const f = j(n, q), B = f ? f.getTag() : s.getTag();
|
|
22
22
|
M(B);
|
|
23
23
|
} else {
|
|
24
|
-
const
|
|
25
|
-
M(
|
|
24
|
+
const f = P(s) ? s.getTag() : s.getType();
|
|
25
|
+
M(f);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
_(t.hasFormat("bold")), T(t.hasFormat("italic")), y(t.hasFormat("underline"));
|
|
28
28
|
}
|
|
29
|
-
}, [
|
|
29
|
+
}, [l]);
|
|
30
30
|
J(() => H(
|
|
31
|
-
|
|
31
|
+
l.registerUpdateListener(({ editorState: t }) => {
|
|
32
32
|
t.read(() => {
|
|
33
|
-
|
|
33
|
+
g();
|
|
34
34
|
});
|
|
35
35
|
}),
|
|
36
|
-
|
|
36
|
+
l.registerCommand(
|
|
37
37
|
Q,
|
|
38
|
-
() => (
|
|
39
|
-
|
|
38
|
+
() => (g(), !1),
|
|
39
|
+
S
|
|
40
40
|
)
|
|
41
|
-
), [
|
|
42
|
-
const
|
|
41
|
+
), [l, g]);
|
|
42
|
+
const d = (t) => {
|
|
43
43
|
t.preventDefault();
|
|
44
|
-
},
|
|
44
|
+
}, k = () => {
|
|
45
45
|
setTimeout(() => {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
l.getEditorState().read(() => {
|
|
47
|
+
g();
|
|
48
48
|
});
|
|
49
49
|
}, 0);
|
|
50
|
-
},
|
|
51
|
-
|
|
50
|
+
}, h = (t) => {
|
|
51
|
+
l.dispatchCommand(G, t), t === "bold" && _((n) => !n), t === "italic" && T((n) => !n), t === "underline" && y((n) => !n);
|
|
52
52
|
}, O = () => {
|
|
53
|
-
b !== "ol" ?
|
|
53
|
+
b !== "ol" ? l.dispatchCommand(K) : l.dispatchCommand(F), k();
|
|
54
54
|
}, R = () => {
|
|
55
|
-
b !== "quote" ?
|
|
55
|
+
b !== "quote" ? l.update(() => {
|
|
56
56
|
const t = p();
|
|
57
57
|
if (N(t))
|
|
58
58
|
if (t.isCollapsed()) {
|
|
59
|
-
const
|
|
60
|
-
|
|
59
|
+
const s = t.anchor.getNode().getTopLevelElementOrThrow(), m = I();
|
|
60
|
+
s.insertAfter(m), m.selectEnd();
|
|
61
61
|
} else
|
|
62
|
-
|
|
63
|
-
}) :
|
|
62
|
+
E(t, () => I());
|
|
63
|
+
}) : l.update(() => {
|
|
64
64
|
const t = p();
|
|
65
|
-
N(t) &&
|
|
66
|
-
}),
|
|
65
|
+
N(t) && E(t, () => V());
|
|
66
|
+
}), k();
|
|
67
67
|
};
|
|
68
|
-
return
|
|
68
|
+
return C ? null : /* @__PURE__ */ x(
|
|
69
69
|
"div",
|
|
70
70
|
{
|
|
71
71
|
className: a(e.toolbar, {
|
|
72
|
-
[e.toolbarIsActive]:
|
|
72
|
+
[e.toolbarIsActive]: C ? !1 : i.isActive
|
|
73
73
|
}),
|
|
74
74
|
ref: A,
|
|
75
75
|
children: [
|
|
76
|
-
|
|
76
|
+
i.isActive ? !i.disableRichText && /* @__PURE__ */ x(
|
|
77
77
|
"div",
|
|
78
78
|
{
|
|
79
79
|
className: a(e.iconToolbar, {
|
|
80
|
-
[e.shortBar]:
|
|
80
|
+
[e.shortBar]: i.shortBar
|
|
81
81
|
}),
|
|
82
82
|
children: [
|
|
83
83
|
/* @__PURE__ */ o(
|
|
84
84
|
"button",
|
|
85
85
|
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
onClick: () => f("bold"),
|
|
86
|
+
onMouseDown: d,
|
|
87
|
+
onClick: () => h("bold"),
|
|
89
88
|
type: "button",
|
|
90
89
|
className: a(e.toolbarItem, { [e.active]: w }),
|
|
91
90
|
"data-testid": "format-bold",
|
|
92
|
-
"aria-label":
|
|
91
|
+
"aria-label": r.formatMessage({
|
|
93
92
|
id: "input.text_editor.plugins.toolbar_plugin.bold.aria_label",
|
|
94
93
|
defaultMessage: "Make text bold"
|
|
95
94
|
}),
|
|
96
95
|
children: /* @__PURE__ */ o(
|
|
97
|
-
|
|
96
|
+
c,
|
|
98
97
|
{
|
|
99
98
|
name: "bold",
|
|
100
99
|
width: 24,
|
|
@@ -107,19 +106,18 @@ const he = (l) => {
|
|
|
107
106
|
/* @__PURE__ */ o(
|
|
108
107
|
"button",
|
|
109
108
|
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
onClick: () => f("italic"),
|
|
109
|
+
onMouseDown: d,
|
|
110
|
+
onClick: () => h("italic"),
|
|
113
111
|
type: "button",
|
|
114
112
|
className: a(e.toolbarItem, {
|
|
115
113
|
[e.active]: D
|
|
116
114
|
}),
|
|
117
|
-
"aria-label":
|
|
115
|
+
"aria-label": r.formatMessage({
|
|
118
116
|
id: "input.text_editor.plugins.toolbar_plugin.italic.aria_label",
|
|
119
117
|
defaultMessage: "Make text italic"
|
|
120
118
|
}),
|
|
121
119
|
children: /* @__PURE__ */ o(
|
|
122
|
-
|
|
120
|
+
c,
|
|
123
121
|
{
|
|
124
122
|
name: "italic",
|
|
125
123
|
width: 24,
|
|
@@ -132,19 +130,18 @@ const he = (l) => {
|
|
|
132
130
|
/* @__PURE__ */ o(
|
|
133
131
|
"button",
|
|
134
132
|
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
onClick: () => f("underline"),
|
|
133
|
+
onMouseDown: d,
|
|
134
|
+
onClick: () => h("underline"),
|
|
138
135
|
type: "button",
|
|
139
136
|
className: a(e.toolbarItem, {
|
|
140
137
|
[e.active]: L
|
|
141
138
|
}),
|
|
142
|
-
"aria-label":
|
|
139
|
+
"aria-label": r.formatMessage({
|
|
143
140
|
id: "input.text_editor.plugins.toolbar_plugin.underline.aria_label",
|
|
144
141
|
defaultMessage: "Underline text"
|
|
145
142
|
}),
|
|
146
143
|
children: /* @__PURE__ */ o(
|
|
147
|
-
|
|
144
|
+
c,
|
|
148
145
|
{
|
|
149
146
|
name: "underline",
|
|
150
147
|
width: 24,
|
|
@@ -157,19 +154,18 @@ const he = (l) => {
|
|
|
157
154
|
/* @__PURE__ */ o(
|
|
158
155
|
"button",
|
|
159
156
|
{
|
|
160
|
-
|
|
161
|
-
onMouseDown: i,
|
|
157
|
+
onMouseDown: d,
|
|
162
158
|
onClick: () => R(),
|
|
163
159
|
type: "button",
|
|
164
160
|
className: a(e.toolbarItem, {
|
|
165
161
|
[e.active]: b === "quote"
|
|
166
162
|
}),
|
|
167
|
-
"aria-label":
|
|
163
|
+
"aria-label": r.formatMessage({
|
|
168
164
|
id: "input.text_editor.plugins.toolbar_plugin.blockquote.aria_label",
|
|
169
165
|
defaultMessage: "Add a blockquote"
|
|
170
166
|
}),
|
|
171
167
|
children: /* @__PURE__ */ o(
|
|
172
|
-
|
|
168
|
+
c,
|
|
173
169
|
{
|
|
174
170
|
name: "blockquote",
|
|
175
171
|
width: 24,
|
|
@@ -182,19 +178,18 @@ const he = (l) => {
|
|
|
182
178
|
/* @__PURE__ */ o(
|
|
183
179
|
"button",
|
|
184
180
|
{
|
|
185
|
-
|
|
186
|
-
onMouseDown: i,
|
|
181
|
+
onMouseDown: d,
|
|
187
182
|
onClick: () => O(),
|
|
188
183
|
type: "button",
|
|
189
184
|
className: a(e.toolbarItem, {
|
|
190
185
|
[e.active]: b === "ol"
|
|
191
186
|
}),
|
|
192
|
-
"aria-label":
|
|
187
|
+
"aria-label": r.formatMessage({
|
|
193
188
|
id: "input.text_editor.plugins.toolbar_plugin.numbered_list.aria_label",
|
|
194
189
|
defaultMessage: "Insert a numbered list"
|
|
195
190
|
}),
|
|
196
191
|
children: /* @__PURE__ */ o(
|
|
197
|
-
|
|
192
|
+
c,
|
|
198
193
|
{
|
|
199
194
|
name: "orderedList",
|
|
200
195
|
width: 24,
|
|
@@ -204,20 +199,19 @@ const he = (l) => {
|
|
|
204
199
|
)
|
|
205
200
|
}
|
|
206
201
|
),
|
|
207
|
-
!
|
|
202
|
+
!i.hideSourceAction && /* @__PURE__ */ o(
|
|
208
203
|
"button",
|
|
209
204
|
{
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
onClick: l.onAddSource,
|
|
205
|
+
onMouseDown: d,
|
|
206
|
+
onClick: i.onAddSource,
|
|
213
207
|
type: "button",
|
|
214
208
|
className: e.toolbarItem,
|
|
215
|
-
"aria-label":
|
|
209
|
+
"aria-label": r.formatMessage({
|
|
216
210
|
id: "input.text_editor.plugins.toolbar_plugin.add_link.aria_label",
|
|
217
211
|
defaultMessage: "Add hyperlink"
|
|
218
212
|
}),
|
|
219
213
|
children: /* @__PURE__ */ o(
|
|
220
|
-
|
|
214
|
+
c,
|
|
221
215
|
{
|
|
222
216
|
name: "link",
|
|
223
217
|
width: 20,
|
|
@@ -230,18 +224,18 @@ const he = (l) => {
|
|
|
230
224
|
]
|
|
231
225
|
}
|
|
232
226
|
) : null,
|
|
233
|
-
/* @__PURE__ */ o("div", { className: e.actionButton, children:
|
|
227
|
+
/* @__PURE__ */ o("div", { className: e.actionButton, children: i.hideSubmit ? null : /* @__PURE__ */ o(
|
|
234
228
|
Y,
|
|
235
229
|
{
|
|
236
230
|
type: "button",
|
|
237
231
|
"data-testid": "submit-button",
|
|
238
|
-
handleClick:
|
|
232
|
+
handleClick: i.onSubmit,
|
|
239
233
|
className: a(e.inputSubmitActionButton, e.submitAction),
|
|
240
|
-
"aria-label":
|
|
234
|
+
"aria-label": r.formatMessage({
|
|
241
235
|
id: "input.text_editor.plugins.toolbar_plugin.submit_button.aria_label",
|
|
242
236
|
defaultMessage: "Send message"
|
|
243
237
|
}),
|
|
244
|
-
children: /* @__PURE__ */ o(
|
|
238
|
+
children: /* @__PURE__ */ o(c, { name: "send", width: 20, height: 20 })
|
|
245
239
|
}
|
|
246
240
|
) })
|
|
247
241
|
]
|
|
@@ -249,5 +243,5 @@ const he = (l) => {
|
|
|
249
243
|
);
|
|
250
244
|
};
|
|
251
245
|
export {
|
|
252
|
-
|
|
246
|
+
ge as ToolbarPlugin
|
|
253
247
|
};
|