@logora/debate 0.3.61 → 0.3.63

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,77 +1,86 @@
1
- import { jsx as o, jsxs as l, Fragment as y } from "react/jsx-runtime";
2
- import B from "classnames";
3
- import { useState as _, useEffect as ae, useCallback as le, Suspense as ne, lazy as de } from "react";
4
- import { useIntl as ce } from "react-intl";
1
+ import { jsx as o, jsxs as l, Fragment as _ } from "react/jsx-runtime";
2
+ import D from "classnames";
3
+ import { useState as g, useEffect as P, useCallback as de, Suspense as ce, lazy as pe } from "react";
4
+ import { useIntl as ue } from "react-intl";
5
5
  import s from "./Argument.module.scss.js";
6
- import { ReplyFooter as pe } from "./ReplyFooter.js";
7
- import { useRichContent as me } from "./useRichContent.js";
8
- import { useAuth as ue } from "../../auth/use_auth/useAuth.js";
9
- import { useConfig as he } from "../../data/config_provider/useConfig.js";
10
- import { useTranslatedContent as D } from "../../translation/translated_content/useTranslatedContent.js";
11
- import { SourceListItem as fe } from "../../source/source_list_item/SourceListItem.js";
12
- import { HashScroll as ye } from "../../tools/hash_scroll/HashScroll.js";
13
- import { ContentHeader as _e } from "../../user_content/content_header/ContentHeader.js";
14
- import { Icon as E } from "../../icons/icon/Icon.js";
15
- import { ReadMore as ge } from "../../text/read_more/ReadMore.js";
16
- import { TranslationButton as be } from "../../translation/translation_button/TranslationButton.js";
17
- import { ContentFooter as Me } from "../../user_content/content_footer/ContentFooter.js";
18
- import { VoteButton as ve } from "../../vote/vote_button/VoteButton.js";
19
- import { VotePaginatedList as Ie } from "../../list/paginated_list/VotePaginatedList.js";
20
- import { UserContentSkeleton as Ce } from "../../skeleton/user_content_skeleton/UserContentSkeleton.js";
6
+ import { ReplyFooter as me } from "./ReplyFooter.js";
7
+ import { useRichContent as he } from "./useRichContent.js";
8
+ import { useAuth as fe } from "../../auth/use_auth/useAuth.js";
9
+ import { useConfig as ye } from "../../data/config_provider/useConfig.js";
10
+ import { useTranslatedContent as F } from "../../translation/translated_content/useTranslatedContent.js";
11
+ import { SourceListItem as _e } from "../../source/source_list_item/SourceListItem.js";
12
+ import { HashScroll as ge } from "../../tools/hash_scroll/HashScroll.js";
13
+ import { ContentHeader as be } from "../../user_content/content_header/ContentHeader.js";
14
+ import { Icon as j } from "../../icons/icon/Icon.js";
15
+ import { ReadMore as Me } from "../../text/read_more/ReadMore.js";
16
+ import { TranslationButton as ve } from "../../translation/translation_button/TranslationButton.js";
17
+ import { ContentFooter as Ie } from "../../user_content/content_footer/ContentFooter.js";
18
+ import { VoteButton as Ce } from "../../vote/vote_button/VoteButton.js";
19
+ import { VotePaginatedList as Re } from "../../list/paginated_list/VotePaginatedList.js";
20
+ import { UserContentSkeleton as we } from "../../skeleton/user_content_skeleton/UserContentSkeleton.js";
21
21
  import { Button as Se } from "../../action/button/Button.js";
