@media-quest/builder 0.0.40 → 0.0.42

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@media-quest/builder",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "description": "Builder library for Media-quest schemas",
5
5
  "main": "dist/public-api.js",
6
6
  "types": "dist/public-api.d.js",
@@ -24,6 +24,6 @@
24
24
  "dts": true
25
25
  },
26
26
  "peerDependencies": {
27
- "@media-quest/engine": "0.0.40"
27
+ "@media-quest/engine": "0.0.42"
28
28
  }
29
29
  }
@@ -56,8 +56,7 @@ export class BuilderOption extends BuilderObject<"builder-question-option", Buil
56
56
  }
57
57
 
58
58
  public static fromJson(dto: BuilderOptionDto) {
59
- const instance = new BuilderOption(dto);
60
- return instance;
59
+ return new BuilderOption(dto);
61
60
  }
62
61
 
63
62
  toJson(): BuilderOptionDto {
@@ -21,6 +21,7 @@ const question2: BuilderQuestionDto = {
21
21
  id: "q3-opt1" as OptionID,
22
22
  value: 0,
23
23
  label: "Nei",
24
+ cssOverride: {maxWidth: 100}
24
25
  },
25
26
  {
26
27
  id: "q3-opt2" as OptionID,
@@ -42,8 +42,7 @@ export class BuilderQuestion extends BuilderObject<"builder-question", BuilderQu
42
42
  };
43
43
 
44
44
  public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
45
- const question = new BuilderQuestion(dto);
46
- return question;
45
+ return new BuilderQuestion(dto);
47
46
  }
48
47
 
49
48
  private constructor(dto: BuilderQuestionDto) {
@@ -44,6 +44,7 @@ const pages: BuilderPageDto[] = [
44
44
  id: OptionID.create(),
45
45
  label: "Neste",
46
46
  value: -1,
47
+ cssOverride: {}
47
48
  },
48
49
  defaultQuestion: {
49
50
  id: QuestionID.create(),
@@ -55,16 +56,19 @@ const pages: BuilderPageDto[] = [
55
56
  id: "opt-nei" as OptionID,
56
57
  value: 0,
57
58
  label: "Nei",
59
+ cssOverride: {}
58
60
  },
59
61
  {
60
62
  id: "opt-ja" as OptionID,
61
63
  value: 1,
62
64
  label: "Ja",
65
+ cssOverride: {}
63
66
  },
64
67
  {
65
68
  id: "opt-vet-ikke" as OptionID,
66
69
  value: 9,
67
70
  label: "Vet ikke",
71
+ cssOverride: {}
68
72
  },
69
73
  ],
70
74
  },
@@ -92,6 +96,7 @@ const pages: BuilderPageDto[] = [
92
96
  id: "next-button-id-page2" as OptionID,
93
97
  label: "Neste",
94
98
  value: -1,
99
+ cssOverride: {}
95
100
  },
