@webwriter/quiz 1.0.5 → 1.0.6

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 (128) hide show
  1. package/LICENSE +6 -6
  2. package/custom.d.ts +175 -175
  3. package/dist/widgets/webwriter-choice-item.css +1 -1
  4. package/dist/widgets/webwriter-choice-item.js +1886 -802
  5. package/dist/widgets/webwriter-choice.css +1 -1
  6. package/dist/widgets/webwriter-choice.js +1943 -846
  7. package/dist/widgets/webwriter-cloze-gap.css +1 -1
  8. package/dist/widgets/webwriter-cloze-gap.js +1988 -902
  9. package/dist/widgets/webwriter-cloze.css +1 -1
  10. package/dist/widgets/webwriter-cloze.js +1833 -748
  11. package/dist/widgets/webwriter-mark.css +1 -1
  12. package/dist/widgets/webwriter-mark.js +1848 -762
  13. package/dist/widgets/webwriter-order-item.css +1 -1
  14. package/dist/widgets/webwriter-order-item.js +1884 -799
  15. package/dist/widgets/webwriter-order.css +1 -1
  16. package/dist/widgets/webwriter-order.js +1882 -790
  17. package/dist/widgets/webwriter-pairing-item.css +1 -1
  18. package/dist/widgets/webwriter-pairing-item.js +1718 -614
  19. package/dist/widgets/webwriter-pairing.css +1 -1
  20. package/dist/widgets/webwriter-pairing.js +1873 -781
  21. package/dist/widgets/webwriter-quiz.css +1 -1
  22. package/dist/widgets/webwriter-quiz.js +2241 -1026
  23. package/dist/widgets/webwriter-speech.css +1 -1
  24. package/dist/widgets/webwriter-speech.js +2179 -961
  25. package/dist/widgets/webwriter-task-explainer.css +1 -1
  26. package/dist/widgets/webwriter-task-explainer.js +1704 -600
  27. package/dist/widgets/webwriter-task-hint.css +1 -1
  28. package/dist/widgets/webwriter-task-hint.js +1695 -591
  29. package/dist/widgets/webwriter-task-prompt.css +1 -1
  30. package/dist/widgets/webwriter-task-prompt.js +1670 -566
  31. package/dist/widgets/webwriter-task.css +1 -1
  32. package/dist/widgets/webwriter-task.js +2361 -1143
  33. package/dist/widgets/webwriter-text.css +1 -1
  34. package/dist/widgets/webwriter-text.js +1876 -770
  35. package/icon.svg +1 -0
  36. package/lit-localize.json +15 -0
  37. package/localization/bg.xlf +54 -0
  38. package/localization/cs.xlf +54 -0
  39. package/localization/da.xlf +54 -0
  40. package/localization/de.xlf +54 -0
  41. package/localization/el.xlf +54 -0
  42. package/localization/es.xlf +54 -0
  43. package/localization/et.xlf +54 -0
  44. package/localization/fi.xlf +54 -0
  45. package/localization/fr.xlf +54 -0
  46. package/localization/generated/bg.ts +25 -0
  47. package/localization/generated/cs.ts +25 -0
  48. package/localization/generated/da.ts +25 -0
  49. package/localization/generated/de.ts +25 -0
  50. package/localization/generated/el.ts +25 -0
  51. package/localization/generated/es.ts +25 -0
  52. package/localization/generated/et.ts +25 -0
  53. package/localization/generated/fi.ts +25 -0
  54. package/localization/generated/fr.ts +25 -0
  55. package/localization/generated/hu.ts +25 -0
  56. package/localization/generated/id.ts +25 -0
  57. package/localization/generated/index.js +3 -0
  58. package/localization/generated/it.ts +25 -0
  59. package/localization/generated/ja.ts +25 -0
  60. package/localization/generated/ko.ts +25 -0
  61. package/localization/generated/locale-codes.js +79 -0
  62. package/localization/generated/lt.ts +25 -0
  63. package/localization/generated/lv.ts +25 -0
  64. package/localization/generated/nb.ts +25 -0
  65. package/localization/generated/nl.ts +25 -0
  66. package/localization/generated/pl.ts +25 -0
  67. package/localization/generated/pt-BR.ts +25 -0
  68. package/localization/generated/pt-PT.ts +25 -0
  69. package/localization/generated/ro.ts +25 -0
  70. package/localization/generated/ru.ts +25 -0
  71. package/localization/generated/sk.ts +25 -0
  72. package/localization/generated/sl.ts +25 -0
  73. package/localization/generated/sv.ts +25 -0
  74. package/localization/generated/tr.ts +25 -0
  75. package/localization/generated/uk.ts +25 -0
  76. package/localization/generated/zh-hans.ts +25 -0
  77. package/localization/hu.xlf +54 -0
  78. package/localization/id.xlf +54 -0
  79. package/localization/it.xlf +54 -0
  80. package/localization/ja.xlf +54 -0
  81. package/localization/ko.xlf +54 -0
  82. package/localization/lt.xlf +54 -0
  83. package/localization/lv.xlf +54 -0
  84. package/localization/nb.xlf +54 -0
  85. package/localization/nl.xlf +54 -0
  86. package/localization/pl.xlf +54 -0
  87. package/localization/pt-BR.xlf +54 -0
  88. package/localization/pt-PT.xlf +54 -0
  89. package/localization/ro.xlf +54 -0
  90. package/localization/ru.xlf +54 -0
  91. package/localization/sk.xlf +54 -0
  92. package/localization/sl.xlf +54 -0
  93. package/localization/sv.xlf +54 -0
  94. package/localization/tr.xlf +54 -0
  95. package/localization/uk.xlf +54 -0
  96. package/localization/zh-hans.xlf +54 -0
  97. package/package.json +206 -198
  98. package/src/lib/combobox.ts +455 -455
  99. package/src/lib/highlighter-fill.svg +5 -5
  100. package/src/snippets/Beispiel-Choice.html +57 -0
  101. package/src/snippets/Beispiel-Mark.html +14 -0
  102. package/src/snippets/Beispiel-Order.html +52 -0
  103. package/src/snippets/Beispiel-Text.html +20 -0
  104. package/src/snippets/choice.html +7 -7
  105. package/src/snippets/cloze.html +3 -3
  106. package/src/snippets/mark.html +3 -3
  107. package/src/snippets/order.html +7 -7
  108. package/src/snippets/pairing.html +9 -9
  109. package/src/snippets/speech.html +3 -3
  110. package/src/snippets/text.html +3 -3
  111. package/src/snippets/wordsearch.html +3 -3
  112. package/src/widgets/webwriter-choice-item.ts +250 -250
  113. package/src/widgets/webwriter-choice.ts +314 -309
  114. package/src/widgets/webwriter-cloze-gap.ts +215 -216
  115. package/src/widgets/webwriter-cloze.ts +135 -135
  116. package/src/widgets/webwriter-mark.ts +431 -434
  117. package/src/widgets/webwriter-order-item.ts +437 -436
  118. package/src/widgets/webwriter-order.ts +284 -279
  119. package/src/widgets/webwriter-pairing-item.ts +160 -155
  120. package/src/widgets/webwriter-pairing.ts +192 -187
  121. package/src/widgets/webwriter-quiz.ts +281 -280
  122. package/src/widgets/webwriter-speech.ts +272 -267
  123. package/src/widgets/webwriter-task-explainer.ts +42 -37
  124. package/src/widgets/webwriter-task-hint.ts +22 -16
  125. package/src/widgets/webwriter-task-prompt.ts +23 -17
  126. package/src/widgets/webwriter-task.ts +546 -543
  127. package/src/widgets/webwriter-text.ts +135 -130
  128. package/tsconfig.json +6 -6
