@media-quest/builder 0.0.22 → 0.0.23
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/package.json +1 -1
- package/src/Builder-option.ts +66 -66
- package/src/Builder-page.spec.ts +320 -320
- package/src/Builder-page.ts +257 -257
- package/src/Builder-question.spec.ts +68 -68
- package/src/Builder-question.ts +101 -101
- package/src/Builder-schema.spec.ts +357 -306
- package/src/Builder-schema.ts +287 -254
- package/src/Builder-text.spec.ts +24 -24
- package/src/Builder-text.ts +57 -57
- package/src/BuilderMainImageDto.ts +7 -7
- package/src/BuilderMainText.ts +81 -81
- package/src/BuilderMainVideoDto.ts +10 -10
- package/src/BuilderObject.ts +61 -61
- package/src/BuilderTag.ts +97 -97
- package/src/builder-compiler.ts +14 -0
- package/src/codebook.ts +72 -72
- package/src/media-files.ts +28 -28
- package/src/primitives/page-prefix.ts +58 -58
- package/src/primitives/prefix.spec.ts +5 -5
- package/src/primitives/schema-prefix.ts +52 -52
- package/src/primitives/varID.ts +11 -11
- package/src/public-api.ts +3 -1
- package/src/rulebuilder/Builder-rule.spec.ts +322 -322
- package/src/rulebuilder/Builder-rule.ts +190 -190
- package/src/rulebuilder/RuleAction.ts +106 -106
- package/src/rulebuilder/RuleBuilder-test-utils.ts +316 -316
- package/src/rulebuilder/RuleInput.ts +44 -44
- package/src/rulebuilder/RuleVariable.ts +49 -49
- package/src/rulebuilder/SingleSelectItem.ts +135 -135
- package/src/rulebuilder/condition/Builder-condition-group.spec.ts +47 -47
- package/src/rulebuilder/condition/Builder-condition-group.ts +118 -118
- package/src/rulebuilder/condition/Builder-condition.spec.ts +195 -195
- package/src/rulebuilder/condition/Builder-condition.ts +208 -208
- package/src/rulebuilder/condition/Builder-operator.spec.ts +9 -9
- package/src/rulebuilder/condition/Builder-operator.ts +31 -31
- package/src/rulebuilder/index.ts +22 -22
- package/src/rulebuilder/jump-to-action-manager.ts +33 -33
- package/src/rulebuilder/multi-select-item.ts +73 -73
- package/src/rulebuilder/page-action-manager.ts +31 -31
- package/src/rulebuilder/rule2/Rule2.ts +211 -211
- package/src/rulebuilder/tag-action-manager.spec.ts +44 -44
- package/src/rulebuilder/tag-action-manager.ts +28 -28
- package/src/schema-config.ts +25 -25
- package/src/theme/AbstractThemeCompiler.ts +7 -7
- package/src/theme/IDefaultTheme.ts +226 -226
- package/src/theme/css-theme.ts +7 -7
- package/src/theme/default-theme-compiler.ts +358 -358
- package/src/theme/icon-urls.ts +29 -29
- package/src/theme/theme-utils.ts +57 -57
- package/src/theme/theme1.spec.ts +52 -52
- package/src/variable/mq-variable.spec.ts +91 -0
- package/src/{mq-variable.ts → variable/mq-variable.ts} +63 -61
- package/src/variable/sum-score-variable.ts +56 -0
- package/tsconfig.json +15 -15
- package/tsconfig.tsbuildinfo +1 -1
package/src/Builder-schema.ts
CHANGED
|
@@ -1,254 +1,287 @@
|
|
|
1
|
-
import type { BuilderPageDto, BuilderPageType } from "./Builder-page";
|
|
2
|
-
import { BuilderPage } from "./Builder-page";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { BuilderRule } from "./rulebuilder";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
readonly
|
|
29
|
-
readonly
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
32
|
-
readonly
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
schema.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
1
|
+
import type { BuilderPageDto, BuilderPageType } from "./Builder-page";
|
|
2
|
+
import { BuilderPage } from "./Builder-page";
|
|
3
|
+
import type {
|
|
4
|
+
BuilderRuleDto,
|
|
5
|
+
CustomVariable,
|
|
6
|
+
ExcludeByPageAction,
|
|
7
|
+
ExcludeByTagAction,
|
|
8
|
+
JumpToPageAction,
|
|
9
|
+
} from "./rulebuilder";
|
|
10
|
+
import { BuilderRule, RuleInput } from "./rulebuilder";
|
|
11
|
+
import type { QuestionVariable } from "./rulebuilder/RuleVariable";
|
|
12
|
+
import type { BuilderTagDto } from "./BuilderTag";
|
|
13
|
+
import { BuilderTag, TagCollection } from "./BuilderTag";
|
|
14
|
+
import { DefaultThemeCompiler } from "./theme/default-theme-compiler";
|
|
15
|
+
import { ImageFile } from "./media-files";
|
|
16
|
+
import { DUtil, SchemaID } from "@media-quest/engine";
|
|
17
|
+
import { PagePrefix } from "./primitives/page-prefix";
|
|
18
|
+
import { SchemaPrefix, SchemaPrefixValue } from "./primitives/schema-prefix";
|
|
19
|
+
import { CodeBook } from "./codebook";
|
|
20
|
+
import { PredefinedVariable } from "./variable/mq-variable";
|
|
21
|
+
import { SchemaConfig } from "./schema-config";
|
|
22
|
+
import { CompilerOption, CompilerOutput } from "./builder-compiler";
|
|
23
|
+
import { SumScoreVariable } from "./variable/sum-score-variable";
|
|
24
|
+
|
|
25
|
+
const U = DUtil;
|
|
26
|
+
|
|
27
|
+
export interface BuilderSchemaDto {
|
|
28
|
+
readonly id: SchemaID;
|
|
29
|
+
readonly prefix: SchemaPrefixValue;
|
|
30
|
+
readonly mainImage: ImageFile | false;
|
|
31
|
+
readonly backgroundColor: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly pages: BuilderPageDto[];
|
|
34
|
+
readonly baseHeight: number;
|
|
35
|
+
readonly baseWidth: number;
|
|
36
|
+
readonly predefinedVariables?: Array<PredefinedVariable>;
|
|
37
|
+
readonly sumScoreVariables?: Array<SumScoreVariable>;
|
|
38
|
+
readonly rules: ReadonlyArray<BuilderRuleDto>;
|
|
39
|
+
readonly tags: ReadonlyArray<BuilderTagDto>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class SumScoreVariableCollection {
|
|
43
|
+
private _all:Array<SumScoreVariable> = []
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class BuilderSchema {
|
|
48
|
+
readonly prefix: SchemaPrefix;
|
|
49
|
+
baseHeight = 1300;
|
|
50
|
+
baseWidth = 1024;
|
|
51
|
+
backgroundColor = "#000000";
|
|
52
|
+
pages: BuilderPage[] = [];
|
|
53
|
+
mainImage: ImageFile | false = false;
|
|
54
|
+
predefinedVariables: PredefinedVariable[] = [];
|
|
55
|
+
private _rules: BuilderRule[] = [];
|
|
56
|
+
private _sumVariables: SumScoreVariable[] = [];
|
|
57
|
+
get rules(): ReadonlyArray<BuilderRule> {
|
|
58
|
+
return [...this._rules];
|
|
59
|
+
}
|
|
60
|
+
get sumScoreVariables(): ReadonlyArray<SumScoreVariable> {
|
|
61
|
+
return [...this._sumVariables];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// get prefix(): SchemaPrefixValue {
|
|
65
|
+
// return this._prefix.value;
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
private readonly _tagCollection: TagCollection = TagCollection.create();
|
|
69
|
+
get tags(): ReadonlyArray<BuilderTag> {
|
|
70
|
+
return [...this._tagCollection];
|
|
71
|
+
}
|
|
72
|
+
public static create(id: SchemaID, name: string, prefix: SchemaPrefixValue) {
|
|
73
|
+
const schemaPrefix = SchemaPrefix.castOrCreateRandom(prefix);
|
|
74
|
+
return new BuilderSchema(id, name, schemaPrefix);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static fromJson(dto: BuilderSchemaDto): BuilderSchema {
|
|
78
|
+
const schemaPrefix = SchemaPrefix.castOrCreateRandom(dto.prefix);
|
|
79
|
+
const schema = new BuilderSchema(dto.id, dto.name, schemaPrefix);
|
|
80
|
+
const pages = dto.pages.map(BuilderPage.fromJson);
|
|
81
|
+
schema._tagCollection.init(dto.tags);
|
|
82
|
+
schema.backgroundColor = dto.backgroundColor;
|
|
83
|
+
schema.baseHeight = dto.baseHeight;
|
|
84
|
+
schema.baseWidth = dto.baseWidth;
|
|
85
|
+
schema.pages = pages;
|
|
86
|
+
schema.predefinedVariables = dto.predefinedVariables ?? [];
|
|
87
|
+
schema.backgroundColor = dto.backgroundColor;
|
|
88
|
+
schema.mainImage = dto.mainImage ?? false;
|
|
89
|
+
const rulesDto = dto.rules ?? [];
|
|
90
|
+
const ruleInput = schema.getRuleInput();
|
|
91
|
+
schema._rules = rulesDto.map((r) => BuilderRule.fromDto(r, ruleInput));
|
|
92
|
+
return schema;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
toJson(): BuilderSchemaDto {
|
|
96
|
+
const pages = this.pages.map((p) => p.toJson());
|
|
97
|
+
const tags = this._tagCollection.toJson();
|
|
98
|
+
const rules = this._rules.map((rule) => rule.toJson());
|
|
99
|
+
|
|
100
|
+
const dto: BuilderSchemaDto = {
|
|
101
|
+
backgroundColor: this.backgroundColor,
|
|
102
|
+
baseHeight: this.baseHeight,
|
|
103
|
+
baseWidth: this.baseWidth,
|
|
104
|
+
id: this.id,
|
|
105
|
+
name: this.name,
|
|
106
|
+
pages,
|
|
107
|
+
rules,
|
|
108
|
+
tags,
|
|
109
|
+
predefinedVariables: this.predefinedVariables,
|
|
110
|
+
mainImage: this.mainImage,
|
|
111
|
+
prefix: this.prefix.value,
|
|
112
|
+
};
|
|
113
|
+
return dto;
|
|
114
|
+
}
|
|
115
|
+
private constructor(
|
|
116
|
+
public readonly id: SchemaID,
|
|
117
|
+
public name: string,
|
|
118
|
+
prefix: SchemaPrefix,
|
|
119
|
+
) {
|
|
120
|
+
this.prefix = prefix;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addPage(type: BuilderPageType, atIndex = -1): BuilderPage {
|
|
124
|
+
const pagePrefix = PagePrefix.create();
|
|
125
|
+
const newPage = BuilderPage.create(type, pagePrefix.value);
|
|
126
|
+
if (atIndex >= 0 && atIndex < this.pages.length) {
|
|
127
|
+
this.pages.splice(atIndex, 0, newPage);
|
|
128
|
+
} else {
|
|
129
|
+
this.pages.push(newPage);
|
|
130
|
+
}
|
|
131
|
+
return newPage;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
addSumScoreVariable(variable: SumScoreVariable) {
|
|
135
|
+
// TODO VALIDATE.
|
|
136
|
+
this._sumVariables.push({ ...variable });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
insertPage(page: BuilderPage, atIndex: number): boolean {
|
|
140
|
+
return this.insertPageAtIndex(page, atIndex);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private insertPageAtIndex(page: BuilderPage, atIndex: number) {
|
|
144
|
+
const isValidIndex = U.isInRange(0, this.pages.length - 1);
|
|
145
|
+
if (!isValidIndex(atIndex)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
const exists = !!this.pages.find((p) => p.id === page.id);
|
|
149
|
+
if (exists) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
this.pages.splice(atIndex, 0, page);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
addRule() {
|
|
157
|
+
const input = this.getRuleInput();
|
|
158
|
+
const count = this._rules.length + 1;
|
|
159
|
+
const name = "Rule-number: " + count;
|
|
160
|
+
const rule = BuilderRule.fromDto(
|
|
161
|
+
{
|
|
162
|
+
conditions: [],
|
|
163
|
+
type: "all",
|
|
164
|
+
name,
|
|
165
|
+
excludeTags: [],
|
|
166
|
+
jumpToPage: false,
|
|
167
|
+
excludePages: [],
|
|
168
|
+
},
|
|
169
|
+
input,
|
|
170
|
+
);
|
|
171
|
+
this._rules.push(rule);
|
|
172
|
+
return rule;
|
|
173
|
+
}
|
|
174
|
+
deleteRule(rule: BuilderRule) {
|
|
175
|
+
this._rules = this._rules.filter((r) => r !== rule);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
movePage(page: BuilderPage, toIndex: number): boolean {
|
|
179
|
+
const index = this.pages.indexOf(page);
|
|
180
|
+
if (index < 0) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const isValidIndex = U.isInRange(0, this.pages.length - 1);
|
|
184
|
+
if (!isValidIndex(toIndex)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
// console.log('Moving from :' + index + ' to: ' + toIndex);
|
|
188
|
+
this.pages.splice(index, 1);
|
|
189
|
+
this.pages.splice(toIndex, 0, page);
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
deletePage(page: BuilderPage): boolean {
|
|
194
|
+
const filtered = this.pages.filter((p) => p !== page);
|
|
195
|
+
const didDelete = filtered.length === this.pages.length - 1;
|
|
196
|
+
this.pages = filtered;
|
|
197
|
+
return didDelete;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
reevaluateRules() {
|
|
201
|
+
console.log("Reevaluationg rulesInput");
|
|
202
|
+
const input = this.getRuleInput();
|
|
203
|
+
const rulesDto = this._rules.map((r) => r.toJson());
|
|
204
|
+
this._rules = rulesDto.map((dto) => BuilderRule.fromDto(dto, input));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getRuleInput(): RuleInput {
|
|
208
|
+
const qVars: QuestionVariable[] = [];
|
|
209
|
+
const cVars: CustomVariable[] = [];
|
|
210
|
+
const pageIdActions: ExcludeByPageAction[] = [];
|
|
211
|
+
const tagActions: ExcludeByTagAction[] = this.tags.map((t) => {
|
|
212
|
+
const tag = t.tagText;
|
|
213
|
+
const pageCount = this.pages.reduce((count, curr) => {
|
|
214
|
+
return curr.tags.includes(tag) ? count + 1 : count;
|
|
215
|
+
}, 0);
|
|
216
|
+
const excludeByTagDto: ExcludeByTagAction = {
|
|
217
|
+
kind: "exclude-by-tag",
|
|
218
|
+
pageCount,
|
|
219
|
+
tag,
|
|
220
|
+
description: t.tagDescription,
|
|
221
|
+
};
|
|
222
|
+
return excludeByTagDto;
|
|
223
|
+
});
|
|
224
|
+
const jumpActions: JumpToPageAction[] = [];
|
|
225
|
+
this.pages.forEach((page, index) => {
|
|
226
|
+
const pageVariables = page.getQuestionVariables(this.prefix, index);
|
|
227
|
+
qVars.push(...pageVariables);
|
|
228
|
+
const mainText = page.mainText.text;
|
|
229
|
+
const pagePrefix = page.prefix;
|
|
230
|
+
const jumpAction: JumpToPageAction = {
|
|
231
|
+
kind: "jump-to-page",
|
|
232
|
+
pageId: page.id,
|
|
233
|
+
pagePrefix,
|
|
234
|
+
pageNumber: index,
|
|
235
|
+
mainText: page.mainText.text,
|
|
236
|
+
};
|
|
237
|
+
const excludePageAction: ExcludeByPageAction = {
|
|
238
|
+
kind: "exclude-by-pageId",
|
|
239
|
+
pageId: page.id,
|
|
240
|
+
pagePrefix,
|
|
241
|
+
pageNumber: index,
|
|
242
|
+
mainText,
|
|
243
|
+
};
|
|
244
|
+
jumpActions.push(jumpAction);
|
|
245
|
+
pageIdActions.push(excludePageAction);
|
|
246
|
+
});
|
|
247
|
+
const ruleInput = new RuleInput(qVars, cVars, pageIdActions, tagActions, jumpActions);
|
|
248
|
+
|
|
249
|
+
return ruleInput;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
deleteTags(tags: ReadonlyArray<BuilderTag>) {
|
|
253
|
+
this._tagCollection.deleteAll(tags);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
addTag(builderTag: BuilderTag) {
|
|
257
|
+
this._tagCollection.add(builderTag);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
compile(
|
|
261
|
+
options: CompilerOption = { blockAutoplayQuestion: false, blockAutoplayVideo: false },
|
|
262
|
+
): CompilerOutput {
|
|
263
|
+
// const moduleDto = this.toJson();
|
|
264
|
+
const builderSchema = BuilderSchema.fromJson(this.toJson());
|
|
265
|
+
|
|
266
|
+
// Overriding the
|
|
267
|
+
builderSchema.pages.forEach((p) => {
|
|
268
|
+
if (options.blockAutoplayQuestion) {
|
|
269
|
+
p.mainText.autoplay = false;
|
|
270
|
+
}
|
|
271
|
+
if (options.blockAutoplayVideo && p.mainMedia) {
|
|
272
|
+
if (p.mainMedia.kind === "main-video") {
|
|
273
|
+
// TODO autoplay as boolean, so that we know if video is optional or required when override.
|
|
274
|
+
p.mainMedia.mode = "optional";
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
const moduleDto = builderSchema.toJson();
|
|
279
|
+
const imp = new DefaultThemeCompiler();
|
|
280
|
+
|
|
281
|
+
const codebook = CodeBook.fromSchema(moduleDto);
|
|
282
|
+
const schema = imp.compile(moduleDto);
|
|
283
|
+
const schemaConfig = SchemaConfig.fromSchema(moduleDto);
|
|
284
|
+
const output: CompilerOutput = { codebook, schema, schemaConfig };
|
|
285
|
+
return output;
|
|
286
|
+
}
|
|
287
|
+
}
|
package/src/Builder-text.spec.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { BuilderTextDto } from "./Builder-text";
|
|
2
|
-
import { BuilderText } from "./Builder-text";
|
|
3
|
-
import type { BuilderObjectId } from "./BuilderObject";
|
|
4
|
-
|
|
5
|
-
const textDto: BuilderTextDto = {
|
|
6
|
-
id: "dto1" as BuilderObjectId.TextID,
|
|
7
|
-
name: "dto1-name",
|
|
8
|
-
text: "text one",
|
|
9
|
-
translationRequired: true,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
let text1 = BuilderText.create("text one created");
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
text1 = BuilderText.create("text one created");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("Builder Text", () => {
|
|
19
|
-
test("Can serialize", () => {
|
|
20
|
-
const instance1 = BuilderText.fromJson(textDto);
|
|
21
|
-
const json = instance1.toJson();
|
|
22
|
-
expect(textDto).toStrictEqual(json);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
1
|
+
import type { BuilderTextDto } from "./Builder-text";
|
|
2
|
+
import { BuilderText } from "./Builder-text";
|
|
3
|
+
import type { BuilderObjectId } from "./BuilderObject";
|
|
4
|
+
|
|
5
|
+
const textDto: BuilderTextDto = {
|
|
6
|
+
id: "dto1" as BuilderObjectId.TextID,
|
|
7
|
+
name: "dto1-name",
|
|
8
|
+
text: "text one",
|
|
9
|
+
translationRequired: true,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
let text1 = BuilderText.create("text one created");
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
text1 = BuilderText.create("text one created");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("Builder Text", () => {
|
|
19
|
+
test("Can serialize", () => {
|
|
20
|
+
const instance1 = BuilderText.fromJson(textDto);
|
|
21
|
+
const json = instance1.toJson();
|
|
22
|
+
expect(textDto).toStrictEqual(json);
|
|
23
|
+
});
|
|
24
|
+
});
|