@logora/debate 0.4.21 → 0.4.23

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