@media-quest/builder 0.0.38 → 0.0.40

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 (41) hide show
  1. package/dist/public-api.d.ts +82 -99
  2. package/dist/public-api.js +36 -101
  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 +78 -62
  8. package/src/Builder-question.ts +98 -98
  9. package/src/Builder-schema.spec.ts +348 -348
  10. package/src/Builder-schema.ts +308 -306
  11. package/src/builder-compiler.ts +14 -20
  12. package/src/code-book/codebook-variable.ts +27 -27
  13. package/src/code-book/codebook.ts +89 -89
  14. package/src/media-files.ts +28 -32
  15. package/src/page/Builder-page-collection.spec.ts +219 -219
  16. package/src/page/Builder-page-collection.ts +129 -129
  17. package/src/page/Builder-page.spec.ts +177 -177
  18. package/src/page/Builder-page.ts +250 -250
  19. package/src/primitives/ID.ts +135 -135
  20. package/src/public-api.ts +29 -30
  21. package/src/rulebuilder/RuleAction.ts +105 -105
  22. package/src/schema-config.ts +25 -26
  23. package/src/sum-score/sum-score-variable-collection.spec.ts +68 -68
  24. package/src/sum-score/sum-score-variable-collection.ts +101 -101
  25. package/src/sum-score/sum-score-variable.ts +0 -1
  26. package/src/sum-score/sum-score.ts +166 -167
  27. package/src/tag/BuilderTag.ts +45 -45
  28. package/src/tag/Tag-Collection.ts +53 -53
  29. package/src/theme/Default-theme.ts +173 -188
  30. package/src/theme/IDefault-theme.ts +125 -125
  31. package/src/theme/ThemeCompiler.ts +10 -11
  32. package/src/theme/default-theme-compiler.spec.ts +31 -31
  33. package/src/theme/default-theme-compiler.ts +655 -652
  34. package/src/theme/icon-urls.ts +29 -29
  35. package/src/theme/icons.ts +117 -117
  36. package/src/theme/theme-utils.spec.ts +52 -52
  37. package/src/theme/theme-utils.ts +56 -56
  38. package/src/theme/theme2.ts +388 -386
  39. package/tsconfig.json +19 -19
  40. package/src/Builder-schema-dto.spec.ts +0 -155
  41. package/src/Builder-schema-dto.ts +0 -86