22
- const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({ default: e.ArgumentInput }))), P = (e) => e?.replace(/ /g, " "), Te = ({
22
+ const Te = pe(() => import("../../input/argument_input/index.js").then((e) => ({ default: e.ArgumentInput }))), G = (e) => e?.replace(/ /g, " "), Ne = ({
23
23
  argument: e,
24
- argumentReplies: n,
25
- nestingLevel: g = 0,
26
- maxNestingLevel: S = 2,
27
- groupType: R,
24
+ argumentReplies: d,
25
+ nestingLevel: b = 0,
26
+ maxNestingLevel: w = 2,
27
+ groupType: S,
28
28
  groupName: T,
29
- positions: b = [],
30
- disableLinks: F = !1,
29
+ positions: M = [],
30
+ disableLinks: H = !1,
31
31
  parentArgument: c,
32
- flashParent: j,
33
- expandable: G,
34
- disabled: M = !1,
32
+ flashParent: V,
33
+ expandable: z,
34
+ disabled: v = !1,
35
35
  hideFooter: N = !1,
36
- hideReplies: w,
37
- vote: H,
38
- fixedContentHeight: V = !1,
39
- enableEdition: z = !0,
40
- enableDeletion: O = !0,
41
- deleteListId: Y,
42
- showModerationFeedback: q,
43
- lineCount: J = 5,
44
- replyRedirectUrl: K,
45
- hideContent: Q = !1
36
+ hideReplies: A,
37
+ vote: O,
38
+ fixedContentHeight: Y = !1,
39
+ enableEdition: q = !0,
40
+ enableDeletion: J = !0,
41
+ deleteListId: K,
42
+ showModerationFeedback: Q,
43
+ lineCount: W = 5,
44
+ replyRedirectUrl: X,
45
+ hideContent: Z = !1
46
46
  }) => {
47
- const i = ce(), { isLoggedIn: W, currentUser: p } = ue(), A = p?.moderation_status === "banned", r = he(), [m, v] = _(!1), [X, x] = _(!1), [Z, ee] = _(!1), L = me(e), [u, h] = _(), f = D(
47
+ const i = ue(), { isLoggedIn: ee, currentUser: p } = fe(), x = p?.moderation_status === "banned", r = ye(), [u, I] = g(!1), [te, L] = g(!1), [oe, se] = g(!1), U = he(e), [m, h] = g(), f = F(
48
48
  e.content,
49
49
  e.language,
50
50
  "content",
51
51
  e.translation_entries
52
- ), te = D(
52
+ ), re = F(
53
53
  e.position?.name,
54
54
  e.position?.language,
55
55
  "name",
56
56
  e.position?.translation_entries
57
- ), I = `argument_${e.id}`, C = e.position && b?.map((t) => t.id).indexOf(e.position.id) + 1;
58
- ae(() => {
59
- n !== void 0 && ie();
60
- }, [n]);
61
- const oe = (t) => {
62
- if (I === t) {
63
- const d = document.getElementById(t);
64
- d && d.scrollIntoView({ behavior: "smooth" }), x(!0);
57
+ ), C = `argument_${e.id}`, R = e.position && M?.map((t) => t.id).indexOf(e.position.id) + 1;
58
+ P(() => {
59
+ d !== void 0 && ne();
60
+ }, [d]), P(() => {
61
+ if (typeof window > "u") return;
62
+ const t = (a) => {
63
+ const n = a.detail?.reply;
64
+ !n || n.reply_to_id !== e.id || h((y) => !y || y.length === 0 ? y : y.map((E) => E.id === n.id ? n : E));
65
+ };
66
+ return window.addEventListener("logora:reply:updated", t), () => {
67
+ window.removeEventListener("logora:reply:updated", t);
68
+ };
69
+ }, [e.id]);
70
+ const ie = (t) => {
71
+ if (C === t) {
72
+ const n = document.getElementById(t);
73
+ n && n.scrollIntoView({ behavior: "smooth" }), L(!0);
65
74
  }
66
- }, U = () => {
67
- ee((t) => !t);
68
75
  }, k = () => {
69
- v((t) => !t), h([]);
70
- }, se = (t) => {
71
- if (!u?.find((a) => a.id === t.id))
76
+ se((t) => !t);
77
+ }, $ = () => {
78
+ I((t) => !t), h([]);
79
+ }, ae = (t) => {
80
+ if (!m?.find((a) => a.id === t.id))
72
81
  return t;
73
- }, re = le((t, a) => /* @__PURE__ */ o(
74
- fe,
82
+ }, le = de((t, a) => /* @__PURE__ */ o(
83
+ _e,
75
84
  {
76
85
  publisher: t.publisher,
77
86
  url: t.source_url,
@@ -79,54 +88,54 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
79
88
  index: a
80
89
  },
81
90
  a
82
- ), []), ie = () => {
83
- if (n && Array.isArray(n)) {
84
- const t = n.filter(
91
+ ), []), ne = () => {
92
+ if (d && Array.isArray(d)) {
93
+ const t = d.filter(
85
94
  (a) => a.reply_to_id === e.id
86
95
  );
87
- t.length > 0 && (h(t), v(!0));
96
+ t.length > 0 && (h(t), I(!0));
88
97
  }
89
- }, $ = (t = null) => /* @__PURE__ */ o(
90
- Ne,
98
+ }, B = (t = null) => /* @__PURE__ */ o(
99
+ Ae,
91
100
  {
92
101
  ...t ? { argument: t } : {},
93
- nestingLevel: g + 1,
94
- maxNestingLevel: S,
95
- disabled: M,
102
+ nestingLevel: b + 1,
103
+ maxNestingLevel: w,
104
+ disabled: v,
96
105
  groupName: T,
97
- groupType: R,
98
- positions: b,
99
- argumentReplies: n,
106
+ groupType: S,
107
+ positions: M,
108
+ argumentReplies: d,
100
109
  parentArgument: e,
101
- flashParent: (a) => oe(`argument_${a}`)
110
+ flashParent: (a) => ie(`argument_${a}`)
102
111
  }
103
112
  );
104
- return /* @__PURE__ */ l(ye, { elementId: I, onScroll: () => x(!0), children: [
113
+ return /* @__PURE__ */ l(ge, { elementId: C, onScroll: () => L(!0), children: [
105
114
  /* @__PURE__ */ l(
106
115
  "div",
107
116
  {
108
- className: B(
117
+ className: D(
109
118
  s.argument,
110
119
  {
111
- [s.flash]: X,
120
+ [s.flash]: te,
112
121
  [s.argumentReply]: e.is_reply === !0
113
122
  },
114
- s[`level-${g}`],
115
- s[`position-${!(e.author.role === "editor" || e.author.role === "moderator") && C}`]
123
+ s[`level-${b}`],
124
+ s[`position-${!(e.author.role === "editor" || e.author.role === "moderator") && R}`]
116
125
  ),
117
- id: I,
126
+ id: C,
118
127
  children: [
119
128
  /* @__PURE__ */ o(
120
- _e,
129
+ be,
121
130
  {
122
131
  selectedContent: e.is_selected,
123
132
  author: e.author,
124
- tag: (e.author.role === "editor" || e.author.role === "moderator") && e.is_reply ? null : te.translatedContent,
133
+ tag: (e.author.role === "editor" || e.author.role === "moderator") && e.is_reply ? null : re.translatedContent,
125
134
  date: e.created_at,
126
- tagClassName: s[`headerPosition-${C}`],
127
- disableLinks: F,
135
+ tagClassName: s[`headerPosition-${R}`],
136
+ disableLinks: H,
128
137
  isDeleted: e.is_deleted,
129
- showModerationFeedback: q ?? (e.status === "rejected" && r.moderation?.showFeedback === !0),
138
+ showModerationFeedback: Q ?? (e.status === "rejected" && r.moderation?.showFeedback === !0),
130
139
  moderationReason: e.moderation_entry?.moderation_reason,
131
140
  moderationNotes: e.moderation_entry?.moderator_notes,
132
141
  moderationPolicyUrl: r.provider?.userGuideUrl
@@ -135,22 +144,22 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
135
144
  e.is_deleted ? /* @__PURE__ */ o("div", { className: s.argumentDeletedBody, children: i.formatMessage({
136
145
  id: "info.deleted_by_user",
137
146
  defaultMessage: "Content deleted by the user"
138
- }) }) : Q ? /* @__PURE__ */ o("div", { className: s.argumentDeletedBody, children: i.formatMessage({
147
+ }) }) : Z ? /* @__PURE__ */ o("div", { className: s.argumentDeletedBody, children: i.formatMessage({
139
148
  id: "argument.argument.content_deleted",
140
149
  defaultMessage: "This content has been removed."
141
- }) }) : /* @__PURE__ */ l(y, { children: [
150
+ }) }) : /* @__PURE__ */ l(_, { children: [
142
151
  /* @__PURE__ */ l(
143
152
  "div",
144
153
  {
145
- className: B(s.argumentBody, {
146
- [s.fixedHeight]: r?.layout?.showAllArgumentInEmbed !== !0 ? V : !1
154
+ className: D(s.argumentBody, {
155
+ [s.fixedHeight]: r?.layout?.showAllArgumentInEmbed !== !0 ? Y : !1
147
156
  }),
148
157
  children: [
149
158
  e.is_reply && c && /* @__PURE__ */ l(
150
159
  "div",
151
160
  {
152
161
  className: s.replyTo,
153
- onClick: () => j(c.id),
162
+ onClick: () => V(c.id),
154
163
  children: [
155
164
  i.formatMessage({
156
165
  id: "info.replying_to",
@@ -161,35 +170,35 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
161
170
  id: "info.deleted",
162
171
  defaultMessage: "Deleted"
163
172
  }) : c.author.full_name,
164
- /* @__PURE__ */ o(E, { name: "chat", height: 16 })
173
+ /* @__PURE__ */ o(j, { name: "chat", height: 16 })
165
174
  ] })
166
175
  ]
167
176
  }
168
177
  ),
169
178
  /* @__PURE__ */ o(
170
- ge,
179
+ Me,
171
180
  {
172
- content: /* @__PURE__ */ l(y, { children: [
181
+ content: /* @__PURE__ */ l(_, { children: [
173
182
  e.is_edited && /* @__PURE__ */ o("div", { className: s.edited, children: i.formatMessage({
174
183
  id: "argument.argument.updated",
175
184
  defaultMessage: "Updated argument"
176
185
  }) }),
177
- L && !f.isTranslated ? /* @__PURE__ */ o(
186
+ U && !f.isTranslated ? /* @__PURE__ */ o(
178
187
  "div",
179
188
  {
180
189
  className: s.argumentContent,
181
- dangerouslySetInnerHTML: { __html: P(L) }
190
+ dangerouslySetInnerHTML: { __html: G(U) }
182
191
  }
183
- ) : /* @__PURE__ */ o("div", { className: s.argumentContent, children: P(f.translatedContent) }),
192
+ ) : /* @__PURE__ */ o("div", { className: s.argumentContent, children: G(f.translatedContent) }),
184
193
  f.isTranslated && /* @__PURE__ */ o(
185
- be,
194
+ ve,
186
195
  {
187
196
  language: e.language,
188
197
  callback: () => f.toggleContent()
189
198
  }
190
199
  )
191
200
  ] }),
192
- lineCount: r?.layout?.showAllArgumentInEmbed !== !0 ? J : void 0,
201
+ lineCount: r?.layout?.showAllArgumentInEmbed !== !0 ? W : void 0,
193
202
  readMoreText: i.formatMessage({
194
203
  id: "action.read_more",
195
204
  defaultMessage: "Read more"
@@ -198,27 +207,27 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
198
207
  id: "action.read_less",
199
208
  defaultMessage: "Read less"
200
209
  }),
201
- expandable: r?.layout?.showAllArgumentInEmbed !== !0 ? G : !1,
210
+ expandable: r?.layout?.showAllArgumentInEmbed !== !0 ? z : !1,
202
211
  readMoreClassName: e.is_reply ? s.replyStyle : s.argumentStyle
203
212
  }
204
213
  )
205
214
  ]
206
215
  }
207
216
  ),
208
- e.sources?.length > 0 && /* @__PURE__ */ o("div", { className: s.argumentSourcesList, children: e.sources.map(re) })
217
+ e.sources?.length > 0 && /* @__PURE__ */ o("div", { className: s.argumentSourcesList, children: e.sources.map(le) })
209
218
  ] }),
210
219
  !N && !e.is_deleted && /* @__PURE__ */ o(
211
- Me,
220
+ Ie,
212
221
  {
213
222
  resource: e,
214
- disabled: M || e.status === "rejected" || !W && r?.actions?.disableInputForVisitor === !0 || A,
223
+ disabled: v || e.status === "rejected" || !ee && r?.actions?.disableInputForVisitor === !0 || x,
215
224
  reportType: "Message",
216
225
  softDelete: r.actions?.softDelete,
217
226
  deleteType: "messages",
218
- deleteListId: Y,
219
- enableReply: g <= S || p.role === "editor" || p.role === "moderator",
220
- handleReplyTo: U,
221
- replyRedirectUrl: K,
227
+ deleteListId: K,
228
+ enableReply: b <= w || p.role === "editor" || p.role === "moderator",
229
+ handleReplyTo: k,
230
+ replyRedirectUrl: X,
222
231
  shareUrl: `https://app.logora.fr/share/a/${e.id}`,
223
232
  shareTitle: i.formatMessage({
224
233
  id: "share.argument.title",
@@ -233,54 +242,49 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
233
242
  showShareText: !0,
234
243
  showShareButton: r?.actions?.hideShareButton !== !0,
235
244
  enableReport: !(e.score === 100 && e.manual_score),
236
- enableEdition: z,
237
- enableDeletion: O,
245
+ enableEdition: q,
246
+ enableDeletion: J,
238
247
  children: /* @__PURE__ */ o(
239
- ve,
248
+ Ce,
240
249
  {
241
250
  voteableType: "Message",
242
251
  voteableId: e.id,
243
252
  totalUpvote: e.upvotes,
244
253
  totalDownvote: 0,
245
- activeClassName: s[`voteButtonPosition-${C}`],
246
- disabled: e.status === "rejected" || p?.id === e?.author?.id || A
254
+ activeClassName: s[`voteButtonPosition-${R}`],
255
+ disabled: e.status === "rejected" || p?.id === e?.author?.id || x
247
256
  }
248
257
  )
249
258
  }
250
259
  ),
251
- !N && !w && /* @__PURE__ */ o(
252
- pe,
260
+ !N && !A && /* @__PURE__ */ o(
261
+ me,
253
262
  {
254
263
  numberReplies: e.number_replies,
255
264
  repliesAuthors: e.replies_authors,
256
- expandReplies: m,
257
- onToggleReplies: k,
265
+ expandReplies: u,
266
+ onToggleReplies: $,
258
267
  isReply: e.is_reply
259
268
  }
260
269
  )
261
270
  ]
262
271
  }
263
272
  ),
264
- !w && /* @__PURE__ */ l(y, { children: [
265
- Z && /* @__PURE__ */ o(ne, { fallback: null, children: /* @__PURE__ */ o(
266
- Re,
273
+ !A && /* @__PURE__ */ l(_, { children: [
274
+ oe && /* @__PURE__ */ o(ce, { fallback: null, children: /* @__PURE__ */ o(
275
+ Te,
267
276
  {
268
277
  groupId: e.group_id,
269
- groupType: R,
278
+ groupType: S,
270
279
  groupName: T,
271
- positions: b,
280
+ positions: M,
272
281
  parentId: e.id,
273
- positionId: H?.position_id,
274
- disabled: M,
282
+ positionId: O?.position_id,
283
+ disabled: v,
275
284
  hideSourceAction: r?.actions?.disableUserSources || !1,
276
285
  argumentListId: `argument_${e.id}_reply_list`,
277
286
  onSubmit: (t) => {
278
- U(), h([t]), v(!0);
279
- },
280
- onUpdate: (t) => {
281
- h(
282
- (a) => a.map((d) => d.id === t.id ? t : d)
283
- );
287
+ k(), h([t]), I(!0);
284
288
  },
285
289
  isReply: !0,
286
290
  avatarSize: 40,
@@ -293,13 +297,13 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
293
297
  },
294
298
  `Reply${e.id}`
295
299
  ) }),
296
- u?.length > 0 && m && /* @__PURE__ */ o("div", { className: s.repliesList, children: u.map((t) => $(t)) }),
297
- m && /* @__PURE__ */ o("div", { className: s.repliesList, children: /* @__PURE__ */ o(
298
- Ie,
300
+ m?.length > 0 && u && /* @__PURE__ */ o("div", { className: s.repliesList, children: m.map((t) => B(t)) }),
301
+ u && /* @__PURE__ */ o("div", { className: s.repliesList, children: /* @__PURE__ */ o(
302
+ Re,
299
303
  {
300
304
  voteableType: "Message",
301
305
  currentListId: `argument_${e.id}_reply_list`,
302
- loadingComponent: /* @__PURE__ */ o(Ce, {}),
306
+ loadingComponent: /* @__PURE__ */ o(we, {}),
303
307
  resource: "messages",
304
308
  sort: "+created_at",
305
309
  filters: {
@@ -310,17 +314,17 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
310
314
  perPage: 5,
311
315
  display: "column",
312
316
  resourcePropName: "argument",
313
- emptyListComponent: /* @__PURE__ */ o(y, {}),
314
- transformData: (t) => se(t),
315
- children: $(e)
317
+ emptyListComponent: /* @__PURE__ */ o(_, {}),
318
+ transformData: (t) => ae(t),
319
+ children: B(e)
316
320
  }
317
321
  ) }),
318
- u?.length > 0 && !m && /* @__PURE__ */ o("div", { className: s.repliesList, children: e.number_replies > 1 && /* @__PURE__ */ o("div", { className: s.readMoreLink, children: /* @__PURE__ */ o(
322
+ m?.length > 0 && !u && /* @__PURE__ */ o("div", { className: s.repliesList, children: e.number_replies > 1 && /* @__PURE__ */ o("div", { className: s.readMoreLink, children: /* @__PURE__ */ o(
319
323
  Se,
320
324
  {
321
325
  role: "link",
322
- rightIcon: /* @__PURE__ */ o(E, { name: "lightArrow", height: 10, width: 10 }),
323
- handleClick: k,
326
+ rightIcon: /* @__PURE__ */ o(j, { name: "lightArrow", height: 10, width: 10 }),
327
+ handleClick: $,
324
328
  children: i.formatMessage({
325
329
  id: "argument.argument.see_more",
326
330
  defaultMessage: "See more"
@@ -329,8 +333,8 @@ const Re = de(() => import("../../input/argument_input/index.js").then((e) => ({
329
333
  ) }) })
330
334
  ] })
331
335
  ] });
332
- }, Ne = Te;
336
+ }, Ae = Ne;
333
337
  export {
334
- Te as Argument,
335
- Ne as ArgumentContainer
338
+ Ne as Argument,
339
+ Ae as ArgumentContainer
336
340
  };
@@ -1,138 +1,137 @@
1
1
  import { jsxs as _, jsx as i } from "react/jsx-runtime";
2
- import De from "@rooks/use-sessionstorage-state";
3
- import { useRef as Ue, useState as c, useEffect as M, Suspense as We, lazy as Ye } from "react";
4
- import { useIntl as ke, FormattedMessage as ge } from "react-intl";
5
- import { useLocation as Re } from "react-router";
6
- import I from "classnames";
2
+ import $e from "@rooks/use-sessionstorage-state";
3
+ import { useRef as qe, useState as c, useEffect as v, Suspense as De, lazy as We } from "react";
4
+ import { useIntl as Ye, FormattedMessage as me } from "react-intl";
5
+ import { useLocation as ke } from "react-router";
6
+ import C from "classnames";
7
7
  import n from "./ArgumentInput.module.scss.js";
8
- import { useDataProvider as je } from "../../data/data_provider/useDataProvider.js";
9
- import { useList as ze } from "../../list/list_provider/useList.js";
10
- import { useConfig as Oe } from "../../data/config_provider/useConfig.js";
11
- import { useInput as Je } from "../input_provider/useInput.js";
12
- import { useAuth as Ke } from "../../auth/use_auth/useAuth.js";
13
- import { useFormValidation as Ge } from "../../forms/use_form_validation/useFormValidation.js";
14
- import { useResponsive as He } from "../../hooks/use_responsive/useResponsive.js";
15
- import { useAuthRequired as Qe } from "../../hooks/use_auth_required/useAuthRequired.js";
16
- import { useModal as Xe } from "../../dialog/modal/useModal.js";
17
- import { useToast as Ze } from "../../dialog/toast_provider/useToast.js";
18
- import { TogglePosition as et } from "../toggle_position/TogglePosition.js";
19
- import { Avatar as tt } from "../../user/avatar/Avatar.js";
20
- import { AuthorBox as nt } from "../../user/author_box/AuthorBox.js";
21
- import { TextEditor as at } from "../text_editor/TextEditor.js";
22
- import { Icon as it } from "../../icons/icon/Icon.js";
23
- const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ default: v.SideModal }))), yt = ({
24
- argumentListId: v,
8
+ import { useDataProvider as Re } from "../../data/data_provider/useDataProvider.js";
9
+ import { useList as je } from "../../list/list_provider/useList.js";
10
+ import { useConfig as ze } from "../../data/config_provider/useConfig.js";
11
+ import { useInput as Oe } from "../input_provider/useInput.js";
12
+ import { useAuth as Je } from "../../auth/use_auth/useAuth.js";
13
+ import { useFormValidation as Ke } from "../../forms/use_form_validation/useFormValidation.js";
14
+ import { useResponsive as Ge } from "../../hooks/use_responsive/useResponsive.js";
15
+ import { useAuthRequired as He } from "../../hooks/use_auth_required/useAuthRequired.js";
16
+ import { useModal as Qe } from "../../dialog/modal/useModal.js";
17
+ import { useToast as Xe } from "../../dialog/toast_provider/useToast.js";
18
+ import { TogglePosition as Ze } from "../toggle_position/TogglePosition.js";
19
+ import { Avatar as et } from "../../user/avatar/Avatar.js";
20
+ import { AuthorBox as tt } from "../../user/author_box/AuthorBox.js";
21
+ import { TextEditor as nt } from "../text_editor/TextEditor.js";
22
+ import { Icon as at } from "../../icons/icon/Icon.js";
23
+ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ default: I.SideModal }))), xt = ({
24
+ argumentListId: I,
25
25
  avatarSize: fe = 48,
26
26
  disabled: z = !1,
27
27
  positions: a = [],
28
28
  disabledPositions: S = [],
29
- groupId: A,
30
- groupName: he,
29
+ groupId: M,
30
+ groupName: ge,
31
31
  groupType: O,
32
- hideSourceAction: pe = !1,
33
- isReply: u = !1,
32
+ hideSourceAction: he = !1,
33
+ isReply: d = !1,
34
34
  onSubmit: J,
35
- onUpdate: K,
36
- parentId: F,
37
- placeholder: _e,
38
- positionId: b,
39
- focusOnInit: Me = !1,
40
- activeOnInit: P = !1,
41
- userGuideUrl: G,
35
+ parentId: L,
36
+ placeholder: pe,
37
+ positionId: w,
38
+ focusOnInit: _e = !1,
39
+ activeOnInit: F = !1,
40
+ userGuideUrl: K,
42
41
  hideUserGuideLink: ve = !1,
43
- hideCharCount: Ae = !1,
44
- disableAutoActivate: be = !1
42
+ hideCharCount: Me = !1,
43
+ disableAutoActivate: we = !1
45
44
  }) => {
46
- const r = ke(), H = je(), x = ze(), h = Oe(), {
47
- focus: Q,
48
- setFocus: N,
49
- setReset: Ce,
50
- inputContent: B,
51
- setInputContent: X,
52
- setInputRichContent: we
53
- } = Je(), { isLoggedIn: C, currentUser: d } = Ke(), { errors: E, validate: V } = Ge(), { isMobile: m } = He(), Ie = Re(), Z = Ue(null), [$, q] = c([]), [D, U] = c(""), [ee, W] = c(null), [l, p] = c(null), [te, ne] = c(null), [ae, ie] = c(!1), [w, oe] = c(!1), [y, se] = c({}), [g, Se] = De(
45
+ const r = Ye(), G = Re(), y = je(), h = ze(), {
46
+ focus: H,
47
+ setFocus: x,
48
+ setReset: be,
49
+ inputContent: E,
50
+ setInputContent: Q,
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(
54
53
  "userSide",
55
54
  {}
56
- ), [f, xe] = c(
57
- !C && h?.actions?.disableInputForVisitor
58
- ), Y = Qe(), { showModal: Ne } = Xe(), { toast: k } = Ze() || {}, re = new URLSearchParams(
59
- typeof window < "u" ? window.location.search : Ie.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
60
59
  );
61
- M(() => {
62
- xe(
63
- !C && h?.actions?.disableInputForVisitor
60
+ v(() => {
61
+ Se(
62
+ !b && h?.actions?.disableInputForVisitor
64
63
  );
65
- }, [C, h]);
66
- const R = d?.role === "editor" || d?.role === "moderator", ue = d?.moderation_status === "banned";
67
- M(() => {
64
+ }, [b, h]);
65
+ const R = u?.role === "editor" || u?.role === "moderator", re = u?.moderation_status === "banned";
66
+ v(() => {
68
67
  let e = null;
69
- typeof window < "u" && (e = re.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);
70
- }, [b]), M(() => {
71
- P && (j(), N(!0));
72
- }, [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(() => {
73
72
  if (typeof window < "u") {
74
- const e = Me || re.get("initArgument");
75
- (e === !0 || e === "true") && (N(!0), Ve());
73
+ const e = _e || oe.get("initArgument");
74
+ (e === !0 || e === "true") && (x(!0), Be());
76
75
  }
77
- }, []), M(() => {
78
- Q && (de(), N(!1));
79
- }, [Q]), M(() => {
80
- B?.id && (ye(B), N(!0));
81
- }, [B]);
82
- const ye = (e) => {
83
- se(e), oe(!0), q(e.sources), U(e.content), W(e.rich_content), ne(e.id), de(), p(e.position?.id), JSON.parse(e.rich_content).hasOwnProperty("root") ? we(e.rich_content) : X(e.content);
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);
84
83
  }, de = () => {
85
- Z.current.scrollIntoView(!1);
86
- }, le = () => {
87
- U(""), W(null), se({}), ne(null), q([]), Ce(!0), X(null);
88
- }, Te = (e) => {
89
- p(e), me(e);
90
- }, Le = () => {
91
- Ne(
92
- /* @__PURE__ */ i(We, { fallback: null, children: /* @__PURE__ */ i(
93
- ot,
84
+ X.current.scrollIntoView(!1);
85
+ }, ue = () => {
86
+ q(""), D(null), se({}), te(null), U([]), be(!0), Q(null);
87
+ }, Ne = (e) => {
88
+ p(e), ce(e);
89
+ }, Te = () => {
90
+ ye(
91
+ /* @__PURE__ */ i(De, { fallback: null, children: /* @__PURE__ */ i(
92
+ it,
94
93
  {
95
94
  modalTitle: r.formatMessage({
96
95
  id: "modal.side_modal.modal_title",
97
96
  defaultMessage: "Choose your side"
98
97
  }),
99
- onChooseSide: Te,
98
+ onChooseSide: Ne,
100
99
  positions: a,
101
- title: he,
102
- disabledPositions: !u && S,
103
- 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
104
103
  }
105
104
  ) })
106
105
  );
107
- }, Fe = () => {
108
- C ? te ? Ee() : !a || a?.length === 0 || !S?.find((e) => e?.id === l) && l || R && u ? me(u && R && a[0]?.id) : Le() : Y({ loginAction: "argument" });
109
- }, Pe = (e, t) => {
110
- f ? Y({ loginAction: "argument" }) : (U(e), W(t), V({ content: e }, [{ content: ["url", null] }]));
111
- }, Be = (e) => {
112
- q(e);
113
- }, ce = [
106
+ }, Le = () => {
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
+ }, Fe = (e, t) => {
109
+ g ? Y({ loginAction: "argument" }) : (q(e), D(t), B({ content: e }, [{ content: ["url", null] }]));
110
+ }, Ee = (e) => {
111
+ U(e);
112
+ }, le = [
114
113
  { content: ["length", 3] },
115
114
  { content: ["required", null] },
116
115
  { content: ["url", null] },
117
116
  ...!a || a?.length === 0 ? [] : [{ position_id: ["required", null] }]
118
- ], me = (e) => {
119
- const t = e || l, o = {
120
- content: D,
121
- rich_content: ee,
122
- group_id: A,
117
+ ], ce = (e) => {
118
+ const t = e || l, s = {
119
+ content: $,
120
+ rich_content: Z,
121
+ group_id: M,
123
122
  ...O && { group_type: O },
124
123
  ...t && { position_id: t },
125
- is_reply: !!F,
126
- message_id: F || null,
127
- source_ids: $?.map((s) => s.id)
124
+ is_reply: !!L,
125
+ message_id: L || null,
126
+ source_ids: V?.map((o) => o.id)
128
127
  };
129
- V(o, ce) && (t && a && a.map((s) => s.id).includes(t) && Se({
130
- groupId: A,
128
+ B(s, le) && (t && a && a.map((o) => o.id).includes(t) && Ie({
129
+ groupId: M,
131
130
  positionId: t
132
- }), le(), H.create("messages", o).then((s) => {
133
- if (s.data.success) {
134
- if (F)
135
- J(s.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(
136
135
  r.formatMessage({
137
136
  id: "alert.argument_create",
138
137
  defaultMessage: "Your contribution has been sent !"
@@ -146,12 +145,12 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
146
145
  }
147
146
  );
148
147
  else {
149
- const T = s.data.data.resource;
150
- let L = v;
151
- t && !m && (L = `argumentList${T.position.id}`), J?.(
152
- D,
153
- a.find((qe) => qe.id === t) || null
154
- ), x.add(L, [T]), k(
148
+ const N = o.data.data.resource;
149
+ let T = I;
150
+ t && !m && (T = `argumentList${N.position.id}`), J?.(
151
+ $,
152
+ a.find((Ue) => Ue.id === t) || null
153
+ ), y.add(T, [N]), k(
155
154
  r.formatMessage({
156
155
  id: "alert.argument_create",
157
156
  defaultMessage: "Your contribution has been sent !"
@@ -163,52 +162,55 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
163
162
  defaultMessage: "Up to 10 eloquence points"
164
163
  }),
165
164
  category: "ARGUMENT",
166
- contentKey: d.messages_count === 2 ? "alert.third_argument" : "alert.first_argument"
165
+ contentKey: u.messages_count === 2 ? "alert.third_argument" : "alert.first_argument"
167
166
  }
168
167
  );
169
168
  }
170
169
  typeof window < "u" && window.dispatchEvent(
171
170
  new CustomEvent("logora:user_content:created", {
172
171
  detail: {
173
- content: s.data.data?.resource
172
+ content: o.data.data?.resource
174
173
  }
175
174
  })
176
175
  );
177
176
  }
178
177
  }));
179
- }, Ee = () => {
178
+ }, Pe = () => {
180
179
  const e = {
181
- content: D,
182
- rich_content: ee,
183
- source_ids: $?.map((t) => t.id),
180
+ content: $,
181
+ rich_content: Z,
182
+ source_ids: V?.map((t) => t.id),
184
183
  ...l && { position_id: l }
185
184
  };
186
- V(e, ce) && H.update("messages", te, e).then((t) => {
185
+ B(e, le) && G.update("messages", ee, e).then((t) => {
187
186
  if (t.data.success) {
188
- const o = t.data.data.resource;
189
- console.log("[updateArgument] réponse API:", o), console.log("[updateArgument] editElement:", y), console.log("[updateArgument] argumentListId prop:", v);
190
- let s = v;
191
- if (o.is_reply ? s = `argument_${o.reply_to_id || y?.reply_to_id}_reply_list` : l && !m && (s = `argumentList${o.position?.id}`), console.log("[updateArgument] listId final:", s), y?.position?.id != o.position?.id && !m && !o.is_reply) {
192
- const T = `argumentList${y.position.id}`, L = `argumentList${o.position.id}`;
193
- x.remove(T, [o]), x.add(L, [o]);
187
+ const s = t.data.data.resource;
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]);
194
192
  } else
195
- x.update(s, [o]), K && K(o);
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
+ );
196
198
  k(r.formatMessage({ id: "alert.argument_modify" }), {
197
199
  type: "success"
198
- }), le();
200
+ }), ue();
199
201
  }
200
202
  });
201
- }, Ve = () => {
202
- if (!ae) {
203
- ie(!0);
203
+ }, Be = () => {
204
+ if (!ne) {
205
+ ae(!0);
204
206
  const e = setTimeout(() => {
205
- ie(!1);
207
+ ae(!1);
206
208
  }, 2e3);
207
209
  return () => clearTimeout(e);
208
210
  }
209
211
  }, j = () => {
210
- f ? Y({ loginAction: "argument" }) : oe(!0);
211
- }, $e = () => {
212
+ g ? Y({ loginAction: "argument" }) : ie(!0);
213
+ }, Ve = () => {
212
214
  const e = S.find(
213
215
  (t) => t.id === l
214
216
  );
@@ -222,7 +224,7 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
222
224
  );
223
225
  };
224
226
  return /* @__PURE__ */ _("div", { className: n.inputContainer, children: [
225
- z && /* @__PURE__ */ i("div", { className: n.disabledInputMask, children: ue ? r.formatMessage({
227
+ z && /* @__PURE__ */ i("div", { className: n.disabledInputMask, children: re ? r.formatMessage({
226
228
  id: "input.argument_input.user_banned",
227
229
  defaultMessage: "You are banned from the debate space."
228
230
  }) : r.formatMessage({
@@ -232,18 +234,18 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
232
234
  /* @__PURE__ */ i(
233
235
  "div",
234
236
  {
235
- className: I(n.argumentInput, {
236
- [n.flash]: ae,
237
- [n.replyInputContainer]: u
237
+ className: C(n.argumentInput, {
238
+ [n.flash]: ne,
239
+ [n.replyInputContainer]: d
238
240
  }),
239
- children: /* @__PURE__ */ i("div", { "data-tid": "action_add_argument", ref: Z, children: /* @__PURE__ */ _("div", { className: n.argumentInputBox, children: [
240
- a.length > 0 && C && (!u || !R) && /* @__PURE__ */ _("div", { className: n.userPosition, children: [
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: [
241
243
  /* @__PURE__ */ i("div", { children: r.formatMessage({
242
244
  id: "input.position",
243
245
  defaultMessage: "Your position"
244
246
  }) }),
245
247
  /* @__PURE__ */ i(
246
- et,
248
+ Ze,
247
249
  {
248
250
  activeLabel: l === a[0].id ? 0 : l === a[1].id ? 1 : null,
249
251
  firstLabel: a[0],
@@ -255,32 +257,32 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
255
257
  /* @__PURE__ */ _(
256
258
  "div",
257
259
  {
258
- className: I(n.argumentTextInputBox, {
260
+ className: C(n.argumentTextInputBox, {
259
261
  [n.argumentTextInputBoxisTablet]: !m,
260
- [n.replyEditorRow]: u
262
+ [n.replyEditorRow]: d
261
263
  }),
262
264
  children: [
263
265
  /* @__PURE__ */ i(
264
266
  "div",
265
267
  {
266
- className: I(n.argumentAuthorContainer, {
268
+ className: C(n.argumentAuthorContainer, {
267
269
  [n.argumentAuthorContainerMobile]: m,
268
- [n.argumentAuthorContainerActivated]: !m && w || u
270
+ [n.argumentAuthorContainerActivated]: !m && A || d
269
271
  }),
270
- children: !m && w || u ? /* @__PURE__ */ i(
271
- tt,
272
+ children: !m && A || d ? /* @__PURE__ */ i(
273
+ et,
272
274
  {
273
- avatarUrl: d.image_url,
274
- userName: d.full_name,
275
+ avatarUrl: u.image_url,
276
+ userName: u.full_name,
275
277
  size: fe
276
278
  }
277
279
  ) : /* @__PURE__ */ i(
278
- nt,
280
+ tt,
279
281
  {
280
- fullName: d?.full_name || r.formatMessage({ id: "default_author.full_name" }),
281
- avatarUrl: d?.image_url,
282
- points: d?.points || 0,
283
- 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
284
286
  }
285
287
  )
286
288
  }
@@ -290,54 +292,54 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
290
292
  {
291
293
  onClick: j,
292
294
  "data-testid": "argument-input",
293
- className: I(n.textEditorBox, {
294
- [n.replyTextEditorBox]: u
295
+ className: C(n.textEditorBox, {
296
+ [n.replyTextEditorBox]: d
295
297
  }),
296
298
  children: [
297
299
  /* @__PURE__ */ i(
298
- at,
300
+ nt,
299
301
  {
300
302
  handleChange: (e, t) => {
301
- Pe(e, t);
303
+ Fe(e, t);
302
304
  },
303
305
  handleSourcesChange: (e) => {
304
- Be(e);
306
+ Ee(e);
305
307
  },
306
- placeholder: _e,
308
+ placeholder: pe,
307
309
  "aria-label": r.formatMessage({
308
310
  id: "input.argument_input.aria_label",
309
311
  defaultMessage: "Message input field"
310
312
  }),
311
- onSubmit: Fe,
312
- sources: $,
313
- hideSourceAction: pe || f,
314
- uid: `Argument${A}`,
313
+ onSubmit: Le,
314
+ sources: V,
315
+ hideSourceAction: he || g,
316
+ uid: `Argument${M}`,
315
317
  onActivation: j,
316
- showStylesControls: w,
317
- disabled: z || f || ue,
318
- maxLength: f ? !1 : h?.actions?.argumentMaxLength,
319
- disableRichText: h?.actions?.disableRichText || f,
320
- shortBar: u,
321
- 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,
322
324
  allowedDomains: h?.allowed_sources,
323
- active: P,
324
- hideCharCount: Ae,
325
- disableAutoActivate: be
325
+ active: F,
326
+ hideCharCount: Me,
327
+ disableAutoActivate: we
326
328
  }
327
329
  ),
328
- E?.content && /* @__PURE__ */ i("div", { className: n.argumentInputWarning, children: E && Object.values(E).map((e, t) => /* @__PURE__ */ i("div", { children: e }, t)) }),
329
- 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(
330
332
  (e) => e.id === l
331
333
  ) && /* @__PURE__ */ _(
332
334
  "div",
333
335
  {
334
- className: I(
336
+ className: C(
335
337
  n.argumentInputWarning,
336
338
  n.disabledPositionWarning
337
339
  ),
338
340
  children: [
339
341
  /* @__PURE__ */ i(
340
- it,
342
+ at,
341
343
  {
342
344
  name: "announcement",
343
345
  className: n.warningIcon,
@@ -345,12 +347,12 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
345
347
  width: 20
346
348
  }
347
349
  ),
348
- /* @__PURE__ */ i("div", { className: n.argumentInputWarningText, children: $e() })
350
+ /* @__PURE__ */ i("div", { className: n.argumentInputWarningText, children: Ve() })
349
351
  ]
350
352
  }
351
353
  ),
352
- w && G && !ve && /* @__PURE__ */ i("div", { className: n.guideMessage, children: /* @__PURE__ */ i(
353
- ge,
354
+ A && K && !ve && /* @__PURE__ */ i("div", { className: n.guideMessage, children: /* @__PURE__ */ i(
355
+ me,
354
356
  {
355
357
  id: "alert.guide_message",
356
358
  defaultMessage: "Contributions must comply with our {userCharter}.",
@@ -359,11 +361,11 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
359
361
  "a",
360
362
  {
361
363
  className: n.guideMessage,
362
- href: G,
364
+ href: K,
363
365
  target: "_blank",
364
366
  rel: "noreferrer",
365
367
  children: /* @__PURE__ */ i(
366
- ge,
368
+ me,
367
369
  {
368
370
  id: "alert.user_charter",
369
371
  defaultMessage: "user charter"
@@ -386,5 +388,5 @@ const ot = Ye(() => import("../../modal/side_modal/index.js").then((v) => ({ def
386
388
  ] });
387
389
  };
388
390
  export {
389
- yt as ArgumentInput
391
+ xt as ArgumentInput
390
392
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.3.61",
3
+ "version": "0.3.63",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",