@logora/debate 0.3.62 → 0.3.64

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,9 +1,9 @@
1
- import { jsxs as _, jsx as o } from "react/jsx-runtime";
1
+ import { jsxs as _, jsx as i } from "react/jsx-runtime";
2
2
  import $e from "@rooks/use-sessionstorage-state";
3
- import { useRef as qe, useState as c, useEffect as M, Suspense as De, lazy as We } from "react";
3
+ import { useRef as qe, useState as c, useEffect as v, Suspense as De, lazy as We } from "react";
4
4
  import { useIntl as Ye, FormattedMessage as me } from "react-intl";
5
5
  import { useLocation as ke } from "react-router";
6
- import I from "classnames";
6
+ import C from "classnames";
7
7
  import n from "./ArgumentInput.module.scss.js";
8
8
  import { useDataProvider as Re } from "../../data/data_provider/useDataProvider.js";
9
9
  import { useList as je } from "../../list/list_provider/useList.js";
@@ -20,95 +20,95 @@ import { Avatar as et } from "../../user/avatar/Avatar.js";
20
20
  import { AuthorBox as tt } from "../../user/author_box/AuthorBox.js";
21
21
  import { TextEditor as nt } from "../text_editor/TextEditor.js";
22
22
  import { Icon as at } from "../../icons/icon/Icon.js";
