@webwriter/quiz 1.0.10 → 1.1.2

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 (104) hide show
  1. package/LICENSE +6 -6
  2. package/custom.d.ts +175 -175
  3. package/dist/widgets/webwriter-choice-item.js +10 -7
  4. package/dist/widgets/webwriter-choice.js +36 -6
  5. package/dist/widgets/webwriter-order-item.js +14 -12
  6. package/dist/widgets/webwriter-order.js +28 -4
  7. package/dist/widgets/webwriter-quiz.js +1 -1
  8. package/dist/widgets/webwriter-task.js +0 -1
  9. package/dist/widgets/webwriter-text.js +26 -9
  10. package/lit-localize.json +14 -14
  11. package/localization/bg.xlf +69 -69
  12. package/localization/cs.xlf +69 -69
  13. package/localization/da.xlf +69 -69
  14. package/localization/de.xlf +74 -74
  15. package/localization/el.xlf +69 -69
  16. package/localization/es.xlf +69 -69
  17. package/localization/et.xlf +69 -69
  18. package/localization/fi.xlf +69 -69
  19. package/localization/fr.xlf +69 -69
  20. package/localization/generated/bg.ts +29 -29
  21. package/localization/generated/cs.ts +29 -29
  22. package/localization/generated/da.ts +29 -29
  23. package/localization/generated/de.ts +29 -29
  24. package/localization/generated/el.ts +29 -29
  25. package/localization/generated/es.ts +29 -29
  26. package/localization/generated/et.ts +29 -29
  27. package/localization/generated/fi.ts +29 -29
  28. package/localization/generated/fr.ts +29 -29
  29. package/localization/generated/hu.ts +29 -29
  30. package/localization/generated/id.ts +29 -29
  31. package/localization/generated/index.js +2 -2
  32. package/localization/generated/it.ts +29 -29
  33. package/localization/generated/ja.ts +29 -29
  34. package/localization/generated/ko.ts +29 -29
  35. package/localization/generated/locale-codes.js +79 -79
  36. package/localization/generated/lt.ts +29 -29
  37. package/localization/generated/lv.ts +29 -29
  38. package/localization/generated/nb.ts +29 -29
  39. package/localization/generated/nl.ts +29 -29
  40. package/localization/generated/pl.ts +29 -29
  41. package/localization/generated/pt-BR.ts +29 -29
  42. package/localization/generated/pt-PT.ts +29 -29
  43. package/localization/generated/ro.ts +29 -29
  44. package/localization/generated/ru.ts +29 -29
  45. package/localization/generated/sk.ts +29 -29
  46. package/localization/generated/sl.ts +29 -29
  47. package/localization/generated/sv.ts +29 -29
  48. package/localization/generated/tr.ts +29 -29
  49. package/localization/generated/uk.ts +29 -29
  50. package/localization/generated/zh-hans.ts +29 -29
  51. package/localization/hu.xlf +69 -69
  52. package/localization/id.xlf +69 -69
  53. package/localization/it.xlf +69 -69
  54. package/localization/ja.xlf +69 -69
  55. package/localization/ko.xlf +69 -69
  56. package/localization/lt.xlf +69 -69
  57. package/localization/lv.xlf +69 -69
  58. package/localization/nb.xlf +69 -69
  59. package/localization/nl.xlf +69 -69
  60. package/localization/pl.xlf +69 -69
  61. package/localization/pt-BR.xlf +69 -69
  62. package/localization/pt-PT.xlf +69 -69
  63. package/localization/ro.xlf +69 -69
  64. package/localization/ru.xlf +69 -69
  65. package/localization/sk.xlf +69 -69
  66. package/localization/sl.xlf +69 -69
  67. package/localization/sv.xlf +69 -69
  68. package/localization/tr.xlf +69 -69
  69. package/localization/uk.xlf +69 -69
  70. package/localization/zh-hans.xlf +69 -69
  71. package/package.json +7 -2
  72. package/src/lib/combobox.ts +455 -455
  73. package/src/lib/highlighter-fill.svg +5 -5
  74. package/src/snippets/Beispiel-Choice.html +57 -57
  75. package/src/snippets/Beispiel-Mark.html +13 -13
  76. package/src/snippets/Beispiel-Order.html +52 -52
  77. package/src/snippets/Beispiel-Text.html +20 -20
  78. package/src/snippets/blank.html +1 -0
  79. package/src/snippets/choice.html +7 -7
  80. package/src/snippets/cloze.html +3 -3
  81. package/src/snippets/mark.html +3 -3
  82. package/src/snippets/order.html +7 -7
  83. package/src/snippets/pairing.html +9 -9
  84. package/src/snippets/speech.html +3 -3
  85. package/src/snippets/text.html +3 -3
  86. package/src/snippets/wordsearch.html +3 -3
  87. package/src/widgets/webwriter-choice-item.ts +253 -250
  88. package/src/widgets/webwriter-choice.ts +336 -314
  89. package/src/widgets/webwriter-cloze-gap.ts +215 -215
  90. package/src/widgets/webwriter-cloze.ts +135 -135
  91. package/src/widgets/webwriter-mark.ts +431 -431
  92. package/src/widgets/webwriter-order-item.ts +440 -437
  93. package/src/widgets/webwriter-order.ts +309 -284
  94. package/src/widgets/webwriter-pairing-item.ts +160 -160
  95. package/src/widgets/webwriter-pairing.ts +192 -192
  96. package/src/widgets/webwriter-quiz.ts +281 -281
  97. package/src/widgets/webwriter-speech.ts +272 -272
  98. package/src/widgets/webwriter-task-explainer.ts +42 -42
  99. package/src/widgets/webwriter-task-hint.ts +22 -22
  100. package/src/widgets/webwriter-task-prompt.ts +23 -23
  101. package/src/widgets/webwriter-task.ts +546 -546
  102. package/src/widgets/webwriter-text.ts +155 -135
  103. package/tsconfig.json +6 -6
  104. package/.env +0 -1
@@ -1,193 +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
- 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
- }
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
+ }
193
193
  }