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