@@ -1,281 +1,282 @@
1
- import {css, html, PropertyValues} from "lit"
2
- import {LitElementWw, option} from "@webwriter/lit"
3
- import {customElement, property, query, queryAssignedElements} from "lit/decorators.js"
4
-
5
- import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js"
6
- import SlButtonGroup from "@shoelace-style/shoelace/dist/components/button-group/button-group.component.js"
7
- import SlDropdown from "@shoelace-style/shoelace/dist/components/dropdown/dropdown.component.js"
8
- import SlMenu from "@shoelace-style/shoelace/dist/components/menu/menu.component.js"
9
- import SlMenuItem from "@shoelace-style/shoelace/dist/components/menu-item/menu-item.component.js"
10
- import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.component.js"
11
- import IconUIChecksGrid from "bootstrap-icons/icons/ui-checks-grid.svg"
12
- import Icon123 from "bootstrap-icons/icons/123.svg"
13
- import IconCardText from "bootstrap-icons/icons/card-text.svg"
14
- import IconHighlighter from "bootstrap-icons/icons/highlighter.svg"
15
- import IconSubtract from "bootstrap-icons/icons/subtract.svg"
16
- import IconBodyText from "bootstrap-icons/icons/body-text.svg"
17
- import IconMic from "bootstrap-icons/icons/mic.svg"
18
- import IconImage from "bootstrap-icons/icons/image.svg"
19
- import IconSearch from "bootstrap-icons/icons/search.svg"
20
- import IconGrid3x3Gap from "bootstrap-icons/icons/grid-3x3-gap.svg"
21
-
22
- import "@shoelace-style/shoelace/dist/themes/light.css"
23
- import type { WebwriterTask } from "./webwriter-task.js"
24
-
25
-
26
- function shuffle<T>(a: T[]) {
27
- for (let i = a.length - 1; i > 0; i--) {
28
- const j = Math.floor(Math.random() * (i + 1));
29
- [a[i], a[j]] = [a[j], a[i]];
30
- }
31
- return a;
32
- }
33
-
34
- declare global {interface HTMLElementTagNameMap {
35
- "webwriter-quiz": WebwriterQuiz;
36
- }}
37
-
38
- @customElement("webwriter-quiz")
39
- export class WebwriterQuiz extends LitElementWw {
40
-
41
- static localization = {}
42
-
43
- msg = (str: string) => this.lang in WebwriterQuiz.localization? WebwriterQuiz.localization[this.lang][str] ?? str: str
44
-
45
- get answerTypes() {
46
- return {
47
- "webwriter-choice": {
48
- label: this.msg("Choice"),
49
- icon: IconUIChecksGrid
50
- },
51
- "webwriter-order": {
52
- label: this.msg("Order"),
53
- icon: Icon123
54
- },
55
- "webwriter-text": {
56
- label: this.msg("Text"),
57
- icon: IconCardText
58
- },
59
- "webwriter-mark": {
60
- label: this.msg("Mark"),
61
- icon: IconHighlighter
62
- },/*
63
- "webwriter-pairing": {
64
- label: this.msg("Pairing"),
65
- icon: IconSubtract
66
- },
67
- "webwriter-cloze": {
68
- label: this.msg("Cloze"),
69
- icon: IconBodyText
70
- },*/
71
- "webwriter-speech": {
72
- label: this.msg("Speech"),
73
- //advanced: true,
74
- icon: IconMic
75
- },
76
- /*"webwriter-wordsearch": {
77
- label: this.msg("Word Search"),
78
- advanced: true,
79
- icon: IconSearch
80
- },
81
- "webwriter-memory": {
82
- label: this.msg("Memory"),
83
- advanced: true,
84
- icon: IconGrid3x3Gap
85
- }*/
86
- }
87
- }
88
-
89
- static scopedElements = {
90
- "sl-button": SlButton,
91
- "sl-button-group": SlButtonGroup,
92
- "sl-icon": SlIcon,
93
- "sl-dropdown": SlDropdown,
94
- "sl-menu": SlMenu,
95
- "sl-menu-item": SlMenuItem,
96
- }
97
-
98
- addTask(answerTypeName: string) {
99
- const task = this.ownerDocument.createElement("webwriter-task") as WebwriterTask
100
- task.setAttribute("counter", this.counter)
101
- const prompt = this.ownerDocument.createElement("webwriter-task-prompt")
102
- const p = this.ownerDocument.createElement("p")
103
- prompt.append(p)
104
- prompt.slot = "prompt"
105
- const answer = this.ownerDocument.createElement(answerTypeName)
106
- task.appendChild(prompt)
107
- task.appendChild(answer)
108
- this.appendChild(task)
109
- document.getSelection().setBaseAndExtent(p, 0, p, 0)
110
- }
111
-
112
- static styles = css`
113
- :host {
114
- border-top: 1px solid darkgray;
115
- border-bottom: 1px solid darkgray;
116
- padding: 1ch;
117
- display: flex !important;
118
- flex-direction: column;
119
- gap: 2rem;
120
- counter-reset: task;
121
- }
122
-
123
- :host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
124
- display: none;
125
- }
126
-
127
- :host(:is([contenteditable=true], [contenteditable=""])) .user-only {
128
- display: none;
129
- }
130
-
131
- :host(:is([contenteditable=true], [contenteditable=""])) ::slotted(*) {
132
- order: unset !important;
133
- }
134
-
135
- sl-button-group::part(base) {
136
- display: flex;
137
- }
138
-
139
- sl-button-group > *:not(sl-dropdown) {
140
- flex-grow: 1;
141
- }
142
-
143
- sl-dropdown[data-empty] {
144
- display: none;
145
- }
146
-
147
- sl-button:not([caret])::part(label) {
148
- padding: 0;
149
- display: flex;
150
- flex-direction: row;
151
- width: 100%;
152
- justify-content: space-evenly;
153
- align-items: center;
154
- }
155
-
156
- sl-icon {
157
- width: 18px;
158
- height: 18px;
159
- }
160
-
161
- sl-menu::part(menu) {
162
- z-index: 10000;
163
- }
164
-
165
- .user-actions {
166
- & #submit {
167
- flex-grow: 3;
168
- }
169
-
170
- & #reset {
171
- flex-grow: 1;
172
- }
173
- }
174
- `
175
-
176
- @property({type: Boolean, attribute: true, reflect: true})
177
- @option({type: Boolean, label: {"en": "Random Task Order"}})
178
- accessor randomOrder = false
179
-
180
- get counter(): "number" | "roman" | "roman-capitalized" | "alphabetical" | "alphabetical-capitalized" {
181
- return this.tasks[0]?.counter
182
- }
183
-
184
- @property({attribute: true}) //@ts-ignore
185
- @option({
186
- type: "select",
187
- label: {
188
- "en": "Counter"
189
- },
190
- options: [
191
- {value: undefined, label: {"en": "None"}},
192
- {value: "number", label: {"en": "1. 2. 3."}},
193
- {value: "roman", label: {"en": "i. ii. iii."}},
194
- {value: "roman-capitalized", label: {"en": "I. II. III."}},
195
- {value: "alphabetical", label: {"en": "a. b. c."}},
196
- {value: "alphabetical-capitalized", label: {"en": "A. B. C."}},
197
- ]
198
- })
199
- set counter(value) {
200
- this.tasks.forEach(el => el.counter = value)
201
- }
202
-
203
- shuffleTasks() {
204
- const n = this.tasks.length
205
- const nums = shuffle([...(new Array(n)).keys()])
206
- this.tasks.forEach((el, i) => el.style.order = String(nums[i]))
207
- }
208
-
209
- handleSubmit(e: Event) {
210
- this.submitted = true
211
- this.dispatchEvent(new Event("submit"))
212
- this.tasks.forEach(task => task.handleSubmit())
213
- }
214
-
215
- handleReset = () => {
216
- this.tasks.forEach(task => task.reset())
217
- this.requestUpdate()
218
- this.submitted = false
219
- }
220
-
221
- observer: MutationObserver
222
-
223
- connectedCallback(): void {
224
- super.connectedCallback()
225
- this.observer = new MutationObserver(() => {
226
- if(!this.contentEditable && this.randomOrder) {
227
- this.shuffleTasks()
228
- }
229
- })
230
- this.observer.observe(this, {childList: true})
231
- }
232
-
233
- disconnectedCallback(): void {
234
- super.disconnectedCallback()
235
- this.observer.disconnect()
236
- }
237
-
238
- @query("slot")
239
- accessor slotEl: HTMLSlotElement
240
-
241
- @queryAssignedElements()
242
- accessor tasks: WebwriterTask[]
243
-
244
- @property({type: Boolean, attribute: true, reflect: true})
245
- accessor submitted = false
246
-
247
- get isChanged() {
248
- return this.tasks.some(task => task.isChanged)
249
- }
250
-
251
- render() {
252
- const basicAnswerTypes = Object.keys(this.answerTypes).filter(k => !this.answerTypes[k]?.advanced)
253
- const otherAnswerTypes = Object.keys(this.answerTypes).filter(k => this.answerTypes[k]?.advanced)
254
- return html`
255
- <slot ?inert=${this.submitted} @ww-answer-change=${() => this.requestUpdate()}></slot>
256
- <sl-button-group class="user-only user-actions">
257
- <sl-button id="submit" @click=${this.handleSubmit}>Submit</sl-button>
258
- <sl-button ?disabled=${!this.isChanged} id="reset" @click=${this.handleReset}>Reset</sl-button>
259
- </sl-button-group>
260
- <sl-button-group class="author-only">
261
- ${basicAnswerTypes.map(k => html`
262
- <sl-button @click=${() => this.addTask(k)}>
263
- <sl-icon src=${this.answerTypes[k]?.icon}></sl-icon>
264
- ${this.answerTypes[k].label}
265
- </sl-button>
266
- `)}
267
- <sl-dropdown data-empty=${!otherAnswerTypes.length} placement="bottom-end" hoist>
268
- <sl-button slot="trigger" caret></sl-button>
269
- <sl-menu>
270
- ${otherAnswerTypes.map(k => html`
271
- <sl-menu-item @click=${() => this.addTask(k)}>
272
- <sl-icon src=${this.answerTypes[k]?.icon}></sl-icon>
273
- ${this.answerTypes[k].label}
274
- </sl-menu-item>
275
- `)}
276
- </sl-menu>
277
- </sl-dropdown>
278
- </sl-button-group>
279
- `
280
- }
1
+ import {css, html, PropertyValues} from "lit"
2
+ import {LitElementWw, option} from "@webwriter/lit"
3
+ import {customElement, property, query, queryAssignedElements} from "lit/decorators.js"
4
+
5
+ import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js"
6
+ import SlButtonGroup from "@shoelace-style/shoelace/dist/components/button-group/button-group.component.js"
7
+ import SlDropdown from "@shoelace-style/shoelace/dist/components/dropdown/dropdown.component.js"
8
+ import SlMenu from "@shoelace-style/shoelace/dist/components/menu/menu.component.js"
9
+ import SlMenuItem from "@shoelace-style/shoelace/dist/components/menu-item/menu-item.component.js"
10
+ import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.component.js"
11
+ import IconUIChecksGrid from "bootstrap-icons/icons/ui-checks-grid.svg"
12
+ import Icon123 from "bootstrap-icons/icons/123.svg"
13
+ import IconCardText from "bootstrap-icons/icons/card-text.svg"
14
+ import IconHighlighter from "bootstrap-icons/icons/highlighter.svg"
15
+ import IconSubtract from "bootstrap-icons/icons/subtract.svg"
16
+ import IconBodyText from "bootstrap-icons/icons/body-text.svg"
17
+ import IconMic from "bootstrap-icons/icons/mic.svg"
18
+ import IconImage from "bootstrap-icons/icons/image.svg"
19
+ import IconSearch from "bootstrap-icons/icons/search.svg"
20
+ import IconGrid3x3Gap from "bootstrap-icons/icons/grid-3x3-gap.svg"
21
+
22
+ import "@shoelace-style/shoelace/dist/themes/light.css"
23
+ import type { WebwriterTask } from "./webwriter-task.js"
24
+
25
+ import LOCALIZE from "../../localization/generated"
26
+ import {msg} from "@lit/localize"
27
+
28
+
29
+ function shuffle<T>(a: T[]) {
30
+ for (let i = a.length - 1; i > 0; i--) {
31
+ const j = Math.floor(Math.random() * (i + 1));
32
+ [a[i], a[j]] = [a[j], a[i]];
33
+ }
34
+ return a;
35
+ }
36
+
37
+ declare global {interface HTMLElementTagNameMap {
38
+ "webwriter-quiz": WebwriterQuiz;
39
+ }}
40
+
41
+ @customElement("webwriter-quiz")
42
+ export class WebwriterQuiz extends LitElementWw {
43
+
44
+ localize = LOCALIZE
45
+
46
+ get answerTypes() {
47
+ return {
48
+ "webwriter-choice": {
49
+ label: msg("Choice"),
50
+ icon: IconUIChecksGrid
51
+ },
52
+ "webwriter-order": {
53
+ label: msg("Order"),
54
+ icon: Icon123
55
+ },
56
+ "webwriter-text": {
57
+ label: msg("Text"),
58
+ icon: IconCardText
59
+ },
60
+ "webwriter-mark": {
61
+ label: msg("Mark"),
62
+ icon: IconHighlighter
63
+ },/*
64
+ "webwriter-pairing": {
65
+ label: this.msg("Pairing"),
66
+ icon: IconSubtract
67
+ },
68
+ "webwriter-cloze": {
69
+ label: this.msg("Cloze"),
70
+ icon: IconBodyText
71
+ },*/
72
+ "webwriter-speech": {
73
+ label: msg("Speech"),
74
+ //advanced: true,
75
+ icon: IconMic
76
+ },
77
+ /*"webwriter-wordsearch": {
78
+ label: this.msg("Word Search"),
79
+ advanced: true,
80
+ icon: IconSearch
81
+ },
82
+ "webwriter-memory": {
83
+ label: this.msg("Memory"),
84
+ advanced: true,
85
+ icon: IconGrid3x3Gap
86
+ }*/
87
+ }
88
+ }
89
+
90
+ static scopedElements = {
91
+ "sl-button": SlButton,
92
+ "sl-button-group": SlButtonGroup,
93
+ "sl-icon": SlIcon,
94
+ "sl-dropdown": SlDropdown,
95
+ "sl-menu": SlMenu,
96
+ "sl-menu-item": SlMenuItem,
97
+ }
98
+
99
+ addTask(answerTypeName: string) {
100
+ const task = this.ownerDocument.createElement("webwriter-task") as WebwriterTask
101
+ task.setAttribute("counter", this.counter)
102
+ const prompt = this.ownerDocument.createElement("webwriter-task-prompt")
103
+ const p = this.ownerDocument.createElement("p")
104
+ prompt.append(p)
105
+ prompt.slot = "prompt"
106
+ const answer = this.ownerDocument.createElement(answerTypeName)
107
+ task.appendChild(prompt)
108
+ task.appendChild(answer)
109
+ this.appendChild(task)
110
+ document.getSelection().setBaseAndExtent(p, 0, p, 0)
111
+ }
112
+
113
+ static styles = css`
114
+ :host {
115
+ border-top: 1px solid darkgray;
116
+ border-bottom: 1px solid darkgray;
117
+ padding: 1ch;
118
+ display: flex !important;
119
+ flex-direction: column;
120
+ gap: 2rem;
121
+ counter-reset: task;
122
+ }
123
+
124
+ :host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
125
+ display: none;
126
+ }
127
+
128
+ :host(:is([contenteditable=true], [contenteditable=""])) .user-only {
129
+ display: none;
130
+ }
131
+
132
+ :host(:is([contenteditable=true], [contenteditable=""])) ::slotted(*) {
133
+ order: unset !important;
134
+ }
135
+
136
+ sl-button-group::part(base) {
137
+ display: flex;
138
+ }
139
+
140
+ sl-button-group > *:not(sl-dropdown) {
141
+ flex-grow: 1;
142
+ }
143
+
144
+ sl-dropdown[data-empty] {
145
+ display: none;
146
+ }
147
+
148
+ sl-button:not([caret])::part(label) {
149
+ padding: 0;
150
+ display: flex;
151
+ flex-direction: row;
152
+ width: 100%;
153
+ justify-content: space-evenly;
154
+ align-items: center;
155
+ }
156
+
157
+ sl-icon {
158
+ width: 18px;
159
+ height: 18px;
160
+ }
161
+
162
+ sl-menu::part(menu) {
163
+ z-index: 10000;
164
+ }
165
+
166
+ .user-actions {
167
+ & #submit {
168
+ flex-grow: 3;
169
+ }
170
+
171
+ & #reset {
172
+ flex-grow: 1;
173
+ }
174
+ }
175
+ `
176
+
177
+ @property({type: Boolean, attribute: true, reflect: true})
178
+ @option({type: Boolean, label: {"en": "Random Task Order"}})
179
+ accessor randomOrder = false
180
+
181
+ get counter(): "number" | "roman" | "roman-capitalized" | "alphabetical" | "alphabetical-capitalized" {
182
+ return this.tasks[0]?.counter
183
+ }
184
+
185
+ @property({attribute: true}) //@ts-ignore
186
+ @option({
187
+ type: "select",
188
+ label: {
189
+ "en": "Counter"
190
+ },
191
+ options: [
192
+ {value: undefined, label: {"en": "None"}},
193
+ {value: "number", label: {"en": "1. 2. 3."}},
194
+ {value: "roman", label: {"en": "i. ii. iii."}},
195
+ {value: "roman-capitalized", label: {"en": "I. II. III."}},
196
+ {value: "alphabetical", label: {"en": "a. b. c."}},
197
+ {value: "alphabetical-capitalized", label: {"en": "A. B. C."}},
198
+ ]
199
+ })
200
+ set counter(value) {
201
+ this.tasks.forEach(el => el.counter = value)
202
+ }
203
+
204
+ shuffleTasks() {
205
+ const n = this.tasks.length
206
+ const nums = shuffle([...(new Array(n)).keys()])
207
+ this.tasks.forEach((el, i) => el.style.order = String(nums[i]))
208
+ }
209
+
210
+ handleSubmit(e: Event) {
211
+ this.submitted = true
212
+ this.dispatchEvent(new Event("submit"))
213
+ this.tasks.forEach(task => task.handleSubmit())
214
+ }
215
+
216
+ handleReset = () => {
217
+ this.tasks.forEach(task => task.reset())
218
+ this.requestUpdate()
219
+ this.submitted = false
220
+ }
221
+
222
+ observer: MutationObserver
223
+
224
+ connectedCallback(): void {
225
+ super.connectedCallback()
226
+ this.observer = new MutationObserver(() => {
227
+ if(!this.contentEditable && this.randomOrder) {
228
+ this.shuffleTasks()
229
+ }
230
+ })
231
+ this.observer.observe(this, {childList: true})
232
+ }
233
+
234
+ disconnectedCallback(): void {
235
+ super.disconnectedCallback()
236
+ this.observer.disconnect()
237
+ }
238
+
239
+ @query("slot")
240
+ accessor slotEl: HTMLSlotElement
241
+
242
+ @queryAssignedElements()
243
+ accessor tasks: WebwriterTask[]
244
+
245
+ @property({type: Boolean, attribute: true, reflect: true})
246
+ accessor submitted = false
247
+
248
+ get isChanged() {
249
+ return this.tasks.some(task => task.isChanged)
250
+ }
251
+
252
+ render() {
253
+ const basicAnswerTypes = Object.keys(this.answerTypes).filter(k => !this.answerTypes[k]?.advanced)
254
+ const otherAnswerTypes = Object.keys(this.answerTypes).filter(k => this.answerTypes[k]?.advanced)
255
+ return html`
256
+ <slot ?inert=${this.submitted} @ww-answer-change=${() => this.requestUpdate()}></slot>
257
+ <sl-button-group class="user-only user-actions">
258
+ <sl-button id="submit" @click=${this.handleSubmit}>${msg("Submit")}</sl-button>
259
+ <sl-button ?disabled=${!this.isChanged} id="reset" @click=${this.handleReset}>${msg("Reset")}</sl-button>
260
+ </sl-button-group>
261
+ <sl-button-group class="author-only">
262
+ ${basicAnswerTypes.map(k => html`
263
+ <sl-button @click=${() => this.addTask(k)}>
264
+ <sl-icon src=${this.answerTypes[k]?.icon}></sl-icon>
265
+ ${this.answerTypes[k].label}
266
+ </sl-button>
267
+ `)}
268
+ <sl-dropdown data-empty=${!otherAnswerTypes.length} placement="bottom-end" hoist>
269
+ <sl-button slot="trigger" caret></sl-button>
270
+ <sl-menu>
271
+ ${otherAnswerTypes.map(k => html`
272
+ <sl-menu-item @click=${() => this.addTask(k)}>
273
+ <sl-icon src=${this.answerTypes[k]?.icon}></sl-icon>
274
+ ${this.answerTypes[k].label}
275
+ </sl-menu-item>
276
+ `)}
277
+ </sl-menu>
278
+ </sl-dropdown>
279
+ </sl-button-group>
280
+ `
281
+ }
281
282
  }