@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 w, jsx as i } from "react/jsx-runtime";
2
- import { $isListNode as A, ListNode as z, INSERT_ORDERED_LIST_COMMAND as G, $isListItemNode as E, $createListNode as X } from "@lexical/list";
3
- import { useLexicalComposerContext as J } from "@lexical/react/LexicalComposerContext";
4
- import { $isHeadingNode as W, $createQuoteNode as D } from "@lexical/rich-text";
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 Y, mergeRegister as Z } from "@lexical/utils";
7
- import a from "classnames";
8
- import { $getSelection as N, $isRangeSelection as T, SELECTION_CHANGE_COMMAND as ee, FORMAT_TEXT_COMMAND as te, $createParagraphNode as B } 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";
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 b } from "../../../icons/icon/Icon.js";
13
- import { Button as le } from "../../../action/button/Button.js";
14
- const _e = (s) => {
15
- const d = ne(), R = 1, [r] = J(), $ = oe(null), [h, I] = g("paragraph"), [se, q] = g(null), [K, x] = g(!1), [P, C] = g(!1), [F, L] = g(!1), k = s.hideSubmit && s.hideSourceAction && s.disableRichText, p = ie(() => {
16
- const t = N();
17
- if (T(t)) {
18
- const n = t.anchor.getNode(), c = n.getKey() === "root" ? n : n.getTopLevelElementOrThrow(), u = c.getKey();
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 (q(u), A(c)) {
21
- const o = Y(n, z), f = o ? o.getTag() : c.getTag();
22
- I(f);
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 o = W(c) ? c.getTag() : c.getType();
25
- I(o);
24
+ const b = ee(c) ? c.getTag() : c.getType();
25
+ k(b);
26
26
  }
27
- x(t.hasFormat("bold")), C(t.hasFormat("italic")), L(t.hasFormat("underline"));
27
+ v(t.hasFormat("bold")), w(t.hasFormat("italic")), C(t.hasFormat("underline"));
28
28
  }
29
29
  }, [r]);
30
- ae(() => Z(
30
+ le(() => oe(
31
31
  r.registerUpdateListener(({ editorState: t }) => {
32
32
  t.read(() => {
33
- p();
33
+ y();
34
34
  });
35
35
  }),
36
36
  r.registerCommand(
37
- ee,
38
- () => (p(), !1),
39
- R
37
+ ie,
38
+ () => (y(), !1),
39
+ q
40
40
  )
41
- ), [r, p]);
42
- const l = (t) => {
41
+ ), [r, y]);
42
+ const a = (t) => {
43
43
  t.preventDefault();
44
- }, M = () => {
44
+ }, E = () => {
45
45
  setTimeout(() => {
46
46
  r.getEditorState().read(() => {
47
- p();
47
+ y();
48
48
  });
49
49
  }, 0);
50
- }, _ = (t) => {
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 t = N();
55
- if (!T(t))
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
- const n = t.getNodes(), c = /* @__PURE__ */ new Set();
58
- for (const m of n) {
59
- let o = m;
60
- for (; o !== null && !E(o); )
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
- const o = m.getParent();
67
- if (!A(o))
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 f = B(), Q = m.getChildren();
70
- for (const y of Q)
71
- f.append(y);
72
- const S = m.getNextSiblings();
73
- if (o.insertAfter(f), S.length > 0) {
74
- const y = S[0].getValue(), v = X(o.getListType(), y);
75
- for (const V of S)
76
- v.append(V);
77
- f.insertAfter(v);
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(), o.getChildrenSize() === 0 && o.remove();
86
+ m.getKey() === c && (f = S), m.remove(), l.getChildrenSize() === 0 && l.remove();
80
87
  }
88
+ f !== null && f.selectEnd();
81
89
  });
82
- }, j = () => {
83
- h !== "ol" ? r.dispatchCommand(G) : U(), M();
84
- }, H = () => {
85
- h !== "quote" ? r.update(() => {
86
- const t = N();
87
- if (T(t))
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 = D();
97
+ const c = t.anchor.getNode().getTopLevelElementOrThrow(), u = K();
90
98
  c.insertAfter(u), u.selectEnd();
91
99
  } else
92
- O(t, () => D());
100
+ O(t, () => K());
93
101
  }) : r.update(() => {
94
- const t = N();
95
- T(t) && O(t, () => B());
96
- }), M();
102
+ const t = h();
103
+ p(t) && O(t, () => R());
104
+ }), E();
97
105
  };
