@webwriter/quiz 1.0.0
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.
- package/LICENSE +7 -0
- package/custom.d.ts +176 -0
- package/dist/widgets/webwriter-choice-item.css +444 -0
- package/dist/widgets/webwriter-choice-item.js +288 -0
- package/dist/widgets/webwriter-choice.css +444 -0
- package/dist/widgets/webwriter-choice.js +327 -0
- package/dist/widgets/webwriter-cloze-gap.css +444 -0
- package/dist/widgets/webwriter-cloze-gap.js +722 -0
- package/dist/widgets/webwriter-cloze.css +444 -0
- package/dist/widgets/webwriter-cloze.js +177 -0
- package/dist/widgets/webwriter-mark.css +444 -0
- package/dist/widgets/webwriter-mark.js +410 -0
- package/dist/widgets/webwriter-order-item.css +444 -0
- package/dist/widgets/webwriter-order-item.js +464 -0
- package/dist/widgets/webwriter-order.css +444 -0
- package/dist/widgets/webwriter-order.js +560 -0
- package/dist/widgets/webwriter-pairing-item.css +444 -0
- package/dist/widgets/webwriter-pairing-item.js +203 -0
- package/dist/widgets/webwriter-pairing.css +444 -0
- package/dist/widgets/webwriter-pairing.js +224 -0
- package/dist/widgets/webwriter-quiz.css +444 -0
- package/dist/widgets/webwriter-quiz.js +323 -0
- package/dist/widgets/webwriter-speech.css +444 -0
- package/dist/widgets/webwriter-speech.js +320 -0
- package/dist/widgets/webwriter-task-explainer.css +444 -0
- package/dist/widgets/webwriter-task-explainer.js +90 -0
- package/dist/widgets/webwriter-task-hint.css +444 -0
- package/dist/widgets/webwriter-task-hint.js +67 -0
- package/dist/widgets/webwriter-task-prompt.css +444 -0
- package/dist/widgets/webwriter-task-prompt.js +68 -0
- package/dist/widgets/webwriter-task.css +444 -0
- package/dist/widgets/webwriter-task.js +546 -0
- package/dist/widgets/webwriter-text.css +444 -0
- package/dist/widgets/webwriter-text.js +174 -0
- package/package.json +199 -0
- package/src/lib/combobox.ts +456 -0
- package/src/lib/highlighter-fill.svg +6 -0
- package/src/snippets/choice.html +8 -0
- package/src/snippets/cloze.html +4 -0
- package/src/snippets/mark.html +4 -0
- package/src/snippets/order.html +8 -0
- package/src/snippets/pairing.html +10 -0
- package/src/snippets/speech.html +4 -0
- package/src/snippets/text.html +4 -0
- package/src/snippets/wordsearch.html +4 -0
- package/src/widgets/webwriter-choice-item.ts +251 -0
- package/src/widgets/webwriter-choice.ts +310 -0
- package/src/widgets/webwriter-cloze-gap.ts +217 -0
- package/src/widgets/webwriter-cloze.ts +136 -0
- package/src/widgets/webwriter-mark.ts +435 -0
- package/src/widgets/webwriter-order-item.ts +445 -0
- package/src/widgets/webwriter-order.ts +273 -0
- package/src/widgets/webwriter-pairing-item.ts +156 -0
- package/src/widgets/webwriter-pairing.ts +188 -0
- package/src/widgets/webwriter-quiz.ts +281 -0
- package/src/widgets/webwriter-speech.ts +268 -0
- package/src/widgets/webwriter-task-explainer.ts +38 -0
- package/src/widgets/webwriter-task-hint.ts +17 -0
- package/src/widgets/webwriter-task-prompt.ts +18 -0
- package/src/widgets/webwriter-task.ts +544 -0
- package/src/widgets/webwriter-text.ts +131 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {LitElement, html, css, RenderOptions} from "lit"
|
|
2
|
+
import {LitElementWw} from "@webwriter/lit"
|
|
3
|
+
import {customElement, query} from "lit/decorators.js"
|
|
4
|
+
|
|
5
|
+
import SlIconButton from "@shoelace-style/shoelace/dist/components/icon-button/icon-button.component.js"
|
|
6
|
+
import SlOption from "@shoelace-style/shoelace/dist/components/option/option.component.js"
|
|
7
|
+
import IconPlus from "bootstrap-icons/icons/plus.svg"
|
|
8
|
+
import IconSlashCircle from "bootstrap-icons/icons/slash-circle.svg"
|
|
9
|
+
import IconCheckCircle from "bootstrap-icons/icons/check-circle.svg"
|
|
10
|
+
import IconX from "bootstrap-icons/icons/x.svg"
|
|
11
|
+
|
|
12
|
+
import { Combobox } from "../lib/combobox"
|
|
13
|
+
import { property } from "lit/decorators/property.js"
|
|
14
|
+
import { queryAsync } from "lit/decorators/query-async.js"
|
|
15
|
+
import "@shoelace-style/shoelace/dist/themes/light.css"
|
|
16
|
+
|
|
17
|
+
declare global {interface HTMLElementTagNameMap {
|
|
18
|
+
"webwriter-cloze-gap": WebwriterClozeGap;
|
|
19
|
+
}}
|
|
20
|
+
|
|
21
|
+
@customElement("webwriter-cloze-gap")
|
|
22
|
+
export class WebwriterClozeGap extends LitElementWw {
|
|
23
|
+
|
|
24
|
+
static localization = {}
|
|
25
|
+
|
|
26
|
+
@property({type: Array, attribute: true, reflect: true})
|
|
27
|
+
accessor solution: string[]
|
|
28
|
+
|
|
29
|
+
@property({type: String, attribute: true, reflect: true})
|
|
30
|
+
accessor value: string
|
|
31
|
+
|
|
32
|
+
@property({type: Array, attribute: true, reflect: true})
|
|
33
|
+
accessor distraction: string[] = []
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@property({type: Boolean, attribute: true, reflect: true})
|
|
37
|
+
accessor showOptions = false
|
|
38
|
+
|
|
39
|
+
msg = (str: string) => this.lang in WebwriterClozeGap.localization? WebwriterClozeGap.localization[this.lang][str] ?? str: str
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
static scopedElements = {
|
|
43
|
+
"ww-combobox": Combobox,
|
|
44
|
+
"sl-icon-button": SlIconButton,
|
|
45
|
+
"sl-option": SlOption
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static styles = css`
|
|
49
|
+
:host {
|
|
50
|
+
display: inline-block !important;
|
|
51
|
+
vertical-align: top;
|
|
52
|
+
margin: 0 1ch;
|
|
53
|
+
max-width: calc(100% - 2ch);
|
|
54
|
+
max-height: 1lh;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:host(::after) {
|
|
58
|
+
content: " ";
|
|
59
|
+
display: block;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
sl-icon-button[data-hidden] {
|
|
63
|
+
visibility: hidden;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
sl-icon-button::part(base) {
|
|
67
|
+
padding: 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
:host(:not(:focus-within)) #add {
|
|
71
|
+
visibility: hidden;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
sl-icon-button {
|
|
75
|
+
overflow: visible;
|
|
76
|
+
margin-right: 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ww-combobox::part(base) {
|
|
80
|
+
min-height: unset;
|
|
81
|
+
padding: 2px 2px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
:host(:is([contenteditable=true], [contenteditable=""])) ww-combobox::part(input) {
|
|
85
|
+
color: var(--sl-color-success-700);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
sl-option::part(base) {
|
|
89
|
+
padding: 0;
|
|
90
|
+
font-size: var(--sl-input-font-size-small);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
sl-option::part(label) {
|
|
94
|
+
padding: var(--sl-spacing-2x-small) 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
sl-option::part(label):hover {
|
|
98
|
+
color: var(--sl-color-primary-600);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
sl-option::part(checked-icon) {
|
|
102
|
+
display: none;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.remove::part(base):hover {
|
|
106
|
+
color: var(--sl-color-danger-600) !important;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.remove::part(base):active {
|
|
110
|
+
color: var(--sl-color-danger-800) !important;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
:is(.toggle, .remove)::part(base) {
|
|
114
|
+
padding: var(--sl-spacing-2x-small);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.solution::part(base) {
|
|
118
|
+
color: var(--sl-color-success-700);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.toggle {
|
|
122
|
+
color: inherit;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
`
|
|
127
|
+
@query("ww-combobox")
|
|
128
|
+
accessor input: Combobox
|
|
129
|
+
|
|
130
|
+
async focus() {
|
|
131
|
+
(await this.input).focus()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
handleChange = (e: CustomEvent) => {
|
|
135
|
+
e.preventDefault()
|
|
136
|
+
if(!this.isContentEditable) {
|
|
137
|
+
this.value = this.input.value as string
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
addSolution(value: string) {
|
|
142
|
+
this.solution = Array.from(new Set([...(this.solution ?? []), value]))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
toggleOptionType(value: string) {
|
|
146
|
+
if(this.solution.includes(value)) {
|
|
147
|
+
this.solution = this.solution.filter(v => v !== value)
|
|
148
|
+
this.distraction = Array.from(new Set([...(this.distraction ?? []), value]))
|
|
149
|
+
}
|
|
150
|
+
else if(this.distraction.includes(value)) {
|
|
151
|
+
this.distraction = this.distraction.filter(v => v !== value)
|
|
152
|
+
this.solution = Array.from(new Set([...(this.solution ?? []), value]))
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
removeOption(value: string) {
|
|
157
|
+
this.solution = this.solution.filter(v => v !== value)
|
|
158
|
+
this.distraction = this.distraction.filter(v => v !== value)
|
|
159
|
+
if(this.allOptions.length === 0) {
|
|
160
|
+
this.isAdding = false
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
handleAddClick = (e: MouseEvent) => {
|
|
165
|
+
e.stopImmediatePropagation()
|
|
166
|
+
e.preventDefault()
|
|
167
|
+
this.addSolution(this.input.value as string)
|
|
168
|
+
this.isAdding = true
|
|
169
|
+
this.input.value = ""
|
|
170
|
+
this.input.open = true
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
handleToggleClick = (e: MouseEvent, value: string) => {
|
|
174
|
+
e.stopImmediatePropagation()
|
|
175
|
+
e.preventDefault()
|
|
176
|
+
this.toggleOptionType(value)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
handleRemoveClick = (e: MouseEvent, value: string) => {
|
|
180
|
+
e.stopImmediatePropagation()
|
|
181
|
+
e.preventDefault()
|
|
182
|
+
this.removeOption(value)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
handleKeydown = (e: KeyboardEvent) => {
|
|
186
|
+
if(e.key === "Enter") {
|
|
187
|
+
this.handleAddClick(e as any)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
handleBlur = (e: FocusEvent) => {
|
|
192
|
+
this.isAdding = false
|
|
193
|
+
if(this.solution.length === 1) {
|
|
194
|
+
this.input.value = this.solution[0]
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
get allOptions() {
|
|
199
|
+
return [...(this.solution ?? []), ...this.distraction]
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@property({type: Boolean, attribute: false})
|
|
203
|
+
accessor isAdding = false
|
|
204
|
+
|
|
205
|
+
render() {
|
|
206
|
+
return html`<ww-combobox @blur=${this.handleBlur} ?suggestions=${this.allOptions.length > 1 || this.isAdding || this.distraction.length > 0} size="small" autosize .value=${this.value} @sl-change=${this.handleChange} @sl-input=${() => this.requestUpdate()} @keydown=${this.handleKeydown} >
|
|
207
|
+
<sl-icon-button id="add" title="Add another solution" ?disabled=${this.allOptions.includes(this.input?.value as string)} ?data-hidden=${!this.input?.value} src=${IconPlus} size="small" slot="prefix" @click=${this.handleAddClick} @mousedown=${(e: Event) => {e.stopPropagation(); e.preventDefault()}} @focus=${e => e.stopPropagation()} ></sl-icon-button>
|
|
208
|
+
${this.allOptions.sort().map(value => html`
|
|
209
|
+
<sl-option size="small" value=${value} class=${this.solution.includes(value)? "solution": "distraction"} >
|
|
210
|
+
<sl-icon-button title=${this.solution.includes(value)? "Change to a distraction": "Change to a solution"} class="toggle" slot="prefix" src=${this.solution.includes(value)? IconCheckCircle: IconSlashCircle} @click=${(e: any) => this.handleToggleClick(e, value)} @mousedown=${(e: Event) => {e.stopPropagation(); e.preventDefault()}}></sl-icon-button>
|
|
211
|
+
<span title=${this.solution.includes(value)? "Solution": "Distraction"}>${value}</span>
|
|
212
|
+
<sl-icon-button title="Remove" class="remove" slot="suffix" src=${IconX} @click=${(e: any) => this.handleRemoveClick(e, value)} @mousedown=${(e: Event) => {e.stopPropagation(); e.preventDefault()}}></sl-icon-button>
|
|
213
|
+
</sl-option>
|
|
214
|
+
`)}
|
|
215
|
+
</ww-combobox>`
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {html, css, LitElement} from "lit"
|
|
2
|
+
import {LitElementWw} from "@webwriter/lit"
|
|
3
|
+
import {customElement, query} from "lit/decorators.js"
|
|
4
|
+
import {styleMap} from "lit/directives/style-map.js"
|
|
5
|
+
|
|
6
|
+
import SlIconButton from "@shoelace-style/shoelace/dist/components/icon-button/icon-button.component.js"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import IconTextarea from "bootstrap-icons/icons/textarea.svg"
|
|
10
|
+
import { WebwriterClozeGap } from "./webwriter-cloze-gap.js"
|
|
11
|
+
import "@shoelace-style/shoelace/dist/themes/light.css"
|
|
12
|
+
|
|
13
|
+
declare global {interface HTMLElementTagNameMap {
|
|
14
|
+
"webwriter-cloze": WebwriterCloze;
|
|
15
|
+
}}
|
|
16
|
+
|
|
17
|
+
@customElement("webwriter-cloze")
|
|
18
|
+
export class WebwriterCloze extends LitElementWw {
|
|
19
|
+
|
|
20
|
+
static shadowRootOptions: ShadowRootInit = {...LitElementWw.shadowRootOptions, delegatesFocus: false}
|
|
21
|
+
|
|
22
|
+
static localization = {}
|
|
23
|
+
|
|
24
|
+
msg = (str: string) => this.lang in WebwriterCloze.localization? WebwriterCloze.localization[this.lang][str] ?? str: str
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
static scopedElements = {
|
|
28
|
+
"sl-icon-button": SlIconButton
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static styles = css`
|
|
32
|
+
:host {
|
|
33
|
+
min-height: 1rem;
|
|
34
|
+
position: relative;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
slot {
|
|
38
|
+
display: block;
|
|
39
|
+
cursor: text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
slot[data-empty]:after {
|
|
43
|
+
content: var(--placeholder);
|
|
44
|
+
position: absolute;
|
|
45
|
+
left: 0;
|
|
46
|
+
top: 0;
|
|
47
|
+
color: darkgray;
|
|
48
|
+
pointer-events: none;
|
|
49
|
+
user-select: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
slot::after, slot::before {
|
|
53
|
+
content: ' ';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#add-gap {
|
|
57
|
+
position: absolute;
|
|
58
|
+
right: 0;
|
|
59
|
+
top: 0;
|
|
60
|
+
background: rgba(255, 255, 255, 0.85);
|
|
61
|
+
|
|
62
|
+
&[data-highlighting]::part(base) {
|
|
63
|
+
background: var(--sl-color-primary-100);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
|
|
68
|
+
display: none;
|
|
69
|
+
}
|
|
70
|
+
`
|
|
71
|
+
|
|
72
|
+
@query("#add-gap")
|
|
73
|
+
accessor addGapButton: SlIconButton
|
|
74
|
+
|
|
75
|
+
observer: MutationObserver
|
|
76
|
+
|
|
77
|
+
connectedCallback(): void {
|
|
78
|
+
super.connectedCallback()
|
|
79
|
+
document.addEventListener("selectionchange", e => {
|
|
80
|
+
const sel = document.getSelection()
|
|
81
|
+
const node = document.getSelection()?.anchorNode
|
|
82
|
+
const el = node.nodeType === node.TEXT_NODE? node.parentElement: node as HTMLElement
|
|
83
|
+
this.addGapButton.toggleAttribute("data-visible", el?.closest("webwriter-cloze")? true: false)
|
|
84
|
+
if(el?.closest("webwriter-cloze") && !sel.isCollapsed) {
|
|
85
|
+
this.addGapButton.toggleAttribute("data-highlighting", true)
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.addGapButton.toggleAttribute("data-highlighting", false)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
this.observer = new MutationObserver(() => this.requestUpdate())
|
|
92
|
+
this.observer.observe(this, {characterData: true, childList: true, subtree: true})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
disconnectedCallback(): void {
|
|
97
|
+
super.disconnectedCallback()
|
|
98
|
+
this.observer?.disconnect()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
toggleGap = () => {
|
|
102
|
+
const sel = document.getSelection()
|
|
103
|
+
const selectedElement = sel.anchorNode.childNodes.item(sel.anchorOffset)
|
|
104
|
+
if(selectedElement?.nodeName.toLowerCase() === "webwriter-cloze-gap") {
|
|
105
|
+
const gap = selectedElement as WebwriterClozeGap
|
|
106
|
+
selectedElement.replaceWith(document.createTextNode(gap.value))
|
|
107
|
+
}
|
|
108
|
+
else if(this.contains(sel.anchorNode)) {
|
|
109
|
+
if(sel.anchorNode !== this) {
|
|
110
|
+
const textContent = sel.toString()
|
|
111
|
+
sel.deleteFromDocument()
|
|
112
|
+
const textNode = sel.anchorNode as Text
|
|
113
|
+
const at = sel.anchorOffset
|
|
114
|
+
const clozeGap = document.createElement("webwriter-cloze-gap")
|
|
115
|
+
clozeGap.classList.add("webwriter-new")
|
|
116
|
+
clozeGap.setAttribute("value", textContent)
|
|
117
|
+
const afterTextNode = textNode.splitText(at)
|
|
118
|
+
afterTextNode.textContent = afterTextNode.textContent.trimStart()
|
|
119
|
+
textNode.textContent = textNode.textContent.trimEnd()
|
|
120
|
+
textNode.parentElement.insertBefore(clozeGap, afterTextNode)
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const clozeGap = document.createElement("webwriter-cloze-gap")
|
|
124
|
+
clozeGap.setAttribute("value", "")
|
|
125
|
+
this.append(clozeGap)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
render() {
|
|
131
|
+
return html`
|
|
132
|
+
<slot style=${styleMap({"--placeholder": `"${this.msg("Text to add gaps to")}"`})} ?data-empty=${!this.textContent.trim() && !this.querySelectorAll("& > p *:not(br)").length}></slot>
|
|
133
|
+
<sl-icon-button class="author-only" id="add-gap" src=${IconTextarea} @click=${this.toggleGap}></sl-icon-button>
|
|
134
|
+
`
|
|
135
|
+
}
|
|
136
|
+
}
|