@logora/debate 0.4.25 → 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,135 +1,146 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { $isListNode as
|
|
3
|
-
import { useLexicalComposerContext as
|
|
4
|
-
import { $isHeadingNode as
|
|
5
|
-
import { $setBlocksType as
|
|
6
|
-
import { $getNearestNodeOfType as
|
|
7
|
-
import
|
|
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
|
|
19
|
-
if (r.getElementByKey(
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
|
|
1
|
+
import { jsxs as B, jsx as i } from "react/jsx-runtime";
|
|
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
|
+
import n from "classnames";
|
|
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
|
|
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.dispatchCommand(
|
|
52
|
-
},
|
|
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 = () => {
|
|
53
60
|
r.update(() => {
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
61
|
+
const e = T();
|
|
62
|
+
if (!y(e))
|
|
56
63
|
return;
|
|
57
|
-
|
|
58
|
-
for (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
let o = e.anchor.getNode();
|
|
65
|
+
for (; o !== null && !_(o); )
|
|
66
|
+
o = o.getParent();
|
|
67
|
+
const a = _(o) ? o.getKey() : null, d = e.getNodes(), L = /* @__PURE__ */ new Set();
|
|
68
|
+
for (const u of d) {
|
|
69
|
+
let l = u;
|
|
70
|
+
for (; l !== null && !_(l); )
|
|
71
|
+
l = l.getParent();
|
|
72
|
+
_(l) && L.add(l);
|
|
63
73
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
const b = Array.from(L).reverse();
|
|
75
|
+
let f = null;
|
|
76
|
+
for (const u of b) {
|
|
77
|
+
const l = u.getParent();
|
|
78
|
+
if (!R(l))
|
|
68
79
|
continue;
|
|
69
|
-
const
|
|
70
|
-
for (const
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
for (const
|
|
76
|
-
|
|
77
|
-
|
|
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);
|
|
78
89
|
}
|
|
79
|
-
|
|
90
|
+
u.getKey() === a && (f = M), u.remove(), l.getChildrenSize() === 0 && l.remove();
|
|
80
91
|
}
|
|
92
|
+
f !== null && f.selectEnd();
|
|
81
93
|
});
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
if (
|
|
89
|
-
const
|
|
90
|
-
|
|
94
|
+
}, z = () => {
|
|
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();
|
|
91
103
|
} else
|
|
92
|
-
|
|
104
|
+
K(e, () => $());
|
|
93
105
|
}) : r.update(() => {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
}),
|
|
106
|
+
const e = T();
|
|
107
|
+
y(e) && K(e, () => q());
|
|
108
|
+
}), D();
|
|
97
109
|
};
|
|
98
|
-
return
|
|
110
|
+
return E ? null : /* @__PURE__ */ B(
|
|
99
111
|
"div",
|
|
100
112
|
{
|
|
101
|
-
className:
|
|
102
|
-
[
|
|
113
|
+
className: n(t.toolbar, {
|
|
114
|
+
[t.toolbarIsActive]: E ? !1 : s.isActive
|
|
103
115
|
}),
|
|
104
|
-
ref:
|
|
116
|
+
ref: x,
|
|
105
117
|
children: [
|
|
106
|
-
s.isActive ? !s.disableRichText && /* @__PURE__ */
|
|
118
|
+
s.isActive ? !s.disableRichText && /* @__PURE__ */ B(
|
|
107
119
|
"div",
|
|
108
120
|
{
|
|
109
|
-
className:
|
|
110
|
-
[
|
|
121
|
+
className: n(t.iconToolbar, {
|
|
122
|
+
[t.shortBar]: s.shortBar
|
|
111
123
|
}),
|
|
112
124
|
children: [
|
|
113
125
|
/* @__PURE__ */ i(
|
|
114
126
|
"button",
|
|
115
127
|
{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
onClick: () => _("bold"),
|
|
128
|
+
onMouseDown: g,
|
|
129
|
+
onClick: () => I("bold"),
|
|
119
130
|
type: "button",
|
|
120
|
-
className:
|
|
131
|
+
className: n(t.toolbarItem, { [t.active]: j }),
|
|
121
132
|
"data-testid": "format-bold",
|
|
122
|
-
"aria-label":
|
|
133
|
+
"aria-label": c.formatMessage({
|
|
123
134
|
id: "input.text_editor.plugins.toolbar_plugin.bold.aria_label",
|
|
124
135
|
defaultMessage: "Make text bold"
|
|
125
136
|
}),
|
|
126
137
|
children: /* @__PURE__ */ i(
|
|
127
|
-
|
|
138
|
+
m,
|
|
128
139
|
{
|
|
129
140
|
name: "bold",
|
|
130
141
|
width: 24,
|
|
131
142
|
height: 24,
|
|
132
|
-
className:
|
|
143
|
+
className: n(t.format, t.bold)
|
|
133
144
|
}
|
|
134
145
|
)
|
|
135
146
|
}
|
|
@@ -137,24 +148,23 @@ const _e = (s) => {
|
|
|
137
148
|
/* @__PURE__ */ i(
|
|
138
149
|
"button",
|
|
139
150
|
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
onClick: () => _("italic"),
|
|
151
|
+
onMouseDown: g,
|
|
152
|
+
onClick: () => I("italic"),
|
|
143
153
|
type: "button",
|
|
144
|
-
className:
|
|
145
|
-
[
|
|
154
|
+
className: n(t.toolbarItem, {
|
|
155
|
+
[t.active]: H
|
|
146
156
|
}),
|
|
147
|
-
"aria-label":
|
|
157
|
+
"aria-label": c.formatMessage({
|
|
148
158
|
id: "input.text_editor.plugins.toolbar_plugin.italic.aria_label",
|
|
149
159
|
defaultMessage: "Make text italic"
|
|
150
160
|
}),
|
|
151
161
|
children: /* @__PURE__ */ i(
|
|
152
|
-
|
|
162
|
+
m,
|
|
153
163
|
{
|
|
154
164
|
name: "italic",
|
|
155
165
|
width: 24,
|
|
156
166
|
height: 24,
|
|
157
|
-
className:
|
|
167
|
+
className: n(t.format, t.italic)
|
|
158
168
|
}
|
|
159
169
|
)
|
|
160
170
|
}
|
|
@@ -162,24 +172,23 @@ const _e = (s) => {
|
|
|
162
172
|
/* @__PURE__ */ i(
|
|
163
173
|
"button",
|
|
164
174
|
{
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
onClick: () => _("underline"),
|
|
175
|
+
onMouseDown: g,
|
|
176
|
+
onClick: () => I("underline"),
|
|
168
177
|
type: "button",
|
|
169
|
-
className:
|
|
170
|
-
[
|
|
178
|
+
className: n(t.toolbarItem, {
|
|
179
|
+
[t.active]: Q
|
|
171
180
|
}),
|
|
172
|
-
"aria-label":
|
|
181
|
+
"aria-label": c.formatMessage({
|
|
173
182
|
id: "input.text_editor.plugins.toolbar_plugin.underline.aria_label",
|
|
174
183
|
defaultMessage: "Underline text"
|
|
175
184
|
}),
|
|
176
185
|
children: /* @__PURE__ */ i(
|
|
177
|
-
|
|
186
|
+
m,
|
|
178
187
|
{
|
|
179
188
|
name: "underline",
|
|
180
189
|
width: 24,
|
|
181
190
|
height: 24,
|
|
182
|
-
className:
|
|
191
|
+
className: n(t.format, t.underline)
|
|
183
192
|
}
|
|
184
193
|
)
|
|
185
194
|
}
|
|
@@ -187,24 +196,23 @@ const _e = (s) => {
|
|
|
187
196
|
/* @__PURE__ */ i(
|
|
188
197
|
"button",
|
|
189
198
|
{
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
onClick: () => H(),
|
|
199
|
+
onMouseDown: g,
|
|
200
|
+
onClick: () => G(),
|
|
193
201
|
type: "button",
|
|
194
|
-
className:
|
|
195
|
-
[
|
|
202
|
+
className: n(t.toolbarItem, {
|
|
203
|
+
[t.active]: p === "quote"
|
|
196
204
|
}),
|
|
197
|
-
"aria-label":
|
|
205
|
+
"aria-label": c.formatMessage({
|
|
198
206
|
id: "input.text_editor.plugins.toolbar_plugin.blockquote.aria_label",
|
|
199
207
|
defaultMessage: "Add a blockquote"
|
|
200
208
|
}),
|
|
201
209
|
children: /* @__PURE__ */ i(
|
|
202
|
-
|
|
210
|
+
m,
|
|
203
211
|
{
|
|
204
212
|
name: "blockquote",
|
|
205
213
|
width: 24,
|
|
206
214
|
height: 24,
|
|
207
|
-
className:
|
|
215
|
+
className: n(t.format, t.quote)
|
|
208
216
|
}
|
|
209
217
|
)
|
|
210
218
|
}
|
|
@@ -212,24 +220,23 @@ const _e = (s) => {
|
|
|
212
220
|
/* @__PURE__ */ i(
|
|
213
221
|
"button",
|
|
214
222
|
{
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
onClick: () => j(),
|
|
223
|
+
onMouseDown: g,
|
|
224
|
+
onClick: () => z(),
|
|
218
225
|
type: "button",
|
|
219
|
-
className:
|
|
220
|
-
[
|
|
226
|
+
className: n(t.toolbarItem, {
|
|
227
|
+
[t.active]: p === "ol"
|
|
221
228
|
}),
|
|
222
|
-
"aria-label":
|
|
229
|
+
"aria-label": c.formatMessage({
|
|
223
230
|
id: "input.text_editor.plugins.toolbar_plugin.numbered_list.aria_label",
|
|
224
231
|
defaultMessage: "Insert a numbered list"
|
|
225
232
|
}),
|
|
226
233
|
children: /* @__PURE__ */ i(
|
|
227
|
-
|
|
234
|
+
m,
|
|
228
235
|
{
|
|
229
236
|
name: "orderedList",
|
|
230
237
|
width: 24,
|
|
231
238
|
height: 24,
|
|
232
|
-
className:
|
|
239
|
+
className: n(t.format, t.numberedList)
|
|
233
240
|
}
|
|
234
241
|
)
|
|
235
242
|
}
|
|
@@ -237,22 +244,21 @@ const _e = (s) => {
|
|
|
237
244
|
!s.hideSourceAction && /* @__PURE__ */ i(
|
|
238
245
|
"button",
|
|
239
246
|
{
|
|
240
|
-
|
|
241
|
-
onMouseDown: l,
|
|
247
|
+
onMouseDown: g,
|
|
242
248
|
onClick: s.onAddSource,
|
|
243
249
|
type: "button",
|
|
244
|
-
className:
|
|
245
|
-
"aria-label":
|
|
250
|
+
className: t.toolbarItem,
|
|
251
|
+
"aria-label": c.formatMessage({
|
|
246
252
|
id: "input.text_editor.plugins.toolbar_plugin.add_link.aria_label",
|
|
247
253
|
defaultMessage: "Add hyperlink"
|
|
248
254
|
}),
|
|
249
255
|
children: /* @__PURE__ */ i(
|
|
250
|
-
|
|
256
|
+
m,
|
|
251
257
|
{
|
|
252
258
|
name: "link",
|
|
253
259
|
width: 20,
|
|
254
260
|
height: 20,
|
|
255
|
-
className:
|
|
261
|
+
className: n(t.format, t.link)
|
|
256
262
|
}
|
|
257
263
|
)
|
|
258
264
|
}
|
|
@@ -260,18 +266,18 @@ const _e = (s) => {
|
|
|
260
266
|
]
|
|
261
267
|
}
|
|
262
268
|
) : null,
|
|
263
|
-
/* @__PURE__ */ i("div", { className:
|
|
264
|
-
|
|
269
|
+
/* @__PURE__ */ i("div", { className: t.actionButton, children: s.hideSubmit ? null : /* @__PURE__ */ i(
|
|
270
|
+
ce,
|
|
265
271
|
{
|
|
266
272
|
type: "button",
|
|
267
273
|
"data-testid": "submit-button",
|
|
268
274
|
handleClick: s.onSubmit,
|
|
269
|
-
className:
|
|
270
|
-
"aria-label":
|
|
275
|
+
className: n(t.inputSubmitActionButton, t.submitAction),
|
|
276
|
+
"aria-label": c.formatMessage({
|
|
271
277
|
id: "input.text_editor.plugins.toolbar_plugin.submit_button.aria_label",
|
|
272
278
|
defaultMessage: "Send message"
|
|
273
279
|
}),
|
|
274
|
-
children: /* @__PURE__ */ i(
|
|
280
|
+
children: /* @__PURE__ */ i(m, { name: "send", width: 20, height: 20 })
|
|
275
281
|
}
|
|
276
282
|
) })
|
|
277
283
|
]
|
|
@@ -279,5 +285,5 @@ const _e = (s) => {
|
|
|
279
285
|
);
|
|
280
286
|
};
|
|
281
287
|
export {
|
|
282
|
-
|
|
288
|
+
Le as ToolbarPlugin
|
|
283
289
|
};
|