@webwriter/quiz 1.0.5 → 1.0.7

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 +281 -193
  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,188 +1,193 @@
1
- import {html, css, PropertyValues} from "lit"
2
- import {LitElementWw, option} from "@webwriter/lit"
3
- import {customElement, property, queryAll} from "lit/decorators.js"
4
- import "@shoelace-style/shoelace/dist/themes/light.css"
5
-
6
- import IconPlus from "bootstrap-icons/icons/plus.svg"
7
- import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js"
8
- import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.component.js"
9
- import type { WebwriterPairingItem } from "./webwriter-pairing-item"
10
-
11
- declare global {interface HTMLElementTagNameMap {
12
- "webwriter-pairing": WebwriterPairing;
13
- }}
14
-
15
- @customElement("webwriter-pairing")
16
- export class WebwriterPairing extends LitElementWw {
17
-
18
- static shadowRootOptions = {...LitElementWw.shadowRootOptions, slotAssignment: "manual" as const}
19
-
20
- static scopedElements = {
21
- "sl-button": SlButton,
22
- "sl-icon": SlIcon
23
- }
24
-
25
- static styles = css`
26
- :host {
27
- display: flex !important;
28
- flex-direction: row;
29
- flex-wrap: wrap;
30
- gap: 30px;
31
- padding-bottom: 30px;
32
- }
33
-
34
- sl-button {
35
-
36
- &::part(base) {
37
- width: 125px;
38
- height: 125px;
39
- border: 1px solid darkgray;
40
- border-radius: 2px;
41
- padding: 10px;
42
- overflow: hidden;
43
- }
44
-
45
- &::part(label) {
46
- padding: 0;
47
- display: flex;
48
- flex-direction: row;
49
- align-items: center;
50
- justify-content: center;
51
- }
52
- }
53
-
54
- .pair {
55
- position: relative;
56
-
57
- & .a-slot, & .b-slot {
58
- display: block;
59
-
60
- &:is(:focus-within, :has(::selection)) {
61
- background: green;
62
- }
63
- }
64
-
65
- & .b-slot {
66
- position: absolute;
67
- left: 20px;
68
- top: 20px;
69
- z-index: 1000;
70
- }
71
- }
72
-
73
- `
74
-
75
- @property({attribute: true, reflect: true})
76
- @option({type: "select", options: [
77
- {value: "drag"},
78
- {value: "memory"}
79
- ]})
80
- accessor mode: "drag" | "memory" = "drag"
81
-
82
- @property({type: Array, attribute: true, reflect: true})
83
- accessor solution: ([string, string] | string)[] = []
84
-
85
- addItem = () => {
86
- const item = document.createElement("webwriter-pairing-item")
87
- const picture = document.createElement("picture")
88
- item.appendChild(picture)
89
- this.appendChild(item)
90
- }
91
-
92
- Pair = (i: number) => {
93
- return html`<div class="pair">
94
- <slot class="a-slot" name=${`${i}a`}></slot>
95
- <slot class="b-slot" name=${`${i}b`}></slot>
96
- </div>`
97
- }
98
-
99
- getPairSlot() {}
100
-
101
-
102
- get pairs() {
103
- let allPairs = Array.from(this.children) as (WebwriterPairingItem | [WebwriterPairingItem, WebwriterPairingItem])[]
104
- for(const [a, b] of this.solution) {
105
- const elA = this.querySelector(`webwriter-pairing-item#${a}`) as WebwriterPairingItem
106
- const elB = this.querySelector(`webwriter-pairing-item#${b}`) as WebwriterPairingItem
107
- allPairs.splice(allPairs.indexOf(elA), 1, [elA, elB])
108
- allPairs.splice(allPairs.indexOf(elB), 1)
109
- }
110
- return allPairs
111
- }
112
-
113
- pair(a: string, b?: string) {
114
- let pairIds = this.pairs.map(entry => Array.isArray(entry)? [entry[0].id, entry[1].id]: entry.id)
115
- const pairIndexOfA = this.solution.findIndex(val => Array.isArray(val) && val.includes(a))
116
- const pairIndexOfB = this.solution.findIndex(val => Array.isArray(val) && val.includes(b))
117
- if(!b) {
118
- pairIds.splice(pairIndexOfA, 1, (pairIds[pairIndexOfA] as [string, string]).filter(id => id !== a)[0])
119
- pairIds.push(a)
120
- }
121
- else {
122
- if(pairIndexOfB !== -1) {
123
- pairIds.splice(pairIndexOfB, 1, (pairIds[pairIndexOfB] as [string, string]).filter(id => id !== b)[0])
124
- }
125
- const indexOfA = this.solution.indexOf(a)
126
- pairIds.splice(indexOfA, 1, [a, b])
127
- pairIds = pairIds.filter(id => id !== b)
128
- }
129
- this.solution = pairIds.filter(entry => Array.isArray(entry)) as any
130
- }
131
-
132
- handlePairWith(e: CustomEvent) {
133
- if(e.type === "ww-pairwith") {
134
- this.pair((e.target as HTMLElement).id, e.detail.with)
135
- }
136
- }
137
-
138
- observer: MutationObserver
139
-
140
- connectedCallback(): void {
141
- super.connectedCallback()
142
- this.observer = new MutationObserver(() => {
143
- let childIds = Array.from(this.children).map(child => child.id)
144
- let solution = [...this.solution]
145
- // solution = solution.filter(k => childIds.includes(k as any))
146
- // solution = [...solution, ...childIds]
147
- this.requestUpdate()
148
- })
149
- this.observer.observe(this, {childList: true})
150
- this.addEventListener("ww-pairwith", this.handlePairWith)
151
- }
152
-
153
- disconnectedCallback(): void {
154
- super.disconnectedCallback()
155
- this.observer.disconnect()
156
- }
157
-
158
- protected willUpdate(_changedProperties: PropertyValues): void {
159
- // this.solution = this.solution.filter(id => childIds.includes(id))
160
- }
161
-
162
- protected updated(_changedProperties: PropertyValues): void {
163
- const slots = Array.from(this.slots)
164
- for(const value of this.pairs) {
165
- if(Array.isArray(value)) {
166
- const [a, b] = value
167
- slots.shift().assign(a)
168
- slots.shift().assign(b)
169
- }
170
- else {
171
- slots.shift().assign(value)
172
- slots.shift()
173
- }
174
- }
175
- }
176
-
177
- @queryAll("slot")
178
- accessor slots: NodeListOf<HTMLSlotElement>
179
-
180
- render() {
181
- return html`
182
- ${this.pairs.map((el, i) => this.Pair(i))}
183
- <sl-button @click=${this.addItem}>
184
- <sl-icon src=${IconPlus}></sl-icon>
185
- </sl-button>
186
- `
187
- }
1
+ import {html, css, PropertyValues} from "lit"
2
+ import {LitElementWw, option} from "@webwriter/lit"
3
+ import {customElement, property, queryAll} from "lit/decorators.js"
4
+ import "@shoelace-style/shoelace/dist/themes/light.css"
5
+
6
+ import IconPlus from "bootstrap-icons/icons/plus.svg"
7
+ import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js"
8
+ import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.component.js"
9
+ import type { WebwriterPairingItem } from "./webwriter-pairing-item"
10
+
11
+ import LOCALIZE from "../../localization/generated"
12
+ import {msg} from "@lit/localize"
13
+
14
+ declare global {interface HTMLElementTagNameMap {
15
+ "webwriter-pairing": WebwriterPairing;
16
+ }}
17
+
18
+ @customElement("webwriter-pairing")
19
+ export class WebwriterPairing extends LitElementWw {
20
+
21
+ localize = LOCALIZE
22
+
23
+ static shadowRootOptions = {...LitElementWw.shadowRootOptions, slotAssignment: "manual" as const}
24
+
25
+ static scopedElements = {
26
+ "sl-button": SlButton,
27
+ "sl-icon": SlIcon
28
+ }
29
+
30
+ static styles = css`
31
+ :host {
32
+ display: flex !important;
33
+ flex-direction: row;
34
+ flex-wrap: wrap;
35
+ gap: 30px;
36
+ padding-bottom: 30px;
37
+ }
38
+
39
+ sl-button {
40
+
41
+ &::part(base) {
42
+ width: 125px;
43
+ height: 125px;
44
+ border: 1px solid darkgray;
45
+ border-radius: 2px;
46
+ padding: 10px;
47
+ overflow: hidden;
48
+ }
49
+
50
+ &::part(label) {
51
+ padding: 0;
52
+ display: flex;
53
+ flex-direction: row;
54
+ align-items: center;
55
+ justify-content: center;
56
+ }
57
+ }
58
+
59
+ .pair {
60
+ position: relative;
61
+
62
+ & .a-slot, & .b-slot {
63
+ display: block;
64
+
65
+ &:is(:focus-within, :has(::selection)) {
66
+ background: green;
67
+ }
68
+ }
69
+
70
+ & .b-slot {
71
+ position: absolute;
72
+ left: 20px;
73
+ top: 20px;
74
+ z-index: 1000;
75
+ }
76
+ }
77
+
78
+ `
79
+
80
+ @property({attribute: true, reflect: true})
81
+ @option({type: "select", options: [
82
+ {value: "drag"},
83
+ {value: "memory"}
84
+ ]})
85
+ accessor mode: "drag" | "memory" = "drag"
86
+
87
+ @property({type: Array, attribute: true, reflect: true})
88
+ accessor solution: ([string, string] | string)[] = []
89
+
90
+ addItem = () => {
91
+ const item = document.createElement("webwriter-pairing-item")
92
+ const picture = document.createElement("picture")
93
+ item.appendChild(picture)
94
+ this.appendChild(item)
95
+ }
96
+
97
+ Pair = (i: number) => {
98
+ return html`<div class="pair">
99
+ <slot class="a-slot" name=${`${i}a`}></slot>
100
+ <slot class="b-slot" name=${`${i}b`}></slot>
101
+ </div>`
102
+ }
103
+
104
+ getPairSlot() {}
105
+
106
+
107
+ get pairs() {
108
+ let allPairs = Array.from(this.children) as (WebwriterPairingItem | [WebwriterPairingItem, WebwriterPairingItem])[]
109
+ for(const [a, b] of this.solution) {
110
+ const elA = this.querySelector(`webwriter-pairing-item#${a}`) as WebwriterPairingItem
111
+ const elB = this.querySelector(`webwriter-pairing-item#${b}`) as WebwriterPairingItem
112
+ allPairs.splice(allPairs.indexOf(elA), 1, [elA, elB])
113
+ allPairs.splice(allPairs.indexOf(elB), 1)
114
+ }
115
+ return allPairs
116
+ }
117
+
118
+ pair(a: string, b?: string) {
119
+ let pairIds = this.pairs.map(entry => Array.isArray(entry)? [entry[0].id, entry[1].id]: entry.id)
120
+ const pairIndexOfA = this.solution.findIndex(val => Array.isArray(val) && val.includes(a))
121
+ const pairIndexOfB = this.solution.findIndex(val => Array.isArray(val) && val.includes(b))
122
+ if(!b) {
123
+ pairIds.splice(pairIndexOfA, 1, (pairIds[pairIndexOfA] as [string, string]).filter(id => id !== a)[0])
124
+ pairIds.push(a)
125
+ }
126
+ else {
127
+ if(pairIndexOfB !== -1) {
128
+ pairIds.splice(pairIndexOfB, 1, (pairIds[pairIndexOfB] as [string, string]).filter(id => id !== b)[0])
129
+ }
130
+ const indexOfA = this.solution.indexOf(a)
131
+ pairIds.splice(indexOfA, 1, [a, b])
132
+ pairIds = pairIds.filter(id => id !== b)
133
+ }
134
+ this.solution = pairIds.filter(entry => Array.isArray(entry)) as any
135
+ }
136
+
137
+ handlePairWith(e: CustomEvent) {
138
+ if(e.type === "ww-pairwith") {
139
+ this.pair((e.target as HTMLElement).id, e.detail.with)
140
+ }
141
+ }
142
+
143
+ observer: MutationObserver
144
+
145
+ connectedCallback(): void {
146
+ super.connectedCallback()
147
+ this.observer = new MutationObserver(() => {
148
+ let childIds = Array.from(this.children).map(child => child.id)
149
+ let solution = [...this.solution]
150
+ // solution = solution.filter(k => childIds.includes(k as any))
151
+ // solution = [...solution, ...childIds]
152
+ this.requestUpdate()
153
+ })
154
+ this.observer.observe(this, {childList: true})
155
+ this.addEventListener("ww-pairwith", this.handlePairWith)
156
+ }
157
+
158
+ disconnectedCallback(): void {
159
+ super.disconnectedCallback()
160
+ this.observer.disconnect()
161
+ }
162
+
163
+ protected willUpdate(_changedProperties: PropertyValues): void {
164
+ // this.solution = this.solution.filter(id => childIds.includes(id))
165
+ }
166
+
167
+ protected updated(_changedProperties: PropertyValues): void {
168
+ const slots = Array.from(this.slots)
169
+ for(const value of this.pairs) {
170
+ if(Array.isArray(value)) {
171
+ const [a, b] = value
172
+ slots.shift().assign(a)
173
+ slots.shift().assign(b)
174
+ }
175
+ else {
176
+ slots.shift().assign(value)
177
+ slots.shift()
178
+ }
179
+ }
180
+ }
181
+
182
+ @queryAll("slot")
183
+ accessor slots: NodeListOf<HTMLSlotElement>
184
+
185
+ render() {
186
+ return html`
187
+ ${this.pairs.map((el, i) => this.Pair(i))}
188
+ <sl-button @click=${this.addItem}>
189
+ <sl-icon src=${IconPlus}></sl-icon>
190
+ </sl-button>
191
+ `
192
+ }
188
193
  }