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