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