@miso.ai/client-sdk-ui 1.13.2-beta.1 → 1.14.0-beta.3
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/cjs/asset/svgs.js +17 -4
- package/dist/cjs/combo/ask/index.js +2 -2
- package/dist/cjs/constants.js +120 -98
- package/dist/cjs/defaults/ask/controls.js +1 -1
- package/dist/cjs/defaults/hybrid-search/answer-box.js +4 -4
- package/dist/cjs/defaults.js +259 -0
- package/dist/cjs/element/container/index.js +28 -0
- package/dist/cjs/element/container/miso-ask.js +3 -3
- package/dist/cjs/element/container/miso-conversation.js +21 -0
- package/dist/cjs/element/container/miso-explore.js +1 -1
- package/dist/cjs/element/container/miso-history.js +21 -0
- package/dist/cjs/element/container/miso-hybrid-search.js +1 -1
- package/dist/cjs/element/container/miso-message-item.js +91 -0
- package/dist/cjs/element/container/miso-recommendation.js +1 -1
- package/dist/cjs/element/container/miso-search.js +1 -1
- package/dist/cjs/element/container/miso-thread-item.js +91 -0
- package/dist/cjs/element/context/miso-follow-ups.js +1 -1
- package/dist/cjs/element/role/index.js +49 -0
- package/dist/cjs/element/role/miso-delete.js +20 -0
- package/dist/cjs/element/role/miso-messages.js +20 -0
- package/dist/cjs/element/role/miso-new-thread.js +20 -0
- package/dist/cjs/element/role/miso-rename.js +20 -0
- package/dist/cjs/element/role/miso-subscription.js +20 -0
- package/dist/cjs/element/role/miso-threads.js +20 -0
- package/dist/cjs/element/role/miso-title.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +1 -1
- package/dist/cjs/layout/banner/banner.js +2 -1
- package/dist/cjs/layout/button/button.js +170 -0
- package/dist/cjs/layout/button/checkbox.js +116 -0
- package/dist/cjs/layout/button/more-button.js +3 -3
- package/dist/cjs/layout/container/container.js +1 -1
- package/dist/cjs/layout/container/item-container.js +99 -0
- package/dist/cjs/layout/error/error.js +2 -1
- package/dist/cjs/layout/index.js +42 -0
- package/dist/cjs/layout/input/facets.js +4 -3
- package/dist/cjs/layout/input/option-list.js +3 -2
- package/dist/cjs/layout/input/search-box.js +50 -12
- package/dist/cjs/layout/input/select.js +2 -1
- package/dist/cjs/layout/list/cards.js +2 -1
- package/dist/cjs/layout/list/carousel.js +2 -1
- package/dist/cjs/layout/list/collection.js +13 -1
- package/dist/cjs/layout/list/gallery.js +2 -1
- package/dist/cjs/layout/list/horizontal.js +2 -1
- package/dist/cjs/layout/list/list.js +2 -1
- package/dist/cjs/layout/list/messages.js +359 -0
- package/dist/cjs/layout/list/threads.js +199 -0
- package/dist/cjs/layout/mixin/trackable.js +4 -5
- package/dist/cjs/layout/mixin/triggerable.js +2 -2
- package/dist/cjs/layout/radio/feedback.js +4 -3
- package/dist/cjs/layout/templates.js +97 -0
- package/dist/cjs/layout/text/question.js +71 -0
- package/dist/cjs/layout/text/text.js +2 -1
- package/dist/cjs/layout/text/typewriter/index.js +18 -23
- package/dist/cjs/plugin.js +43 -104
- package/dist/cjs/util/confirm.js +33 -0
- package/dist/cjs/util/dom.js +21 -0
- package/dist/cjs/util/modal.js +48 -0
- package/dist/cjs/util/prompt.js +47 -0
- package/dist/cjs/version.js +1 -1
- package/package.json +5 -4
- package/src/CLAUDE.md +51 -104
- package/src/asset/svgs.js +16 -3
- package/src/combo/ask/index.js +2 -2
- package/src/constants.js +39 -147
- package/src/defaults/ask/controls.js +1 -1
- package/src/defaults/hybrid-search/answer-box.js +2 -2
- package/src/defaults.js +174 -0
- package/src/element/container/index.js +4 -0
- package/src/element/container/miso-ask.js +3 -3
- package/src/element/container/miso-conversation.js +19 -0
- package/src/element/container/miso-explore.js +1 -1
- package/src/element/container/miso-history.js +19 -0
- package/src/element/container/miso-hybrid-search.js +1 -1
- package/src/element/container/miso-message-item.js +94 -0
- package/src/element/container/miso-recommendation.js +1 -1
- package/src/element/container/miso-search.js +1 -1
- package/src/element/container/miso-thread-item.js +94 -0
- package/src/element/context/miso-follow-ups.js +1 -1
- package/src/element/role/index.js +7 -0
- package/src/element/role/miso-delete.js +16 -0
- package/src/element/role/miso-messages.js +16 -0
- package/src/element/role/miso-new-thread.js +16 -0
- package/src/element/role/miso-rename.js +16 -0
- package/src/element/role/miso-subscription.js +16 -0
- package/src/element/role/miso-threads.js +16 -0
- package/src/element/role/miso-title.js +16 -0
- package/src/layout/affiliation/affiliation.js +2 -2
- package/src/layout/banner/banner.js +2 -1
- package/src/layout/button/button.js +152 -0
- package/src/layout/button/checkbox.js +92 -0
- package/src/layout/button/more-button.js +3 -3
- package/src/layout/container/container.js +2 -2
- package/src/layout/container/item-container.js +99 -0
- package/src/layout/error/error.js +2 -1
- package/src/layout/index.js +6 -0
- package/src/layout/input/facets.js +3 -2
- package/src/layout/input/option-list.js +3 -2
- package/src/layout/input/search-box.js +45 -8
- package/src/layout/input/select.js +2 -1
- package/src/layout/list/cards.js +2 -1
- package/src/layout/list/carousel.js +2 -1
- package/src/layout/list/collection.js +15 -2
- package/src/layout/list/gallery.js +2 -1
- package/src/layout/list/horizontal.js +2 -1
- package/src/layout/list/list.js +2 -1
- package/src/layout/list/messages.js +316 -0
- package/src/layout/list/threads.js +166 -0
- package/src/layout/mixin/trackable.js +2 -3
- package/src/layout/mixin/triggerable.js +1 -1
- package/src/layout/radio/feedback.js +3 -2
- package/src/layout/templates.js +97 -0
- package/src/layout/text/question.js +58 -0
- package/src/layout/text/text.js +2 -1
- package/src/layout/text/typewriter/index.js +15 -18
- package/src/plugin.js +31 -117
- package/src/util/confirm.js +28 -0
- package/src/util/dom.js +16 -0
- package/src/util/modal.js +49 -0
- package/src/util/prompt.js +42 -0
- package/src/version.js +1 -1
- package/dist/cjs/actor/data.js +0 -132
- package/dist/cjs/actor/feedback.js +0 -29
- package/dist/cjs/actor/fields.js +0 -57
- package/dist/cjs/actor/filters.js +0 -161
- package/dist/cjs/actor/hub.js +0 -57
- package/dist/cjs/actor/index.js +0 -73
- package/dist/cjs/actor/interactions.js +0 -36
- package/dist/cjs/actor/sessions.js +0 -25
- package/dist/cjs/actor/tracker-states.js +0 -61
- package/dist/cjs/actor/tracker.js +0 -109
- package/dist/cjs/actor/trackers.js +0 -52
- package/dist/cjs/actor/utils.js +0 -15
- package/dist/cjs/actor/view.js +0 -294
- package/dist/cjs/actor/views.js +0 -209
- package/dist/cjs/source.js +0 -27
- package/dist/cjs/util/proxy.js +0 -88
- package/dist/cjs/util/trackers.js +0 -88
- package/dist/cjs/workflow/affiliations.js +0 -140
- package/dist/cjs/workflow/answer-based.js +0 -337
- package/dist/cjs/workflow/ask.js +0 -319
- package/dist/cjs/workflow/asks.js +0 -150
- package/dist/cjs/workflow/autocompletable.js +0 -63
- package/dist/cjs/workflow/autocomplete.js +0 -120
- package/dist/cjs/workflow/base.js +0 -418
- package/dist/cjs/workflow/context.js +0 -19
- package/dist/cjs/workflow/explore.js +0 -210
- package/dist/cjs/workflow/explores.js +0 -21
- package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
- package/dist/cjs/workflow/hybrid-search-views.js +0 -109
- package/dist/cjs/workflow/hybrid-search.js +0 -213
- package/dist/cjs/workflow/index.js +0 -41
- package/dist/cjs/workflow/options/api.js +0 -41
- package/dist/cjs/workflow/options/auto-query.js +0 -97
- package/dist/cjs/workflow/options/configurable.js +0 -45
- package/dist/cjs/workflow/options/data-processor.js +0 -20
- package/dist/cjs/workflow/options/filters.js +0 -15
- package/dist/cjs/workflow/options/index.js +0 -126
- package/dist/cjs/workflow/options/interactions.js +0 -41
- package/dist/cjs/workflow/options/layouts.js +0 -79
- package/dist/cjs/workflow/options/options.js +0 -156
- package/dist/cjs/workflow/options/pagination.js +0 -25
- package/dist/cjs/workflow/options/roles.js +0 -15
- package/dist/cjs/workflow/options/templates.js +0 -30
- package/dist/cjs/workflow/options/trackers.js +0 -83
- package/dist/cjs/workflow/options/utils.js +0 -33
- package/dist/cjs/workflow/processors.js +0 -607
- package/dist/cjs/workflow/recommendation.js +0 -57
- package/dist/cjs/workflow/recommendations.js +0 -18
- package/dist/cjs/workflow/search-based.js +0 -337
- package/dist/cjs/workflow/search.js +0 -64
- package/dist/cjs/workflow/unit.js +0 -57
- package/dist/cjs/workflow/units.js +0 -42
- package/dist/cjs/workflow/use-link.js +0 -49
- package/src/actor/data.js +0 -106
- package/src/actor/feedback.js +0 -28
- package/src/actor/fields.js +0 -51
- package/src/actor/filters.js +0 -149
- package/src/actor/hub.js +0 -47
- package/src/actor/index.js +0 -10
- package/src/actor/interactions.js +0 -32
- package/src/actor/sessions.js +0 -21
- package/src/actor/tracker-states.js +0 -57
- package/src/actor/tracker.js +0 -104
- package/src/actor/trackers.js +0 -45
- package/src/actor/utils.js +0 -7
- package/src/actor/view.js +0 -272
- package/src/actor/views.js +0 -224
- package/src/source.js +0 -17
- package/src/util/proxy.js +0 -81
- package/src/util/trackers.js +0 -84
- package/src/workflow/affiliations.js +0 -121
- package/src/workflow/answer-based.js +0 -312
- package/src/workflow/ask.js +0 -284
- package/src/workflow/asks.js +0 -143
- package/src/workflow/autocompletable.js +0 -67
- package/src/workflow/autocomplete.js +0 -114
- package/src/workflow/base.js +0 -396
- package/src/workflow/context.js +0 -16
- package/src/workflow/explore.js +0 -194
- package/src/workflow/explores.js +0 -18
- package/src/workflow/hybrid-search-answer.js +0 -73
- package/src/workflow/hybrid-search-views.js +0 -116
- package/src/workflow/hybrid-search.js +0 -230
- package/src/workflow/index.js +0 -5
- package/src/workflow/options/api.js +0 -31
- package/src/workflow/options/auto-query.js +0 -70
- package/src/workflow/options/configurable.js +0 -48
- package/src/workflow/options/data-processor.js +0 -15
- package/src/workflow/options/filters.js +0 -10
- package/src/workflow/options/index.js +0 -11
- package/src/workflow/options/interactions.js +0 -36
- package/src/workflow/options/layouts.js +0 -73
- package/src/workflow/options/options.js +0 -175
- package/src/workflow/options/pagination.js +0 -18
- package/src/workflow/options/roles.js +0 -12
- package/src/workflow/options/templates.js +0 -27
- package/src/workflow/options/trackers.js +0 -80
- package/src/workflow/options/utils.js +0 -26
- package/src/workflow/processors.js +0 -490
- package/src/workflow/recommendation.js +0 -63
- package/src/workflow/recommendations.js +0 -14
- package/src/workflow/search-based.js +0 -329
- package/src/workflow/search.js +0 -73
- package/src/workflow/unit.js +0 -51
- package/src/workflow/units.js +0 -43
- package/src/workflow/use-link.js +0 -41
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _commons = require("@miso.ai/commons");
|
|
8
|
-
var _constants = require("../constants.js");
|
|
9
|
-
const {
|
|
10
|
-
IMPRESSION,
|
|
11
|
-
VIEWABLE,
|
|
12
|
-
CLICK
|
|
13
|
-
} = _constants.EVENT_TYPE;
|
|
14
|
-
const {
|
|
15
|
-
UNTRACKED,
|
|
16
|
-
TRIGGERED
|
|
17
|
-
} = _constants.TRACKING_STATUS;
|
|
18
|
-
const UNTRACKED_STATES = Object.freeze({
|
|
19
|
-
[IMPRESSION]: UNTRACKED,
|
|
20
|
-
[VIEWABLE]: UNTRACKED,
|
|
21
|
-
[CLICK]: UNTRACKED
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Tracking states for a session to keep track of the tracking status of each product.
|
|
26
|
-
* For each entry there are status of impression, viewable, and click events.
|
|
27
|
-
*/
|
|
28
|
-
class States {
|
|
29
|
-
constructor(sessionId) {
|
|
30
|
-
this.sessionId = sessionId;
|
|
31
|
-
this._states = new Map(); // item key -> {impression, viewable, click}
|
|
32
|
-
}
|
|
33
|
-
getFullState(item) {
|
|
34
|
-
// when we receive a bind event, impression is trigger, making an entry here
|
|
35
|
-
// so if the state is not found, the product is not present yet => all untracked
|
|
36
|
-
const state = this._states.get(this._getKey(item));
|
|
37
|
-
return state ? Object.assign({}, state) : UNTRACKED_STATES;
|
|
38
|
-
}
|
|
39
|
-
get(item, type) {
|
|
40
|
-
const state = this._states.get(this._getKey(item));
|
|
41
|
-
return state && state[type] || UNTRACKED;
|
|
42
|
-
}
|
|
43
|
-
set(items, type, status) {
|
|
44
|
-
(0, _constants.validateEventType)(type);
|
|
45
|
-
(0, _constants.validateTrackingStatus)(status);
|
|
46
|
-
for (const item of (0, _commons.asArray)(items)) {
|
|
47
|
-
this._setOne(item, type, status);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
untriggered(items, type) {
|
|
51
|
-
return items.filter(item => this.get(item, type) !== TRIGGERED);
|
|
52
|
-
}
|
|
53
|
-
_getKey(item) {
|
|
54
|
-
// TODO: ad-hoc! should move away to higher level
|
|
55
|
-
return item.product_id || item.text || item.id || item;
|
|
56
|
-
}
|
|
57
|
-
_setOne(item, type, status) {
|
|
58
|
-
(0, _commons.computeIfAbsent)(this._states, this._getKey(item), () => Object.assign({}, UNTRACKED_STATES))[type] = status;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.default = States;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _commons = require("@miso.ai/commons");
|
|
8
|
-
var _constants = require("../constants.js");
|
|
9
|
-
var fields = _interopRequireWildcard(require("./fields.js"));
|
|
10
|
-
var _trackerStates = _interopRequireDefault(require("./tracker-states.js"));
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
-
// a dummy item array for manipulating deduplication
|
|
14
|
-
const ITEMLESS_DUMMY_ITEMS = [Symbol('itemless')];
|
|
15
|
-
class Tracker {
|
|
16
|
-
constructor({
|
|
17
|
-
hub,
|
|
18
|
-
role,
|
|
19
|
-
options
|
|
20
|
-
}) {
|
|
21
|
-
this._hub = hub;
|
|
22
|
-
this._role = role;
|
|
23
|
-
this._options = options;
|
|
24
|
-
// TODO: know item type
|
|
25
|
-
|
|
26
|
-
this._states = new _trackerStates.default(this._getSessionId());
|
|
27
|
-
}
|
|
28
|
-
get options() {
|
|
29
|
-
return typeof this._options === 'function' ? this._options() : this._options;
|
|
30
|
-
}
|
|
31
|
-
getState(item) {
|
|
32
|
-
return this._states.getFullState(item);
|
|
33
|
-
}
|
|
34
|
-
_trigger(type, items, meta) {
|
|
35
|
-
(0, _constants.validateEventType)(type);
|
|
36
|
-
const {
|
|
37
|
-
options
|
|
38
|
-
} = this;
|
|
39
|
-
if (!options || options.active === false) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
this._syncSession();
|
|
43
|
-
const {
|
|
44
|
-
deduplicated = true,
|
|
45
|
-
itemless = false
|
|
46
|
-
} = options;
|
|
47
|
-
if (deduplicated) {
|
|
48
|
-
if (itemless) {
|
|
49
|
-
items = ITEMLESS_DUMMY_ITEMS;
|
|
50
|
-
}
|
|
51
|
-
items = this._states.untriggered((0, _commons.asArray)(items), type);
|
|
52
|
-
if (items.length === 0) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
|
|
56
|
-
}
|
|
57
|
-
this._sendToHub(Object.assign({
|
|
58
|
-
type,
|
|
59
|
-
items: itemless ? undefined : items
|
|
60
|
-
}, meta));
|
|
61
|
-
}
|
|
62
|
-
_sendToHub(args) {
|
|
63
|
-
this._hub.trigger(fields.tracker(), Object.freeze((0, _commons.trimObj)(Object.assign({
|
|
64
|
-
role: this._role
|
|
65
|
-
}, args))));
|
|
66
|
-
}
|
|
67
|
-
_syncSession() {
|
|
68
|
-
const sessionId = this._getSessionId();
|
|
69
|
-
if (!sessionId) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (!this._states || sessionId !== this._states.sessionId) {
|
|
73
|
-
this._states = new _trackerStates.default(sessionId);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
_getSessionId() {
|
|
77
|
-
const {
|
|
78
|
-
session
|
|
79
|
-
} = this._getViewState() || {};
|
|
80
|
-
return session && session.uuid;
|
|
81
|
-
}
|
|
82
|
-
_getMisoId() {
|
|
83
|
-
const state = this._getViewState();
|
|
84
|
-
return state && state.meta && state.meta.miso_id || undefined;
|
|
85
|
-
}
|
|
86
|
-
_getRequestPayload() {
|
|
87
|
-
const {
|
|
88
|
-
request
|
|
89
|
-
} = this._getViewState() || {};
|
|
90
|
-
return request && request.payload;
|
|
91
|
-
}
|
|
92
|
-
_getViewState() {
|
|
93
|
-
return this._hub.states[fields.view(this._role)];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.default = Tracker;
|
|
97
|
-
for (const type of _constants.PERFORMANCE_EVENT_TYPES) {
|
|
98
|
-
Tracker.prototype[(0, _commons.snakeToLowerCamel)(type)] = function (items, meta) {
|
|
99
|
-
this._trigger(type, items, meta);
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
for (const type of _constants.DIRECT_TRACKING_EVENT_TYPES) {
|
|
103
|
-
Tracker.prototype[(0, _commons.snakeToLowerCamel)(type)] = function (args) {
|
|
104
|
-
this._syncSession();
|
|
105
|
-
this._sendToHub(Object.assign({}, args, {
|
|
106
|
-
type
|
|
107
|
-
}));
|
|
108
|
-
};
|
|
109
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TrackersActor = void 0;
|
|
7
|
-
exports.proxyTrackers = proxyTrackers;
|
|
8
|
-
var _constants = require("../constants.js");
|
|
9
|
-
var _tracker = _interopRequireDefault(require("./tracker.js"));
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
class TrackersActor {
|
|
12
|
-
constructor(hub, {
|
|
13
|
-
roles,
|
|
14
|
-
options
|
|
15
|
-
}) {
|
|
16
|
-
this._hub = hub;
|
|
17
|
-
this._roles = roles;
|
|
18
|
-
this._options = options;
|
|
19
|
-
this._trackers = {};
|
|
20
|
-
}
|
|
21
|
-
get(role) {
|
|
22
|
-
if (!this._roles.members.includes(role)) {
|
|
23
|
-
throw new Error(`Role "${role}" is not a member of this workflow.`);
|
|
24
|
-
}
|
|
25
|
-
if (!this._trackers[role]) {
|
|
26
|
-
this._trackers[role] = new _tracker.default({
|
|
27
|
-
hub: this._hub,
|
|
28
|
-
role,
|
|
29
|
-
itemless: role === _constants.ROLE.CONTAINER,
|
|
30
|
-
options: () => this._getTrackerOptions(role)
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return this._trackers[role];
|
|
34
|
-
}
|
|
35
|
-
_getTrackerOptions(role) {
|
|
36
|
-
const allTrackerOptions = this._options.resolved.trackers;
|
|
37
|
-
return allTrackerOptions && allTrackerOptions[role] || {
|
|
38
|
-
active: false
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.TrackersActor = TrackersActor;
|
|
43
|
-
function proxyTrackers(trackers) {
|
|
44
|
-
return new Proxy(trackers, {
|
|
45
|
-
get: (target, prop) => {
|
|
46
|
-
try {
|
|
47
|
-
return target.get(prop);
|
|
48
|
-
} catch (_) {}
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
package/dist/cjs/actor/utils.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isCurrentSession = isCurrentSession;
|
|
7
|
-
function isCurrentSession(hub, session) {
|
|
8
|
-
if (!session) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const {
|
|
12
|
-
session: currentSession
|
|
13
|
-
} = hub.states;
|
|
14
|
-
return currentSession && currentSession.index === session.index;
|
|
15
|
-
}
|
package/dist/cjs/actor/view.js
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _commons = require("@miso.ai/commons");
|
|
8
|
-
var _constants = require("../constants.js");
|
|
9
|
-
var fields = _interopRequireWildcard(require("./fields.js"));
|
|
10
|
-
var _proxy = _interopRequireDefault(require("../util/proxy.js"));
|
|
11
|
-
const _excluded = ["value", "error", "status", "meta"];
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
15
|
-
// TODO: browser dependency on syncSize
|
|
16
|
-
|
|
17
|
-
function statesEqual(a, b) {
|
|
18
|
-
return a === b || a && b && a.status === b.status && a.error === b.error && a.value === b.value &&
|
|
19
|
-
// skip deep equals
|
|
20
|
-
a.ongoing === b.ongoing && stateEmptyness(a) === stateEmptyness(b) &&
|
|
21
|
-
// TODO: ad-hoc
|
|
22
|
-
sessionEquals(a.session, b.session);
|
|
23
|
-
}
|
|
24
|
-
function sessionEquals(a, b) {
|
|
25
|
-
return a === b || a && b && a.uuid === b.uuid;
|
|
26
|
-
}
|
|
27
|
-
function stateEmptyness(data) {
|
|
28
|
-
return data && data.meta && data.meta.empty;
|
|
29
|
-
}
|
|
30
|
-
class ViewActor {
|
|
31
|
-
constructor(views, role) {
|
|
32
|
-
this._events = new _commons.EventEmitter({
|
|
33
|
-
target: this
|
|
34
|
-
});
|
|
35
|
-
this._views = views;
|
|
36
|
-
// TODO: we should pull this up to views, for the results are also used in judging container emptyness
|
|
37
|
-
this._mapping = asMappingFunction((views._roles.mappings || {})[role] || role);
|
|
38
|
-
(0, _commons.defineValues)(this, {
|
|
39
|
-
role,
|
|
40
|
-
interface: new View(this)
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
get hub() {
|
|
44
|
-
return this._views._hub;
|
|
45
|
-
}
|
|
46
|
-
get element() {
|
|
47
|
-
return this._element;
|
|
48
|
-
}
|
|
49
|
-
set element(element) {
|
|
50
|
-
if (element === this._element) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (this._element) {
|
|
54
|
-
this._safeApplyOnLayout('unrender', this._element);
|
|
55
|
-
}
|
|
56
|
-
this._element = element;
|
|
57
|
-
this._proxyElement && this._proxyElement.sync();
|
|
58
|
-
this._events.emit('element', element);
|
|
59
|
-
this.refresh({
|
|
60
|
-
force: true
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
get proxyElement() {
|
|
64
|
-
if (!this._proxyElement) {
|
|
65
|
-
this._proxyElement = new _proxy.default(() => this.element);
|
|
66
|
-
}
|
|
67
|
-
return this._proxyElement;
|
|
68
|
-
}
|
|
69
|
-
get layout() {
|
|
70
|
-
return this._layout;
|
|
71
|
-
}
|
|
72
|
-
set layout(layout) {
|
|
73
|
-
if (layout === this._layout) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (layout && typeof layout.render !== 'function') {
|
|
77
|
-
throw new Error(`Render function is mandatory in a layout.`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// clean up old layout
|
|
81
|
-
const {
|
|
82
|
-
element
|
|
83
|
-
} = this;
|
|
84
|
-
element && this._safeApplyOnLayout('unrender', element);
|
|
85
|
-
this._safeApplyOnLayout('destroy');
|
|
86
|
-
this._layout = layout;
|
|
87
|
-
|
|
88
|
-
// initialize new layout
|
|
89
|
-
if (layout) {
|
|
90
|
-
layout._view = this;
|
|
91
|
-
// don't use _safeApplyOnLayout, for any error should be thrown
|
|
92
|
-
if (typeof layout.initialize === 'function') {
|
|
93
|
-
layout.initialize(this);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// in case the data is already there
|
|
98
|
-
this.refresh({
|
|
99
|
-
force: true
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
get tracker() {
|
|
103
|
-
return this._views.trackers[this.role];
|
|
104
|
-
}
|
|
105
|
-
get workflow() {
|
|
106
|
-
return this._views._workflow;
|
|
107
|
-
}
|
|
108
|
-
get workflowOptions() {
|
|
109
|
-
return this._views._options.resolved;
|
|
110
|
-
}
|
|
111
|
-
get trackerOptions() {
|
|
112
|
-
return this._views._getTrackerOptions(this.role);
|
|
113
|
-
}
|
|
114
|
-
get filters() {
|
|
115
|
-
return this._views.filters;
|
|
116
|
-
}
|
|
117
|
-
async refresh({
|
|
118
|
-
force = false,
|
|
119
|
-
data
|
|
120
|
-
} = {}) {
|
|
121
|
-
// protocol: no reaction when layout is absent
|
|
122
|
-
if (!this._layout) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// nothing to do when element is absent
|
|
127
|
-
const {
|
|
128
|
-
element
|
|
129
|
-
} = this;
|
|
130
|
-
if (!element) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// sync data
|
|
135
|
-
const previousData = this._data;
|
|
136
|
-
this._data = data = this._sliceData(data || this._views._getData());
|
|
137
|
-
|
|
138
|
-
// if data is unchanged, skip unless forced
|
|
139
|
-
if (!force && statesEqual(data, previousData)) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const {
|
|
143
|
-
session,
|
|
144
|
-
status,
|
|
145
|
-
ongoing,
|
|
146
|
-
request,
|
|
147
|
-
meta,
|
|
148
|
-
value
|
|
149
|
-
} = data;
|
|
150
|
-
const baseState = Object.assign({
|
|
151
|
-
session,
|
|
152
|
-
status,
|
|
153
|
-
ongoing,
|
|
154
|
-
request,
|
|
155
|
-
meta,
|
|
156
|
-
data: value
|
|
157
|
-
}, getDataEmptyness(this.role, data));
|
|
158
|
-
|
|
159
|
-
// render
|
|
160
|
-
const notifyUpdate = (state = {}, options) => {
|
|
161
|
-
state !== false && this.updateState(Object.assign({}, baseState, state), options);
|
|
162
|
-
};
|
|
163
|
-
try {
|
|
164
|
-
await this._layout.render(element, data, {
|
|
165
|
-
notifyUpdate
|
|
166
|
-
});
|
|
167
|
-
} catch (error) {
|
|
168
|
-
this._error(error);
|
|
169
|
-
notifyUpdate({
|
|
170
|
-
error
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
updateState(state, {
|
|
175
|
-
silent = false
|
|
176
|
-
} = {}) {
|
|
177
|
-
// there might be error from notifyUpdate() call
|
|
178
|
-
const status = state.error ? _constants.STATUS.ERRONEOUS : state.status;
|
|
179
|
-
state = this._state = Object.freeze((0, _commons.trimObj)(Object.assign({}, state, {
|
|
180
|
-
status
|
|
181
|
-
})));
|
|
182
|
-
const {
|
|
183
|
-
role
|
|
184
|
-
} = this;
|
|
185
|
-
this.hub.update(fields.view(role), state, {
|
|
186
|
-
silent
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
_sliceData(data) {
|
|
190
|
-
const {
|
|
191
|
-
value,
|
|
192
|
-
status,
|
|
193
|
-
meta
|
|
194
|
-
} = data,
|
|
195
|
-
rest = _objectWithoutPropertiesLoose(data, _excluded);
|
|
196
|
-
const sliced = Object.assign({
|
|
197
|
-
value: this._mapping(data, this),
|
|
198
|
-
status,
|
|
199
|
-
data: value,
|
|
200
|
-
meta
|
|
201
|
-
}, rest);
|
|
202
|
-
if (this.role === _constants.ROLE.CONTAINER) {
|
|
203
|
-
// pass empty/nonempty information
|
|
204
|
-
sliced.meta = Object.assign({}, meta, {
|
|
205
|
-
empty: this._isContainerEmpty(data)
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
return (0, _commons.trimObj)(sliced);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// TODO: move this to workflow
|
|
212
|
-
_isContainerEmpty(data) {
|
|
213
|
-
const {
|
|
214
|
-
element
|
|
215
|
-
} = this;
|
|
216
|
-
if (!element) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
// iterate over all member components' roles
|
|
220
|
-
for (const {
|
|
221
|
-
role
|
|
222
|
-
} of element.components) {
|
|
223
|
-
// not a data role -> irrelevant
|
|
224
|
-
if (!(0, _constants.isDataRole)(role)) {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
// respect data mapping
|
|
228
|
-
const mapping = asMappingFunction((this._views._roles.mappings || {})[role] || role);
|
|
229
|
-
const sliced = mapping(data, this); // TODO: the view passed in should be the view of the role, not container role
|
|
230
|
-
if (!isDateValueEmpty(role, sliced)) {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
_syncSize() {
|
|
237
|
-
this._element && this._safeApplyOnLayout('syncSize', this._element);
|
|
238
|
-
}
|
|
239
|
-
_safeApplyOnLayout(method, ...args) {
|
|
240
|
-
if (!this._layout || typeof this._layout[method] !== 'function') {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
try {
|
|
244
|
-
this._layout[method](...args);
|
|
245
|
-
} catch (e) {
|
|
246
|
-
this._error(e);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
_emit(name, data) {
|
|
250
|
-
this._events.emit(name, data);
|
|
251
|
-
this._views._events.emit(`${this.role}:${name}`, data);
|
|
252
|
-
}
|
|
253
|
-
_error(e) {
|
|
254
|
-
this._views._error(e);
|
|
255
|
-
}
|
|
256
|
-
_destroy() {
|
|
257
|
-
this._safeApplyOnLayout('destroy');
|
|
258
|
-
this._proxyElement && this._proxyElement.destroy();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
exports.default = ViewActor;
|
|
262
|
-
class View {
|
|
263
|
-
constructor(actor) {
|
|
264
|
-
(0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'tracker']);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function asMappingFunction(fn) {
|
|
268
|
-
switch (typeof fn) {
|
|
269
|
-
case 'function':
|
|
270
|
-
return fn;
|
|
271
|
-
case 'string':
|
|
272
|
-
return data => data.value && data.value[fn];
|
|
273
|
-
default:
|
|
274
|
-
throw new Error(`Invalid mapping function: ${fn}`);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function getDataEmptyness(role, data) {
|
|
278
|
-
return isDataStatusRelevantToEmptyness(data) ? {
|
|
279
|
-
empty: !!isDateValueEmpty(role, data && data.value)
|
|
280
|
-
} : {};
|
|
281
|
-
}
|
|
282
|
-
function isDataStatusRelevantToEmptyness(data) {
|
|
283
|
-
return data.status === _constants.STATUS.READY && !data.ongoing;
|
|
284
|
-
}
|
|
285
|
-
function isDateValueEmpty(role, value) {
|
|
286
|
-
// TODO: ad-hoc
|
|
287
|
-
switch (role) {
|
|
288
|
-
case _constants.ROLE.ANSWER:
|
|
289
|
-
case _constants.ROLE.REASONING:
|
|
290
|
-
return !value || !value.value;
|
|
291
|
-
default:
|
|
292
|
-
return value === undefined || (Array.isArray(value) || typeof value === 'string') && !value.length;
|
|
293
|
-
}
|
|
294
|
-
}
|