@media-quest/builder 0.0.25 → 0.0.27
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.ts +819 -0
- package/dist/public-api.js +2696 -0
- package/dist/public-api.js.map +1 -0
- package/package.json +20 -6
- package/src/Builder-option.ts +64 -64
- package/src/Builder-question.spec.ts +68 -68
- package/src/Builder-question.ts +98 -102
- package/src/Builder-schema.spec.ts +135 -144
- package/src/Builder-schema.ts +70 -69
- package/src/Builder-text.spec.ts +24 -24
- package/src/Builder-text.ts +57 -57
- package/src/BuilderObject.ts +30 -29
- package/src/builder-compiler.ts +1 -1
- package/src/code-book/codebook-variable.ts +27 -0
- package/src/code-book/codebook.ts +81 -0
- package/src/page/Builder-page-collection.spec.ts +209 -0
- package/src/page/Builder-page-collection.ts +113 -0
- package/src/page/Builder-page.spec.ts +163 -0
- package/src/{Builder-page.ts → page/Builder-page.ts} +74 -95
- package/src/primitives/ID.spec.ts +39 -39
- package/src/primitives/ID.ts +26 -10
- package/src/primitives/page-prefix.ts +59 -59
- package/src/primitives/varID.ts +12 -12
- package/src/public-api.ts +8 -6
- package/src/rulebuilder/Builder-rule.spec.ts +323 -323
- package/src/rulebuilder/Builder-rule.ts +191 -191
- package/src/rulebuilder/RuleAction.ts +105 -106
- package/src/rulebuilder/RuleBuilder-test-utils.ts +320 -320
- package/src/rulebuilder/RuleInput.ts +30 -30
- package/src/rulebuilder/RuleVariable.ts +34 -48
- package/src/rulebuilder/SingleSelectItem.ts +9 -8
- package/src/rulebuilder/condition/Builder-condition-group.ts +14 -6
- package/src/rulebuilder/condition/Builder-condition.spec.ts +12 -12
- package/src/rulebuilder/condition/Builder-condition.ts +17 -13
- package/src/rulebuilder/index.ts +16 -3
- package/src/rulebuilder/page-action-manager.ts +33 -33
- package/src/rulebuilder/rule2/Rule2.ts +211 -215
- package/src/schema-config.ts +25 -25
- package/src/sum-score/sum-score-answer.ts +6 -0
- package/src/sum-score/sum-score-variable-collection.spec.ts +68 -0
- package/src/sum-score/sum-score-variable-collection.ts +101 -0
- package/src/sum-score/sum-score-variable.spec.ts +253 -0
- package/src/sum-score/sum-score-variable.ts +98 -0
- package/src/{variable → sum-score}/sum-score.ts +57 -26
- package/src/tag/BuilderTag.ts +45 -0
- package/src/tag/Tag-Collection.ts +53 -0
- package/src/theme/default-theme-compiler.ts +358 -358
- package/tsconfig.json +19 -15
- package/src/Builder-page.spec.ts +0 -320
- package/src/BuilderTag.ts +0 -96
- package/src/codebook.ts +0 -72
- package/src/variable/b-variable.ts +0 -68
- package/src/variable/mq-variable.spec.ts +0 -147
- package/src/variable/sum-score-variable.ts +0 -50
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import type { BuilderQuestionDto } from "./Builder-question";
|
|
2
|
-
import { BuilderQuestion } from "./Builder-question";
|
|
3
|
-
import { OptionID, QuestionID } from "./primitives/ID";
|
|
4
|
-
|
|
5
|
-
const question1: BuilderQuestionDto = {
|
|
6
|
-
id: QuestionID.validateOrThrow("id-for-question-1"),
|
|
7
|
-
prefix: "q1",
|
|
8
|
-
text: "sadf",
|
|
9
|
-
options: [],
|
|
10
|
-
_type: "select-one",
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const question2: BuilderQuestionDto = {
|
|
14
|
-
id: QuestionID.validateOrThrow("id-for-question-2"),
|
|
15
|
-
prefix: "a",
|
|
16
|
-
text: "har du..",
|
|
17
|
-
_type: "select-one",
|
|
18
|
-
// options: []
|
|
19
|
-
options: [
|
|
20
|
-
{
|
|
21
|
-
id: "q3-opt1" as OptionID,
|
|
22
|
-
value: 0,
|
|
23
|
-
label: "Nei",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
id: "q3-opt2" as OptionID,
|
|
27
|
-
value: 1,
|
|
28
|
-
label: "Ja",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id: "q3-opt3" as OptionID,
|
|
32
|
-
value: 9,
|
|
33
|
-
label: "Vet ikke",
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
describe("Builder Question", () => {
|
|
39
|
-
test("Can create question from json", () => {
|
|
40
|
-
const q1 = BuilderQuestion.fromJson(question1);
|
|
41
|
-
const q1AsJson = q1.toJson();
|
|
42
|
-
expect(question1).toStrictEqual(q1AsJson);
|
|
43
|
-
const q2Instance = BuilderQuestion.fromJson(question2);
|
|
44
|
-
const q2AsJson = q2Instance.toJson();
|
|
45
|
-
expect(question2).toStrictEqual(q2AsJson);
|
|
46
|
-
});
|
|
47
|
-
test("Can add options", () => {
|
|
48
|
-
const q1 = BuilderQuestion.fromJson(question1);
|
|
49
|
-
expect(q1.options.length).toBe(0);
|
|
50
|
-
q1.addOption("Ja", 1);
|
|
51
|
-
expect(q1.options.length).toBe(1);
|
|
52
|
-
const nei = q1.addOption("Nei", 0, 0);
|
|
53
|
-
expect(q1.options.length).toBe(2);
|
|
54
|
-
expect(q1.options[0]).toBe(nei);
|
|
55
|
-
const vetIkke = q1.addOption("Vet-ikke", 9);
|
|
56
|
-
expect(q1.options.length).toBe(3);
|
|
57
|
-
expect(q1.options[2]).toBe(vetIkke);
|
|
58
|
-
});
|
|
59
|
-
test("Can delete options", () => {
|
|
60
|
-
const q = BuilderQuestion.fromJson(question2);
|
|
61
|
-
expect(q.options.length).toBe(3);
|
|
62
|
-
const o1 = q.options[0];
|
|
63
|
-
const o2 = q.options[1];
|
|
64
|
-
const o3 = q.options[2];
|
|
65
|
-
const didDelete = q.deleteOption(o1);
|
|
66
|
-
expect(q.options.length).toBe(2);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
1
|
+
import type { BuilderQuestionDto } from "./Builder-question";
|
|
2
|
+
import { BuilderQuestion } from "./Builder-question";
|
|
3
|
+
import { OptionID, QuestionID } from "./primitives/ID";
|
|
4
|
+
|
|
5
|
+
const question1: BuilderQuestionDto = {
|
|
6
|
+
id: QuestionID.validateOrThrow("id-for-question-1"),
|
|
7
|
+
prefix: "q1",
|
|
8
|
+
text: "sadf",
|
|
9
|
+
options: [],
|
|
10
|
+
_type: "select-one",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const question2: BuilderQuestionDto = {
|
|
14
|
+
id: QuestionID.validateOrThrow("id-for-question-2"),
|
|
15
|
+
prefix: "a",
|
|
16
|
+
text: "har du..",
|
|
17
|
+
_type: "select-one",
|
|
18
|
+
// options: []
|
|
19
|
+
options: [
|
|
20
|
+
{
|
|
21
|
+
id: "q3-opt1" as OptionID,
|
|
22
|
+
value: 0,
|
|
23
|
+
label: "Nei",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "q3-opt2" as OptionID,
|
|
27
|
+
value: 1,
|
|
28
|
+
label: "Ja",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "q3-opt3" as OptionID,
|
|
32
|
+
value: 9,
|
|
33
|
+
label: "Vet ikke",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe("Builder Question", () => {
|
|
39
|
+
test("Can create question from json", () => {
|
|
40
|
+
const q1 = BuilderQuestion.fromJson(question1);
|
|
41
|
+
const q1AsJson = q1.toJson();
|
|
42
|
+
expect(question1).toStrictEqual(q1AsJson);
|
|
43
|
+
const q2Instance = BuilderQuestion.fromJson(question2);
|
|
44
|
+
const q2AsJson = q2Instance.toJson();
|
|
45
|
+
expect(question2).toStrictEqual(q2AsJson);
|
|
46
|
+
});
|
|
47
|
+
test("Can add options", () => {
|
|
48
|
+
const q1 = BuilderQuestion.fromJson(question1);
|
|
49
|
+
expect(q1.options.length).toBe(0);
|
|
50
|
+
q1.addOption("Ja", 1);
|
|
51
|
+
expect(q1.options.length).toBe(1);
|
|
52
|
+
const nei = q1.addOption("Nei", 0, 0);
|
|
53
|
+
expect(q1.options.length).toBe(2);
|
|
54
|
+
expect(q1.options[0]).toBe(nei);
|
|
55
|
+
const vetIkke = q1.addOption("Vet-ikke", 9);
|
|
56
|
+
expect(q1.options.length).toBe(3);
|
|
57
|
+
expect(q1.options[2]).toBe(vetIkke);
|
|
58
|
+
});
|
|
59
|
+
test("Can delete options", () => {
|
|
60
|
+
const q = BuilderQuestion.fromJson(question2);
|
|
61
|
+
expect(q.options.length).toBe(3);
|
|
62
|
+
const o1 = q.options[0];
|
|
63
|
+
const o2 = q.options[1];
|
|
64
|
+
const o3 = q.options[2];
|
|
65
|
+
const didDelete = q.deleteOption(o1);
|
|
66
|
+
expect(q.options.length).toBe(2);
|
|
67
|
+
});
|
|
68
|
+
});
|
package/src/Builder-question.ts
CHANGED
|
@@ -1,102 +1,98 @@
|
|
|
1
|
-
import type { BuilderOptionDto } from "./Builder-option";
|
|
2
|
-
import { BuilderOption } from "./Builder-option";
|
|
3
|
-
import { BuilderObject } from "./BuilderObject";
|
|
4
|
-
import { QuestionID } from "./primitives/ID";
|
|
5
|
-
|
|
6
|
-
export type BuilderQuestionType =
|
|
7
|
-
| "select-one"
|
|
8
|
-
| "select-many"
|
|
9
|
-
| "text"
|
|
10
|
-
| "
|
|
11
|
-
| "
|
|
12
|
-
| "
|
|
13
|
-
| "
|
|
14
|
-
| "
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
return clonedDto;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
import type { BuilderOptionDto } from "./Builder-option";
|
|
2
|
+
import { BuilderOption } from "./Builder-option";
|
|
3
|
+
import { BuilderObject } from "./BuilderObject";
|
|
4
|
+
import { QuestionID } from "./primitives/ID";
|
|
5
|
+
|
|
6
|
+
export type BuilderQuestionType =
|
|
7
|
+
| "select-one"
|
|
8
|
+
| "select-many"
|
|
9
|
+
| "text"
|
|
10
|
+
| "time"
|
|
11
|
+
| "textarea"
|
|
12
|
+
| "date"
|
|
13
|
+
| "numeric-range"
|
|
14
|
+
| "duration";
|
|
15
|
+
|
|
16
|
+
export interface BuilderQuestionDto {
|
|
17
|
+
readonly id: QuestionID;
|
|
18
|
+
_type: BuilderQuestionType;
|
|
19
|
+
text: string;
|
|
20
|
+
options: ReadonlyArray<BuilderOptionDto>;
|
|
21
|
+
prefix: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class BuilderQuestion extends BuilderObject<"builder-question", BuilderQuestionDto> {
|
|
25
|
+
readonly objectType = "builder-question";
|
|
26
|
+
id: QuestionID;
|
|
27
|
+
type: BuilderQuestionType;
|
|
28
|
+
questionText = "";
|
|
29
|
+
options: BuilderOption[] = [];
|
|
30
|
+
prefix = "";
|
|
31
|
+
|
|
32
|
+
static create = (type: BuilderQuestionType) => {
|
|
33
|
+
const id = QuestionID.create();
|
|
34
|
+
|
|
35
|
+
return new BuilderQuestion({
|
|
36
|
+
id,
|
|
37
|
+
_type: type,
|
|
38
|
+
text: "",
|
|
39
|
+
options: [],
|
|
40
|
+
prefix: "",
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
|
|
45
|
+
const question = new BuilderQuestion(dto);
|
|
46
|
+
return question;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private constructor(dto: BuilderQuestionDto) {
|
|
50
|
+
super(dto);
|
|
51
|
+
this.id = QuestionID.validateOrCreate(dto.id);
|
|
52
|
+
this.type = dto._type;
|
|
53
|
+
this.questionText = dto.text;
|
|
54
|
+
this.prefix = dto.prefix;
|
|
55
|
+
this.options = dto.options.map((o) => BuilderOption.fromJson(o));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
addOption(label: string, value: number, atIndex = -1) {
|
|
59
|
+
const option = BuilderOption.create(value, label);
|
|
60
|
+
if (atIndex >= 0 && atIndex < this.options.length) {
|
|
61
|
+
this.options.splice(atIndex, 0, option);
|
|
62
|
+
} else {
|
|
63
|
+
this.options.push(option);
|
|
64
|
+
}
|
|
65
|
+
return option;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
deleteOption(option: BuilderOption): boolean {
|
|
69
|
+
const filtered = this.options.filter((o) => o.id !== option.id);
|
|
70
|
+
const didDelete = filtered.length === this.options.length - 1;
|
|
71
|
+
this.options = filtered;
|
|
72
|
+
return didDelete;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
toJson() {
|
|
76
|
+
const optionsJson = this.options.map((o) => o.toJson());
|
|
77
|
+
const dto: BuilderQuestionDto = {
|
|
78
|
+
id: this.id,
|
|
79
|
+
prefix: this.prefix,
|
|
80
|
+
_type: this.type,
|
|
81
|
+
text: this.questionText,
|
|
82
|
+
options: optionsJson,
|
|
83
|
+
};
|
|
84
|
+
return dto;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
clone(): BuilderQuestionDto {
|
|
88
|
+
const cloneId = QuestionID.create();
|
|
89
|
+
const dto = this.toJson();
|
|
90
|
+
const optionsClone = this.options.map((o) => o.clone());
|
|
91
|
+
const clonedDto: BuilderQuestionDto = {
|
|
92
|
+
...dto,
|
|
93
|
+
id: cloneId,
|
|
94
|
+
options: optionsClone,
|
|
95
|
+
};
|
|
96
|
+
return clonedDto;
|
|
97
|
+
}
|
|
98
|
+
}
|