@logora/debate 0.4.25 → 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,135 +1,143 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { $isListNode as
|
|
3
|
-
import { useLexicalComposerContext as
|
|
4
|
-
import { $isHeadingNode 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
5
|
import { $setBlocksType as O } from "@lexical/selection";
|
|
6
|
-
import { $getNearestNodeOfType as
|
|
7
|
-
import
|
|
8
|
-
import { $getSelection as
|
|
9
|
-
import { useRef as
|
|
10
|
-
import { useIntl as
|
|
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 d =
|
|
16
|
-
const t =
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
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
19
|
if (r.getElementByKey(u) !== null)
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
|
|
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
29
|
}, [r]);
|
|
30
|
-
|
|
30
|
+
le(() => oe(
|
|
31
31
|
r.registerUpdateListener(({ editorState: t }) => {
|
|
32
32
|
t.read(() => {
|
|
33
|
-
|
|
33
|
+
y();
|
|
34
34
|
});
|
|
35
35
|
}),
|
|
36
36
|
r.registerCommand(
|
|
37
|
-
|
|
38
|
-
() => (
|
|
39
|
-
|
|
37
|
+
ie,
|
|
38
|
+
() => (y(), !1),
|
|
39
|
+
q
|
|
40
40
|
)
|
|
41
|
-
), [r,
|
|
42
|
-
const
|
|
41
|
+
), [r, y]);
|
|
42
|
+
const a = (t) => {
|
|
43
43
|
t.preventDefault();
|
|
44
|
-
},
|
|
44
|
+
}, E = () => {
|
|
45
45
|
setTimeout(() => {
|
|
46
46
|
r.getEditorState().read(() => {
|
|
47
|
-
|
|
47
|
+
y();
|
|
48
48
|
});
|
|
49
49
|
}, 0);
|
|
50
|
-
},
|
|
51
|
-
r.dispatchCommand(te, t), t === "bold" && x((n) => !n), t === "italic" && C((n) => !n), t === "underline" && L((n) => !n), M();
|
|
52
|
-
}, U = () => {
|
|
50
|
+
}, M = (t) => {
|
|
53
51
|
r.update(() => {
|
|
54
|
-
const
|
|
55
|
-
|
|
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
|
-
o = o.getParent();
|
|
62
|
-
E(o) && c.add(o);
|
|
63
|
-
}
|
|
64
|
-
const u = Array.from(c).reverse();
|
|
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();
|
|
65
64
|
for (const m of u) {
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
let l = m;
|
|
66
|
+
for (; l !== null && !_(l); )
|
|
67
|
+
l = l.getParent();
|
|
68
|
+
_(l) && I.add(l);
|
|
69
|
+
}
|
|
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 c = t.anchor.getNode().getTopLevelElementOrThrow(), u =
|
|
97
|
+
const c = t.anchor.getNode().getTopLevelElementOrThrow(), u = K();
|
|
90
98
|
c.insertAfter(u), u.selectEnd();
|
|
91
99
|
} else
|
|
92
|
-
O(t, () =>
|
|
100
|
+
O(t, () => K());
|
|
93
101
|
}) : r.update(() => {
|
|
94
|
-
const t =
|
|
95
|
-
|
|
96
|
-
}),
|
|
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
|
-
s.isActive ? !s.disableRichText && /* @__PURE__ */
|
|
114
|
+
s.isActive ? !s.disableRichText && /* @__PURE__ */ B(
|
|
107
115
|
"div",
|
|
108
116
|
{
|
|
109
|
-
className:
|
|
117
|
+
className: n(e.iconToolbar, {
|
|
110
118
|
[e.shortBar]: s.shortBar
|
|
111
119
|
}),
|
|
112
120
|
children: [
|
|
113
121
|
/* @__PURE__ */ i(
|
|
114
122
|
"button",
|
|
115
123
|
{
|
|
116
|
-
onTouchStart:
|
|
117
|
-
onMouseDown:
|
|
118
|
-
onClick: () =>
|
|
124
|
+
onTouchStart: a,
|
|
125
|
+
onMouseDown: a,
|
|
126
|
+
onClick: () => M("bold"),
|
|
119
127
|
type: "button",
|
|
120
|
-
className:
|
|
128
|
+
className: n(e.toolbarItem, { [e.active]: F }),
|
|
121
129
|
"data-testid": "format-bold",
|
|
122
130
|
"aria-label": d.formatMessage({
|
|
123
131
|
id: "input.text_editor.plugins.toolbar_plugin.bold.aria_label",
|
|
124
132
|
defaultMessage: "Make text bold"
|
|
125
133
|
}),
|
|
126
134
|
children: /* @__PURE__ */ i(
|
|
127
|
-
|
|
135
|
+
g,
|
|
128
136
|
{
|
|
129
137
|
name: "bold",
|
|
130
138
|
width: 24,
|
|
131
139
|
height: 24,
|
|
132
|
-
className:
|
|
140
|
+
className: n(e.format, e.bold)
|
|
133
141
|
}
|
|
134
142
|
)
|
|
135
143
|
}
|
|
@@ -137,24 +145,24 @@ const _e = (s) => {
|
|
|
137
145
|
/* @__PURE__ */ i(
|
|
138
146
|
"button",
|
|
139
147
|
{
|
|
140
|
-
onTouchStart:
|
|
141
|
-
onMouseDown:
|
|
142
|
-
onClick: () =>
|
|
148
|
+
onTouchStart: a,
|
|
149
|
+
onMouseDown: a,
|
|
150
|
+
onClick: () => M("italic"),
|
|
143
151
|
type: "button",
|
|
144
|
-
className:
|
|
145
|
-
[e.active]:
|
|
152
|
+
className: n(e.toolbarItem, {
|
|
153
|
+
[e.active]: j
|
|
146
154
|
}),
|
|
147
155
|
"aria-label": d.formatMessage({
|
|
148
156
|
id: "input.text_editor.plugins.toolbar_plugin.italic.aria_label",
|
|
149
157
|
defaultMessage: "Make text italic"
|
|
150
158
|
}),
|
|
151
159
|
children: /* @__PURE__ */ i(
|
|
152
|
-
|
|
160
|
+
g,
|
|
153
161
|
{
|
|
154
162
|
name: "italic",
|
|
155
163
|
width: 24,
|
|
156
164
|
height: 24,
|
|
157
|
-
className:
|
|
165
|
+
className: n(e.format, e.italic)
|
|
158
166
|
}
|
|
159
167
|
)
|
|
160
168
|
}
|
|
@@ -162,24 +170,24 @@ const _e = (s) => {
|
|
|
162
170
|
/* @__PURE__ */ i(
|
|
163
171
|
"button",
|
|
164
172
|
{
|
|
165
|
-
onTouchStart:
|
|
166
|
-
onMouseDown:
|
|
167
|
-
onClick: () =>
|
|
173
|
+
onTouchStart: a,
|
|
174
|
+
onMouseDown: a,
|
|
175
|
+
onClick: () => M("underline"),
|
|
168
176
|
type: "button",
|
|
169
|
-
className:
|
|
170
|
-
[e.active]:
|
|
177
|
+
className: n(e.toolbarItem, {
|
|
178
|
+
[e.active]: H
|
|
171
179
|
}),
|
|
172
180
|
"aria-label": d.formatMessage({
|
|
173
181
|
id: "input.text_editor.plugins.toolbar_plugin.underline.aria_label",
|
|
174
182
|
defaultMessage: "Underline text"
|
|
175
183
|
}),
|
|
176
184
|
children: /* @__PURE__ */ i(
|
|
177
|
-
|
|
185
|
+
g,
|
|
178
186
|
{
|
|
179
187
|
name: "underline",
|
|
180
188
|
width: 24,
|
|
181
189
|
height: 24,
|
|
182
|
-
className:
|
|
190
|
+
className: n(e.format, e.underline)
|
|
183
191
|
}
|
|
184
192
|
)
|
|
185
193
|
}
|
|
@@ -187,24 +195,24 @@ const _e = (s) => {
|
|
|
187
195
|
/* @__PURE__ */ i(
|
|
188
196
|
"button",
|
|
189
197
|
{
|
|
190
|
-
onTouchStart:
|
|
191
|
-
onMouseDown:
|
|
192
|
-
onClick: () =>
|
|
198
|
+
onTouchStart: a,
|
|
199
|
+
onMouseDown: a,
|
|
200
|
+
onClick: () => z(),
|
|
193
201
|
type: "button",
|
|
194
|
-
className:
|
|
195
|
-
[e.active]:
|
|
202
|
+
className: n(e.toolbarItem, {
|
|
203
|
+
[e.active]: T === "quote"
|
|
196
204
|
}),
|
|
197
205
|
"aria-label": d.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
|
+
g,
|
|
203
211
|
{
|
|
204
212
|
name: "blockquote",
|
|
205
213
|
width: 24,
|
|
206
214
|
height: 24,
|
|
207
|
-
className:
|
|
215
|
+
className: n(e.format, e.quote)
|
|
208
216
|
}
|
|
209
217
|
)
|
|
210
218
|
}
|
|
@@ -212,24 +220,24 @@ const _e = (s) => {
|
|
|
212
220
|
/* @__PURE__ */ i(
|
|
213
221
|
"button",
|
|
214
222
|
{
|
|
215
|
-
onTouchStart:
|
|
216
|
-
onMouseDown:
|
|
217
|
-
onClick: () =>
|
|
223
|
+
onTouchStart: a,
|
|
224
|
+
onMouseDown: a,
|
|
225
|
+
onClick: () => V(),
|
|
218
226
|
type: "button",
|
|
219
|
-
className:
|
|
220
|
-
[e.active]:
|
|
227
|
+
className: n(e.toolbarItem, {
|
|
228
|
+
[e.active]: T === "ol"
|
|
221
229
|
}),
|
|
222
230
|
"aria-label": d.formatMessage({
|
|
223
231
|
id: "input.text_editor.plugins.toolbar_plugin.numbered_list.aria_label",
|
|
224
232
|
defaultMessage: "Insert a numbered list"
|
|
225
233
|
}),
|
|
226
234
|
children: /* @__PURE__ */ i(
|
|
227
|
-
|
|
235
|
+
g,
|
|
228
236
|
{
|
|
229
237
|
name: "orderedList",
|
|
230
238
|
width: 24,
|
|
231
239
|
height: 24,
|
|
232
|
-
className:
|
|
240
|
+
className: n(e.format, e.numberedList)
|
|
233
241
|
}
|
|
234
242
|
)
|
|
235
243
|
}
|
|
@@ -237,8 +245,8 @@ const _e = (s) => {
|
|
|
237
245
|
!s.hideSourceAction && /* @__PURE__ */ i(
|
|
238
246
|
"button",
|
|
239
247
|
{
|
|
240
|
-
onTouchStart:
|
|
241
|
-
onMouseDown:
|
|
248
|
+
onTouchStart: a,
|
|
249
|
+
onMouseDown: a,
|
|
242
250
|
onClick: s.onAddSource,
|
|
243
251
|
type: "button",
|
|
244
252
|
className: e.toolbarItem,
|
|
@@ -247,12 +255,12 @@ const _e = (s) => {
|
|
|
247
255
|
defaultMessage: "Add hyperlink"
|
|
248
256
|
}),
|
|
249
257
|
children: /* @__PURE__ */ i(
|
|
250
|
-
|
|
258
|
+
g,
|
|
251
259
|
{
|
|
252
260
|
name: "link",
|
|
253
261
|
width: 20,
|
|
254
262
|
height: 20,
|
|
255
|
-
className:
|
|
263
|
+
className: n(e.format, e.link)
|
|
256
264
|
}
|
|
257
265
|
)
|
|
258
266
|
}
|
|
@@ -261,17 +269,17 @@ const _e = (s) => {
|
|
|
261
269
|
}
|
|
262
270
|
) : null,
|
|
263
271
|
/* @__PURE__ */ i("div", { className: e.actionButton, children: s.hideSubmit ? null : /* @__PURE__ */ i(
|
|
264
|
-
|
|
272
|
+
re,
|
|
265
273
|
{
|
|
266
274
|
type: "button",
|
|
267
275
|
"data-testid": "submit-button",
|
|
268
276
|
handleClick: s.onSubmit,
|
|
269
|
-
className:
|
|
277
|
+
className: n(e.inputSubmitActionButton, e.submitAction),
|
|
270
278
|
"aria-label": d.formatMessage({
|
|
271
279
|
id: "input.text_editor.plugins.toolbar_plugin.submit_button.aria_label",
|
|
272
280
|
defaultMessage: "Send message"
|
|
273
281
|
}),
|
|
274
|
-
children: /* @__PURE__ */ i(
|
|
282
|
+
children: /* @__PURE__ */ i(g, { name: "send", width: 20, height: 20 })
|
|
275
283
|
}
|
|
276
284
|
) })
|
|
277
285
|
]
|
|
@@ -279,5 +287,5 @@ const _e = (s) => {
|
|
|
279
287
|
);
|
|
280
288
|
};
|
|
281
289
|
export {
|
|
282
|
-
|
|
290
|
+
Me as ToolbarPlugin
|
|
283
291
|
};
|