@media-quest/builder 0.0.1 → 0.0.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/public-api.d.mts +652 -0
- package/dist/public-api.d.ts +652 -0
- package/dist/public-api.js +2187 -0
- package/dist/public-api.mjs +2136 -0
- package/package.json +11 -3
- package/src/Builder-option.ts +67 -0
- package/src/Builder-page.spec.ts +313 -0
- package/src/Builder-page.ts +249 -0
- package/src/Builder-question.spec.ts +68 -0
- package/src/Builder-question.ts +101 -0
- package/src/Builder-schema.spec.ts +302 -0
- package/src/Builder-schema.ts +250 -0
- package/src/Builder-text.spec.ts +24 -0
- package/src/Builder-text.ts +57 -0
- package/src/BuilderMainImageDto.ts +7 -0
- package/src/BuilderMainText.ts +81 -0
- package/src/BuilderMainVideoDto.ts +10 -0
- package/src/BuilderObject.ts +69 -0
- package/src/BuilderTag.ts +97 -0
- package/src/media-files.ts +28 -0
- package/src/public-api.ts +13 -6
- package/src/rulebuilder/Builder-rule.spec.ts +207 -0
- package/src/rulebuilder/Builder-rule.ts +134 -0
- package/src/rulebuilder/RuleAction.ts +20 -0
- package/src/rulebuilder/RuleBuilder-test-utils.ts +254 -0
- package/src/rulebuilder/RuleInput.ts +44 -0
- package/src/rulebuilder/RuleVariable.ts +39 -0
- package/src/rulebuilder/SingleSelectItem.ts +135 -0
- package/src/rulebuilder/condition/Builder-condition-group.spec.ts +47 -0
- package/src/rulebuilder/condition/Builder-condition-group.ts +91 -0
- package/src/rulebuilder/condition/Builder-condition.spec.ts +169 -0
- package/src/rulebuilder/condition/Builder-condition.ts +186 -0
- package/src/rulebuilder/condition/Builder-operator.spec.ts +9 -0
- package/src/rulebuilder/condition/Builder-operator.ts +31 -0
- package/src/rulebuilder/index.ts +22 -0
- package/src/rulebuilder/jump-to-action-manager.ts +33 -0
- package/src/rulebuilder/multi-select-item.ts +70 -0
- package/src/rulebuilder/page-action-manager.ts +20 -0
- package/src/rulebuilder/tag-action-manager.spec.ts +44 -0
- package/src/rulebuilder/tag-action-manager.ts +18 -0
- package/src/theme/AbstractThemeCompiler.ts +7 -0
- package/src/theme/IDefaultTheme.ts +178 -0
- package/src/theme/css-theme.ts +7 -0
- package/src/theme/default-theme-compiler.ts +395 -0
- package/src/theme/icon-urls.ts +29 -0
- package/src/theme/standard-props.ts +113 -0
- package/src/theme/theme-utils.ts +110 -0
- package/src/theme/theme1.spec.ts +52 -0
- package/tsconfig.json +0 -2
|
@@ -0,0 +1,2187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/public-api.ts
|
|
21
|
+
var public_api_exports = {};
|
|
22
|
+
__export(public_api_exports, {
|
|
23
|
+
BuilderCondition: () => BuilderCondition,
|
|
24
|
+
BuilderConditionGroup: () => BuilderConditionGroup,
|
|
25
|
+
BuilderMainText: () => BuilderMainText,
|
|
26
|
+
BuilderOperator: () => BuilderOperator,
|
|
27
|
+
BuilderOption: () => BuilderOption,
|
|
28
|
+
BuilderPage: () => BuilderPage,
|
|
29
|
+
BuilderQuestion: () => BuilderQuestion,
|
|
30
|
+
BuilderRule: () => BuilderRule,
|
|
31
|
+
BuilderSchema: () => BuilderSchema,
|
|
32
|
+
BuilderTag: () => BuilderTag,
|
|
33
|
+
BuilderText: () => BuilderText,
|
|
34
|
+
BuilderVariableOption: () => BuilderVariableOption,
|
|
35
|
+
CustomVariable: () => CustomVariable,
|
|
36
|
+
ExcludeByPageIdSelectItem: () => ExcludeByPageIdSelectItem,
|
|
37
|
+
ExcludeByTagSelectItem: () => ExcludeByTagSelectItem,
|
|
38
|
+
JumpToActionManager: () => JumpToActionManager,
|
|
39
|
+
JumpToPageSelectItem: () => JumpToPageSelectItem,
|
|
40
|
+
MultiSelectItem: () => MultiSelectItem,
|
|
41
|
+
OperatorSelectItem: () => OperatorSelectItem,
|
|
42
|
+
PageActionManager: () => PageActionManager,
|
|
43
|
+
QuestionVariable: () => QuestionVariable,
|
|
44
|
+
RuleInput: () => RuleInput,
|
|
45
|
+
RuleOptionSelectItem: () => RuleOptionSelectItem,
|
|
46
|
+
RuleVariableSelectItem: () => RuleVariableSelectItem,
|
|
47
|
+
SingleSelectItem: () => SingleSelectItem,
|
|
48
|
+
TagActionManager: () => TagActionManager,
|
|
49
|
+
TagCollection: () => TagCollection
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(public_api_exports);
|
|
52
|
+
|
|
53
|
+
// src/BuilderObject.ts
|
|
54
|
+
var import_engine = require("@media-quest/engine");
|
|
55
|
+
var U = import_engine.DUtil;
|
|
56
|
+
var BuilderObjectId;
|
|
57
|
+
((BuilderObjectId2) => {
|
|
58
|
+
BuilderObjectId2.createTagId = () => {
|
|
59
|
+
return createId("builder-tag");
|
|
60
|
+
};
|
|
61
|
+
BuilderObjectId2.mainTextId = () => {
|
|
62
|
+
return createId("builder-main-text");
|
|
63
|
+
};
|
|
64
|
+
BuilderObjectId2.textId = () => {
|
|
65
|
+
return createId("builder-text");
|
|
66
|
+
};
|
|
67
|
+
BuilderObjectId2.questionOptionId = () => {
|
|
68
|
+
return createId("builder-question-option");
|
|
69
|
+
};
|
|
70
|
+
BuilderObjectId2.questionId = () => {
|
|
71
|
+
return createId("builder-question");
|
|
72
|
+
};
|
|
73
|
+
BuilderObjectId2.pageId = () => {
|
|
74
|
+
return createId("builder-page");
|
|
75
|
+
};
|
|
76
|
+
const createId = (type) => {
|
|
77
|
+
const id = U.randomString(24);
|
|
78
|
+
return type + "-" + id;
|
|
79
|
+
};
|
|
80
|
+
})(BuilderObjectId || (BuilderObjectId = {}));
|
|
81
|
+
var BuilderObject = class {
|
|
82
|
+
originalDto;
|
|
83
|
+
constructor(dto) {
|
|
84
|
+
this.originalDto = dto;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/theme/icon-urls.ts
|
|
89
|
+
var IconUrls = {
|
|
90
|
+
ispeWhitePng: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fispe-hvit.png?alt=media&token=f6fe628b-2d99-472d-a2ea-e062873e2e22",
|
|
91
|
+
pauseSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fpause-24px.svg?alt=media&token=47337491-bb0d-4c56-9c89-a073ce19fad4",
|
|
92
|
+
pauseCircleOutlineSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fpause_circle_outline-24px.svg?alt=media&token=133aabc8-ab9a-4eaa-9914-4f0f82c22ee2",
|
|
93
|
+
pauseCircleFilledSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fpause_circle_filled-24px.svg?alt=media&token=af3f12c3-3199-4096-8ed2-76347b9a0a0a",
|
|
94
|
+
playCircleRegular: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fplay-circle-regular.svg?alt=media&token=0867b690-d7fd-475c-8e91-b2d7aeca54d1",
|
|
95
|
+
playArrowSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fplay_arrow-24px.svg?alt=media&token=2fa95e1f-61f7-4a18-afb3-210eabae8227",
|
|
96
|
+
playCircleOutline: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fplay_circle_outline-24px.svg?alt=media&token=3a9f62c5-dfa2-40ef-a50e-cf1bdd2d47f2",
|
|
97
|
+
stopCircleSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fstop_circle-24px.svg?alt=media&token=8fbc8b89-29bb-49ad-ae11-b8882ba3ca77",
|
|
98
|
+
stopSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fstop-24px.svg?alt=media&token=d2cd41f1-1331-4243-9b7a-dc0f0ccd255d",
|
|
99
|
+
replayCircleSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Freplay-24px.svg?alt=media&token=3c35ccf4-b467-4e81-85d6-b36ac64738ad",
|
|
100
|
+
volumeOffSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fvolume_off-24px.svg?alt=media&token=4e41cc10-9f4b-4967-b4df-ed0682e657a9",
|
|
101
|
+
volumeUpSvg: "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fvolume_up-24px.svg?alt=media&token=551bd0a6-a515-4f87-a245-da433f4833f9"
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/theme/IDefaultTheme.ts
|
|
105
|
+
var BuilderOptionTheme;
|
|
106
|
+
((BuilderOptionTheme2) => {
|
|
107
|
+
const GREEN = "#70AD47";
|
|
108
|
+
const YELLOW = "#FFC000";
|
|
109
|
+
const ORANGE = "#F4902C";
|
|
110
|
+
const RED = "#FF0000";
|
|
111
|
+
const LIGHT_BLUE = "#42719C";
|
|
112
|
+
const WHITE = "#ffffff";
|
|
113
|
+
const BLUE = "#2F5597";
|
|
114
|
+
const BTN_WIDTH = 18.5;
|
|
115
|
+
const BTN_BORDER_WIDTH = 3;
|
|
116
|
+
const BTN_BORDER_RADIUS = 10;
|
|
117
|
+
const BTN_BORDER_STYLE = "solid";
|
|
118
|
+
const BTN_HEIGHT = 9.2;
|
|
119
|
+
const BTN_SHORT_WIDTH = 13.7;
|
|
120
|
+
const FONT_WEIGHT = 600;
|
|
121
|
+
const FONT_SIZE = 35;
|
|
122
|
+
BuilderOptionTheme2.blueButton = () => ({
|
|
123
|
+
name: "blue-button-theme",
|
|
124
|
+
div: {
|
|
125
|
+
css: {
|
|
126
|
+
backgroundColor: BLUE,
|
|
127
|
+
borderColor: BLUE,
|
|
128
|
+
textColor: WHITE,
|
|
129
|
+
fontSize: { _unit: "px", value: FONT_SIZE },
|
|
130
|
+
borderWidth: { _unit: "px", value: BTN_BORDER_WIDTH },
|
|
131
|
+
borderStyle: BTN_BORDER_STYLE,
|
|
132
|
+
borderRadius: { value: BTN_BORDER_RADIUS, _unit: "px" },
|
|
133
|
+
padding: { _unit: "px", value: 40 },
|
|
134
|
+
h: BTN_HEIGHT,
|
|
135
|
+
w: BTN_WIDTH,
|
|
136
|
+
x: 10,
|
|
137
|
+
y: 8,
|
|
138
|
+
textAlign: "center"
|
|
139
|
+
},
|
|
140
|
+
cssDisabled: { opacity: 0.3, cursor: "not-allowed" },
|
|
141
|
+
cssEnabled: { opacity: 1, cursor: "pointer" }
|
|
142
|
+
},
|
|
143
|
+
text1: {
|
|
144
|
+
y: 50,
|
|
145
|
+
transform: "translate(0%, 50%)",
|
|
146
|
+
textColor: WHITE,
|
|
147
|
+
fontSize: { _unit: "px", value: FONT_SIZE },
|
|
148
|
+
w: 84,
|
|
149
|
+
x: 8,
|
|
150
|
+
fontWeight: FONT_WEIGHT,
|
|
151
|
+
textAlign: "center"
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
})(BuilderOptionTheme || (BuilderOptionTheme = {}));
|
|
155
|
+
var DefaultTheme = {
|
|
156
|
+
name: "default-theme",
|
|
157
|
+
videoPlayer: {
|
|
158
|
+
playButton: {
|
|
159
|
+
iconUrl: IconUrls.playCircleRegular,
|
|
160
|
+
css: { w: 5, h: 5, y: 48, x: 4 },
|
|
161
|
+
cssDisabled: { opacity: 0.3, cursor: "not-allowed" },
|
|
162
|
+
cssEnabled: { opacity: 0.8, cursor: "pointer" }
|
|
163
|
+
},
|
|
164
|
+
pauseButton: {
|
|
165
|
+
iconUrl: IconUrls.pauseSvg,
|
|
166
|
+
css: { w: 5, h: 5, y: 48, x: 4 },
|
|
167
|
+
cssDisabled: { opacity: 0.3, cursor: "not-allowed" },
|
|
168
|
+
cssEnabled: { opacity: 0.8, cursor: "pointer" }
|
|
169
|
+
},
|
|
170
|
+
videoElement: { css: { w: 100, h: 45, y: 55, x: 0 } }
|
|
171
|
+
},
|
|
172
|
+
image: { style: { h: 50, w: 100, x: 0 } },
|
|
173
|
+
mainText: {
|
|
174
|
+
noMedia: {
|
|
175
|
+
text: {
|
|
176
|
+
css: {
|
|
177
|
+
w: 80,
|
|
178
|
+
y: 27,
|
|
179
|
+
x: 10,
|
|
180
|
+
textAlign: "center",
|
|
181
|
+
textColor: "black",
|
|
182
|
+
fontSize: { _unit: "px", value: 30 }
|
|
183
|
+
},
|
|
184
|
+
cssDisabled: {},
|
|
185
|
+
cssEnabled: {}
|
|
186
|
+
},
|
|
187
|
+
audio: {
|
|
188
|
+
css: {
|
|
189
|
+
h: 6,
|
|
190
|
+
w: 6,
|
|
191
|
+
x: 4,
|
|
192
|
+
y: 32,
|
|
193
|
+
cursor: "pointer",
|
|
194
|
+
opacity: 0.8,
|
|
195
|
+
visibility: "visible"
|
|
196
|
+
},
|
|
197
|
+
cssDisabled: { opacity: 0.3, cursor: "not-allowed" },
|
|
198
|
+
cssEnabled: { opacity: 0.8, cursor: "pointer" }
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
withMedia: {
|
|
202
|
+
text: {
|
|
203
|
+
css: {
|
|
204
|
+
w: 80,
|
|
205
|
+
y: 27,
|
|
206
|
+
x: 10,
|
|
207
|
+
textAlign: "center",
|
|
208
|
+
textColor: "black",
|
|
209
|
+
fontSize: { _unit: "px", value: 30 }
|
|
210
|
+
},
|
|
211
|
+
cssDisabled: {},
|
|
212
|
+
cssEnabled: {}
|
|
213
|
+
},
|
|
214
|
+
audio: {
|
|
215
|
+
css: {
|
|
216
|
+
h: 6,
|
|
217
|
+
w: 6,
|
|
218
|
+
x: 4,
|
|
219
|
+
y: 32,
|
|
220
|
+
cursor: "pointer",
|
|
221
|
+
opacity: 0.8,
|
|
222
|
+
visibility: "visible"
|
|
223
|
+
},
|
|
224
|
+
cssDisabled: { opacity: 0.3, cursor: "not-allowed" },
|
|
225
|
+
cssEnabled: { opacity: 0.8, cursor: "pointer" }
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
nextButtonTheme: BuilderOptionTheme.blueButton(),
|
|
230
|
+
responseButtons: BuilderOptionTheme.blueButton()
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/Builder-option.ts
|
|
234
|
+
var BuilderOption = class _BuilderOption extends BuilderObject {
|
|
235
|
+
objectType = "builder-question-option";
|
|
236
|
+
theme = DefaultTheme.responseButtons;
|
|
237
|
+
id;
|
|
238
|
+
value;
|
|
239
|
+
label = "";
|
|
240
|
+
_labelAudioFile = false;
|
|
241
|
+
get labelAudioFile() {
|
|
242
|
+
return this._labelAudioFile;
|
|
243
|
+
}
|
|
244
|
+
set labelAudioFile(audioFile) {
|
|
245
|
+
this._labelAudioFile = audioFile;
|
|
246
|
+
}
|
|
247
|
+
constructor(dto) {
|
|
248
|
+
super(dto);
|
|
249
|
+
this.id = dto.id;
|
|
250
|
+
this.value = dto.value;
|
|
251
|
+
this.label = dto.label;
|
|
252
|
+
}
|
|
253
|
+
static create(value, label) {
|
|
254
|
+
const id = BuilderObjectId.questionOptionId();
|
|
255
|
+
const dto = {
|
|
256
|
+
id,
|
|
257
|
+
value,
|
|
258
|
+
label
|
|
259
|
+
};
|
|
260
|
+
const instance = new _BuilderOption(dto);
|
|
261
|
+
return instance;
|
|
262
|
+
}
|
|
263
|
+
static fromJson(dto) {
|
|
264
|
+
const instance = new _BuilderOption(dto);
|
|
265
|
+
return instance;
|
|
266
|
+
}
|
|
267
|
+
toJson() {
|
|
268
|
+
const dto = {
|
|
269
|
+
id: this.id,
|
|
270
|
+
value: this.value,
|
|
271
|
+
label: this.label
|
|
272
|
+
};
|
|
273
|
+
return dto;
|
|
274
|
+
}
|
|
275
|
+
clone() {
|
|
276
|
+
const cloneId = BuilderObjectId.questionOptionId();
|
|
277
|
+
const dto = this.toJson();
|
|
278
|
+
const cloneDto = { ...dto, id: cloneId };
|
|
279
|
+
return cloneDto;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/Builder-question.ts
|
|
284
|
+
var BuilderQuestion = class _BuilderQuestion extends BuilderObject {
|
|
285
|
+
objectType = "builder-question";
|
|
286
|
+
id;
|
|
287
|
+
type;
|
|
288
|
+
questionText = "";
|
|
289
|
+
options = [];
|
|
290
|
+
prefix = "";
|
|
291
|
+
static create = (type) => {
|
|
292
|
+
const id = BuilderObjectId.questionId();
|
|
293
|
+
return new _BuilderQuestion({
|
|
294
|
+
id,
|
|
295
|
+
_type: type,
|
|
296
|
+
text: "",
|
|
297
|
+
options: [],
|
|
298
|
+
prefix: ""
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
static fromJson(dto) {
|
|
302
|
+
const question = new _BuilderQuestion(dto);
|
|
303
|
+
return question;
|
|
304
|
+
}
|
|
305
|
+
constructor(dto) {
|
|
306
|
+
super(dto);
|
|
307
|
+
this.id = dto.id;
|
|
308
|
+
this.type = dto._type;
|
|
309
|
+
this.questionText = dto.text;
|
|
310
|
+
this.prefix = dto.prefix;
|
|
311
|
+
this.options = dto.options.map((o) => BuilderOption.fromJson(o));
|
|
312
|
+
}
|
|
313
|
+
addOption(label, value, atIndex = -1) {
|
|
314
|
+
const option = BuilderOption.create(value, label);
|
|
315
|
+
if (atIndex >= 0 && atIndex < this.options.length) {
|
|
316
|
+
this.options.splice(atIndex, 0, option);
|
|
317
|
+
} else {
|
|
318
|
+
this.options.push(option);
|
|
319
|
+
}
|
|
320
|
+
return option;
|
|
321
|
+
}
|
|
322
|
+
deleteOption(option) {
|
|
323
|
+
const filtered = this.options.filter((o) => o.id !== option.id);
|
|
324
|
+
const didDelete = filtered.length === this.options.length - 1;
|
|
325
|
+
this.options = filtered;
|
|
326
|
+
return didDelete;
|
|
327
|
+
}
|
|
328
|
+
toJson() {
|
|
329
|
+
const optionsJson = this.options.map((o) => o.toJson());
|
|
330
|
+
const dto = {
|
|
331
|
+
id: this.id,
|
|
332
|
+
prefix: this.prefix,
|
|
333
|
+
_type: this.type,
|
|
334
|
+
text: this.questionText,
|
|
335
|
+
options: optionsJson
|
|
336
|
+
};
|
|
337
|
+
return dto;
|
|
338
|
+
}
|
|
339
|
+
clone() {
|
|
340
|
+
const cloneId = BuilderObjectId.questionId();
|
|
341
|
+
const dto = this.toJson();
|
|
342
|
+
const optionsClone = this.options.map((o) => o.clone());
|
|
343
|
+
const clonedDto = {
|
|
344
|
+
...dto,
|
|
345
|
+
id: cloneId,
|
|
346
|
+
options: optionsClone
|
|
347
|
+
};
|
|
348
|
+
return clonedDto;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// src/BuilderMainText.ts
|
|
353
|
+
var BuilderMainText = class _BuilderMainText extends BuilderObject {
|
|
354
|
+
objectType = "builder-main-text";
|
|
355
|
+
autoplay = false;
|
|
356
|
+
_audioFile = false;
|
|
357
|
+
autoplayDelay = 0;
|
|
358
|
+
text = "";
|
|
359
|
+
constructor(dto) {
|
|
360
|
+
super(dto);
|
|
361
|
+
this._audioFile = dto.audioFile ?? false;
|
|
362
|
+
this.autoplay = dto.autoplay ?? false;
|
|
363
|
+
this.autoplayDelay = dto.autoplayDelay ?? 0;
|
|
364
|
+
this.text = dto.text ?? "";
|
|
365
|
+
}
|
|
366
|
+
get autoplayDelayInSeconds() {
|
|
367
|
+
const delay = this.autoplayDelay;
|
|
368
|
+
const s = delay / 1e3;
|
|
369
|
+
const formatted = s.toFixed(1);
|
|
370
|
+
return formatted;
|
|
371
|
+
}
|
|
372
|
+
get durationTag() {
|
|
373
|
+
if (!this.audioFile)
|
|
374
|
+
return "";
|
|
375
|
+
const dur = this.audioFile.duration.toFixed(1);
|
|
376
|
+
return "dur " + dur + " s";
|
|
377
|
+
}
|
|
378
|
+
static fromJson(dto) {
|
|
379
|
+
const mainText = new _BuilderMainText(dto);
|
|
380
|
+
return mainText;
|
|
381
|
+
}
|
|
382
|
+
static create = () => {
|
|
383
|
+
const dto = {
|
|
384
|
+
autoplay: false,
|
|
385
|
+
autoplayDelay: 0,
|
|
386
|
+
audioFile: false,
|
|
387
|
+
text: ""
|
|
388
|
+
};
|
|
389
|
+
return new _BuilderMainText(dto);
|
|
390
|
+
};
|
|
391
|
+
clone() {
|
|
392
|
+
const dto = this.toJson();
|
|
393
|
+
const clone = JSON.parse(JSON.stringify(dto));
|
|
394
|
+
return clone;
|
|
395
|
+
}
|
|
396
|
+
toJson() {
|
|
397
|
+
const dto = {
|
|
398
|
+
text: this.text,
|
|
399
|
+
audioFile: this.audioFile,
|
|
400
|
+
autoplay: this.autoplay,
|
|
401
|
+
autoplayDelay: this.autoplayDelay
|
|
402
|
+
};
|
|
403
|
+
return dto;
|
|
404
|
+
}
|
|
405
|
+
get audioFile() {
|
|
406
|
+
return this._audioFile;
|
|
407
|
+
}
|
|
408
|
+
set audioFile(audioFile) {
|
|
409
|
+
if (audioFile === false) {
|
|
410
|
+
this.autoplayDelay = 0;
|
|
411
|
+
this.autoplay = false;
|
|
412
|
+
}
|
|
413
|
+
this._audioFile = audioFile;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// src/rulebuilder/RuleVariable.ts
|
|
418
|
+
var BuilderVariableOption = class {
|
|
419
|
+
constructor(label, value) {
|
|
420
|
+
this.label = label;
|
|
421
|
+
this.value = value;
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
var QuestionVariable = class {
|
|
425
|
+
constructor(varId, label, options, pageNumber) {
|
|
426
|
+
this.varId = varId;
|
|
427
|
+
this.label = label;
|
|
428
|
+
this.options = options;
|
|
429
|
+
this.pageNumber = pageNumber;
|
|
430
|
+
}
|
|
431
|
+
kind = "question-variable";
|
|
432
|
+
dataType = "numericWithOptions";
|
|
433
|
+
};
|
|
434
|
+
var CustomVariable = class {
|
|
435
|
+
constructor(varId, label, options) {
|
|
436
|
+
this.varId = varId;
|
|
437
|
+
this.label = label;
|
|
438
|
+
this.options = options;
|
|
439
|
+
}
|
|
440
|
+
kind = "configuration-variable";
|
|
441
|
+
dataType = "numericWithOptions";
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// src/Builder-page.ts
|
|
445
|
+
var import_engine2 = require("@media-quest/engine");
|
|
446
|
+
var U2 = import_engine2.DUtil;
|
|
447
|
+
var BuilderPage = class _BuilderPage extends BuilderObject {
|
|
448
|
+
objectType = "builder-page";
|
|
449
|
+
id;
|
|
450
|
+
_pageType;
|
|
451
|
+
_prefix = "";
|
|
452
|
+
_questions = [];
|
|
453
|
+
_tags;
|
|
454
|
+
_backgroundColor = "#FFFFFF";
|
|
455
|
+
mainMedia = false;
|
|
456
|
+
defaultQuestion;
|
|
457
|
+
mainText;
|
|
458
|
+
nextButton = BuilderOption.create(-1, "Neste");
|
|
459
|
+
static create(type, _prefix) {
|
|
460
|
+
const id = BuilderObjectId.pageId();
|
|
461
|
+
const mainTextDto = {
|
|
462
|
+
text: "",
|
|
463
|
+
audioFile: false,
|
|
464
|
+
autoplay: false,
|
|
465
|
+
autoplayDelay: 0
|
|
466
|
+
};
|
|
467
|
+
const nextButtonDto = BuilderOption.create(-1, "page-next-button-text").toJson();
|
|
468
|
+
const defaultQuestionDto = BuilderQuestion.create("select-one").toJson();
|
|
469
|
+
const dto = {
|
|
470
|
+
_type: type,
|
|
471
|
+
autoplaySequence: [],
|
|
472
|
+
defaultQuestion: defaultQuestionDto,
|
|
473
|
+
id,
|
|
474
|
+
nextButton: nextButtonDto,
|
|
475
|
+
mainText: mainTextDto,
|
|
476
|
+
prefix: "",
|
|
477
|
+
questions: [],
|
|
478
|
+
tags: []
|
|
479
|
+
};
|
|
480
|
+
const page = new _BuilderPage(dto);
|
|
481
|
+
return page;
|
|
482
|
+
}
|
|
483
|
+
static fromJson(dto) {
|
|
484
|
+
const page = new _BuilderPage(dto);
|
|
485
|
+
return page;
|
|
486
|
+
}
|
|
487
|
+
constructor(dto) {
|
|
488
|
+
super(dto);
|
|
489
|
+
this.id = dto.id;
|
|
490
|
+
this._pageType = dto._type;
|
|
491
|
+
this._prefix = dto.prefix;
|
|
492
|
+
this.mainText = BuilderMainText.fromJson(dto.mainText);
|
|
493
|
+
this.nextButton = BuilderOption.fromJson(dto.nextButton);
|
|
494
|
+
this.defaultQuestion = BuilderQuestion.fromJson(dto.defaultQuestion);
|
|
495
|
+
this._questions = dto.questions.map((q) => BuilderQuestion.fromJson(q));
|
|
496
|
+
const tagList = Array.isArray(dto.tags) ? dto.tags : [];
|
|
497
|
+
this._tags = new Set(tagList);
|
|
498
|
+
if (dto.mainMedia) {
|
|
499
|
+
this.mainMedia = dto.mainMedia;
|
|
500
|
+
}
|
|
501
|
+
this.updateRows();
|
|
502
|
+
}
|
|
503
|
+
insertQuestion(question, atIndex) {
|
|
504
|
+
const validIndexFn = U2.isInRange(0, this._questions.length);
|
|
505
|
+
if (!validIndexFn(atIndex)) {
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
const hasQuestion = !!this._questions.find((q) => q.id === question.id);
|
|
509
|
+
if (hasQuestion) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
this._questions.splice(atIndex, 0, question);
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
addQuestion(type, atIndex = -1) {
|
|
516
|
+
const question = BuilderQuestion.create(type);
|
|
517
|
+
if (atIndex < this._questions.length && atIndex >= 0) {
|
|
518
|
+
this._questions.splice(atIndex, 0, question);
|
|
519
|
+
} else {
|
|
520
|
+
this._questions.push(question);
|
|
521
|
+
}
|
|
522
|
+
return question;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Move a question in questions-array
|
|
526
|
+
* @param question (reference)
|
|
527
|
+
* @param toIndex
|
|
528
|
+
*/
|
|
529
|
+
moveQuestion(question, toIndex) {
|
|
530
|
+
const validToIndexFn = U2.isInRange(0, this._questions.length);
|
|
531
|
+
if (!validToIndexFn(toIndex)) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
const currentIndex = this._questions.indexOf(question);
|
|
535
|
+
if (currentIndex < 0) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
this._questions.splice(currentIndex, 1);
|
|
539
|
+
this._questions.splice(toIndex, 0, question);
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
deleteQuestion(question) {
|
|
543
|
+
this._questions = this._questions.filter((q) => q !== question);
|
|
544
|
+
this.updateRows();
|
|
545
|
+
}
|
|
546
|
+
updateRows() {
|
|
547
|
+
if (this._pageType === "question" || this._pageType === "info-page") {
|
|
548
|
+
this._questions = [];
|
|
549
|
+
}
|
|
550
|
+
if (this._pageType === "form" && this._questions.length === 0) {
|
|
551
|
+
this._questions = [];
|
|
552
|
+
this.addQuestion("text");
|
|
553
|
+
}
|
|
554
|
+
if (this._pageType === "multi-select" && this._questions.length === 0) {
|
|
555
|
+
this._questions = [];
|
|
556
|
+
this.addQuestion("text");
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
addTag(tag) {
|
|
560
|
+
this._tags.add(tag);
|
|
561
|
+
}
|
|
562
|
+
deleteTag(tag) {
|
|
563
|
+
this._tags.delete(tag);
|
|
564
|
+
}
|
|
565
|
+
set pageType(value) {
|
|
566
|
+
this._pageType = value;
|
|
567
|
+
this.updateRows();
|
|
568
|
+
}
|
|
569
|
+
getQuestionVariables(modulePrefix, pageNumber) {
|
|
570
|
+
const variables = [];
|
|
571
|
+
if (this._pageType === "question") {
|
|
572
|
+
const pagePrefix = this.prefix;
|
|
573
|
+
const id = modulePrefix ? modulePrefix + "_" + pagePrefix : pagePrefix;
|
|
574
|
+
const label = this.mainText.text;
|
|
575
|
+
const op = this.defaultQuestion.options.map((o) => {
|
|
576
|
+
const label2 = o.label;
|
|
577
|
+
const value = o.value;
|
|
578
|
+
return new BuilderVariableOption(label2, value);
|
|
579
|
+
});
|
|
580
|
+
const singleVar = new QuestionVariable(id, label, op, pageNumber);
|
|
581
|
+
variables.push(singleVar);
|
|
582
|
+
}
|
|
583
|
+
return variables;
|
|
584
|
+
}
|
|
585
|
+
get tags() {
|
|
586
|
+
return [...this._tags];
|
|
587
|
+
}
|
|
588
|
+
get pageType() {
|
|
589
|
+
return this._pageType;
|
|
590
|
+
}
|
|
591
|
+
get prefix() {
|
|
592
|
+
return this._prefix;
|
|
593
|
+
}
|
|
594
|
+
set prefix(value) {
|
|
595
|
+
this._prefix = value;
|
|
596
|
+
}
|
|
597
|
+
toJson() {
|
|
598
|
+
const questions = this._questions.map((q) => q.toJson());
|
|
599
|
+
const mainText = this.mainText.toJson();
|
|
600
|
+
const nextButton = this.nextButton.toJson();
|
|
601
|
+
const mainMedia = this.mainMedia;
|
|
602
|
+
const dto = {
|
|
603
|
+
_type: this.pageType,
|
|
604
|
+
mainText,
|
|
605
|
+
autoplaySequence: [],
|
|
606
|
+
nextButton,
|
|
607
|
+
id: this.id,
|
|
608
|
+
tags: [...this.tags],
|
|
609
|
+
prefix: this._prefix,
|
|
610
|
+
defaultQuestion: this.defaultQuestion.toJson(),
|
|
611
|
+
questions
|
|
612
|
+
};
|
|
613
|
+
if (mainMedia) {
|
|
614
|
+
dto.mainMedia = mainMedia;
|
|
615
|
+
}
|
|
616
|
+
return dto;
|
|
617
|
+
}
|
|
618
|
+
clone() {
|
|
619
|
+
const dto = this.toJson();
|
|
620
|
+
const defaultQuestionClone = this.defaultQuestion.clone();
|
|
621
|
+
const mainTextClone = JSON.parse(JSON.stringify(this.mainText));
|
|
622
|
+
const questionsClone = this.questions.map((q) => q.clone());
|
|
623
|
+
const newId = BuilderObjectId.pageId();
|
|
624
|
+
const clone = {
|
|
625
|
+
...dto,
|
|
626
|
+
id: newId,
|
|
627
|
+
defaultQuestion: defaultQuestionClone,
|
|
628
|
+
mainText: mainTextClone,
|
|
629
|
+
questions: questionsClone
|
|
630
|
+
};
|
|
631
|
+
return clone;
|
|
632
|
+
}
|
|
633
|
+
get backgroundColor() {
|
|
634
|
+
return this._backgroundColor;
|
|
635
|
+
}
|
|
636
|
+
set backgroundColor(color) {
|
|
637
|
+
if (typeof color === "string") {
|
|
638
|
+
this._backgroundColor = color;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
get questions() {
|
|
642
|
+
return this._questions;
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/rulebuilder/SingleSelectItem.ts
|
|
647
|
+
var SingleSelectItem = class {
|
|
648
|
+
constructor(data) {
|
|
649
|
+
this.data = data;
|
|
650
|
+
this._selectLabel = this.getSelectLabel();
|
|
651
|
+
this._toolTip = this.getTooltip();
|
|
652
|
+
this._searchString = this.getSearchString();
|
|
653
|
+
}
|
|
654
|
+
_selectLabel;
|
|
655
|
+
_toolTip;
|
|
656
|
+
_searchString;
|
|
657
|
+
get selectLabel() {
|
|
658
|
+
return this._selectLabel;
|
|
659
|
+
}
|
|
660
|
+
get tooltip() {
|
|
661
|
+
return this._toolTip;
|
|
662
|
+
}
|
|
663
|
+
get searchString() {
|
|
664
|
+
return this._searchString;
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
var RuleVariableSelectItem = class _RuleVariableSelectItem extends SingleSelectItem {
|
|
668
|
+
constructor(data) {
|
|
669
|
+
super(data);
|
|
670
|
+
this.data = data;
|
|
671
|
+
this.options = data.options.map(RuleOptionSelectItem.create);
|
|
672
|
+
}
|
|
673
|
+
static create = (data) => {
|
|
674
|
+
return new _RuleVariableSelectItem(data);
|
|
675
|
+
};
|
|
676
|
+
options;
|
|
677
|
+
getSearchString() {
|
|
678
|
+
return this.data.varId + this.data.label;
|
|
679
|
+
}
|
|
680
|
+
getSelectLabel() {
|
|
681
|
+
return this.data.varId;
|
|
682
|
+
}
|
|
683
|
+
getTooltip() {
|
|
684
|
+
return this.data.label;
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
var RuleOptionSelectItem = class _RuleOptionSelectItem extends SingleSelectItem {
|
|
688
|
+
static create = (option) => {
|
|
689
|
+
return new _RuleOptionSelectItem(option);
|
|
690
|
+
};
|
|
691
|
+
constructor(option) {
|
|
692
|
+
super(option);
|
|
693
|
+
}
|
|
694
|
+
getSearchString() {
|
|
695
|
+
return "";
|
|
696
|
+
}
|
|
697
|
+
getSelectLabel() {
|
|
698
|
+
return this.data.label + "(" + this.data.value + ")";
|
|
699
|
+
}
|
|
700
|
+
getTooltip() {
|
|
701
|
+
return "";
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
var OperatorSelectItem = class _OperatorSelectItem extends SingleSelectItem {
|
|
705
|
+
static EQ = new _OperatorSelectItem("equal");
|
|
706
|
+
static NOT_EQ = new _OperatorSelectItem("notEqual");
|
|
707
|
+
static fromSymbol = (symbol) => {
|
|
708
|
+
if (symbol === "equal") {
|
|
709
|
+
return _OperatorSelectItem.EQ;
|
|
710
|
+
}
|
|
711
|
+
if (symbol === "notEqual") {
|
|
712
|
+
return _OperatorSelectItem.NOT_EQ;
|
|
713
|
+
}
|
|
714
|
+
return false;
|
|
715
|
+
};
|
|
716
|
+
constructor(operator) {
|
|
717
|
+
super(operator);
|
|
718
|
+
}
|
|
719
|
+
getSearchString() {
|
|
720
|
+
return "";
|
|
721
|
+
}
|
|
722
|
+
getSelectLabel() {
|
|
723
|
+
const operator = this.data;
|
|
724
|
+
if (operator === "equal") {
|
|
725
|
+
return "Equals";
|
|
726
|
+
}
|
|
727
|
+
if (operator === "notEqual") {
|
|
728
|
+
return "Not equals";
|
|
729
|
+
}
|
|
730
|
+
return "";
|
|
731
|
+
}
|
|
732
|
+
getTooltip() {
|
|
733
|
+
const operator = this.data;
|
|
734
|
+
if (operator === "equal") {
|
|
735
|
+
return "Equals";
|
|
736
|
+
}
|
|
737
|
+
if (operator === "notEqual") {
|
|
738
|
+
return "Not equals";
|
|
739
|
+
}
|
|
740
|
+
return "";
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
var JumpToPageSelectItem = class _JumpToPageSelectItem extends SingleSelectItem {
|
|
744
|
+
static create = (pageData) => new _JumpToPageSelectItem(pageData);
|
|
745
|
+
constructor(pageData) {
|
|
746
|
+
super(pageData);
|
|
747
|
+
}
|
|
748
|
+
getSearchString() {
|
|
749
|
+
return this.data.pageId + this.data.mainText;
|
|
750
|
+
}
|
|
751
|
+
getSelectLabel() {
|
|
752
|
+
return this.data.pageId + " (" + this.data.pageNumber + ")";
|
|
753
|
+
}
|
|
754
|
+
getTooltip() {
|
|
755
|
+
return this.data.mainText;
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
// src/rulebuilder/RuleInput.ts
|
|
760
|
+
var RuleInput = class {
|
|
761
|
+
constructor(_questionVariables, _customVariables, _pageIdActions, _tagActions, _jumpActions) {
|
|
762
|
+
this._questionVariables = _questionVariables;
|
|
763
|
+
this._customVariables = _customVariables;
|
|
764
|
+
this._pageIdActions = _pageIdActions;
|
|
765
|
+
this._tagActions = _tagActions;
|
|
766
|
+
this._jumpActions = _jumpActions;
|
|
767
|
+
}
|
|
768
|
+
get questionVars() {
|
|
769
|
+
return this._questionVariables;
|
|
770
|
+
}
|
|
771
|
+
getConditionInput() {
|
|
772
|
+
return [...this.questionVars, ...this.customVars];
|
|
773
|
+
}
|
|
774
|
+
getJumpToPageOptions() {
|
|
775
|
+
return this._jumpActions.map(JumpToPageSelectItem.create);
|
|
776
|
+
}
|
|
777
|
+
get customVars() {
|
|
778
|
+
return this._customVariables;
|
|
779
|
+
}
|
|
780
|
+
get excludeByPageIdActions() {
|
|
781
|
+
return this._pageIdActions;
|
|
782
|
+
}
|
|
783
|
+
get excludeByTagActions() {
|
|
784
|
+
return this._tagActions;
|
|
785
|
+
}
|
|
786
|
+
get jumpToPageActions() {
|
|
787
|
+
return this._jumpActions;
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// src/BuilderTag.ts
|
|
792
|
+
var BuilderTag = class _BuilderTag extends BuilderObject {
|
|
793
|
+
objectType = "builder-tag";
|
|
794
|
+
id;
|
|
795
|
+
tagText = "";
|
|
796
|
+
tagDescription = "";
|
|
797
|
+
static MAX_LENGTH = 20;
|
|
798
|
+
static MIN_LENGTH = 1;
|
|
799
|
+
static create = (tag, description = "") => {
|
|
800
|
+
const id = BuilderObjectId.createTagId();
|
|
801
|
+
const dto = {
|
|
802
|
+
id,
|
|
803
|
+
tag,
|
|
804
|
+
description
|
|
805
|
+
};
|
|
806
|
+
return new _BuilderTag(dto);
|
|
807
|
+
};
|
|
808
|
+
static fromDto = (dto) => {
|
|
809
|
+
return new _BuilderTag(dto);
|
|
810
|
+
};
|
|
811
|
+
constructor(dto) {
|
|
812
|
+
const id = dto.id ?? BuilderObjectId.createTagId();
|
|
813
|
+
const withId = { ...dto, id };
|
|
814
|
+
super(withId);
|
|
815
|
+
this.id = id;
|
|
816
|
+
this.tagText = dto.tag ?? "";
|
|
817
|
+
this.tagDescription = dto.description ?? "";
|
|
818
|
+
}
|
|
819
|
+
clone() {
|
|
820
|
+
return this.toJson();
|
|
821
|
+
}
|
|
822
|
+
toJson() {
|
|
823
|
+
return { tag: this.tagText, description: this.tagDescription, id: this.id };
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
var TagCollection = class _TagCollection {
|
|
827
|
+
_tags = /* @__PURE__ */ new Set();
|
|
828
|
+
static create = () => {
|
|
829
|
+
return new _TagCollection([]);
|
|
830
|
+
};
|
|
831
|
+
[Symbol.iterator]() {
|
|
832
|
+
const list = [...this._tags];
|
|
833
|
+
return list[Symbol.iterator]();
|
|
834
|
+
}
|
|
835
|
+
constructor(initialTags) {
|
|
836
|
+
initialTags.forEach((tag) => {
|
|
837
|
+
this._tags.add(tag);
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
init(tags) {
|
|
841
|
+
const dtoList = Array.isArray(tags) ? tags : [];
|
|
842
|
+
const all = dtoList.map(BuilderTag.fromDto);
|
|
843
|
+
all.forEach((tag) => {
|
|
844
|
+
this._tags.add(tag);
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
add(tag) {
|
|
848
|
+
this._tags.add(tag);
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Delete this tag from collection;
|
|
852
|
+
* @param tag
|
|
853
|
+
*/
|
|
854
|
+
delete(tag) {
|
|
855
|
+
this._tags.delete(tag);
|
|
856
|
+
}
|
|
857
|
+
toJson() {
|
|
858
|
+
const list = [...this._tags];
|
|
859
|
+
const dtoList = list.map((t) => t.toJson());
|
|
860
|
+
return dtoList;
|
|
861
|
+
}
|
|
862
|
+
deleteAll(tags) {
|
|
863
|
+
const l = tags[Symbol.iterator]();
|
|
864
|
+
const asList = [...tags];
|
|
865
|
+
asList.forEach((t) => {
|
|
866
|
+
this.delete(t);
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
// src/rulebuilder/condition/Builder-operator.ts
|
|
872
|
+
var BuilderOperatorSymbols = {
|
|
873
|
+
equal: true,
|
|
874
|
+
notEqual: true,
|
|
875
|
+
lessThan: true,
|
|
876
|
+
lessThanOrEqual: true,
|
|
877
|
+
greaterThan: true,
|
|
878
|
+
greaterThanOrEqual: true,
|
|
879
|
+
between: true,
|
|
880
|
+
notBetween: true,
|
|
881
|
+
in: true,
|
|
882
|
+
notIn: true,
|
|
883
|
+
missing: true,
|
|
884
|
+
notMissing: true,
|
|
885
|
+
contains: true,
|
|
886
|
+
notContains: true,
|
|
887
|
+
empty: true,
|
|
888
|
+
notEmpty: true,
|
|
889
|
+
startsWith: true,
|
|
890
|
+
endsWith: true
|
|
891
|
+
};
|
|
892
|
+
var BuilderOperator;
|
|
893
|
+
((BuilderOperator2) => {
|
|
894
|
+
BuilderOperator2.is = (symbol) => {
|
|
895
|
+
if (typeof symbol !== "string") {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
return Object.keys(BuilderOperatorSymbols).includes(symbol);
|
|
899
|
+
};
|
|
900
|
+
})(BuilderOperator || (BuilderOperator = {}));
|
|
901
|
+
|
|
902
|
+
// src/rulebuilder/condition/Builder-condition.ts
|
|
903
|
+
var BuilderCondition = class _BuilderCondition extends BuilderObject {
|
|
904
|
+
objectType = "builder-condition";
|
|
905
|
+
static NUMBER_OPERATORS = [
|
|
906
|
+
OperatorSelectItem.EQ,
|
|
907
|
+
OperatorSelectItem.NOT_EQ
|
|
908
|
+
];
|
|
909
|
+
initialDto;
|
|
910
|
+
name = "";
|
|
911
|
+
static create = (variableList) => {
|
|
912
|
+
const condition = new _BuilderCondition(
|
|
913
|
+
{
|
|
914
|
+
kind: "condition",
|
|
915
|
+
name: "",
|
|
916
|
+
operator: "",
|
|
917
|
+
variableId: "",
|
|
918
|
+
value: ""
|
|
919
|
+
},
|
|
920
|
+
variableList
|
|
921
|
+
);
|
|
922
|
+
return condition;
|
|
923
|
+
};
|
|
924
|
+
static fromDto = (dto, variables) => {
|
|
925
|
+
const _dto = {
|
|
926
|
+
kind: "condition",
|
|
927
|
+
name: dto.name ?? "",
|
|
928
|
+
value: dto.value ?? "",
|
|
929
|
+
operator: dto.operator ?? "",
|
|
930
|
+
variableId: dto.variableId ?? ""
|
|
931
|
+
};
|
|
932
|
+
const instance = new _BuilderCondition(_dto, variables);
|
|
933
|
+
return instance;
|
|
934
|
+
};
|
|
935
|
+
_variable = false;
|
|
936
|
+
_operator = "";
|
|
937
|
+
_value = false;
|
|
938
|
+
_variableList = [];
|
|
939
|
+
/**
|
|
940
|
+
* Can only set variables that exist in variableList.
|
|
941
|
+
* @param variable
|
|
942
|
+
*/
|
|
943
|
+
set variable(variable) {
|
|
944
|
+
if (variable === this._variable) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
this._variable = variable;
|
|
948
|
+
this._operator = "";
|
|
949
|
+
this._value = false;
|
|
950
|
+
}
|
|
951
|
+
get variable() {
|
|
952
|
+
return this._variable;
|
|
953
|
+
}
|
|
954
|
+
set value(variableValue) {
|
|
955
|
+
this._value = variableValue;
|
|
956
|
+
}
|
|
957
|
+
get value() {
|
|
958
|
+
return this._value;
|
|
959
|
+
}
|
|
960
|
+
validate() {
|
|
961
|
+
if (this._variableList.length === 0) {
|
|
962
|
+
return {
|
|
963
|
+
isValid: false,
|
|
964
|
+
message: "Has no variableList to check dto against."
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
if (!this._variable) {
|
|
968
|
+
return {
|
|
969
|
+
isValid: false,
|
|
970
|
+
message: "Variable has not been initialized from variableList."
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
if (!this._operator) {
|
|
974
|
+
return { isValid: false, message: "Operator has not been initialized" };
|
|
975
|
+
}
|
|
976
|
+
if (!this._value) {
|
|
977
|
+
return {
|
|
978
|
+
isValid: false,
|
|
979
|
+
message: "Value (BuilderVariableOption) is not initialized"
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
return { isValid: true };
|
|
983
|
+
}
|
|
984
|
+
findVariableInUniverse(variableId) {
|
|
985
|
+
const v = this._variableList.find((v2) => v2.varId === variableId);
|
|
986
|
+
return v ?? false;
|
|
987
|
+
}
|
|
988
|
+
set operator(operator) {
|
|
989
|
+
if (BuilderOperator.is(operator)) {
|
|
990
|
+
this._operator = operator;
|
|
991
|
+
} else {
|
|
992
|
+
this._operator = "";
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
get operator() {
|
|
996
|
+
return this._operator;
|
|
997
|
+
}
|
|
998
|
+
constructor(dto, variables) {
|
|
999
|
+
super(dto);
|
|
1000
|
+
this.initialDto = dto;
|
|
1001
|
+
this.name = dto.name;
|
|
1002
|
+
this._setVariableList(variables);
|
|
1003
|
+
}
|
|
1004
|
+
get variableSelectItemsInUniverse() {
|
|
1005
|
+
return this._variableList.map(RuleVariableSelectItem.create);
|
|
1006
|
+
}
|
|
1007
|
+
get operatorsSelectItems() {
|
|
1008
|
+
return this._variable ? _BuilderCondition.NUMBER_OPERATORS : [];
|
|
1009
|
+
}
|
|
1010
|
+
get selectValueItems() {
|
|
1011
|
+
if (!this._variable) {
|
|
1012
|
+
return [];
|
|
1013
|
+
}
|
|
1014
|
+
const opt = this._variable.options.map(RuleOptionSelectItem.create);
|
|
1015
|
+
return opt;
|
|
1016
|
+
}
|
|
1017
|
+
clone() {
|
|
1018
|
+
return this.toJson();
|
|
1019
|
+
}
|
|
1020
|
+
_setVariableList(variables) {
|
|
1021
|
+
this._variableList = variables;
|
|
1022
|
+
const v = this._variableList.find((v2) => v2.varId === this.originalDto.variableId);
|
|
1023
|
+
if (!v) {
|
|
1024
|
+
this._variable = false;
|
|
1025
|
+
this._operator = "";
|
|
1026
|
+
this._value = false;
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
this._variable = v;
|
|
1030
|
+
const op = this.originalDto.operator;
|
|
1031
|
+
if (!BuilderOperator.is(op)) {
|
|
1032
|
+
return false;
|
|
1033
|
+
}
|
|
1034
|
+
this._operator = op;
|
|
1035
|
+
const maybeOption = v.options.find((op2) => op2.value === this.originalDto.value);
|
|
1036
|
+
if (!maybeOption) {
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
this._value = maybeOption;
|
|
1040
|
+
return true;
|
|
1041
|
+
}
|
|
1042
|
+
toJson() {
|
|
1043
|
+
const name = this.name;
|
|
1044
|
+
const variableId = this._variable ? this._variable.varId : "";
|
|
1045
|
+
const operator = this._operator ? this._operator : "";
|
|
1046
|
+
const value = this._value ? this._value.value : "";
|
|
1047
|
+
return {
|
|
1048
|
+
kind: "condition",
|
|
1049
|
+
name,
|
|
1050
|
+
operator,
|
|
1051
|
+
variableId,
|
|
1052
|
+
value
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
// src/rulebuilder/condition/Builder-condition-group.ts
|
|
1058
|
+
var ConditionGroupType = {
|
|
1059
|
+
all: true,
|
|
1060
|
+
any: true,
|
|
1061
|
+
count: true,
|
|
1062
|
+
range: true
|
|
1063
|
+
};
|
|
1064
|
+
var BuilderConditionGroup = class _BuilderConditionGroup extends BuilderObject {
|
|
1065
|
+
static isConditionGroupType = (value) => {
|
|
1066
|
+
if (typeof value !== "string") {
|
|
1067
|
+
return false;
|
|
1068
|
+
}
|
|
1069
|
+
const validValues = Object.keys(ConditionGroupType);
|
|
1070
|
+
return validValues.includes(value);
|
|
1071
|
+
};
|
|
1072
|
+
objectType = "builder-condition-group";
|
|
1073
|
+
_type;
|
|
1074
|
+
name = "";
|
|
1075
|
+
_conditions;
|
|
1076
|
+
_variableList;
|
|
1077
|
+
static fromDto = (dto, variableList) => {
|
|
1078
|
+
return new _BuilderConditionGroup(dto, variableList);
|
|
1079
|
+
};
|
|
1080
|
+
constructor(dto, variableList) {
|
|
1081
|
+
super(dto);
|
|
1082
|
+
this.name = dto.name;
|
|
1083
|
+
this._type = dto.type;
|
|
1084
|
+
const conditionList = Array.isArray(dto.conditions) ? dto.conditions : [];
|
|
1085
|
+
this._conditions = conditionList.map((dto2) => BuilderCondition.fromDto(dto2, variableList));
|
|
1086
|
+
this._variableList = variableList;
|
|
1087
|
+
}
|
|
1088
|
+
get conditions() {
|
|
1089
|
+
return this._conditions;
|
|
1090
|
+
}
|
|
1091
|
+
get conditionCount() {
|
|
1092
|
+
return this._conditions.length;
|
|
1093
|
+
}
|
|
1094
|
+
addCondition() {
|
|
1095
|
+
const newConditions = BuilderCondition.create(this._variableList);
|
|
1096
|
+
this._conditions.push(newConditions);
|
|
1097
|
+
return newConditions;
|
|
1098
|
+
}
|
|
1099
|
+
removeCondition(condition) {
|
|
1100
|
+
const index = this._conditions.indexOf(condition);
|
|
1101
|
+
if (index < 0) {
|
|
1102
|
+
return false;
|
|
1103
|
+
}
|
|
1104
|
+
this._conditions.splice(index, 1);
|
|
1105
|
+
return true;
|
|
1106
|
+
}
|
|
1107
|
+
clone() {
|
|
1108
|
+
return this.toJson();
|
|
1109
|
+
}
|
|
1110
|
+
toJson() {
|
|
1111
|
+
const conditions = [...this._conditions.map((c) => c.toJson())];
|
|
1112
|
+
return {
|
|
1113
|
+
name: this.name,
|
|
1114
|
+
conditions,
|
|
1115
|
+
type: this._type,
|
|
1116
|
+
kind: "condition-group"
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
get type() {
|
|
1120
|
+
return this._type;
|
|
1121
|
+
}
|
|
1122
|
+
set type(conditionGroupType) {
|
|
1123
|
+
if (_BuilderConditionGroup.isConditionGroupType(conditionGroupType)) {
|
|
1124
|
+
this._type = conditionGroupType;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
// src/rulebuilder/multi-select-item.ts
|
|
1130
|
+
var MultiSelectItem = class {
|
|
1131
|
+
constructor(data, isSelected) {
|
|
1132
|
+
this.data = data;
|
|
1133
|
+
this._isSelectedInitially = isSelected;
|
|
1134
|
+
this.isSelected = isSelected;
|
|
1135
|
+
this._searchString = this.getSearchString();
|
|
1136
|
+
this._toolTip = this.getTooltip();
|
|
1137
|
+
this._selectLabel = this.getSelectLabel();
|
|
1138
|
+
}
|
|
1139
|
+
_isSelectedInitially;
|
|
1140
|
+
_selectLabel;
|
|
1141
|
+
_toolTip;
|
|
1142
|
+
_searchString;
|
|
1143
|
+
isSelected;
|
|
1144
|
+
get selectLabel() {
|
|
1145
|
+
return this._selectLabel;
|
|
1146
|
+
}
|
|
1147
|
+
get tooltip() {
|
|
1148
|
+
return this._toolTip;
|
|
1149
|
+
}
|
|
1150
|
+
get searchString() {
|
|
1151
|
+
return this._searchString;
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
var ExcludeByTagSelectItem = class _ExcludeByTagSelectItem extends MultiSelectItem {
|
|
1155
|
+
static create = (tagData, isSelected) => {
|
|
1156
|
+
return new _ExcludeByTagSelectItem(tagData, isSelected);
|
|
1157
|
+
};
|
|
1158
|
+
constructor(data, isSelected) {
|
|
1159
|
+
super(data, isSelected);
|
|
1160
|
+
}
|
|
1161
|
+
getSearchString() {
|
|
1162
|
+
return this.data.tag;
|
|
1163
|
+
}
|
|
1164
|
+
getSelectLabel() {
|
|
1165
|
+
return this.data.tag + " (" + this.data.pageCount + ")";
|
|
1166
|
+
}
|
|
1167
|
+
getTooltip() {
|
|
1168
|
+
return this.data.tag + " (used in " + this.data.pageCount + " pages)";
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
var ExcludeByPageIdSelectItem = class _ExcludeByPageIdSelectItem extends MultiSelectItem {
|
|
1172
|
+
static create = (ruleActionPage, isSelected) => {
|
|
1173
|
+
return new _ExcludeByPageIdSelectItem(ruleActionPage, isSelected);
|
|
1174
|
+
};
|
|
1175
|
+
constructor(data, isSelected) {
|
|
1176
|
+
super(data, isSelected);
|
|
1177
|
+
}
|
|
1178
|
+
getSearchString() {
|
|
1179
|
+
return this.data.pageId + this.data.mainText;
|
|
1180
|
+
}
|
|
1181
|
+
getSelectLabel() {
|
|
1182
|
+
return this.data.pageId + " (" + this.data.pageNumber + ")";
|
|
1183
|
+
}
|
|
1184
|
+
getTooltip() {
|
|
1185
|
+
return this.data.mainText;
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
|
|
1189
|
+
// src/rulebuilder/tag-action-manager.ts
|
|
1190
|
+
var TagActionManager = class {
|
|
1191
|
+
constructor(validOptions, initialSelection) {
|
|
1192
|
+
this.validOptions = validOptions;
|
|
1193
|
+
this.initialSelection = initialSelection;
|
|
1194
|
+
this._initialSelection = /* @__PURE__ */ new Set([...initialSelection]);
|
|
1195
|
+
this.selectItems = validOptions.map((opt) => {
|
|
1196
|
+
const isSelected = this._initialSelection.has(opt.tag);
|
|
1197
|
+
return ExcludeByTagSelectItem.create(opt, isSelected);
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
_initialSelection;
|
|
1201
|
+
selectItems;
|
|
1202
|
+
getCurrentSelection() {
|
|
1203
|
+
const selected = this.selectItems.filter((item) => item.isSelected).map((itm) => itm.data.tag);
|
|
1204
|
+
return selected;
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// src/rulebuilder/page-action-manager.ts
|
|
1209
|
+
var PageActionManager = class {
|
|
1210
|
+
constructor(validOptions, initialSelection) {
|
|
1211
|
+
this.validOptions = validOptions;
|
|
1212
|
+
this.initialSelection = initialSelection;
|
|
1213
|
+
this._initialSelection = /* @__PURE__ */ new Set([...initialSelection]);
|
|
1214
|
+
this.selectItems = validOptions.map((opt) => {
|
|
1215
|
+
const isSelected = this._initialSelection.has(opt.pageId);
|
|
1216
|
+
return ExcludeByPageIdSelectItem.create(opt, isSelected);
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
_initialSelection;
|
|
1220
|
+
selectItems;
|
|
1221
|
+
getCurrentSelection() {
|
|
1222
|
+
const selected = this.selectItems.filter((item) => item.isSelected).map((itm) => itm.data.pageId);
|
|
1223
|
+
return selected;
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
|
|
1227
|
+
// src/rulebuilder/jump-to-action-manager.ts
|
|
1228
|
+
var JumpToActionManager = class {
|
|
1229
|
+
constructor(validOptions, initialSelection) {
|
|
1230
|
+
this.validOptions = validOptions;
|
|
1231
|
+
this.initialSelection = initialSelection;
|
|
1232
|
+
this.options = validOptions.map(JumpToPageSelectItem.create);
|
|
1233
|
+
this._selected = this.findSelected(initialSelection);
|
|
1234
|
+
}
|
|
1235
|
+
options;
|
|
1236
|
+
_selected;
|
|
1237
|
+
get selected() {
|
|
1238
|
+
return this._selected;
|
|
1239
|
+
}
|
|
1240
|
+
set selected(selected) {
|
|
1241
|
+
this._selected = this.findSelected(selected);
|
|
1242
|
+
}
|
|
1243
|
+
getSelectedPageId() {
|
|
1244
|
+
return this._selected ? this._selected.data.pageId : false;
|
|
1245
|
+
}
|
|
1246
|
+
findSelected(value) {
|
|
1247
|
+
if (!value)
|
|
1248
|
+
return false;
|
|
1249
|
+
if (value instanceof JumpToPageSelectItem) {
|
|
1250
|
+
return this.options.find((v) => v === value) || false;
|
|
1251
|
+
}
|
|
1252
|
+
if (typeof value === "string") {
|
|
1253
|
+
return this.options.find((v) => v.data.pageId === value) || false;
|
|
1254
|
+
}
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
// src/rulebuilder/Builder-rule.ts
|
|
1260
|
+
var BuilderRule = class _BuilderRule extends BuilderObject {
|
|
1261
|
+
constructor(dto, _ruleInput) {
|
|
1262
|
+
super(dto);
|
|
1263
|
+
this.dto = dto;
|
|
1264
|
+
this._ruleInput = _ruleInput;
|
|
1265
|
+
const conditionInput = this._ruleInput.getConditionInput();
|
|
1266
|
+
this.name = dto.name ?? "";
|
|
1267
|
+
this._type = dto.type ?? "any";
|
|
1268
|
+
this._conditions = dto.conditions.reduce((acc, curr) => {
|
|
1269
|
+
if (curr.kind === "condition") {
|
|
1270
|
+
const condition = BuilderCondition.fromDto(curr, conditionInput);
|
|
1271
|
+
acc.push(condition);
|
|
1272
|
+
}
|
|
1273
|
+
if (curr.kind === "condition-group") {
|
|
1274
|
+
const conditionGroup = BuilderConditionGroup.fromDto(curr, conditionInput);
|
|
1275
|
+
acc.push(conditionGroup);
|
|
1276
|
+
}
|
|
1277
|
+
return acc;
|
|
1278
|
+
}, []);
|
|
1279
|
+
this._pageActionManager = new PageActionManager(_ruleInput.excludeByPageIdActions, dto.excludePages);
|
|
1280
|
+
this._tagActionManager = new TagActionManager(_ruleInput.excludeByTagActions, dto.excludeTags);
|
|
1281
|
+
this.jumpToActionManager = new JumpToActionManager(_ruleInput.jumpToPageActions, dto.jumpToPage);
|
|
1282
|
+
}
|
|
1283
|
+
objectType = "builder-rule";
|
|
1284
|
+
_type = "all";
|
|
1285
|
+
name = "Rule name";
|
|
1286
|
+
// public countNumber = 1;
|
|
1287
|
+
_conditions = [];
|
|
1288
|
+
_tagActionManager;
|
|
1289
|
+
_pageActionManager;
|
|
1290
|
+
jumpToActionManager;
|
|
1291
|
+
static fromDto = (dto, input) => {
|
|
1292
|
+
return new _BuilderRule(dto, input);
|
|
1293
|
+
};
|
|
1294
|
+
get conditions() {
|
|
1295
|
+
return this._conditions;
|
|
1296
|
+
}
|
|
1297
|
+
getTagActions() {
|
|
1298
|
+
return this._tagActionManager.selectItems;
|
|
1299
|
+
}
|
|
1300
|
+
getValidPageActions() {
|
|
1301
|
+
return this._pageActionManager.selectItems;
|
|
1302
|
+
}
|
|
1303
|
+
get conditionCount() {
|
|
1304
|
+
return this._conditions.length;
|
|
1305
|
+
}
|
|
1306
|
+
set type(type) {
|
|
1307
|
+
if (BuilderConditionGroup.isConditionGroupType(type)) {
|
|
1308
|
+
this._type = type;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
get type() {
|
|
1312
|
+
return this._type;
|
|
1313
|
+
}
|
|
1314
|
+
deleteCondition(condition) {
|
|
1315
|
+
const index = this._conditions.indexOf(condition);
|
|
1316
|
+
if (index < 0) {
|
|
1317
|
+
return false;
|
|
1318
|
+
}
|
|
1319
|
+
this._conditions.splice(index, 1);
|
|
1320
|
+
return true;
|
|
1321
|
+
}
|
|
1322
|
+
addCondition() {
|
|
1323
|
+
const condition = BuilderCondition.create(this._ruleInput.getConditionInput());
|
|
1324
|
+
this._conditions.push(condition);
|
|
1325
|
+
return condition;
|
|
1326
|
+
}
|
|
1327
|
+
addConditionGroup() {
|
|
1328
|
+
const dto = {
|
|
1329
|
+
kind: "condition-group",
|
|
1330
|
+
name: "",
|
|
1331
|
+
type: "all",
|
|
1332
|
+
conditions: []
|
|
1333
|
+
};
|
|
1334
|
+
const newGroup = BuilderConditionGroup.fromDto(dto, this._ruleInput.questionVars);
|
|
1335
|
+
this._conditions.push(newGroup);
|
|
1336
|
+
return newGroup;
|
|
1337
|
+
}
|
|
1338
|
+
clone() {
|
|
1339
|
+
return this.toJson();
|
|
1340
|
+
}
|
|
1341
|
+
toJson() {
|
|
1342
|
+
const conditions = this._conditions.map((c) => c.toJson());
|
|
1343
|
+
const excludePages = this._pageActionManager.getCurrentSelection();
|
|
1344
|
+
const excludeTags = this._tagActionManager.getCurrentSelection();
|
|
1345
|
+
const jumpToPage = this.jumpToActionManager.getSelectedPageId();
|
|
1346
|
+
const dto = {
|
|
1347
|
+
type: this._type,
|
|
1348
|
+
name: this.name,
|
|
1349
|
+
conditions,
|
|
1350
|
+
excludePages,
|
|
1351
|
+
jumpToPage,
|
|
1352
|
+
excludeTags
|
|
1353
|
+
};
|
|
1354
|
+
return dto;
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
// src/theme/AbstractThemeCompiler.ts
|
|
1359
|
+
var AbstractThemeCompiler = class {
|
|
1360
|
+
constructor(theme) {
|
|
1361
|
+
this.theme = theme;
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1365
|
+
// src/theme/standard-props.ts
|
|
1366
|
+
var import_engine3 = require("@media-quest/engine");
|
|
1367
|
+
var DStateProps;
|
|
1368
|
+
((DStateProps2) => {
|
|
1369
|
+
DStateProps2.mediaBlockedBySequence = new import_engine3.BooleanStateProperty(
|
|
1370
|
+
"media-blocked-by-autoplay-sequence",
|
|
1371
|
+
false,
|
|
1372
|
+
"Should be true if the page is in a autoplay-sequence. The autoplay-sequence will always block other media."
|
|
1373
|
+
);
|
|
1374
|
+
DStateProps2.inputBlockingBySequence = new import_engine3.BooleanStateProperty("input-blocked-by-autoplay-sequence", false, "");
|
|
1375
|
+
DStateProps2.mediaBlockedByAudio = new import_engine3.BooleanStateProperty("media-blocked-by-audio", false, "");
|
|
1376
|
+
DStateProps2.inputBlockedByAudio = new import_engine3.BooleanStateProperty("input-blocked-by-audio", false, "");
|
|
1377
|
+
DStateProps2.mediaBlockedByVideo = new import_engine3.BooleanStateProperty("media-blocked-by-video", false, "");
|
|
1378
|
+
DStateProps2.inputBlockedByVideo = new import_engine3.BooleanStateProperty(
|
|
1379
|
+
"input-blocked-by-video",
|
|
1380
|
+
false,
|
|
1381
|
+
"Should be true if a video is playing, and this video is suppose to block user-input."
|
|
1382
|
+
);
|
|
1383
|
+
DStateProps2.userPausedVideo = new import_engine3.BooleanStateProperty(
|
|
1384
|
+
"user-paused-video",
|
|
1385
|
+
false,
|
|
1386
|
+
"Should be true if user paused the video by pressing the pause-button."
|
|
1387
|
+
);
|
|
1388
|
+
DStateProps2.videoIsPlaying = new import_engine3.BooleanStateProperty(
|
|
1389
|
+
"video-is-playing",
|
|
1390
|
+
false,
|
|
1391
|
+
"Should be true if any video is playing on the page."
|
|
1392
|
+
);
|
|
1393
|
+
DStateProps2.audioIsPlaying = new import_engine3.BooleanStateProperty(
|
|
1394
|
+
"audio-is-playing",
|
|
1395
|
+
false,
|
|
1396
|
+
"Should be tru if any audio is playing on page"
|
|
1397
|
+
);
|
|
1398
|
+
const _props = {
|
|
1399
|
+
inputBlockedByAudio: DStateProps2.inputBlockedByAudio,
|
|
1400
|
+
mediaBlockedByAudio: DStateProps2.mediaBlockedByAudio,
|
|
1401
|
+
inputBlockingBySequence: DStateProps2.inputBlockingBySequence,
|
|
1402
|
+
mediaBlockedBySequence: DStateProps2.mediaBlockedBySequence,
|
|
1403
|
+
inputBlockedByVideo: DStateProps2.inputBlockedByVideo,
|
|
1404
|
+
mediaBlockedByVideo: DStateProps2.mediaBlockedByVideo,
|
|
1405
|
+
userPausedVideo: DStateProps2.userPausedVideo,
|
|
1406
|
+
videoIsPlaying: DStateProps2.videoIsPlaying
|
|
1407
|
+
};
|
|
1408
|
+
const disableAudioIconQuery = {
|
|
1409
|
+
name: "disable-Audio",
|
|
1410
|
+
condition: {
|
|
1411
|
+
kind: "complex-condition",
|
|
1412
|
+
name: "audio-controls-are-blocked",
|
|
1413
|
+
some: [
|
|
1414
|
+
DStateProps2.mediaBlockedBySequence.getIsTrueCondition(),
|
|
1415
|
+
DStateProps2.mediaBlockedByAudio.getIsTrueCondition(),
|
|
1416
|
+
DStateProps2.mediaBlockedByVideo.getIsTrueCondition()
|
|
1417
|
+
],
|
|
1418
|
+
all: []
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
const hideVideoPlayQuery = {
|
|
1422
|
+
name: "hide-video-play-button",
|
|
1423
|
+
condition: {
|
|
1424
|
+
kind: "complex-condition",
|
|
1425
|
+
name: "video-is-playing-condition",
|
|
1426
|
+
all: [DStateProps2.videoIsPlaying.getIsTrueCondition()],
|
|
1427
|
+
some: []
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
const hideVideoPauseQuery = {
|
|
1431
|
+
name: "hide-video-pause-button",
|
|
1432
|
+
condition: {
|
|
1433
|
+
kind: "complex-condition",
|
|
1434
|
+
name: "video-is-not-playing-condition",
|
|
1435
|
+
all: [DStateProps2.videoIsPlaying.getIsFalseCondition()],
|
|
1436
|
+
some: []
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
const disableVideoPlayQuery = {
|
|
1440
|
+
name: "disable-video",
|
|
1441
|
+
condition: {
|
|
1442
|
+
kind: "complex-condition",
|
|
1443
|
+
name: "video-play shall be disabled",
|
|
1444
|
+
all: [DStateProps2.userPausedVideo.getIsFalseCondition()],
|
|
1445
|
+
some: [
|
|
1446
|
+
DStateProps2.mediaBlockedBySequence.getIsTrueCondition(),
|
|
1447
|
+
DStateProps2.mediaBlockedByAudio.getIsTrueCondition(),
|
|
1448
|
+
DStateProps2.mediaBlockedByVideo.getIsTrueCondition(),
|
|
1449
|
+
DStateProps2.audioIsPlaying.getIsTrueCondition()
|
|
1450
|
+
]
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
const disableUserInputQuery = {
|
|
1454
|
+
name: "disable-user-input",
|
|
1455
|
+
condition: {
|
|
1456
|
+
kind: "complex-condition",
|
|
1457
|
+
name: "User input shall be disabled (Response-buttons, FormControls...)",
|
|
1458
|
+
all: [],
|
|
1459
|
+
some: [
|
|
1460
|
+
DStateProps2.inputBlockedByAudio.getIsTrueCondition(),
|
|
1461
|
+
DStateProps2.inputBlockedByVideo.getIsTrueCondition(),
|
|
1462
|
+
DStateProps2.inputBlockingBySequence.getIsTrueCondition()
|
|
1463
|
+
]
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
1466
|
+
DStateProps2._Queries = {
|
|
1467
|
+
disableAudioIconQuery,
|
|
1468
|
+
disableVideoPlayQuery,
|
|
1469
|
+
disableUserInputQuery,
|
|
1470
|
+
hideVideoPauseQuery,
|
|
1471
|
+
hideVideoPlayQuery
|
|
1472
|
+
};
|
|
1473
|
+
DStateProps2.allDefaultProperties = Object.values(_props);
|
|
1474
|
+
DStateProps2.allDefaultQueries = Object.values(DStateProps2._Queries);
|
|
1475
|
+
})(DStateProps || (DStateProps = {}));
|
|
1476
|
+
|
|
1477
|
+
// src/theme/theme-utils.ts
|
|
1478
|
+
var ThemeUtils;
|
|
1479
|
+
((ThemeUtils2) => {
|
|
1480
|
+
ThemeUtils2.disableClickCommands = (elementId, styleChanges) => {
|
|
1481
|
+
return [
|
|
1482
|
+
{
|
|
1483
|
+
kind: "ELEMENT_DISABLE_CLICK_COMMAND",
|
|
1484
|
+
target: "ELEMENT",
|
|
1485
|
+
targetId: elementId,
|
|
1486
|
+
payload: {}
|
|
1487
|
+
},
|
|
1488
|
+
{
|
|
1489
|
+
kind: "ELEMENT_STYLE_COMMAND",
|
|
1490
|
+
target: "ELEMENT",
|
|
1491
|
+
targetId: elementId,
|
|
1492
|
+
payload: { changes: styleChanges }
|
|
1493
|
+
}
|
|
1494
|
+
];
|
|
1495
|
+
};
|
|
1496
|
+
ThemeUtils2.enableClickCommands = (elementId, styleChanges) => {
|
|
1497
|
+
return [
|
|
1498
|
+
{
|
|
1499
|
+
kind: "ELEMENT_ENABLE_CLICK_COMMAND",
|
|
1500
|
+
target: "ELEMENT",
|
|
1501
|
+
targetId: elementId,
|
|
1502
|
+
payload: {}
|
|
1503
|
+
},
|
|
1504
|
+
{
|
|
1505
|
+
kind: "ELEMENT_STYLE_COMMAND",
|
|
1506
|
+
target: "ELEMENT",
|
|
1507
|
+
targetId: elementId,
|
|
1508
|
+
payload: { changes: styleChanges }
|
|
1509
|
+
}
|
|
1510
|
+
];
|
|
1511
|
+
};
|
|
1512
|
+
ThemeUtils2.hideCommand = (elementId) => {
|
|
1513
|
+
const hideCommand2 = {
|
|
1514
|
+
kind: "ELEMENT_STYLE_COMMAND",
|
|
1515
|
+
target: "ELEMENT",
|
|
1516
|
+
targetId: elementId,
|
|
1517
|
+
payload: { changes: { visibility: "hidden" } }
|
|
1518
|
+
};
|
|
1519
|
+
return hideCommand2;
|
|
1520
|
+
};
|
|
1521
|
+
ThemeUtils2.showCommand = (elementId) => {
|
|
1522
|
+
const showCommand2 = {
|
|
1523
|
+
kind: "ELEMENT_STYLE_COMMAND",
|
|
1524
|
+
target: "ELEMENT",
|
|
1525
|
+
targetId: elementId,
|
|
1526
|
+
payload: { changes: { visibility: "visible" } }
|
|
1527
|
+
};
|
|
1528
|
+
return showCommand2;
|
|
1529
|
+
};
|
|
1530
|
+
ThemeUtils2.spaceEvenlyX = (items, options = {
|
|
1531
|
+
startAt: 0,
|
|
1532
|
+
endAt: 100,
|
|
1533
|
+
defaultItemWidth: 5
|
|
1534
|
+
}) => {
|
|
1535
|
+
const startAt = options?.startAt ?? 0;
|
|
1536
|
+
const endAt = options?.endAt ?? 100;
|
|
1537
|
+
const range = Math.abs(endAt - startAt);
|
|
1538
|
+
if (items.length === 0) {
|
|
1539
|
+
return [];
|
|
1540
|
+
}
|
|
1541
|
+
const marginCount = items.length + 1;
|
|
1542
|
+
const defaultWidth = options.defaultItemWidth ?? 150 / marginCount;
|
|
1543
|
+
let totalWidthOfElements = items.reduce((prev, curr) => {
|
|
1544
|
+
const w = curr.style.w ?? defaultWidth;
|
|
1545
|
+
return prev + w;
|
|
1546
|
+
}, 0);
|
|
1547
|
+
let cursor = startAt;
|
|
1548
|
+
const rest = Math.max(range - totalWidthOfElements, 0);
|
|
1549
|
+
const margin = rest / marginCount;
|
|
1550
|
+
items.forEach((item) => {
|
|
1551
|
+
cursor = cursor + margin;
|
|
1552
|
+
const w = item.style.w ?? defaultWidth;
|
|
1553
|
+
const x = cursor;
|
|
1554
|
+
cursor = cursor + w;
|
|
1555
|
+
item.style.w = w;
|
|
1556
|
+
item.style.x = x;
|
|
1557
|
+
});
|
|
1558
|
+
return items;
|
|
1559
|
+
};
|
|
1560
|
+
ThemeUtils2.centerY = () => ({
|
|
1561
|
+
y: 50,
|
|
1562
|
+
transform: "translate(0%, 50%)"
|
|
1563
|
+
});
|
|
1564
|
+
ThemeUtils2.centerX = () => ({
|
|
1565
|
+
x: 50,
|
|
1566
|
+
transform: "translate(-50%, 0%)"
|
|
1567
|
+
});
|
|
1568
|
+
ThemeUtils2.centerXY = () => ({
|
|
1569
|
+
x: 50,
|
|
1570
|
+
y: 50,
|
|
1571
|
+
transform: "translate(-50%, 50%)"
|
|
1572
|
+
});
|
|
1573
|
+
})(ThemeUtils || (ThemeUtils = {}));
|
|
1574
|
+
|
|
1575
|
+
// src/theme/default-theme-compiler.ts
|
|
1576
|
+
var import_engine4 = require("@media-quest/engine");
|
|
1577
|
+
var U3 = import_engine4.DUtil;
|
|
1578
|
+
var generateElementId = () => U3.randomString(32);
|
|
1579
|
+
var DefaultThemeCompiler = class extends AbstractThemeCompiler {
|
|
1580
|
+
name = "Ispe default theme.";
|
|
1581
|
+
constructor() {
|
|
1582
|
+
super(DefaultTheme);
|
|
1583
|
+
}
|
|
1584
|
+
compile(source) {
|
|
1585
|
+
const pages = source.pages.map((p) => this.compilePage(p, source.id));
|
|
1586
|
+
const dto = {
|
|
1587
|
+
backgroundColor: source.backgroundColor,
|
|
1588
|
+
baseHeight: source.baseHeight,
|
|
1589
|
+
baseWidth: source.baseWidth,
|
|
1590
|
+
id: source.id,
|
|
1591
|
+
pageSequences: [],
|
|
1592
|
+
pages,
|
|
1593
|
+
predefinedFacts: [],
|
|
1594
|
+
prefix: source.prefix,
|
|
1595
|
+
rules: [],
|
|
1596
|
+
stateFromEvent: [
|
|
1597
|
+
{
|
|
1598
|
+
onEvent: "VIDEO_ENDED_EVENT",
|
|
1599
|
+
thenExecute: [
|
|
1600
|
+
DStateProps.userPausedVideo.getSetFalseCommand(),
|
|
1601
|
+
DStateProps.mediaBlockedByVideo.getSetFalseCommand(),
|
|
1602
|
+
DStateProps.videoIsPlaying.getSetFalseCommand()
|
|
1603
|
+
]
|
|
1604
|
+
},
|
|
1605
|
+
{
|
|
1606
|
+
onEvent: "VIDEO_PAUSED_EVENT",
|
|
1607
|
+
thenExecute: [
|
|
1608
|
+
DStateProps.videoIsPlaying.getSetFalseCommand(),
|
|
1609
|
+
DStateProps.mediaBlockedByVideo.getSetFalseCommand()
|
|
1610
|
+
]
|
|
1611
|
+
},
|
|
1612
|
+
{
|
|
1613
|
+
onEvent: "VIDEO_PLAY_EVENT",
|
|
1614
|
+
thenExecute: [
|
|
1615
|
+
DStateProps.videoIsPlaying.getSetTrueCommand(),
|
|
1616
|
+
DStateProps.userPausedVideo.getSetFalseCommand()
|
|
1617
|
+
]
|
|
1618
|
+
},
|
|
1619
|
+
{
|
|
1620
|
+
onEvent: "AUDIO_PLAY_EVENT",
|
|
1621
|
+
thenExecute: [
|
|
1622
|
+
DStateProps.audioIsPlaying.getSetTrueCommand(),
|
|
1623
|
+
DStateProps.mediaBlockedByAudio.getSetTrueCommand()
|
|
1624
|
+
]
|
|
1625
|
+
},
|
|
1626
|
+
{
|
|
1627
|
+
onEvent: "AUDIO_ENDED_EVENT",
|
|
1628
|
+
thenExecute: [
|
|
1629
|
+
DStateProps.audioIsPlaying.getSetFalseCommand(),
|
|
1630
|
+
DStateProps.mediaBlockedByAudio.getSetFalseCommand()
|
|
1631
|
+
]
|
|
1632
|
+
},
|
|
1633
|
+
{
|
|
1634
|
+
onEvent: "AUDIO_PAUSED_EVENT",
|
|
1635
|
+
thenExecute: [
|
|
1636
|
+
DStateProps.audioIsPlaying.getSetFalseCommand(),
|
|
1637
|
+
DStateProps.mediaBlockedByAudio.getSetFalseCommand()
|
|
1638
|
+
]
|
|
1639
|
+
}
|
|
1640
|
+
],
|
|
1641
|
+
stateProps: DStateProps.allDefaultProperties.map((def) => def.propDefinition),
|
|
1642
|
+
stateQueries: DStateProps.allDefaultQueries
|
|
1643
|
+
};
|
|
1644
|
+
return dto;
|
|
1645
|
+
}
|
|
1646
|
+
compilePage(page, _moduleId) {
|
|
1647
|
+
const { nextButton, mainText, id, mainMedia, _type } = page;
|
|
1648
|
+
const elements = [];
|
|
1649
|
+
const audioResourcesDto = [];
|
|
1650
|
+
const videoResources = [];
|
|
1651
|
+
let mainVideo = false;
|
|
1652
|
+
let mainTextAudio = false;
|
|
1653
|
+
if (page.mainText.audioFile) {
|
|
1654
|
+
const res = this.compileMainTextAudio(page.mainText.audioFile);
|
|
1655
|
+
elements.push(...res.elements);
|
|
1656
|
+
audioResourcesDto.push(res.audioDto);
|
|
1657
|
+
mainTextAudio = res.audioDto;
|
|
1658
|
+
}
|
|
1659
|
+
if (_type === "question") {
|
|
1660
|
+
const { buttons, question } = this.compileQuestion(id, page);
|
|
1661
|
+
elements.push(...buttons, question);
|
|
1662
|
+
}
|
|
1663
|
+
if (_type === "info-page") {
|
|
1664
|
+
const infoText = mainText.text;
|
|
1665
|
+
const nextBtnElement = this.compileButton(id, nextButton, {
|
|
1666
|
+
kind: "next-button"
|
|
1667
|
+
});
|
|
1668
|
+
const element = {
|
|
1669
|
+
text: infoText,
|
|
1670
|
+
_tag: "p",
|
|
1671
|
+
id: generateElementId(),
|
|
1672
|
+
style: DefaultTheme.mainText.withMedia.text.css
|
|
1673
|
+
};
|
|
1674
|
+
elements.push(element);
|
|
1675
|
+
elements.push(nextBtnElement);
|
|
1676
|
+
}
|
|
1677
|
+
if (mainMedia && mainMedia.kind === "main-image") {
|
|
1678
|
+
const mainImageElement = this.compileImage(mainMedia);
|
|
1679
|
+
elements.push(mainImageElement);
|
|
1680
|
+
}
|
|
1681
|
+
if (mainMedia && mainMedia.kind === "main-video") {
|
|
1682
|
+
const videoOutput = this.compileVideo(mainMedia);
|
|
1683
|
+
mainVideo = videoOutput.videoDto;
|
|
1684
|
+
elements.push(...videoOutput.elements);
|
|
1685
|
+
videoResources.push(videoOutput.videoDto);
|
|
1686
|
+
}
|
|
1687
|
+
const mainVideoId = mainVideo ? mainVideo.id : void 0;
|
|
1688
|
+
const autoPlaySequence = {
|
|
1689
|
+
blockUserInput: true,
|
|
1690
|
+
id: "1",
|
|
1691
|
+
items: [],
|
|
1692
|
+
startCommands: [
|
|
1693
|
+
DStateProps.mediaBlockedBySequence.getSetTrueCommand(),
|
|
1694
|
+
DStateProps.inputBlockingBySequence.getSetTrueCommand()
|
|
1695
|
+
],
|
|
1696
|
+
endCommands: [
|
|
1697
|
+
DStateProps.mediaBlockedBySequence.getSetFalseCommand(),
|
|
1698
|
+
DStateProps.inputBlockingBySequence.getSetFalseCommand()
|
|
1699
|
+
]
|
|
1700
|
+
};
|
|
1701
|
+
if (mainVideo && page.mainMedia && page.mainMedia.kind === "main-video" && page.mainMedia.mode === "autoplay") {
|
|
1702
|
+
autoPlaySequence.items.push({
|
|
1703
|
+
kind: "autoplay-video",
|
|
1704
|
+
videoId: mainVideo.id
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
if (mainTextAudio && page.mainText.autoplay) {
|
|
1708
|
+
autoPlaySequence.items.push({
|
|
1709
|
+
kind: "autoplay-audio",
|
|
1710
|
+
audioId: mainTextAudio.id
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
const pageDto = {
|
|
1714
|
+
audio: audioResourcesDto,
|
|
1715
|
+
autoPlaySequence,
|
|
1716
|
+
backgroundColor: "red",
|
|
1717
|
+
elements,
|
|
1718
|
+
id,
|
|
1719
|
+
mainVideoId,
|
|
1720
|
+
tags: [],
|
|
1721
|
+
video: videoResources
|
|
1722
|
+
};
|
|
1723
|
+
return pageDto;
|
|
1724
|
+
}
|
|
1725
|
+
compileImage(image) {
|
|
1726
|
+
const img = {
|
|
1727
|
+
_tag: "img",
|
|
1728
|
+
id: image.file.id,
|
|
1729
|
+
style: this.theme.image.style,
|
|
1730
|
+
url: image.file.downloadUrl
|
|
1731
|
+
};
|
|
1732
|
+
return img;
|
|
1733
|
+
}
|
|
1734
|
+
compileMainTextAudio(audioFile) {
|
|
1735
|
+
const t = this.theme.mainText;
|
|
1736
|
+
const audioId = audioFile.id;
|
|
1737
|
+
const iconUrl = "https://firebasestorage.googleapis.com/v0/b/ispe-backend-dev.appspot.com/o/public-assets%2Fvolume_up-24px.svg?alt=media&token=551bd0a6-a515-4f87-a245-da433f4833f9";
|
|
1738
|
+
const buttonId = U3.randomString(30);
|
|
1739
|
+
const playMainTextAudio = {
|
|
1740
|
+
_tag: "img",
|
|
1741
|
+
id: buttonId,
|
|
1742
|
+
url: iconUrl,
|
|
1743
|
+
style: { ...t.withMedia.audio.css },
|
|
1744
|
+
onClick: [
|
|
1745
|
+
{
|
|
1746
|
+
kind: "AUDIO_PLAY_COMMAND",
|
|
1747
|
+
target: "AUDIO",
|
|
1748
|
+
targetId: audioId,
|
|
1749
|
+
payload: { volume: 1 }
|
|
1750
|
+
}
|
|
1751
|
+
],
|
|
1752
|
+
onStateChange: [
|
|
1753
|
+
{
|
|
1754
|
+
queryName: DStateProps._Queries.disableAudioIconQuery.name,
|
|
1755
|
+
whenTrue: [...ThemeUtils.disableClickCommands(buttonId, t.withMedia.audio.cssDisabled)],
|
|
1756
|
+
whenFalse: [...ThemeUtils.enableClickCommands(buttonId, t.withMedia.audio.cssEnabled)]
|
|
1757
|
+
}
|
|
1758
|
+
]
|
|
1759
|
+
};
|
|
1760
|
+
const audioDto = {
|
|
1761
|
+
_tag: "audio",
|
|
1762
|
+
// eventHandlers: [],
|
|
1763
|
+
id: audioFile.id,
|
|
1764
|
+
url: audioFile.downloadUrl
|
|
1765
|
+
};
|
|
1766
|
+
return { audioDto, elements: [playMainTextAudio] };
|
|
1767
|
+
}
|
|
1768
|
+
compileVideo(video) {
|
|
1769
|
+
const t = this.theme.videoPlayer;
|
|
1770
|
+
const videoId = video.file.id;
|
|
1771
|
+
const playButtonId = "play-btn-for" + videoId;
|
|
1772
|
+
const pauseButtonId = "pause-btn-for" + videoId;
|
|
1773
|
+
const elements = [];
|
|
1774
|
+
const videoDto = {
|
|
1775
|
+
_tag: "video",
|
|
1776
|
+
id: video.file.id,
|
|
1777
|
+
style: t.videoElement.css,
|
|
1778
|
+
url: video.file.downloadUrl
|
|
1779
|
+
};
|
|
1780
|
+
const playBtn = {
|
|
1781
|
+
id: playButtonId,
|
|
1782
|
+
_tag: "img",
|
|
1783
|
+
url: t.playButton.iconUrl,
|
|
1784
|
+
style: { ...t.playButton.css, ...t.playButton.cssEnabled },
|
|
1785
|
+
onClick: [
|
|
1786
|
+
{
|
|
1787
|
+
kind: "VIDEO_PLAY_COMMAND",
|
|
1788
|
+
target: "VIDEO",
|
|
1789
|
+
targetId: videoId,
|
|
1790
|
+
payload: {}
|
|
1791
|
+
},
|
|
1792
|
+
// TODO Check if this video shall block other media first?
|
|
1793
|
+
DStateProps.mediaBlockedByVideo.getSetTrueCommand(),
|
|
1794
|
+
DStateProps.userPausedVideo.getSetFalseCommand()
|
|
1795
|
+
],
|
|
1796
|
+
onStateChange: [
|
|
1797
|
+
{
|
|
1798
|
+
queryName: DStateProps._Queries.disableVideoPlayQuery.name,
|
|
1799
|
+
whenTrue: [...ThemeUtils.disableClickCommands(playButtonId, t.playButton.cssDisabled)],
|
|
1800
|
+
whenFalse: [...ThemeUtils.enableClickCommands(playButtonId, t.playButton.cssEnabled)]
|
|
1801
|
+
},
|
|
1802
|
+
{
|
|
1803
|
+
queryName: DStateProps._Queries.hideVideoPlayQuery.name,
|
|
1804
|
+
whenTrue: [ThemeUtils.hideCommand(playButtonId)],
|
|
1805
|
+
whenFalse: [ThemeUtils.showCommand(playButtonId)]
|
|
1806
|
+
}
|
|
1807
|
+
]
|
|
1808
|
+
};
|
|
1809
|
+
const pauseBtn = {
|
|
1810
|
+
id: pauseButtonId,
|
|
1811
|
+
_tag: "img",
|
|
1812
|
+
style: {
|
|
1813
|
+
...t.pauseButton.css,
|
|
1814
|
+
visibility: "hidden",
|
|
1815
|
+
...t.pauseButton.cssEnabled
|
|
1816
|
+
},
|
|
1817
|
+
url: t.pauseButton.iconUrl,
|
|
1818
|
+
onClick: [
|
|
1819
|
+
{
|
|
1820
|
+
kind: "VIDEO_PAUSE_COMMAND",
|
|
1821
|
+
target: "VIDEO",
|
|
1822
|
+
targetId: videoId,
|
|
1823
|
+
payload: {}
|
|
1824
|
+
},
|
|
1825
|
+
DStateProps.mediaBlockedByVideo.getSetFalseCommand(),
|
|
1826
|
+
DStateProps.userPausedVideo.getSetTrueCommand()
|
|
1827
|
+
],
|
|
1828
|
+
onStateChange: [
|
|
1829
|
+
{
|
|
1830
|
+
queryName: DStateProps._Queries.hideVideoPauseQuery.name,
|
|
1831
|
+
whenTrue: [ThemeUtils.hideCommand(pauseButtonId)],
|
|
1832
|
+
whenFalse: [ThemeUtils.showCommand(pauseButtonId)]
|
|
1833
|
+
}
|
|
1834
|
+
]
|
|
1835
|
+
};
|
|
1836
|
+
elements.push(playBtn);
|
|
1837
|
+
elements.push(pauseBtn);
|
|
1838
|
+
return { videoDto, elements };
|
|
1839
|
+
}
|
|
1840
|
+
compileQuestion(pageId, page) {
|
|
1841
|
+
const q = page.defaultQuestion;
|
|
1842
|
+
const text = page.mainText.text;
|
|
1843
|
+
const question = {
|
|
1844
|
+
_tag: "p",
|
|
1845
|
+
text,
|
|
1846
|
+
eventHandlers: [],
|
|
1847
|
+
id: U3.randomString(30),
|
|
1848
|
+
onClick: [],
|
|
1849
|
+
onStateChange: [],
|
|
1850
|
+
style: DefaultTheme.mainText.withMedia.text.css
|
|
1851
|
+
};
|
|
1852
|
+
const buttons = q.options.map((o) => {
|
|
1853
|
+
const btns = this.compileButton(pageId, o, {
|
|
1854
|
+
kind: "response-button",
|
|
1855
|
+
questionId: ""
|
|
1856
|
+
});
|
|
1857
|
+
return btns;
|
|
1858
|
+
});
|
|
1859
|
+
ThemeUtils.spaceEvenlyX(buttons);
|
|
1860
|
+
return { question, buttons };
|
|
1861
|
+
}
|
|
1862
|
+
compileButton(pageId, buttonDto, options) {
|
|
1863
|
+
const factsCollected = [];
|
|
1864
|
+
const { id, value, label } = buttonDto;
|
|
1865
|
+
const { div, text1 } = DefaultTheme.responseButtons;
|
|
1866
|
+
if (options.kind === "response-button") {
|
|
1867
|
+
const fact = {
|
|
1868
|
+
kind: "numeric-fact",
|
|
1869
|
+
label,
|
|
1870
|
+
value,
|
|
1871
|
+
referenceId: options.questionId,
|
|
1872
|
+
referenceLabel: "QuestionId: " + options.questionId
|
|
1873
|
+
};
|
|
1874
|
+
factsCollected.push(fact);
|
|
1875
|
+
}
|
|
1876
|
+
const onClickHandler = {
|
|
1877
|
+
kind: "ENGINE_LEAVE_PAGE_COMMAND",
|
|
1878
|
+
target: "ENGINE",
|
|
1879
|
+
targetId: "ENGINE",
|
|
1880
|
+
payload: {
|
|
1881
|
+
pageId,
|
|
1882
|
+
factsCollected
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
const btn = {
|
|
1886
|
+
id,
|
|
1887
|
+
_tag: "div",
|
|
1888
|
+
children: [
|
|
1889
|
+
{
|
|
1890
|
+
_tag: "p",
|
|
1891
|
+
id: U3.randomString(30),
|
|
1892
|
+
text: label,
|
|
1893
|
+
style: text1
|
|
1894
|
+
}
|
|
1895
|
+
],
|
|
1896
|
+
onStateChange: [
|
|
1897
|
+
{
|
|
1898
|
+
queryName: DStateProps._Queries.disableUserInputQuery.name,
|
|
1899
|
+
whenFalse: [...ThemeUtils.enableClickCommands(id, div.cssEnabled)],
|
|
1900
|
+
whenTrue: [...ThemeUtils.disableClickCommands(id, div.cssDisabled)]
|
|
1901
|
+
}
|
|
1902
|
+
],
|
|
1903
|
+
style: { ...div.css, ...div.cssEnabled },
|
|
1904
|
+
onClick: [onClickHandler]
|
|
1905
|
+
};
|
|
1906
|
+
if (options.kind === "next-button") {
|
|
1907
|
+
btn.style.x = 50;
|
|
1908
|
+
btn.style.y = 8;
|
|
1909
|
+
btn.style.transform = "translate(-50%, 0%)";
|
|
1910
|
+
}
|
|
1911
|
+
return btn;
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
|
|
1915
|
+
// src/Builder-schema.ts
|
|
1916
|
+
var import_engine5 = require("@media-quest/engine");
|
|
1917
|
+
var U4 = import_engine5.DUtil;
|
|
1918
|
+
var BuilderSchema = class _BuilderSchema {
|
|
1919
|
+
constructor(id, name, prefix) {
|
|
1920
|
+
this.id = id;
|
|
1921
|
+
this.name = name;
|
|
1922
|
+
this.prefix = prefix;
|
|
1923
|
+
}
|
|
1924
|
+
baseHeight = 1300;
|
|
1925
|
+
baseWidth = 1024;
|
|
1926
|
+
backgroundColor = "#000000";
|
|
1927
|
+
pages = [];
|
|
1928
|
+
mainImage = false;
|
|
1929
|
+
_rules = [];
|
|
1930
|
+
get rules() {
|
|
1931
|
+
return [...this._rules];
|
|
1932
|
+
}
|
|
1933
|
+
_tagCollection = TagCollection.create();
|
|
1934
|
+
get tags() {
|
|
1935
|
+
return [...this._tagCollection];
|
|
1936
|
+
}
|
|
1937
|
+
static create(id, name, prefix) {
|
|
1938
|
+
return new _BuilderSchema(id, name, prefix);
|
|
1939
|
+
}
|
|
1940
|
+
static fromJson(dto) {
|
|
1941
|
+
const schema = new _BuilderSchema(dto.id, dto.name, dto.prefix);
|
|
1942
|
+
const pages = dto.pages.map(BuilderPage.fromJson);
|
|
1943
|
+
schema._tagCollection.init(dto.tags);
|
|
1944
|
+
schema.backgroundColor = dto.backgroundColor;
|
|
1945
|
+
schema.baseHeight = dto.baseHeight;
|
|
1946
|
+
schema.baseWidth = dto.baseWidth;
|
|
1947
|
+
schema.pages = pages;
|
|
1948
|
+
schema.backgroundColor = dto.backgroundColor;
|
|
1949
|
+
schema.mainImage = dto.mainImage ?? false;
|
|
1950
|
+
const rulesDto = dto.rules ?? [];
|
|
1951
|
+
const ruleInput = schema.getRuleInput();
|
|
1952
|
+
schema._rules = rulesDto.map((r) => BuilderRule.fromDto(r, ruleInput));
|
|
1953
|
+
return schema;
|
|
1954
|
+
}
|
|
1955
|
+
toJson() {
|
|
1956
|
+
const pages = this.pages.map((p) => p.toJson());
|
|
1957
|
+
const tags = this._tagCollection.toJson();
|
|
1958
|
+
const rules = this._rules.map((rule) => rule.toJson());
|
|
1959
|
+
const dto = {
|
|
1960
|
+
backgroundColor: this.backgroundColor,
|
|
1961
|
+
baseHeight: this.baseHeight,
|
|
1962
|
+
baseWidth: this.baseWidth,
|
|
1963
|
+
id: this.id,
|
|
1964
|
+
name: this.name,
|
|
1965
|
+
pages,
|
|
1966
|
+
rules,
|
|
1967
|
+
tags,
|
|
1968
|
+
mainImage: this.mainImage,
|
|
1969
|
+
prefix: this.prefix
|
|
1970
|
+
};
|
|
1971
|
+
return dto;
|
|
1972
|
+
}
|
|
1973
|
+
addPage(type, atIndex = -1) {
|
|
1974
|
+
const newPage = BuilderPage.create(type, "");
|
|
1975
|
+
if (atIndex >= 0 && atIndex < this.pages.length) {
|
|
1976
|
+
this.pages.splice(atIndex, 0, newPage);
|
|
1977
|
+
} else {
|
|
1978
|
+
this.pages.push(newPage);
|
|
1979
|
+
}
|
|
1980
|
+
return newPage;
|
|
1981
|
+
}
|
|
1982
|
+
insertPage(page, atIndex) {
|
|
1983
|
+
return this.insertPageAtIndex(page, atIndex);
|
|
1984
|
+
}
|
|
1985
|
+
insertPageAtIndex(page, atIndex) {
|
|
1986
|
+
const isValidIndex = U4.isInRange(0, this.pages.length - 1);
|
|
1987
|
+
if (!isValidIndex(atIndex)) {
|
|
1988
|
+
return false;
|
|
1989
|
+
}
|
|
1990
|
+
const exists = !!this.pages.find((p) => p.id === page.id);
|
|
1991
|
+
if (exists) {
|
|
1992
|
+
return false;
|
|
1993
|
+
}
|
|
1994
|
+
this.pages.splice(atIndex, 0, page);
|
|
1995
|
+
return true;
|
|
1996
|
+
}
|
|
1997
|
+
addRule() {
|
|
1998
|
+
const input = this.getRuleInput();
|
|
1999
|
+
const count = this._rules.length + 1;
|
|
2000
|
+
const name = "Rule-number: " + count;
|
|
2001
|
+
const rule = BuilderRule.fromDto(
|
|
2002
|
+
{
|
|
2003
|
+
conditions: [],
|
|
2004
|
+
type: "all",
|
|
2005
|
+
name,
|
|
2006
|
+
excludeTags: [],
|
|
2007
|
+
jumpToPage: false,
|
|
2008
|
+
excludePages: []
|
|
2009
|
+
},
|
|
2010
|
+
input
|
|
2011
|
+
);
|
|
2012
|
+
this._rules.push(rule);
|
|
2013
|
+
}
|
|
2014
|
+
deleteRule(rule) {
|
|
2015
|
+
this._rules = this._rules.filter((r) => r !== rule);
|
|
2016
|
+
}
|
|
2017
|
+
movePage(page, toIndex) {
|
|
2018
|
+
const index = this.pages.indexOf(page);
|
|
2019
|
+
if (index < 0) {
|
|
2020
|
+
return false;
|
|
2021
|
+
}
|
|
2022
|
+
const isValidIndex = U4.isInRange(0, this.pages.length - 1);
|
|
2023
|
+
if (!isValidIndex(toIndex)) {
|
|
2024
|
+
return false;
|
|
2025
|
+
}
|
|
2026
|
+
this.pages.splice(index, 1);
|
|
2027
|
+
this.pages.splice(toIndex, 0, page);
|
|
2028
|
+
return true;
|
|
2029
|
+
}
|
|
2030
|
+
deletePage(page) {
|
|
2031
|
+
const filtered = this.pages.filter((p) => p !== page);
|
|
2032
|
+
const didDelete = filtered.length === this.pages.length - 1;
|
|
2033
|
+
this.pages = filtered;
|
|
2034
|
+
return didDelete;
|
|
2035
|
+
}
|
|
2036
|
+
reevaluateRules() {
|
|
2037
|
+
console.log("Reevaluationg rulesInput");
|
|
2038
|
+
const input = this.getRuleInput();
|
|
2039
|
+
const rulesDto = this._rules.map((r) => r.toJson());
|
|
2040
|
+
this._rules = rulesDto.map((dto) => BuilderRule.fromDto(dto, input));
|
|
2041
|
+
}
|
|
2042
|
+
getRuleInput() {
|
|
2043
|
+
const qVars = [];
|
|
2044
|
+
const cVars = [];
|
|
2045
|
+
const pageIdActions = [];
|
|
2046
|
+
const tagActions = this.tags.map((t) => {
|
|
2047
|
+
const tag = t.tagText;
|
|
2048
|
+
const pageCount = this.pages.reduce((count, curr) => {
|
|
2049
|
+
return curr.tags.includes(tag) ? count + 1 : count;
|
|
2050
|
+
}, 0);
|
|
2051
|
+
const excludeByTagDto = {
|
|
2052
|
+
kind: "exclude-by-tag",
|
|
2053
|
+
pageCount,
|
|
2054
|
+
tag,
|
|
2055
|
+
description: t.tagDescription
|
|
2056
|
+
};
|
|
2057
|
+
return excludeByTagDto;
|
|
2058
|
+
});
|
|
2059
|
+
const jumpActions = [];
|
|
2060
|
+
const prefix = "";
|
|
2061
|
+
this.pages.forEach((page, index) => {
|
|
2062
|
+
const pageVariables = page.getQuestionVariables(prefix, index);
|
|
2063
|
+
qVars.push(...pageVariables);
|
|
2064
|
+
const pageId = page.prefix;
|
|
2065
|
+
const mainText = page.mainText.text;
|
|
2066
|
+
const jumpAction = {
|
|
2067
|
+
kind: "jump-to-page",
|
|
2068
|
+
pageId,
|
|
2069
|
+
pageNumber: index,
|
|
2070
|
+
mainText: page.mainText.text
|
|
2071
|
+
};
|
|
2072
|
+
const excludePageAction = {
|
|
2073
|
+
kind: "exclude-by-pageId",
|
|
2074
|
+
pageId,
|
|
2075
|
+
pageNumber: index,
|
|
2076
|
+
mainText
|
|
2077
|
+
};
|
|
2078
|
+
jumpActions.push(jumpAction);
|
|
2079
|
+
pageIdActions.push(excludePageAction);
|
|
2080
|
+
});
|
|
2081
|
+
const ruleInput = new RuleInput(qVars, cVars, pageIdActions, tagActions, jumpActions);
|
|
2082
|
+
return ruleInput;
|
|
2083
|
+
}
|
|
2084
|
+
deleteTags(tags) {
|
|
2085
|
+
this._tagCollection.deleteAll(tags);
|
|
2086
|
+
}
|
|
2087
|
+
addTag(builderTag) {
|
|
2088
|
+
this._tagCollection.add(builderTag);
|
|
2089
|
+
}
|
|
2090
|
+
// getHash(): SchemaHash {
|
|
2091
|
+
// const md5 = MD5(this.toJson());
|
|
2092
|
+
// return
|
|
2093
|
+
// }
|
|
2094
|
+
// hasChanged(hash: SchemaHash): boolean {
|
|
2095
|
+
// return hash !== this.getHash();
|
|
2096
|
+
// }
|
|
2097
|
+
getQuestionVariables(withModulePrefix = false) {
|
|
2098
|
+
const prefix = withModulePrefix ? this.prefix : "";
|
|
2099
|
+
const all = this.pages.map((page, index) => {
|
|
2100
|
+
return page.getQuestionVariables(prefix, index);
|
|
2101
|
+
}).flat(1);
|
|
2102
|
+
return all;
|
|
2103
|
+
}
|
|
2104
|
+
compile() {
|
|
2105
|
+
const moduleDto = this.toJson();
|
|
2106
|
+
const imp = new DefaultThemeCompiler();
|
|
2107
|
+
const schema = imp.compile(moduleDto);
|
|
2108
|
+
return { codebook: {}, schema, schemaConfig: {} };
|
|
2109
|
+
}
|
|
2110
|
+
};
|
|
2111
|
+
|
|
2112
|
+
// src/Builder-text.ts
|
|
2113
|
+
var BuilderText = class _BuilderText extends BuilderObject {
|
|
2114
|
+
objectType = "builder-text";
|
|
2115
|
+
id;
|
|
2116
|
+
text = "";
|
|
2117
|
+
name = "";
|
|
2118
|
+
translateRequired = false;
|
|
2119
|
+
// audio: {id: B}
|
|
2120
|
+
constructor(dto) {
|
|
2121
|
+
super(dto);
|
|
2122
|
+
this.id = dto.id;
|
|
2123
|
+
this.translateRequired = dto.translationRequired;
|
|
2124
|
+
this.name = dto.name;
|
|
2125
|
+
this.text = dto.text;
|
|
2126
|
+
}
|
|
2127
|
+
static create(name) {
|
|
2128
|
+
const id = BuilderObjectId.textId();
|
|
2129
|
+
const dto = {
|
|
2130
|
+
id,
|
|
2131
|
+
name,
|
|
2132
|
+
text: "",
|
|
2133
|
+
translationRequired: false
|
|
2134
|
+
};
|
|
2135
|
+
const instance = new _BuilderText(dto);
|
|
2136
|
+
return instance;
|
|
2137
|
+
}
|
|
2138
|
+
static fromJson(dto) {
|
|
2139
|
+
const instance = new _BuilderText(dto);
|
|
2140
|
+
return instance;
|
|
2141
|
+
}
|
|
2142
|
+
clone() {
|
|
2143
|
+
const newId = BuilderObjectId.textId();
|
|
2144
|
+
const dto = this.toJson();
|
|
2145
|
+
const withNewId = { ...dto, id: newId };
|
|
2146
|
+
return withNewId;
|
|
2147
|
+
}
|
|
2148
|
+
toJson() {
|
|
2149
|
+
const dto = {
|
|
2150
|
+
id: this.id,
|
|
2151
|
+
name: this.name,
|
|
2152
|
+
text: this.text,
|
|
2153
|
+
translationRequired: this.translateRequired
|
|
2154
|
+
};
|
|
2155
|
+
return dto;
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2159
|
+
0 && (module.exports = {
|
|
2160
|
+
BuilderCondition,
|
|
2161
|
+
BuilderConditionGroup,
|
|
2162
|
+
BuilderMainText,
|
|
2163
|
+
BuilderOperator,
|
|
2164
|
+
BuilderOption,
|
|
2165
|
+
BuilderPage,
|
|
2166
|
+
BuilderQuestion,
|
|
2167
|
+
BuilderRule,
|
|
2168
|
+
BuilderSchema,
|
|
2169
|
+
BuilderTag,
|
|
2170
|
+
BuilderText,
|
|
2171
|
+
BuilderVariableOption,
|
|
2172
|
+
CustomVariable,
|
|
2173
|
+
ExcludeByPageIdSelectItem,
|
|
2174
|
+
ExcludeByTagSelectItem,
|
|
2175
|
+
JumpToActionManager,
|
|
2176
|
+
JumpToPageSelectItem,
|
|
2177
|
+
MultiSelectItem,
|
|
2178
|
+
OperatorSelectItem,
|
|
2179
|
+
PageActionManager,
|
|
2180
|
+
QuestionVariable,
|
|
2181
|
+
RuleInput,
|
|
2182
|
+
RuleOptionSelectItem,
|
|
2183
|
+
RuleVariableSelectItem,
|
|
2184
|
+
SingleSelectItem,
|
|
2185
|
+
TagActionManager,
|
|
2186
|
+
TagCollection
|
|
2187
|
+
});
|