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