@media-quest/builder 0.0.6 → 0.0.8
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 +51 -39
- package/dist/public-api.d.ts +51 -39
- package/dist/public-api.js +152 -49
- package/dist/public-api.mjs +153 -50
- package/package.json +3 -3
- package/src/Builder-page.spec.ts +21 -15
- package/src/Builder-page.ts +21 -18
- package/src/Builder-schema.spec.ts +270 -268
- package/src/Builder-schema.ts +32 -31
- package/src/BuilderObject.ts +0 -8
- package/src/prefix.spec.ts +5 -0
- package/src/prefix.ts +107 -0
- package/src/rulebuilder/Builder-rule.spec.ts +64 -35
- package/src/rulebuilder/Builder-rule.ts +3 -3
- package/src/rulebuilder/RuleAction.ts +7 -5
- package/src/rulebuilder/RuleBuilder-test-utils.ts +61 -30
- package/src/rulebuilder/RuleVariable.ts +6 -2
- package/src/rulebuilder/condition/Builder-condition-group.ts +2 -2
- package/src/rulebuilder/condition/Builder-condition.spec.ts +38 -29
- package/src/rulebuilder/condition/Builder-condition.ts +2 -2
- package/src/theme/IDefaultTheme.ts +2 -2
- package/src/theme/default-theme-compiler.ts +9 -6
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@media-quest/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Builder library for Media-quest schemas",
|
|
5
5
|
"main": "dist/public-api.js",
|
|
6
6
|
"module": "dist/public-api.mjs",
|
|
7
7
|
"types": "dist/public-api.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"check": "tsc --watch --noEmit",
|
|
10
|
+
"tsc:check:builder": "tsc --watch --noEmit",
|
|
11
11
|
"clean": "rimraf dist",
|
|
12
12
|
"build": "npm run clean && tsup src/public-api.ts --sourcemap inline --format cjs,esm --dts",
|
|
13
13
|
"prepublishOnly": "npm run build"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@media-quest/engine": "0.0.
|
|
16
|
+
"@media-quest/engine": "0.0.8"
|
|
17
17
|
}
|
|
18
18
|
}
|
package/src/Builder-page.spec.ts
CHANGED
|
@@ -3,7 +3,8 @@ import type { BuilderPageDto } from "./Builder-page";
|
|
|
3
3
|
import type { BuilderQuestionDto } from "./Builder-question";
|
|
4
4
|
import { BuilderQuestion } from "./Builder-question";
|
|
5
5
|
import type { BuilderObjectId } from "./BuilderObject";
|
|
6
|
-
import { DUtil } from "@media-quest/engine";
|
|
6
|
+
import { DUtil, PageID } from "@media-quest/engine";
|
|
7
|
+
import { PagePrefix, SchemaPrefix } from "./prefix";
|
|
7
8
|
|
|
8
9
|
const U = DUtil;
|
|
9
10
|
const deleteIdsFromPage = (page: BuilderPageDto) => {
|
|
@@ -19,6 +20,7 @@ const deleteIdsFromPage = (page: BuilderPageDto) => {
|
|
|
19
20
|
return page;
|
|
20
21
|
};
|
|
21
22
|
|
|
23
|
+
const pxx = PagePrefix.fromStringOrThrow("pxx");
|
|
22
24
|
const questionPageDto: BuilderPageDto = {
|
|
23
25
|
_type: "question",
|
|
24
26
|
autoplaySequence: [],
|
|
@@ -58,8 +60,9 @@ const questionPageDto: BuilderPageDto = {
|
|
|
58
60
|
],
|
|
59
61
|
_type: "select-one",
|
|
60
62
|
},
|
|
61
|
-
id: "p1" as BuilderObjectId.PageID,
|
|
62
|
-
|
|
63
|
+
// id: "p1" as BuilderObjectId.PageID,
|
|
64
|
+
id: PageID.create(),
|
|
65
|
+
prefix: PagePrefix.fromStringOrThrow("pxx"),
|
|
63
66
|
questions: [],
|
|
64
67
|
};
|
|
65
68
|
|
|
@@ -86,8 +89,8 @@ const multiQuestionPageDto: BuilderPageDto = {
|
|
|
86
89
|
value: -1,
|
|
87
90
|
},
|
|
88
91
|
|
|
89
|
-
id:
|
|
90
|
-
prefix: "",
|
|
92
|
+
id: PageID.create(),
|
|
93
|
+
prefix: PagePrefix.fromStringOrThrow("pxx"),
|
|
91
94
|
questions: [
|
|
92
95
|
{
|
|
93
96
|
id: "q3" as BuilderObjectId.QuestionID,
|
|
@@ -140,10 +143,10 @@ const multiQuestionPageDto: BuilderPageDto = {
|
|
|
140
143
|
],
|
|
141
144
|
};
|
|
142
145
|
|
|
143
|
-
let page = BuilderPage.create("info-page", "a");
|
|
146
|
+
let page = BuilderPage.create("info-page", PagePrefix.fromStringOrThrow("a"));
|
|
144
147
|
|
|
145
148
|
beforeEach(() => {
|
|
146
|
-
page = BuilderPage.create("info-page", "a");
|
|
149
|
+
page = BuilderPage.create("info-page", PagePrefix.fromStringOrThrow("a"));
|
|
147
150
|
});
|
|
148
151
|
|
|
149
152
|
describe("Builder Page", () => {
|
|
@@ -190,7 +193,7 @@ describe("Builder Page", () => {
|
|
|
190
193
|
expect(q3.type).toBe("email");
|
|
191
194
|
});
|
|
192
195
|
test("Can clone a page and everything except id is equal ", () => {
|
|
193
|
-
const page1 = BuilderPage.create("info-page", "as");
|
|
196
|
+
const page1 = BuilderPage.create("info-page", PagePrefix.fromStringOrThrow("as"));
|
|
194
197
|
const clone1 = BuilderPage.fromJson(page1.clone());
|
|
195
198
|
const page1Json = deleteIdsFromPage(page1.clone());
|
|
196
199
|
const clone1Json = deleteIdsFromPage(page1.clone());
|
|
@@ -209,7 +212,7 @@ describe("Builder Page", () => {
|
|
|
209
212
|
expect(page3Json).toStrictEqual(clone3Json);
|
|
210
213
|
});
|
|
211
214
|
test("Can clone a page and no id is equal", () => {
|
|
212
|
-
const page1 = BuilderPage.create("info-page",
|
|
215
|
+
const page1 = BuilderPage.create("info-page", pxx);
|
|
213
216
|
const clone1 = BuilderPage.fromJson(page1.clone());
|
|
214
217
|
expect(page1.id).not.toBe(clone1.id);
|
|
215
218
|
|
|
@@ -243,7 +246,7 @@ describe("Builder Page", () => {
|
|
|
243
246
|
testDtoIds(multiQuestionPageDto);
|
|
244
247
|
});
|
|
245
248
|
test("Can insert a new Question at index", () => {
|
|
246
|
-
const page1 = BuilderPage.create("form",
|
|
249
|
+
const page1 = BuilderPage.create("form", pxx);
|
|
247
250
|
const q1 = page1.addQuestion("select-one");
|
|
248
251
|
const q2 = page1.addQuestion("select-many");
|
|
249
252
|
expect(page1.questions.length).toBe(3);
|
|
@@ -256,7 +259,7 @@ describe("Builder Page", () => {
|
|
|
256
259
|
expect(page1.questions[1]).toBe(q1Clone);
|
|
257
260
|
});
|
|
258
261
|
test("Can not insert a duplicate question", () => {
|
|
259
|
-
const page1 = BuilderPage.create("form",
|
|
262
|
+
const page1 = BuilderPage.create("form", pxx);
|
|
260
263
|
const q1 = page1.addQuestion("select-one");
|
|
261
264
|
expect(page1.questions.length).toBe(2);
|
|
262
265
|
expect(page1.questions[1]).toBe(q1);
|
|
@@ -266,7 +269,7 @@ describe("Builder Page", () => {
|
|
|
266
269
|
});
|
|
267
270
|
|
|
268
271
|
test("Can move a question", () => {
|
|
269
|
-
const page1 = BuilderPage.create("form",
|
|
272
|
+
const page1 = BuilderPage.create("form", pxx);
|
|
270
273
|
const q1 = page1.addQuestion("select-many");
|
|
271
274
|
const q2 = page1.addQuestion("select-one");
|
|
272
275
|
const q3 = page1.addQuestion("select-one");
|
|
@@ -285,7 +288,8 @@ describe("Builder Page", () => {
|
|
|
285
288
|
});
|
|
286
289
|
|
|
287
290
|
test("Can not move a question that is not in questions-array", () => {
|
|
288
|
-
const
|
|
291
|
+
const prefix = PagePrefix.fromStringOrThrow("as1");
|
|
292
|
+
const page1 = BuilderPage.create("form", prefix);
|
|
289
293
|
const q1 = page1.addQuestion("select-many");
|
|
290
294
|
const q2 = page1.addQuestion("select-one");
|
|
291
295
|
expect(page1.questions.length).toBe(3);
|
|
@@ -295,11 +299,13 @@ describe("Builder Page", () => {
|
|
|
295
299
|
expect(m1).toBe(false);
|
|
296
300
|
});
|
|
297
301
|
test("Can get all rule-variables.", () => {
|
|
298
|
-
const
|
|
302
|
+
const prefix = PagePrefix.fromStringOrThrow("as1");
|
|
303
|
+
const page = BuilderPage.create("question", prefix);
|
|
299
304
|
page.mainText.text = "Hva heter du?";
|
|
300
305
|
page.defaultQuestion.addOption("Ja", 1);
|
|
301
306
|
page.defaultQuestion.addOption("Nei", 0);
|
|
302
|
-
const
|
|
307
|
+
const shemaPrefix = SchemaPrefix.fromValueOrThrow("ax");
|
|
308
|
+
const variables = page.getQuestionVariables(shemaPrefix, 1);
|
|
303
309
|
const first = variables[0];
|
|
304
310
|
expect(variables.length).toBe(1);
|
|
305
311
|
expect(first.options.length).toBe(2);
|
package/src/Builder-page.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderQuestionDto, BuilderQuestionType } from "./Builder-question";
|
|
2
2
|
import { BuilderQuestion } from "./Builder-question";
|
|
3
|
-
import { BuilderObject
|
|
3
|
+
import { BuilderObject } from "./BuilderObject";
|
|
4
4
|
import type { BuilderOptionDto } from "./Builder-option";
|
|
5
5
|
import { BuilderOption } from "./Builder-option";
|
|
6
6
|
import type { BuilderMainVideoDto } from "./BuilderMainVideoDto";
|
|
@@ -8,14 +8,15 @@ import type { BuilderMainImageDto } from "./BuilderMainImageDto";
|
|
|
8
8
|
import type { BuilderMainTextDto } from "./BuilderMainText";
|
|
9
9
|
import { BuilderMainText } from "./BuilderMainText";
|
|
10
10
|
import { BuilderVariableOption, QuestionVariable } from "./rulebuilder/RuleVariable";
|
|
11
|
-
import { DUtil } from "@media-quest/engine";
|
|
11
|
+
import { DUtil, PageID } from "@media-quest/engine";
|
|
12
|
+
import { PagePrefix, PagePrefixValue, VarID, SchemaPrefix, SchemaPrefixValue } from "./prefix";
|
|
12
13
|
|
|
13
14
|
const U = DUtil;
|
|
14
15
|
export type BuilderPageType = "info-page" | "question" | "multi-select" | "form";
|
|
15
16
|
|
|
16
17
|
export interface BuilderPageDto {
|
|
17
|
-
readonly id:
|
|
18
|
-
prefix:
|
|
18
|
+
readonly id: PageID;
|
|
19
|
+
readonly prefix: PagePrefixValue;
|
|
19
20
|
_type: BuilderPageType;
|
|
20
21
|
mainText: BuilderMainTextDto;
|
|
21
22
|
nextButton: BuilderOptionDto;
|
|
@@ -28,9 +29,9 @@ export interface BuilderPageDto {
|
|
|
28
29
|
|
|
29
30
|
export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
30
31
|
readonly objectType: "builder-page" = "builder-page";
|
|
31
|
-
readonly id:
|
|
32
|
+
readonly id: PageID;
|
|
32
33
|
private _pageType: BuilderPageType;
|
|
33
|
-
private _prefix
|
|
34
|
+
private _prefix: PagePrefix;
|
|
34
35
|
private _questions: Array<BuilderQuestion> = [];
|
|
35
36
|
private readonly _tags: Set<string>;
|
|
36
37
|
private _backgroundColor = "#FFFFFF";
|
|
@@ -39,8 +40,8 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
39
40
|
mainText: BuilderMainText;
|
|
40
41
|
nextButton = BuilderOption.create(-1, "Neste");
|
|
41
42
|
|
|
42
|
-
public static create(type: BuilderPageType, _prefix:
|
|
43
|
-
const id =
|
|
43
|
+
public static create(type: BuilderPageType, _prefix: PagePrefixValue) {
|
|
44
|
+
const id = PageID.create();
|
|
44
45
|
const mainTextDto: BuilderMainTextDto = {
|
|
45
46
|
text: "",
|
|
46
47
|
audioFile: false,
|
|
@@ -49,6 +50,7 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
49
50
|
};
|
|
50
51
|
const nextButtonDto = BuilderOption.create(-1, "page-next-button-text").toJson();
|
|
51
52
|
const defaultQuestionDto = BuilderQuestion.create("select-one").toJson();
|
|
53
|
+
|
|
52
54
|
const dto: BuilderPageDto = {
|
|
53
55
|
_type: type,
|
|
54
56
|
autoplaySequence: [],
|
|
@@ -56,7 +58,7 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
56
58
|
id,
|
|
57
59
|
nextButton: nextButtonDto,
|
|
58
60
|
mainText: mainTextDto,
|
|
59
|
-
prefix:
|
|
61
|
+
prefix: _prefix,
|
|
60
62
|
questions: [],
|
|
61
63
|
tags: [],
|
|
62
64
|
};
|
|
@@ -73,7 +75,8 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
73
75
|
super(dto);
|
|
74
76
|
this.id = dto.id;
|
|
75
77
|
this._pageType = dto._type;
|
|
76
|
-
|
|
78
|
+
const prefixInstance = PagePrefix.castOrCreateRandom(dto.prefix);
|
|
79
|
+
this._prefix = prefixInstance;
|
|
77
80
|
this.mainText = BuilderMainText.fromJson(dto.mainText);
|
|
78
81
|
this.nextButton = BuilderOption.fromJson(dto.nextButton);
|
|
79
82
|
this.defaultQuestion = BuilderQuestion.fromJson(dto.defaultQuestion);
|
|
@@ -160,19 +163,19 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
160
163
|
this.updateRows();
|
|
161
164
|
}
|
|
162
165
|
|
|
163
|
-
getQuestionVariables(modulePrefix:
|
|
166
|
+
getQuestionVariables(modulePrefix: SchemaPrefix, pageNumber: number): ReadonlyArray<QuestionVariable> {
|
|
164
167
|
const variables: QuestionVariable[] = [];
|
|
165
168
|
|
|
166
169
|
if (this._pageType === "question") {
|
|
167
170
|
const pagePrefix = this.prefix;
|
|
168
|
-
const
|
|
171
|
+
const varId = VarID.create(modulePrefix.value, pagePrefix);
|
|
169
172
|
const label = this.mainText.text;
|
|
170
173
|
const op = this.defaultQuestion.options.map((o) => {
|
|
171
174
|
const label = o.label;
|
|
172
175
|
const value = o.value;
|
|
173
176
|
return new BuilderVariableOption(label, value);
|
|
174
177
|
});
|
|
175
|
-
const singleVar = new QuestionVariable(
|
|
178
|
+
const singleVar = new QuestionVariable(varId, label, op, pageNumber);
|
|
176
179
|
variables.push(singleVar);
|
|
177
180
|
}
|
|
178
181
|
return variables;
|
|
@@ -186,11 +189,11 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
get prefix() {
|
|
189
|
-
return this._prefix;
|
|
192
|
+
return this._prefix.value;
|
|
190
193
|
}
|
|
191
194
|
|
|
192
|
-
set prefix(value:
|
|
193
|
-
this._prefix = value;
|
|
195
|
+
set prefix(value: PagePrefixValue) {
|
|
196
|
+
this._prefix.value = value;
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
toJson(): BuilderPageDto {
|
|
@@ -205,7 +208,7 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
205
208
|
nextButton,
|
|
206
209
|
id: this.id,
|
|
207
210
|
tags: [...this.tags],
|
|
208
|
-
prefix: this._prefix,
|
|
211
|
+
prefix: this._prefix.value,
|
|
209
212
|
defaultQuestion: this.defaultQuestion.toJson(),
|
|
210
213
|
questions,
|
|
211
214
|
};
|
|
@@ -221,7 +224,7 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
221
224
|
const mainTextClone = JSON.parse(JSON.stringify(this.mainText));
|
|
222
225
|
// const pagesClone = this
|
|
223
226
|
const questionsClone = this.questions.map((q) => q.clone());
|
|
224
|
-
const newId =
|
|
227
|
+
const newId = PageID.create();
|
|
225
228
|
const clone: BuilderPageDto = {
|
|
226
229
|
...dto,
|
|
227
230
|
id: newId,
|