@logora/debate 0.4.25 → 0.4.27

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