@webwriter/quiz 1.0.3 → 1.0.5

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/LICENSE +6 -6
  2. package/custom.d.ts +175 -175
  3. package/dist/widgets/webwriter-choice-item.js +58 -13
  4. package/dist/widgets/webwriter-choice.js +64 -19
  5. package/dist/widgets/webwriter-cloze-gap.js +59 -14
  6. package/dist/widgets/webwriter-cloze.js +56 -11
  7. package/dist/widgets/webwriter-mark.js +56 -11
  8. package/dist/widgets/webwriter-order-item.js +56 -11
  9. package/dist/widgets/webwriter-order.js +226 -1685
  10. package/dist/widgets/webwriter-pairing.js +59 -14
  11. package/dist/widgets/webwriter-quiz.js +67 -22
  12. package/dist/widgets/webwriter-speech.js +66 -20
  13. package/dist/widgets/webwriter-task.js +534 -308
  14. package/dist/widgets/webwriter-text.js +60 -14
  15. package/package.json +200 -200
  16. package/src/lib/combobox.ts +455 -455
  17. package/src/snippets/choice.html +7 -7
  18. package/src/snippets/cloze.html +3 -3
  19. package/src/snippets/mark.html +3 -3
  20. package/src/snippets/order.html +7 -7
  21. package/src/snippets/pairing.html +9 -9
  22. package/src/snippets/speech.html +3 -3
  23. package/src/snippets/text.html +3 -3
  24. package/src/snippets/wordsearch.html +3 -3
  25. package/src/widgets/webwriter-choice-item.ts +250 -250
  26. package/src/widgets/webwriter-choice.ts +309 -309
  27. package/src/widgets/webwriter-cloze-gap.ts +216 -216
  28. package/src/widgets/webwriter-cloze.ts +135 -135
  29. package/src/widgets/webwriter-mark.ts +434 -434
  30. package/src/widgets/webwriter-order-item.ts +436 -444
  31. package/src/widgets/webwriter-order.ts +279 -272
  32. package/src/widgets/webwriter-pairing-item.ts +155 -155
  33. package/src/widgets/webwriter-pairing.ts +187 -187
  34. package/src/widgets/webwriter-quiz.ts +280 -280
  35. package/src/widgets/webwriter-speech.ts +267 -267
  36. package/src/widgets/webwriter-task-explainer.ts +37 -37
  37. package/src/widgets/webwriter-task-hint.ts +16 -16
  38. package/src/widgets/webwriter-task-prompt.ts +17 -17
  39. package/src/widgets/webwriter-task.ts +543 -543
  40. package/src/widgets/webwriter-text.ts +130 -130
  41. package/tsconfig.json +6 -6
@@ -1,281 +1,281 @@
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 { 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
+
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
+ }
281
281
  }