@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,68 +1,68 @@
1
- import { SumScoreVariableCollection } from "./sum-score-variable-collection";
2
- import { SumScoreVariable } from "./sum-score-variable";
3
-
4
- const v = (name: string) => {
5
- return SumScoreVariable.create({ name, description: "description for " + name, useAvg: true });
6
- };
7
-
8
- let empty = SumScoreVariableCollection.create([]);
9
- beforeEach(() => {
10
- empty = SumScoreVariableCollection.create([]);
11
- });
12
- describe("Sum-score-variable-collection", () => {
13
- test("Add, update, delete works", () => {
14
- const v1 = empty.addNew({ name: "v1", description: "v1 desc", useAvg: true });
15
- const v2 = empty.addNew({ name: "v2", description: "v2 desc", useAvg: true });
16
-
17
- const v2_updated = empty._updateOne(v2.id, { name: "n2", description: "d2", useAvg: false });
18
- expect(v2_updated).toBeTruthy();
19
- expect(empty.size).toBe(2);
20
- const variable = empty._getVariableById(v2.id);
21
- expect(variable).toBeDefined();
22
- expect(variable!.name).toBe("n2");
23
- expect(variable!.description).toBe("d2");
24
- expect(variable!.useAvg).toBe(false);
25
- empty._deleteVariable(v1.id);
26
- expect(empty.size).toBe(1);
27
- });
28
- test("Duplicate names are detected", () => {
29
- const v1 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
30
- const v2 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
31
- expect(v1.hasErrors).toBe(true);
32
- expect(v2.hasErrors).toBe(true);
33
- });
34
- test("Error are removed on update", () => {
35
- const v1 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
36
- const v2 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
37
- expect(v1.hasErrors).toBe(true);
38
- expect(v2.hasErrors).toBe(true);
39
- empty._updateOne(v1.id, { name: "updated-name-updated" });
40
- expect(v1.hasErrors).toBe(false);
41
- expect(v2.hasErrors).toBe(false);
42
- });
43
- test("Error are removed on delete", () => {
44
- const v1 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
45
- const v2 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
46
- expect(v1.hasErrors).toBe(true);
47
- expect(v2.hasErrors).toBe(true);
48
- empty._deleteVariable(v1.id);
49
-
50
- expect(empty.size).toBe(1);
51
- expect(v2.hasErrors).toBe(false);
52
- });
53
- test("Error are detected on construction", () => {
54
- const col = SumScoreVariableCollection.create([v("v1"), v("v1")]);
55
- expect(col.errorsCount).toBe(2);
56
- });
57
-
58
- test("Error are detected after init", () => {
59
- const col = SumScoreVariableCollection.create([]);
60
- const v1 = v("v1");
61
- const v1_duplicate = v("v1");
62
- const v3 = v("v3");
63
- const v4 = v("v4");
64
- col.init([v1, v1_duplicate, v3, v4]);
65
- expect(col.errorsCount).toBe(2);
66
- expect(col.size).toBe(4);
67
- });
68
- });
1
+ import { SumScoreVariableCollection } from "./sum-score-variable-collection";
2
+ import { SumScoreVariable } from "./sum-score-variable";
3
+
4
+ const v = (name: string) => {
5
+ return SumScoreVariable.create({ name, description: "description for " + name, useAvg: true });
6
+ };
7
+
8
+ let empty = SumScoreVariableCollection.create([]);
9
+ beforeEach(() => {
10
+ empty = SumScoreVariableCollection.create([]);
11
+ });
12
+ describe("Sum-score-variable-collection", () => {
13
+ test("Add, update, delete works", () => {
14
+ const v1 = empty.addNew({ name: "v1", description: "v1 desc", useAvg: true });
15
+ const v2 = empty.addNew({ name: "v2", description: "v2 desc", useAvg: true });
16
+
17
+ const v2_updated = empty._updateOne(v2.id, { name: "n2", description: "d2", useAvg: false });
18
+ expect(v2_updated).toBeTruthy();
19
+ expect(empty.size).toBe(2);
20
+ const variable = empty._getVariableById(v2.id);
21
+ expect(variable).toBeDefined();
22
+ expect(variable!.name).toBe("n2");
23
+ expect(variable!.description).toBe("d2");
24
+ expect(variable!.useAvg).toBe(false);
25
+ empty._deleteVariable(v1.id);
26
+ expect(empty.size).toBe(1);
27
+ });
28
+ test("Duplicate names are detected", () => {
29
+ const v1 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
30
+ const v2 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
31
+ expect(v1.hasErrors).toBe(true);
32
+ expect(v2.hasErrors).toBe(true);
33
+ });
34
+ test("Error are removed on update", () => {
35
+ const v1 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
36
+ const v2 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
37
+ expect(v1.hasErrors).toBe(true);
38
+ expect(v2.hasErrors).toBe(true);
39
+ empty._updateOne(v1.id, { name: "updated-name-updated" });
40
+ expect(v1.hasErrors).toBe(false);
41
+ expect(v2.hasErrors).toBe(false);
42
+ });
43
+ test("Error are removed on delete", () => {
44
+ const v1 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
45
+ const v2 = empty.addNew({ name: "v1", description: "desc", useAvg: true });
46
+ expect(v1.hasErrors).toBe(true);
47
+ expect(v2.hasErrors).toBe(true);
48
+ empty._deleteVariable(v1.id);
49
+
50
+ expect(empty.size).toBe(1);
51
+ expect(v2.hasErrors).toBe(false);
52
+ });
53
+ test("Error are detected on construction", () => {
54
+ const col = SumScoreVariableCollection.create([v("v1"), v("v1")]);
55
+ expect(col.errorsCount).toBe(2);
56
+ });
57
+
58
+ test("Error are detected after init", () => {
59
+ const col = SumScoreVariableCollection.create([]);
60
+ const v1 = v("v1");
61
+ const v1_duplicate = v("v1");
62
+ const v3 = v("v3");
63
+ const v4 = v("v4");
64
+ col.init([v1, v1_duplicate, v3, v4]);
65
+ expect(col.errorsCount).toBe(2);
66
+ expect(col.size).toBe(4);
67
+ });
68
+ });
@@ -1,101 +1,101 @@
1
- import { SumScoreVariable, SumScoreVariableDto } from "./sum-score-variable";
2
- import { SumScoreVariableID } from "../primitives/ID";
3
-
4
- export class SumScoreVariableCollection implements Iterable<SumScoreVariable> {
5
- private _all: Array<SumScoreVariable> = [];
6
-
7
- [Symbol.iterator]() {
8
- const list = [...this._all];
9
- return list[Symbol.iterator]();
10
- }
11
-
12
- asArray(): ReadonlyArray<SumScoreVariable> {
13
- return [...this._all];
14
- }
15
-
16
- public static readonly create = (
17
- variables?: SumScoreVariableDto[],
18
- ): SumScoreVariableCollection => {
19
- return new SumScoreVariableCollection(variables);
20
- };
21
-
22
- private constructor(sumScoreVariables?: SumScoreVariableDto[]) {
23
- const all = Array.isArray(sumScoreVariables) ? sumScoreVariables : [];
24
- this._all = all.map((dto) => SumScoreVariable.fromDto(dto));
25
- this.checkForErrors();
26
- }
27
-
28
- init(variables: SumScoreVariableDto[]) {
29
- this._all = variables.map((variable) => SumScoreVariable.fromDto(variable));
30
- this.checkForErrors();
31
- }
32
- addNew(options: { name: string; description: string; useAvg: boolean }) {
33
- // console.log(options);
34
- const newVariable = SumScoreVariable.create({ ...options });
35
- this._all.push(newVariable);
36
- this.checkForErrors();
37
- return newVariable;
38
- }
39
-
40
- get size() {
41
- return this._all.length;
42
- }
43
-
44
- get errorsCount() {
45
- return this._all.filter((variable) => variable.hasErrors).length;
46
- }
47
-
48
- toJson() {
49
- return this._all.map((item) => item.toJson());
50
- }
51
-
52
- /**
53
- *
54
- */
55
- _deleteVariable(id: SumScoreVariableID) {
56
- const initialSize = this._all.length;
57
- this._all = this._all.filter((variable) => variable.id !== id);
58
- this.checkForErrors();
59
- return initialSize === this.size + 1;
60
- }
61
-
62
- /**
63
- * @internal
64
- */
65
- _updateOne(
66
- id: SumScoreVariableID,
67
- updates: { name?: string; description?: string; useAvg?: boolean },
68
- ): boolean {
69
- const variable = this._all.find((variable) => variable.id === id);
70
- if (variable) {
71
- variable._update(updates);
72
- this.checkForErrors();
73
- return true;
74
- } else {
75
- return false;
76
- }
77
- }
78
-
79
- /** @internal */
80
- _getVariableById(id: SumScoreVariableID): SumScoreVariable | undefined {
81
- return this._all.find((variable) => variable.id === id);
82
- }
83
-
84
- private checkForErrors() {
85
- const nameMap = new Map<string, SumScoreVariable[]>();
86
- this._all.forEach((v) => {
87
- const array = nameMap.get(v.name) ?? [];
88
- array.push(v);
89
- nameMap.set(v.name, array);
90
- });
91
- nameMap.forEach((sameNameArray) => {
92
- sameNameArray.forEach((sameNameItem) => {
93
- if (sameNameArray.length > 1) {
94
- sameNameItem._setError("Duplicate name");
95
- } else {
96
- sameNameItem._setError("");
97
- }
98
- });
99
- });
100
- }
101
- }
1
+ import { SumScoreVariable, SumScoreVariableDto } from "./sum-score-variable";
2
+ import { SumScoreVariableID } from "../primitives/ID";
3
+
4
+ export class SumScoreVariableCollection implements Iterable<SumScoreVariable> {
5
+ private _all: Array<SumScoreVariable> = [];
6
+
7
+ [Symbol.iterator]() {
8
+ const list = [...this._all];
9
+ return list[Symbol.iterator]();
10
+ }
11
+
12
+ asArray(): ReadonlyArray<SumScoreVariable> {
13
+ return [...this._all];
14
+ }
15
+
16
+ public static readonly create = (
17
+ variables?: SumScoreVariableDto[],
18
+ ): SumScoreVariableCollection => {
19
+ return new SumScoreVariableCollection(variables);
20
+ };
21
+
22
+ private constructor(sumScoreVariables?: SumScoreVariableDto[]) {
23
+ const all = Array.isArray(sumScoreVariables) ? sumScoreVariables : [];
24
+ this._all = all.map((dto) => SumScoreVariable.fromDto(dto));
25
+ this.checkForErrors();
26
+ }
27
+
28
+ init(variables: SumScoreVariableDto[]) {
29
+ this._all = variables.map((variable) => SumScoreVariable.fromDto(variable));
30
+ this.checkForErrors();
31
+ }
32
+ addNew(options: { name: string; description: string; useAvg: boolean }) {
33
+ // console.log(options);
34
+ const newVariable = SumScoreVariable.create({ ...options });
35
+ this._all.push(newVariable);
36
+ this.checkForErrors();
37
+ return newVariable;
38
+ }
39
+
40
+ get size() {
41
+ return this._all.length;
42
+ }
43
+
44
+ get errorsCount() {
45
+ return this._all.filter((variable) => variable.hasErrors).length;
46
+ }
47
+
48
+ toJson() {
49
+ return this._all.map((item) => item.toJson());
50
+ }
51
+
52
+ /**
53
+ *
54
+ */
55
+ _deleteVariable(id: SumScoreVariableID) {
56
+ const initialSize = this._all.length;
57
+ this._all = this._all.filter((variable) => variable.id !== id);
58
+ this.checkForErrors();
59
+ return initialSize === this.size + 1;
60
+ }
61
+
62
+ /**
63
+ * @internal
64
+ */
65
+ _updateOne(
66
+ id: SumScoreVariableID,
67
+ updates: { name?: string; description?: string; useAvg?: boolean },
68
+ ): boolean {
69
+ const variable = this._all.find((variable) => variable.id === id);
70
+ if (variable) {
71
+ variable._update(updates);
72
+ this.checkForErrors();
73
+ return true;
74
+ } else {
75
+ return false;
76
+ }
77
+ }
78
+
79
+ /** @internal */
80
+ _getVariableById(id: SumScoreVariableID): SumScoreVariable | undefined {
81
+ return this._all.find((variable) => variable.id === id);
82
+ }
83
+
84
+ private checkForErrors() {
85
+ const nameMap = new Map<string, SumScoreVariable[]>();
86
+ this._all.forEach((v) => {
87
+ const array = nameMap.get(v.name) ?? [];
88
+ array.push(v);
89
+ nameMap.set(v.name, array);
90
+ });
91
+ nameMap.forEach((sameNameArray) => {
92
+ sameNameArray.forEach((sameNameItem) => {
93
+ if (sameNameArray.length > 1) {
94
+ sameNameItem._setError("Duplicate name");
95
+ } else {
96
+ sameNameItem._setError("");
97
+ }
98
+ });
99
+ });
100
+ }
101
+ }
@@ -68,7 +68,6 @@ export class SumScoreVariable extends BuilderObject<
68
68
  /** @internal*/
69
69
  _update(data: { name?: string; description?: string; useAvg?: boolean }) {
70
70
  const d = data ?? {};
71
-
72
71
  if (DUtil.isString(d.name)) {
73
72
  this._name = d.name;
74
73
  }