@media-quest/builder 0.0.22 → 0.0.24
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 +51 -0
- package/src/Builder-schema.ts +47 -15
- 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 +146 -0
- package/src/{mq-variable.ts → variable/mq-variable.ts} +8 -1
- package/src/variable/sum-score.ts +138 -0
- package/tsconfig.json +15 -15
- package/tsconfig.tsbuildinfo +1 -1
package/src/Builder-question.ts
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import type { BuilderOptionDto } from "./Builder-option";
|
|
2
|
-
import { BuilderOption } from "./Builder-option";
|
|
3
|
-
import { BuilderObject, BuilderObjectId } from "./BuilderObject";
|
|
4
|
-
|
|
5
|
-
export type BuilderQuestionType =
|
|
6
|
-
| "select-one"
|
|
7
|
-
| "select-many"
|
|
8
|
-
| "text"
|
|
9
|
-
| "color"
|
|
10
|
-
| "radio"
|
|
11
|
-
| "email"
|
|
12
|
-
| "time"
|
|
13
|
-
| "checkbox"
|
|
14
|
-
| "textarea"
|
|
15
|
-
| "date"
|
|
16
|
-
| "numeric-range"
|
|
17
|
-
| "duration";
|
|
18
|
-
|
|
19
|
-
export interface BuilderQuestionDto {
|
|
20
|
-
readonly id: BuilderObjectId.QuestionID;
|
|
21
|
-
_type: BuilderQuestionType;
|
|
22
|
-
text: string;
|
|
23
|
-
options: ReadonlyArray<BuilderOptionDto>;
|
|
24
|
-
prefix: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class BuilderQuestion extends BuilderObject<"builder-question", BuilderQuestionDto> {
|
|
28
|
-
readonly objectType = "builder-question";
|
|
29
|
-
id: BuilderObjectId.QuestionID;
|
|
30
|
-
type: BuilderQuestionType;
|
|
31
|
-
questionText = "";
|
|
32
|
-
options: BuilderOption[] = [];
|
|
33
|
-
prefix = "";
|
|
34
|
-
|
|
35
|
-
static create = (type: BuilderQuestionType) => {
|
|
36
|
-
const id = BuilderObjectId.questionId();
|
|
37
|
-
|
|
38
|
-
return new BuilderQuestion({
|
|
39
|
-
id,
|
|
40
|
-
_type: type,
|
|
41
|
-
text: "",
|
|
42
|
-
options: [],
|
|
43
|
-
prefix: "",
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
|
|
48
|
-
const question = new BuilderQuestion(dto);
|
|
49
|
-
return question;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private constructor(dto: BuilderQuestionDto) {
|
|
53
|
-
super(dto);
|
|
54
|
-
this.id = dto.id as BuilderObjectId.QuestionID;
|
|
55
|
-
this.type = dto._type;
|
|
56
|
-
this.questionText = dto.text;
|
|
57
|
-
this.prefix = dto.prefix;
|
|
58
|
-
this.options = dto.options.map((o) => BuilderOption.fromJson(o));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
addOption(label: string, value: number, atIndex = -1) {
|
|
62
|
-
const option = BuilderOption.create(value, label);
|
|
63
|
-
if (atIndex >= 0 && atIndex < this.options.length) {
|
|
64
|
-
this.options.splice(atIndex, 0, option);
|
|
65
|
-
} else {
|
|
66
|
-
this.options.push(option);
|
|
67
|
-
}
|
|
68
|
-
return option;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
deleteOption(option: BuilderOption): boolean {
|
|
72
|
-
const filtered = this.options.filter((o) => o.id !== option.id);
|
|
73
|
-
const didDelete = filtered.length === this.options.length - 1;
|
|
74
|
-
this.options = filtered;
|
|
75
|
-
return didDelete;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
toJson() {
|
|
79
|
-
const optionsJson = this.options.map((o) => o.toJson());
|
|
80
|
-
const dto: BuilderQuestionDto = {
|
|
81
|
-
id: this.id,
|
|
82
|
-
prefix: this.prefix,
|
|
83
|
-
_type: this.type,
|
|
84
|
-
text: this.questionText,
|
|
85
|
-
options: optionsJson,
|
|
86
|
-
};
|
|
87
|
-
return dto;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
clone(): BuilderQuestionDto {
|
|
91
|
-
const cloneId = BuilderObjectId.questionId();
|
|
92
|
-
const dto = this.toJson();
|
|
93
|
-
const optionsClone = this.options.map((o) => o.clone());
|
|
94
|
-
const clonedDto: BuilderQuestionDto = {
|
|
95
|
-
...dto,
|
|
96
|
-
id: cloneId,
|
|
97
|
-
options: optionsClone,
|
|
98
|
-
};
|
|
99
|
-
return clonedDto;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
import type { BuilderOptionDto } from "./Builder-option";
|
|
2
|
+
import { BuilderOption } from "./Builder-option";
|
|
3
|
+
import { BuilderObject, BuilderObjectId } from "./BuilderObject";
|
|
4
|
+
|
|
5
|
+
export type BuilderQuestionType =
|
|
6
|
+
| "select-one"
|
|
7
|
+
| "select-many"
|
|
8
|
+
| "text"
|
|
9
|
+
| "color"
|
|
10
|
+
| "radio"
|
|
11
|
+
| "email"
|
|
12
|
+
| "time"
|
|
13
|
+
| "checkbox"
|
|
14
|
+
| "textarea"
|
|
15
|
+
| "date"
|
|
16
|
+
| "numeric-range"
|
|
17
|
+
| "duration";
|
|
18
|
+
|
|
19
|
+
export interface BuilderQuestionDto {
|
|
20
|
+
readonly id: BuilderObjectId.QuestionID;
|
|
21
|
+
_type: BuilderQuestionType;
|
|
22
|
+
text: string;
|
|
23
|
+
options: ReadonlyArray<BuilderOptionDto>;
|
|
24
|
+
prefix: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class BuilderQuestion extends BuilderObject<"builder-question", BuilderQuestionDto> {
|
|
28
|
+
readonly objectType = "builder-question";
|
|
29
|
+
id: BuilderObjectId.QuestionID;
|
|
30
|
+
type: BuilderQuestionType;
|
|
31
|
+
questionText = "";
|
|
32
|
+
options: BuilderOption[] = [];
|
|
33
|
+
prefix = "";
|
|
34
|
+
|
|
35
|
+
static create = (type: BuilderQuestionType) => {
|
|
36
|
+
const id = BuilderObjectId.questionId();
|
|
37
|
+
|
|
38
|
+
return new BuilderQuestion({
|
|
39
|
+
id,
|
|
40
|
+
_type: type,
|
|
41
|
+
text: "",
|
|
42
|
+
options: [],
|
|
43
|
+
prefix: "",
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
|
|
48
|
+
const question = new BuilderQuestion(dto);
|
|
49
|
+
return question;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private constructor(dto: BuilderQuestionDto) {
|
|
53
|
+
super(dto);
|
|
54
|
+
this.id = dto.id as BuilderObjectId.QuestionID;
|
|
55
|
+
this.type = dto._type;
|
|
56
|
+
this.questionText = dto.text;
|
|
57
|
+
this.prefix = dto.prefix;
|
|
58
|
+
this.options = dto.options.map((o) => BuilderOption.fromJson(o));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
addOption(label: string, value: number, atIndex = -1) {
|
|
62
|
+
const option = BuilderOption.create(value, label);
|
|
63
|
+
if (atIndex >= 0 && atIndex < this.options.length) {
|
|
64
|
+
this.options.splice(atIndex, 0, option);
|
|
65
|
+
} else {
|
|
66
|
+
this.options.push(option);
|
|
67
|
+
}
|
|
68
|
+
return option;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
deleteOption(option: BuilderOption): boolean {
|
|
72
|
+
const filtered = this.options.filter((o) => o.id !== option.id);
|
|
73
|
+
const didDelete = filtered.length === this.options.length - 1;
|
|
74
|
+
this.options = filtered;
|
|
75
|
+
return didDelete;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
toJson() {
|
|
79
|
+
const optionsJson = this.options.map((o) => o.toJson());
|
|
80
|
+
const dto: BuilderQuestionDto = {
|
|
81
|
+
id: this.id,
|
|
82
|
+
prefix: this.prefix,
|
|
83
|
+
_type: this.type,
|
|
84
|
+
text: this.questionText,
|
|
85
|
+
options: optionsJson,
|
|
86
|
+
};
|
|
87
|
+
return dto;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
clone(): BuilderQuestionDto {
|
|
91
|
+
const cloneId = BuilderObjectId.questionId();
|
|
92
|
+
const dto = this.toJson();
|
|
93
|
+
const optionsClone = this.options.map((o) => o.clone());
|
|
94
|
+
const clonedDto: BuilderQuestionDto = {
|
|
95
|
+
...dto,
|
|
96
|
+
id: cloneId,
|
|
97
|
+
options: optionsClone,
|
|
98
|
+
};
|
|
99
|
+
return clonedDto;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -7,6 +7,7 @@ import type { BuilderObjectId } from "./BuilderObject";
|
|
|
7
7
|
import { PageID, SchemaID } from "@media-quest/engine";
|
|
8
8
|
import { PagePrefix } from "./primitives/page-prefix";
|
|
9
9
|
import { SchemaPrefix } from "./primitives/schema-prefix";
|
|
10
|
+
import { SumScoreVariable } from "./variable/sum-score";
|
|
10
11
|
|
|
11
12
|
const tag1: BuilderTagDto = BuilderTag.create("tag1", "This tag is defined in schemaDto1").toJson();
|
|
12
13
|
|
|
@@ -21,6 +22,16 @@ const schemaDto1: BuilderSchemaDto = {
|
|
|
21
22
|
id: SchemaID.create(),
|
|
22
23
|
name: "dto1-name",
|
|
23
24
|
tags: [tag1, tag2, tag3],
|
|
25
|
+
sumScoreVariables: [
|
|
26
|
+
{
|
|
27
|
+
kind: "numeric-variable",
|
|
28
|
+
origin: "sum-score",
|
|
29
|
+
label: "label for dummy variable",
|
|
30
|
+
initialValue: 0,
|
|
31
|
+
varId: "testId",
|
|
32
|
+
basedOn: [],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
24
35
|
pages: [
|
|
25
36
|
{
|
|
26
37
|
id: PageID.ensure("a".repeat(24)),
|
|
@@ -303,4 +314,44 @@ describe("Builder schema", () => {
|
|
|
303
314
|
expect(allPageIds.has(v.pageId)).toBe(true);
|
|
304
315
|
});
|
|
305
316
|
});
|
|
317
|
+
test.skip("Can add sum-variables - and save as json", () => {
|
|
318
|
+
// p0.prefix = "info_page_prefix_";
|
|
319
|
+
const p1 = builderSchema.addPage("question");
|
|
320
|
+
const p2 = builderSchema.addPage("question");
|
|
321
|
+
p1.prefix = PagePrefix.fromStringOrThrow("p1_prefix");
|
|
322
|
+
p2.prefix = PagePrefix.fromStringOrThrow("p2_prefix");
|
|
323
|
+
p1.defaultQuestion.addOption("Ja", 1, 0);
|
|
324
|
+
p1.defaultQuestion.addOption("Nei", 0, 0);
|
|
325
|
+
p2.defaultQuestion.addOption("Ja", 1, 0);
|
|
326
|
+
p2.defaultQuestion.addOption("Nei", 0);
|
|
327
|
+
|
|
328
|
+
const ruleInput = builderSchema.getRuleInput();
|
|
329
|
+
const ss1: SumScoreVariable = {
|
|
330
|
+
label: "ss1",
|
|
331
|
+
varId: "ss1_var_id",
|
|
332
|
+
initialValue: 0,
|
|
333
|
+
kind: "numeric-variable",
|
|
334
|
+
origin: "sum-score",
|
|
335
|
+
basedOn: [],
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
builderSchema.addSumScoreVariable(ss1);
|
|
339
|
+
|
|
340
|
+
expect(ruleInput.questionVars.length).toBe(2);
|
|
341
|
+
expect(ruleInput.jumpToPageActions.length).toBe(3);
|
|
342
|
+
|
|
343
|
+
// TODO add TAGS!!
|
|
344
|
+
// expect(ruleInput.excludeByTagActions.length).toBe(0);
|
|
345
|
+
// expect(ruleInput.excludeByPageIdActions.length).toBe(3);
|
|
346
|
+
// const allPageIds = new Set(ruleInput.jumpToPageActions.map((a) => a.pageId));
|
|
347
|
+
// expect(allPageIds.has(p0.id)).toBe(true);
|
|
348
|
+
// expect(allPageIds.has(p1.id)).toBe(true);
|
|
349
|
+
// expect(allPageIds.has(p2.id)).toBe(true);
|
|
350
|
+
// ruleInput.questionVars.forEach((v) => {
|
|
351
|
+
// expect(allPageIds.has(v.varId)).toBe(true);
|
|
352
|
+
// });
|
|
353
|
+
// ruleInput.jumpToPageActions.forEach((v) => {
|
|
354
|
+
// expect(allPageIds.has(v.pageId)).toBe(true);
|
|
355
|
+
// });
|
|
356
|
+
});
|
|
306
357
|
});
|
package/src/Builder-schema.ts
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import type { BuilderPageDto, BuilderPageType } from "./Builder-page";
|
|
2
2
|
import { BuilderPage } from "./Builder-page";
|
|
3
|
-
import {
|
|
3
|
+
import type {
|
|
4
|
+
BuilderRuleDto,
|
|
5
|
+
CustomVariable,
|
|
6
|
+
ExcludeByPageAction,
|
|
7
|
+
ExcludeByTagAction,
|
|
8
|
+
JumpToPageAction,
|
|
9
|
+
} from "./rulebuilder";
|
|
10
|
+
import { BuilderRule, RuleInput } from "./rulebuilder";
|
|
4
11
|
import type { QuestionVariable } from "./rulebuilder/RuleVariable";
|
|
5
|
-
import type { CustomVariable } from "./rulebuilder";
|
|
6
|
-
import type { ExcludeByPageAction, ExcludeByTagAction, JumpToPageAction } from "./rulebuilder";
|
|
7
12
|
import type { BuilderTagDto } from "./BuilderTag";
|
|
8
13
|
import { BuilderTag, TagCollection } from "./BuilderTag";
|
|
9
|
-
import type { BuilderRuleDto } from "./rulebuilder";
|
|
10
|
-
import { BuilderRule } from "./rulebuilder";
|
|
11
14
|
import { DefaultThemeCompiler } from "./theme/default-theme-compiler";
|
|
12
15
|
import { ImageFile } from "./media-files";
|
|
13
|
-
import {
|
|
16
|
+
import { DUtil, SchemaID } from "@media-quest/engine";
|
|
14
17
|
import { PagePrefix } from "./primitives/page-prefix";
|
|
15
18
|
import { SchemaPrefix, SchemaPrefixValue } from "./primitives/schema-prefix";
|
|
16
|
-
import {
|
|
17
|
-
import { PredefinedVariable } from "./mq-variable";
|
|
19
|
+
import { CodeBook } from "./codebook";
|
|
20
|
+
import { PredefinedVariable } from "./variable/mq-variable";
|
|
18
21
|
import { SchemaConfig } from "./schema-config";
|
|
22
|
+
import { CompilerOption, CompilerOutput } from "./builder-compiler";
|
|
23
|
+
import { SumScoreVariable } from "./variable/sum-score";
|
|
24
|
+
|
|
19
25
|
const U = DUtil;
|
|
20
26
|
|
|
21
27
|
export interface BuilderSchemaDto {
|
|
@@ -28,14 +34,13 @@ export interface BuilderSchemaDto {
|
|
|
28
34
|
readonly baseHeight: number;
|
|
29
35
|
readonly baseWidth: number;
|
|
30
36
|
readonly predefinedVariables?: Array<PredefinedVariable>;
|
|
37
|
+
readonly sumScoreVariables?: Array<SumScoreVariable>;
|
|
31
38
|
readonly rules: ReadonlyArray<BuilderRuleDto>;
|
|
32
39
|
readonly tags: ReadonlyArray<BuilderTagDto>;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
codebook: Codebook;
|
|
38
|
-
schemaConfig: SchemaConfig;
|
|
42
|
+
class SumScoreVariableCollection {
|
|
43
|
+
private _all: Array<SumScoreVariable> = [];
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
export class BuilderSchema {
|
|
@@ -47,9 +52,13 @@ export class BuilderSchema {
|
|
|
47
52
|
mainImage: ImageFile | false = false;
|
|
48
53
|
predefinedVariables: PredefinedVariable[] = [];
|
|
49
54
|
private _rules: BuilderRule[] = [];
|
|
55
|
+
private _sumVariables: SumScoreVariable[] = [];
|
|
50
56
|
get rules(): ReadonlyArray<BuilderRule> {
|
|
51
57
|
return [...this._rules];
|
|
52
58
|
}
|
|
59
|
+
get sumScoreVariables(): ReadonlyArray<SumScoreVariable> {
|
|
60
|
+
return [...this._sumVariables];
|
|
61
|
+
}
|
|
53
62
|
|
|
54
63
|
// get prefix(): SchemaPrefixValue {
|
|
55
64
|
// return this._prefix.value;
|
|
@@ -121,6 +130,11 @@ export class BuilderSchema {
|
|
|
121
130
|
return newPage;
|
|
122
131
|
}
|
|
123
132
|
|
|
133
|
+
addSumScoreVariable(variable: SumScoreVariable) {
|
|
134
|
+
// TODO VALIDATE.
|
|
135
|
+
this._sumVariables.push({ ...variable });
|
|
136
|
+
}
|
|
137
|
+
|
|
124
138
|
insertPage(page: BuilderPage, atIndex: number): boolean {
|
|
125
139
|
return this.insertPageAtIndex(page, atIndex);
|
|
126
140
|
}
|
|
@@ -242,13 +256,31 @@ export class BuilderSchema {
|
|
|
242
256
|
this._tagCollection.add(builderTag);
|
|
243
257
|
}
|
|
244
258
|
|
|
245
|
-
compile(
|
|
246
|
-
|
|
259
|
+
compile(
|
|
260
|
+
options: CompilerOption = { blockAutoplayQuestion: false, blockAutoplayVideo: false },
|
|
261
|
+
): CompilerOutput {
|
|
262
|
+
// const moduleDto = this.toJson();
|
|
263
|
+
const builderSchema = BuilderSchema.fromJson(this.toJson());
|
|
264
|
+
|
|
265
|
+
// Overriding the
|
|
266
|
+
builderSchema.pages.forEach((p) => {
|
|
267
|
+
if (options.blockAutoplayQuestion) {
|
|
268
|
+
p.mainText.autoplay = false;
|
|
269
|
+
}
|
|
270
|
+
if (options.blockAutoplayVideo && p.mainMedia) {
|
|
271
|
+
if (p.mainMedia.kind === "main-video") {
|
|
272
|
+
// TODO autoplay as boolean, so that we know if video is optional or required when override.
|
|
273
|
+
p.mainMedia.mode = "optional";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
const moduleDto = builderSchema.toJson();
|
|
247
278
|
const imp = new DefaultThemeCompiler();
|
|
279
|
+
|
|
248
280
|
const codebook = CodeBook.fromSchema(moduleDto);
|
|
249
281
|
const schema = imp.compile(moduleDto);
|
|
250
282
|
const schemaConfig = SchemaConfig.fromSchema(moduleDto);
|
|
251
|
-
const output:
|
|
283
|
+
const output: CompilerOutput = { codebook, schema, schemaConfig };
|
|
252
284
|
return output;
|
|
253
285
|
}
|
|
254
286
|
}
|
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
|
+
});
|
package/src/Builder-text.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { BuilderObjectId, BuilderObject } from './BuilderObject';
|
|
2
|
-
|
|
3
|
-
export interface BuilderTextDto {
|
|
4
|
-
readonly id: BuilderObjectId.TextID;
|
|
5
|
-
text: string;
|
|
6
|
-
name: string;
|
|
7
|
-
translationRequired: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class BuilderText extends BuilderObject<'builder-text', BuilderTextDto> {
|
|
11
|
-
readonly objectType = 'builder-text';
|
|
12
|
-
id: BuilderObjectId.TextID;
|
|
13
|
-
text = '';
|
|
14
|
-
name = '';
|
|
15
|
-
translateRequired = false;
|
|
16
|
-
// audio: {id: B}
|
|
17
|
-
private constructor(dto: BuilderTextDto) {
|
|
18
|
-
super(dto);
|
|
19
|
-
this.id = dto.id;
|
|
20
|
-
this.translateRequired = dto.translationRequired;
|
|
21
|
-
this.name = dto.name;
|
|
22
|
-
this.text = dto.text;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static create(name: string) {
|
|
26
|
-
const id = BuilderObjectId.textId();
|
|
27
|
-
const dto: BuilderTextDto = {
|
|
28
|
-
id,
|
|
29
|
-
name,
|
|
30
|
-
text: '',
|
|
31
|
-
translationRequired: false
|
|
32
|
-
};
|
|
33
|
-
const instance = new BuilderText(dto);
|
|
34
|
-
return instance;
|
|
35
|
-
}
|
|
36
|
-
public static fromJson(dto: BuilderTextDto) {
|
|
37
|
-
const instance = new BuilderText(dto);
|
|
38
|
-
return instance;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
clone(): BuilderTextDto {
|
|
42
|
-
const newId = BuilderObjectId.textId();
|
|
43
|
-
const dto = this.toJson();
|
|
44
|
-
const withNewId: BuilderTextDto = { ...dto, id: newId };
|
|
45
|
-
return withNewId;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
toJson(): BuilderTextDto {
|
|
49
|
-
const dto: BuilderTextDto = {
|
|
50
|
-
id: this.id,
|
|
51
|
-
name: this.name,
|
|
52
|
-
text: this.text,
|
|
53
|
-
translationRequired: this.translateRequired
|
|
54
|
-
};
|
|
55
|
-
return dto;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import { BuilderObjectId, BuilderObject } from './BuilderObject';
|
|
2
|
+
|
|
3
|
+
export interface BuilderTextDto {
|
|
4
|
+
readonly id: BuilderObjectId.TextID;
|
|
5
|
+
text: string;
|
|
6
|
+
name: string;
|
|
7
|
+
translationRequired: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class BuilderText extends BuilderObject<'builder-text', BuilderTextDto> {
|
|
11
|
+
readonly objectType = 'builder-text';
|
|
12
|
+
id: BuilderObjectId.TextID;
|
|
13
|
+
text = '';
|
|
14
|
+
name = '';
|
|
15
|
+
translateRequired = false;
|
|
16
|
+
// audio: {id: B}
|
|
17
|
+
private constructor(dto: BuilderTextDto) {
|
|
18
|
+
super(dto);
|
|
19
|
+
this.id = dto.id;
|
|
20
|
+
this.translateRequired = dto.translationRequired;
|
|
21
|
+
this.name = dto.name;
|
|
22
|
+
this.text = dto.text;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static create(name: string) {
|
|
26
|
+
const id = BuilderObjectId.textId();
|
|
27
|
+
const dto: BuilderTextDto = {
|
|
28
|
+
id,
|
|
29
|
+
name,
|
|
30
|
+
text: '',
|
|
31
|
+
translationRequired: false
|
|
32
|
+
};
|
|
33
|
+
const instance = new BuilderText(dto);
|
|
34
|
+
return instance;
|
|
35
|
+
}
|
|
36
|
+
public static fromJson(dto: BuilderTextDto) {
|
|
37
|
+
const instance = new BuilderText(dto);
|
|
38
|
+
return instance;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
clone(): BuilderTextDto {
|
|
42
|
+
const newId = BuilderObjectId.textId();
|
|
43
|
+
const dto = this.toJson();
|
|
44
|
+
const withNewId: BuilderTextDto = { ...dto, id: newId };
|
|
45
|
+
return withNewId;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
toJson(): BuilderTextDto {
|
|
49
|
+
const dto: BuilderTextDto = {
|
|
50
|
+
id: this.id,
|
|
51
|
+
name: this.name,
|
|
52
|
+
text: this.text,
|
|
53
|
+
translationRequired: this.translateRequired
|
|
54
|
+
};
|
|
55
|
+
return dto;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ImageFile } from "./media-files";
|
|
2
|
-
|
|
3
|
-
export interface BuilderMainImageDto {
|
|
4
|
-
readonly kind: "main-image";
|
|
5
|
-
readonly file: ImageFile;
|
|
6
|
-
readonly overlay: { text: string; fontsize: number; xPos: number; yPos: number } | false;
|
|
7
|
-
}
|
|
1
|
+
import { ImageFile } from "./media-files";
|
|
2
|
+
|
|
3
|
+
export interface BuilderMainImageDto {
|
|
4
|
+
readonly kind: "main-image";
|
|
5
|
+
readonly file: ImageFile;
|
|
6
|
+
readonly overlay: { text: string; fontsize: number; xPos: number; yPos: number } | false;
|
|
7
|
+
}
|