@media-quest/builder 0.0.39 → 0.0.41

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.
Files changed (42) hide show
  1. package/dist/public-api.d.ts +82 -100
  2. package/dist/public-api.js +68 -128
  3. package/dist/public-api.js.map +1 -1
  4. package/package.json +29 -29
  5. package/src/{theme → ARKIV}/button-bar/button-text-utils.ts +233 -233
  6. package/src/{theme → ARKIV}/button-bar/text-utils.spec.ts +105 -105
  7. package/src/Builder-option.ts +77 -62
  8. package/src/Builder-question.spec.ts +1 -0
  9. package/src/Builder-question.ts +97 -98
  10. package/src/Builder-schema.spec.ts +348 -348
  11. package/src/Builder-schema.ts +308 -306
  12. package/src/builder-compiler.ts +14 -20
  13. package/src/code-book/codebook-variable.ts +27 -27
  14. package/src/code-book/codebook.ts +89 -89
  15. package/src/media-files.ts +28 -32
  16. package/src/page/Builder-page-collection.spec.ts +224 -219
  17. package/src/page/Builder-page-collection.ts +129 -129
  18. package/src/page/Builder-page.spec.ts +177 -177
  19. package/src/page/Builder-page.ts +250 -250
  20. package/src/primitives/ID.ts +135 -135
  21. package/src/public-api.ts +29 -30
  22. package/src/rulebuilder/RuleAction.ts +105 -105
  23. package/src/schema-config.ts +25 -26
  24. package/src/sum-score/sum-score-variable-collection.spec.ts +68 -68
  25. package/src/sum-score/sum-score-variable-collection.ts +101 -101
  26. package/src/sum-score/sum-score-variable.ts +0 -1
  27. package/src/sum-score/sum-score.ts +166 -167
  28. package/src/tag/BuilderTag.ts +45 -45
  29. package/src/tag/Tag-Collection.ts +53 -53
  30. package/src/theme/Default-theme.ts +173 -188
  31. package/src/theme/IDefault-theme.ts +124 -125
  32. package/src/theme/ThemeCompiler.ts +10 -11
  33. package/src/theme/default-theme-compiler.spec.ts +31 -31
  34. package/src/theme/default-theme-compiler.ts +660 -652
  35. package/src/theme/icon-urls.ts +29 -29
  36. package/src/theme/icons.ts +117 -117
  37. package/src/theme/theme-utils.spec.ts +52 -52
  38. package/src/theme/theme-utils.ts +56 -56
  39. package/src/theme/theme2.ts +399 -386
  40. package/tsconfig.json +19 -19
  41. package/src/Builder-schema-dto.spec.ts +0 -155
  42. package/src/Builder-schema-dto.ts +0 -86