@@ -1,105 +1,105 @@
1
- import { ButtonBarState, ButtonTextState, buttonTextUtils } from "./button-text-utils";
2
-
3
- const lineCount2 = 2;
4
- describe("Button-text-utils", () => {
5
- test("ButtonTextState works", () => {
6
- const b1 = new ButtonTextState("vet ikke");
7
-
8
- expect(b1.canSplit).toBe(true);
9
- expect(b1.splitDiff).toBe(4);
10
- expect(b1.width).toBe(8);
11
- expect(b1.isSplit).toBe(false);
12
- b1.tryToSplit();
13
- expect(b1.width).toBe(4);
14
- expect(b1.isSplit).toBe(true);
15
- b1.unSplit();
16
- expect(b1.width).toBe(8);
17
- expect(b1.isSplit).toBe(false);
18
-
19
- const b2 = new ButtonTextState("ja");
20
- expect(b2.splitDiff).toBe(0);
21
- expect(b2.canSplit).toBe(false);
22
- expect(b2.width).toBe(2);
23
- expect(b2.isSplit).toBe(false);
24
- b2.tryToSplit();
25
- expect(b2.width).toBe(2);
26
- expect(b2.isSplit).toBe(true);
27
- const b3 = new ButtonTextState("Mer enn 30 minutter");
28
- expect(b3.canSplit).toBe(true);
29
- expect(b3.splitDiff).toBe(9);
30
- expect(b3.width).toBe(19);
31
- expect(b3.isSplit).toBe(false);
32
- b3.tryToSplit();
33
- expect(b3.width).toBe(10);
34
- expect(b3.isSplit).toBe(true);
35
- b3.unSplit();
36
- expect(b3.getState().width).toBe(19);
37
- });
38
-
39
- test("ButtonBarState workss", () => {
40
- const bar = new ButtonBarState(["ja", "nei", "vet ikke"], { oneLineMax: 10, twoLineMax: 10 });
41
- expect(bar.getWidth()).toBe(13);
42
- expect(bar.isFitting()).toBe(false);
43
- expect(bar.isOneLine()).toBe(true);
44
- expect(bar.canCompress()).toBe(true);
45
- expect(bar.compressOneButton()).toBe(true);
46
- });
47
-
48
- test("Max word length works", () => {
49
- const a = buttonTextUtils.maxWordLength("ja");
50
- expect(buttonTextUtils.maxWordLength("ja")).toBe(2);
51
- expect(buttonTextUtils.maxWordLength("Ganske fin i dag")).toBe(6);
52
- expect(buttonTextUtils.maxWordLength("rått")).toBe(4);
53
- });
54
-
55
- test("All splitts work. ", () => {
56
- const a = buttonTextUtils.allSplits("del da");
57
- expect(a.length).toBe(2);
58
- });
59
-
60
- test("Can split a string into two lines at the middle", () => {
61
- const text = "del da for helvete";
62
- const a = buttonTextUtils.splitInTwo(text);
63
- expect(a.first).toBe("del da for");
64
- const b = buttonTextUtils.splitInTwo("Mer enn 10 minutter");
65
- expect(b.longest).toBe(10);
66
- const c = buttonTextUtils.splitInTwo("litt vanskelig og");
67
- expect(c.first).toBe("litt");
68
- expect(c.last).toBe("vanskelig og");
69
- });
70
-
71
- test("Will check if a text can fit within bounds.", () => {
72
- const text = "dette blir en altfor lang text. Faen.";
73
- const a = buttonTextUtils.checkLength(text);
74
- expect(a.max).toBe(text.length);
75
- expect(a.min).toBe(20);
76
- });
77
-
78
- test("Fit all will detect if buttons dont fit on a single line.", () => {
79
- const buttons = ["ja", "nei", "vet ikke"];
80
- const r1 = buttonTextUtils.fitAll(buttons, {
81
- oneLine: { min: 5, max: 12 },
82
- twoLine: { min: 10, max: 20 },
83
- });
84
-
85
- expect(r1.isSingleLine).toEqual(false);
86
- expect(r1.requiredSpace).toEqual(buttons.join("").length);
87
- expect(r1.twoLineCount).toEqual(1);
88
- const r2 = buttonTextUtils.fitAll(buttons, {
89
- oneLine: { min: 5, max: 13 },
90
- twoLine: { min: 10, max: 20 },
91
- });
92
- expect(r2.isSingleLine).toEqual(true);
93
- expect(r2.twoLineCount).toEqual(0);
94
- });
95
- test("Will calculate required space, when break", () => {
96
- const buttons = ["ja", "nei", "vet ikke"];
97
- const r1 = buttonTextUtils.fitAll(buttons, {
98
- oneLine: { min: 5, max: 10 },
99
- twoLine: { min: 5, max: 10 },
100
- });
101
- // expect(r1.isSingleLine).toEqual(false);
102
- // expect(r1.requiredSpace).toEqual("ja".length + "nei".length + "ikke".length);
103
- // expect(r1.twoLineCount).toEqual(1);
104
- });
105
- });
1
+ import { ButtonBarState, ButtonTextState, buttonTextUtils } from "./button-text-utils";
2
+
3
+ const lineCount2 = 2;
4
+ describe("Button-text-utils", () => {
5
+ test("ButtonTextState works", () => {
6
+ const b1 = new ButtonTextState("vet ikke");
7
+
8
+ expect(b1.canSplit).toBe(true);
9
+ expect(b1.splitDiff).toBe(4);
10
+ expect(b1.width).toBe(8);
11
+ expect(b1.isSplit).toBe(false);
12
+ b1.tryToSplit();
13
+ expect(b1.width).toBe(4);
14
+ expect(b1.isSplit).toBe(true);
15
+ b1.unSplit();
16
+ expect(b1.width).toBe(8);
17
+ expect(b1.isSplit).toBe(false);
18
+
19
+ const b2 = new ButtonTextState("ja");
20
+ expect(b2.splitDiff).toBe(0);
21
+ expect(b2.canSplit).toBe(false);
22
+ expect(b2.width).toBe(2);
23
+ expect(b2.isSplit).toBe(false);
24
+ b2.tryToSplit();
25
+ expect(b2.width).toBe(2);
26
+ expect(b2.isSplit).toBe(true);
27
+ const b3 = new ButtonTextState("Mer enn 30 minutter");
28
+ expect(b3.canSplit).toBe(true);
29
+ expect(b3.splitDiff).toBe(9);
30
+ expect(b3.width).toBe(19);
31
+ expect(b3.isSplit).toBe(false);
32
+ b3.tryToSplit();
33
+ expect(b3.width).toBe(10);
34
+ expect(b3.isSplit).toBe(true);
35
+ b3.unSplit();
36
+ expect(b3.getState().width).toBe(19);
37
+ });
38
+
39
+ test("ButtonBarState workss", () => {
40
+ const bar = new ButtonBarState(["ja", "nei", "vet ikke"], { oneLineMax: 10, twoLineMax: 10 });
41
+ expect(bar.getWidth()).toBe(13);
42
+ expect(bar.isFitting()).toBe(false);
43
+ expect(bar.isOneLine()).toBe(true);
44
+ expect(bar.canCompress()).toBe(true);
45
+ expect(bar.compressOneButton()).toBe(true);
46
+ });
47
+
48
+ test("Max word length works", () => {
49
+ const a = buttonTextUtils.maxWordLength("ja");
50
+ expect(buttonTextUtils.maxWordLength("ja")).toBe(2);
51
+ expect(buttonTextUtils.maxWordLength("Ganske fin i dag")).toBe(6);
52
+ expect(buttonTextUtils.maxWordLength("rått")).toBe(4);
53
+ });
54
+
55
+ test("All splitts work. ", () => {
56
+ const a = buttonTextUtils.allSplits("del da");
57
+ expect(a.length).toBe(2);
58
+ });
59
+
60
+ test("Can split a string into two lines at the middle", () => {
61
+ const text = "del da for helvete";
62
+ const a = buttonTextUtils.splitInTwo(text);
63
+ expect(a.first).toBe("del da for");
64
+ const b = buttonTextUtils.splitInTwo("Mer enn 10 minutter");
65
+ expect(b.longest).toBe(10);
66
+ const c = buttonTextUtils.splitInTwo("litt vanskelig og");
67
+ expect(c.first).toBe("litt");
68
+ expect(c.last).toBe("vanskelig og");
69
+ });
70
+
71
+ test("Will check if a text can fit within bounds.", () => {
72
+ const text = "dette blir en altfor lang text. Faen.";
73
+ const a = buttonTextUtils.checkLength(text);
74
+ expect(a.max).toBe(text.length);
75
+ expect(a.min).toBe(20);
76
+ });
77
+
78
+ test("Fit all will detect if buttons dont fit on a single line.", () => {
79
+ const buttons = ["ja", "nei", "vet ikke"];
80
+ const r1 = buttonTextUtils.fitAll(buttons, {
81
+ oneLine: { min: 5, max: 12 },
82
+ twoLine: { min: 10, max: 20 },
83
+ });
84
+
85
+ expect(r1.isSingleLine).toEqual(false);
86
+ expect(r1.requiredSpace).toEqual(buttons.join("").length);
87
+ expect(r1.twoLineCount).toEqual(1);
88
+ const r2 = buttonTextUtils.fitAll(buttons, {
89
+ oneLine: { min: 5, max: 13 },
90
+ twoLine: { min: 10, max: 20 },
91
+ });
92
+ expect(r2.isSingleLine).toEqual(true);
93
+ expect(r2.twoLineCount).toEqual(0);
94
+ });
95
+ test("Will calculate required space, when break", () => {
96
+ const buttons = ["ja", "nei", "vet ikke"];
97
+ const r1 = buttonTextUtils.fitAll(buttons, {
98
+ oneLine: { min: 5, max: 10 },
99
+ twoLine: { min: 5, max: 10 },
100
+ });
101
+ // expect(r1.isSingleLine).toEqual(false);
102
+ // expect(r1.requiredSpace).toEqual("ja".length + "nei".length + "ikke".length);
103
+ // expect(r1.twoLineCount).toEqual(1);
104
+ });
105
+ });
@@ -1,62 +1,78 @@
1
- import { BuilderObject } from "./BuilderObject";
2
- import { AudioFile } from "./media-files";
3
- import { OptionID } from "./primitives/ID";
4
-
5
- export interface BuilderOptionDto {
6
- readonly id: OptionID;
7
- readonly value: number;
8
- readonly label: string;
9
- readonly labelAudio?: AudioFile;
10
- }
11
-
12
- export class BuilderOption extends BuilderObject<"builder-question-option", BuilderOptionDto> {
13
- readonly objectType = "builder-question-option";
14
- id: OptionID;
15
- value: number;
16
- label = "";
17
- private _labelAudioFile: AudioFile | false = false;
18
- get labelAudioFile() {
19
- return this._labelAudioFile;
20
- }
21
- set labelAudioFile(audioFile: AudioFile | false) {
22
- this._labelAudioFile = audioFile;
23
- }
24
-
25
- private constructor(dto: BuilderOptionDto) {
26
- super(dto);
27
- this.id = dto.id;
28
- this.value = dto.value;
29
- this.label = dto.label;
30
- // this.theme = dto.theme;
31
- }
32
- public static create(value: number, label: string) {
33
- const id = OptionID.create();
34
- const dto: BuilderOptionDto = {
35
- id,
36
- value,
37
- label,
38
- };
39
- const instance = new BuilderOption(dto);
40
- return instance;
41
- }
42
-
43
- public static fromJson(dto: BuilderOptionDto) {
44
- const instance = new BuilderOption(dto);
45
- return instance;
46
- }
47
-
48
- toJson(): BuilderOptionDto {
49
- const dto: BuilderOptionDto = {
50
- id: this.id,
51
- value: this.value,
52
- label: this.label,
53
- };
54
- return dto;
55
- }
56
-
57
- clone(): BuilderOptionDto {
58
- const dto = this.toJson();
59
- const cloneDto: BuilderOptionDto = { ...dto, id: OptionID.create() };
60
- return cloneDto;
61
- }
62
- }
1
+ import { BuilderObject } from "./BuilderObject";
2
+ import { AudioFile } from "./media-files";
3
+ import { OptionID } from "./primitives/ID";
4
+ import { PStyle } from "@media-quest/engine";
5
+
6
+ export interface BuilderOptionDto {
7
+ readonly id: OptionID;
8
+ readonly value: number;
9
+ readonly label: string;
10
+ readonly labelAudio?: AudioFile;
11
+ readonly cssOverride?: PStyle;
12
+ }
13
+
14
+ export class BuilderOption extends BuilderObject<"builder-question-option", BuilderOptionDto> {
15
+ readonly objectType = "builder-question-option";
16
+
17
+ id: OptionID;
18
+
19
+ value: number;
20
+
21
+ label = "";
22
+
23
+ cssOverride: PStyle = {}
24
+
25
+ private _labelAudioFile: AudioFile | false = false;
26
+
27
+ get labelAudioFile() {
28
+ return this._labelAudioFile;
29
+ }
30
+
31
+ set labelAudioFile(audioFile: AudioFile | false) {
32
+ this._labelAudioFile = audioFile;
33
+ }
34
+
35
+ private constructor(dto: BuilderOptionDto) {
36
+ super(dto);
37
+ this.id = dto.id;
38
+ this.value = dto.value;
39
+ this.label = dto.label;
40
+ if(dto.cssOverride) {
41
+ this.cssOverride = { ...dto.cssOverride };
42
+ }
43
+ // this.theme = dto.theme;
44
+ }
45
+ public static create(value: number, label: string, css: PStyle = {}) {
46
+ const id = OptionID.create();
47
+ const dto: BuilderOptionDto = {
48
+ id,
49
+ value,
50
+ label,
51
+ cssOverride: css
52
+ };
53
+
54
+ const instance = new BuilderOption(dto);
55
+ return instance;
56
+ }
57
+
58
+ public static fromJson(dto: BuilderOptionDto) {
59
+ const instance = new BuilderOption(dto);
60
+ return instance;
61
+ }
62
+
63
+ toJson(): BuilderOptionDto {
64
+ const dto: BuilderOptionDto = {
65
+ id: this.id,
66
+ value: this.value,
67
+ label: this.label,
68
+ cssOverride: {...this.cssOverride}
69
+ };
70
+ return dto;
71
+ }
72
+
73
+ clone(): BuilderOptionDto {
74
+ const dto = this.toJson();
75
+ const cloneDto: BuilderOptionDto = { ...dto, id: OptionID.create() };
76
+ return cloneDto;
77
+ }
78
+ }
@@ -1,98 +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
- | "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
- }
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
+ }