96
101
  defaultQuestion: {
97
102
  id: QuestionID.validateOrCreate("default-question-id"),
@@ -1,7 +1,6 @@
1
- import { DStyle } from "@media-quest/engine";
1
+ import { PStyle } from "@media-quest/engine";
2
2
  import type { CssTheme } from "./css-theme";
3
3
 
4
- type PStyle = Partial<DStyle>;
5
4
  export interface IDefaultTheme {
6
5
  name: string;
7
6
  schemaBackgroundColor: string;
@@ -11,7 +11,7 @@ import {
11
11
  DDivDto,
12
12
  DelayTask,
13
13
  DElementDto,
14
- DImgDto,
14
+ DImgDto, DStyle,
15
15
  DTextDto,
16
16
  PageDto,
17
17
  PlayAudioTask,
@@ -633,20 +633,25 @@ export class DefaultThemeCompiler implements ThemeCompiler<IDefaultTheme> {
633
633
  }
634
634
  : { kind: "next-page" };
635
635
 
636
- let btnStyles =
636
+ const _btnStyles =
637
637
  value === 9 ? t.buttonBar.responseButtons.dontKnow : t.buttonBar.responseButtons.normal;
638
+ let css: PStyle = DStyle.clone(_btnStyles.btn.css)
639
+ const cssEnabled = DStyle.clone(_btnStyles.btn.cssEnabled)
640
+
638
641
  if (t.buttonBar.vibrateMs) {
639
- onclickAction.vibrateMs = t.buttonBar.vibrateMs;
642
+ // TODO DO NOT WORK.
643
+ // onclickAction.vibrateMs = t.buttonBar.vibrateMs;
640
644
  }
641
645
 
642
646
  if(cssOverride) {
643
- btnStyles.btn.css = {...btnStyles.btn.css, ...cssOverride}
647
+ console.log(cssOverride);
648
+ css = {...css, ...cssOverride}
644
649
  }
645
650
 
646
651
  const btn: DButtonDto = {
647
652
  _tag: "button",
648
653
  innerText: label,
649
- style: { ...btnStyles.btn.css, ...btnStyles.btn.cssEnabled },
654
+ style: { ...css, ...cssEnabled },
650
655
  onClick: onclickAction,
651
656
  };
652
657
 
@@ -4,6 +4,10 @@ import { CssTheme } from "./css-theme";
4
4
  import { PStyle } from "@media-quest/engine";
5
5
  import { THEME_2_ICONS } from "./icons";
6
6
 
7
+ const deepClone = <T>(obj: T): T => {
8
+ return JSON.parse(JSON.stringify(obj));
9
+ }
10
+
7
11
  const translate = (pos: { x?: number; y?: number }) => {
8
12
  const x = pos.x || 0;
9
13
  const y = pos.y || 0;
@@ -85,21 +89,26 @@ const BUTTON_BAR_WIDTH = Q_AREA_WIDTH - 2 * W_M3;
85
89
  const MAIN_TEXT_WIDE = Q_AREA_WIDTH - 2 * W_M3;
86
90
  const MAIN_TEXT_NARROW = MAIN_TEXT_WIDE - AUDIO_ICON_WIDTH - W_M3;
87
91
 
88
- const btnTextBase: PStyle = {
89
- fontSize: { _unit: "px", value: 25 },
90
- bottom: VIDEO_CONTROLS_BOTTOM + 1.2,
91
- zIndex: LAYER_5,
92
- width: VIDEO_CONTROLS_WIDTH / 2,
93
- textAlign: "center",
94
- visibility: "hidden",
95
- margin: { _unit: "px", value: 0 },
92
+ // const btnTextBase: PStyle = {
93
+
96
94
  // backgroundColor: Colors.yellow,
97
- };
95
+ // };
98
96
 
99
- const muteUnmuteText: PStyle = { ...btnTextBase, right: VIDEO_CONTROLS_RIGHT };
100
- const playPauseText: PStyle = { ...btnTextBase, left: VIDEO_CONTROLS_LEFT };
97
+ const btnTextBaseObj = (): PStyle => {
98
+ return {
99
+ fontSize: { _unit: "px", value: 25 },
100
+ bottom: VIDEO_CONTROLS_BOTTOM + 1.2,
101
+ zIndex: LAYER_5,
102
+ width: VIDEO_CONTROLS_WIDTH / 2,
103
+ textAlign: "center",
104
+ visibility: "hidden",
105
+ margin: { _unit: "px", value: 0 },
106
+ }
107
+ }
108
+ const muteUnmuteText: PStyle = { ...btnTextBaseObj(), right: VIDEO_CONTROLS_RIGHT };
109
+ const playPauseText: PStyle = { ...btnTextBaseObj(), left: VIDEO_CONTROLS_LEFT };
101
110
  const replayText: PStyle = {
102
- ...btnTextBase,
111
+ ...btnTextBaseObj(),
103
112
  width: VIDEO_CONTROLS_WIDTH,
104
113
  left: VIDEO_CONTROLS_LEFT,
105
114
  // backgroundColor: Colors.yellow,
@@ -156,8 +165,9 @@ const responseButtonBaseCss = (): CssTheme => ({
156
165
  fontSize: { _unit: "px", value: 28 },
157
166
  lineHeight: 1.1,
158
167
 
159
- // TODO Denne angir knappens max-bredde. Default bør være 25.
160
- maxWidth: 25,
168
+ // TODO Skal knappene vokse, med mindre det settes en maksbredde?
169
+ // maxWidth: 25,
170
+ // maxWidth: { _unit: "percent", value: 10 },
161
171
  minWidth: 12,
162
172
  // width: 20,
163
173
  // flex: "0 0 auto",
@@ -171,11 +181,11 @@ const responseButtonBaseCss = (): CssTheme => ({
171
181
  position: "relative",
172
182
  display: "block",
173
183
  cursor: "pointer",
174
- // maxWidth: { _unit: "percent", value: 10 },
175
184
  },
176
185
  cssDisabled: { opacity: 0.3, cursor: "not-allowed" },
177
186
  cssEnabled: { opacity: 1, cursor: "pointer" },
178
187
  });
188
+
179
189
  export const primaryButton = (overridesCss: PStyle): BuilderOptionTheme => {
180
190
  const base = responseButtonBaseCss();
181
191
  const optionTheme: BuilderOptionTheme = {
@@ -183,8 +193,8 @@ export const primaryButton = (overridesCss: PStyle): BuilderOptionTheme => {
183
193
  normal: {
184
194
  btn: {
185
195
  css: {
186
- ...base.css,
187
- ...overridesCss,
196
+ ...deepClone(base.css),
197
+ ...deepClone(overridesCss),
188
198
  backgroundColor: Colors.primary,
189
199
  borderColor: Colors.primary,
190
200
  textColor: Colors.white,
@@ -200,8 +210,8 @@ export const primaryButton = (overridesCss: PStyle): BuilderOptionTheme => {
200
210
  dontKnow: {
201
211
  btn: {
202
212
  css: {
203
- ...base.css,
204
- ...overridesCss,
213
+ ...deepClone(base.css),
214
+ ...deepClone(overridesCss),
205
215
  backgroundColor: Colors.secondary,
206
216
  borderColor: Colors.secondary,
207
217
  textColor: Colors.primary,
@@ -375,14 +385,15 @@ export const Theme2: IDefaultTheme = {
375
385
  bottom: Q_AREA_BOTTOM + H_M3,
376
386
  left: Q_AREA_LEFT + W_M3,
377
387
  // backgroundColor: "green",
378
- gap: { _unit: "px", value: 40 },
388
+ gap: { _unit: "px", value: 32 },
379
389
  alignItems: "stretch",
380
390
  },
381
391
  whenSingle: { justifyContent: "center" },
382
392
  whenMany: { justifyContent: "flex-start" },
383
393
  },
384
394
 
385
- nextButtonTheme: primaryButton({}),
386
- responseButtons: primaryButton({}),
395
+ nextButtonTheme: primaryButton({fontSize: { _unit: "px", value: 28 }, maxWidth: {_unit: "percent", value: 25}}),
396
+ responseButtons: primaryButton({fontSize: { _unit: "px", value: 28 }, maxWidth: {_unit: "percent", value: 25 }}),
387
397
  },
388
398
  };
399
+ console.log(Theme2);