@@ -1,250 +1,250 @@
1
- import type { BuilderQuestionDto, BuilderQuestionType } from "../Builder-question";
2
- import { BuilderQuestion } from "../Builder-question";
3
- import { BuilderObject } from "../BuilderObject";
4
- import type { BuilderOptionDto } from "../Builder-option";
5
- import { BuilderOption } from "../Builder-option";
6
- import type { BuilderMainVideoDto } from "../BuilderMainVideoDto";
7
- import type { BuilderMainImageDto } from "../BuilderMainImageDto";
8
- import type { BuilderMainTextDto } from "../BuilderMainText";
9
- import { BuilderMainText } from "../BuilderMainText";
10
- import { RuleVariableOption, RuleQuestionVariable } from "../rulebuilder";
11
- import { DUtil } from "@media-quest/engine";
12
- import { PagePrefix, PagePrefixValue } from "../primitives/page-prefix";
13
- import { VarID } from "../primitives/varID";
14
- import { SchemaPrefix } from "../primitives/schema-prefix";
15
- import { PageID, SumScoreVariableID } from "../primitives/ID";
16
- import { SumScoreVariable } from "../sum-score/sum-score-variable";
17
-
18
- const U = DUtil;
19
- export type BuilderPageType = "info-page" | "question";
20
-
21
- export interface BuilderPageDto {
22
- readonly id: PageID;
23
- readonly prefix: PagePrefixValue;
24
- _type: BuilderPageType;
25
- mainText: BuilderMainTextDto;
26
- nextButton: BuilderOptionDto;
27
- defaultQuestion: BuilderQuestionDto;
28
- mainMedia?: BuilderMainImageDto | BuilderMainVideoDto;
29
- includedInSumScores: Array<{ sumScoreVariableId: SumScoreVariableID; weight: number }>;
30
- autoplaySequence: Array<string>;
31
- tags: ReadonlyArray<string>;
32
- }
33
-
34
- export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
35
- readonly objectType: "builder-page" = "builder-page";
36
- readonly id: PageID;
37
- private _pageType: BuilderPageType;
38
- private _prefix: PagePrefix;
39
- private readonly _tags: Set<string>;
40
- private _backgroundColor = "#FFFFFF";
41
- private _includedInSumScores: Map<
42
- SumScoreVariableID,
43
- {
44
- sumScoreVariableId: SumScoreVariableID;
45
- weight: number;
46
- name: string;
47
- description: string;
48
- }
49
- > = new Map();
50
-
51
- mainMedia: BuilderMainVideoDto | BuilderMainImageDto | false = false;
52
- defaultQuestion: BuilderQuestion;
53
- mainText: BuilderMainText;
54
- nextButton = BuilderOption.create(-1, "Neste");
55
-
56
- public static create(type: BuilderPageType, _prefix: PagePrefixValue) {
57
- const id = PageID.create();
58
- const mainTextDto: BuilderMainTextDto = {
59
- text: "",
60
- audioFile: false,
61
- autoplay: false,
62
- autoplayDelay: 0,
63
- };
64
- const nextButtonDto = BuilderOption.create(-1, "page-next-button-text").toJson();
65
- const defaultQuestionDto = BuilderQuestion.create("select-one").toJson();
66
-
67
- const dto: BuilderPageDto = {
68
- _type: type,
69
- autoplaySequence: [],
70
- defaultQuestion: defaultQuestionDto,
71
- id,
72
- nextButton: nextButtonDto,
73
- mainText: mainTextDto,
74
- prefix: _prefix,
75
- includedInSumScores: [],
76
- tags: [],
77
- };
78
-
79
- const page = new BuilderPage(dto);
80
- return page;
81
- }
82
- public static fromJson(dto: BuilderPageDto): BuilderPage {
83
- const page = new BuilderPage(dto);
84
- return page;
85
- }
86
-
87
- private constructor(dto: BuilderPageDto) {
88
- super(dto);
89
- this.id = dto.id;
90
- this._pageType = dto._type;
91
- const prefixInstance = PagePrefix.castOrCreateRandom(dto.prefix);
92
- this._prefix = prefixInstance;
93
- this.mainText = BuilderMainText.fromJson(dto.mainText);
94
- this.nextButton = BuilderOption.fromJson(dto.nextButton);
95
- this.defaultQuestion = BuilderQuestion.fromJson(dto.defaultQuestion);
96
- const tagList: string[] = Array.isArray(dto.tags) ? dto.tags : [];
97
- const sumScores = Array.isArray(dto.includedInSumScores) ? dto.includedInSumScores : [];
98
- sumScores.forEach((item) => {
99
- this._includedInSumScores.set(item.sumScoreVariableId, {
100
- sumScoreVariableId: item.sumScoreVariableId,
101
- weight: item.weight,
102
- name: "",
103
- description: "",
104
- });
105
- });
106
- this._tags = new Set(tagList);
107
- if (dto.mainMedia) {
108
- this.mainMedia = dto.mainMedia;
109
- }
110
- }
111
-
112
- public addTag(tag: string) {
113
- this._tags.add(tag);
114
- }
115
- public deleteTag(tag: string) {
116
- this._tags.delete(tag);
117
- }
118
-
119
- set pageType(value: BuilderPageType) {
120
- this._pageType = value;
121
- }
122
-
123
- get includedInSumScores() {
124
- return [...this._includedInSumScores.values()];
125
- }
126
-
127
- getQuestionVariables(
128
- modulePrefix: SchemaPrefix,
129
- pageNumber: number,
130
- ): ReadonlyArray<RuleQuestionVariable> {
131
- const variables: RuleQuestionVariable[] = [];
132
-
133
- if (this._pageType === "question") {
134
- const pagePrefix = this.prefix;
135
- const varId = VarID.create(modulePrefix.value, pagePrefix);
136
- const label = this.mainText.text;
137
- const op = this.defaultQuestion.options.map((o) => {
138
- const label = o.label;
139
- const value = o.value;
140
- return new RuleVariableOption(label, value);
141
- });
142
- const singleVar = new RuleQuestionVariable(varId, label, op, pageNumber);
143
- variables.push(singleVar);
144
- }
145
- return variables;
146
- }
147
-
148
- get tags(): ReadonlyArray<string> {
149
- return [...this._tags];
150
- }
151
- get pageType() {
152
- return this._pageType;
153
- }
154
-
155
- get prefix() {
156
- return this._prefix.value;
157
- }
158
-
159
- set prefix(value: PagePrefixValue) {
160
- this._prefix.value = value;
161
- }
162
-
163
- /** @internal */
164
- sumScoreVariableSet(sumScoreVariable: SumScoreVariable, weight: number) {
165
- const { id, name, description } = sumScoreVariable;
166
-
167
- this._includedInSumScores.set(sumScoreVariable.id, {
168
- sumScoreVariableId: id,
169
- weight,
170
- name,
171
- description,
172
- });
173
-
174
- return true;
175
- }
176
-
177
- /** @internal */
178
- updateRelationShips(variables: ReadonlyArray<SumScoreVariable>) {
179
- variables.forEach((v) => {
180
- const sumScoreEntry = this._includedInSumScores.get(v.id);
181
- if (sumScoreEntry) {
182
- this.sumScoreVariableSet(v, sumScoreEntry.weight);
183
- }
184
- });
185
- }
186
-
187
- toJson(): BuilderPageDto {
188
- const mainText = this.mainText.toJson();
189
- const nextButton = this.nextButton.toJson();
190
- const mainMedia = this.mainMedia;
191
- const includedInSumScores = this.includedInSumScores.map(({ sumScoreVariableId, weight }) => ({
192
- sumScoreVariableId,
193
- weight,
194
- }));
195
- const dto: BuilderPageDto = {
196
- _type: this.pageType,
197
- mainText,
198
- autoplaySequence: [],
199
- nextButton,
200
- id: this.id,
201
- tags: [...this.tags],
202
- includedInSumScores,
203
- prefix: this._prefix.value,
204
- defaultQuestion: this.defaultQuestion.toJson(),
205
- };
206
- if (mainMedia) {
207
- dto.mainMedia = mainMedia;
208
- }
209
- return dto;
210
- }
211
-
212
- clone(): BuilderPageDto {
213
- const dto = this.toJson();
214
- const defaultQuestionClone = this.defaultQuestion.clone();
215
- const mainTextClone = JSON.parse(JSON.stringify(this.mainText));
216
- const newId = PageID.create();
217
- const clone: BuilderPageDto = {
218
- ...dto,
219
- id: newId,
220
- defaultQuestion: defaultQuestionClone,
221
- mainText: mainTextClone,
222
- };
223
- // const cloneDto
224
- return clone;
225
- }
226
-
227
- get backgroundColor() {
228
- return this._backgroundColor;
229
- }
230
-
231
- set backgroundColor(color: string) {
232
- if (typeof color === "string") {
233
- this._backgroundColor = color;
234
- }
235
- }
236
-
237
- /**
238
- * @internal
239
- */
240
- _isIncludedInSumScore(sumScoreId: SumScoreVariableID) {
241
- return this._includedInSumScores.has(sumScoreId);
242
- }
243
-
244
- /**
245
- * @internal
246
- */
247
- sumScoreVariableDelete(sumScoreVariableID: SumScoreVariableID) {
248
- this._includedInSumScores.delete(sumScoreVariableID);
249
- }
250
- }
1
+ import type { BuilderQuestionDto, BuilderQuestionType } from "../Builder-question";
2
+ import { BuilderQuestion } from "../Builder-question";
3
+ import { BuilderObject } from "../BuilderObject";
4
+ import type { BuilderOptionDto } from "../Builder-option";
5
+ import { BuilderOption } from "../Builder-option";
6
+ import type { BuilderMainVideoDto } from "../BuilderMainVideoDto";
7
+ import type { BuilderMainImageDto } from "../BuilderMainImageDto";
8
+ import type { BuilderMainTextDto } from "../BuilderMainText";
9
+ import { BuilderMainText } from "../BuilderMainText";
10
+ import { RuleVariableOption, RuleQuestionVariable } from "../rulebuilder";
11
+ import { DUtil } from "@media-quest/engine";
12
+ import { PagePrefix, PagePrefixValue } from "../primitives/page-prefix";
13
+ import { VarID } from "../primitives/varID";
14
+ import { SchemaPrefix } from "../primitives/schema-prefix";
15
+ import { PageID, SumScoreVariableID } from "../primitives/ID";
16
+ import { SumScoreVariable } from "../sum-score/sum-score-variable";
17
+
18
+ const U = DUtil;
19
+ export type BuilderPageType = "info-page" | "question";
20
+
21
+ export interface BuilderPageDto {
22
+ readonly id: PageID;
23
+ readonly prefix: PagePrefixValue;
24
+ _type: BuilderPageType;
25
+ mainText: BuilderMainTextDto;
26
+ nextButton: BuilderOptionDto;
27
+ defaultQuestion: BuilderQuestionDto;
28
+ mainMedia?: BuilderMainImageDto | BuilderMainVideoDto;
29
+ includedInSumScores: Array<{ sumScoreVariableId: SumScoreVariableID; weight: number }>;
30
+ autoplaySequence: Array<string>;
31
+ tags: ReadonlyArray<string>;
32
+ }
33
+
34
+ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
35
+ readonly objectType: "builder-page" = "builder-page";
36
+ readonly id: PageID;
37
+ private _pageType: BuilderPageType;
38
+ private _prefix: PagePrefix;
39
+ private readonly _tags: Set<string>;
40
+ private _backgroundColor = "#FFFFFF";
41
+ private _includedInSumScores: Map<
42
+ SumScoreVariableID,
43
+ {
44
+ sumScoreVariableId: SumScoreVariableID;
45
+ weight: number;
46
+ name: string;
47
+ description: string;
48
+ }
49
+ > = new Map();
50
+
51
+ mainMedia: BuilderMainVideoDto | BuilderMainImageDto | false = false;
52
+ defaultQuestion: BuilderQuestion;
53
+ mainText: BuilderMainText;
54
+ nextButton = BuilderOption.create(-1, "Neste");
55
+
56
+ public static create(type: BuilderPageType, _prefix: PagePrefixValue) {
57
+ const id = PageID.create();
58
+ const mainTextDto: BuilderMainTextDto = {
59
+ text: "",
60
+ audioFile: false,
61
+ autoplay: false,
62
+ autoplayDelay: 0,
63
+ };
64
+ const nextButtonDto = BuilderOption.create(-1, "page-next-button-text").toJson();
65
+ const defaultQuestionDto = BuilderQuestion.create("select-one").toJson();
66
+
67
+ const dto: BuilderPageDto = {
68
+ _type: type,
69
+ autoplaySequence: [],
70
+ defaultQuestion: defaultQuestionDto,
71
+ id,
72
+ nextButton: nextButtonDto,
73
+ mainText: mainTextDto,
74
+ prefix: _prefix,
75
+ includedInSumScores: [],
76
+ tags: [],
77
+ };
78
+
79
+ const page = new BuilderPage(dto);
80
+ return page;
81
+ }
82
+ public static fromJson(dto: BuilderPageDto): BuilderPage {
83
+ const page = new BuilderPage(dto);
84
+ return page;
85
+ }
86
+
87
+ private constructor(dto: BuilderPageDto) {
88
+ super(dto);
89
+ this.id = dto.id;
90
+ this._pageType = dto._type;
91
+ const prefixInstance = PagePrefix.castOrCreateRandom(dto.prefix);
92
+ this._prefix = prefixInstance;
93
+ this.mainText = BuilderMainText.fromJson(dto.mainText);
94
+ this.nextButton = BuilderOption.fromJson(dto.nextButton);
95
+ this.defaultQuestion = BuilderQuestion.fromJson(dto.defaultQuestion);
96
+ const tagList: string[] = Array.isArray(dto.tags) ? dto.tags : [];
97
+ const sumScores = Array.isArray(dto.includedInSumScores) ? dto.includedInSumScores : [];
98
+ sumScores.forEach((item) => {
99
+ this._includedInSumScores.set(item.sumScoreVariableId, {
100
+ sumScoreVariableId: item.sumScoreVariableId,
101
+ weight: item.weight,
102
+ name: "",
103
+ description: "",
104
+ });
105
+ });
106
+ this._tags = new Set(tagList);
107
+ if (dto.mainMedia) {
108
+ this.mainMedia = dto.mainMedia;
109
+ }
110
+ }
111
+
112
+ public addTag(tag: string) {
113
+ this._tags.add(tag);
114
+ }
115
+ public deleteTag(tag: string) {
116
+ this._tags.delete(tag);
117
+ }
118
+
119
+ set pageType(value: BuilderPageType) {
120
+ this._pageType = value;
121
+ }
122
+
123
+ get includedInSumScores() {
124
+ return [...this._includedInSumScores.values()];
125
+ }
126
+
127
+ getQuestionVariables(
128
+ modulePrefix: SchemaPrefix,
129
+ pageNumber: number,
130
+ ): ReadonlyArray<RuleQuestionVariable> {
131
+ const variables: RuleQuestionVariable[] = [];
132
+
133
+ if (this._pageType === "question") {
134
+ const pagePrefix = this.prefix;
135
+ const varId = VarID.create(modulePrefix.value, pagePrefix);
136
+ const label = this.mainText.text;
137
+ const op = this.defaultQuestion.options.map((o) => {
138
+ const label = o.label;
139
+ const value = o.value;
140
+ return new RuleVariableOption(label, value);
141
+ });
142
+ const singleVar = new RuleQuestionVariable(varId, label, op, pageNumber);
143
+ variables.push(singleVar);
144
+ }
145
+ return variables;
146
+ }
147
+
148
+ get tags(): ReadonlyArray<string> {
149
+ return [...this._tags];
150
+ }
151
+ get pageType() {
152
+ return this._pageType;
153
+ }
154
+
155
+ get prefix() {
156
+ return this._prefix.value;
157
+ }
158
+
159
+ set prefix(value: PagePrefixValue) {
160
+ this._prefix.value = value;
161
+ }
162
+
163
+ /** @internal */
164
+ sumScoreVariableSet(sumScoreVariable: SumScoreVariable, weight: number) {
165
+ const { id, name, description } = sumScoreVariable;
166
+
167
+ this._includedInSumScores.set(sumScoreVariable.id, {
168
+ sumScoreVariableId: id,
169
+ weight,
170
+ name,
171
+ description,
172
+ });
173
+
174
+ return true;
175
+ }
176
+
177
+ /** @internal */
178
+ updateRelationShips(variables: ReadonlyArray<SumScoreVariable>) {
179
+ variables.forEach((v) => {
180
+ const sumScoreEntry = this._includedInSumScores.get(v.id);
181
+ if (sumScoreEntry) {
182
+ this.sumScoreVariableSet(v, sumScoreEntry.weight);
183
+ }
184
+ });
185
+ }
186
+
187
+ toJson(): BuilderPageDto {
188
+ const mainText = this.mainText.toJson();
189
+ const nextButton = this.nextButton.toJson();
190
+ const mainMedia = this.mainMedia;
191
+ const includedInSumScores = this.includedInSumScores.map(({ sumScoreVariableId, weight }) => ({
192
+ sumScoreVariableId,
193
+ weight,
194
+ }));
195
+ const dto: BuilderPageDto = {
196
+ _type: this.pageType,
197
+ mainText,
198
+ autoplaySequence: [],
199
+ nextButton,
200
+ id: this.id,
201
+ tags: [...this.tags],
202
+ includedInSumScores,
203
+ prefix: this._prefix.value,
204
+ defaultQuestion: this.defaultQuestion.toJson(),
205
+ };
206
+ if (mainMedia) {
207
+ dto.mainMedia = mainMedia;
208
+ }
209
+ return dto;
210
+ }
211
+
212
+ clone(): BuilderPageDto {
213
+ const dto = this.toJson();
214
+ const defaultQuestionClone = this.defaultQuestion.clone();
215
+ const mainTextClone = JSON.parse(JSON.stringify(this.mainText));
216
+ const newId = PageID.create();
217
+ const clone: BuilderPageDto = {
218
+ ...dto,
219
+ id: newId,
220
+ defaultQuestion: defaultQuestionClone,
221
+ mainText: mainTextClone,
222
+ };
223
+ // const cloneDto
224
+ return clone;
225
+ }
226
+
227
+ get backgroundColor() {
228
+ return this._backgroundColor;
229
+ }
230
+
231
+ set backgroundColor(color: string) {
232
+ if (typeof color === "string") {
233
+ this._backgroundColor = color;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * @internal
239
+ */
240
+ _isIncludedInSumScore(sumScoreId: SumScoreVariableID) {
241
+ return this._includedInSumScores.has(sumScoreId);
242
+ }
243
+
244
+ /**
245
+ * @internal
246
+ */
247
+ sumScoreVariableDelete(sumScoreVariableID: SumScoreVariableID) {
248
+ this._includedInSumScores.delete(sumScoreVariableID);
249
+ }
250
+ }