23
- const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ default: v.SideModal }))), Nt = ({
24
- argumentListId: v,
25
- avatarSize: ge = 48,
23
+ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ default: I.SideModal }))), xt = ({
24
+ argumentListId: I,
25
+ avatarSize: fe = 48,
26
26
  disabled: z = !1,
27
27
  positions: a = [],
28
28
  disabledPositions: S = [],
29
- groupId: A,
30
- groupName: fe,
29
+ groupId: M,
30
+ groupName: ge,
31
31
  groupType: O,
32
32
  hideSourceAction: he = !1,
33
- isReply: u = !1,
33
+ isReply: d = !1,
34
34
  onSubmit: J,
35
- parentId: F,
35
+ parentId: L,
36
36
  placeholder: pe,
37
- positionId: b,
37
+ positionId: w,
38
38
  focusOnInit: _e = !1,
39
- activeOnInit: P = !1,
39
+ activeOnInit: F = !1,
40
40
  userGuideUrl: K,
41
- hideUserGuideLink: Me = !1,
42
- hideCharCount: ve = !1,
43
- disableAutoActivate: Ae = !1
41
+ hideUserGuideLink: ve = !1,
42
+ hideCharCount: Me = !1,
43
+ disableAutoActivate: we = !1
44
44
  }) => {
45
- const r = Ye(), G = Re(), x = je(), h = ze(), {
45
+ const r = Ye(), G = Re(), y = je(), h = ze(), {
46
46
  focus: H,
47
- setFocus: N,
47
+ setFocus: x,
48
48
  setReset: be,
49
- inputContent: B,
49
+ inputContent: E,
50
50
  setInputContent: Q,
51
- setInputRichContent: Ce
52
- } = Oe(), { isLoggedIn: C, currentUser: d } = Je(), { errors: E, validate: V } = Ke(), { isMobile: m } = Ge(), we = ke(), X = qe(null), [U, $] = c([]), [q, D] = c(""), [Z, W] = c(null), [l, p] = c(null), [ee, te] = c(null), [ne, ae] = c(!1), [w, oe] = c(!1), [y, ie] = c({}), [g, Ie] = $e(
51
+ setInputRichContent: Ae
52
+ } = Oe(), { isLoggedIn: b, currentUser: u } = Je(), { errors: P, validate: B } = Ke(), { isMobile: m } = Ge(), Ce = ke(), X = qe(null), [V, U] = c([]), [$, q] = c(""), [Z, D] = c(null), [l, p] = c(null), [ee, te] = c(null), [ne, ae] = c(!1), [A, ie] = c(!1), [W, se] = c({}), [f, Ie] = $e(
53
53
  "userSide",
54
54
  {}
55
- ), [f, Se] = c(
56
- !C && h?.actions?.disableInputForVisitor
57
- ), Y = He(), { showModal: xe } = Qe(), { toast: k } = Xe() || {}, se = new URLSearchParams(
58
- typeof window < "u" ? window.location.search : we.search
55
+ ), [g, Se] = c(
56
+ !b && h?.actions?.disableInputForVisitor
57
+ ), Y = He(), { showModal: ye } = Qe(), { toast: k } = Xe() || {}, oe = new URLSearchParams(
58
+ typeof window < "u" ? window.location.search : Ce.search
59
59
  );
60
- M(() => {
60
+ v(() => {
61
61
  Se(
62
- !C && h?.actions?.disableInputForVisitor
62
+ !b && h?.actions?.disableInputForVisitor
63
63
  );
64
- }, [C, h]);
65
- const R = d?.role === "editor" || d?.role === "moderator", re = d?.moderation_status === "banned";
66
- M(() => {
64
+ }, [b, h]);
65
+ const R = u?.role === "editor" || u?.role === "moderator", re = u?.moderation_status === "banned";
66
+ v(() => {
67
67
  let e = null;
68
- typeof window < "u" && (e = se.get("positionId")), b && b != a[2]?.id && a?.find((t) => t.id === b) ? p(b) : e && e != a[2]?.id ? p(e) : g && g.groupId == A && g.positionId != a[2]?.id && p(g.positionId);
69
- }, [b]), M(() => {
70
- P && (j(), N(!0));
71
- }, [P]), M(() => {
68
+ typeof window < "u" && (e = oe.get("positionId")), w && w != a[2]?.id && a?.find((t) => t.id === w) ? p(w) : e && e != a[2]?.id ? p(e) : f && f.groupId == M && f.positionId != a[2]?.id && p(f.positionId);
69
+ }, [w]), v(() => {
70
+ F && (j(), x(!0));
71
+ }, [F]), v(() => {
72
72
  if (typeof window < "u") {
73
- const e = _e || se.get("initArgument");
74
- (e === !0 || e === "true") && (N(!0), Ee());
73
+ const e = _e || oe.get("initArgument");
74
+ (e === !0 || e === "true") && (x(!0), Be());
75
75
  }
76
- }, []), M(() => {
77
- H && (ue(), N(!1));
78
- }, [H]), M(() => {
79
- B?.id && (Ne(B), N(!0));
80
- }, [B]);
81
- const Ne = (e) => {
82
- ie(e), oe(!0), $(e.sources), D(e.content), W(e.rich_content), te(e.id), ue(), p(e.position?.id), JSON.parse(e.rich_content).hasOwnProperty("root") ? Ce(e.rich_content) : Q(e.content);
83
- }, ue = () => {
84
- X.current.scrollIntoView(!1);
76
+ }, []), v(() => {
77
+ H && (de(), x(!1));
78
+ }, [H]), v(() => {
79
+ E?.id && (xe(E), x(!0));
80
+ }, [E]);
81
+ const xe = (e) => {
82
+ se(e), ie(!0), U(e.sources), q(e.content), D(e.rich_content), te(e.id), de(), p(e.position?.id), JSON.parse(e.rich_content).hasOwnProperty("root") ? Ae(e.rich_content) : Q(e.content);
85
83
  }, de = () => {
86
- D(""), W(null), ie({}), te(null), $([]), be(!0), Q(null);
87
- }, ye = (e) => {
84
+ X.current.scrollIntoView(!1);
85
+ }, ue = () => {
86
+ q(""), D(null), se({}), te(null), U([]), be(!0), Q(null);
87
+ }, Ne = (e) => {
88
88
  p(e), ce(e);
89
89
  }, Te = () => {
90
- xe(
91
- /* @__PURE__ */ o(De, { fallback: null, children: /* @__PURE__ */ o(
92
- ot,
90
+ ye(
91
+ /* @__PURE__ */ i(De, { fallback: null, children: /* @__PURE__ */ i(
92
+ it,
93
93
  {
94
94
  modalTitle: r.formatMessage({
95
95
  id: "modal.side_modal.modal_title",
96
96
  defaultMessage: "Choose your side"
97
97
  }),
98
- onChooseSide: ye,
98
+ onChooseSide: Ne,
99
99
  positions: a,
100
- title: fe,
101
- disabledPositions: !u && S,
102
- isNeutral: g && g.groupId == A && g.positionId === a[2]?.id
100
+ title: ge,
101
+ disabledPositions: !d && S,
102
+ isNeutral: f && f.groupId == M && f.positionId === a[2]?.id
103
103
  }
104
104
  ) })
105
105
  );
106
106
  }, Le = () => {
107
- C ? ee ? Be() : !a || a?.length === 0 || !S?.find((e) => e?.id === l) && l || R && u ? ce(u && R && a[0]?.id) : Te() : Y({ loginAction: "argument" });
107
+ b ? ee ? Pe() : !a || a?.length === 0 || !S?.find((e) => e?.id === l) && l || R && d ? ce(d && R && a[0]?.id) : Te() : Y({ loginAction: "argument" });
108
108
  }, Fe = (e, t) => {
109
- f ? Y({ loginAction: "argument" }) : (D(e), W(t), V({ content: e }, [{ content: ["url", null] }]));
110
- }, Pe = (e) => {
111
- $(e);
109
+ g ? Y({ loginAction: "argument" }) : (q(e), D(t), B({ content: e }, [{ content: ["url", null] }]));
110
+ }, Ee = (e) => {
111
+ U(e);
112
112
  }, le = [
113
113
  { content: ["length", 3] },
114
114
  { content: ["required", null] },
@@ -116,22 +116,22 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
116
116
  ...!a || a?.length === 0 ? [] : [{ position_id: ["required", null] }]
117
117
  ], ce = (e) => {
118
118
  const t = e || l, s = {
119
- content: q,
119
+ content: $,
120
120
  rich_content: Z,
121
- group_id: A,
121
+ group_id: M,
122
122
  ...O && { group_type: O },
123
123
  ...t && { position_id: t },
124
- is_reply: !!F,
125
- message_id: F || null,
126
- source_ids: U?.map((i) => i.id)
124
+ is_reply: !!L,
125
+ message_id: L || null,
126
+ source_ids: V?.map((o) => o.id)
127
127
  };
128
- V(s, le) && (t && a && a.map((i) => i.id).includes(t) && Ie({
129
- groupId: A,
128
+ B(s, le) && (t && a && a.map((o) => o.id).includes(t) && Ie({
129
+ groupId: M,
130
130
  positionId: t
131
- }), de(), G.create("messages", s).then((i) => {
132
- if (i.data.success) {
133
- if (F)
134
- J(i.data.data.resource), k(
131
+ }), ue(), G.create("messages", s).then((o) => {
132
+ if (o.data.success) {
133
+ if (L)
134
+ J(o.data.data.resource), k(
135
135
  r.formatMessage({
136
136
  id: "alert.argument_create",
137
137
  defaultMessage: "Your contribution has been sent !"
@@ -145,12 +145,12 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
145
145
  }
146
146
  );
147
147
  else {
148
- const T = i.data.data.resource;
149
- let L = v;
150
- t && !m && (L = `argumentList${T.position.id}`), J?.(
151
- q,
148
+ const N = o.data.data.resource;
149
+ let T = I;
150
+ t && !m && (T = `argumentList${N.position.id}`), J?.(
151
+ $,
152
152
  a.find((Ue) => Ue.id === t) || null
153
- ), x.add(L, [T]), k(
153
+ ), y.add(T, [N]), k(
154
154
  r.formatMessage({
155
155
  id: "alert.argument_create",
156
156
  defaultMessage: "Your contribution has been sent !"
@@ -162,42 +162,45 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
162
162
  defaultMessage: "Up to 10 eloquence points"
163
163
  }),
164
164
  category: "ARGUMENT",
165
- contentKey: d.messages_count === 2 ? "alert.third_argument" : "alert.first_argument"
165
+ contentKey: u.messages_count === 2 ? "alert.third_argument" : "alert.first_argument"
166
166
  }
167
167
  );
168
168
  }
169
169
  typeof window < "u" && window.dispatchEvent(
170
170
  new CustomEvent("logora:user_content:created", {
171
171
  detail: {
172
- content: i.data.data?.resource
172
+ content: o.data.data?.resource
173
173
  }
174
174
  })
175
175
  );
176
176
  }
177
177
  }));
178
- }, Be = () => {
178
+ }, Pe = () => {
179
179
  const e = {
180
- content: q,
180
+ content: $,
181
181
  rich_content: Z,
182
- source_ids: U?.map((t) => t.id),
182
+ source_ids: V?.map((t) => t.id),
183
183
  ...l && { position_id: l }
184
184
  };
185
- V(e, le) && G.update("messages", ee, e).then((t) => {
185
+ B(e, le) && G.update("messages", ee, e).then((t) => {
186
186
  if (t.data.success) {
187
187
  const s = t.data.data.resource;
188
- console.log("[updateArgument] réponse API:", s), console.log("[updateArgument] editElement:", y), console.log("[updateArgument] argumentListId prop:", v);
189
- let i = v;
190
- if (s.is_reply ? i = `argument_${s.reply_to_id || y?.reply_to_id}_reply_list` : l && !m && (i = `argumentList${s.position?.id}`), console.log("[updateArgument] listId final:", i), y?.position?.id != s.position?.id && !m && !s.is_reply) {
191
- const T = `argumentList${y.position.id}`, L = `argumentList${s.position.id}`;
192
- x.remove(T, [s]), x.add(L, [s]);
188
+ let o = I;
189
+ if (s.is_reply ? o = `argument_${s.reply_to_id || W?.reply_to_id}_reply_list` : l && !m && (o = `argumentList${s.position?.id}`), W?.position?.id != s.position?.id && !m && !s.is_reply) {
190
+ const N = `argumentList${W.position.id}`, T = `argumentList${s.position.id}`;
191
+ y.remove(N, [s]), y.add(T, [s]);
193
192
  } else
194
- x.update(i, [s]);
193
+ y.update(o, [s]), s.is_reply && typeof window < "u" && window.dispatchEvent(
194
+ new CustomEvent("logora:reply:updated", {
195
+ detail: { reply: s }
196
+ })
197
+ );
195
198
  k(r.formatMessage({ id: "alert.argument_modify" }), {
196
199
  type: "success"
197
- }), de();
200
+ }), ue();
198
201
  }
199
202
  });
200
- }, Ee = () => {
203
+ }, Be = () => {
201
204
  if (!ne) {
202
205
  ae(!0);
203
206
  const e = setTimeout(() => {
@@ -206,7 +209,7 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
206
209
  return () => clearTimeout(e);
207
210
  }
208
211
  }, j = () => {
209
- f ? Y({ loginAction: "argument" }) : oe(!0);
212
+ g ? Y({ loginAction: "argument" }) : ie(!0);
210
213
  }, Ve = () => {
211
214
  const e = S.find(
212
215
  (t) => t.id === l
@@ -221,27 +224,27 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
221
224
  );
222
225
  };
223
226
  return /* @__PURE__ */ _("div", { className: n.inputContainer, children: [
224
- z && /* @__PURE__ */ o("div", { className: n.disabledInputMask, children: re ? r.formatMessage({
227
+ z && /* @__PURE__ */ i("div", { className: n.disabledInputMask, children: re ? r.formatMessage({
225
228
  id: "input.argument_input.user_banned",
226
229
  defaultMessage: "You are banned from the debate space."
227
230
  }) : r.formatMessage({
228
231
  id: "info.debate_is_inactive",
229
232
  defaultMessage: "Debate is closed"
230
233
  }) }),
231
- /* @__PURE__ */ o(
234
+ /* @__PURE__ */ i(
232
235
  "div",
233
236
  {
234
- className: I(n.argumentInput, {
237
+ className: C(n.argumentInput, {
235
238
  [n.flash]: ne,
236
- [n.replyInputContainer]: u
239
+ [n.replyInputContainer]: d
237
240
  }),
238
- children: /* @__PURE__ */ o("div", { "data-tid": "action_add_argument", ref: X, children: /* @__PURE__ */ _("div", { className: n.argumentInputBox, children: [
239
- a.length > 0 && C && (!u || !R) && /* @__PURE__ */ _("div", { className: n.userPosition, children: [
240
- /* @__PURE__ */ o("div", { children: r.formatMessage({
241
+ children: /* @__PURE__ */ i("div", { "data-tid": "action_add_argument", ref: X, children: /* @__PURE__ */ _("div", { className: n.argumentInputBox, children: [
242
+ a.length > 0 && b && (!d || !R) && /* @__PURE__ */ _("div", { className: n.userPosition, children: [
243
+ /* @__PURE__ */ i("div", { children: r.formatMessage({
241
244
  id: "input.position",
242
245
  defaultMessage: "Your position"
243
246
  }) }),
244
- /* @__PURE__ */ o(
247
+ /* @__PURE__ */ i(
245
248
  Ze,
246
249
  {
247
250
  activeLabel: l === a[0].id ? 0 : l === a[1].id ? 1 : null,
@@ -254,32 +257,32 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
254
257
  /* @__PURE__ */ _(
255
258
  "div",
256
259
  {
257
- className: I(n.argumentTextInputBox, {
260
+ className: C(n.argumentTextInputBox, {
258
261
  [n.argumentTextInputBoxisTablet]: !m,
259
- [n.replyEditorRow]: u
262
+ [n.replyEditorRow]: d
260
263
  }),
261
264
  children: [
262
- /* @__PURE__ */ o(
265
+ /* @__PURE__ */ i(
263
266
  "div",
264
267
  {
265
- className: I(n.argumentAuthorContainer, {
268
+ className: C(n.argumentAuthorContainer, {
266
269
  [n.argumentAuthorContainerMobile]: m,
267
- [n.argumentAuthorContainerActivated]: !m && w || u
270
+ [n.argumentAuthorContainerActivated]: !m && A || d
268
271
  }),
269
- children: !m && w || u ? /* @__PURE__ */ o(
272
+ children: !m && A || d ? /* @__PURE__ */ i(
270
273
  et,
271
274
  {
272
- avatarUrl: d.image_url,
273
- userName: d.full_name,
274
- size: ge
275
+ avatarUrl: u.image_url,
276
+ userName: u.full_name,
277
+ size: fe
275
278
  }
276
- ) : /* @__PURE__ */ o(
279
+ ) : /* @__PURE__ */ i(
277
280
  tt,
278
281
  {
279
- fullName: d?.full_name || r.formatMessage({ id: "default_author.full_name" }),
280
- avatarUrl: d?.image_url,
281
- points: d?.points || 0,
282
- slug: d?.hash_id
282
+ fullName: u?.full_name || r.formatMessage({ id: "default_author.full_name" }),
283
+ avatarUrl: u?.image_url,
284
+ points: u?.points || 0,
285
+ slug: u?.hash_id
283
286
  }
284
287
  )
285
288
  }
@@ -289,18 +292,18 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
289
292
  {
290
293
  onClick: j,
291
294
  "data-testid": "argument-input",
292
- className: I(n.textEditorBox, {
293
- [n.replyTextEditorBox]: u
295
+ className: C(n.textEditorBox, {
296
+ [n.replyTextEditorBox]: d
294
297
  }),
295
298
  children: [
296
- /* @__PURE__ */ o(
299
+ /* @__PURE__ */ i(
297
300
  nt,
298
301
  {
299
302
  handleChange: (e, t) => {
300
303
  Fe(e, t);
301
304
  },
302
305
  handleSourcesChange: (e) => {
303
- Pe(e);
306
+ Ee(e);
304
307
  },
305
308
  placeholder: pe,
306
309
  "aria-label": r.formatMessage({
@@ -308,34 +311,34 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
308
311
  defaultMessage: "Message input field"
309
312
  }),
310
313
  onSubmit: Le,
311
- sources: U,
312
- hideSourceAction: he || f,
313
- uid: `Argument${A}`,
314
+ sources: V,
315
+ hideSourceAction: he || g,
316
+ uid: `Argument${M}`,
314
317
  onActivation: j,
315
- showStylesControls: w,
316
- disabled: z || f || re,
317
- maxLength: f ? !1 : h?.actions?.argumentMaxLength,
318
- disableRichText: h?.actions?.disableRichText || f,
319
- shortBar: u,
320
- hideSubmit: f,
318
+ showStylesControls: A,
319
+ disabled: z || g || re,
320
+ maxLength: g ? !1 : h?.actions?.argumentMaxLength,
321
+ disableRichText: h?.actions?.disableRichText || g,
322
+ shortBar: d,
323
+ hideSubmit: g,
321
324
  allowedDomains: h?.allowed_sources,
322
- active: P,
323
- hideCharCount: ve,
324
- disableAutoActivate: Ae
325
+ active: F,
326
+ hideCharCount: Me,
327
+ disableAutoActivate: we
325
328
  }
326
329
  ),
327
- E?.content && /* @__PURE__ */ o("div", { className: n.argumentInputWarning, children: E && Object.values(E).map((e, t) => /* @__PURE__ */ o("div", { children: e }, t)) }),
328
- w && S?.find(
330
+ P?.content && /* @__PURE__ */ i("div", { className: n.argumentInputWarning, children: P && Object.values(P).map((e, t) => /* @__PURE__ */ i("div", { children: e }, t)) }),
331
+ A && S?.find(
329
332
  (e) => e.id === l
330
333
  ) && /* @__PURE__ */ _(
331
334
  "div",
332
335
  {
333
- className: I(
336
+ className: C(
334
337
  n.argumentInputWarning,
335
338
  n.disabledPositionWarning
336
339
  ),
337
340
  children: [
338
- /* @__PURE__ */ o(
341
+ /* @__PURE__ */ i(
339
342
  at,
340
343
  {
341
344
  name: "announcement",
@@ -344,24 +347,24 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
344
347
  width: 20
345
348
  }
346
349
  ),
347
- /* @__PURE__ */ o("div", { className: n.argumentInputWarningText, children: Ve() })
350
+ /* @__PURE__ */ i("div", { className: n.argumentInputWarningText, children: Ve() })
348
351
  ]
349
352
  }
350
353
  ),
351
- w && K && !Me && /* @__PURE__ */ o("div", { className: n.guideMessage, children: /* @__PURE__ */ o(
354
+ A && K && !ve && /* @__PURE__ */ i("div", { className: n.guideMessage, children: /* @__PURE__ */ i(
352
355
  me,
353
356
  {
354
357
  id: "alert.guide_message",
355
358
  defaultMessage: "Contributions must comply with our {userCharter}.",
356
359
  values: {
357
- userCharter: /* @__PURE__ */ o(
360
+ userCharter: /* @__PURE__ */ i(
358
361
  "a",
359
362
  {
360
363
  className: n.guideMessage,
361
364
  href: K,
362
365
  target: "_blank",
363
366
  rel: "noreferrer",
364
- children: /* @__PURE__ */ o(
367
+ children: /* @__PURE__ */ i(
365
368
  me,
366
369
  {
367
370
  id: "alert.user_charter",
@@ -385,5 +388,5 @@ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ def
385
388
  ] });
386
389
  };
387
390
  export {
388
- Nt as ArgumentInput
391
+ xt as ArgumentInput
389
392
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.3.62",
3
+ "version": "0.3.64",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",