@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 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";
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 u } from "../../../icons/icon/Icon.js";
13
- import { Button as le } from "../../../action/button/Button.js";
14
- const ye = (l) => {
15
- const r = ne(), D = 1, [n] = J(), O = oe(null), [h, I] = g("paragraph"), [se, P] = g(null), [B, R] = g(!1), [$, q] = g(!1), [K, F] = g(!1), S = l.hideSubmit && l.hideSourceAction && l.disableRichText, p = ie(() => {
16
- const t = N();
17
- if (_(t)) {
18
- const c = t.anchor.getNode(), s = c.getKey() === "root" ? c : c.getTopLevelElementOrThrow(), d = s.getKey();
19
- if (n.getElementByKey(d) !== null)
20
- if (P(d), k(s)) {
21
- const o = Y(c, z), f = o ? o.getTag() : s.getTag();
22
- I(f);
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 o = W(s) ? s.getTag() : s.getType();
25
- I(o);
24
+ const b = ee(c) ? c.getTag() : c.getType();
25
+ k(b);
26
26
  }
27
- R(t.hasFormat("bold")), q(t.hasFormat("italic")), F(t.hasFormat("underline"));
27
+ v(t.hasFormat("bold")), w(t.hasFormat("italic")), C(t.hasFormat("underline"));
28
28
  }
29
- }, [n]);
30
- ae(() => Z(
31
- n.registerUpdateListener(({ editorState: t }) => {
29
+ }, [r]);
30
+ le(() => oe(
31
+ r.registerUpdateListener(({ editorState: t }) => {
32
32
  t.read(() => {
33
- p();
33
+ y();
34
34
  });
35
35
  }),
36
- n.registerCommand(
37
- ee,
38
- () => (p(), !1),
39
- D
36
+ r.registerCommand(
37
+ ie,
38
+ () => (y(), !1),
39
+ q
40
40
  )
41
- ), [n, p]);
42
- const b = (t) => {
43
- t.pointerType !== "touch" && t.pointerType !== "pen" && t.preventDefault();
44
- }, x = () => {
41
+ ), [r, y]);
42
+ const a = (t) => {
43
+ t.preventDefault();
44
+ }, E = () => {
45
45
  setTimeout(() => {
46
- n.getEditorState().read(() => {
47
- p();
46
+ r.getEditorState().read(() => {
47
+ y();
48
48
  });
49
49
  }, 0);
50
- }, T = (t) => {
51
- n.dispatchCommand(te, t), n.focus();
52
- }, U = () => {
53
- n.update(() => {
54
- const t = N();
55
- if (!_(t))
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
- 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);
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 d = Array.from(s).reverse();
65
- for (const m of d) {
66
- const o = m.getParent();
67
- if (!k(o))
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 = 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);
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" ? n.dispatchCommand(G) : U(), x();
84
- }, H = () => {
85
- h !== "quote" ? n.update(() => {
86
- const t = N();
87
- if (_(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 s = t.anchor.getNode().getTopLevelElementOrThrow(), d = A();
90
- s.insertAfter(d), d.selectEnd();
97
+ const c = t.anchor.getNode().getTopLevelElementOrThrow(), u = K();
98
+ c.insertAfter(u), u.selectEnd();
91
99
  } else
92
- v(t, () => A());
93
- }) : n.update(() => {
94
- const t = N();
95
- _(t) && v(t, () => E());
96
- }), x();
100
+ O(t, () => K());
101
+ }) : r.update(() => {
102
+ const t = h();
103
+ p(t) && O(t, () => R());
104
+ }), E();
97
105
  };
98
- return S ? null : /* @__PURE__ */ L(
106
+ return A ? null : /* @__PURE__ */ B(
99
107
  "div",
100
108
  {
101
- className: a(e.toolbar, {
102
- [e.toolbarIsActive]: S ? !1 : l.isActive
109
+ className: n(e.toolbar, {
110
+ [e.toolbarIsActive]: A ? !1 : s.isActive
103
111
  }),
104
- ref: O,
112
+ ref: P,
105
113
  children: [
106
- l.isActive ? !l.disableRichText && /* @__PURE__ */ L(
114
+ s.isActive ? !s.disableRichText && /* @__PURE__ */ B(
107
115
  "div",
108
116
  {
109
- className: a(e.iconToolbar, {
110
- [e.shortBar]: l.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
- onPointerDown: b,
117
- onClick: () => T("bold"),
124
+ onTouchStart: a,
125
+ onMouseDown: a,
126
+ onClick: () => M("bold"),
118
127
  type: "button",
119
- className: a(e.toolbarItem, { [e.active]: B }),
128
+ className: n(e.toolbarItem, { [e.active]: F }),
120
129
  "data-testid": "format-bold",
121
- "aria-label": r.formatMessage({
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
- u,
135
+ g,
127
136
  {
128
137
  name: "bold",
129
138
  width: 24,
130
139
  height: 24,
131
- className: a(e.format, e.bold)
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
- onPointerDown: b,
140
- onClick: () => T("italic"),
148
+ onTouchStart: a,
149
+ onMouseDown: a,
150
+ onClick: () => M("italic"),
141
151
  type: "button",
142
- className: a(e.toolbarItem, {
143
- [e.active]: $
152
+ className: n(e.toolbarItem, {
153
+ [e.active]: j
144
154
  }),
145
- "aria-label": r.formatMessage({
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
- u,
160
+ g,
151
161
  {
152
162
  name: "italic",
153
163
  width: 24,
154
164
  height: 24,
155
- className: a(e.format, e.italic)
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
- onPointerDown: b,
164
- onClick: () => T("underline"),
173
+ onTouchStart: a,
174
+ onMouseDown: a,
175
+ onClick: () => M("underline"),
165
176
  type: "button",
166
- className: a(e.toolbarItem, {
167
- [e.active]: K
177
+ className: n(e.toolbarItem, {
178
+ [e.active]: H
168
179
  }),
169
- "aria-label": r.formatMessage({
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
- u,
185
+ g,
175
186
  {
176
187
  name: "underline",
177
188
  width: 24,
178
189
  height: 24,
179
- className: a(e.format, e.underline)
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
- onPointerDown: b,
188
- onClick: () => H(),
198
+ onTouchStart: a,
199
+ onMouseDown: a,
200
+ onClick: () => z(),
189
201
  type: "button",
190
- className: a(e.toolbarItem, {
191
- [e.active]: h === "quote"
202
+ className: n(e.toolbarItem, {
203
+ [e.active]: T === "quote"
192
204
  }),
193
- "aria-label": r.formatMessage({
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
- u,
210
+ g,
199
211
  {
200
212
  name: "blockquote",
201
213
  width: 24,
202
214
  height: 24,
203
- className: a(e.format, e.quote)
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
- onPointerDown: b,
212
- onClick: () => j(),
223
+ onTouchStart: a,
224
+ onMouseDown: a,
225
+ onClick: () => V(),
213
226
  type: "button",
214
- className: a(e.toolbarItem, {
215
- [e.active]: h === "ol"
227
+ className: n(e.toolbarItem, {
228
+ [e.active]: T === "ol"
216
229
  }),
217
- "aria-label": r.formatMessage({
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
- u,
235
+ g,
223
236
  {
224
237
  name: "orderedList",
225
238
  width: 24,
226
239
  height: 24,
227
- className: a(e.format, e.numberedList)
240
+ className: n(e.format, e.numberedList)
228
241
  }
229
242
  )
230
243
  }
231
244
  ),
232
- !l.hideSourceAction && /* @__PURE__ */ i(
245
+ !s.hideSourceAction && /* @__PURE__ */ i(
233
246
  "button",
234
247
  {
235
- onPointerDown: b,
236
- onClick: l.onAddSource,
248
+ onTouchStart: a,
249
+ onMouseDown: a,
250
+ onClick: s.onAddSource,
237
251
  type: "button",
238
252
  className: e.toolbarItem,
239
- "aria-label": r.formatMessage({
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
- u,
258
+ g,
245
259
  {
246
260
  name: "link",
247
261
  width: 20,
248
262
  height: 20,
249
- className: a(e.format, e.link)
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: l.hideSubmit ? null : /* @__PURE__ */ i(
258
- le,
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: l.onSubmit,
263
- className: a(e.inputSubmitActionButton, e.submitAction),
264
- "aria-label": r.formatMessage({
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(u, { name: "send", width: 20, height: 20 })
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
- ye as ToolbarPlugin
290
+ Me as ToolbarPlugin
277
291
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.4.24",
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",