@webwriter/quiz 1.1.1 → 1.1.3

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.
@@ -5845,9 +5845,14 @@ var WebwriterChoice = class extends (_a2 = LitElementWw, _mode_dec = [n5({ type:
5845
5845
  })], _randomOrder_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({
5846
5846
  type: Boolean,
5847
5847
  label: { "en": "Random Choice Order", "de": "Zuf\xE4llige Reihenfolge" }
5848
- })], _showSolution_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({
5849
- type: Boolean,
5850
- label: { "en": "show Solution", "de": "L\xF6sung anzeigen" }
5848
+ })], _showSolution_dec = [n5({ type: String, attribute: true, reflect: true }), option({
5849
+ type: "select",
5850
+ label: { "de": "L\xF6sung anzeigen", "en": "Show solution" },
5851
+ options: [
5852
+ { value: "right", label: { "en": "Right answers", "de": "Korrekte Antworten" } },
5853
+ { value: "both", label: { "en": "all (indicator)", "de": "Alle (Indikator)" } },
5854
+ { value: "full", label: { "en": "all (conclusive)", "de": "Alle (vollst\xE4ndig)" } }
5855
+ ]
5851
5856
  })], _slotEl_dec = [e6("slot")], _addItem_dec = [action()], _items_dec = [o6()], _value_dec = [n5({ type: Array, attribute: false })], _itemsSlotEl_dec = [e6("#items-slot")], _a2) {
5852
5857
  constructor() {
5853
5858
  super(...arguments);
@@ -5855,7 +5860,7 @@ var WebwriterChoice = class extends (_a2 = LitElementWw, _mode_dec = [n5({ type:
5855
5860
  __publicField(this, "localize", generated_default);
5856
5861
  __privateAdd(this, _mode, __runInitializers(_init2, 8, this, "single")), __runInitializers(_init2, 11, this);
5857
5862
  __privateAdd(this, _randomOrder, __runInitializers(_init2, 12, this, false)), __runInitializers(_init2, 15, this);
5858
- __privateAdd(this, _showSolution, __runInitializers(_init2, 16, this, false)), __runInitializers(_init2, 19, this);
5863
+ __privateAdd(this, _showSolution, __runInitializers(_init2, 16, this, "right")), __runInitializers(_init2, 19, this);
5859
5864
  __privateAdd(this, _slotEl, __runInitializers(_init2, 20, this)), __runInitializers(_init2, 23, this);
5860
5865
  __privateAdd(this, _items, __runInitializers(_init2, 24, this)), __runInitializers(_init2, 27, this);
5861
5866
  __privateAdd(this, _value, []);
@@ -5889,11 +5894,11 @@ var WebwriterChoice = class extends (_a2 = LitElementWw, _mode_dec = [n5({ type:
5889
5894
  this.items.forEach((item) => value.includes(item.id) ? item.valid = true : null);
5890
5895
  }
5891
5896
  reportSolution() {
5897
+ console.log(this.solution, this.items);
5892
5898
  let itemActive = false;
5893
5899
  this.items.forEach((item) => {
5894
5900
  itemActive = itemActive || item.active;
5895
5901
  });
5896
- console.log(itemActive);
5897
5902
  if (!itemActive) {
5898
5903
  this.items.forEach((item) => {
5899
5904
  item.valid = void 0;
@@ -5902,30 +5907,40 @@ var WebwriterChoice = class extends (_a2 = LitElementWw, _mode_dec = [n5({ type:
5902
5907
  });
5903
5908
  return;
5904
5909
  }
5905
- console.warn("h");
5906
5910
  if (!this.solution) {
5907
5911
  this.items.forEach((item) => item.valid = true);
5908
5912
  return;
5909
5913
  }
5914
+ let wrongSolution = false;
5910
5915
  this.items.forEach(
5911
5916
  (item) => {
5917
+ console.log(!(item.active === item.valid), item.active, item.valid);
5912
5918
  item.valid = (this.solution ?? []).includes(item.id);
5913
- console.log(this.solution, item.active, item.valid);
5914
- if (item.active != item.valid && !this.showSolution) {
5915
- this.items.forEach((item2) => {
5916
- item2.showSolution = false;
5917
- });
5919
+ if (item.active != item.valid) {
5920
+ wrongSolution = true;
5921
+ if (this.showSolution != "full") {
5922
+ this.items.forEach((item2) => {
5923
+ item2.showSolution = false;
5924
+ });
5925
+ }
5918
5926
  }
5919
5927
  item.style.pointerEvents = "none";
5920
5928
  }
5921
5929
  );
5930
+ if (wrongSolution) {
5931
+ if (this.showSolution != "right") {
5932
+ this.style.backgroundColor = "#F9B5C4";
5933
+ }
5934
+ } else {
5935
+ this.style.backgroundColor = "#BCE194";
5936
+ }
5922
5937
  }
5923
5938
  reset() {
5924
5939
  this.items.forEach((item) => {
5925
5940
  item.valid = void 0;
5926
5941
  item.active = false;
5927
5942
  item.showSolution = true;
5928
- item.style.pointerEvents = "auto";
5943
+ item.style.pointerEvents = "auto", this.style.backgroundColor = "";
5929
5944
  });
5930
5945
  this.shuffleItems();
5931
5946
  }
@@ -3393,7 +3393,6 @@ var WebwriterOrderItem = class extends (_a2 = LitElementWw, _showSolution_dec =
3393
3393
  }
3394
3394
  async updated(_changedProperties) {
3395
3395
  if (_changedProperties.has("layout") && this.layout === "list") {
3396
- console.log("switched to list");
3397
3396
  this.syncSize(true);
3398
3397
  this.observer?.disconnect();
3399
3398
  this.requestUpdate();
@@ -4585,15 +4585,20 @@ var WebwriterOrder = class extends (_a2 = LitElementWw, _layout_dec = [n5({ type
4585
4585
  { value: "list", label: { "en": "List" } },
4586
4586
  { value: "tiles", label: { "en": "Tiles" } }
4587
4587
  ]
4588
- })], _hideOrderButtons_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({ type: Boolean, label: { "en": "Hide order buttons", "de": "Pfeile zum Verschieben verstecken" } })], _showSolution_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({
4589
- type: Boolean,
4590
- label: { "en": "show Solution", "de": "L\xF6sung anzeigen" }
4588
+ })], _hideOrderButtons_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({ type: Boolean, label: { "en": "Hide order buttons", "de": "Pfeile zum Verschieben verstecken" } })], _showSolution_dec = [n5({ type: String, attribute: true, reflect: true }), option({
4589
+ type: "select",
4590
+ label: { "de": "L\xF6sung anzeigen", "en": "Show solution" },
4591
+ options: [
4592
+ { value: "right", label: { "en": "Right answers", "de": "Korrekte Antworten" } },
4593
+ { value: "both", label: { "en": "all (indicator)", "de": "Alle (Indikator)" } },
4594
+ { value: "full", label: { "en": "all (conclusive)", "de": "Alle (vollst\xE4ndig)" } }
4595
+ ]
4591
4596
  })], _itemsSlot_dec = [e6("#items-slot")], _items_dec = [o6()], _solution_dec = [n5({ attribute: false })], _a2) {
4592
4597
  constructor() {
4593
4598
  super(...arguments);
4594
4599
  __runInitializers(_init2, 5, this);
4595
4600
  __publicField(this, "localize", generated_default);
4596
- __privateAdd(this, _showSolution, __runInitializers(_init2, 8, this, true)), __runInitializers(_init2, 11, this);
4601
+ __privateAdd(this, _showSolution, __runInitializers(_init2, 8, this, "right")), __runInitializers(_init2, 11, this);
4597
4602
  __publicField(this, "observer");
4598
4603
  __publicField(this, "orderSheet", new CSSStyleSheet());
4599
4604
  __publicField(this, "clearDropPreviews", () => {
@@ -4701,17 +4706,24 @@ var WebwriterOrder = class extends (_a2 = LitElementWw, _layout_dec = [n5({ type
4701
4706
  }
4702
4707
  }
4703
4708
  reportSolution() {
4704
- console.log(this.solution, this.items);
4705
4709
  this.solution.forEach((id, i7) => this.querySelector(`#${id}`).validOrder = i7);
4706
- if (!this.showSolution) {
4707
- this.items.forEach((item) => {
4708
- console.log(item.validOrder, this.solution.indexOf(item.id));
4709
- if (this.items.indexOf(item) != this.solution.indexOf(item.id)) {
4710
+ let wrongSolution = false;
4711
+ this.items.forEach((item) => {
4712
+ if (this.items.indexOf(item) != this.solution.indexOf(item.id)) {
4713
+ wrongSolution = true;
4714
+ if (this.showSolution != "full") {
4710
4715
  this.items.forEach((i7) => {
4711
4716
  i7.showSolution = false;
4712
4717
  });
4713
4718
  }
4714
- });
4719
+ }
4720
+ });
4721
+ if (wrongSolution) {
4722
+ if (this.showSolution != "right") {
4723
+ this.style.backgroundColor = "#F9B5C4";
4724
+ }
4725
+ } else {
4726
+ this.style.backgroundColor = "#BCE194";
4715
4727
  }
4716
4728
  this.items.forEach((item) => {
4717
4729
  item.style.pointerEvents = "none";
@@ -4719,6 +4731,7 @@ var WebwriterOrder = class extends (_a2 = LitElementWw, _layout_dec = [n5({ type
4719
4731
  }
4720
4732
  reset() {
4721
4733
  this.solution = void 0;
4734
+ this.style.backgroundColor = "";
4722
4735
  this.shuffleItems();
4723
4736
  this.items.forEach((item) => {
4724
4737
  item.style.pointerEvents = "auto";
@@ -4730,9 +4743,11 @@ var WebwriterOrder = class extends (_a2 = LitElementWw, _layout_dec = [n5({ type
4730
4743
  render() {
4731
4744
  return x`
4732
4745
  <slot id="items-slot" @webwriter-clear-drop-preview=${this.clearDropPreviews}></slot>
4733
- <sl-button size="small" id="add-option" class="author-only" @click=${() => this.addItem()}>
4746
+ ${this.hasAttribute("contenteditable") ? x`
4747
+ <sl-button size="small" id="add-option" @click=${() => this.addItem()}>
4734
4748
  <sl-icon src=${plus_default}></sl-icon><span>${msg("Add Option")}</span>
4735
4749
  </sl-button>
4750
+ ` : ""}
4736
4751
  `;
4737
4752
  }
4738
4753
  };
@@ -4819,11 +4834,11 @@ __publicField(WebwriterOrder, "styles", i`
4819
4834
  align-items: center;
4820
4835
  justify-content: center;
4821
4836
  }
4822
-
4823
-
4837
+ // broken for some reason o.O
4838
+ /*
4824
4839
  :host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
4825
4840
  display: none;
4826
- }
4841
+ } */
4827
4842
  `);
4828
4843
  __runInitializers(_init2, 1, WebwriterOrder);
4829
4844
  export {
@@ -7972,7 +7972,6 @@ var WebwriterQuiz = class extends (_a2 = LitElementWw, _randomOrder_dec = [n5({
7972
7972
  __publicField(this, "localize", generated_default);
7973
7973
  __privateAdd(this, _randomOrder, __runInitializers(_init2, 8, this, false)), __runInitializers(_init2, 11, this);
7974
7974
  __publicField(this, "handleReset", () => {
7975
- console.warn(this.tasks);
7976
7975
  this.tasks.forEach((task) => task.handleReset());
7977
7976
  this.requestUpdate();
7978
7977
  this.submitted = false;
@@ -8230,7 +8230,6 @@ var WebwriterTask = class extends (_a2 = LitElementWw, _hints_dec = [o7({ slot:
8230
8230
  }
8231
8231
  });
8232
8232
  __publicField(this, "handleHintKeydown", (e11) => {
8233
- console.log(document.getSelection().anchorOffset === 0, this.hints.includes(document.getSelection().anchorNode.parentElement));
8234
8233
  if (e11.key === "Backspace" && document.getSelection().anchorOffset === 0 && this.hints.includes(document.getSelection().anchorNode.parentElement)) {
8235
8234
  this.hintOpen = false;
8236
8235
  this.hint = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webwriter/quiz",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Add interactive tasks (multiple choice, order, free text, highlighting, or speech input). Make a quiz out of multiple tasks.",
5
5
  "keywords": [
6
6
  "webwriter-widget",
@@ -72,12 +72,17 @@ export class WebwriterChoice extends LitElementWw {
72
72
  })
73
73
  accessor randomOrder = false
74
74
 
75
- @property({type: Boolean, attribute: true, reflect: true})
75
+ @property({type: String, attribute: true, reflect: true})
76
76
  @option({
77
- type: Boolean,
78
- label: {"en": "show Solution", "de": "Lösung anzeigen"},
77
+ type: "select",
78
+ label: {"de": "Lösung anzeigen", "en": "Show solution"},
79
+ options: [
80
+ {value: "right", label: {"en": "Right answers", "de": "Korrekte Antworten"}},
81
+ {value: "both", label: {"en": "all (indicator)", "de": "Alle (Indikator)"}},
82
+ {value: "full", label: {"en": "all (conclusive)", "de": "Alle (vollständig)"}}
83
+ ],
79
84
  })
80
- accessor showSolution = false
85
+ accessor showSolution = "right"
81
86
 
82
87
  get solution() {
83
88
  const validIDs = this.items.filter(item => item.valid).map(item => item.id)
@@ -90,35 +95,43 @@ export class WebwriterChoice extends LitElementWw {
90
95
 
91
96
 
92
97
  reportSolution() {
93
-
98
+ console.log(this.solution, this.items)
94
99
  let itemActive: boolean = false
95
100
  this.items.forEach(item => {itemActive = itemActive || item.active})
96
- console.log(itemActive)
97
101
  if(!itemActive){
98
102
  this.items.forEach(item => {item.valid = undefined; item.active = false; item.style.pointerEvents = "auto"})
99
103
  return
100
104
  }
101
- console.warn("h")
102
105
  if(!this.solution) {
103
106
  this.items.forEach(item => item.valid = true)
104
107
  return
105
108
  }
109
+ let wrongSolution: boolean = false
106
110
  this.items.forEach(item => {
111
+ console.log(!(item.active === item.valid), item.active, item.valid)
107
112
  item.valid = (this.solution ?? []).includes(item.id)
108
- console.log(this.solution, item.active, item.valid)
109
- if(item.active != item.valid && !this.showSolution){
110
- this.items.forEach(item => {
111
- item.showSolution = false
112
- })
113
+ if(item.active != item.valid){
114
+ wrongSolution = true
115
+ if(this.showSolution != "full"){
116
+ this.items.forEach(item => {
117
+ item.showSolution = false
118
+ })
119
+ }
113
120
  }
114
121
  item.style.pointerEvents = "none"
115
122
  }
116
123
  )
117
-
124
+ if(wrongSolution){
125
+ if(this.showSolution != "right"){
126
+ this.style.backgroundColor = "#F9B5C4"
127
+ }
128
+ }else{
129
+ this.style.backgroundColor = "#BCE194"
130
+ }
118
131
  }
119
132
 
120
133
  reset() {
121
- this.items.forEach(item => {item.valid = undefined; item.active = false; item.showSolution = true; item.style.pointerEvents = "auto"})
134
+ this.items.forEach(item => {item.valid = undefined; item.active = false; item.showSolution = true; item.style.pointerEvents = "auto", this.style.backgroundColor = ""})
122
135
  this.shuffleItems()
123
136
  }
124
137
 
@@ -367,7 +367,7 @@ export class WebwriterOrderItem extends LitElementWw {
367
367
 
368
368
  protected async updated(_changedProperties: PropertyValues) {
369
369
  if(_changedProperties.has("layout") && this.layout === "list") {
370
- console.log("switched to list")
370
+ // console.log("switched to list")
371
371
  this.syncSize(true)
372
372
  this.observer?.disconnect()
373
373
  this.requestUpdate()
@@ -103,11 +103,11 @@ export class WebwriterOrder extends LitElementWw {
103
103
  align-items: center;
104
104
  justify-content: center;
105
105
  }
106
-
107
-
106
+ // broken for some reason o.O
107
+ /*
108
108
  :host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
109
109
  display: none;
110
- }
110
+ } */
111
111
  `
112
112
 
113
113
  get layout(): "list" | "tiles" {
@@ -137,12 +137,17 @@ export class WebwriterOrder extends LitElementWw {
137
137
  this.items.forEach(item => item.hideOrderButtons = value)
138
138
  }
139
139
 
140
- @property({type: Boolean, attribute: true, reflect: true})
140
+ @property({type: String, attribute: true, reflect: true})
141
141
  @option({
142
- type: Boolean,
143
- label: {"en": "show Solution", "de": "Lösung anzeigen"},
142
+ type: "select",
143
+ label: {"de": "Lösung anzeigen", "en": "Show solution"},
144
+ options: [
145
+ {value: "right", label: {"en": "Right answers", "de": "Korrekte Antworten"}},
146
+ {value: "both", label: {"en": "all (indicator)", "de": "Alle (Indikator)"}},
147
+ {value: "full", label: {"en": "all (conclusive)", "de": "Alle (vollständig)"}}
148
+ ],
144
149
  })
145
- accessor showSolution = true
150
+ accessor showSolution = "right"
146
151
 
147
152
  observer: MutationObserver
148
153
 
@@ -272,17 +277,24 @@ export class WebwriterOrder extends LitElementWw {
272
277
 
273
278
 
274
279
  reportSolution() {
275
- console.log(this.solution, this.items)
276
280
  this.solution.forEach((id, i) => (this.querySelector(`#${id}`) as any).validOrder = i)
277
- if(!this.showSolution){
278
- this.items.forEach(item => {
279
- console.log(item.validOrder, this.solution.indexOf(item.id))
280
- if(this.items.indexOf(item) != this.solution.indexOf(item.id)){
281
+ let wrongSolution: boolean = false
282
+ this.items.forEach(item => {
283
+ if(this.items.indexOf(item) != this.solution.indexOf(item.id)){
284
+ wrongSolution = true
285
+ if(this.showSolution != "full"){
281
286
  this.items.forEach(i => {
282
287
  i.showSolution = false
283
288
  })
284
289
  }
285
- })
290
+ }
291
+ })
292
+ if(wrongSolution){
293
+ if(this.showSolution != "right"){
294
+ this.style.backgroundColor = "#F9B5C4"
295
+ }
296
+ }else{
297
+ this.style.backgroundColor = "#BCE194"
286
298
  }
287
299
  this.items.forEach(item=>{
288
300
  item.style.pointerEvents="none"
@@ -291,6 +303,7 @@ export class WebwriterOrder extends LitElementWw {
291
303
 
292
304
  reset() {
293
305
  this.solution = undefined
306
+ this.style.backgroundColor = ""
294
307
  this.shuffleItems()
295
308
  this.items.forEach(item=>{
296
309
  item.style.pointerEvents="auto"
@@ -304,9 +317,11 @@ export class WebwriterOrder extends LitElementWw {
304
317
  render() {
305
318
  return html`
306
319
  <slot id="items-slot" @webwriter-clear-drop-preview=${this.clearDropPreviews}></slot>
307
- <sl-button size="small" id="add-option" class="author-only" @click=${() => this.addItem()}>
320
+ ${this.hasAttribute("contenteditable")?html`
321
+ <sl-button size="small" id="add-option" @click=${() => this.addItem()}>
308
322
  <sl-icon src=${IconPlus}></sl-icon><span>${msg("Add Option")}</span>
309
323
  </sl-button>
324
+ `:""}
310
325
  `
311
326
  }
312
327
  }
@@ -214,7 +214,6 @@ export class WebwriterQuiz extends LitElementWw {
214
214
  }
215
215
 
216
216
  handleReset = () => {
217
- console.warn(this.tasks)
218
217
  this.tasks.forEach(task => task.handleReset())
219
218
  this.requestUpdate()
220
219
  this.submitted = false
@@ -460,7 +460,7 @@ export class WebwriterTask extends LitElementWw {
460
460
  }
461
461
 
462
462
  handleHintKeydown = (e: KeyboardEvent) => {
463
- console.log(document.getSelection().anchorOffset === 0, this.hints.includes(document.getSelection().anchorNode.parentElement))
463
+ // console.log(document.getSelection().anchorOffset === 0, this.hints.includes(document.getSelection().anchorNode.parentElement))
464
464
  if(e.key === "Backspace" && document.getSelection().anchorOffset === 0 && this.hints.includes(document.getSelection().anchorNode.parentElement)) {
465
465
  this.hintOpen = false
466
466
  this.hint = false