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