@streamlayer/react 0.2.9 → 0.2.11
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/main.cjs +3111 -0
- package/main.js +3081 -0
- package/package.json +15 -13
- package/src/app/app.d.ts +0 -3
- package/src/app/provider.d.ts +0 -19
- package/src/app/useStreamLayer.d.ts +0 -7
- package/src/main.d.ts +0 -3
package/main.cjs
ADDED
|
@@ -0,0 +1,3111 @@
|
|
|
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/main.tsx
|
|
31
|
+
var main_exports = {};
|
|
32
|
+
__export(main_exports, {
|
|
33
|
+
StreamLayerProvider: () => StreamLayerProvider,
|
|
34
|
+
StreamLayerSDKReact: () => StreamLayerSDKReact,
|
|
35
|
+
useSDK: () => useSDK,
|
|
36
|
+
useStreamLayer: () => useStreamLayer
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(main_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 (phone) => {
|
|
354
|
+
const transport2 = (0, import_connect_web.createGrpcWebTransport)({
|
|
355
|
+
baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
|
|
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 (phone) => {
|
|
362
|
+
const transport2 = (0, import_connect_web.createGrpcWebTransport)({
|
|
363
|
+
baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
|
|
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 (phone, code) => {
|
|
370
|
+
const transport2 = (0, import_connect_web.createGrpcWebTransport)({
|
|
371
|
+
baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
|
|
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 }) => {
|
|
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(parsed);
|
|
540
|
+
} catch (err) {
|
|
541
|
+
await register(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(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" }, disabled: true, 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?.average
|
|
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 });
|
|
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 user = (0, import_react12.useStore)(sdk.getUserStore());
|
|
1691
|
+
if (user.loading) {
|
|
1692
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { children: "authentificating..." });
|
|
1693
|
+
}
|
|
1694
|
+
if (!user.data) {
|
|
1695
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(LoginComponent, { sdk });
|
|
1696
|
+
}
|
|
1697
|
+
const gamification = sdk.getFeatures().get("games");
|
|
1698
|
+
if (!gamification) {
|
|
1699
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { children: "wait gamification..." });
|
|
1700
|
+
}
|
|
1701
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(GamificationComponent, { gamification, sdk });
|
|
1702
|
+
};
|
|
1703
|
+
|
|
1704
|
+
// packages/react-ui/src/lib/theme/index.tsx
|
|
1705
|
+
var import_react13 = require("@emotion/react");
|
|
1706
|
+
var import_jsx_runtime22 = require("@emotion/react/jsx-runtime");
|
|
1707
|
+
var StreamLayerThemeProvider = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react13.ThemeProvider, { theme, children });
|
|
1708
|
+
|
|
1709
|
+
// packages/react/src/app/provider.tsx
|
|
1710
|
+
var import_react15 = require("react");
|
|
1711
|
+
|
|
1712
|
+
// packages/sdk-web-interfaces/src/auth.ts
|
|
1713
|
+
var AbstractAuthenticationProvider = class {
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
// packages/sdk-web-interfaces/src/feature.ts
|
|
1717
|
+
var import_sdkSettings2 = require("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb");
|
|
1718
|
+
var import_nanostores3 = require("nanostores");
|
|
1719
|
+
|
|
1720
|
+
// packages/sdk-web-interfaces/src/store/map.ts
|
|
1721
|
+
var import_nanostores2 = require("nanostores");
|
|
1722
|
+
|
|
1723
|
+
// packages/sdk-web-interfaces/src/store/abstract.ts
|
|
1724
|
+
var import_nanostores = require("nanostores");
|
|
1725
|
+
var import_logger = require("@nanostores/logger");
|
|
1726
|
+
var import_microdiff = __toESM(require("microdiff"), 1);
|
|
1727
|
+
window.storeLogger = /* @__PURE__ */ Object.create(null);
|
|
1728
|
+
var slStoreLogger = (store2, name) => (0, import_logger.buildLogger)(store2, name, {
|
|
1729
|
+
mount: ({ storeName }) => {
|
|
1730
|
+
if (!window.storeLogger[storeName]) {
|
|
1731
|
+
window.storeLogger[storeName] = { mounted: true, history: [{ type: "mount" }] };
|
|
1732
|
+
}
|
|
1733
|
+
window.storeLogger[storeName].store = store2;
|
|
1734
|
+
},
|
|
1735
|
+
unmount: ({ storeName }) => {
|
|
1736
|
+
window.storeLogger[storeName].mounted = false;
|
|
1737
|
+
window.storeLogger[storeName]?.history.push({ type: "unmount" });
|
|
1738
|
+
},
|
|
1739
|
+
change: ({ actionName, storeName, changed, newValue, oldValue, valueMessage }) => {
|
|
1740
|
+
window.storeLogger[storeName]?.history.push({
|
|
1741
|
+
type: "change",
|
|
1742
|
+
changed,
|
|
1743
|
+
newValue,
|
|
1744
|
+
oldValue,
|
|
1745
|
+
diff: (0, import_microdiff.default)({ ...oldValue }, { ...newValue }, { cyclesFix: false }),
|
|
1746
|
+
actionName,
|
|
1747
|
+
valueMessage
|
|
1748
|
+
});
|
|
1749
|
+
},
|
|
1750
|
+
action: {
|
|
1751
|
+
start: ({ actionName, args, storeName }) => {
|
|
1752
|
+
window.storeLogger[storeName]?.history.push({
|
|
1753
|
+
type: "action:start",
|
|
1754
|
+
actionName,
|
|
1755
|
+
args,
|
|
1756
|
+
storeName
|
|
1757
|
+
});
|
|
1758
|
+
},
|
|
1759
|
+
error: ({ actionName, error, storeName }) => {
|
|
1760
|
+
window.storeLogger[storeName]?.history.push({
|
|
1761
|
+
type: "action:error",
|
|
1762
|
+
actionName,
|
|
1763
|
+
error
|
|
1764
|
+
});
|
|
1765
|
+
},
|
|
1766
|
+
end: ({ actionName, storeName }) => {
|
|
1767
|
+
window.storeLogger[storeName]?.history.push({
|
|
1768
|
+
type: "action:end",
|
|
1769
|
+
actionName
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
var AbstractStore = class {
|
|
1775
|
+
/**
|
|
1776
|
+
* store instance (nanostores)
|
|
1777
|
+
*/
|
|
1778
|
+
store;
|
|
1779
|
+
name;
|
|
1780
|
+
constructor(store2, name) {
|
|
1781
|
+
this.store = store2;
|
|
1782
|
+
this.name = name;
|
|
1783
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1784
|
+
slStoreLogger(this.store, this.name);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* return store instance
|
|
1789
|
+
*/
|
|
1790
|
+
getStore() {
|
|
1791
|
+
return this.store;
|
|
1792
|
+
}
|
|
1793
|
+
};
|
|
1794
|
+
var mergeStores = (stores) => {
|
|
1795
|
+
const storeKeys = Object.keys(stores);
|
|
1796
|
+
return (0, import_nanostores.computed)(
|
|
1797
|
+
storeKeys.map((key) => stores[key].getStore()),
|
|
1798
|
+
(...storeValues) => Object.fromEntries(storeKeys.map((key, i) => [key, storeValues[i]]))
|
|
1799
|
+
);
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
// packages/sdk-web-interfaces/src/store/map.ts
|
|
1803
|
+
var MapStore = class extends AbstractStore {
|
|
1804
|
+
getValues = () => {
|
|
1805
|
+
const store2 = this.getStore();
|
|
1806
|
+
return store2.get();
|
|
1807
|
+
};
|
|
1808
|
+
getValue = (key) => {
|
|
1809
|
+
const store2 = this.getStore();
|
|
1810
|
+
return store2.get()[key];
|
|
1811
|
+
};
|
|
1812
|
+
setValue = (path, value) => {
|
|
1813
|
+
const store2 = this.getStore();
|
|
1814
|
+
return store2.setKey(path, value);
|
|
1815
|
+
};
|
|
1816
|
+
subscribe = (...args) => {
|
|
1817
|
+
const store2 = this.getStore();
|
|
1818
|
+
return store2.subscribe(...args);
|
|
1819
|
+
};
|
|
1820
|
+
unsubscribe = () => {
|
|
1821
|
+
const store2 = this.getStore();
|
|
1822
|
+
return store2.off();
|
|
1823
|
+
};
|
|
1824
|
+
};
|
|
1825
|
+
var createMapStore = (initialData) => {
|
|
1826
|
+
return (0, import_nanostores2.map)(initialData);
|
|
1827
|
+
};
|
|
1828
|
+
|
|
1829
|
+
// packages/sdk-web-interfaces/src/feature.ts
|
|
1830
|
+
var FeatureTypes = {
|
|
1831
|
+
[import_sdkSettings2.SdkOverlayType.BETTING]: "betting",
|
|
1832
|
+
[import_sdkSettings2.SdkOverlayType.GAMES]: "games",
|
|
1833
|
+
[import_sdkSettings2.SdkOverlayType.PUBLIC_CHAT]: "publicChat",
|
|
1834
|
+
[import_sdkSettings2.SdkOverlayType.TWITTER]: "twitter"
|
|
1835
|
+
};
|
|
1836
|
+
var AbstractFeature = class {
|
|
1837
|
+
status;
|
|
1838
|
+
source;
|
|
1839
|
+
config;
|
|
1840
|
+
settings;
|
|
1841
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1842
|
+
settingsKey;
|
|
1843
|
+
constructor({ settings, ...config2 }, source) {
|
|
1844
|
+
this.settingsKey = FeatureTypes[config2.type];
|
|
1845
|
+
this.status = (0, import_nanostores3.atom)("suspended" /* Suspended */);
|
|
1846
|
+
this.config = new MapStore(createMapStore(config2), `feature:config:${this.settingsKey}`);
|
|
1847
|
+
if (this.settingsKey !== void 0 && settings?.overlaySettings.case === this.settingsKey) {
|
|
1848
|
+
this.settings = new MapStore(
|
|
1849
|
+
createMapStore(settings.overlaySettings.value),
|
|
1850
|
+
`feature:settings:${this.settingsKey}`
|
|
1851
|
+
);
|
|
1852
|
+
} else {
|
|
1853
|
+
this.settings = new MapStore(createMapStore({}), `feature:settings:${this.settingsKey}`);
|
|
1854
|
+
}
|
|
1855
|
+
this.source = source;
|
|
1856
|
+
}
|
|
1857
|
+
get featureConfig() {
|
|
1858
|
+
return this.config.getStore();
|
|
1859
|
+
}
|
|
1860
|
+
get featureSettings() {
|
|
1861
|
+
return this.settings.getStore();
|
|
1862
|
+
}
|
|
1863
|
+
registerEventListener(listener) {
|
|
1864
|
+
this.listeners.add(listener);
|
|
1865
|
+
}
|
|
1866
|
+
enable = () => {
|
|
1867
|
+
this.status.set("ready" /* Ready */);
|
|
1868
|
+
};
|
|
1869
|
+
disabled = () => {
|
|
1870
|
+
this.status.set("suspended" /* Suspended */);
|
|
1871
|
+
};
|
|
1872
|
+
setFeatureConfig = ({ settings, ...config2 }) => {
|
|
1873
|
+
let configKey;
|
|
1874
|
+
for (configKey in config2) {
|
|
1875
|
+
this.config.setValue(configKey, config2[configKey]);
|
|
1876
|
+
}
|
|
1877
|
+
if (settings?.overlaySettings.case === this.settingsKey) {
|
|
1878
|
+
const newSettings = settings.overlaySettings.value;
|
|
1879
|
+
if (newSettings !== void 0) {
|
|
1880
|
+
let key;
|
|
1881
|
+
for (key in newSettings) {
|
|
1882
|
+
console.log(key, newSettings[key]);
|
|
1883
|
+
if (newSettings[key] !== 0 && newSettings[key] !== "") {
|
|
1884
|
+
this.settings.setValue(key, newSettings[key]);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
update = (config2, source) => {
|
|
1891
|
+
if (this.source === "STREAM" /* STREAM */ && source === "ORGANIZATION" /* ORGANIZATION */) {
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
this.setFeatureConfig(config2);
|
|
1895
|
+
this.source = source;
|
|
1896
|
+
};
|
|
1897
|
+
fireEvent(event) {
|
|
1898
|
+
for (const listener of this.listeners.values()) {
|
|
1899
|
+
try {
|
|
1900
|
+
listener.onEvent(event);
|
|
1901
|
+
} catch (err) {
|
|
1902
|
+
console.error(err);
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
|
|
1908
|
+
// packages/sdk-web-interfaces/src/store/single.ts
|
|
1909
|
+
var import_nanostores4 = require("nanostores");
|
|
1910
|
+
var SingleStore = class extends AbstractStore {
|
|
1911
|
+
getValue = () => {
|
|
1912
|
+
const store2 = this.getStore();
|
|
1913
|
+
return store2.get();
|
|
1914
|
+
};
|
|
1915
|
+
getValues() {
|
|
1916
|
+
throw new Error("not implemented");
|
|
1917
|
+
}
|
|
1918
|
+
setValue = (value) => {
|
|
1919
|
+
const store2 = this.getStore();
|
|
1920
|
+
return store2.set(value);
|
|
1921
|
+
};
|
|
1922
|
+
subscribe = (listener) => {
|
|
1923
|
+
const store2 = this.getStore();
|
|
1924
|
+
return store2.subscribe(listener);
|
|
1925
|
+
};
|
|
1926
|
+
unsubscribe = () => {
|
|
1927
|
+
const store2 = this.getStore();
|
|
1928
|
+
return store2.off();
|
|
1929
|
+
};
|
|
1930
|
+
listen(listener) {
|
|
1931
|
+
const store2 = this.getStore();
|
|
1932
|
+
return store2.listen(listener);
|
|
1933
|
+
}
|
|
1934
|
+
get() {
|
|
1935
|
+
const store2 = this.getStore();
|
|
1936
|
+
return store2.get();
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
var createSingleStore = (initialData) => (0, import_nanostores4.atom)(initialData);
|
|
1940
|
+
|
|
1941
|
+
// packages/sdk-web-interfaces/src/store/api.ts
|
|
1942
|
+
var import_nanostores5 = require("nanostores");
|
|
1943
|
+
var ApiStore = class extends AbstractStore {
|
|
1944
|
+
atomStore;
|
|
1945
|
+
constructor(store2, name, atomPicker) {
|
|
1946
|
+
super(store2, `api:${name}`);
|
|
1947
|
+
this.atomStore = (0, import_nanostores5.atom)();
|
|
1948
|
+
if (atomPicker) {
|
|
1949
|
+
store2.subscribe((data) => {
|
|
1950
|
+
this.atomStore.set(atomPicker(data));
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
getAtomStore = () => this.atomStore;
|
|
1955
|
+
getValue = async () => {
|
|
1956
|
+
const store2 = this.getStore();
|
|
1957
|
+
if (store2.value === void 0) {
|
|
1958
|
+
throw new Error("no store");
|
|
1959
|
+
}
|
|
1960
|
+
await store2.value.promise;
|
|
1961
|
+
return store2.get().data;
|
|
1962
|
+
};
|
|
1963
|
+
getValues = () => {
|
|
1964
|
+
throw new Error("not implemented");
|
|
1965
|
+
};
|
|
1966
|
+
setValue = (value) => {
|
|
1967
|
+
const store2 = this.getStore();
|
|
1968
|
+
return store2.set({ loading: false, data: value?.data });
|
|
1969
|
+
};
|
|
1970
|
+
subscribe = (listener) => {
|
|
1971
|
+
const store2 = this.getStore();
|
|
1972
|
+
return store2.subscribe(listener);
|
|
1973
|
+
};
|
|
1974
|
+
unsubscribe = () => {
|
|
1975
|
+
throw new Error("not implemented");
|
|
1976
|
+
};
|
|
1977
|
+
invalidate = () => {
|
|
1978
|
+
this.store.invalidate();
|
|
1979
|
+
};
|
|
1980
|
+
listen = (cb) => {
|
|
1981
|
+
const store2 = this.getStore();
|
|
1982
|
+
return store2.listen(cb);
|
|
1983
|
+
};
|
|
1984
|
+
get() {
|
|
1985
|
+
throw new Error("not implemented");
|
|
1986
|
+
}
|
|
1987
|
+
key = () => {
|
|
1988
|
+
const store2 = this.getStore();
|
|
1989
|
+
return store2.key;
|
|
1990
|
+
};
|
|
1991
|
+
off = () => {
|
|
1992
|
+
const store2 = this.getStore();
|
|
1993
|
+
return store2.off();
|
|
1994
|
+
};
|
|
1995
|
+
};
|
|
1996
|
+
|
|
1997
|
+
// packages/sdk-web-api/src/grpc/transport.ts
|
|
1998
|
+
var import_connect3 = require("@connectrpc/connect");
|
|
1999
|
+
var import_connect_web2 = require("@bufbuild/connect-web");
|
|
2000
|
+
var import_query = require("@nanostores/query");
|
|
2001
|
+
|
|
2002
|
+
// packages/sdk-web-api/src/utils/devtools.ts
|
|
2003
|
+
async function* logEach(store2, stream) {
|
|
2004
|
+
for await (const m of stream) {
|
|
2005
|
+
store2.response.message = m;
|
|
2006
|
+
store2.received_at = Date.now();
|
|
2007
|
+
const msg = {
|
|
2008
|
+
type: "__GRPC_DEVTOOLS_EXTENSION__",
|
|
2009
|
+
data: store2
|
|
2010
|
+
};
|
|
2011
|
+
window.postMessage(msg);
|
|
2012
|
+
yield m;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
var __GRPC_DEVTOOLS_EXTENSION__ = () => (next) => async (request) => {
|
|
2016
|
+
const store2 = {
|
|
2017
|
+
name: request.url,
|
|
2018
|
+
request: {},
|
|
2019
|
+
response: {}
|
|
2020
|
+
};
|
|
2021
|
+
store2.request.header = Object.fromEntries(request.header.entries());
|
|
2022
|
+
store2.sent_at = Date.now();
|
|
2023
|
+
try {
|
|
2024
|
+
const response = await next(request);
|
|
2025
|
+
store2.received_at = Date.now();
|
|
2026
|
+
store2.stream = response.stream;
|
|
2027
|
+
store2.response.header = Object.fromEntries(response.header.entries());
|
|
2028
|
+
store2.response.trailer = Object.fromEntries(response.trailer.entries());
|
|
2029
|
+
if (!response.stream) {
|
|
2030
|
+
store2.request.message = request.message;
|
|
2031
|
+
store2.response.message = response.message;
|
|
2032
|
+
store2.latency = store2.received_at - store2.sent_at;
|
|
2033
|
+
const msg = {
|
|
2034
|
+
type: "__GRPC_DEVTOOLS_EXTENSION__",
|
|
2035
|
+
data: store2
|
|
2036
|
+
};
|
|
2037
|
+
window.postMessage(msg);
|
|
2038
|
+
} else {
|
|
2039
|
+
return {
|
|
2040
|
+
...response,
|
|
2041
|
+
message: logEach(store2, response.message)
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
return response;
|
|
2045
|
+
} catch (e) {
|
|
2046
|
+
store2.received_at = Date.now();
|
|
2047
|
+
store2.request.message = request.message;
|
|
2048
|
+
store2.response.trailer = {
|
|
2049
|
+
["grpc-status"]: e.code,
|
|
2050
|
+
["grpc-message"]: e.rawMessage
|
|
2051
|
+
};
|
|
2052
|
+
store2.response.message = e.rawMessage;
|
|
2053
|
+
store2.latency = store2.received_at - store2.sent_at;
|
|
2054
|
+
const msg = {
|
|
2055
|
+
type: "__GRPC_DEVTOOLS_EXTENSION__",
|
|
2056
|
+
data: store2
|
|
2057
|
+
};
|
|
2058
|
+
window.postMessage(msg);
|
|
2059
|
+
throw e;
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
window.dispatchEvent(new CustomEvent("grpc_devtools_loaded"));
|
|
2063
|
+
|
|
2064
|
+
// packages/sdk-web-api/src/grpc/subscription.ts
|
|
2065
|
+
var import_connect2 = require("@connectrpc/connect");
|
|
2066
|
+
var ServerStreamSubscription = class {
|
|
2067
|
+
params;
|
|
2068
|
+
stream;
|
|
2069
|
+
method;
|
|
2070
|
+
name;
|
|
2071
|
+
headers;
|
|
2072
|
+
listeners;
|
|
2073
|
+
state;
|
|
2074
|
+
store;
|
|
2075
|
+
constructor(headers, method, params, options) {
|
|
2076
|
+
const initState = {
|
|
2077
|
+
status: "init" /* Init */,
|
|
2078
|
+
ts: /* @__PURE__ */ new Date(),
|
|
2079
|
+
log: []
|
|
2080
|
+
};
|
|
2081
|
+
this.state = new MapStore(createMapStore(initState), `subscription:${options.name}:state`);
|
|
2082
|
+
this.name = options.name;
|
|
2083
|
+
this.headers = headers;
|
|
2084
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
2085
|
+
this.params = params;
|
|
2086
|
+
this.method = method;
|
|
2087
|
+
if (options.withStore) {
|
|
2088
|
+
this.store = new SingleStore(createSingleStore(null), `subscription:${options.name}:store`);
|
|
2089
|
+
}
|
|
2090
|
+
if ("subscribe" in params && typeof params.subscribe === "function") {
|
|
2091
|
+
params.subscribe(() => {
|
|
2092
|
+
this.reconnect();
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
this.updateState("ready" /* Ready */);
|
|
2096
|
+
}
|
|
2097
|
+
updateState = (status) => {
|
|
2098
|
+
this.state.setValue("status", status);
|
|
2099
|
+
this.state.setValue("ts", /* @__PURE__ */ new Date());
|
|
2100
|
+
this.addStateLog(`status => ${status}`);
|
|
2101
|
+
};
|
|
2102
|
+
addStateLog = (msg) => {
|
|
2103
|
+
const log = this.state.getStore().get()["log"];
|
|
2104
|
+
this.state.setValue("log", [...log, `${(/* @__PURE__ */ new Date()).toLocaleString()}: ${msg}`]);
|
|
2105
|
+
};
|
|
2106
|
+
addListener = (name, listener) => {
|
|
2107
|
+
if (this.listeners.has(name)) {
|
|
2108
|
+
this.addStateLog(`listener '${name}' not added`);
|
|
2109
|
+
return false;
|
|
2110
|
+
}
|
|
2111
|
+
this.listeners.set(name, listener);
|
|
2112
|
+
this.addStateLog(`listener '${name}' added`);
|
|
2113
|
+
return true;
|
|
2114
|
+
};
|
|
2115
|
+
removeListener = (name) => {
|
|
2116
|
+
this.listeners.delete(name);
|
|
2117
|
+
this.addStateLog(`listener '${name}' removed`);
|
|
2118
|
+
};
|
|
2119
|
+
connect = () => {
|
|
2120
|
+
this.updateState("connecting" /* Connecting */);
|
|
2121
|
+
if (this.stream) {
|
|
2122
|
+
this.addStateLog(`disconnect prev connection`);
|
|
2123
|
+
this.stream();
|
|
2124
|
+
}
|
|
2125
|
+
const params = "get" in this.params && typeof this.params.get === "function" ? this.params.get() : this.params;
|
|
2126
|
+
this.stream = this.method(
|
|
2127
|
+
params,
|
|
2128
|
+
// ToDo: fix types
|
|
2129
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2130
|
+
// @ts-ignore
|
|
2131
|
+
this.onData,
|
|
2132
|
+
this.onStreamError,
|
|
2133
|
+
{ headers: this.headers.getValues() }
|
|
2134
|
+
);
|
|
2135
|
+
this.updateState("connected" /* Connected */);
|
|
2136
|
+
};
|
|
2137
|
+
disconnect = () => {
|
|
2138
|
+
if (this.stream) {
|
|
2139
|
+
this.stream();
|
|
2140
|
+
}
|
|
2141
|
+
this.listeners.clear();
|
|
2142
|
+
this.updateState("disconnected" /* Disconnected */);
|
|
2143
|
+
};
|
|
2144
|
+
reconnect = () => {
|
|
2145
|
+
this.updateState("reconnecting" /* Reconnecting */);
|
|
2146
|
+
this.connect();
|
|
2147
|
+
};
|
|
2148
|
+
getStore = () => this.store?.getStore();
|
|
2149
|
+
onData = (response) => {
|
|
2150
|
+
this.addStateLog(`received data => ${JSON.stringify(response)}`);
|
|
2151
|
+
if (this.store) {
|
|
2152
|
+
this.store.setValue(response);
|
|
2153
|
+
}
|
|
2154
|
+
for (const [, listener] of this.listeners) {
|
|
2155
|
+
listener(response);
|
|
2156
|
+
}
|
|
2157
|
+
this.addStateLog(`data routed to ${this.listeners.size} listeners`);
|
|
2158
|
+
};
|
|
2159
|
+
onStreamError = (error) => {
|
|
2160
|
+
if (error.code !== import_connect2.Code.Canceled && error.rawMessage !== "[canceled] BodyStreamBuffer was aborted") {
|
|
2161
|
+
this.updateState("failed" /* Failed */);
|
|
2162
|
+
this.state.setValue("error", error);
|
|
2163
|
+
} else {
|
|
2164
|
+
this.disconnect();
|
|
2165
|
+
}
|
|
2166
|
+
};
|
|
2167
|
+
};
|
|
2168
|
+
|
|
2169
|
+
// packages/sdk-web-api/src/grpc/transport.ts
|
|
2170
|
+
var Transport = class {
|
|
2171
|
+
toJsonOptions = {
|
|
2172
|
+
emitDefaultValues: false,
|
|
2173
|
+
enumAsInteger: true,
|
|
2174
|
+
useProtoFieldName: false
|
|
2175
|
+
};
|
|
2176
|
+
transport;
|
|
2177
|
+
nanoquery;
|
|
2178
|
+
interceptors = [];
|
|
2179
|
+
$headers;
|
|
2180
|
+
clients;
|
|
2181
|
+
callbackClients;
|
|
2182
|
+
subscriptions;
|
|
2183
|
+
constructor() {
|
|
2184
|
+
this.$headers = new MapStore(
|
|
2185
|
+
createMapStore({
|
|
2186
|
+
["sl-device-id"]: process.env.NX_DEVICE_ID || "sdk-web-dev"
|
|
2187
|
+
}),
|
|
2188
|
+
"transport:headers"
|
|
2189
|
+
);
|
|
2190
|
+
this.initInterceptors();
|
|
2191
|
+
this.clients = /* @__PURE__ */ new Map();
|
|
2192
|
+
this.callbackClients = /* @__PURE__ */ new Map();
|
|
2193
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
2194
|
+
const [createFetcherStore, createMutatorStore, utils] = (0, import_query.nanoquery)();
|
|
2195
|
+
this.nanoquery = { createFetcherStore, createMutatorStore, utils };
|
|
2196
|
+
this.transport = (0, import_connect_web2.createGrpcWebTransport)({
|
|
2197
|
+
baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443",
|
|
2198
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2199
|
+
// @ts-ignore
|
|
2200
|
+
interceptors: this.interceptors,
|
|
2201
|
+
useBinaryFormat: true
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
// use shared request params, based on Atom, each new Atom will create new subscription
|
|
2205
|
+
// mutate Atom, subscription automatically reconnect with new params
|
|
2206
|
+
// if headers changed, reconnect subscription with new headers automatically
|
|
2207
|
+
addSubscription = (method, params, options) => {
|
|
2208
|
+
const currentSubscription = this.subscriptions.get(params);
|
|
2209
|
+
if (currentSubscription) {
|
|
2210
|
+
return currentSubscription;
|
|
2211
|
+
}
|
|
2212
|
+
const subscription = new ServerStreamSubscription(this.$headers, method, params, options);
|
|
2213
|
+
this.subscriptions.set(params, subscription);
|
|
2214
|
+
return subscription;
|
|
2215
|
+
};
|
|
2216
|
+
removeSubscription = (subscription) => {
|
|
2217
|
+
subscription.disconnect();
|
|
2218
|
+
this.subscriptions.delete(subscription.params);
|
|
2219
|
+
};
|
|
2220
|
+
// cleanup subscriptions
|
|
2221
|
+
disconnect = () => {
|
|
2222
|
+
for (const [name, subscription] of this.subscriptions) {
|
|
2223
|
+
subscription.disconnect();
|
|
2224
|
+
this.subscriptions.delete(name);
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
registerInterceptor = (interceptor) => {
|
|
2228
|
+
this.interceptors.push(interceptor);
|
|
2229
|
+
};
|
|
2230
|
+
removeInterceptor = (interceptor) => {
|
|
2231
|
+
this.interceptors = this.interceptors.filter((i) => i !== interceptor);
|
|
2232
|
+
};
|
|
2233
|
+
getClient = (service) => {
|
|
2234
|
+
const serviceName = service.typeName;
|
|
2235
|
+
if (this.clients.has(serviceName)) {
|
|
2236
|
+
return this.clients.get(serviceName);
|
|
2237
|
+
}
|
|
2238
|
+
const client = (0, import_connect3.createPromiseClient)(service, this.transport);
|
|
2239
|
+
this.clients.set(serviceName, client);
|
|
2240
|
+
return client;
|
|
2241
|
+
};
|
|
2242
|
+
getCallbackClient = (service) => {
|
|
2243
|
+
const serviceName = service.typeName;
|
|
2244
|
+
if (this.callbackClients.has(serviceName)) {
|
|
2245
|
+
return this.callbackClients.get(serviceName);
|
|
2246
|
+
}
|
|
2247
|
+
const client = (0, import_connect3.createCallbackClient)(service, this.transport);
|
|
2248
|
+
this.callbackClients.set(serviceName, client);
|
|
2249
|
+
return client;
|
|
2250
|
+
};
|
|
2251
|
+
// create unary client, used for query request
|
|
2252
|
+
createPromiseClient = (service, { params = [], method }) => {
|
|
2253
|
+
const client = this.getClient(service);
|
|
2254
|
+
const methodName = service.methods[method].name;
|
|
2255
|
+
const queryKey = [
|
|
2256
|
+
service.typeName,
|
|
2257
|
+
methodName.charAt(0).toLowerCase() + methodName.slice(1),
|
|
2258
|
+
...Array.isArray(params) ? params : [params]
|
|
2259
|
+
];
|
|
2260
|
+
const queryKeyWithoutParams = [service.typeName, methodName.charAt(0).toLowerCase() + methodName.slice(1)];
|
|
2261
|
+
return { client, queryKey, queryKeyStr: queryKeyWithoutParams.join("") };
|
|
2262
|
+
};
|
|
2263
|
+
// create callback client, used for server stream subscriptions
|
|
2264
|
+
createCallbackClient = (service) => {
|
|
2265
|
+
const client = this.getCallbackClient(service);
|
|
2266
|
+
return { client };
|
|
2267
|
+
};
|
|
2268
|
+
setSdkKey = (sdkKey) => {
|
|
2269
|
+
this.$headers.setValue("sdk", sdkKey);
|
|
2270
|
+
};
|
|
2271
|
+
setAuth = (token) => {
|
|
2272
|
+
this.$headers.setValue("authorization", token);
|
|
2273
|
+
};
|
|
2274
|
+
setHeader = (name, value) => this.$headers.setValue(name, value);
|
|
2275
|
+
getHeader = (name) => this.$headers.getValue(name);
|
|
2276
|
+
getHeaders = () => this.$headers.getValues();
|
|
2277
|
+
initInterceptors = () => {
|
|
2278
|
+
if (this.interceptors.length !== 0) {
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2281
|
+
const auth = (next) => async (req) => {
|
|
2282
|
+
const headers = this.$headers.getValues();
|
|
2283
|
+
for (const header in headers) {
|
|
2284
|
+
req.header.set(header, headers[header]);
|
|
2285
|
+
}
|
|
2286
|
+
try {
|
|
2287
|
+
return await next(req);
|
|
2288
|
+
} catch (err) {
|
|
2289
|
+
console.log({ err, req }, "catch err");
|
|
2290
|
+
throw err;
|
|
2291
|
+
}
|
|
2292
|
+
};
|
|
2293
|
+
this.interceptors.push(auth);
|
|
2294
|
+
this.interceptors.push(__GRPC_DEVTOOLS_EXTENSION__());
|
|
2295
|
+
};
|
|
2296
|
+
};
|
|
2297
|
+
|
|
2298
|
+
// packages/sdk-web-api/src/grpc/queries/index.ts
|
|
2299
|
+
var queries_exports = {};
|
|
2300
|
+
__export(queries_exports, {
|
|
2301
|
+
$bypassLogin: () => $bypassLogin,
|
|
2302
|
+
$organizationAdvertising: () => $organizationAdvertising,
|
|
2303
|
+
$organizationSettings: () => $organizationSettings,
|
|
2304
|
+
$retrieveEventId: () => $retrieveEventId,
|
|
2305
|
+
$streamSettings: () => $streamSettings,
|
|
2306
|
+
$user: () => $user,
|
|
2307
|
+
$userSettings: () => $userSettings,
|
|
2308
|
+
bypassAuth: () => bypassAuth,
|
|
2309
|
+
register: () => register2
|
|
2310
|
+
});
|
|
2311
|
+
|
|
2312
|
+
// packages/sdk-web-api/src/grpc/queries/event.ts
|
|
2313
|
+
var import_events_connect = require("@streamlayer/sl-eslib/sports/events/events_connect");
|
|
2314
|
+
var import_client_connect = require("@streamlayer/sl-eslib/sdkSettings/client/client_connect");
|
|
2315
|
+
var $retrieveEventId = ($providerStreamId, transport2) => {
|
|
2316
|
+
const { client, queryKey } = transport2.createPromiseClient(import_events_connect.Events, {
|
|
2317
|
+
method: "retrieveEventId",
|
|
2318
|
+
params: [$providerStreamId]
|
|
2319
|
+
});
|
|
2320
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2321
|
+
fetcher: async (_, __, id) => {
|
|
2322
|
+
if (!id || typeof id !== "string") {
|
|
2323
|
+
return "";
|
|
2324
|
+
}
|
|
2325
|
+
try {
|
|
2326
|
+
const res = await client.retrieveEventId({
|
|
2327
|
+
id
|
|
2328
|
+
});
|
|
2329
|
+
return res.data?.id || "";
|
|
2330
|
+
} catch (err) {
|
|
2331
|
+
return "";
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
});
|
|
2335
|
+
};
|
|
2336
|
+
var $streamSettings = (slStreamId, transport2) => {
|
|
2337
|
+
const { client, queryKey } = transport2.createPromiseClient(import_client_connect.Client, { method: "getStream", params: [slStreamId] });
|
|
2338
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2339
|
+
fetcher: async (_, __, id) => {
|
|
2340
|
+
if (!id) {
|
|
2341
|
+
return void 0;
|
|
2342
|
+
}
|
|
2343
|
+
const res = await client.getStream({
|
|
2344
|
+
id
|
|
2345
|
+
// we are sure that id is a string
|
|
2346
|
+
});
|
|
2347
|
+
return res.data?.attributes;
|
|
2348
|
+
}
|
|
2349
|
+
});
|
|
2350
|
+
};
|
|
2351
|
+
|
|
2352
|
+
// packages/sdk-web-api/src/grpc/queries/organization.ts
|
|
2353
|
+
var import_client_connect3 = require("@streamlayer/sl-eslib/sdkSettings/client/client_connect");
|
|
2354
|
+
|
|
2355
|
+
// packages/sdk-web-api/src/grpc/queries/user.ts
|
|
2356
|
+
var import_users_connect2 = require("@streamlayer/sl-eslib/users/users_connect");
|
|
2357
|
+
var import_client_connect2 = require("@streamlayer/sl-eslib/sdkSettings/client/client_connect");
|
|
2358
|
+
var $user = ($userToken, transport2) => {
|
|
2359
|
+
const { queryKey, client } = transport2.createPromiseClient(import_users_connect2.Users, { method: "me", params: [$userToken] });
|
|
2360
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2361
|
+
fetcher: () => client.me({})
|
|
2362
|
+
});
|
|
2363
|
+
};
|
|
2364
|
+
var $bypassLogin = (transport2) => {
|
|
2365
|
+
const { client, queryKeyStr } = transport2.createPromiseClient(import_users_connect2.Users, { method: "bypassAuth" });
|
|
2366
|
+
return transport2.nanoquery.createMutatorStore(
|
|
2367
|
+
async ({ data: { userKey, schema, init }, getCacheUpdater }) => {
|
|
2368
|
+
const [updateCache] = getCacheUpdater(queryKeyStr);
|
|
2369
|
+
const user = await client.bypassAuth({ userKey, schema, init });
|
|
2370
|
+
updateCache(user);
|
|
2371
|
+
return user;
|
|
2372
|
+
}
|
|
2373
|
+
);
|
|
2374
|
+
};
|
|
2375
|
+
var bypassAuth = (transport2, params) => {
|
|
2376
|
+
const { client } = transport2.createPromiseClient(import_users_connect2.Users, { method: "bypassAuth" });
|
|
2377
|
+
return client.bypassAuth(params);
|
|
2378
|
+
};
|
|
2379
|
+
var $userSettings = ($userToken, transport2) => {
|
|
2380
|
+
const { client, queryKey } = transport2.createPromiseClient(import_client_connect2.Client, { method: "get", params: [$userToken] });
|
|
2381
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2382
|
+
fetcher: async () => {
|
|
2383
|
+
const data = await client.get({});
|
|
2384
|
+
return data.data?.attributes;
|
|
2385
|
+
}
|
|
2386
|
+
});
|
|
2387
|
+
};
|
|
2388
|
+
var register2 = (transport2, phone) => {
|
|
2389
|
+
const { client } = transport2.createPromiseClient(import_users_connect2.Users, { method: "register" });
|
|
2390
|
+
return client.register({ id: phone });
|
|
2391
|
+
};
|
|
2392
|
+
|
|
2393
|
+
// packages/sdk-web-api/src/grpc/queries/organization.ts
|
|
2394
|
+
var $organizationSettings = ($enabled, transport2) => {
|
|
2395
|
+
const { client, queryKey } = transport2.createPromiseClient(import_client_connect3.Client, { method: "getOrganization", params: [$enabled] });
|
|
2396
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2397
|
+
fetcher: async () => {
|
|
2398
|
+
const res = await client.getOrganization({});
|
|
2399
|
+
return res.data ? {
|
|
2400
|
+
...res.data.attributes,
|
|
2401
|
+
id: res.data.id
|
|
2402
|
+
} : void 0;
|
|
2403
|
+
}
|
|
2404
|
+
});
|
|
2405
|
+
};
|
|
2406
|
+
var $organizationAdvertising = ($enabled, transport2) => {
|
|
2407
|
+
const { client, queryKey } = transport2.createPromiseClient(import_client_connect3.Client, {
|
|
2408
|
+
method: "getOrganizationAdvertising",
|
|
2409
|
+
params: [$enabled]
|
|
2410
|
+
});
|
|
2411
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2412
|
+
fetcher: async () => {
|
|
2413
|
+
const res = await client.getOrganizationAdvertising({});
|
|
2414
|
+
return res.data?.attributes;
|
|
2415
|
+
}
|
|
2416
|
+
});
|
|
2417
|
+
};
|
|
2418
|
+
|
|
2419
|
+
// packages/sdk-web-api/src/index.ts
|
|
2420
|
+
var transport = (instance, opts, done) => {
|
|
2421
|
+
instance.transport = new Transport();
|
|
2422
|
+
instance.transport.setSdkKey(opts.sdkKey);
|
|
2423
|
+
done();
|
|
2424
|
+
};
|
|
2425
|
+
|
|
2426
|
+
// packages/sdk-web-core/src/store/store.ts
|
|
2427
|
+
var initializeStore = (transport2) => {
|
|
2428
|
+
const enabled = new SingleStore(createSingleStore(), "enabled");
|
|
2429
|
+
const status = new SingleStore(createSingleStore("disabled" /* DISABLED */), "status");
|
|
2430
|
+
const userKey = new SingleStore(createSingleStore(), "userKey");
|
|
2431
|
+
const userToken = new SingleStore(createSingleStore(), "userToken");
|
|
2432
|
+
userToken.listen((token) => {
|
|
2433
|
+
if (token) {
|
|
2434
|
+
localStorage.setItem("sl-user-token", token);
|
|
2435
|
+
} else {
|
|
2436
|
+
localStorage.removeItem("sl-user-token");
|
|
2437
|
+
}
|
|
2438
|
+
});
|
|
2439
|
+
const providerStreamId = new SingleStore(createSingleStore(), "providerStreamId");
|
|
2440
|
+
const slStreamId = new ApiStore(
|
|
2441
|
+
queries_exports.$retrieveEventId(providerStreamId.getStore(), transport2),
|
|
2442
|
+
"slStreamId",
|
|
2443
|
+
(data) => data?.data
|
|
2444
|
+
);
|
|
2445
|
+
const user = new ApiStore(
|
|
2446
|
+
queries_exports.$user(userToken.getStore(), transport2),
|
|
2447
|
+
"user",
|
|
2448
|
+
(data) => data?.data?.data?.id
|
|
2449
|
+
);
|
|
2450
|
+
const userSettings = new ApiStore(
|
|
2451
|
+
queries_exports.$userSettings(userToken.getStore(), transport2),
|
|
2452
|
+
"userSettings"
|
|
2453
|
+
);
|
|
2454
|
+
const streamSettings = new ApiStore(
|
|
2455
|
+
queries_exports.$streamSettings(slStreamId.getAtomStore(), transport2),
|
|
2456
|
+
"streamSettings"
|
|
2457
|
+
);
|
|
2458
|
+
slStreamId.getAtomStore().listen((eventId) => {
|
|
2459
|
+
if (eventId === "" || eventId === void 0) {
|
|
2460
|
+
streamSettings.getStore().mutate(void 0);
|
|
2461
|
+
}
|
|
2462
|
+
});
|
|
2463
|
+
const organizationSettings = new ApiStore(
|
|
2464
|
+
queries_exports.$organizationSettings(enabled.getStore(), transport2),
|
|
2465
|
+
"organizationSettings",
|
|
2466
|
+
(data) => data?.data?.id
|
|
2467
|
+
);
|
|
2468
|
+
const organizationAdvertising = new ApiStore(
|
|
2469
|
+
queries_exports.$organizationAdvertising(organizationSettings.getAtomStore(), transport2),
|
|
2470
|
+
"organizationAdvertising"
|
|
2471
|
+
);
|
|
2472
|
+
return {
|
|
2473
|
+
enabled,
|
|
2474
|
+
status,
|
|
2475
|
+
providerStreamId,
|
|
2476
|
+
slStreamId,
|
|
2477
|
+
streamSettings,
|
|
2478
|
+
user,
|
|
2479
|
+
userKey,
|
|
2480
|
+
userToken,
|
|
2481
|
+
userSettings,
|
|
2482
|
+
organizationSettings,
|
|
2483
|
+
organizationAdvertising
|
|
2484
|
+
};
|
|
2485
|
+
};
|
|
2486
|
+
var CoreStore = class extends AbstractStore {
|
|
2487
|
+
stores;
|
|
2488
|
+
constructor(transport2) {
|
|
2489
|
+
const storesObj = initializeStore(transport2);
|
|
2490
|
+
const store2 = mergeStores(storesObj);
|
|
2491
|
+
super(store2, "core");
|
|
2492
|
+
this.stores = storesObj;
|
|
2493
|
+
}
|
|
2494
|
+
getValue() {
|
|
2495
|
+
throw new Error("Not implemented");
|
|
2496
|
+
}
|
|
2497
|
+
getValues() {
|
|
2498
|
+
return this.stores;
|
|
2499
|
+
}
|
|
2500
|
+
setValue() {
|
|
2501
|
+
throw new Error("Not implemented");
|
|
2502
|
+
}
|
|
2503
|
+
subscribe = (subscribes) => {
|
|
2504
|
+
let storeKey;
|
|
2505
|
+
for (storeKey in this.stores) {
|
|
2506
|
+
const fn = subscribes[storeKey];
|
|
2507
|
+
if (storeKey in subscribes && fn !== void 0) {
|
|
2508
|
+
this.stores[storeKey].subscribe(subscribes[storeKey]);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
};
|
|
2512
|
+
unsubscribe = () => {
|
|
2513
|
+
const store2 = this.getStore();
|
|
2514
|
+
return store2.off();
|
|
2515
|
+
};
|
|
2516
|
+
};
|
|
2517
|
+
|
|
2518
|
+
// packages/sdk-web-core/src/index.ts
|
|
2519
|
+
var core = (instance, opts, done) => {
|
|
2520
|
+
instance.sdk = /* @__PURE__ */ Object.create(null);
|
|
2521
|
+
instance.sdk.initializeApp = async () => {
|
|
2522
|
+
instance.storeSubscribe();
|
|
2523
|
+
instance.stores.enabled.setValue("on");
|
|
2524
|
+
instance.stores.status.setValue("initialization" /* INITIALIZATION */);
|
|
2525
|
+
try {
|
|
2526
|
+
const organizationSettings = await instance.stores.organizationSettings.getValue();
|
|
2527
|
+
if (organizationSettings) {
|
|
2528
|
+
instance.stores.status.setValue("ready" /* READY */);
|
|
2529
|
+
return { enabled: !!organizationSettings };
|
|
2530
|
+
}
|
|
2531
|
+
instance.stores.status.setValue("failed" /* FAILED */);
|
|
2532
|
+
return { err: "failed" };
|
|
2533
|
+
} catch (err) {
|
|
2534
|
+
instance.stores.enabled.setValue();
|
|
2535
|
+
instance.stores.status.setValue("failed" /* FAILED */);
|
|
2536
|
+
return { err: `${err}` };
|
|
2537
|
+
}
|
|
2538
|
+
};
|
|
2539
|
+
instance.sdk.disableApp = () => {
|
|
2540
|
+
instance.stores.enabled.setValue();
|
|
2541
|
+
instance.stores.status.setValue("disabled" /* DISABLED */);
|
|
2542
|
+
instance.storeUnsubscribe();
|
|
2543
|
+
};
|
|
2544
|
+
instance.sdk.createEventSession = (providerStreamId) => {
|
|
2545
|
+
instance.stores.providerStreamId.setValue("");
|
|
2546
|
+
instance.stores.providerStreamId.setValue(providerStreamId);
|
|
2547
|
+
};
|
|
2548
|
+
done();
|
|
2549
|
+
};
|
|
2550
|
+
|
|
2551
|
+
// packages/feature-gamification/src/queries/index.ts
|
|
2552
|
+
var import_nanostores6 = require("nanostores");
|
|
2553
|
+
var import_interactive4 = require("@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect");
|
|
2554
|
+
|
|
2555
|
+
// packages/feature-gamification/src/queries/leaderboard.ts
|
|
2556
|
+
var import_interactive3 = require("@streamlayer/sl-eslib/interactive/leaderboard/interactive.leaderboard_connect");
|
|
2557
|
+
var $userSummary = ($eventId, $userId, transport2) => {
|
|
2558
|
+
const { client, queryKey } = transport2.createPromiseClient(import_interactive3.Leaderboard, {
|
|
2559
|
+
method: "summary",
|
|
2560
|
+
params: [$eventId, $userId]
|
|
2561
|
+
});
|
|
2562
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2563
|
+
fetcher: async (_, __, eventId, userId) => {
|
|
2564
|
+
const res = await client.summary({
|
|
2565
|
+
eventId,
|
|
2566
|
+
userId
|
|
2567
|
+
});
|
|
2568
|
+
return res.data?.attributes;
|
|
2569
|
+
}
|
|
2570
|
+
});
|
|
2571
|
+
};
|
|
2572
|
+
|
|
2573
|
+
// packages/feature-gamification/src/queries/index.ts
|
|
2574
|
+
var $activeQuestion = (slStreamId, transport2) => {
|
|
2575
|
+
const { client, queryKey } = transport2.createPromiseClient(import_interactive4.Feed, { method: "syncQuestion", params: [slStreamId] });
|
|
2576
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2577
|
+
fetcher: async (_, __, id) => {
|
|
2578
|
+
if (!id) {
|
|
2579
|
+
return void 0;
|
|
2580
|
+
}
|
|
2581
|
+
const res = await client.syncQuestion({
|
|
2582
|
+
filter: {
|
|
2583
|
+
eventId: id
|
|
2584
|
+
}
|
|
2585
|
+
});
|
|
2586
|
+
return res.data?.attributes;
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
};
|
|
2590
|
+
var feedSubscription = ($slStreamId, transport2) => {
|
|
2591
|
+
const { client } = transport2.createCallbackClient(import_interactive4.Feed);
|
|
2592
|
+
const params = (0, import_nanostores6.atom)({ eventId: $slStreamId.get() || "", feedId: "" });
|
|
2593
|
+
$slStreamId.subscribe((eventId = "") => {
|
|
2594
|
+
params.set({ eventId, feedId: "" });
|
|
2595
|
+
});
|
|
2596
|
+
const subscription = transport2.addSubscription(
|
|
2597
|
+
client.subscription,
|
|
2598
|
+
params,
|
|
2599
|
+
{ name: "feedSubscription" }
|
|
2600
|
+
);
|
|
2601
|
+
return subscription;
|
|
2602
|
+
};
|
|
2603
|
+
var questionSubscription = (questionId, transport2) => {
|
|
2604
|
+
const { client } = transport2.createCallbackClient(import_interactive4.Feed);
|
|
2605
|
+
const subscription = transport2.addSubscription(client.questionSubscription, { questionId }, { name: "questionSubscription" });
|
|
2606
|
+
return subscription;
|
|
2607
|
+
};
|
|
2608
|
+
var $questionByUser = ($questionId, transport2) => {
|
|
2609
|
+
const { client, queryKey } = transport2.createPromiseClient(import_interactive4.Feed, { method: "questionByUser", params: [$questionId] });
|
|
2610
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2611
|
+
fetcher: async (_, __, questionId) => {
|
|
2612
|
+
const res = await client.questionByUser({
|
|
2613
|
+
questionId
|
|
2614
|
+
});
|
|
2615
|
+
return res.data?.attributes?.question;
|
|
2616
|
+
}
|
|
2617
|
+
});
|
|
2618
|
+
};
|
|
2619
|
+
var $pickHistory = (slStreamId, transport2) => {
|
|
2620
|
+
const { client, queryKey } = transport2.createPromiseClient(import_interactive4.Feed, { method: "pickHistory", params: [slStreamId] });
|
|
2621
|
+
return transport2.nanoquery.createFetcherStore(queryKey, {
|
|
2622
|
+
fetcher: async (_, __, eventId) => {
|
|
2623
|
+
if (!eventId) {
|
|
2624
|
+
return void 0;
|
|
2625
|
+
}
|
|
2626
|
+
const res = await client.pickHistory({
|
|
2627
|
+
eventId
|
|
2628
|
+
});
|
|
2629
|
+
return res.data?.map(({ attributes }) => attributes);
|
|
2630
|
+
}
|
|
2631
|
+
});
|
|
2632
|
+
};
|
|
2633
|
+
|
|
2634
|
+
// packages/feature-gamification/src/queries/actions.ts
|
|
2635
|
+
var import_interactive5 = require("@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect");
|
|
2636
|
+
var submitAnswer = (transport2, data) => {
|
|
2637
|
+
const { client } = transport2.createPromiseClient(import_interactive5.Feed, { method: "submitAnswer" });
|
|
2638
|
+
return client.submitAnswer({ data });
|
|
2639
|
+
};
|
|
2640
|
+
var submitInplay = (transport2, eventId) => {
|
|
2641
|
+
const { client } = transport2.createPromiseClient(import_interactive5.Feed, { method: "submitInplay" });
|
|
2642
|
+
return client.submitInplay({ data: { eventId: +eventId } });
|
|
2643
|
+
};
|
|
2644
|
+
var skipQuestion = (transport2, questionId) => {
|
|
2645
|
+
const { client } = transport2.createPromiseClient(import_interactive5.Feed, { method: "skipQuestion" });
|
|
2646
|
+
return client.skipQuestion({ data: { id: questionId } });
|
|
2647
|
+
};
|
|
2648
|
+
|
|
2649
|
+
// packages/feature-gamification/src/index.ts
|
|
2650
|
+
var Gamification = class extends AbstractFeature {
|
|
2651
|
+
// user statistics (leaderboard panel)
|
|
2652
|
+
userSummary;
|
|
2653
|
+
// questions list (pick history)
|
|
2654
|
+
questions;
|
|
2655
|
+
// pinned leaderboard id
|
|
2656
|
+
leaderboardId;
|
|
2657
|
+
// sl event id
|
|
2658
|
+
slStreamId;
|
|
2659
|
+
// current user id
|
|
2660
|
+
userId;
|
|
2661
|
+
organizationId;
|
|
2662
|
+
// opened question, using to download statistics
|
|
2663
|
+
openedQuestionId;
|
|
2664
|
+
// opened question statistics
|
|
2665
|
+
openedQuestion;
|
|
2666
|
+
// last active question in feed
|
|
2667
|
+
activeQuestionId;
|
|
2668
|
+
// moderation id
|
|
2669
|
+
moderationId;
|
|
2670
|
+
// feed id (deprecated?)
|
|
2671
|
+
feedId;
|
|
2672
|
+
// pinned leaderboard id
|
|
2673
|
+
onbordingComplete;
|
|
2674
|
+
notifications;
|
|
2675
|
+
transport;
|
|
2676
|
+
constructor(config2, source, instance) {
|
|
2677
|
+
super(config2, source);
|
|
2678
|
+
this.leaderboardId = new SingleStore(
|
|
2679
|
+
createSingleStore(this.settings.getValue("pinnedLeaderboardId")),
|
|
2680
|
+
"pinnedLeaderboardId"
|
|
2681
|
+
).getStore();
|
|
2682
|
+
this.slStreamId = instance.stores.slStreamId.getAtomStore();
|
|
2683
|
+
this.userId = instance.stores.user.getAtomStore();
|
|
2684
|
+
this.organizationId = instance.stores.organizationSettings.getAtomStore();
|
|
2685
|
+
this.moderationId = new SingleStore(createSingleStore(), "moderationId").getStore();
|
|
2686
|
+
this.feedId = new SingleStore(createSingleStore(), "feedId").getStore();
|
|
2687
|
+
this.onbordingComplete = new SingleStore(createSingleStore(false), "onbordingComplete").getStore();
|
|
2688
|
+
this.openedQuestionId = new SingleStore(createSingleStore(), "openedQuestionId").getStore();
|
|
2689
|
+
this.notifications = instance.notifications;
|
|
2690
|
+
this.transport = instance.transport;
|
|
2691
|
+
if (!this.userId.get()) {
|
|
2692
|
+
this.userId.subscribe((userId) => {
|
|
2693
|
+
if (userId) {
|
|
2694
|
+
this.connect(instance.transport);
|
|
2695
|
+
const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
|
|
2696
|
+
this.onbordingComplete.set(!!cached);
|
|
2697
|
+
}
|
|
2698
|
+
});
|
|
2699
|
+
} else {
|
|
2700
|
+
this.connect(instance.transport);
|
|
2701
|
+
const userId = this.userId.get();
|
|
2702
|
+
const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
|
|
2703
|
+
this.onbordingComplete.set(!!cached);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
getCurrentSessionIdPrefix = (opts) => {
|
|
2707
|
+
const eventId = opts.eventId || this.slStreamId.get();
|
|
2708
|
+
const userId = opts.userId || this.userId.get();
|
|
2709
|
+
const organizationId = opts.organizationId || this.organizationId.get();
|
|
2710
|
+
return `${organizationId}:${userId}:${eventId}:${opts.prefix || ""}`;
|
|
2711
|
+
};
|
|
2712
|
+
connect = (transport2) => {
|
|
2713
|
+
this.userSummary = new ApiStore(
|
|
2714
|
+
$userSummary(this.slStreamId, this.userId, transport2),
|
|
2715
|
+
"gamification:userSummary"
|
|
2716
|
+
);
|
|
2717
|
+
this.questions = new ApiStore(
|
|
2718
|
+
$pickHistory(this.slStreamId, transport2),
|
|
2719
|
+
"gamification:questions"
|
|
2720
|
+
);
|
|
2721
|
+
this.activeQuestionId = new ApiStore(
|
|
2722
|
+
$activeQuestion(this.slStreamId, transport2),
|
|
2723
|
+
"gamification:activeQuestionId"
|
|
2724
|
+
);
|
|
2725
|
+
this.openedQuestion = new ApiStore(
|
|
2726
|
+
$questionByUser(this.openedQuestionId, transport2),
|
|
2727
|
+
"gamification:activeQuestionId"
|
|
2728
|
+
);
|
|
2729
|
+
let questionSubscription2 = void 0;
|
|
2730
|
+
this.openedQuestionId.listen((questionId) => {
|
|
2731
|
+
if (questionId) {
|
|
2732
|
+
questionSubscription2 = questionSubscription(questionId, transport2);
|
|
2733
|
+
questionSubscription2.addListener(
|
|
2734
|
+
"feed-subscription-opened-question",
|
|
2735
|
+
(response) => {
|
|
2736
|
+
window.requestAnimationFrame(() => {
|
|
2737
|
+
this.openedQuestion?.getStore().mutate(response.data?.attributes?.question);
|
|
2738
|
+
this.openedQuestion?.getStore().invalidate();
|
|
2739
|
+
this.userSummary?.getStore().invalidate();
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
);
|
|
2743
|
+
questionSubscription2.connect();
|
|
2744
|
+
} else {
|
|
2745
|
+
console.log("cleanup on close question");
|
|
2746
|
+
this.openedQuestion?.getStore().mutate(void 0);
|
|
2747
|
+
if (questionSubscription2 !== void 0) {
|
|
2748
|
+
transport2.removeSubscription(questionSubscription2);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
});
|
|
2752
|
+
this.activeQuestionId?.listen((question) => {
|
|
2753
|
+
if (question?.data?.notification?.title) {
|
|
2754
|
+
if (question.data.question.status === import_interactive.QuestionStatus.ACTIVE) {
|
|
2755
|
+
this.notifications.add({
|
|
2756
|
+
id: this.getCurrentSessionIdPrefix({ prefix: `notification-id:${question.data.question.id}` }),
|
|
2757
|
+
data: question.data
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
});
|
|
2762
|
+
const feedSubscription2 = feedSubscription(this.slStreamId, transport2);
|
|
2763
|
+
feedSubscription2.addListener("feed-subscription-active-question", (response) => {
|
|
2764
|
+
window.requestAnimationFrame(() => {
|
|
2765
|
+
const $activeQuestionId = this.activeQuestionId?.getStore();
|
|
2766
|
+
if ($activeQuestionId) {
|
|
2767
|
+
$activeQuestionId.mutate(response.data?.attributes);
|
|
2768
|
+
}
|
|
2769
|
+
});
|
|
2770
|
+
});
|
|
2771
|
+
feedSubscription2.addListener("feed-subscription-questions-list", () => {
|
|
2772
|
+
window.requestAnimationFrame(() => {
|
|
2773
|
+
this.questions?.invalidate();
|
|
2774
|
+
});
|
|
2775
|
+
});
|
|
2776
|
+
};
|
|
2777
|
+
// onboarding
|
|
2778
|
+
submitInplay = async () => {
|
|
2779
|
+
const eventId = this.slStreamId.get();
|
|
2780
|
+
if (eventId) {
|
|
2781
|
+
await submitInplay(this.transport, eventId);
|
|
2782
|
+
this.onbordingComplete.set(true);
|
|
2783
|
+
localStorage.setItem(`sl-onbording:${this.userId.get()}:${eventId}`, "true");
|
|
2784
|
+
}
|
|
2785
|
+
};
|
|
2786
|
+
submitAnswer = async (questionId, answerId) => {
|
|
2787
|
+
await submitAnswer(this.transport, { questionId, answerId });
|
|
2788
|
+
this.questions?.invalidate();
|
|
2789
|
+
};
|
|
2790
|
+
skipQuestion = async (questionId) => {
|
|
2791
|
+
await skipQuestion(this.transport, questionId);
|
|
2792
|
+
this.questions?.invalidate();
|
|
2793
|
+
};
|
|
2794
|
+
openQuestion = (questionId) => {
|
|
2795
|
+
this.openedQuestionId.set(questionId);
|
|
2796
|
+
this.notifications.markAsViewed(this.getCurrentSessionIdPrefix({ prefix: `notification-id:${questionId}` }));
|
|
2797
|
+
};
|
|
2798
|
+
closeQuestion = () => {
|
|
2799
|
+
this.notifications.markAsViewed(
|
|
2800
|
+
this.getCurrentSessionIdPrefix({ prefix: `notification-id:${this.openedQuestionId.get()}` })
|
|
2801
|
+
);
|
|
2802
|
+
window.requestAnimationFrame(() => {
|
|
2803
|
+
this.openedQuestionId.set(void 0);
|
|
2804
|
+
});
|
|
2805
|
+
};
|
|
2806
|
+
};
|
|
2807
|
+
|
|
2808
|
+
// packages/sdk-web-features/src/index.ts
|
|
2809
|
+
var Feature = class extends AbstractFeature {
|
|
2810
|
+
};
|
|
2811
|
+
var initFeature = (overlay, source, instance) => {
|
|
2812
|
+
if (overlay.type === import_sdkSettings.SdkOverlayType.GAMES) {
|
|
2813
|
+
return new Gamification(overlay, source, instance);
|
|
2814
|
+
}
|
|
2815
|
+
return new Feature(overlay, source);
|
|
2816
|
+
};
|
|
2817
|
+
var features = (instance, opts, done) => {
|
|
2818
|
+
instance.features = /* @__PURE__ */ new Map();
|
|
2819
|
+
instance.sdk.getFeatures = () => instance.features;
|
|
2820
|
+
instance.initFeature = (overlay, source = "ORGANIZATION" /* ORGANIZATION */) => {
|
|
2821
|
+
const feature = initFeature(overlay, source, instance);
|
|
2822
|
+
instance.features.set(overlay.name, feature);
|
|
2823
|
+
};
|
|
2824
|
+
instance.updateFeature = (overlay, source) => {
|
|
2825
|
+
instance.features.get(overlay.name)?.update(overlay, source);
|
|
2826
|
+
};
|
|
2827
|
+
instance.destroyFeature = (overlay) => {
|
|
2828
|
+
instance.features.delete(overlay.name);
|
|
2829
|
+
};
|
|
2830
|
+
instance.reinitializeFeatures = async () => {
|
|
2831
|
+
const organizationSettings = await instance.stores.organizationSettings.getValue();
|
|
2832
|
+
instance.features.clear();
|
|
2833
|
+
for (const overlay of organizationSettings?.overlays || []) {
|
|
2834
|
+
instance.initFeature(overlay, "ORGANIZATION" /* ORGANIZATION */);
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
instance.stores.providerStreamId.listen((eventId) => {
|
|
2838
|
+
if (!eventId) {
|
|
2839
|
+
void instance.reinitializeFeatures();
|
|
2840
|
+
}
|
|
2841
|
+
});
|
|
2842
|
+
done();
|
|
2843
|
+
};
|
|
2844
|
+
|
|
2845
|
+
// packages/sdk-web/src/index.ts
|
|
2846
|
+
var import_avvio = __toESM(require("avvio"), 1);
|
|
2847
|
+
|
|
2848
|
+
// packages/sdk-web-core/src/store/index.ts
|
|
2849
|
+
var store = (instance, opts, done) => {
|
|
2850
|
+
instance.store = new CoreStore(instance.transport);
|
|
2851
|
+
instance.stores = instance.store.getValues();
|
|
2852
|
+
instance.sdk.sdkStore = instance.store.getStore();
|
|
2853
|
+
instance.storeSubscribe = () => {
|
|
2854
|
+
const processSettings = (source, settings) => {
|
|
2855
|
+
if (!settings?.overlays)
|
|
2856
|
+
return;
|
|
2857
|
+
if (source === "STREAM" /* STREAM */) {
|
|
2858
|
+
instance.features.clear();
|
|
2859
|
+
}
|
|
2860
|
+
for (const overlay of settings.overlays) {
|
|
2861
|
+
const featureName = overlay.name;
|
|
2862
|
+
if (!instance.features.has(featureName)) {
|
|
2863
|
+
instance.initFeature(overlay, source);
|
|
2864
|
+
} else {
|
|
2865
|
+
instance.updateFeature(overlay, source);
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
const subscribes = {
|
|
2870
|
+
/**
|
|
2871
|
+
* During the initial SDK initialization, it's imperative to initialize features first,
|
|
2872
|
+
* followed by their direct subscriptions to store fields.
|
|
2873
|
+
* This section is currently in development, and it's
|
|
2874
|
+
* essential to implement checks to determine whether a feature
|
|
2875
|
+
* has already been initialized. If it has, events related to
|
|
2876
|
+
* that feature should be skipped. Conversely, if a feature is
|
|
2877
|
+
* missing in the new settings, it should be deinitialized.
|
|
2878
|
+
*/
|
|
2879
|
+
organizationSettings: (orgSettings) => {
|
|
2880
|
+
if (orgSettings.data) {
|
|
2881
|
+
try {
|
|
2882
|
+
processSettings("ORGANIZATION" /* ORGANIZATION */, orgSettings.data);
|
|
2883
|
+
} catch (err) {
|
|
2884
|
+
console.log(err);
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
},
|
|
2888
|
+
streamSettings: (streamSettings) => {
|
|
2889
|
+
if (streamSettings.data) {
|
|
2890
|
+
try {
|
|
2891
|
+
processSettings("STREAM" /* STREAM */, streamSettings.data);
|
|
2892
|
+
} catch (err) {
|
|
2893
|
+
console.log(err);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
};
|
|
2898
|
+
instance.store.subscribe(subscribes);
|
|
2899
|
+
};
|
|
2900
|
+
instance.storeUnsubscribe = () => {
|
|
2901
|
+
instance.store.unsubscribe();
|
|
2902
|
+
};
|
|
2903
|
+
done();
|
|
2904
|
+
};
|
|
2905
|
+
|
|
2906
|
+
// packages/sdk-web-core/src/auth/bypass/index.ts
|
|
2907
|
+
var BypassAuth = class extends AbstractAuthenticationProvider {
|
|
2908
|
+
$coreStore;
|
|
2909
|
+
transport;
|
|
2910
|
+
$bypassLogin;
|
|
2911
|
+
constructor(store2, transport2) {
|
|
2912
|
+
super();
|
|
2913
|
+
this.$coreStore = store2;
|
|
2914
|
+
this.transport = transport2;
|
|
2915
|
+
this.$bypassLogin = queries_exports.$bypassLogin(this.transport);
|
|
2916
|
+
this.subscribe();
|
|
2917
|
+
}
|
|
2918
|
+
me = async () => {
|
|
2919
|
+
const res = await this.$coreStore.getValues().user.getValue();
|
|
2920
|
+
return res?.data;
|
|
2921
|
+
};
|
|
2922
|
+
login = async (schema, userKey) => {
|
|
2923
|
+
this.$coreStore.getValues().userKey.setValue(userKey);
|
|
2924
|
+
await this.$bypassLogin.mutate({ schema, userKey, init: false });
|
|
2925
|
+
return this.me();
|
|
2926
|
+
};
|
|
2927
|
+
isAuthenticated = () => {
|
|
2928
|
+
return this.me();
|
|
2929
|
+
};
|
|
2930
|
+
logout = () => {
|
|
2931
|
+
this.$coreStore.getValues().user.setValue();
|
|
2932
|
+
this.$coreStore.getValues().userKey.setValue();
|
|
2933
|
+
this.$coreStore.getValues().userToken.setValue();
|
|
2934
|
+
this.transport.setAuth("");
|
|
2935
|
+
};
|
|
2936
|
+
/**
|
|
2937
|
+
* subscribe to user store and set auth header to the Transport on user update
|
|
2938
|
+
*/
|
|
2939
|
+
subscribe = () => {
|
|
2940
|
+
this.$bypassLogin.subscribe((user, key) => {
|
|
2941
|
+
if (key === "data") {
|
|
2942
|
+
this.transport.setAuth(user?.data?.meta?.jwt);
|
|
2943
|
+
this.$coreStore.getValues().userToken.setValue(user?.data?.meta?.jwt);
|
|
2944
|
+
}
|
|
2945
|
+
});
|
|
2946
|
+
};
|
|
2947
|
+
};
|
|
2948
|
+
|
|
2949
|
+
// packages/sdk-web-core/src/auth/index.ts
|
|
2950
|
+
var bypass = async (instance, opts, done) => {
|
|
2951
|
+
instance.auth = new BypassAuth(instance.store, instance.transport);
|
|
2952
|
+
const prevUserSchema = localStorage.getItem("sl-user-schema");
|
|
2953
|
+
const prevUserToken = localStorage.getItem("sl-user-token");
|
|
2954
|
+
if (prevUserSchema && prevUserToken) {
|
|
2955
|
+
console.log("try to login prev user");
|
|
2956
|
+
await instance.auth.login(prevUserSchema, prevUserToken);
|
|
2957
|
+
}
|
|
2958
|
+
instance.sdk.authorizationBypass = async (schema, userKey) => {
|
|
2959
|
+
await instance.auth.login(schema, userKey);
|
|
2960
|
+
localStorage.setItem("sl-user-schema", schema);
|
|
2961
|
+
};
|
|
2962
|
+
instance.sdk.logout = () => {
|
|
2963
|
+
instance.auth.logout();
|
|
2964
|
+
};
|
|
2965
|
+
instance.sdk.getUserStore = () => {
|
|
2966
|
+
return instance.stores.user.getStore();
|
|
2967
|
+
};
|
|
2968
|
+
instance.sdk.isUserAuthorized = () => {
|
|
2969
|
+
return instance.auth.isAuthenticated();
|
|
2970
|
+
};
|
|
2971
|
+
done();
|
|
2972
|
+
};
|
|
2973
|
+
|
|
2974
|
+
// packages/sdk-web-core/src/notifications/notifications.ts
|
|
2975
|
+
var Notifications2 = class {
|
|
2976
|
+
queue;
|
|
2977
|
+
constructor() {
|
|
2978
|
+
this.queue = new SingleStore(createSingleStore([]), "notifications");
|
|
2979
|
+
}
|
|
2980
|
+
add = (notification) => {
|
|
2981
|
+
if (this.isNewNotify(notification.id)) {
|
|
2982
|
+
this.queue.getStore().set([...this.queue.getValue() || [], notification]);
|
|
2983
|
+
} else {
|
|
2984
|
+
console.log("skip notification:", notification);
|
|
2985
|
+
}
|
|
2986
|
+
};
|
|
2987
|
+
getQueueStore = () => {
|
|
2988
|
+
return this.queue.getStore();
|
|
2989
|
+
};
|
|
2990
|
+
isNewNotify = (id) => {
|
|
2991
|
+
const exist = localStorage.getItem(`opened:${id}`);
|
|
2992
|
+
return !exist;
|
|
2993
|
+
};
|
|
2994
|
+
markAsViewed = (id) => {
|
|
2995
|
+
localStorage.setItem(`opened:${id}`, id);
|
|
2996
|
+
};
|
|
2997
|
+
};
|
|
2998
|
+
|
|
2999
|
+
// packages/sdk-web-core/src/notifications/index.ts
|
|
3000
|
+
var notifications = (instance, opts, done) => {
|
|
3001
|
+
instance.notifications = new Notifications2();
|
|
3002
|
+
instance.addNotification = instance.notifications.add;
|
|
3003
|
+
instance.sdk.getNotificationsStore = () => instance.notifications.getQueueStore();
|
|
3004
|
+
done();
|
|
3005
|
+
};
|
|
3006
|
+
|
|
3007
|
+
// packages/sdk-web/src/index.ts
|
|
3008
|
+
function StreamLayer(sdkKey) {
|
|
3009
|
+
const streamLayer = (0, import_avvio.default)(/* @__PURE__ */ Object.create(null), { autostart: false });
|
|
3010
|
+
streamLayer.use(core);
|
|
3011
|
+
streamLayer.use(transport, { sdkKey });
|
|
3012
|
+
streamLayer.use(store);
|
|
3013
|
+
streamLayer.use(bypass);
|
|
3014
|
+
streamLayer.use(features);
|
|
3015
|
+
streamLayer.use(notifications);
|
|
3016
|
+
streamLayer.after(async (err, context, done) => {
|
|
3017
|
+
if (err) {
|
|
3018
|
+
throw err;
|
|
3019
|
+
}
|
|
3020
|
+
await context.sdk.initializeApp();
|
|
3021
|
+
done();
|
|
3022
|
+
});
|
|
3023
|
+
streamLayer.onClose(() => {
|
|
3024
|
+
console.log("close");
|
|
3025
|
+
});
|
|
3026
|
+
return streamLayer;
|
|
3027
|
+
}
|
|
3028
|
+
|
|
3029
|
+
// packages/react/src/app/useStreamLayer.ts
|
|
3030
|
+
var import_react14 = require("react");
|
|
3031
|
+
window.instance = null;
|
|
3032
|
+
var useStreamLayer = (sdkKey, plugins) => {
|
|
3033
|
+
const [sdk, setSdk] = (0, import_react14.useState)(null);
|
|
3034
|
+
(0, import_react14.useEffect)(() => {
|
|
3035
|
+
let ignore = false;
|
|
3036
|
+
if (!sdkKey) {
|
|
3037
|
+
throw new Error("sdk key should be provided");
|
|
3038
|
+
}
|
|
3039
|
+
const instance = StreamLayer(sdkKey);
|
|
3040
|
+
if (plugins) {
|
|
3041
|
+
for (const plugin of plugins) {
|
|
3042
|
+
instance.use(plugin);
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
instance.ready().then((service) => {
|
|
3046
|
+
if (!ignore) {
|
|
3047
|
+
window.instance = service;
|
|
3048
|
+
setSdk(service.sdk);
|
|
3049
|
+
}
|
|
3050
|
+
}).catch((err) => console.log(err));
|
|
3051
|
+
return () => {
|
|
3052
|
+
ignore = true;
|
|
3053
|
+
instance.close(function(err) {
|
|
3054
|
+
if (err)
|
|
3055
|
+
throw err;
|
|
3056
|
+
});
|
|
3057
|
+
};
|
|
3058
|
+
}, [sdkKey]);
|
|
3059
|
+
return sdk;
|
|
3060
|
+
};
|
|
3061
|
+
|
|
3062
|
+
// packages/react/src/app/provider.tsx
|
|
3063
|
+
var import_jsx_runtime23 = require("@emotion/react/jsx-runtime");
|
|
3064
|
+
var StreamLayerContext3 = (0, import_react15.createContext)({
|
|
3065
|
+
status: 0 /* UNSET */
|
|
3066
|
+
});
|
|
3067
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3068
|
+
StreamLayerContext3.displayName = "StreamLayerProvider";
|
|
3069
|
+
}
|
|
3070
|
+
var StreamLayerProvider = ({
|
|
3071
|
+
sdkKey,
|
|
3072
|
+
plugins,
|
|
3073
|
+
children
|
|
3074
|
+
}) => {
|
|
3075
|
+
const streamLayer = useStreamLayer(sdkKey, plugins);
|
|
3076
|
+
const value = (0, import_react15.useMemo)(() => {
|
|
3077
|
+
if (!streamLayer) {
|
|
3078
|
+
return { status: 1 /* CONNECTED */ };
|
|
3079
|
+
}
|
|
3080
|
+
return { sdk: streamLayer, status: 2 /* READY */ };
|
|
3081
|
+
}, [streamLayer]);
|
|
3082
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(StreamLayerThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(StreamLayerContext3.Provider, { value, children }) });
|
|
3083
|
+
};
|
|
3084
|
+
|
|
3085
|
+
// packages/react/src/app/app.tsx
|
|
3086
|
+
var import_react16 = require("react");
|
|
3087
|
+
var import_jsx_runtime24 = require("@emotion/react/jsx-runtime");
|
|
3088
|
+
var useSDK = () => {
|
|
3089
|
+
const { sdk } = (0, import_react16.useContext)(StreamLayerContext3);
|
|
3090
|
+
return sdk;
|
|
3091
|
+
};
|
|
3092
|
+
var StreamLayerSDKReact = () => {
|
|
3093
|
+
const { sdk, status } = (0, import_react16.useContext)(StreamLayerContext3);
|
|
3094
|
+
if (status === 0 /* UNSET */) {
|
|
3095
|
+
throw new Error("Wrap app in `StreamLayerProvider`");
|
|
3096
|
+
}
|
|
3097
|
+
if (status === 1 /* CONNECTED */) {
|
|
3098
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { children: "wait" });
|
|
3099
|
+
}
|
|
3100
|
+
if (sdk === void 0) {
|
|
3101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { children: "sdk not initialized" });
|
|
3102
|
+
}
|
|
3103
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Demo, { sdk });
|
|
3104
|
+
};
|
|
3105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3106
|
+
0 && (module.exports = {
|
|
3107
|
+
StreamLayerProvider,
|
|
3108
|
+
StreamLayerSDKReact,
|
|
3109
|
+
useSDK,
|
|
3110
|
+
useStreamLayer
|
|
3111
|
+
});
|