98
- return k ? null : /* @__PURE__ */ w(
106
+ return A ? null : /* @__PURE__ */ B(
99
107
  "div",
100
108
  {
101
- className: a(e.toolbar, {
102
- [e.toolbarIsActive]: k ? !1 : s.isActive
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__ */ w(
114
+ s.isActive ? !s.disableRichText && /* @__PURE__ */ B(
107
115
  "div",
108
116
  {
109
- className: a(e.iconToolbar, {
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: l,
117
- onMouseDown: l,
118
- onClick: () => _("bold"),
124
+ onTouchStart: a,
125
+ onMouseDown: a,
126
+ onClick: () => M("bold"),
119
127
  type: "button",
120
- className: a(e.toolbarItem, { [e.active]: K }),
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
- b,
135
+ g,
128
136
  {
129
137
  name: "bold",
130
138
  width: 24,
131
139
  height: 24,
132
- className: a(e.format, e.bold)
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: l,
141
- onMouseDown: l,
142
- onClick: () => _("italic"),
148
+ onTouchStart: a,
149
+ onMouseDown: a,
150
+ onClick: () => M("italic"),
143
151
  type: "button",
144
- className: a(e.toolbarItem, {
145
- [e.active]: P
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
- b,
160
+ g,
153
161
  {
154
162
  name: "italic",
155
163
  width: 24,
156
164
  height: 24,
157
- className: a(e.format, e.italic)
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: l,
166
- onMouseDown: l,
167
- onClick: () => _("underline"),
173
+ onTouchStart: a,
174
+ onMouseDown: a,
175
+ onClick: () => M("underline"),
168
176
  type: "button",
169
- className: a(e.toolbarItem, {
170
- [e.active]: F
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
- b,
185
+ g,
178
186
  {
179
187
  name: "underline",
180
188
  width: 24,
181
189
  height: 24,
182
- className: a(e.format, e.underline)
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: l,
191
- onMouseDown: l,
192
- onClick: () => H(),
198
+ onTouchStart: a,
199
+ onMouseDown: a,
200
+ onClick: () => z(),
193
201
  type: "button",
194
- className: a(e.toolbarItem, {
195
- [e.active]: h === "quote"
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
- b,
210
+ g,
203
211
  {
204
212
  name: "blockquote",
205
213
  width: 24,
206
214
  height: 24,
207
- className: a(e.format, e.quote)
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: l,
216
- onMouseDown: l,
217
- onClick: () => j(),
223
+ onTouchStart: a,
224
+ onMouseDown: a,
225
+ onClick: () => V(),
218
226
  type: "button",
219
- className: a(e.toolbarItem, {
220
- [e.active]: h === "ol"
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
- b,
235
+ g,
228
236
  {
229
237
  name: "orderedList",
230
238
  width: 24,
231
239
  height: 24,
232
- className: a(e.format, e.numberedList)
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: l,
241
- onMouseDown: l,
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
- b,
258
+ g,
251
259
  {
252
260
  name: "link",
253
261
  width: 20,
254
262
  height: 20,
255
- className: a(e.format, e.link)
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
- le,
272
+ re,
265
273
  {
266
274
  type: "button",
267
275
  "data-testid": "submit-button",
268
276
  handleClick: s.onSubmit,
269
- className: a(e.inputSubmitActionButton, e.submitAction),
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(b, { name: "send", width: 20, height: 20 })
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
- _e as ToolbarPlugin
290
+ Me as ToolbarPlugin
283
291
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.4.25",
3
+ "version": "0.4.26",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",