@logora/debate 0.4.21 → 0.4.23
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,214 +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
|
|
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
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 (
|
|
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
18
|
const c = t.anchor.getNode(), s = c.getKey() === "root" ? c : c.getTopLevelElementOrThrow(), d = s.getKey();
|
|
19
|
-
if (
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
|
|
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
|
|
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
|
-
}, [
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
}, [l]);
|
|
30
|
+
ae(() => Z(
|
|
31
|
+
l.registerUpdateListener(({ editorState: t }) => {
|
|
32
32
|
t.read(() => {
|
|
33
|
-
|
|
33
|
+
p();
|
|
34
34
|
});
|
|
35
35
|
}),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
() => (
|
|
39
|
-
|
|
36
|
+
l.registerCommand(
|
|
37
|
+
ee,
|
|
38
|
+
() => (p(), !1),
|
|
39
|
+
D
|
|
40
40
|
)
|
|
41
|
-
), [
|
|
42
|
-
const
|
|
41
|
+
), [l, p]);
|
|
42
|
+
const b = (t) => {
|
|
43
|
+
t.pointerType !== "touch" && t.pointerType !== "pen" && t.preventDefault();
|
|
44
|
+
}, x = () => {
|
|
43
45
|
setTimeout(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
l.getEditorState().read(() => {
|
|
47
|
+
p();
|
|
46
48
|
});
|
|
47
49
|
}, 0);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
}, T = (t) => {
|
|
51
|
+
l.dispatchCommand(te, t);
|
|
52
|
+
}, U = () => {
|
|
53
|
+
l.update(() => {
|
|
54
|
+
const t = N();
|
|
55
|
+
if (!_(t))
|
|
56
|
+
return;
|
|
57
|
+
const c = t.getNodes(), s = /* @__PURE__ */ new Set();
|
|
58
|
+
for (const m of c) {
|
|
59
|
+
let o = m;
|
|
60
|
+
for (; o !== null && !w(o); )
|
|
61
|
+
o = o.getParent();
|
|
62
|
+
w(o) && s.add(o);
|
|
63
|
+
}
|
|
64
|
+
const d = Array.from(s).reverse();
|
|
65
|
+
for (const m of d) {
|
|
66
|
+
const o = m.getParent();
|
|
67
|
+
if (!k(o))
|
|
68
|
+
continue;
|
|
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);
|
|
78
|
+
}
|
|
79
|
+
m.remove(), o.getChildrenSize() === 0 && o.remove();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}, j = () => {
|
|
83
|
+
h !== "ol" ? l.dispatchCommand(G) : U(), x();
|
|
84
|
+
}, H = () => {
|
|
85
|
+
h !== "quote" ? l.update(() => {
|
|
86
|
+
const t = N();
|
|
87
|
+
if (_(t))
|
|
56
88
|
if (t.isCollapsed()) {
|
|
57
|
-
const s = t.anchor.getNode().getTopLevelElementOrThrow(), d =
|
|
89
|
+
const s = t.anchor.getNode().getTopLevelElementOrThrow(), d = A();
|
|
58
90
|
s.insertAfter(d), d.selectEnd();
|
|
59
91
|
} else
|
|
60
|
-
|
|
61
|
-
}) :
|
|
62
|
-
const t =
|
|
63
|
-
|
|
64
|
-
}),
|
|
92
|
+
v(t, () => A());
|
|
93
|
+
}) : l.update(() => {
|
|
94
|
+
const t = N();
|
|
95
|
+
_(t) && v(t, () => E());
|
|
96
|
+
}), x();
|
|
65
97
|
};
|
|
66
|
-
return
|
|
98
|
+
return S ? null : /* @__PURE__ */ L(
|
|
67
99
|
"div",
|
|
68
100
|
{
|
|
69
|
-
className:
|
|
70
|
-
[e.toolbarIsActive]:
|
|
101
|
+
className: a(e.toolbar, {
|
|
102
|
+
[e.toolbarIsActive]: S ? !1 : n.isActive
|
|
71
103
|
}),
|
|
72
|
-
ref:
|
|
104
|
+
ref: O,
|
|
73
105
|
children: [
|
|
74
|
-
|
|
106
|
+
n.isActive ? !n.disableRichText && /* @__PURE__ */ L(
|
|
75
107
|
"div",
|
|
76
108
|
{
|
|
77
|
-
className:
|
|
78
|
-
[e.shortBar]:
|
|
109
|
+
className: a(e.iconToolbar, {
|
|
110
|
+
[e.shortBar]: n.shortBar
|
|
79
111
|
}),
|
|
80
112
|
children: [
|
|
81
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ i(
|
|
82
114
|
"button",
|
|
83
115
|
{
|
|
84
|
-
|
|
116
|
+
onPointerDown: b,
|
|
117
|
+
onClick: () => T("bold"),
|
|
85
118
|
type: "button",
|
|
86
|
-
className:
|
|
119
|
+
className: a(e.toolbarItem, { [e.active]: B }),
|
|
87
120
|
"data-testid": "format-bold",
|
|
88
|
-
"aria-label":
|
|
121
|
+
"aria-label": r.formatMessage({
|
|
89
122
|
id: "input.text_editor.plugins.toolbar_plugin.bold.aria_label",
|
|
90
123
|
defaultMessage: "Make text bold"
|
|
91
124
|
}),
|
|
92
|
-
children: /* @__PURE__ */
|
|
93
|
-
|
|
125
|
+
children: /* @__PURE__ */ i(
|
|
126
|
+
u,
|
|
94
127
|
{
|
|
95
128
|
name: "bold",
|
|
96
129
|
width: 24,
|
|
97
130
|
height: 24,
|
|
98
|
-
className:
|
|
131
|
+
className: a(e.format, e.bold)
|
|
99
132
|
}
|
|
100
133
|
)
|
|
101
134
|
}
|
|
102
135
|
),
|
|
103
|
-
/* @__PURE__ */
|
|
136
|
+
/* @__PURE__ */ i(
|
|
104
137
|
"button",
|
|
105
138
|
{
|
|
106
|
-
|
|
139
|
+
onPointerDown: b,
|
|
140
|
+
onClick: () => T("italic"),
|
|
107
141
|
type: "button",
|
|
108
|
-
className:
|
|
109
|
-
[e.active]:
|
|
142
|
+
className: a(e.toolbarItem, {
|
|
143
|
+
[e.active]: $
|
|
110
144
|
}),
|
|
111
|
-
"aria-label":
|
|
145
|
+
"aria-label": r.formatMessage({
|
|
112
146
|
id: "input.text_editor.plugins.toolbar_plugin.italic.aria_label",
|
|
113
147
|
defaultMessage: "Make text italic"
|
|
114
148
|
}),
|
|
115
|
-
children: /* @__PURE__ */
|
|
116
|
-
|
|
149
|
+
children: /* @__PURE__ */ i(
|
|
150
|
+
u,
|
|
117
151
|
{
|
|
118
152
|
name: "italic",
|
|
119
153
|
width: 24,
|
|
120
154
|
height: 24,
|
|
121
|
-
className:
|
|
155
|
+
className: a(e.format, e.italic)
|
|
122
156
|
}
|
|
123
157
|
)
|
|
124
158
|
}
|
|
125
159
|
),
|
|
126
|
-
/* @__PURE__ */
|
|
160
|
+
/* @__PURE__ */ i(
|
|
127
161
|
"button",
|
|
128
162
|
{
|
|
129
|
-
|
|
163
|
+
onPointerDown: b,
|
|
164
|
+
onClick: () => T("underline"),
|
|
130
165
|
type: "button",
|
|
131
|
-
className:
|
|
132
|
-
[e.active]:
|
|
166
|
+
className: a(e.toolbarItem, {
|
|
167
|
+
[e.active]: K
|
|
133
168
|
}),
|
|
134
|
-
"aria-label":
|
|
169
|
+
"aria-label": r.formatMessage({
|
|
135
170
|
id: "input.text_editor.plugins.toolbar_plugin.underline.aria_label",
|
|
136
171
|
defaultMessage: "Underline text"
|
|
137
172
|
}),
|
|
138
|
-
children: /* @__PURE__ */
|
|
139
|
-
|
|
173
|
+
children: /* @__PURE__ */ i(
|
|
174
|
+
u,
|
|
140
175
|
{
|
|
141
176
|
name: "underline",
|
|
142
177
|
width: 24,
|
|
143
178
|
height: 24,
|
|
144
|
-
className:
|
|
179
|
+
className: a(e.format, e.underline)
|
|
145
180
|
}
|
|
146
181
|
)
|
|
147
182
|
}
|
|
148
183
|
),
|
|
149
|
-
/* @__PURE__ */
|
|
184
|
+
/* @__PURE__ */ i(
|
|
150
185
|
"button",
|
|
151
186
|
{
|
|
152
|
-
|
|
187
|
+
onPointerDown: b,
|
|
188
|
+
onClick: () => H(),
|
|
153
189
|
type: "button",
|
|
154
|
-
className:
|
|
155
|
-
[e.active]:
|
|
190
|
+
className: a(e.toolbarItem, {
|
|
191
|
+
[e.active]: h === "quote"
|
|
156
192
|
}),
|
|
157
|
-
"aria-label":
|
|
193
|
+
"aria-label": r.formatMessage({
|
|
158
194
|
id: "input.text_editor.plugins.toolbar_plugin.blockquote.aria_label",
|
|
159
195
|
defaultMessage: "Add a blockquote"
|
|
160
196
|
}),
|
|
161
|
-
children: /* @__PURE__ */
|
|
162
|
-
|
|
197
|
+
children: /* @__PURE__ */ i(
|
|
198
|
+
u,
|
|
163
199
|
{
|
|
164
200
|
name: "blockquote",
|
|
165
201
|
width: 24,
|
|
166
202
|
height: 24,
|
|
167
|
-
className:
|
|
203
|
+
className: a(e.format, e.quote)
|
|
168
204
|
}
|
|
169
205
|
)
|
|
170
206
|
}
|
|
171
207
|
),
|
|
172
|
-
/* @__PURE__ */
|
|
208
|
+
/* @__PURE__ */ i(
|
|
173
209
|
"button",
|
|
174
210
|
{
|
|
175
|
-
|
|
211
|
+
onPointerDown: b,
|
|
212
|
+
onClick: () => j(),
|
|
176
213
|
type: "button",
|
|
177
|
-
className:
|
|
178
|
-
[e.active]:
|
|
214
|
+
className: a(e.toolbarItem, {
|
|
215
|
+
[e.active]: h === "ol"
|
|
179
216
|
}),
|
|
180
|
-
"aria-label":
|
|
217
|
+
"aria-label": r.formatMessage({
|
|
181
218
|
id: "input.text_editor.plugins.toolbar_plugin.numbered_list.aria_label",
|
|
182
219
|
defaultMessage: "Insert a numbered list"
|
|
183
220
|
}),
|
|
184
|
-
children: /* @__PURE__ */
|
|
185
|
-
|
|
221
|
+
children: /* @__PURE__ */ i(
|
|
222
|
+
u,
|
|
186
223
|
{
|
|
187
224
|
name: "orderedList",
|
|
188
225
|
width: 24,
|
|
189
226
|
height: 24,
|
|
190
|
-
className:
|
|
227
|
+
className: a(e.format, e.numberedList)
|
|
191
228
|
}
|
|
192
229
|
)
|
|
193
230
|
}
|
|
194
231
|
),
|
|
195
|
-
!
|
|
232
|
+
!n.hideSourceAction && /* @__PURE__ */ i(
|
|
196
233
|
"button",
|
|
197
234
|
{
|
|
198
|
-
|
|
235
|
+
onPointerDown: b,
|
|
236
|
+
onClick: n.onAddSource,
|
|
199
237
|
type: "button",
|
|
200
238
|
className: e.toolbarItem,
|
|
201
|
-
"aria-label":
|
|
239
|
+
"aria-label": r.formatMessage({
|
|
202
240
|
id: "input.text_editor.plugins.toolbar_plugin.add_link.aria_label",
|
|
203
241
|
defaultMessage: "Add hyperlink"
|
|
204
242
|
}),
|
|
205
|
-
children: /* @__PURE__ */
|
|
206
|
-
|
|
243
|
+
children: /* @__PURE__ */ i(
|
|
244
|
+
u,
|
|
207
245
|
{
|
|
208
246
|
name: "link",
|
|
209
247
|
width: 20,
|
|
210
248
|
height: 20,
|
|
211
|
-
className:
|
|
249
|
+
className: a(e.format, e.link)
|
|
212
250
|
}
|
|
213
251
|
)
|
|
214
252
|
}
|
|
@@ -216,18 +254,18 @@ const be = (l) => {
|
|
|
216
254
|
]
|
|
217
255
|
}
|
|
218
256
|
) : null,
|
|
219
|
-
/* @__PURE__ */
|
|
220
|
-
|
|
257
|
+
/* @__PURE__ */ i("div", { className: e.actionButton, children: n.hideSubmit ? null : /* @__PURE__ */ i(
|
|
258
|
+
le,
|
|
221
259
|
{
|
|
222
260
|
type: "button",
|
|
223
261
|
"data-testid": "submit-button",
|
|
224
|
-
handleClick:
|
|
225
|
-
className:
|
|
226
|
-
"aria-label":
|
|
262
|
+
handleClick: n.onSubmit,
|
|
263
|
+
className: a(e.inputSubmitActionButton, e.submitAction),
|
|
264
|
+
"aria-label": r.formatMessage({
|
|
227
265
|
id: "input.text_editor.plugins.toolbar_plugin.submit_button.aria_label",
|
|
228
266
|
defaultMessage: "Send message"
|
|
229
267
|
}),
|
|
230
|
-
children: /* @__PURE__ */
|
|
268
|
+
children: /* @__PURE__ */ i(u, { name: "send", width: 20, height: 20 })
|
|
231
269
|
}
|
|
232
270
|
) })
|
|
233
271
|
]
|
|
@@ -235,5 +273,5 @@ const be = (l) => {
|
|
|
235
273
|
);
|
|
236
274
|
};
|
|
237
275
|
export {
|
|
238
|
-
|
|
276
|
+
ye as ToolbarPlugin
|
|
239
277
|
};
|