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