@monterosa/sdk-interact-kit 0.18.2-rc.4 → 0.18.3-rc.1
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/dist/index.cjs.js +106 -99
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +28 -48
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +106 -98
- package/dist/index.esm5.js.map +1 -1
- package/dist/src/core/element/factory.d.ts +3 -3
- package/dist/src/core/project/api.d.ts +1 -5
- package/package.json +10 -6
- package/dist/src/core/project/internal.d.ts +0 -12
package/dist/index.esm2017.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getConnect as getConnect$1, login as login$1, connect, disconnect, subscribe as subscribe$1, unsubscribe as unsubscribe$1, send, ConnState, onConnected } from '@monterosa/sdk-connect-kit';
|
|
2
|
-
import { Emitter, memoizePromise, subscribe as subscribe$2, onTick, now,
|
|
2
|
+
import { Emitter, memoizePromise, subscribe as subscribe$2, onTick, now, calculatePercentage, getErrorMessage, createError } from '@monterosa/sdk-util';
|
|
3
3
|
import { getSdk } from '@monterosa/sdk-core';
|
|
4
|
+
import { fetchSettings } from '@monterosa/sdk-interact-interop';
|
|
5
|
+
import { storageRead, storageWrite } from '@monterosa/sdk-storage-kit';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @license
|
|
@@ -299,22 +301,6 @@ function onConnectionHealthState(connectionHealth, callback) {
|
|
|
299
301
|
return subscribe$2(connectionHealth, 'state', callback);
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
/**
|
|
303
|
-
* @license
|
|
304
|
-
* internal.ts
|
|
305
|
-
* interact-kit
|
|
306
|
-
*
|
|
307
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
|
|
308
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
309
|
-
*
|
|
310
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
311
|
-
*/
|
|
312
|
-
async function fetchSettings(host, id) {
|
|
313
|
-
const response = await fetch(`https://${host}/projects/${id.substring(0, 2)}/${id}/settings.json`);
|
|
314
|
-
const data = await response.json();
|
|
315
|
-
return data;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
304
|
/**
|
|
319
305
|
* @license
|
|
320
306
|
* constants.ts
|
|
@@ -638,14 +624,6 @@ const getProjectMemoized = memoizePromise(async (sdk) => {
|
|
|
638
624
|
function getProject(sdk = getSdk()) {
|
|
639
625
|
return getProjectMemoized(sdk);
|
|
640
626
|
}
|
|
641
|
-
/**
|
|
642
|
-
* @internal
|
|
643
|
-
*/
|
|
644
|
-
async function fetchListings(host, projectId) {
|
|
645
|
-
const response = await fetch(`https://${host}/projects/${projectId.substring(0, 2)}/${projectId}/listings.json`);
|
|
646
|
-
const data = (await response.json());
|
|
647
|
-
return data;
|
|
648
|
-
}
|
|
649
627
|
/**
|
|
650
628
|
* Adds an observer for when {@link InteractProject.fields | project fields}
|
|
651
629
|
* are updated
|
|
@@ -1528,13 +1506,12 @@ class ElementImpl extends Emitter {
|
|
|
1528
1506
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1529
1507
|
*/
|
|
1530
1508
|
const elements = new Map();
|
|
1531
|
-
|
|
1532
|
-
function buildElement(options, context) {
|
|
1509
|
+
async function buildElement(options, context) {
|
|
1533
1510
|
if (elements.has(options.id)) {
|
|
1534
1511
|
return elements.get(options.id);
|
|
1535
1512
|
}
|
|
1536
1513
|
const element = new ElementImpl(options, context);
|
|
1537
|
-
restoreAnswer(element);
|
|
1514
|
+
await restoreAnswer(element);
|
|
1538
1515
|
elements.set(element.id, element);
|
|
1539
1516
|
return element;
|
|
1540
1517
|
}
|
|
@@ -1592,7 +1569,7 @@ async function handleCreateMessage(message) {
|
|
|
1592
1569
|
}
|
|
1593
1570
|
else {
|
|
1594
1571
|
const context = Object.assign(Object.assign({}, event.context), { event });
|
|
1595
|
-
const element = buildElement(options, context);
|
|
1572
|
+
const element = await buildElement(options, context);
|
|
1596
1573
|
event.emit('publish', element);
|
|
1597
1574
|
}
|
|
1598
1575
|
}
|
|
@@ -1641,6 +1618,7 @@ function handleRevealMessage(message) {
|
|
|
1641
1618
|
element.context.event.emit('update', element);
|
|
1642
1619
|
}
|
|
1643
1620
|
async function handleEventHistory(history) {
|
|
1621
|
+
var e_1, _a;
|
|
1644
1622
|
if (history.timeline.length === 0) {
|
|
1645
1623
|
return;
|
|
1646
1624
|
}
|
|
@@ -1649,10 +1627,20 @@ async function handleEventHistory(history) {
|
|
|
1649
1627
|
return;
|
|
1650
1628
|
}
|
|
1651
1629
|
const context = Object.assign(Object.assign({}, event.context), { event });
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1630
|
+
try {
|
|
1631
|
+
for (var _b = __asyncValues(history.timeline), _c; _c = await _b.next(), !_c.done;) {
|
|
1632
|
+
const snapshot = _c.value;
|
|
1633
|
+
if (!elements.has(snapshot.id)) {
|
|
1634
|
+
await buildElement(snapshot, context);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1639
|
+
finally {
|
|
1640
|
+
try {
|
|
1641
|
+
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
|
|
1655
1642
|
}
|
|
1643
|
+
finally { if (e_1) throw e_1.error; }
|
|
1656
1644
|
}
|
|
1657
1645
|
}
|
|
1658
1646
|
async function sendAnswer(element, userAnswer) {
|
|
@@ -1664,27 +1652,19 @@ async function sendAnswer(element, userAnswer) {
|
|
|
1664
1652
|
.join(':');
|
|
1665
1653
|
connect.sendVote(event.id, element.pollId, answer);
|
|
1666
1654
|
}
|
|
1667
|
-
function storeAnswer(element, userAnswer) {
|
|
1655
|
+
async function storeAnswer(element, userAnswer) {
|
|
1668
1656
|
try {
|
|
1669
1657
|
element.userAnswer = userAnswer;
|
|
1670
|
-
|
|
1671
|
-
// Can throw a "QuotaExceededError" DOMException exception
|
|
1672
|
-
// if the quota has been exceeded.
|
|
1673
|
-
setItem(`element_${element.id}_vote`, JSON.stringify(userAnswer));
|
|
1674
|
-
}
|
|
1658
|
+
await storageWrite(`element_${element.id}_vote`, JSON.stringify(userAnswer));
|
|
1675
1659
|
}
|
|
1676
1660
|
catch (err) {
|
|
1677
|
-
|
|
1678
|
-
console.warn(`Can't store user answer: ${err.message}`);
|
|
1679
|
-
}
|
|
1661
|
+
console.warn(`Failed to store user answer: ${getErrorMessage(err)}`);
|
|
1680
1662
|
}
|
|
1681
1663
|
}
|
|
1682
|
-
function restoreAnswer(element) {
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
element.userAnswer = Answer.fromJSON(userAnswer);
|
|
1687
|
-
}
|
|
1664
|
+
async function restoreAnswer(element) {
|
|
1665
|
+
const userAnswer = await storageRead(`element_${element.id}_vote`);
|
|
1666
|
+
if (userAnswer !== null) {
|
|
1667
|
+
element.userAnswer = Answer.fromJSON(userAnswer);
|
|
1688
1668
|
}
|
|
1689
1669
|
}
|
|
1690
1670
|
|
|
@@ -1842,5 +1822,5 @@ function onElementRevoked(event, callback) {
|
|
|
1842
1822
|
return subscribe$2(event, 'revoke', callback);
|
|
1843
1823
|
}
|
|
1844
1824
|
|
|
1845
|
-
export { Answer, AnswerError, Channel, ConnectionHealthState, ElementImpl, ElementState, ElementType, EventImpl, EventState, Klass, ProjectImpl, State, answer,
|
|
1825
|
+
export { Answer, AnswerError, Channel, ConnectionHealthState, ElementImpl, ElementState, ElementType, EventImpl, EventState, Klass, ProjectImpl, State, answer, getConnect, getConnectionHealth, getElement, getElementMemoized, getElements, getElementsMemoized, getEvent, getEventMemoized, getEvents, getEventsMemoized, getProject, getProjectMemoized, login, onConnectionHealthState, onElementPublished, onElementResults, onElementRevoked, onElementStateChanged, onElementUpdated, onEventAdded, onEventPublished, onEventRemoved, onEventState, onEventUpdated, onProjectFieldsUpdated, onProjectListingsUpdated, validateAnswer };
|
|
1846
1826
|
//# sourceMappingURL=index.esm2017.js.map
|