@streamlayer/react 0.3.1 → 0.7.0

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.
package/lib/index.cjs DELETED
@@ -1,3119 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // packages/react/src/index.tsx
31
- var src_exports = {};
32
- __export(src_exports, {
33
- StreamLayerProvider: () => StreamLayerProvider,
34
- StreamLayerSDKReact: () => StreamLayerSDKReact,
35
- useStreamLayer: () => useStreamLayer,
36
- useStreamLayerApp: () => useStreamLayerApp
37
- });
38
- module.exports = __toCommonJS(src_exports);
39
-
40
- // node_modules/.pnpm/@esbuild-plugins+node-globals-polyfill@0.2.3_esbuild@0.19.5/node_modules/@esbuild-plugins/node-globals-polyfill/process.js
41
- function defaultSetTimout() {
42
- throw new Error("setTimeout has not been defined");
43
- }
44
- function defaultClearTimeout() {
45
- throw new Error("clearTimeout has not been defined");
46
- }
47
- var cachedSetTimeout = defaultSetTimout;
48
- var cachedClearTimeout = defaultClearTimeout;
49
- if (typeof globalThis.setTimeout === "function") {
50
- cachedSetTimeout = setTimeout;
51
- }
52
- if (typeof globalThis.clearTimeout === "function") {
53
- cachedClearTimeout = clearTimeout;
54
- }
55
- function runTimeout(fun) {
56
- if (cachedSetTimeout === setTimeout) {
57
- return setTimeout(fun, 0);
58
- }
59
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
60
- cachedSetTimeout = setTimeout;
61
- return setTimeout(fun, 0);
62
- }
63
- try {
64
- return cachedSetTimeout(fun, 0);
65
- } catch (e) {
66
- try {
67
- return cachedSetTimeout.call(null, fun, 0);
68
- } catch (e2) {
69
- return cachedSetTimeout.call(this, fun, 0);
70
- }
71
- }
72
- }
73
- function runClearTimeout(marker) {
74
- if (cachedClearTimeout === clearTimeout) {
75
- return clearTimeout(marker);
76
- }
77
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
78
- cachedClearTimeout = clearTimeout;
79
- return clearTimeout(marker);
80
- }
81
- try {
82
- return cachedClearTimeout(marker);
83
- } catch (e) {
84
- try {
85
- return cachedClearTimeout.call(null, marker);
86
- } catch (e2) {
87
- return cachedClearTimeout.call(this, marker);
88
- }
89
- }
90
- }
91
- var queue = [];
92
- var draining = false;
93
- var currentQueue;
94
- var queueIndex = -1;
95
- function cleanUpNextTick() {
96
- if (!draining || !currentQueue) {
97
- return;
98
- }
99
- draining = false;
100
- if (currentQueue.length) {
101
- queue = currentQueue.concat(queue);
102
- } else {
103
- queueIndex = -1;
104
- }
105
- if (queue.length) {
106
- drainQueue();
107
- }
108
- }
109
- function drainQueue() {
110
- if (draining) {
111
- return;
112
- }
113
- var timeout = runTimeout(cleanUpNextTick);
114
- draining = true;
115
- var len = queue.length;
116
- while (len) {
117
- currentQueue = queue;
118
- queue = [];
119
- while (++queueIndex < len) {
120
- if (currentQueue) {
121
- currentQueue[queueIndex].run();
122
- }
123
- }
124
- queueIndex = -1;
125
- len = queue.length;
126
- }
127
- currentQueue = null;
128
- draining = false;
129
- runClearTimeout(timeout);
130
- }
131
- function nextTick(fun) {
132
- var args = new Array(arguments.length - 1);
133
- if (arguments.length > 1) {
134
- for (var i = 1; i < arguments.length; i++) {
135
- args[i - 1] = arguments[i];
136
- }
137
- }
138
- queue.push(new Item(fun, args));
139
- if (queue.length === 1 && !draining) {
140
- runTimeout(drainQueue);
141
- }
142
- }
143
- function Item(fun, array) {
144
- this.fun = fun;
145
- this.array = array;
146
- }
147
- Item.prototype.run = function() {
148
- this.fun.apply(null, this.array);
149
- };
150
- var title = "browser";
151
- var platform = "browser";
152
- var browser = true;
153
- var env = {};
154
- var argv = [];
155
- var version = "";
156
- var versions = {};
157
- var release = {};
158
- var config = {};
159
- function noop() {
160
- }
161
- var on = noop;
162
- var addListener = noop;
163
- var once = noop;
164
- var off = noop;
165
- var removeListener = noop;
166
- var removeAllListeners = noop;
167
- var emit = noop;
168
- function binding(name) {
169
- throw new Error("process.binding is not supported");
170
- }
171
- function cwd() {
172
- return "/";
173
- }
174
- function chdir(dir) {
175
- throw new Error("process.chdir is not supported");
176
- }
177
- function umask() {
178
- return 0;
179
- }
180
- var performance = globalThis.performance || {};
181
- var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function() {
182
- return (/* @__PURE__ */ new Date()).getTime();
183
- };
184
- function hrtime(previousTimestamp) {
185
- var clocktime = performanceNow.call(performance) * 1e-3;
186
- var seconds = Math.floor(clocktime);
187
- var nanoseconds = Math.floor(clocktime % 1 * 1e9);
188
- if (previousTimestamp) {
189
- seconds = seconds - previousTimestamp[0];
190
- nanoseconds = nanoseconds - previousTimestamp[1];
191
- if (nanoseconds < 0) {
192
- seconds--;
193
- nanoseconds += 1e9;
194
- }
195
- }
196
- return [seconds, nanoseconds];
197
- }
198
- var startTime = /* @__PURE__ */ new Date();
199
- function uptime() {
200
- var currentTime = /* @__PURE__ */ new Date();
201
- var dif = currentTime - startTime;
202
- return dif / 1e3;
203
- }
204
- var process = {
205
- nextTick,
206
- title,
207
- browser,
208
- env,
209
- argv,
210
- version,
211
- versions,
212
- on,
213
- addListener,
214
- once,
215
- off,
216
- removeListener,
217
- removeAllListeners,
218
- emit,
219
- binding,
220
- cwd,
221
- chdir,
222
- umask,
223
- hrtime,
224
- platform,
225
- release,
226
- config,
227
- uptime
228
- };
229
- var defines = {};
230
- Object.keys(defines).forEach((key) => {
231
- const segs = key.split(".");
232
- let target = process;
233
- for (let i = 0; i < segs.length; i++) {
234
- const seg = segs[i];
235
- if (i === segs.length - 1) {
236
- target[seg] = defines[key];
237
- } else {
238
- target = target[seg] || (target[seg] = {});
239
- }
240
- }
241
- });
242
-
243
- // packages/react-ui/src/lib/gamification/inapp/index.tsx
244
- var import_react = require("react");
245
-
246
- // packages/react-ui/src/assets/icons/icon-exit.svg
247
- var icon_exit_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A <rect width="24" height="24" rx="12" fill="white" fill-opacity="0.1"/>%0A <rect x="8.25" y="7" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(45 8.25 7)" fill="white"/>%0A <rect x="7" y="15.75" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(-45 7 15.75)" fill="white"/>%0A</svg>%0A';
248
-
249
- // packages/react-ui/src/lib/gamification/inapp/styles.tsx
250
- var import_styled = __toESM(require("@emotion/styled"), 1);
251
- var Container = import_styled.default.div`
252
- box-sizing: border-box;
253
- border: ${(props) => `1px solid ${props.theme.COLORS.BLUE_PRIMARY}`};
254
- border-radius: 13px;
255
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT};
256
- color: ${(props) => props.theme.COLORS.WHITE};
257
- display: flex;
258
- user-select: none;
259
- cursor: pointer;
260
- overflow: hidden;
261
- animation: slidein 0.3s ease-in;
262
-
263
- @keyframes slidein {
264
- from {
265
- transform: translateX(-100%);
266
- }
267
-
268
- to {
269
- transform: translateX(0);
270
- }
271
- }
272
- `;
273
- var IconWrap = import_styled.default.div`
274
- display: flex;
275
- justify-content: center;
276
- align-items: center;
277
- padding: 14px;
278
- background-color: ${(props) => props.theme.COLORS.BLUE_PRIMARY};
279
- `;
280
- var Icon = import_styled.default.img`
281
- max-width: 40px;
282
- max-height: 40px;
283
- width: 100%;
284
- height: 100%;
285
- border-radius: 50%;
286
- `;
287
- var Content = import_styled.default.div`
288
- display: flex;
289
- justify-content: space-between;
290
- width: 100%;
291
- align-items: center;
292
- `;
293
- var TitleWrap = import_styled.default.div`
294
- padding-left: 20px;
295
- padding-right: 5px;
296
- font-weight: 700;
297
- font-size: 14px;
298
- flex: 1;
299
- `;
300
- var Title = import_styled.default.div`
301
- display: -webkit-box;
302
- -webkit-box-orient: vertical;
303
- -webkit-line-clamp: 2;
304
- overflow: hidden;
305
- text-overflow: ellipsis;
306
- `;
307
- var CloseBtnWrap = import_styled.default.div`
308
- padding: 20px;
309
- `;
310
- var CloseBtn = import_styled.default.button`
311
- border: none;
312
- outline: none;
313
- background-color: transparent;
314
- cursor: pointer;
315
- display: flex;
316
- justify-content: center;
317
- align-items: center;
318
- `;
319
- var CloseIcon = import_styled.default.img`
320
- width: 24px;
321
- height: 24px;
322
- `;
323
-
324
- // packages/react-ui/src/lib/gamification/inapp/index.tsx
325
- var import_jsx_runtime = require("@emotion/react/jsx-runtime");
326
- var InApp = ({ title: title2 = "", icon, color, openVoiting, closeInApp }) => {
327
- const _closeInApp = (0, import_react.useCallback)(
328
- (e) => {
329
- e.stopPropagation();
330
- closeInApp();
331
- },
332
- [closeInApp]
333
- );
334
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Container, { onClick: openVoiting, children: [
335
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconWrap, { style: color ? { backgroundColor: color } : {}, children: !!icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { alt: "in-app-icon", src: icon }) }),
336
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Content, { children: [
337
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TitleWrap, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Title, { id: "in-app-title", children: title2 }) }),
338
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CloseBtnWrap, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CloseBtn, { onClick: _closeInApp, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CloseIcon, { alt: "close-in-app-icon", src: icon_exit_default }) }) })
339
- ] })
340
- ] });
341
- };
342
-
343
- // packages/react-ui/src/lib/gamification/login/index.tsx
344
- var import_react3 = require("react");
345
- var import_react_phone_number_input = __toESM(require("react-phone-number-input"), 1);
346
- var import_style = require("react-phone-number-input/style.css");
347
- var import_react_digit_input = __toESM(require("react-digit-input"), 1);
348
-
349
- // packages/react-ui/src/utils/login.ts
350
- var import_connect_web = require("@bufbuild/connect-web");
351
- var import_connect = require("@connectrpc/connect");
352
- var import_users_connect = require("@streamlayer/sl-eslib/users/users_connect");
353
- var requestLoginCode = async (host, phone) => {
354
- const transport2 = (0, import_connect_web.createGrpcWebTransport)({
355
- baseUrl: host
356
- });
357
- const userClient = (0, import_connect.createPromiseClient)(import_users_connect.Users, transport2);
358
- await userClient.requestPassword({ id: phone });
359
- return true;
360
- };
361
- var register = async (host, phone) => {
362
- const transport2 = (0, import_connect_web.createGrpcWebTransport)({
363
- baseUrl: host
364
- });
365
- const userClient = (0, import_connect.createPromiseClient)(import_users_connect.Users, transport2);
366
- await userClient.register({ id: phone });
367
- return true;
368
- };
369
- var login = async (host, phone, code) => {
370
- const transport2 = (0, import_connect_web.createGrpcWebTransport)({
371
- baseUrl: host
372
- });
373
- const userClient = (0, import_connect.createPromiseClient)(import_users_connect.Users, transport2);
374
- const res = await userClient.login({ id: phone, password: code });
375
- return res?.meta?.jwt;
376
- };
377
-
378
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/index.tsx
379
- var import_react2 = require("react");
380
- var import_react_countdown_circle_timer = require("react-countdown-circle-timer");
381
-
382
- // packages/react-ui/src/lib/theme/theme.ts
383
- var theme = {
384
- COLORS: {
385
- BG_TRANSPARENT: "rgba(0,0,0, .8)",
386
- BG_TRANSPARENT_VOTE_CONTAINER: "rgba(10, 14, 19, 0.8)",
387
- BG_TRANSPARENT_ITEM: "rgba(0, 0, 0, 0.7)",
388
- BG_TRANSPARENT_ITEM_VOTE: "rgba(255, 255, 255, 0.1)",
389
- BG_TRANSPARENT_ITEM_SUCCESS: "rgba(0, 139, 251, 0.2)",
390
- BG_TRANSPARENT_ITEM_ERROR: "rgba(205, 37, 37, 0.2)",
391
- BG_TRANSPARENT_VOTE_PROGRESS: "rgba(255, 255, 255, 0.2)",
392
- BG_TRANSPARENT_VOTE_PROGRESS_SUCCESS: "rgba(60, 139, 251, 0.5)",
393
- BG_TRANSPARENT_VOTE_PROGRESS_ERROR: "rgba(205, 37, 37, 0.5)",
394
- BG_TRANSPARENT_USER_CONTAINER: "rgba(255, 255, 255, 0.05)",
395
- BLUE_PRIMARY: "#1589EE",
396
- RED_PRIMARY: "#CD2525",
397
- BLUE_QUESTION_ACTION_BTN: "#1589ee",
398
- WHITE: "#FFFFFF",
399
- GREY_1: "#909395",
400
- GREY_2: "#22262b",
401
- GREY_3: "#2d3135",
402
- GREY_4: "#53565a",
403
- BLACK_1: "#161a1f",
404
- GREEN_1: "#F7B801",
405
- RED_1: "#A30000",
406
- RED_2: "#FF4170",
407
- GREY_PRIMARY: "#909395",
408
- DIVIDER_COLOR_PRIMARY: "#2d3135",
409
- DIVIDER_COLOR_SECONDARY: "#53565a",
410
- GREEN_PRIMARY_BTN: "#009B77"
411
- },
412
- FONT: {
413
- FAMILY: "Roboto, sans-serif",
414
- COLOR: "#fff"
415
- }
416
- };
417
-
418
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/styles.tsx
419
- var import_styled2 = __toESM(require("@emotion/styled"), 1);
420
- var RemainingTime = import_styled2.default.div`
421
- color: ${(props) => props.remainingTime ? "inherit" : props.theme.COLORS.RED_2};
422
- font-size: 12px;
423
- `;
424
-
425
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/index.tsx
426
- var import_jsx_runtime2 = require("@emotion/react/jsx-runtime");
427
- var TIMER_COLORS = [theme.COLORS.BLUE_PRIMARY, theme.COLORS.GREEN_1, theme.COLORS.RED_1];
428
- var TIMER_COLORS_TIME = [10, 6, 0];
429
- var DEFAULT_DURATION = 30;
430
- var TIMER_SIZE = 32;
431
- var STROKE_WIDTH = 4;
432
- var TRAIL_STROKE_WIDTH = 0;
433
- var Timer = ({ isPlaying = true, duration = DEFAULT_DURATION, setTimeToExpire }) => {
434
- const renderTime = ({ remainingTime }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemainingTime, { remainingTime, children: remainingTime });
435
- (0, import_react2.useEffect)(() => {
436
- setTimeToExpire(false);
437
- }, [setTimeToExpire]);
438
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
439
- import_react_countdown_circle_timer.CountdownCircleTimer,
440
- {
441
- isPlaying,
442
- duration,
443
- colors: TIMER_COLORS,
444
- colorsTime: TIMER_COLORS_TIME,
445
- size: TIMER_SIZE,
446
- strokeWidth: STROKE_WIDTH,
447
- trailStrokeWidth: TRAIL_STROKE_WIDTH,
448
- onComplete: () => setTimeToExpire(true),
449
- children: renderTime
450
- }
451
- );
452
- };
453
-
454
- // packages/react-ui/src/lib/gamification/login/styles.tsx
455
- var import_styled3 = __toESM(require("@emotion/styled"), 1);
456
- var Panel = import_styled3.default.div`
457
- border-radius: 8px;
458
- padding: 0 12px;
459
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
460
- display: flex;
461
- align-items: center;
462
- height: 100%;
463
- `;
464
- var Form = import_styled3.default.form`
465
- display: flex;
466
- margin: auto;
467
- flex-direction: column;
468
- align-items: center;
469
- text-align: center;
470
- `;
471
- var FormTitle = import_styled3.default.div`
472
- margin-bottom: 20px;
473
- font-size: 18px;
474
- `;
475
- var FormDescription = import_styled3.default.div`
476
- margin-bottom: 10px;
477
- font-size: 14px;
478
-
479
- display: flex;
480
- align-items: center;
481
- flex-direction: column;
482
- `;
483
- var FormSubmit = import_styled3.default.button`
484
- background-color: ${(props) => props.theme.COLORS.BLUE_QUESTION_ACTION_BTN};
485
- border: none;
486
- border-radius: 2px;
487
- padding: 6px;
488
- text-transform: uppercase;
489
- color: #fff;
490
- cursor: pointer;
491
-
492
- &:disabled {
493
- opacity: 0.5;
494
- cursor: default;
495
- }
496
- margin-bottom: 20px;
497
- `;
498
- var FormInputContainer = import_styled3.default.div`
499
- input {
500
- font-size: 20px;
501
- background: transparent;
502
- color: #fff;
503
- border: none;
504
- outline: none;
505
- }
506
-
507
- margin-bottom: 40px;
508
- border-bottom: 1px solid white;
509
- `;
510
- var Digits = import_styled3.default.div`
511
- display: flex;
512
- gap: 10px;
513
- margin-bottom: 20px;
514
-
515
- input {
516
- width: 20px;
517
- height: 40px;
518
- font-size: 40px;
519
- }
520
- `;
521
-
522
- // packages/react-ui/src/lib/gamification/login/index.tsx
523
- var import_jsx_runtime3 = require("@emotion/react/jsx-runtime");
524
- var Login = ({ login: login2, anonymousLogin, host }) => {
525
- const [phoneInput, setPhoneInput] = (0, import_react3.useState)("");
526
- const [phone, setPhone] = (0, import_react3.useState)("");
527
- const [code, setCode] = (0, import_react3.useState)("");
528
- const digits = (0, import_react_digit_input.default)({
529
- acceptedCharacters: /^[0-9]$/,
530
- length: 4,
531
- value: code,
532
- onChange: setCode
533
- });
534
- const requestCode = async (e) => {
535
- e.preventDefault();
536
- try {
537
- const parsed = phoneInput.replaceAll("+", "");
538
- try {
539
- await requestLoginCode(host, parsed);
540
- } catch (err) {
541
- await register(host, parsed);
542
- }
543
- setPhone(parsed);
544
- } catch (err) {
545
- window.alert(err);
546
- }
547
- };
548
- const loginByCode = async (e) => {
549
- e.preventDefault();
550
- if (phone && code) {
551
- try {
552
- const token = await login(host, phone, code);
553
- if (token && login2) {
554
- await login2(token);
555
- } else {
556
- console.log("token", token);
557
- }
558
- } catch (err) {
559
- window.alert(err);
560
- }
561
- }
562
- };
563
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Panel, { children: [
564
- !phone && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
565
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Form, { onSubmit: requestCode, children: [
566
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormTitle, { children: "Enter your phone number" }),
567
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormDescription, { children: "Enter your phone up for number to log in or sign an account." }),
568
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormInputContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_phone_number_input.default, { value: phoneInput, onChange: (val) => setPhoneInput(`${val}`) }) }),
569
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormSubmit, { disabled: !(0, import_react_phone_number_input.isValidPhoneNumber)(phoneInput), type: "submit", children: "request code" })
570
- ] }),
571
- anonymousLogin && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormSubmit, { style: { display: "block", margin: "auto" }, onClick: anonymousLogin, children: "anonymous login" })
572
- ] }),
573
- phone && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Form, { onSubmit: loginByCode, children: [
574
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormTitle, { children: "Enter Verification Code" }),
575
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(FormDescription, { children: [
576
- "Please enter the verification code ",
577
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("br", {}),
578
- "sent to ",
579
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("b", { children: (0, import_react_phone_number_input.formatPhoneNumberIntl)(phoneInput) })
580
- ] }),
581
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Digits, { children: [
582
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { autoFocus: true, inputMode: "decimal", ...digits[0] }),
583
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { inputMode: "decimal", ...digits[1] }),
584
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { inputMode: "decimal", ...digits[2] }),
585
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { inputMode: "decimal", ...digits[3] })
586
- ] }),
587
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormSubmit, { disabled: code.length !== 4, type: "submit", children: "login" }),
588
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(FormDescription, { children: [
589
- "Didn't get 59 the code? ",
590
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("br", {}),
591
- "Resend Code in",
592
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Timer, { duration: 30, setTimeToExpire: () => {
593
- }, isPlaying: true })
594
- ] })
595
- ] })
596
- ] });
597
- };
598
-
599
- // packages/react-ui/src/lib/gamification/onboarding/styles.tsx
600
- var import_styled4 = __toESM(require("@emotion/styled"), 1);
601
- var Container2 = import_styled4.default.div`
602
- box-sizing: border-box;
603
- display: flex;
604
- color: ${(props) => props.theme.COLORS.WHITE};
605
- flex-direction: column;
606
- height: 100%;
607
- width: 100%;
608
- `;
609
- var Content2 = import_styled4.default.div`
610
- flex: 1;
611
- display: flex;
612
- justify-content: center;
613
- flex-direction: column;
614
- align-items: center;
615
- `;
616
- var Description = import_styled4.default.div`
617
- font-size: 22px;
618
- font-weight: 300;
619
- margin-bottom: 4px;
620
- `;
621
- var Title2 = import_styled4.default.div`
622
- font-size: 26px;
623
- font-weight: 700;
624
- `;
625
- var OnboardingActionBtn = import_styled4.default.button`
626
- color: ${(props) => props.theme.COLORS.WHITE};
627
- width: 100%;
628
- border: none;
629
- outline: none;
630
- background-color: ${(props) => props.theme.COLORS.GREEN_PRIMARY_BTN};
631
- cursor: pointer;
632
- padding: 12px 16px;
633
- display: flex;
634
- justify-content: center;
635
- align-items: center;
636
- font-size: 16px;
637
- font-weight: 600;
638
- border-radius: 6px;
639
- `;
640
-
641
- // packages/react-ui/src/lib/gamification/onboarding/index.tsx
642
- var import_jsx_runtime4 = require("@emotion/react/jsx-runtime");
643
- var Onboarding = ({ action }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Container2, { children: [
644
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Content2, { children: [
645
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Description, { children: "Welcome to the" }),
646
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Title2, { children: "Inplay Game" })
647
- ] }),
648
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OnboardingActionBtn, { onClick: action, children: "Let\u2019s play" })
649
- ] });
650
-
651
- // packages/sdk-web-types/src/sl-types.ts
652
- var import_interactive = require("@streamlayer/sl-eslib/interactive/interactive.common_pb");
653
- var import_interactive2 = require("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb");
654
- var import_sdkSettings = require("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb");
655
-
656
- // packages/react-ui/src/assets/icons/icon-poll.svg
657
- var icon_poll_default = 'data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Poll">%0A<path id="Notification/Icon/Poll" fill-rule="evenodd" clip-rule="evenodd" d="M9.7778 1.68421V5.05263H13.3333C13.8243 5.05263 14.2222 4.67561 14.2222 4.21053V2.52632C14.2222 2.06123 13.8243 1.68421 13.3333 1.68421H9.7778ZM2.66667 0C1.19391 0 0 1.13107 0 2.52632V4.21053C0 5.60577 1.19391 6.73684 2.66667 6.73684H13.3333C14.8061 6.73684 16 5.60577 16 4.21053V2.52632C16 1.13107 14.8061 0 13.3333 0H2.66667ZM4.44446 10.9473H13.3333C13.8243 10.9473 14.2222 11.3243 14.2222 11.7894V13.4736C14.2222 13.9387 13.8243 14.3157 13.3333 14.3157H4.44446V10.9473ZM0 11.7894C0 10.3942 1.19391 9.2631 2.66667 9.2631H13.3333C14.8061 9.2631 16 10.3942 16 11.7894V13.4736C16 14.8689 14.8061 15.9999 13.3333 15.9999H2.66667C1.19391 15.9999 0 14.8689 0 13.4736V11.7894Z" fill="white" fill-opacity="0.5"/>%0A</g>%0A</svg>%0A';
658
-
659
- // packages/react-ui/src/assets/icons/icon-prediction.svg
660
- var icon_prediction_default = 'data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Icon/Notification/Prediciton">%0A<path id="Icon/Prediction" fill-rule="evenodd" clip-rule="evenodd" d="M16 7.00522C16 7.00522 9.20048 6.81607 9.20048 0C9.20048 6.36168 3.27729 6.95056 2.48756 7.00078L2.40094 7.00522C2.40094 7.00522 9.20048 7.19435 9.20048 14.0104C9.20048 7.64877 15.1234 7.05989 15.9131 7.00964L16 7.00522ZM6.97382 12.5652C6.97382 12.5652 3.48691 12.4724 3.48691 9.13033C3.48691 12.2496 0.449402 12.5384 0.0444186 12.563L0 12.5652C0 12.5652 3.48691 12.6579 3.48691 16C3.48691 12.8807 6.52429 12.592 6.92927 12.5673L6.97382 12.5652Z" fill="white" fill-opacity="0.5"/>%0A</g>%0A</svg>%0A';
661
-
662
- // packages/react-ui/src/assets/icons/icon-trivia.svg
663
- var icon_trivia_default = 'data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Icon/Notification/Trivia">%0A<path id="Notification/Icon/Trivia" fill-rule="evenodd" clip-rule="evenodd" d="M2.01663 1.3808C0.739913 1.55586 -0.153153 2.73276 0.021912 4.00948L1.3808 13.9196C1.55586 15.1963 2.73276 16.0894 4.00948 15.9143L13.9196 14.5554C15.1963 14.3803 16.0894 13.2034 15.9143 11.9267L14.5554 2.01663C14.3803 0.739913 13.2034 -0.153153 11.9267 0.021912L2.01663 1.3808ZM9.59613 3.788C9.11431 3.46991 8.47813 3.30151 7.7566 3.30151C7.54377 3.30151 7.32625 3.31671 7.10872 3.34478C6.38836 3.44067 5.68901 3.79034 5.18965 4.30138C4.68445 4.82062 4.4377 5.45563 4.51722 6.04151C4.57452 6.4742 4.90078 6.7537 5.34635 6.7537C5.39429 6.7537 5.44341 6.7502 5.49136 6.74435C6.08778 6.66483 6.21642 6.25436 6.34036 5.85675L6.34045 5.85648C6.48192 5.40401 6.61534 4.97731 7.38585 4.87444C7.46537 4.86391 7.54138 4.85806 7.61506 4.85806C8.16939 4.85806 8.51436 5.15042 8.58454 5.68252C8.65353 6.20293 8.24307 6.61807 7.80684 7.0566L7.80393 7.05954C7.31582 7.55231 6.7639 8.1095 6.86895 8.90083C6.89585 9.10548 6.9859 9.29493 7.12272 9.43644C7.27826 9.599 7.4829 9.68436 7.71331 9.68436C7.75541 9.68436 7.79868 9.68203 7.84311 9.67618C8.46691 9.59324 8.55162 9.23139 8.63338 8.8821L8.63365 8.88097L8.63661 8.86859C8.66723 8.7403 8.69877 8.60813 8.75995 8.48804C8.84649 8.31613 9.06283 8.11265 9.31428 7.87875C9.9142 7.31858 10.734 6.55143 10.582 5.41589C10.4872 4.70603 10.1551 4.15757 9.59611 3.78802L9.59613 3.788ZM8.11605 10.28C8.06927 10.28 8.02132 10.2836 7.97454 10.2894C7.38396 10.3689 6.96765 10.9127 7.04599 11.5033C7.11733 12.0377 7.57808 12.4412 8.1172 12.4412C8.16397 12.4412 8.21192 12.4377 8.25987 12.4318C8.85045 12.3523 9.2656 11.8085 9.18842 11.2179C9.11591 10.6823 8.65517 10.28 8.11605 10.28Z" fill="white" fill-opacity="0.5"/>%0A</g>%0A</svg>%0A';
664
-
665
- // packages/react-ui/src/assets/icons/icon-check-green.svg
666
- var icon_check_green_default = 'data:image/svg+xml,<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Check">%0A<path id="Vector" d="M13.4315 3.18246L5.53321 11.0808L1.99771 7.54527C1.54056 7.08811 0.799913 7.08811 0.342864 7.54527C-0.114288 8.00242 -0.114288 8.74307 0.342864 9.20011L4.70567 13.5629C4.93331 13.7906 5.23415 13.9063 5.53307 13.9063C5.83202 13.9063 6.13096 13.7924 6.36048 13.5629L15.0861 4.83731C15.5432 4.38016 15.5432 3.63951 15.0861 3.18246C14.629 2.72531 13.8884 2.72531 13.4312 3.18246H13.4315Z" fill="%2300BD60"/>%0A</g>%0A</svg>%0A';
667
-
668
- // packages/react-ui/src/assets/icons/icon-cross.svg
669
- var icon_cross_default = 'data:image/svg+xml,<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Group 465">%0A<rect id="Rectangle 368" x="2" y="0.506104" width="16.4992" height="2.35702" rx="1.17851" transform="rotate(45 2 0.506104)" fill="%239e0a1f"/>%0A<rect id="Rectangle 369" x="0.333008" y="12.1729" width="16.4992" height="2.35702" rx="1.17851" transform="rotate(-45 0.333008 12.1729)" fill="%239e0a1f"/>%0A</g>%0A</svg>%0A';
670
-
671
- // packages/react-ui/src/assets/icons/icon-chevron.svg
672
- var icon_chevron_default = 'data:image/svg+xml,<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Chevron">%0A<path id="Chevron_2" d="M12 8.17222C12 8.28783 11.9781 8.39553 11.9342 8.49533C11.8903 8.59513 11.822 8.68992 11.7292 8.7797L6.36949 13.9439C6.21462 14.0965 6.02742 14.1729 5.80787 14.1729C5.65752 14.1729 5.52191 14.1379 5.40104 14.0679C5.28016 13.998 5.1831 13.9039 5.10986 13.7856C5.03662 13.6673 5 13.5345 5 13.3873C5 13.1721 5.08288 12.9818 5.24863 12.8164L10.0807 8.17095L5.24863 3.52799C5.08288 3.36425 5 3.17439 5 2.95841C5 2.81118 5.03662 2.67842 5.10986 2.56013C5.1831 2.44183 5.28016 2.34771 5.40104 2.27777C5.52191 2.20782 5.65752 2.17285 5.80787 2.17285C6.02742 2.17285 6.21462 2.24731 6.36949 2.39624L11.7292 7.56473C11.8211 7.65451 11.889 7.74909 11.9329 7.84846C11.9768 7.94784 11.9991 8.05576 12 8.17222Z" fill="%23FFFFFF"/>%0A</g>%0A</svg>%0A';
673
-
674
- // packages/react-ui/src/lib/gamification/question/styles.tsx
675
- var import_styled5 = __toESM(require("@emotion/styled"), 1);
676
- var Panel2 = import_styled5.default.div`
677
- border-radius: 8px;
678
- padding: 12px;
679
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
680
- display: flex;
681
- align-items: center;
682
- cursor: pointer;
683
-
684
- &:hover {
685
- background: #000;
686
- }
687
- `;
688
- var QuestionTypeIconWrap = import_styled5.default.div`
689
- padding-right: 12px;
690
- display: flex;
691
- align-items: center;
692
- justify-content: center;
693
- `;
694
- var QuestionTypeIcon = import_styled5.default.img`
695
- width: 16px;
696
- height: 16px;
697
- `;
698
- var QuestionContent = import_styled5.default.div`
699
- font-weight: 700;
700
- flex: 1;
701
- display: flex;
702
- flex-direction: column;
703
- overflow: hidden;
704
- `;
705
- var QuestionTypeLabel = import_styled5.default.div`
706
- color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
707
- font-size: 10px;
708
- overflow: hidden;
709
- text-overflow: ellipsis;
710
- white-space: nowrap;
711
- padding-bottom: 5px;
712
- text-transform: uppercase;
713
- `;
714
- var QuestionSubject = import_styled5.default.div`
715
- color: ${(props) => props.theme.COLORS.WHITE};
716
- font-size: 12px;
717
- overflow: hidden;
718
- text-overflow: ellipsis;
719
- white-space: nowrap;
720
- `;
721
- var QuestionActionTitle = import_styled5.default.button`
722
- background-color: ${(props) => props.theme.COLORS.BLUE_QUESTION_ACTION_BTN};
723
- border: none;
724
- border-radius: 2px;
725
- font-size: 8px;
726
- padding: 6px;
727
- height: 20px;
728
- text-transform: uppercase;
729
- color: #fff;
730
- cursor: pointer;
731
- `;
732
- var QuestionActionIcon = import_styled5.default.button`
733
- border: none;
734
- font-size: 8px;
735
- padding: 6px;
736
- display: flex;
737
- align-items: center;
738
- background-color: transparent;
739
- cursor: pointer;
740
- `;
741
- var QuestionStatusIcon = import_styled5.default.img`
742
- width: 16px;
743
- height: 16px;
744
- `;
745
- var QuestionTypeTitle = import_styled5.default.span`
746
- text-transform: uppercase;
747
- `;
748
- var ExpiredQuestion = import_styled5.default.span`
749
- text-transform: uppercase;
750
- border-left: ${(props) => `1px solid ${props.theme.COLORS.GREY_PRIMARY}`};
751
- padding-left: 5px;
752
- margin-left: 5px;
753
- `;
754
-
755
- // packages/react-ui/src/lib/gamification/question/index.tsx
756
- var import_jsx_runtime5 = require("@emotion/react/jsx-runtime");
757
- var QuestionTypeData = {
758
- [import_interactive.QuestionType.POLL]: { label: "Poll", icon: icon_poll_default },
759
- [import_interactive.QuestionType.TRIVIA]: { label: "Trivia", icon: icon_trivia_default },
760
- [import_interactive.QuestionType.PREDICTION]: { label: "Prediction", icon: icon_prediction_default }
761
- };
762
- var QuestionStatusTypeData = {
763
- [import_interactive2.PickHistoryStatus.LOST]: icon_cross_default,
764
- [import_interactive2.PickHistoryStatus.WON]: icon_check_green_default,
765
- [import_interactive2.PickHistoryStatus.UNSET]: icon_chevron_default,
766
- [import_interactive2.PickHistoryStatus.DNP]: icon_chevron_default
767
- };
768
- var Question = ({
769
- questionId,
770
- questionType,
771
- questionStatus,
772
- subject,
773
- openForVoting,
774
- openQuestion,
775
- status
776
- }) => {
777
- const questionTypeData = QuestionTypeData[questionType];
778
- if (questionTypeData === void 0) {
779
- return null;
780
- }
781
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Panel2, { onClick: () => openQuestion?.(questionId), children: [
782
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionTypeIconWrap, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionTypeIcon, { alt: "question-type-icon", src: questionTypeData.icon }) }),
783
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(QuestionContent, { children: [
784
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(QuestionTypeLabel, { children: [
785
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionTypeTitle, { children: questionTypeData.label }),
786
- questionType === import_interactive.QuestionType.TRIVIA && questionStatus === import_interactive.QuestionStatus.RESOLVED && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ExpiredQuestion, { children: "Expired" })
787
- ] }),
788
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionSubject, { children: subject || "" })
789
- ] }),
790
- openForVoting ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionActionTitle, { children: "play" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionActionIcon, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionStatusIcon, { alt: "question-status-icon", src: QuestionStatusTypeData[status] }) })
791
- ] });
792
- };
793
-
794
- // packages/react-ui/src/lib/gamification/question-list/styles.tsx
795
- var import_styled6 = __toESM(require("@emotion/styled"), 1);
796
- var Container3 = import_styled6.default.div`
797
- display: flex;
798
- flex-direction: column;
799
- height: calc(100% - 160px);
800
- border-radius: 13px;
801
- `;
802
- var Title3 = import_styled6.default.div`
803
- color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
804
- text-transform: uppercase;
805
- font-size: 12px;
806
- font-weight: 500;
807
- margin-bottom: 8px;
808
- `;
809
- var ItemsContainer = import_styled6.default.div`
810
- display: flex;
811
- flex-direction: column;
812
- overflow-y: auto;
813
- max-height: 100%;
814
-
815
- & > div {
816
- margin-bottom: 8px;
817
- }
818
- `;
819
-
820
- // packages/react-ui/src/lib/gamification/question-list/index.tsx
821
- var import_jsx_runtime6 = require("@emotion/react/jsx-runtime");
822
- var QuestionList = ({ questions, openQuestion }) => {
823
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Container3, { children: [
824
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Title3, { children: "PICK HISTORY" }),
825
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ItemsContainer, { children: questions?.map((props) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Question, { openQuestion, ...props }, props.questionId)) })
826
- ] });
827
- };
828
-
829
- // packages/react-ui/src/assets/icons/icon-trophy.svg
830
- var icon_trophy_default = 'data:image/svg+xml,<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Trophy">%0A<path id="Combined Shape" fill-rule="evenodd" clip-rule="evenodd" d="M2.76916 3.50002C2.76916 4.49786 2.94705 5.38348 3.30282 6.15692C2.62493 6.01847 2.05883 5.74872 1.6045 5.34768C1.15017 4.94663 0.923008 4.55992 0.923008 4.18752V3.50002H2.76916ZM11.0768 3.50002V4.18752C11.0768 4.55992 10.8497 4.94663 10.3953 5.34768C9.941 5.74872 9.3749 6.01847 8.69701 6.15692C9.05278 5.38348 9.23066 4.49786 9.23066 3.50002H11.0768ZM12 4.1875V3.27083C12 3.07986 11.9327 2.91754 11.7981 2.78385C11.6635 2.65017 11.5 2.58333 11.3077 2.58333H9.23077V1.89583C9.23077 1.58073 9.11779 1.31098 8.89183 1.08659C8.66586 0.862195 8.39423 0.75 8.07692 0.75H3.92308C3.60577 0.75 3.33414 0.862195 3.10817 1.08659C2.88221 1.31098 2.76923 1.58073 2.76923 1.89583V2.58333H0.692308C0.499999 2.58333 0.336539 2.65017 0.201923 2.78385C0.067307 2.91754 0 3.07986 0 3.27083V4.1875C0 4.52648 0.0997586 4.86784 0.299279 5.21159C0.498799 5.55534 0.768027 5.86567 1.10697 6.14258C1.44592 6.41949 1.86178 6.65223 2.35457 6.84082C2.84736 7.02941 3.36538 7.13563 3.90865 7.15951C4.11058 7.41732 4.33894 7.6441 4.59375 7.83984C4.77644 8.00217 4.90264 8.17524 4.97236 8.35905C5.04207 8.54286 5.07692 8.75651 5.07692 9C5.07692 9.25781 5.00361 9.47504 4.85697 9.65169C4.71034 9.82834 4.47596 9.91667 4.15385 9.91667C3.79327 9.91667 3.47236 10.0253 3.19111 10.2425C2.90985 10.4597 2.76923 10.7331 2.76923 11.0625V11.5208C2.76923 11.5877 2.79087 11.6426 2.83413 11.6855C2.8774 11.7285 2.93269 11.75 3 11.75H9C9.06731 11.75 9.1226 11.7285 9.16586 11.6855C9.20913 11.6426 9.23077 11.5877 9.23077 11.5208V11.0625C9.23077 10.7331 9.09015 10.4597 8.80889 10.2425C8.52764 10.0253 8.20673 9.91667 7.84615 9.91667C7.52404 9.91667 7.28966 9.82834 7.14303 9.65169C6.99639 9.47504 6.92308 9.25781 6.92308 9C6.92308 8.75651 6.95793 8.54286 7.02764 8.35905C7.09736 8.17524 7.22356 8.00217 7.40625 7.83984C7.66106 7.6441 7.88942 7.41732 8.09135 7.15951C8.63462 7.13563 9.15264 7.02941 9.64543 6.84082C10.1382 6.65223 10.5541 6.41949 10.893 6.14258C11.232 5.86567 11.5012 5.55534 11.7007 5.21159C11.9002 4.86784 12 4.52648 12 4.1875ZM5.07033 5.38491L6.0383 4.87503L7.00627 5.38491L6.8214 4.30497L7.60451 3.54016L6.52228 3.3826L6.0383 2.40003L5.55431 3.3826L4.47209 3.54016L5.25519 4.30497L5.07033 5.38491Z" fill="%23F2C94C"/>%0A</g>%0A</svg>%0A';
831
-
832
- // packages/react-ui/src/lib/gamification/user-statistics/components/statistics/styles.tsx
833
- var import_styled7 = __toESM(require("@emotion/styled"), 1);
834
- var Container4 = import_styled7.default.div`
835
- font-weight: 700;
836
- display: flex;
837
- flex-direction: column;
838
- row-gap: 4px;
839
- align-items: center;
840
- text-align: center;
841
- `;
842
- var Indicator = import_styled7.default.div`
843
- font-size: 18px;
844
- color: #fff;
845
- `;
846
-
847
- // packages/react-ui/src/lib/gamification/user-statistics/components/statistics/index.tsx
848
- var import_jsx_runtime7 = require("@emotion/react/jsx-runtime");
849
- var Statistics = ({ indicator, title: title2 }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Container4, { children: [
850
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Indicator, { children: indicator }),
851
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: title2 })
852
- ] });
853
-
854
- // packages/react-ui/src/lib/gamification/user-statistics/components/rank/styles.tsx
855
- var import_styled8 = __toESM(require("@emotion/styled"), 1);
856
- var Container5 = import_styled8.default.div`
857
- display: flex;
858
- justify-content: flex-end;
859
- align-items: center;
860
- column-gap: 2px;
861
- overflow: hidden;
862
- `;
863
- var Title4 = import_styled8.default.div`
864
- width: 75px;
865
- `;
866
- var Indicator2 = import_styled8.default.div`
867
- font-size: 14px;
868
- color: #fff;
869
- overflow: hidden;
870
- text-overflow: ellipsis;
871
- white-space: nowrap;
872
- width: 25px;
873
- `;
874
-
875
- // packages/react-ui/src/lib/gamification/user-statistics/components/rank/index.tsx
876
- var import_jsx_runtime8 = require("@emotion/react/jsx-runtime");
877
- var Rank = ({ indicator, title: title2 }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Container5, { children: [
878
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Title4, { children: title2 }),
879
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Indicator2, { children: indicator })
880
- ] });
881
-
882
- // packages/react-ui/src/lib/gamification/user-statistics/styles.tsx
883
- var import_styled9 = __toESM(require("@emotion/styled"), 1);
884
- var Container6 = import_styled9.default.div`
885
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_USER_CONTAINER};
886
- border-radius: 12px;
887
- color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
888
- font-size: 10px;
889
- font-weight: 600;
890
- `;
891
- var TopInfo = import_styled9.default.div`
892
- padding: 12px;
893
- border-bottom: ${(props) => `1px solid ${props.theme.COLORS.DIVIDER_COLOR_PRIMARY}`};
894
- display: flex;
895
- justify-content: space-between;
896
- align-items: center;
897
- column-gap: 5px;
898
- `;
899
- var BottomInfo = import_styled9.default.div`
900
- padding: 12px 16px;
901
- text-transform: uppercase;
902
- display: flex;
903
- justify-content: space-between;
904
- column-gap: 16px;
905
- `;
906
- var User = import_styled9.default.div`
907
- display: flex;
908
- column-gap: 8px;
909
- flex: 1;
910
- overflow: hidden;
911
- `;
912
- var Avatar = import_styled9.default.img`
913
- width: 100%;
914
- height: 100%;
915
- max-width: 48px;
916
- max-height: 48px;
917
- border-radius: 50%;
918
- object-fit: cover;
919
- object-position: center;
920
- flex-shrink: 0;
921
- `;
922
- var UserInfo = import_styled9.default.div`
923
- padding-top: 4px;
924
- display: flex;
925
- flex-direction: column;
926
- row-gap: 4px;
927
- overflow: hidden;
928
- `;
929
- var UserName = import_styled9.default.div`
930
- font-size: 18px;
931
- color: ${(props) => props.theme.COLORS.WHITE};
932
- overflow: hidden;
933
- text-overflow: ellipsis;
934
- white-space: nowrap;
935
- `;
936
- var UserRating = import_styled9.default.div`
937
- text-transform: uppercase;
938
- display: flex;
939
- align-items: center;
940
- `;
941
- var TrophyIcon = import_styled9.default.img`
942
- width: 12px;
943
- height: 12px;
944
- margin-right: 4px;
945
- `;
946
- var Rts = import_styled9.default.div`
947
- display: flex;
948
- align-items: center;
949
- column-gap: 4px;
950
- border-right: ${(props) => `1px solid ${props.theme.COLORS.DIVIDER_COLOR_SECONDARY}`};
951
- padding-right: 5px;
952
- `;
953
- var RtsIndicator = import_styled9.default.div`
954
- font-size: 14px;
955
- color: ${(props) => props.theme.COLORS.WHITE};
956
- `;
957
- var Top = import_styled9.default.div`
958
- padding-left: 5px;
959
- `;
960
- var Ranks = import_styled9.default.div`
961
- text-transform: uppercase;
962
- display: flex;
963
- flex-direction: column;
964
- row-gap: 4px;
965
- `;
966
- var AvatarPlaceholder = import_styled9.default.div`
967
- background: #2d6ffd;
968
- border-radius: 50%;
969
- width: 48px;
970
- height: 48px;
971
- text-align: center;
972
- text-transform: uppercase;
973
- display: flex;
974
- align-items: center;
975
- justify-content: center;
976
- color: #fff;
977
- font-size: 18px;
978
- flex-shrink: 0;
979
- `;
980
-
981
- // packages/react-ui/src/lib/gamification/user-statistics/index.tsx
982
- var import_jsx_runtime9 = require("@emotion/react/jsx-runtime");
983
- var abbreviate = (name) => name.split(/\s+/).map((p) => p[0]).join("").toUpperCase();
984
- var UserStatistics = ({
985
- avatar,
986
- name,
987
- points,
988
- grade,
989
- friendsRank,
990
- globalRank,
991
- winStreak,
992
- correct,
993
- incorrect,
994
- successRate
995
- }) => {
996
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Container6, { children: [
997
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(TopInfo, { children: [
998
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(User, { children: [
999
- avatar && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Avatar, { alt: "avatar", src: avatar }),
1000
- !avatar && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AvatarPlaceholder, { children: abbreviate(name) }),
1001
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(UserInfo, { children: [
1002
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(UserName, { children: name }),
1003
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(UserRating, { children: [
1004
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(TrophyIcon, { alt: "rank-icon", src: icon_trophy_default }),
1005
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Rts, { children: [
1006
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(RtsIndicator, { children: points || "-" }),
1007
- "RTS"
1008
- ] }),
1009
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Top, { children: [
1010
- "TOP ",
1011
- grade,
1012
- "%"
1013
- ] })
1014
- ] })
1015
- ] })
1016
- ] }),
1017
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Ranks, { children: [
1018
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Rank, { title: "Friens rank", indicator: friendsRank || "-" }),
1019
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Rank, { title: "Global rank", indicator: globalRank || "-" })
1020
- ] })
1021
- ] }),
1022
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(BottomInfo, { children: [
1023
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Statistics, { indicator: winStreak || "-", title: "Win streak" }),
1024
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Statistics, { indicator: correct || "-", title: "Correct" }),
1025
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Statistics, { indicator: incorrect || "-", title: "Incorrect" }),
1026
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Statistics, { indicator: `${successRate || "-"}%`, title: "Success rate" })
1027
- ] })
1028
- ] });
1029
- };
1030
-
1031
- // packages/react-ui/src/lib/gamification/vote/index.tsx
1032
- var import_react4 = require("react");
1033
-
1034
- // packages/react-ui/src/assets/icons/icon-check.svg
1035
- var icon_check_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Checkmark">%0A<path id="Selected" fill-rule="evenodd" clip-rule="evenodd" d="M24 12.002C24 18.6294 18.6274 24.002 12 24.002C5.37258 24.002 0 18.6294 0 12.002C0 5.37454 5.37258 0.00195312 12 0.00195312C18.6274 0.00195312 24 5.37454 24 12.002ZM17.4086 8.15357C16.94 7.68494 16.1802 7.68494 15.7116 8.15357L10.4072 14.9579L7.62573 13.1036C7.07429 12.736 6.32925 12.885 5.96163 13.4365C5.59401 13.9879 5.74301 14.7329 6.29445 15.1006L9.89445 17.5006C10.3704 17.8179 11.0041 17.7551 11.4086 17.3506L17.4086 9.85063C17.8772 9.382 17.8772 8.6222 17.4086 8.15357Z" fill="%2300BD60"/>%0A</g>%0A</svg>%0A';
1036
-
1037
- // packages/react-ui/src/assets/icons/icon-close.svg
1038
- var icon_close_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<rect y="0.00195312" width="24" height="24" rx="12" fill="%23F80022"/>%0A<rect x="8.25" y="7.00195" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(45 8.25 7.00195)" fill="white"/>%0A<rect x="7" y="15.752" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(-45 7 15.752)" fill="white"/>%0A</svg>%0A';
1039
-
1040
- // packages/react-ui/src/assets/icons/icon-check-white.svg
1041
- var icon_check_white_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Checkmark">%0A<path id="Selected" fill-rule="evenodd" clip-rule="evenodd" d="M24 12.002C24 18.6294 18.6274 24.002 12 24.002C5.37258 24.002 0 18.6294 0 12.002C0 5.37454 5.37258 0.00195312 12 0.00195312C18.6274 0.00195312 24 5.37454 24 12.002ZM17.4086 8.15357C16.94 7.68494 16.1802 7.68494 15.7116 8.15357L10.4072 14.9579L7.62573 13.1036C7.07429 12.736 6.32925 12.885 5.96163 13.4365C5.59401 13.9879 5.74301 14.7329 6.29445 15.1006L9.89445 17.5006C10.3704 17.8179 11.0041 17.7551 11.4086 17.3506L17.4086 9.85063C17.8772 9.382 17.8772 8.6222 17.4086 8.15357Z" fill="%23FFFFFF"/>%0A</g>%0A</svg>%0A';
1042
-
1043
- // packages/react-ui/src/lib/gamification/vote/components/voting-option/styles.tsx
1044
- var import_styled10 = __toESM(require("@emotion/styled"), 1);
1045
- var Container7 = import_styled10.default.div`
1046
- box-sizing: border-box;
1047
- border-radius: 4px;
1048
- height: 44px;
1049
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM_VOTE};
1050
- border: 2px solid transparent;
1051
- position: relative;
1052
-
1053
- ${(props) => !props.questionAnswered && `
1054
- &:hover {
1055
- border-color: inherit;
1056
- }
1057
- `}
1058
- `;
1059
- var AnsweredContainer = (0, import_styled10.default)(Container7)`
1060
- background-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BG_TRANSPARENT_ITEM_SUCCESS : theme2.COLORS.BG_TRANSPARENT_ITEM_ERROR};
1061
- border: 2px solid;
1062
- border-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BLUE_PRIMARY : theme2.COLORS.RED_PRIMARY};
1063
-
1064
- &:hover {
1065
- border-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BLUE_PRIMARY : theme2.COLORS.RED_PRIMARY};
1066
- }
1067
- `;
1068
- var ButtonPct = import_styled10.default.div`
1069
- position: absolute;
1070
- left: 0;
1071
- border-radius: 2px;
1072
- z-index: 0;
1073
- height: 100%;
1074
- background-color: inherit;
1075
- transition: all 1s ease-in;
1076
- `;
1077
- var Button = import_styled10.default.button`
1078
- border-radius: 20px;
1079
- position: relative;
1080
- background-color: transparent;
1081
- padding: 0px 16px;
1082
- display: flex;
1083
- align-items: center;
1084
- border: none;
1085
- outline: none;
1086
- width: 100%;
1087
- color: ${(props) => props.theme.COLORS.WHITE};
1088
- font-weight: 700;
1089
- font-size: 14px;
1090
- height: 100%;
1091
- border-radius: 2px;
1092
- cursor: pointer;
1093
-
1094
- &:disabled {
1095
- cursor: default;
1096
- }
1097
- `;
1098
- var Icon2 = import_styled10.default.img`
1099
- width: 32px;
1100
- height: 32px;
1101
- border-radius: 50%;
1102
- margin-right: 8px;
1103
- `;
1104
- var Title5 = import_styled10.default.span`
1105
- overflow: hidden;
1106
- text-overflow: ellipsis;
1107
- white-space: nowrap;
1108
- padding: 8px 0px;
1109
- flex: 1;
1110
- text-align: left;
1111
- `;
1112
- var Indicators = import_styled10.default.span`
1113
- display: flex;
1114
- `;
1115
- var CheckIconWrap = import_styled10.default.div`
1116
- width: 16px;
1117
- height: 16px;
1118
- margin-left: 8px;
1119
- `;
1120
- var Percentage = import_styled10.default.div`
1121
- margin-left: 12px;
1122
- `;
1123
- var CheckIcon = import_styled10.default.img`
1124
- width: 16px;
1125
- height: 16px;
1126
- `;
1127
-
1128
- // packages/react-ui/src/lib/gamification/vote/components/voting-option/index.tsx
1129
- var import_jsx_runtime10 = require("@emotion/react/jsx-runtime");
1130
- var VotingOption = ({
1131
- icon,
1132
- id,
1133
- title: title2,
1134
- questionId,
1135
- disabled,
1136
- percentage,
1137
- onVote,
1138
- toggleIsLoadingSubmitAnswer,
1139
- correct,
1140
- questionAnswered,
1141
- hasCorrectAnswer,
1142
- answered
1143
- }) => {
1144
- if (questionAnswered && answered) {
1145
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(AnsweredContainer, { answeredCorrect: !hasCorrectAnswer || correct, questionAnswered: false, children: [
1146
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ButtonPct, { style: { width: `${percentage}%` } }),
1147
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Button, { disabled, onClick: () => onVote(questionId, id), children: [
1148
- icon && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon2, { alt: "option-icon", src: icon }),
1149
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Title5, { children: title2 }),
1150
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Indicators, { children: [
1151
- hasCorrectAnswer && correct && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CheckIconWrap, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CheckIcon, { alt: "icon-correct", src: answered ? icon_check_white_default : icon_check_default }) }),
1152
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Percentage, { children: [
1153
- percentage,
1154
- "%"
1155
- ] })
1156
- ] })
1157
- ] })
1158
- ] });
1159
- }
1160
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Container7, { questionAnswered, children: [
1161
- questionAnswered && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ButtonPct, { style: { width: `${percentage}%` } }),
1162
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1163
- Button,
1164
- {
1165
- disabled,
1166
- onClick: () => {
1167
- toggleIsLoadingSubmitAnswer(true);
1168
- onVote(questionId, id);
1169
- },
1170
- children: [
1171
- icon && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon2, { alt: "option-icon", src: icon }),
1172
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Title5, { children: title2 }),
1173
- questionAnswered && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Indicators, { children: [
1174
- hasCorrectAnswer && correct && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CheckIconWrap, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CheckIcon, { alt: "icon-correct", src: answered ? icon_check_white_default : icon_check_default }) }),
1175
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Percentage, { children: [
1176
- percentage,
1177
- "%"
1178
- ] })
1179
- ] })
1180
- ]
1181
- }
1182
- )
1183
- ] });
1184
- };
1185
-
1186
- // packages/react-ui/src/lib/gamification/vote/styles.tsx
1187
- var import_styled11 = __toESM(require("@emotion/styled"), 1);
1188
- var Container8 = import_styled11.default.div`
1189
- padding: 16px;
1190
- color: ${(props) => props.theme.COLORS.WHITE};
1191
- font-weight: 700;
1192
- font-size: 14px;
1193
-
1194
- & > div:not(:last-child) {
1195
- margin-bottom: 16px;
1196
- }
1197
- `;
1198
- var Title6 = import_styled11.default.div`
1199
- font-size: 16px;
1200
- `;
1201
- var Options = import_styled11.default.div`
1202
- overflow-y: auto;
1203
- max-height: 220px;
1204
- position: relative;
1205
-
1206
- & > div:not(:last-child) {
1207
- margin-bottom: 12px;
1208
- }
1209
- `;
1210
- var Loader = import_styled11.default.div`
1211
- position: absolute;
1212
- left: 0px;
1213
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_VOTE_CONTAINER};
1214
- width: 100%;
1215
- height: 100%;
1216
- z-index: 1;
1217
- display: flex;
1218
- justify-content: center;
1219
- align-items: center;
1220
- `;
1221
- var Feedback = import_styled11.default.div`
1222
- padding: 14px 12px 14px 16px;
1223
- display: flex;
1224
- align-items: center;
1225
- `;
1226
- var FeedbackIcon = import_styled11.default.img`
1227
- width: 24px;
1228
- height: 24px;
1229
- margin-right: 12px;
1230
- `;
1231
- var FeedbackTitle = import_styled11.default.div`
1232
- overflow: hidden;
1233
- text-overflow: ellipsis;
1234
- white-space: nowrap;
1235
- font-size: 16;
1236
- font-weight: 700;
1237
- margin-bottom: 10px;
1238
- `;
1239
- var FeedbackDescription = import_styled11.default.div`
1240
- display: -webkit-box;
1241
- -webkit-box-orient: vertical;
1242
- -webkit-line-clamp: 4;
1243
- overflow: hidden;
1244
- text-overflow: ellipsis;
1245
- font-size: 14;
1246
- font-weight: 500;
1247
- `;
1248
-
1249
- // packages/react-ui/src/lib/gamification/vote/index.tsx
1250
- var import_jsx_runtime11 = require("@emotion/react/jsx-runtime");
1251
- var Vote = ({
1252
- title: title2,
1253
- questionId,
1254
- options,
1255
- questionAnswered,
1256
- feedbackMessages,
1257
- questionAnsweredCorrectly,
1258
- questionType
1259
- }) => {
1260
- const [isLoadingSubmitAnswer, setIsLoadingSubmitAnswer] = (0, import_react4.useState)(false);
1261
- const toggleIsLoadingSubmitAnswer = (0, import_react4.useCallback)(
1262
- (flag) => {
1263
- setIsLoadingSubmitAnswer(flag);
1264
- },
1265
- [setIsLoadingSubmitAnswer]
1266
- );
1267
- (0, import_react4.useEffect)(() => {
1268
- toggleIsLoadingSubmitAnswer(false);
1269
- }, [options, toggleIsLoadingSubmitAnswer]);
1270
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(Container8, { children: [
1271
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Title6, { children: title2 }),
1272
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(Options, { children: [
1273
- isLoadingSubmitAnswer && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Loader, { children: "Loading..." }),
1274
- options.map((props) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1275
- VotingOption,
1276
- {
1277
- toggleIsLoadingSubmitAnswer,
1278
- questionId,
1279
- ...props
1280
- },
1281
- props.id
1282
- ))
1283
- ] }),
1284
- questionAnswered && questionType === import_interactive.QuestionType.TRIVIA && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(Feedback, { children: [
1285
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FeedbackIcon, { alt: "reaction-to-answer", src: questionAnsweredCorrectly ? icon_check_default : icon_close_default }),
1286
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { children: [
1287
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FeedbackTitle, { children: questionAnsweredCorrectly ? feedbackMessages.correctFeedback.title : feedbackMessages.incorrectFeedback.title }),
1288
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FeedbackDescription, { children: questionAnsweredCorrectly ? feedbackMessages.correctFeedback.description : feedbackMessages.incorrectFeedback.description })
1289
- ] })
1290
- ] })
1291
- ] });
1292
- };
1293
-
1294
- // packages/react-ui/src/lib/demo/index.tsx
1295
- var import_react12 = require("@nanostores/react");
1296
-
1297
- // packages/react-ui/src/lib/demo/Gamification.tsx
1298
- var import_react11 = require("@nanostores/react");
1299
-
1300
- // packages/react-ui/src/lib/demo/components/UserSummary.tsx
1301
- var import_react5 = require("@nanostores/react");
1302
- var import_jsx_runtime12 = require("@emotion/react/jsx-runtime");
1303
- var UserSummary = ({ store: store2 }) => {
1304
- const { data: user } = (0, import_react5.useStore)(store2);
1305
- if (!user?.summary) {
1306
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { children: "wait user..." });
1307
- }
1308
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1309
- UserStatistics,
1310
- {
1311
- avatar: user.summary.avatar,
1312
- name: user.summary.name,
1313
- points: user.summary.points,
1314
- grade: "0",
1315
- friendsRank: user.summary.friendsRank,
1316
- globalRank: user.summary.rank,
1317
- winStreak: user.summary.streak,
1318
- correct: user.summary.correct,
1319
- incorrect: user.summary.incorrect,
1320
- successRate: user.percentage?.correct
1321
- }
1322
- );
1323
- };
1324
-
1325
- // packages/react-ui/src/lib/demo/components/QuestionsList.tsx
1326
- var import_react6 = require("@nanostores/react");
1327
- var import_jsx_runtime13 = require("@emotion/react/jsx-runtime");
1328
- var QuestionsList = ({ store: store2, openQuestion }) => {
1329
- const { data: questions } = (0, import_react6.useStore)(store2);
1330
- if (!questions) {
1331
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { children: "wait questions..." });
1332
- }
1333
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(QuestionList, { openQuestion, questions });
1334
- };
1335
-
1336
- // packages/react-ui/src/lib/demo/components/Question.tsx
1337
- var import_styled14 = __toESM(require("@emotion/styled"), 1);
1338
- var import_react7 = require("@nanostores/react");
1339
- var import_react8 = require("react");
1340
-
1341
- // packages/react-ui/src/assets/icons/icon-trophy-green.svg
1342
- var icon_trophy_green_default = 'data:image/svg+xml,<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">%0A <g id="Trophy">%0A <path id="Combined Shape" fill-rule="evenodd" clip-rule="evenodd" d="M2.76916 3.50002C2.76916 4.49786 2.94705 5.38348 3.30282 6.15692C2.62493 6.01847 2.05883 5.74872 1.6045 5.34768C1.15017 4.94663 0.923008 4.55992 0.923008 4.18752V3.50002H2.76916ZM11.0768 3.50002V4.18752C11.0768 4.55992 10.8497 4.94663 10.3953 5.34768C9.941 5.74872 9.3749 6.01847 8.69701 6.15692C9.05278 5.38348 9.23066 4.49786 9.23066 3.50002H11.0768ZM12 4.1875V3.27083C12 3.07986 11.9327 2.91754 11.7981 2.78385C11.6635 2.65017 11.5 2.58333 11.3077 2.58333H9.23077V1.89583C9.23077 1.58073 9.11779 1.31098 8.89183 1.08659C8.66586 0.862195 8.39423 0.75 8.07692 0.75H3.92308C3.60577 0.75 3.33414 0.862195 3.10817 1.08659C2.88221 1.31098 2.76923 1.58073 2.76923 1.89583V2.58333H0.692308C0.499999 2.58333 0.336539 2.65017 0.201923 2.78385C0.067307 2.91754 0 3.07986 0 3.27083V4.1875C0 4.52648 0.0997586 4.86784 0.299279 5.21159C0.498799 5.55534 0.768027 5.86567 1.10697 6.14258C1.44592 6.41949 1.86178 6.65223 2.35457 6.84082C2.84736 7.02941 3.36538 7.13563 3.90865 7.15951C4.11058 7.41732 4.33894 7.6441 4.59375 7.83984C4.77644 8.00217 4.90264 8.17524 4.97236 8.35905C5.04207 8.54286 5.07692 8.75651 5.07692 9C5.07692 9.25781 5.00361 9.47504 4.85697 9.65169C4.71034 9.82834 4.47596 9.91667 4.15385 9.91667C3.79327 9.91667 3.47236 10.0253 3.19111 10.2425C2.90985 10.4597 2.76923 10.7331 2.76923 11.0625V11.5208C2.76923 11.5877 2.79087 11.6426 2.83413 11.6855C2.8774 11.7285 2.93269 11.75 3 11.75H9C9.06731 11.75 9.1226 11.7285 9.16586 11.6855C9.20913 11.6426 9.23077 11.5877 9.23077 11.5208V11.0625C9.23077 10.7331 9.09015 10.4597 8.80889 10.2425C8.52764 10.0253 8.20673 9.91667 7.84615 9.91667C7.52404 9.91667 7.28966 9.82834 7.14303 9.65169C6.99639 9.47504 6.92308 9.25781 6.92308 9C6.92308 8.75651 6.95793 8.54286 7.02764 8.35905C7.09736 8.17524 7.22356 8.00217 7.40625 7.83984C7.66106 7.6441 7.88942 7.41732 8.09135 7.15951C8.63462 7.13563 9.15264 7.02941 9.64543 6.84082C10.1382 6.65223 10.5541 6.41949 10.893 6.14258C11.232 5.86567 11.5012 5.55534 11.7007 5.21159C11.9002 4.86784 12 4.52648 12 4.1875ZM5.07033 5.38491L6.0383 4.87503L7.00627 5.38491L6.8214 4.30497L7.60451 3.54016L6.52228 3.3826L6.0383 2.40003L5.55431 3.3826L4.47209 3.54016L5.25519 4.30497L5.07033 5.38491Z" fill="white"/>%0A </g>%0A </svg>%0A';
1343
-
1344
- // packages/react-ui/src/assets/icons/icon-thumb-down.svg
1345
- var icon_thumb_down_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22" fill="none">%0A <path d="M5.5 2.78867V12.4137C5.5 13.1729 4.88426 13.75 4.125 13.75H1.375C0.615742 13.75 0 13.1343 0 12.4137V2.82734C0 2.06808 0.615742 1.49102 1.375 1.49102H4.125C4.88555 1.41367 5.5 1.99375 5.5 2.78867ZM22 12.3707C22 13.5094 21.077 14.4323 19.9375 14.4323H13.6426C14.621 16.0613 15.1259 17.9077 15.1259 18.5582C15.125 19.5714 14.3301 20.625 12.998 20.625C10.2854 20.625 11.8654 17.3529 8.34883 14.5406L7.64844 13.982C7.14141 13.5738 6.88359 12.9766 6.8793 12.375C6.87829 12.374 6.8793 12.375 6.8793 12.375L6.875 5.5C6.875 4.85117 7.18064 4.23973 7.7 3.85043L9.16695 2.75086C10.3555 1.85625 11.8035 1.375 13.2902 1.375H15.8125C16.952 1.375 17.875 2.29754 17.875 3.43664C17.875 3.59283 17.8544 3.74357 17.8215 3.88996C18.6484 4.15937 19.25 4.92422 19.25 5.84375C19.25 6.23683 19.1341 6.60043 18.9432 6.91281C19.8988 7.08984 20.625 7.92773 20.625 8.9332C20.625 9.47031 20.4148 9.955 20.0784 10.322C21.1492 10.3941 22 11.2793 22 12.3707Z" fill="white"/>%0A </svg>%0A';
1346
-
1347
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/styles.tsx
1348
- var import_styled12 = __toESM(require("@emotion/styled"), 1);
1349
- var Container9 = import_styled12.default.div`
1350
- box-sizing: border-box;
1351
- background-color: transparent;
1352
- color: ${(props) => props.theme.COLORS.WHITE};
1353
- display: flex;
1354
- flex-direction: row-reverse;
1355
- justify-content: space-between;
1356
- padding: 0px 16px;
1357
- align-items: center;
1358
- `;
1359
- var Logo = import_styled12.default.img`
1360
- width: 60px;
1361
- height: 80%;
1362
- `;
1363
- var RightBlock = import_styled12.default.div`
1364
- display: flex;
1365
- align-items: center;
1366
- `;
1367
- var ExitBtn = import_styled12.default.button`
1368
- border: none;
1369
- outline: none;
1370
- background-color: transparent;
1371
- border-radius: 50%;
1372
- padding: 0px;
1373
- width: 24px;
1374
- height: 24px;
1375
- margin-left: 25px;
1376
- cursor: pointer;
1377
- `;
1378
- var ExitIcon = import_styled12.default.img`
1379
- width: 24px;
1380
- height: 24px;
1381
- `;
1382
- var Interactive = import_styled12.default.div`
1383
- display: flex;
1384
- align-items: center;
1385
- padding: 4px 0px;
1386
- margin-left: 10px;
1387
- `;
1388
- var ReactionIconWrap = import_styled12.default.div`
1389
- background-color: ${(props) => props.isSuccess ? "#f1be1c" : "#da3732"};
1390
- width: 32px;
1391
- height: 32px;
1392
- border-radius: 50%;
1393
- display: flex;
1394
- justify-content: center;
1395
- align-items: center;
1396
- `;
1397
- var ReactionIcon = import_styled12.default.img`
1398
- width: 20px;
1399
- height: 20px;
1400
- `;
1401
-
1402
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/points/styles.tsx
1403
- var import_styled13 = __toESM(require("@emotion/styled"), 1);
1404
- var Container10 = import_styled13.default.div`
1405
- display: flex;
1406
- flex-direction: column;
1407
- align-items: flex-end;
1408
- margin-right: 10px;
1409
- font-weight: 700;
1410
- `;
1411
- var Title7 = import_styled13.default.div`
1412
- color: rgba(255, 255, 255, 0.8);
1413
- font-size: 8px;
1414
- line-height: 12px;
1415
- text-align: right;
1416
- `;
1417
- var PointContainer = import_styled13.default.div`
1418
- text-align: right;
1419
- `;
1420
- var Point = import_styled13.default.span`
1421
- color: rgba(255, 255, 255, 0.9);
1422
- font-size: 14px;
1423
- line-height: 16px;
1424
- margin-right: 2px;
1425
- `;
1426
- var PointLabel = import_styled13.default.span`
1427
- color: white;
1428
- font-size: 10px;
1429
- font-weight: 600;
1430
- line-height: 16px;
1431
- `;
1432
-
1433
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/points/index.tsx
1434
- var import_jsx_runtime14 = require("@emotion/react/jsx-runtime");
1435
- var Points = ({ points }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Container10, { children: [
1436
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Title7, { children: "YOU WON" }),
1437
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(PointContainer, { children: [
1438
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Point, { children: points }),
1439
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(PointLabel, { children: "PTS" })
1440
- ] })
1441
- ] });
1442
-
1443
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/index.tsx
1444
- var import_jsx_runtime15 = require("@emotion/react/jsx-runtime");
1445
- var VotingHeader = ({
1446
- logo,
1447
- points,
1448
- questionAnswered,
1449
- questionAnsweredCorrectly,
1450
- questionType,
1451
- closeQuestion,
1452
- setTimeToExpire
1453
- }) => {
1454
- const isShowTimer = !questionAnswered && questionType !== import_interactive.QuestionType.PREDICTION;
1455
- const isShowTriviaFeedback = questionAnswered && questionType === import_interactive.QuestionType.TRIVIA;
1456
- const successTriviaFeedback = isShowTriviaFeedback && questionAnsweredCorrectly;
1457
- const errorTriviaFeedback = isShowTriviaFeedback && !questionAnsweredCorrectly;
1458
- const isShowPredictionFeedback = questionAnswered && questionType === import_interactive.QuestionType.PREDICTION;
1459
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container9, { children: [
1460
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(RightBlock, { children: [
1461
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Interactive, { children: [
1462
- isShowTimer && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Timer, { setTimeToExpire }),
1463
- successTriviaFeedback && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1464
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Points, { points }),
1465
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ReactionIconWrap, { isSuccess: true, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ReactionIcon, { alt: "reaction-icon", src: icon_trophy_green_default }) })
1466
- ] }),
1467
- errorTriviaFeedback && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1468
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Points, { points: 0 }),
1469
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ReactionIconWrap, { isSuccess: false, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ReactionIcon, { alt: "reaction-icon", src: icon_thumb_down_default }) })
1470
- ] }),
1471
- isShowPredictionFeedback && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Points, { points })
1472
- ] }),
1473
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ExitBtn, { onClick: closeQuestion, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ExitIcon, { alt: "exit-icon", src: icon_exit_default }) })
1474
- ] }),
1475
- logo && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Logo, { src: logo })
1476
- ] });
1477
- };
1478
-
1479
- // packages/react-ui/src/assets/icons/fedex.svg
1480
- var fedex_default = 'data:image/svg+xml,<svg width="68" height="22" viewBox="0 0 68 22" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Vector">%0A<path fill-rule="evenodd" clip-rule="evenodd" d="M56.6155 7.44146H50.7066L56.3072 13.8615L50.7066 20.2805H56.4357L59.1587 17.137L61.9068 20.2805H67.84L62.19 13.8348L67.7636 7.44146H62.0606L59.3897 10.5602L56.6155 7.44146ZM62.2721 7.91659L59.3964 11.2747L56.4092 7.91659H51.7446L56.9307 13.8615L51.7447 19.8054H56.2257L59.1571 16.4213L62.1156 19.8054H66.7987L61.566 13.8357L66.7261 7.91659H62.2721Z" fill="white"/>%0A<path fill-rule="evenodd" clip-rule="evenodd" d="M44.3635 7.44146V4.56406H50.7066V0.0559998H39.702V20.2805H50.7066V15.7601H44.3635V11.7794H50.7066V7.44146H44.3635ZM50.2408 7.91659H43.8978V4.08893H50.2408V0.531132H40.1678V19.8054H50.2408V16.2352H43.8978V11.3043H50.2408V7.91659Z" fill="white"/>%0A<path d="M35.06 0.0559998V8.33281H35.0087C33.9803 7.12787 32.6966 6.70881 31.207 6.70881C28.1552 6.70881 25.8561 8.826 25.0493 11.6236C24.128 8.54092 21.7544 6.65084 18.2349 6.65084C15.3769 6.65084 13.1197 7.95936 11.9422 10.0918V7.44146H6.03416V4.56406H12.4815V0.0559998H0.768005V20.2805H6.03416V11.7794H11.2836C11.127 12.4037 11.0432 13.0727 11.0432 13.7788C11.0432 17.997 14.2031 20.958 18.2349 20.958C21.6258 20.958 23.8607 19.334 25.0419 16.374H20.5284C19.9183 17.2644 19.4553 17.5276 18.2349 17.5276C16.8199 17.5276 15.5995 16.2685 15.5995 14.7756H24.7894C25.1881 18.1262 27.7472 21.016 31.2582 21.016C32.773 21.016 34.1601 20.2558 35.0078 18.9729H35.059V20.2824H39.701L39.702 0.0559998H35.06ZM15.7467 11.8393C16.0392 10.5545 17.0164 9.71545 18.2358 9.71545C19.5782 9.71545 20.5051 10.5289 20.7492 11.8393C20.8517 11.8393 15.7467 11.8393 15.7467 11.8393ZM32.242 17.2016C30.5307 17.2016 29.4668 15.5748 29.4668 13.8767C29.4668 12.0617 30.3919 10.316 32.242 10.316C34.1601 10.316 34.924 12.0617 34.924 13.8767C34.924 15.5976 34.1144 17.2016 32.242 17.2016Z" fill="white"/>%0A</g>%0A</svg>%0A';
1481
-
1482
- // packages/react-ui/src/lib/demo/components/Question.tsx
1483
- var import_jsx_runtime16 = require("@emotion/react/jsx-runtime");
1484
- var QuestionContainer = import_styled14.default.div`
1485
- position: absolute;
1486
- top: 0;
1487
- background: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
1488
- width: 100%;
1489
- height: 100%;
1490
-
1491
- display: flex;
1492
- align-items: center;
1493
- justify-content: center;
1494
- flex-direction: column;
1495
-
1496
- > div {
1497
- width: 100%;
1498
- background: #000;
1499
- animation: slidein 0.3s ease-in;
1500
- }
1501
-
1502
- @keyframes slidein {
1503
- from {
1504
- transform: translateX(-100%);
1505
- }
1506
-
1507
- to {
1508
- transform: translateX(0);
1509
- }
1510
- }
1511
- `;
1512
- var Question2 = ({ store: store2, closeQuestion, vote }) => {
1513
- const { data: openedQuestion } = (0, import_react7.useStore)(store2);
1514
- const [answerTimeExpired, setAnswerTimeExpired] = (0, import_react8.useState)(false);
1515
- const setTimeToExpire = (0, import_react8.useCallback)(
1516
- (flag) => {
1517
- setAnswerTimeExpired(flag);
1518
- },
1519
- [setAnswerTimeExpired]
1520
- );
1521
- const questionAnswered = (0, import_react8.useMemo)(
1522
- () => openedQuestion?.answers.find((answer) => answer.youVoted === true),
1523
- [openedQuestion]
1524
- );
1525
- const hasCorrectAnswer = (0, import_react8.useMemo)(
1526
- () => !!openedQuestion?.answers.find((answer) => answer.correct === true),
1527
- [openedQuestion]
1528
- );
1529
- if (!openedQuestion) {
1530
- return null;
1531
- }
1532
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(QuestionContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { children: [
1533
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1534
- VotingHeader,
1535
- {
1536
- points: questionAnswered?.points || 0,
1537
- questionAnswered: !!questionAnswered,
1538
- questionAnsweredCorrectly: questionAnswered?.correct,
1539
- logo: fedex_default,
1540
- closeQuestion,
1541
- setTimeToExpire,
1542
- questionType: openedQuestion.type
1543
- }
1544
- ),
1545
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1546
- Vote,
1547
- {
1548
- title: openedQuestion.subject,
1549
- feedbackMessages: openedQuestion.options?.options.value,
1550
- questionType: openedQuestion.type,
1551
- questionId: openedQuestion.id,
1552
- questionAnswered: !!questionAnswered,
1553
- questionAnsweredCorrectly: questionAnswered?.correct,
1554
- options: openedQuestion.answers.map((answer) => ({
1555
- id: answer.id,
1556
- title: answer.text,
1557
- icon: answer.icon,
1558
- type: openedQuestion.type,
1559
- correct: answer.correct,
1560
- percentage: answer.percentage,
1561
- answered: answer.youVoted,
1562
- disabled: !!questionAnswered || openedQuestion.marketClosed || answerTimeExpired,
1563
- questionAnswered: !!questionAnswered,
1564
- hasCorrectAnswer,
1565
- onVote: vote
1566
- }))
1567
- }
1568
- ) })
1569
- ] }) });
1570
- };
1571
-
1572
- // packages/react-ui/src/lib/demo/components/Notifications.tsx
1573
- var import_react9 = require("@nanostores/react");
1574
- var import_react10 = require("react");
1575
- var import_jsx_runtime17 = require("@emotion/react/jsx-runtime");
1576
- var Notifications = ({ notificationsStore, openQuestion }) => {
1577
- const timeout = (0, import_react10.useRef)();
1578
- const [lastNotification, setLastNotification] = (0, import_react10.useState)();
1579
- const notifications2 = (0, import_react9.useStore)(notificationsStore);
1580
- (0, import_react10.useEffect)(() => {
1581
- if (notifications2) {
1582
- setLastNotification(notifications2[notifications2.length - 1]?.data);
1583
- timeout.current = setTimeout(() => {
1584
- setLastNotification(void 0);
1585
- }, 5e3);
1586
- }
1587
- return () => {
1588
- if (timeout.current) {
1589
- clearTimeout(timeout.current);
1590
- }
1591
- };
1592
- }, [notifications2]);
1593
- if (!lastNotification?.question || !lastNotification?.notification) {
1594
- return null;
1595
- }
1596
- const closeInApp = () => {
1597
- if (timeout.current) {
1598
- clearTimeout(timeout.current);
1599
- }
1600
- setLastNotification(void 0);
1601
- };
1602
- const openVoiting = () => {
1603
- closeInApp();
1604
- openQuestion(lastNotification.question.id);
1605
- };
1606
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1607
- InApp,
1608
- {
1609
- openVoiting,
1610
- closeInApp,
1611
- title: lastNotification.notification.title,
1612
- icon: lastNotification.notification.image,
1613
- color: lastNotification.notification.indicatorColor
1614
- }
1615
- );
1616
- };
1617
-
1618
- // packages/react-ui/src/lib/demo/components/InPlayGame.tsx
1619
- var import_jsx_runtime18 = require("@emotion/react/jsx-runtime");
1620
- var InPlayGame = ({ action }) => {
1621
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Onboarding, { action });
1622
- };
1623
-
1624
- // packages/react-ui/src/lib/demo/styles.tsx
1625
- var import_styled15 = __toESM(require("@emotion/styled"), 1);
1626
- var DemoContainer = import_styled15.default.div`
1627
- position: relative;
1628
- height: 100%;
1629
- overflow: hidden;
1630
- `;
1631
- var DemoContainerNotifications = import_styled15.default.div`
1632
- position: absolute;
1633
- width: 100%;
1634
- `;
1635
- var UserStatisticsContainer = import_styled15.default.div`
1636
- margin-bottom: 15px;
1637
- `;
1638
-
1639
- // packages/react-ui/src/lib/demo/Gamification.tsx
1640
- var import_jsx_runtime19 = require("@emotion/react/jsx-runtime");
1641
- var GamificationComponent = ({
1642
- gamification,
1643
- sdk
1644
- }) => {
1645
- const onbordingComplete = (0, import_react11.useStore)(gamification.onbordingComplete);
1646
- const { slStreamId } = (0, import_react11.useStore)(sdk.sdkStore);
1647
- if (slStreamId?.loading) {
1648
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DemoContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: "Event is loading" }) });
1649
- }
1650
- if (!slStreamId?.data) {
1651
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DemoContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: "Event is forbidden" }) });
1652
- }
1653
- if (!onbordingComplete) {
1654
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DemoContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(InPlayGame, { action: gamification.submitInplay }) });
1655
- }
1656
- const openQuestion = (questionId) => {
1657
- gamification.openQuestion(questionId);
1658
- };
1659
- const closeQuestion = () => {
1660
- gamification.closeQuestion();
1661
- };
1662
- const vote = (questionId, answerId) => {
1663
- void gamification.submitAnswer(questionId, answerId);
1664
- };
1665
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DemoContainer, { children: [
1666
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DemoContainerNotifications, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Notifications, { notificationsStore: sdk.getNotificationsStore(), openQuestion }) }),
1667
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(UserStatisticsContainer, { children: gamification.userSummary && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(UserSummary, { store: gamification.userSummary.getStore() }) }),
1668
- gamification.questions && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(QuestionsList, { openQuestion, store: gamification.questions.getStore() }),
1669
- gamification.openedQuestion && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Question2, { closeQuestion, vote, store: gamification.openedQuestion.getStore() })
1670
- ] });
1671
- };
1672
-
1673
- // packages/react-ui/src/lib/demo/Login.tsx
1674
- var import_jsx_runtime20 = require("@emotion/react/jsx-runtime");
1675
- var LoginComponent = ({ sdk }) => {
1676
- const login2 = async (token) => {
1677
- try {
1678
- await sdk.authorizationBypass("streamlayer:streamlayer", token);
1679
- } catch (err) {
1680
- console.log("login err", err);
1681
- throw err;
1682
- }
1683
- };
1684
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Login, { login: login2, anonymousLogin: sdk.anonymousAuthorization, host: sdk.host });
1685
- };
1686
-
1687
- // packages/react-ui/src/lib/demo/index.tsx
1688
- var import_jsx_runtime21 = require("@emotion/react/jsx-runtime");
1689
- var Demo = ({ sdk }) => {
1690
- const organization = (0, import_react12.useStore)(sdk.organizationStore());
1691
- const user = (0, import_react12.useStore)(sdk.getUserStore());
1692
- if (organization.loading) {
1693
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { children: "authentificating..." });
1694
- }
1695
- if (!organization.data) {
1696
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { children: "wrong sdk key..." });
1697
- }
1698
- if (user.loading) {
1699
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { children: "authentificating..." });
1700
- }
1701
- if (!user.data) {
1702
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(LoginComponent, { sdk });
1703
- }
1704
- const gamification = sdk.getFeatures().get("games");
1705
- if (!gamification) {
1706
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { children: "wait gamification..." });
1707
- }
1708
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(GamificationComponent, { gamification, sdk });
1709
- };
1710
-
1711
- // packages/react-ui/src/lib/theme/index.tsx
1712
- var import_react13 = require("@emotion/react");
1713
- var import_jsx_runtime22 = require("@emotion/react/jsx-runtime");
1714
- var StreamLayerThemeProvider = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react13.ThemeProvider, { theme, children });
1715
-
1716
- // packages/react/src/app/provider.tsx
1717
- var import_react15 = require("react");
1718
-
1719
- // packages/sdk-web-interfaces/src/auth.ts
1720
- var AbstractAuthenticationProvider = class {
1721
- };
1722
-
1723
- // packages/sdk-web-interfaces/src/feature.ts
1724
- var import_sdkSettings2 = require("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb");
1725
- var import_nanostores3 = require("nanostores");
1726
-
1727
- // packages/sdk-web-interfaces/src/store/map.ts
1728
- var import_nanostores2 = require("nanostores");
1729
-
1730
- // packages/sdk-web-interfaces/src/store/abstract.ts
1731
- var import_nanostores = require("nanostores");
1732
- var import_logger = require("@nanostores/logger");
1733
- var import_microdiff = __toESM(require("microdiff"), 1);
1734
- window.storeLogger = /* @__PURE__ */ Object.create(null);
1735
- var slStoreLogger = (store2, name) => (0, import_logger.buildLogger)(store2, name, {
1736
- mount: ({ storeName }) => {
1737
- if (!window.storeLogger[storeName]) {
1738
- window.storeLogger[storeName] = { mounted: true, history: [{ type: "mount" }] };
1739
- }
1740
- window.storeLogger[storeName].store = store2;
1741
- },
1742
- unmount: ({ storeName }) => {
1743
- window.storeLogger[storeName].mounted = false;
1744
- window.storeLogger[storeName]?.history.push({ type: "unmount" });
1745
- },
1746
- change: ({ actionName, storeName, changed, newValue, oldValue, valueMessage }) => {
1747
- window.storeLogger[storeName]?.history.push({
1748
- type: "change",
1749
- changed,
1750
- newValue,
1751
- oldValue,
1752
- diff: (0, import_microdiff.default)({ ...oldValue }, { ...newValue }, { cyclesFix: false }),
1753
- actionName,
1754
- valueMessage
1755
- });
1756
- },
1757
- action: {
1758
- start: ({ actionName, args, storeName }) => {
1759
- window.storeLogger[storeName]?.history.push({
1760
- type: "action:start",
1761
- actionName,
1762
- args,
1763
- storeName
1764
- });
1765
- },
1766
- error: ({ actionName, error, storeName }) => {
1767
- window.storeLogger[storeName]?.history.push({
1768
- type: "action:error",
1769
- actionName,
1770
- error
1771
- });
1772
- },
1773
- end: ({ actionName, storeName }) => {
1774
- window.storeLogger[storeName]?.history.push({
1775
- type: "action:end",
1776
- actionName
1777
- });
1778
- }
1779
- }
1780
- });
1781
- var AbstractStore = class {
1782
- /**
1783
- * store instance (nanostores)
1784
- */
1785
- store;
1786
- name;
1787
- constructor(store2, name) {
1788
- this.store = store2;
1789
- this.name = name;
1790
- if (process.env.NODE_ENV !== "production") {
1791
- slStoreLogger(this.store, this.name);
1792
- }
1793
- }
1794
- /**
1795
- * return store instance
1796
- */
1797
- getStore() {
1798
- return this.store;
1799
- }
1800
- };
1801
- var mergeStores = (stores) => {
1802
- const storeKeys = Object.keys(stores);
1803
- return (0, import_nanostores.computed)(
1804
- storeKeys.map((key) => stores[key].getStore()),
1805
- (...storeValues) => Object.fromEntries(storeKeys.map((key, i) => [key, storeValues[i]]))
1806
- );
1807
- };
1808
-
1809
- // packages/sdk-web-interfaces/src/store/map.ts
1810
- var MapStore = class extends AbstractStore {
1811
- getValues = () => {
1812
- const store2 = this.getStore();
1813
- return store2.get();
1814
- };
1815
- getValue = (key) => {
1816
- const store2 = this.getStore();
1817
- return store2.get()[key];
1818
- };
1819
- setValue = (path, value) => {
1820
- const store2 = this.getStore();
1821
- return store2.setKey(path, value);
1822
- };
1823
- subscribe = (...args) => {
1824
- const store2 = this.getStore();
1825
- return store2.subscribe(...args);
1826
- };
1827
- unsubscribe = () => {
1828
- const store2 = this.getStore();
1829
- return store2.off();
1830
- };
1831
- };
1832
- var createMapStore = (initialData) => {
1833
- return (0, import_nanostores2.map)(initialData);
1834
- };
1835
-
1836
- // packages/sdk-web-interfaces/src/feature.ts
1837
- var FeatureTypes = {
1838
- [import_sdkSettings2.SdkOverlayType.BETTING]: "betting",
1839
- [import_sdkSettings2.SdkOverlayType.GAMES]: "games",
1840
- [import_sdkSettings2.SdkOverlayType.PUBLIC_CHAT]: "publicChat",
1841
- [import_sdkSettings2.SdkOverlayType.TWITTER]: "twitter"
1842
- };
1843
- var AbstractFeature = class {
1844
- status;
1845
- source;
1846
- config;
1847
- settings;
1848
- listeners = /* @__PURE__ */ new Set();
1849
- settingsKey;
1850
- constructor({ settings, ...config2 }, source) {
1851
- this.settingsKey = FeatureTypes[config2.type];
1852
- this.status = (0, import_nanostores3.atom)("suspended" /* Suspended */);
1853
- this.config = new MapStore(createMapStore(config2), `feature:config:${this.settingsKey}`);
1854
- if (this.settingsKey !== void 0 && settings?.overlaySettings.case === this.settingsKey) {
1855
- this.settings = new MapStore(
1856
- createMapStore(settings.overlaySettings.value),
1857
- `feature:settings:${this.settingsKey}`
1858
- );
1859
- } else {
1860
- this.settings = new MapStore(createMapStore({}), `feature:settings:${this.settingsKey}`);
1861
- }
1862
- this.source = source;
1863
- }
1864
- get featureConfig() {
1865
- return this.config.getStore();
1866
- }
1867
- get featureSettings() {
1868
- return this.settings.getStore();
1869
- }
1870
- registerEventListener(listener) {
1871
- this.listeners.add(listener);
1872
- }
1873
- enable = () => {
1874
- this.status.set("ready" /* Ready */);
1875
- };
1876
- disabled = () => {
1877
- this.status.set("suspended" /* Suspended */);
1878
- };
1879
- setFeatureConfig = ({ settings, ...config2 }) => {
1880
- let configKey;
1881
- for (configKey in config2) {
1882
- this.config.setValue(configKey, config2[configKey]);
1883
- }
1884
- if (settings?.overlaySettings.case === this.settingsKey) {
1885
- const newSettings = settings.overlaySettings.value;
1886
- if (newSettings !== void 0) {
1887
- let key;
1888
- for (key in newSettings) {
1889
- console.log(key, newSettings[key]);
1890
- if (newSettings[key] !== 0 && newSettings[key] !== "") {
1891
- this.settings.setValue(key, newSettings[key]);
1892
- }
1893
- }
1894
- }
1895
- }
1896
- };
1897
- update = (config2, source) => {
1898
- if (this.source === "STREAM" /* STREAM */ && source === "ORGANIZATION" /* ORGANIZATION */) {
1899
- return;
1900
- }
1901
- this.setFeatureConfig(config2);
1902
- this.source = source;
1903
- };
1904
- fireEvent(event) {
1905
- for (const listener of this.listeners.values()) {
1906
- try {
1907
- listener.onEvent(event);
1908
- } catch (err) {
1909
- console.error(err);
1910
- }
1911
- }
1912
- }
1913
- };
1914
-
1915
- // packages/sdk-web-interfaces/src/store/single.ts
1916
- var import_nanostores4 = require("nanostores");
1917
- var SingleStore = class extends AbstractStore {
1918
- getValue = () => {
1919
- const store2 = this.getStore();
1920
- return store2.get();
1921
- };
1922
- getValues() {
1923
- throw new Error("not implemented");
1924
- }
1925
- setValue = (value) => {
1926
- const store2 = this.getStore();
1927
- return store2.set(value);
1928
- };
1929
- subscribe = (listener) => {
1930
- const store2 = this.getStore();
1931
- return store2.subscribe(listener);
1932
- };
1933
- unsubscribe = () => {
1934
- const store2 = this.getStore();
1935
- return store2.off();
1936
- };
1937
- listen(listener) {
1938
- const store2 = this.getStore();
1939
- return store2.listen(listener);
1940
- }
1941
- get() {
1942
- const store2 = this.getStore();
1943
- return store2.get();
1944
- }
1945
- };
1946
- var createSingleStore = (initialData) => (0, import_nanostores4.atom)(initialData);
1947
-
1948
- // packages/sdk-web-interfaces/src/store/api.ts
1949
- var import_nanostores5 = require("nanostores");
1950
- var ApiStore = class extends AbstractStore {
1951
- atomStore;
1952
- constructor(store2, name, atomPicker) {
1953
- super(store2, `api:${name}`);
1954
- this.atomStore = (0, import_nanostores5.atom)();
1955
- if (atomPicker) {
1956
- store2.subscribe((data) => {
1957
- this.atomStore.set(atomPicker(data));
1958
- });
1959
- }
1960
- }
1961
- getAtomStore = () => this.atomStore;
1962
- getValue = async () => {
1963
- const store2 = this.getStore();
1964
- if (store2.value === void 0) {
1965
- throw new Error("no store");
1966
- }
1967
- await store2.value.promise;
1968
- return store2.get().data;
1969
- };
1970
- getValues = () => {
1971
- throw new Error("not implemented");
1972
- };
1973
- setValue = (value) => {
1974
- const store2 = this.getStore();
1975
- return store2.set({ loading: false, data: value?.data });
1976
- };
1977
- subscribe = (listener) => {
1978
- const store2 = this.getStore();
1979
- return store2.subscribe(listener);
1980
- };
1981
- unsubscribe = () => {
1982
- throw new Error("not implemented");
1983
- };
1984
- invalidate = () => {
1985
- this.store.invalidate();
1986
- };
1987
- listen = (cb) => {
1988
- const store2 = this.getStore();
1989
- return store2.listen(cb);
1990
- };
1991
- get() {
1992
- throw new Error("not implemented");
1993
- }
1994
- key = () => {
1995
- const store2 = this.getStore();
1996
- return store2.key;
1997
- };
1998
- off = () => {
1999
- const store2 = this.getStore();
2000
- return store2.off();
2001
- };
2002
- };
2003
-
2004
- // packages/sdk-web-api/src/grpc/transport.ts
2005
- var import_connect3 = require("@connectrpc/connect");
2006
- var import_connect_web2 = require("@bufbuild/connect-web");
2007
- var import_query = require("@nanostores/query");
2008
-
2009
- // packages/sdk-web-api/src/utils/devtools.ts
2010
- async function* logEach(store2, stream) {
2011
- for await (const m of stream) {
2012
- store2.response.message = m;
2013
- store2.received_at = Date.now();
2014
- const msg = {
2015
- type: "__GRPC_DEVTOOLS_EXTENSION__",
2016
- data: store2
2017
- };
2018
- window.postMessage(msg);
2019
- yield m;
2020
- }
2021
- }
2022
- var __GRPC_DEVTOOLS_EXTENSION__ = () => (next) => async (request) => {
2023
- const store2 = {
2024
- name: request.url,
2025
- request: {},
2026
- response: {}
2027
- };
2028
- store2.request.header = Object.fromEntries(request.header.entries());
2029
- store2.sent_at = Date.now();
2030
- try {
2031
- const response = await next(request);
2032
- store2.received_at = Date.now();
2033
- store2.stream = response.stream;
2034
- store2.response.header = Object.fromEntries(response.header.entries());
2035
- store2.response.trailer = Object.fromEntries(response.trailer.entries());
2036
- if (!response.stream) {
2037
- store2.request.message = request.message;
2038
- store2.response.message = response.message;
2039
- store2.latency = store2.received_at - store2.sent_at;
2040
- const msg = {
2041
- type: "__GRPC_DEVTOOLS_EXTENSION__",
2042
- data: store2
2043
- };
2044
- window.postMessage(msg);
2045
- } else {
2046
- return {
2047
- ...response,
2048
- message: logEach(store2, response.message)
2049
- };
2050
- }
2051
- return response;
2052
- } catch (e) {
2053
- store2.received_at = Date.now();
2054
- store2.request.message = request.message;
2055
- store2.response.trailer = {
2056
- ["grpc-status"]: e.code,
2057
- ["grpc-message"]: e.rawMessage
2058
- };
2059
- store2.response.message = e.rawMessage;
2060
- store2.latency = store2.received_at - store2.sent_at;
2061
- const msg = {
2062
- type: "__GRPC_DEVTOOLS_EXTENSION__",
2063
- data: store2
2064
- };
2065
- window.postMessage(msg);
2066
- throw e;
2067
- }
2068
- };
2069
- window.dispatchEvent(new CustomEvent("grpc_devtools_loaded"));
2070
-
2071
- // packages/sdk-web-api/src/grpc/subscription.ts
2072
- var import_connect2 = require("@connectrpc/connect");
2073
- var ServerStreamSubscription = class {
2074
- params;
2075
- stream;
2076
- method;
2077
- name;
2078
- headers;
2079
- listeners;
2080
- state;
2081
- store;
2082
- constructor(headers, method, params, options) {
2083
- const initState = {
2084
- status: "init" /* Init */,
2085
- ts: /* @__PURE__ */ new Date(),
2086
- log: []
2087
- };
2088
- this.state = new MapStore(createMapStore(initState), `subscription:${options.name}:state`);
2089
- this.name = options.name;
2090
- this.headers = headers;
2091
- this.listeners = /* @__PURE__ */ new Map();
2092
- this.params = params;
2093
- this.method = method;
2094
- if (options.withStore) {
2095
- this.store = new SingleStore(createSingleStore(null), `subscription:${options.name}:store`);
2096
- }
2097
- if ("subscribe" in params && typeof params.subscribe === "function") {
2098
- params.subscribe(() => {
2099
- this.reconnect();
2100
- });
2101
- }
2102
- this.updateState("ready" /* Ready */);
2103
- }
2104
- updateState = (status) => {
2105
- this.state.setValue("status", status);
2106
- this.state.setValue("ts", /* @__PURE__ */ new Date());
2107
- this.addStateLog(`status => ${status}`);
2108
- };
2109
- addStateLog = (msg) => {
2110
- const log = this.state.getStore().get()["log"];
2111
- this.state.setValue("log", [...log, `${(/* @__PURE__ */ new Date()).toLocaleString()}: ${msg}`]);
2112
- };
2113
- addListener = (name, listener) => {
2114
- if (this.listeners.has(name)) {
2115
- this.addStateLog(`listener '${name}' not added`);
2116
- return false;
2117
- }
2118
- this.listeners.set(name, listener);
2119
- this.addStateLog(`listener '${name}' added`);
2120
- return true;
2121
- };
2122
- removeListener = (name) => {
2123
- this.listeners.delete(name);
2124
- this.addStateLog(`listener '${name}' removed`);
2125
- };
2126
- connect = () => {
2127
- this.updateState("connecting" /* Connecting */);
2128
- if (this.stream) {
2129
- this.addStateLog(`disconnect prev connection`);
2130
- this.stream();
2131
- }
2132
- const params = "get" in this.params && typeof this.params.get === "function" ? this.params.get() : this.params;
2133
- this.stream = this.method(
2134
- params,
2135
- // ToDo: fix types
2136
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2137
- // @ts-ignore
2138
- this.onData,
2139
- this.onStreamError,
2140
- { headers: this.headers.getValues() }
2141
- );
2142
- this.updateState("connected" /* Connected */);
2143
- };
2144
- disconnect = () => {
2145
- if (this.stream) {
2146
- this.stream();
2147
- }
2148
- this.listeners.clear();
2149
- this.updateState("disconnected" /* Disconnected */);
2150
- };
2151
- reconnect = () => {
2152
- this.updateState("reconnecting" /* Reconnecting */);
2153
- this.connect();
2154
- };
2155
- getStore = () => this.store?.getStore();
2156
- onData = (response) => {
2157
- this.addStateLog(`received data => ${JSON.stringify(response)}`);
2158
- if (this.store) {
2159
- this.store.setValue(response);
2160
- }
2161
- for (const [, listener] of this.listeners) {
2162
- listener(response);
2163
- }
2164
- this.addStateLog(`data routed to ${this.listeners.size} listeners`);
2165
- };
2166
- onStreamError = (error) => {
2167
- if (error.code !== import_connect2.Code.Canceled && error.rawMessage !== "[canceled] BodyStreamBuffer was aborted") {
2168
- this.updateState("failed" /* Failed */);
2169
- this.state.setValue("error", error);
2170
- } else {
2171
- this.disconnect();
2172
- }
2173
- };
2174
- };
2175
-
2176
- // packages/sdk-web-api/src/grpc/transport.ts
2177
- var Transport = class {
2178
- toJsonOptions = {
2179
- emitDefaultValues: false,
2180
- enumAsInteger: true,
2181
- useProtoFieldName: false
2182
- };
2183
- transport;
2184
- nanoquery;
2185
- host;
2186
- interceptors = [];
2187
- $headers;
2188
- clients;
2189
- callbackClients;
2190
- subscriptions;
2191
- constructor(host) {
2192
- this.host = host;
2193
- this.$headers = new MapStore(
2194
- createMapStore({
2195
- ["sl-device-id"]: process.env.NX_DEVICE_ID || "sdk-web-dev"
2196
- }),
2197
- "transport:headers"
2198
- );
2199
- this.initInterceptors();
2200
- this.clients = /* @__PURE__ */ new Map();
2201
- this.callbackClients = /* @__PURE__ */ new Map();
2202
- this.subscriptions = /* @__PURE__ */ new Map();
2203
- const [createFetcherStore, createMutatorStore, utils] = (0, import_query.nanoquery)();
2204
- this.nanoquery = { createFetcherStore, createMutatorStore, utils };
2205
- this.transport = (0, import_connect_web2.createGrpcWebTransport)({
2206
- baseUrl: host,
2207
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2208
- // @ts-ignore
2209
- interceptors: this.interceptors,
2210
- useBinaryFormat: true
2211
- });
2212
- }
2213
- // use shared request params, based on Atom, each new Atom will create new subscription
2214
- // mutate Atom, subscription automatically reconnect with new params
2215
- // if headers changed, reconnect subscription with new headers automatically
2216
- addSubscription = (method, params, options) => {
2217
- const currentSubscription = this.subscriptions.get(params);
2218
- if (currentSubscription) {
2219
- return currentSubscription;
2220
- }
2221
- const subscription = new ServerStreamSubscription(this.$headers, method, params, options);
2222
- this.subscriptions.set(params, subscription);
2223
- return subscription;
2224
- };
2225
- removeSubscription = (subscription) => {
2226
- subscription.disconnect();
2227
- this.subscriptions.delete(subscription.params);
2228
- };
2229
- // cleanup subscriptions
2230
- disconnect = () => {
2231
- for (const [name, subscription] of this.subscriptions) {
2232
- subscription.disconnect();
2233
- this.subscriptions.delete(name);
2234
- }
2235
- };
2236
- registerInterceptor = (interceptor) => {
2237
- this.interceptors.push(interceptor);
2238
- };
2239
- removeInterceptor = (interceptor) => {
2240
- this.interceptors = this.interceptors.filter((i) => i !== interceptor);
2241
- };
2242
- getClient = (service) => {
2243
- const serviceName = service.typeName;
2244
- if (this.clients.has(serviceName)) {
2245
- return this.clients.get(serviceName);
2246
- }
2247
- const client = (0, import_connect3.createPromiseClient)(service, this.transport);
2248
- this.clients.set(serviceName, client);
2249
- return client;
2250
- };
2251
- getCallbackClient = (service) => {
2252
- const serviceName = service.typeName;
2253
- if (this.callbackClients.has(serviceName)) {
2254
- return this.callbackClients.get(serviceName);
2255
- }
2256
- const client = (0, import_connect3.createCallbackClient)(service, this.transport);
2257
- this.callbackClients.set(serviceName, client);
2258
- return client;
2259
- };
2260
- // create unary client, used for query request
2261
- createPromiseClient = (service, { params = [], method }) => {
2262
- const client = this.getClient(service);
2263
- const methodName = service.methods[method].name;
2264
- const queryKey = [
2265
- service.typeName,
2266
- methodName.charAt(0).toLowerCase() + methodName.slice(1),
2267
- ...Array.isArray(params) ? params : [params]
2268
- ];
2269
- const queryKeyWithoutParams = [service.typeName, methodName.charAt(0).toLowerCase() + methodName.slice(1)];
2270
- return { client, queryKey, queryKeyStr: queryKeyWithoutParams.join("") };
2271
- };
2272
- // create callback client, used for server stream subscriptions
2273
- createCallbackClient = (service) => {
2274
- const client = this.getCallbackClient(service);
2275
- return { client };
2276
- };
2277
- setSdkKey = (sdkKey) => {
2278
- this.$headers.setValue("sdk", sdkKey);
2279
- };
2280
- setAuth = (token) => {
2281
- this.$headers.setValue("authorization", token);
2282
- };
2283
- setHeader = (name, value) => this.$headers.setValue(name, value);
2284
- getHeader = (name) => this.$headers.getValue(name);
2285
- getHeaders = () => this.$headers.getValues();
2286
- initInterceptors = () => {
2287
- if (this.interceptors.length !== 0) {
2288
- return;
2289
- }
2290
- const auth = (next) => (req) => {
2291
- const headers = this.$headers.getValues();
2292
- for (const header in headers) {
2293
- req.header.set(header, headers[header]);
2294
- }
2295
- return next(req);
2296
- };
2297
- this.interceptors.push(auth);
2298
- this.interceptors.push(__GRPC_DEVTOOLS_EXTENSION__());
2299
- };
2300
- };
2301
-
2302
- // packages/sdk-web-api/src/grpc/queries/index.ts
2303
- var queries_exports = {};
2304
- __export(queries_exports, {
2305
- $bypassLogin: () => $bypassLogin,
2306
- $organizationAdvertising: () => $organizationAdvertising,
2307
- $organizationSettings: () => $organizationSettings,
2308
- $retrieveEventId: () => $retrieveEventId,
2309
- $streamSettings: () => $streamSettings,
2310
- $user: () => $user,
2311
- $userSettings: () => $userSettings,
2312
- bypassAuth: () => bypassAuth,
2313
- register: () => register2
2314
- });
2315
-
2316
- // packages/sdk-web-api/src/grpc/queries/event.ts
2317
- var import_events_connect = require("@streamlayer/sl-eslib/sports/events/events_connect");
2318
- var import_client_connect = require("@streamlayer/sl-eslib/sdkSettings/client/client_connect");
2319
- var $retrieveEventId = ($providerStreamId, transport2) => {
2320
- const { client, queryKey } = transport2.createPromiseClient(import_events_connect.Events, {
2321
- method: "retrieveEventId",
2322
- params: [$providerStreamId]
2323
- });
2324
- return transport2.nanoquery.createFetcherStore(queryKey, {
2325
- fetcher: async (_, __, id) => {
2326
- if (!id || typeof id !== "string") {
2327
- return "";
2328
- }
2329
- try {
2330
- const res = await client.retrieveEventId({
2331
- id
2332
- });
2333
- return res.data?.id || "";
2334
- } catch (err) {
2335
- return "";
2336
- }
2337
- }
2338
- });
2339
- };
2340
- var $streamSettings = (slStreamId, transport2) => {
2341
- const { client, queryKey } = transport2.createPromiseClient(import_client_connect.Client, { method: "getStream", params: [slStreamId] });
2342
- return transport2.nanoquery.createFetcherStore(queryKey, {
2343
- fetcher: async (_, __, id) => {
2344
- if (!id) {
2345
- return void 0;
2346
- }
2347
- const res = await client.getStream({
2348
- id
2349
- // we are sure that id is a string
2350
- });
2351
- return res.data?.attributes;
2352
- }
2353
- });
2354
- };
2355
-
2356
- // packages/sdk-web-api/src/grpc/queries/organization.ts
2357
- var import_client_connect3 = require("@streamlayer/sl-eslib/sdkSettings/client/client_connect");
2358
-
2359
- // packages/sdk-web-api/src/grpc/queries/user.ts
2360
- var import_users_connect2 = require("@streamlayer/sl-eslib/users/users_connect");
2361
- var import_client_connect2 = require("@streamlayer/sl-eslib/sdkSettings/client/client_connect");
2362
- var $user = ($userToken, transport2) => {
2363
- const { queryKey, client } = transport2.createPromiseClient(import_users_connect2.Users, { method: "me", params: [$userToken] });
2364
- return transport2.nanoquery.createFetcherStore(queryKey, {
2365
- fetcher: () => client.me({})
2366
- });
2367
- };
2368
- var $bypassLogin = (transport2) => {
2369
- const { client, queryKeyStr } = transport2.createPromiseClient(import_users_connect2.Users, { method: "bypassAuth" });
2370
- return transport2.nanoquery.createMutatorStore(
2371
- async ({ data: { userKey, schema, init }, getCacheUpdater }) => {
2372
- const [updateCache] = getCacheUpdater(queryKeyStr);
2373
- const user = await client.bypassAuth({ userKey, schema, init });
2374
- updateCache(user);
2375
- return user;
2376
- }
2377
- );
2378
- };
2379
- var bypassAuth = (transport2, params) => {
2380
- const { client } = transport2.createPromiseClient(import_users_connect2.Users, { method: "bypassAuth" });
2381
- return client.bypassAuth(params);
2382
- };
2383
- var $userSettings = ($userToken, transport2) => {
2384
- const { client, queryKey } = transport2.createPromiseClient(import_client_connect2.Client, { method: "get", params: [$userToken] });
2385
- return transport2.nanoquery.createFetcherStore(queryKey, {
2386
- fetcher: async () => {
2387
- const data = await client.get({});
2388
- return data.data?.attributes;
2389
- }
2390
- });
2391
- };
2392
- var register2 = (transport2, phone) => {
2393
- const { client } = transport2.createPromiseClient(import_users_connect2.Users, { method: "register" });
2394
- return client.register({ id: phone });
2395
- };
2396
-
2397
- // packages/sdk-web-api/src/grpc/queries/organization.ts
2398
- var $organizationSettings = ($enabled, transport2) => {
2399
- const { client, queryKey } = transport2.createPromiseClient(import_client_connect3.Client, { method: "getOrganization", params: [$enabled] });
2400
- return transport2.nanoquery.createFetcherStore(queryKey, {
2401
- fetcher: async () => {
2402
- const res = await client.getOrganization({});
2403
- return res.data ? {
2404
- ...res.data.attributes,
2405
- id: res.data.id
2406
- } : void 0;
2407
- }
2408
- });
2409
- };
2410
- var $organizationAdvertising = ($enabled, transport2) => {
2411
- const { client, queryKey } = transport2.createPromiseClient(import_client_connect3.Client, {
2412
- method: "getOrganizationAdvertising",
2413
- params: [$enabled]
2414
- });
2415
- return transport2.nanoquery.createFetcherStore(queryKey, {
2416
- fetcher: async () => {
2417
- const res = await client.getOrganizationAdvertising({});
2418
- return res.data?.attributes;
2419
- }
2420
- });
2421
- };
2422
-
2423
- // packages/sdk-web-api/src/index.ts
2424
- var transport = (instance, opts, done) => {
2425
- instance.transport = new Transport(opts.host);
2426
- instance.sdk.host = instance.transport.host;
2427
- instance.transport.setSdkKey(opts.sdkKey);
2428
- done();
2429
- };
2430
-
2431
- // packages/sdk-web-core/src/store/store.ts
2432
- var initializeStore = (transport2) => {
2433
- const enabled = new SingleStore(createSingleStore(), "enabled");
2434
- const status = new SingleStore(createSingleStore("disabled" /* DISABLED */), "status");
2435
- const userKey = new SingleStore(createSingleStore(), "userKey");
2436
- const userToken = new SingleStore(createSingleStore(), "userToken");
2437
- userToken.listen((token) => {
2438
- if (token) {
2439
- localStorage.setItem("sl-user-token", token);
2440
- } else {
2441
- localStorage.removeItem("sl-user-token");
2442
- }
2443
- });
2444
- const providerStreamId = new SingleStore(createSingleStore(), "providerStreamId");
2445
- const slStreamId = new ApiStore(
2446
- queries_exports.$retrieveEventId(providerStreamId.getStore(), transport2),
2447
- "slStreamId",
2448
- (data) => data?.data
2449
- );
2450
- const user = new ApiStore(
2451
- queries_exports.$user(userToken.getStore(), transport2),
2452
- "user",
2453
- (data) => data?.data?.data?.id
2454
- );
2455
- const userSettings = new ApiStore(
2456
- queries_exports.$userSettings(userToken.getStore(), transport2),
2457
- "userSettings"
2458
- );
2459
- const streamSettings = new ApiStore(
2460
- queries_exports.$streamSettings(slStreamId.getAtomStore(), transport2),
2461
- "streamSettings"
2462
- );
2463
- slStreamId.getAtomStore().listen((eventId) => {
2464
- if (eventId === "" || eventId === void 0) {
2465
- streamSettings.getStore().mutate(void 0);
2466
- }
2467
- });
2468
- const organizationSettings = new ApiStore(
2469
- queries_exports.$organizationSettings(enabled.getStore(), transport2),
2470
- "organizationSettings",
2471
- (data) => data?.data?.id
2472
- );
2473
- const organizationAdvertising = new ApiStore(
2474
- queries_exports.$organizationAdvertising(organizationSettings.getAtomStore(), transport2),
2475
- "organizationAdvertising"
2476
- );
2477
- return {
2478
- enabled,
2479
- status,
2480
- providerStreamId,
2481
- slStreamId,
2482
- streamSettings,
2483
- user,
2484
- userKey,
2485
- userToken,
2486
- userSettings,
2487
- organizationSettings,
2488
- organizationAdvertising
2489
- };
2490
- };
2491
- var CoreStore = class extends AbstractStore {
2492
- stores;
2493
- constructor(transport2) {
2494
- const storesObj = initializeStore(transport2);
2495
- const store2 = mergeStores(storesObj);
2496
- super(store2, "core");
2497
- this.stores = storesObj;
2498
- }
2499
- getValue() {
2500
- throw new Error("Not implemented");
2501
- }
2502
- getValues() {
2503
- return this.stores;
2504
- }
2505
- setValue() {
2506
- throw new Error("Not implemented");
2507
- }
2508
- subscribe = (subscribes) => {
2509
- let storeKey;
2510
- for (storeKey in this.stores) {
2511
- const fn = subscribes[storeKey];
2512
- if (storeKey in subscribes && fn !== void 0) {
2513
- this.stores[storeKey].subscribe(subscribes[storeKey]);
2514
- }
2515
- }
2516
- };
2517
- unsubscribe = () => {
2518
- const store2 = this.getStore();
2519
- return store2.off();
2520
- };
2521
- };
2522
-
2523
- // packages/sdk-web-core/src/index.ts
2524
- var core = (instance, opts, done) => {
2525
- instance.sdk = /* @__PURE__ */ Object.create(null);
2526
- instance.sdk.initializeApp = async () => {
2527
- instance.storeSubscribe();
2528
- instance.stores.enabled.setValue("on");
2529
- instance.stores.status.setValue("initialization" /* INITIALIZATION */);
2530
- try {
2531
- const organizationSettings = await instance.stores.organizationSettings.getValue();
2532
- if (organizationSettings) {
2533
- instance.stores.status.setValue("ready" /* READY */);
2534
- return { enabled: !!organizationSettings };
2535
- }
2536
- instance.stores.status.setValue("failed" /* FAILED */);
2537
- return { err: "failed" };
2538
- } catch (err) {
2539
- instance.stores.enabled.setValue();
2540
- instance.stores.status.setValue("failed" /* FAILED */);
2541
- return { err: `${err}` };
2542
- }
2543
- };
2544
- instance.sdk.disableApp = () => {
2545
- instance.stores.enabled.setValue();
2546
- instance.stores.status.setValue("disabled" /* DISABLED */);
2547
- instance.storeUnsubscribe();
2548
- };
2549
- instance.sdk.createEventSession = (providerStreamId) => {
2550
- instance.stores.providerStreamId.setValue("");
2551
- instance.stores.providerStreamId.setValue(providerStreamId);
2552
- };
2553
- done();
2554
- };
2555
-
2556
- // packages/feature-gamification/src/queries/index.ts
2557
- var import_nanostores6 = require("nanostores");
2558
- var import_interactive4 = require("@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect");
2559
-
2560
- // packages/feature-gamification/src/queries/leaderboard.ts
2561
- var import_interactive3 = require("@streamlayer/sl-eslib/interactive/leaderboard/interactive.leaderboard_connect");
2562
- var $userSummary = ($eventId, $userId, transport2) => {
2563
- const { client, queryKey } = transport2.createPromiseClient(import_interactive3.Leaderboard, {
2564
- method: "summary",
2565
- params: [$eventId, $userId]
2566
- });
2567
- return transport2.nanoquery.createFetcherStore(queryKey, {
2568
- fetcher: async (_, __, eventId, userId) => {
2569
- const res = await client.summary({
2570
- eventId,
2571
- userId
2572
- });
2573
- return res.data?.attributes;
2574
- }
2575
- });
2576
- };
2577
-
2578
- // packages/feature-gamification/src/queries/index.ts
2579
- var $activeQuestion = (slStreamId, transport2) => {
2580
- const { client, queryKey } = transport2.createPromiseClient(import_interactive4.Feed, { method: "syncQuestion", params: [slStreamId] });
2581
- return transport2.nanoquery.createFetcherStore(queryKey, {
2582
- fetcher: async (_, __, id) => {
2583
- if (!id) {
2584
- return void 0;
2585
- }
2586
- const res = await client.syncQuestion({
2587
- filter: {
2588
- eventId: id
2589
- }
2590
- });
2591
- return res.data?.attributes;
2592
- }
2593
- });
2594
- };
2595
- var feedSubscription = ($slStreamId, transport2) => {
2596
- const { client } = transport2.createCallbackClient(import_interactive4.Feed);
2597
- const params = (0, import_nanostores6.atom)({ eventId: $slStreamId.get() || "", feedId: "" });
2598
- $slStreamId.subscribe((eventId = "") => {
2599
- params.set({ eventId, feedId: "" });
2600
- });
2601
- const subscription = transport2.addSubscription(
2602
- client.subscription,
2603
- params,
2604
- { name: "feedSubscription" }
2605
- );
2606
- return subscription;
2607
- };
2608
- var questionSubscription = (questionId, transport2) => {
2609
- const { client } = transport2.createCallbackClient(import_interactive4.Feed);
2610
- const subscription = transport2.addSubscription(client.questionSubscription, { questionId }, { name: "questionSubscription" });
2611
- return subscription;
2612
- };
2613
- var $questionByUser = ($questionId, transport2) => {
2614
- const { client, queryKey } = transport2.createPromiseClient(import_interactive4.Feed, { method: "questionByUser", params: [$questionId] });
2615
- return transport2.nanoquery.createFetcherStore(queryKey, {
2616
- fetcher: async (_, __, questionId) => {
2617
- const res = await client.questionByUser({
2618
- questionId
2619
- });
2620
- return res.data?.attributes?.question;
2621
- }
2622
- });
2623
- };
2624
- var $pickHistory = (slStreamId, transport2) => {
2625
- const { client, queryKey } = transport2.createPromiseClient(import_interactive4.Feed, { method: "pickHistory", params: [slStreamId] });
2626
- return transport2.nanoquery.createFetcherStore(queryKey, {
2627
- fetcher: async (_, __, eventId) => {
2628
- if (!eventId) {
2629
- return void 0;
2630
- }
2631
- const res = await client.pickHistory({
2632
- eventId
2633
- });
2634
- return res.data?.map(({ attributes }) => attributes);
2635
- }
2636
- });
2637
- };
2638
-
2639
- // packages/feature-gamification/src/queries/actions.ts
2640
- var import_interactive5 = require("@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect");
2641
- var submitAnswer = (transport2, data) => {
2642
- const { client } = transport2.createPromiseClient(import_interactive5.Feed, { method: "submitAnswer" });
2643
- return client.submitAnswer({ data });
2644
- };
2645
- var submitInplay = (transport2, eventId) => {
2646
- const { client } = transport2.createPromiseClient(import_interactive5.Feed, { method: "submitInplay" });
2647
- return client.submitInplay({ data: { eventId: +eventId } });
2648
- };
2649
- var skipQuestion = (transport2, questionId) => {
2650
- const { client } = transport2.createPromiseClient(import_interactive5.Feed, { method: "skipQuestion" });
2651
- return client.skipQuestion({ data: { id: questionId } });
2652
- };
2653
-
2654
- // packages/feature-gamification/src/index.ts
2655
- var Gamification = class extends AbstractFeature {
2656
- // user statistics (leaderboard panel)
2657
- userSummary;
2658
- // questions list (pick history)
2659
- questions;
2660
- // pinned leaderboard id
2661
- leaderboardId;
2662
- // sl event id
2663
- slStreamId;
2664
- // current user id
2665
- userId;
2666
- organizationId;
2667
- // opened question, using to download statistics
2668
- openedQuestionId;
2669
- // opened question statistics
2670
- openedQuestion;
2671
- // last active question in feed
2672
- activeQuestionId;
2673
- // moderation id
2674
- moderationId;
2675
- // feed id (deprecated?)
2676
- feedId;
2677
- // pinned leaderboard id
2678
- onbordingComplete;
2679
- notifications;
2680
- transport;
2681
- constructor(config2, source, instance) {
2682
- super(config2, source);
2683
- this.leaderboardId = new SingleStore(
2684
- createSingleStore(this.settings.getValue("pinnedLeaderboardId")),
2685
- "pinnedLeaderboardId"
2686
- ).getStore();
2687
- this.slStreamId = instance.stores.slStreamId.getAtomStore();
2688
- this.userId = instance.stores.user.getAtomStore();
2689
- this.organizationId = instance.stores.organizationSettings.getAtomStore();
2690
- this.moderationId = new SingleStore(createSingleStore(), "moderationId").getStore();
2691
- this.feedId = new SingleStore(createSingleStore(), "feedId").getStore();
2692
- this.onbordingComplete = new SingleStore(createSingleStore(false), "onbordingComplete").getStore();
2693
- this.openedQuestionId = new SingleStore(createSingleStore(), "openedQuestionId").getStore();
2694
- this.notifications = instance.notifications;
2695
- this.transport = instance.transport;
2696
- if (!this.userId.get()) {
2697
- this.userId.subscribe((userId) => {
2698
- if (userId) {
2699
- this.connect(instance.transport);
2700
- const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
2701
- this.onbordingComplete.set(!!cached);
2702
- }
2703
- });
2704
- } else {
2705
- this.connect(instance.transport);
2706
- const userId = this.userId.get();
2707
- const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
2708
- this.onbordingComplete.set(!!cached);
2709
- }
2710
- }
2711
- getCurrentSessionIdPrefix = (opts) => {
2712
- const eventId = opts.eventId || this.slStreamId.get();
2713
- const userId = opts.userId || this.userId.get();
2714
- const organizationId = opts.organizationId || this.organizationId.get();
2715
- return `${organizationId}:${userId}:${eventId}:${opts.prefix || ""}`;
2716
- };
2717
- connect = (transport2) => {
2718
- this.userSummary = new ApiStore(
2719
- $userSummary(this.slStreamId, this.userId, transport2),
2720
- "gamification:userSummary"
2721
- );
2722
- this.questions = new ApiStore(
2723
- $pickHistory(this.slStreamId, transport2),
2724
- "gamification:questions"
2725
- );
2726
- this.activeQuestionId = new ApiStore(
2727
- $activeQuestion(this.slStreamId, transport2),
2728
- "gamification:activeQuestionId"
2729
- );
2730
- this.openedQuestion = new ApiStore(
2731
- $questionByUser(this.openedQuestionId, transport2),
2732
- "gamification:activeQuestionId"
2733
- );
2734
- let questionSubscription2 = void 0;
2735
- this.openedQuestionId.listen((questionId) => {
2736
- if (questionId) {
2737
- questionSubscription2 = questionSubscription(questionId, transport2);
2738
- questionSubscription2.addListener(
2739
- "feed-subscription-opened-question",
2740
- (response) => {
2741
- window.requestAnimationFrame(() => {
2742
- this.openedQuestion?.getStore().mutate(response.data?.attributes?.question);
2743
- this.openedQuestion?.getStore().invalidate();
2744
- this.userSummary?.getStore().invalidate();
2745
- });
2746
- }
2747
- );
2748
- questionSubscription2.connect();
2749
- } else {
2750
- console.log("cleanup on close question");
2751
- this.openedQuestion?.getStore().mutate(void 0);
2752
- if (questionSubscription2 !== void 0) {
2753
- transport2.removeSubscription(questionSubscription2);
2754
- }
2755
- }
2756
- });
2757
- this.activeQuestionId?.listen((question) => {
2758
- if (question?.data?.notification?.title) {
2759
- if (question.data.question.status === import_interactive.QuestionStatus.ACTIVE) {
2760
- this.notifications.add({
2761
- id: this.getCurrentSessionIdPrefix({ prefix: `notification-id:${question.data.question.id}` }),
2762
- data: question.data
2763
- });
2764
- }
2765
- }
2766
- });
2767
- const feedSubscription2 = feedSubscription(this.slStreamId, transport2);
2768
- feedSubscription2.addListener("feed-subscription-active-question", (response) => {
2769
- window.requestAnimationFrame(() => {
2770
- const $activeQuestionId = this.activeQuestionId?.getStore();
2771
- if ($activeQuestionId) {
2772
- $activeQuestionId.mutate(response.data?.attributes);
2773
- }
2774
- });
2775
- });
2776
- feedSubscription2.addListener("feed-subscription-questions-list", () => {
2777
- window.requestAnimationFrame(() => {
2778
- this.questions?.invalidate();
2779
- });
2780
- });
2781
- };
2782
- // onboarding
2783
- submitInplay = async () => {
2784
- const eventId = this.slStreamId.get();
2785
- if (eventId) {
2786
- await submitInplay(this.transport, eventId);
2787
- this.onbordingComplete.set(true);
2788
- localStorage.setItem(`sl-onbording:${this.userId.get()}:${eventId}`, "true");
2789
- }
2790
- };
2791
- submitAnswer = async (questionId, answerId) => {
2792
- await submitAnswer(this.transport, { questionId, answerId });
2793
- this.questions?.invalidate();
2794
- };
2795
- skipQuestion = async (questionId) => {
2796
- await skipQuestion(this.transport, questionId);
2797
- this.questions?.invalidate();
2798
- };
2799
- openQuestion = (questionId) => {
2800
- this.openedQuestionId.set(questionId);
2801
- this.notifications.markAsViewed(this.getCurrentSessionIdPrefix({ prefix: `notification-id:${questionId}` }));
2802
- };
2803
- closeQuestion = () => {
2804
- this.notifications.markAsViewed(
2805
- this.getCurrentSessionIdPrefix({ prefix: `notification-id:${this.openedQuestionId.get()}` })
2806
- );
2807
- window.requestAnimationFrame(() => {
2808
- this.openedQuestionId.set(void 0);
2809
- });
2810
- };
2811
- };
2812
-
2813
- // packages/sdk-web-features/src/index.ts
2814
- var Feature = class extends AbstractFeature {
2815
- };
2816
- var initFeature = (overlay, source, instance) => {
2817
- if (overlay.type === import_sdkSettings.SdkOverlayType.GAMES) {
2818
- return new Gamification(overlay, source, instance);
2819
- }
2820
- return new Feature(overlay, source);
2821
- };
2822
- var features = (instance, opts, done) => {
2823
- instance.features = /* @__PURE__ */ new Map();
2824
- instance.sdk.getFeatures = () => instance.features;
2825
- instance.initFeature = (overlay, source = "ORGANIZATION" /* ORGANIZATION */) => {
2826
- const feature = initFeature(overlay, source, instance);
2827
- instance.features.set(overlay.name, feature);
2828
- };
2829
- instance.updateFeature = (overlay, source) => {
2830
- instance.features.get(overlay.name)?.update(overlay, source);
2831
- };
2832
- instance.destroyFeature = (overlay) => {
2833
- instance.features.delete(overlay.name);
2834
- };
2835
- instance.reinitializeFeatures = async () => {
2836
- const organizationSettings = await instance.stores.organizationSettings.getValue();
2837
- instance.features.clear();
2838
- for (const overlay of organizationSettings?.overlays || []) {
2839
- instance.initFeature(overlay, "ORGANIZATION" /* ORGANIZATION */);
2840
- }
2841
- };
2842
- instance.stores.providerStreamId.listen((eventId) => {
2843
- if (!eventId) {
2844
- void instance.reinitializeFeatures();
2845
- }
2846
- });
2847
- done();
2848
- };
2849
-
2850
- // packages/sdk-web/src/index.ts
2851
- var import_avvio = __toESM(require("avvio"), 1);
2852
-
2853
- // packages/sdk-web-core/src/store/index.ts
2854
- var store = (instance, opts, done) => {
2855
- instance.store = new CoreStore(instance.transport);
2856
- instance.stores = instance.store.getValues();
2857
- instance.sdk.sdkStore = instance.store.getStore();
2858
- instance.sdk.organizationStore = () => instance.stores.organizationSettings.getStore();
2859
- instance.storeSubscribe = () => {
2860
- const processSettings = (source, settings) => {
2861
- if (!settings?.overlays)
2862
- return;
2863
- if (source === "STREAM" /* STREAM */) {
2864
- instance.features.clear();
2865
- }
2866
- for (const overlay of settings.overlays) {
2867
- const featureName = overlay.name;
2868
- if (!instance.features.has(featureName)) {
2869
- instance.initFeature(overlay, source);
2870
- } else {
2871
- instance.updateFeature(overlay, source);
2872
- }
2873
- }
2874
- };
2875
- const subscribes = {
2876
- /**
2877
- * During the initial SDK initialization, it's imperative to initialize features first,
2878
- * followed by their direct subscriptions to store fields.
2879
- * This section is currently in development, and it's
2880
- * essential to implement checks to determine whether a feature
2881
- * has already been initialized. If it has, events related to
2882
- * that feature should be skipped. Conversely, if a feature is
2883
- * missing in the new settings, it should be deinitialized.
2884
- */
2885
- organizationSettings: (orgSettings) => {
2886
- if (orgSettings.data) {
2887
- try {
2888
- processSettings("ORGANIZATION" /* ORGANIZATION */, orgSettings.data);
2889
- } catch (err) {
2890
- console.log(err);
2891
- }
2892
- }
2893
- },
2894
- streamSettings: (streamSettings) => {
2895
- if (streamSettings.data) {
2896
- try {
2897
- processSettings("STREAM" /* STREAM */, streamSettings.data);
2898
- } catch (err) {
2899
- console.log(err);
2900
- }
2901
- }
2902
- }
2903
- };
2904
- instance.store.subscribe(subscribes);
2905
- };
2906
- instance.storeUnsubscribe = () => {
2907
- instance.store.unsubscribe();
2908
- };
2909
- done();
2910
- };
2911
-
2912
- // packages/sdk-web-core/src/auth/bypass/index.ts
2913
- var BypassAuth = class extends AbstractAuthenticationProvider {
2914
- $coreStore;
2915
- transport;
2916
- $bypassLogin;
2917
- constructor(store2, transport2) {
2918
- super();
2919
- this.$coreStore = store2;
2920
- this.transport = transport2;
2921
- this.$bypassLogin = queries_exports.$bypassLogin(this.transport);
2922
- this.subscribe();
2923
- }
2924
- me = async () => {
2925
- const res = await this.$coreStore.getValues().user.getValue();
2926
- return res?.data;
2927
- };
2928
- login = async (schema, userKey) => {
2929
- this.$coreStore.getValues().userKey.setValue(userKey);
2930
- await this.$bypassLogin.mutate({ schema, userKey, init: false });
2931
- return this.me();
2932
- };
2933
- isAuthenticated = () => {
2934
- return this.me();
2935
- };
2936
- logout = () => {
2937
- this.$coreStore.getValues().user.setValue();
2938
- this.$coreStore.getValues().userKey.setValue();
2939
- this.$coreStore.getValues().userToken.setValue();
2940
- this.transport.setAuth("");
2941
- };
2942
- /**
2943
- * subscribe to user store and set auth header to the Transport on user update
2944
- */
2945
- subscribe = () => {
2946
- this.$bypassLogin.subscribe((user, key) => {
2947
- if (key === "data") {
2948
- this.transport.setAuth(user?.data?.meta?.jwt);
2949
- this.$coreStore.getValues().userToken.setValue(user?.data?.meta?.jwt);
2950
- }
2951
- });
2952
- };
2953
- };
2954
-
2955
- // packages/sdk-web-core/src/auth/index.ts
2956
- var bypass = async (instance, opts, done) => {
2957
- instance.auth = new BypassAuth(instance.store, instance.transport);
2958
- const prevUserSchema = localStorage.getItem("sl-user-schema");
2959
- const prevUserToken = localStorage.getItem("sl-user-token");
2960
- if (prevUserSchema && prevUserToken) {
2961
- console.log("try to login prev user");
2962
- await instance.auth.login(prevUserSchema, prevUserToken);
2963
- }
2964
- instance.sdk.authorizationBypass = async (schema, userKey) => {
2965
- await instance.auth.login(schema, userKey);
2966
- localStorage.setItem("sl-user-schema", "streamlayer:streamlayer");
2967
- };
2968
- instance.sdk.logout = () => {
2969
- instance.auth.logout();
2970
- };
2971
- instance.sdk.getUserStore = () => {
2972
- return instance.stores.user.getStore();
2973
- };
2974
- instance.sdk.isUserAuthorized = () => {
2975
- return instance.auth.isAuthenticated();
2976
- };
2977
- done();
2978
- };
2979
-
2980
- // packages/sdk-web-core/src/notifications/notifications.ts
2981
- var Notifications2 = class {
2982
- queue;
2983
- constructor() {
2984
- this.queue = new SingleStore(createSingleStore([]), "notifications");
2985
- }
2986
- add = (notification) => {
2987
- if (this.isNewNotify(notification.id)) {
2988
- this.queue.getStore().set([...this.queue.getValue() || [], notification]);
2989
- } else {
2990
- console.log("skip notification:", notification);
2991
- }
2992
- };
2993
- getQueueStore = () => {
2994
- return this.queue.getStore();
2995
- };
2996
- isNewNotify = (id) => {
2997
- const exist = localStorage.getItem(`opened:${id}`);
2998
- return !exist;
2999
- };
3000
- markAsViewed = (id) => {
3001
- localStorage.setItem(`opened:${id}`, id);
3002
- };
3003
- };
3004
-
3005
- // packages/sdk-web-core/src/notifications/index.ts
3006
- var notifications = (instance, opts, done) => {
3007
- instance.notifications = new Notifications2();
3008
- instance.addNotification = instance.notifications.add;
3009
- instance.sdk.getNotificationsStore = () => instance.notifications.getQueueStore();
3010
- done();
3011
- };
3012
-
3013
- // packages/sdk-web/src/index.ts
3014
- function StreamLayer(sdkKey, production = true) {
3015
- const host = production ? "https://grpc-web.streamlayer.io:443" : "https://grpc-web.next.streamlayer.io:443";
3016
- const streamLayer = (0, import_avvio.default)(/* @__PURE__ */ Object.create(null), { autostart: false });
3017
- streamLayer.use(core);
3018
- streamLayer.use(transport, { sdkKey, host });
3019
- streamLayer.use(store);
3020
- streamLayer.use(bypass);
3021
- streamLayer.use(features);
3022
- streamLayer.use(notifications);
3023
- streamLayer.after(async (err, context, done) => {
3024
- if (err) {
3025
- throw err;
3026
- }
3027
- await context.sdk.initializeApp();
3028
- done();
3029
- });
3030
- streamLayer.onClose(() => {
3031
- console.log("close");
3032
- });
3033
- return streamLayer;
3034
- }
3035
-
3036
- // packages/react/src/app/useStreamLayerApp.ts
3037
- var import_react14 = require("react");
3038
- window.instance = null;
3039
- var useStreamLayerApp = (sdkKey, plugins, production) => {
3040
- const [sdk, setSdk] = (0, import_react14.useState)(null);
3041
- (0, import_react14.useEffect)(() => {
3042
- let ignore = false;
3043
- if (!sdkKey) {
3044
- throw new Error("sdk key should be provided");
3045
- }
3046
- const instance = StreamLayer(sdkKey, production);
3047
- if (plugins) {
3048
- for (const plugin of plugins) {
3049
- instance.use(plugin);
3050
- }
3051
- }
3052
- instance.ready().then((service) => {
3053
- if (!ignore) {
3054
- window.instance = service;
3055
- setSdk(service.sdk);
3056
- }
3057
- }).catch((err) => console.log(err));
3058
- return () => {
3059
- ignore = true;
3060
- instance.close(function(err) {
3061
- if (err)
3062
- throw err;
3063
- });
3064
- };
3065
- }, [sdkKey]);
3066
- return sdk;
3067
- };
3068
-
3069
- // packages/react/src/app/provider.tsx
3070
- var import_jsx_runtime23 = require("@emotion/react/jsx-runtime");
3071
- var StreamLayerContext3 = (0, import_react15.createContext)({
3072
- status: 0 /* UNSET */
3073
- });
3074
- if (process.env.NODE_ENV !== "production") {
3075
- StreamLayerContext3.displayName = "StreamLayerProvider";
3076
- }
3077
- var StreamLayerProvider = ({
3078
- sdkKey,
3079
- plugins,
3080
- children,
3081
- production = true
3082
- }) => {
3083
- const streamLayer = useStreamLayerApp(sdkKey, plugins, production);
3084
- const value = (0, import_react15.useMemo)(() => {
3085
- if (!streamLayer) {
3086
- return { status: 1 /* CONNECTED */ };
3087
- }
3088
- return { sdk: streamLayer, status: 2 /* READY */ };
3089
- }, [streamLayer]);
3090
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(StreamLayerThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(StreamLayerContext3.Provider, { value, children }) });
3091
- };
3092
-
3093
- // packages/react/src/app/app.tsx
3094
- var import_react16 = require("react");
3095
- var import_jsx_runtime24 = require("@emotion/react/jsx-runtime");
3096
- var useStreamLayer = () => {
3097
- const { sdk } = (0, import_react16.useContext)(StreamLayerContext3);
3098
- return sdk;
3099
- };
3100
- var StreamLayerSDKReact = () => {
3101
- const { sdk, status } = (0, import_react16.useContext)(StreamLayerContext3);
3102
- if (status === 0 /* UNSET */) {
3103
- throw new Error("Wrap app in `StreamLayerProvider`");
3104
- }
3105
- if (status === 1 /* CONNECTED */) {
3106
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { children: "wait" });
3107
- }
3108
- if (sdk === void 0) {
3109
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { children: "sdk not initialized" });
3110
- }
3111
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Demo, { sdk });
3112
- };
3113
- // Annotate the CommonJS export names for ESM import in node:
3114
- 0 && (module.exports = {
3115
- StreamLayerProvider,
3116
- StreamLayerSDKReact,
3117
- useStreamLayer,
3118
- useStreamLayerApp
3119
- });