@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,560 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
5
|
+
var __typeError = (msg) => {
|
|
6
|
+
throw TypeError(msg);
|
|
7
|
+
};
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
|
|
11
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
12
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
13
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
14
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
15
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
16
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
20
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
21
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
22
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
23
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
24
|
+
return __privateGet(this, extra);
|
|
25
|
+
}, set [name](x) {
|
|
26
|
+
return __privateSet(this, extra, x);
|
|
27
|
+
} }, name));
|
|
28
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
29
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
30
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
31
|
+
if (k) {
|
|
32
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
33
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
34
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
35
|
+
}
|
|
36
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
37
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
38
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
39
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
40
|
+
}
|
|
41
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
42
|
+
};
|
|
43
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
44
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
45
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
46
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
47
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
48
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
49
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
50
|
+
|
|
51
|
+
// src/widgets/webwriter-order.ts
|
|
52
|
+
import { css as css2, html as html2 } from "lit";
|
|
53
|
+
import { LitElementWw as LitElementWw2, option as option2 } from "@webwriter/lit";
|
|
54
|
+
import { customElement as customElement2, property as property2, query as query2, queryAssignedElements as queryAssignedElements2 } from "lit/decorators.js";
|
|
55
|
+
import SlButton2 from "@shoelace-style/shoelace/dist/components/button/button.component.js";
|
|
56
|
+
import SlIcon2 from "@shoelace-style/shoelace/dist/components/icon/icon.component.js";
|
|
57
|
+
|
|
58
|
+
// ../../node_modules/bootstrap-icons/icons/plus.svg
|
|
59
|
+
var plus_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus" viewBox="0 0 16 16">%0A <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"/>%0A</svg>';
|
|
60
|
+
|
|
61
|
+
// src/widgets/webwriter-choice.ts
|
|
62
|
+
import { html, css } from "lit";
|
|
63
|
+
import { LitElementWw, option, action } from "@webwriter/lit";
|
|
64
|
+
import { customElement, property, queryAssignedElements, query } from "lit/decorators.js";
|
|
65
|
+
import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js";
|
|
66
|
+
import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.component.js";
|
|
67
|
+
import SlRadio from "@shoelace-style/shoelace/dist/components/radio/radio.component.js";
|
|
68
|
+
import SlCheckbox from "@shoelace-style/shoelace/dist/components/checkbox/checkbox.component.js";
|
|
69
|
+
import SlRadioButton from "@shoelace-style/shoelace/dist/components/radio-button/radio-button.component.js";
|
|
70
|
+
import SlRadioGroup from "@shoelace-style/shoelace/dist/components/radio-group/radio-group.component.js";
|
|
71
|
+
|
|
72
|
+
// ../../node_modules/bootstrap-icons/icons/plus-square.svg
|
|
73
|
+
var plus_square_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-square" viewBox="0 0 16 16">%0A <path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/>%0A <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"/>%0A</svg>';
|
|
74
|
+
|
|
75
|
+
// ../../node_modules/bootstrap-icons/icons/plus-circle.svg
|
|
76
|
+
var plus_circle_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle" viewBox="0 0 16 16">%0A <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>%0A <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"/>%0A</svg>';
|
|
77
|
+
|
|
78
|
+
// src/widgets/webwriter-choice.ts
|
|
79
|
+
function shuffle(a) {
|
|
80
|
+
for (let i = a.length - 1; i > 0; i--) {
|
|
81
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
82
|
+
[a[i], a[j]] = [a[j], a[i]];
|
|
83
|
+
}
|
|
84
|
+
return a;
|
|
85
|
+
}
|
|
86
|
+
var _itemsSlotEl_dec, _value_dec, _items_dec, _addItem_dec, _slotEl_dec, _randomOrder_dec, _layout_dec, _mode_dec, _a, _WebwriterChoice_decorators, _init, _mode, _randomOrder, _slotEl, _items, _value, _itemsSlotEl;
|
|
87
|
+
_WebwriterChoice_decorators = [customElement("webwriter-choice")];
|
|
88
|
+
var WebwriterChoice = class extends (_a = LitElementWw, _mode_dec = [property({ type: String, attribute: true, reflect: true }), option({
|
|
89
|
+
type: "select",
|
|
90
|
+
options: [
|
|
91
|
+
{ value: "truefalse", label: { "en": "True/False" } },
|
|
92
|
+
{ value: "single", label: { "en": "Single Choice" } },
|
|
93
|
+
{ value: "multiple", label: { "en": "Multiple Choice" } }
|
|
94
|
+
]
|
|
95
|
+
})], _layout_dec = [property({ type: String, attribute: true, reflect: true }), option({
|
|
96
|
+
type: "select",
|
|
97
|
+
options: [
|
|
98
|
+
{ value: "list", label: { "en": "List" } },
|
|
99
|
+
{ value: "tiles", label: { "en": "Tiles" } }
|
|
100
|
+
]
|
|
101
|
+
})], _randomOrder_dec = [property({ type: Boolean, attribute: true, reflect: true }), option({
|
|
102
|
+
type: Boolean,
|
|
103
|
+
label: { "en": "Random Choice Order" }
|
|
104
|
+
})], _slotEl_dec = [query("slot")], _addItem_dec = [action()], _items_dec = [queryAssignedElements()], _value_dec = [property({ type: Array, attribute: false })], _itemsSlotEl_dec = [query("#items-slot")], _a) {
|
|
105
|
+
constructor() {
|
|
106
|
+
super(...arguments);
|
|
107
|
+
__runInitializers(_init, 5, this);
|
|
108
|
+
__privateAdd(this, _mode, __runInitializers(_init, 8, this, "single")), __runInitializers(_init, 11, this);
|
|
109
|
+
__privateAdd(this, _randomOrder, __runInitializers(_init, 12, this, false)), __runInitializers(_init, 15, this);
|
|
110
|
+
__privateAdd(this, _slotEl, __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
|
|
111
|
+
__privateAdd(this, _items, __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
|
|
112
|
+
__privateAdd(this, _value, []);
|
|
113
|
+
__publicField(this, "handleControlChange", (e) => {
|
|
114
|
+
if (this.mode === "single") {
|
|
115
|
+
const item = e.target;
|
|
116
|
+
const otherItems = this.items.filter((el) => el !== item);
|
|
117
|
+
otherItems.forEach((el) => this.isContentEditable ? el.valid = false : el.active = false);
|
|
118
|
+
}
|
|
119
|
+
this.applyValue();
|
|
120
|
+
this.dispatchEvent(new CustomEvent("ww-answer-change", {
|
|
121
|
+
detail: { value: this.value },
|
|
122
|
+
bubbles: true,
|
|
123
|
+
composed: true
|
|
124
|
+
}));
|
|
125
|
+
});
|
|
126
|
+
__privateAdd(this, _itemsSlotEl, __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
|
|
127
|
+
}
|
|
128
|
+
get layout() {
|
|
129
|
+
return this.children?.item(0)?.getAttribute("layout") ?? "list";
|
|
130
|
+
}
|
|
131
|
+
set layout(value) {
|
|
132
|
+
this.querySelectorAll("webwriter-choice-item").forEach((el) => el.setAttribute("layout", value));
|
|
133
|
+
this.requestUpdate("layout");
|
|
134
|
+
}
|
|
135
|
+
get solution() {
|
|
136
|
+
const validIDs = this.items.filter((item) => item.valid).map((item) => item.id);
|
|
137
|
+
return validIDs.length ? validIDs : void 0;
|
|
138
|
+
}
|
|
139
|
+
set solution(value) {
|
|
140
|
+
this.items.forEach((item) => value.includes(item.id) ? item.valid = true : null);
|
|
141
|
+
}
|
|
142
|
+
reportSolution() {
|
|
143
|
+
if (!this.solution) {
|
|
144
|
+
this.items.forEach((item) => item.valid = true);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
this.items.forEach((item) => item.valid = (this.solution ?? []).includes(item.id));
|
|
148
|
+
}
|
|
149
|
+
reset() {
|
|
150
|
+
this.items.forEach((item) => {
|
|
151
|
+
item.valid = void 0;
|
|
152
|
+
item.active = false;
|
|
153
|
+
});
|
|
154
|
+
this.shuffleItems();
|
|
155
|
+
}
|
|
156
|
+
addItem() {
|
|
157
|
+
const choiceItem = this.ownerDocument.createElement("webwriter-choice-item");
|
|
158
|
+
const p = this.ownerDocument.createElement("p");
|
|
159
|
+
choiceItem.appendChild(p);
|
|
160
|
+
choiceItem.setAttribute("layout", this.layout);
|
|
161
|
+
this.appendChild(choiceItem);
|
|
162
|
+
this.ownerDocument.getSelection().setBaseAndExtent(p, 0, p, 0);
|
|
163
|
+
}
|
|
164
|
+
shuffleItems() {
|
|
165
|
+
const items = this.slotEl.assignedElements();
|
|
166
|
+
const n = items.length;
|
|
167
|
+
const nums = shuffle([...new Array(n).keys()]);
|
|
168
|
+
items.forEach((el, i) => el.style.order = String(nums[i]));
|
|
169
|
+
}
|
|
170
|
+
connectedCallback() {
|
|
171
|
+
super.connectedCallback();
|
|
172
|
+
const observer = new MutationObserver(() => {
|
|
173
|
+
if (!this.contentEditable && this.randomOrder) {
|
|
174
|
+
this.shuffleItems();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
observer.observe(this, { childList: true });
|
|
178
|
+
}
|
|
179
|
+
firstUpdated(_changedProperties) {
|
|
180
|
+
if (!this.contentEditable && this.randomOrder) {
|
|
181
|
+
this.shuffleItems();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
get value() {
|
|
185
|
+
return __privateGet(this, _value);
|
|
186
|
+
}
|
|
187
|
+
set value(value) {
|
|
188
|
+
__privateSet(this, _value, value);
|
|
189
|
+
this.items.forEach((item, i) => {
|
|
190
|
+
this.isContentEditable ? item.valid = __privateGet(this, _value).includes(i) : item.active = __privateGet(this, _value).includes(i);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
applyValue() {
|
|
194
|
+
__privateSet(this, _value, this.items.map((item, i) => [item.valid, i]).filter(([valid]) => valid).map(([_, i]) => i));
|
|
195
|
+
}
|
|
196
|
+
handleSlotChange(e) {
|
|
197
|
+
this.requestUpdate();
|
|
198
|
+
}
|
|
199
|
+
willUpdate(changed) {
|
|
200
|
+
if (changed.has("mode") && this.mode === "single") {
|
|
201
|
+
this.items.filter((el) => this.isContentEditable ? el.valid : el.active).slice(1).forEach((el) => this.isContentEditable ? el.valid = false : el.active = false);
|
|
202
|
+
}
|
|
203
|
+
if (changed.has("mode") && this.mode === "truefalse") {
|
|
204
|
+
this.items.forEach((el) => el.remove());
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
render() {
|
|
208
|
+
return html`
|
|
209
|
+
${this.mode === "truefalse" ? html`
|
|
210
|
+
<sl-radio-group>
|
|
211
|
+
<sl-radio-button value="true">True</sl-radio-button>
|
|
212
|
+
<sl-radio-button value="false">False</sl-radio-button>
|
|
213
|
+
</sl-radio-group>
|
|
214
|
+
` : html`
|
|
215
|
+
<slot id="items-slot" @sl-change=${this.handleControlChange} @slotchange=${this.handleSlotChange}></slot>
|
|
216
|
+
`}
|
|
217
|
+
<sl-button size="small" id="add-option" class="author-only" @click=${() => this.addItem()}>
|
|
218
|
+
<sl-icon src=${this.mode === "multiple" ? plus_square_default : plus_circle_default}></sl-icon><span>Add Option</span>
|
|
219
|
+
</sl-button>
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
_init = __decoratorStart(_a);
|
|
224
|
+
_mode = new WeakMap();
|
|
225
|
+
_randomOrder = new WeakMap();
|
|
226
|
+
_slotEl = new WeakMap();
|
|
227
|
+
_items = new WeakMap();
|
|
228
|
+
_value = new WeakMap();
|
|
229
|
+
_itemsSlotEl = new WeakMap();
|
|
230
|
+
__decorateElement(_init, 4, "mode", _mode_dec, WebwriterChoice, _mode);
|
|
231
|
+
__decorateElement(_init, 3, "layout", _layout_dec, WebwriterChoice);
|
|
232
|
+
__decorateElement(_init, 4, "randomOrder", _randomOrder_dec, WebwriterChoice, _randomOrder);
|
|
233
|
+
__decorateElement(_init, 4, "slotEl", _slotEl_dec, WebwriterChoice, _slotEl);
|
|
234
|
+
__decorateElement(_init, 1, "addItem", _addItem_dec, WebwriterChoice);
|
|
235
|
+
__decorateElement(_init, 4, "items", _items_dec, WebwriterChoice, _items);
|
|
236
|
+
__decorateElement(_init, 3, "value", _value_dec, WebwriterChoice);
|
|
237
|
+
__decorateElement(_init, 4, "itemsSlotEl", _itemsSlotEl_dec, WebwriterChoice, _itemsSlotEl);
|
|
238
|
+
WebwriterChoice = __decorateElement(_init, 0, "WebwriterChoice", _WebwriterChoice_decorators, WebwriterChoice);
|
|
239
|
+
__publicField(WebwriterChoice, "scopedElements", {
|
|
240
|
+
"sl-button": SlButton,
|
|
241
|
+
"sl-icon": SlIcon,
|
|
242
|
+
"sl-radio": SlRadio,
|
|
243
|
+
"sl-checkbox": SlCheckbox,
|
|
244
|
+
"sl-radio-button": SlRadioButton,
|
|
245
|
+
"sl-radio-group": SlRadioGroup
|
|
246
|
+
});
|
|
247
|
+
__publicField(WebwriterChoice, "styles", css`
|
|
248
|
+
:host {
|
|
249
|
+
display: flex !important;
|
|
250
|
+
flex-direction: column;
|
|
251
|
+
align-items: flex-start;
|
|
252
|
+
gap: 0.5rem;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
:host([layout=tiles]) {
|
|
256
|
+
|
|
257
|
+
flex-direction: row;
|
|
258
|
+
flex-wrap: wrap;
|
|
259
|
+
gap: 15px;
|
|
260
|
+
|
|
261
|
+
& ::slotted(*) {
|
|
262
|
+
aspect-ratio: 1;
|
|
263
|
+
min-width: 125px;
|
|
264
|
+
width: 125px;
|
|
265
|
+
max-width: 350px;
|
|
266
|
+
min-height: 125px;
|
|
267
|
+
height: 125px;
|
|
268
|
+
max-height: 350px;
|
|
269
|
+
overflow: hidden;
|
|
270
|
+
resize: both;
|
|
271
|
+
border: 2px solid var(--sl-color-gray-500);
|
|
272
|
+
border-radius: 5px;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
sl-button::part(label) {
|
|
277
|
+
padding: 0;
|
|
278
|
+
display: flex;
|
|
279
|
+
flex-direction: row;
|
|
280
|
+
align-items: center;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
sl-button::part(base) {
|
|
284
|
+
border: none;
|
|
285
|
+
background: transparent;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
sl-icon {
|
|
289
|
+
width: 19px;
|
|
290
|
+
height: 19px;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
sl-icon::part(svg) {
|
|
294
|
+
overflow: visible;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
:host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
|
|
298
|
+
display: none !important;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
#add-option span {
|
|
302
|
+
margin-inline-start: 0.5em;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
:host(:is([contenteditable=true], [contenteditable=""])) ::slotted(*) {
|
|
306
|
+
order: unset !important;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
:host(:not([mode=multiple])) {
|
|
310
|
+
--webwriter-choice-radius: 100%;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
#add-option:not(:hover)::part(base) {
|
|
314
|
+
color: darkgray;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
:host([layout=tiles]) #add-option {
|
|
318
|
+
width: 125px;
|
|
319
|
+
height: 125px;
|
|
320
|
+
overflow: hidden;
|
|
321
|
+
border: 2px solid var(--sl-color-gray-300);
|
|
322
|
+
border-radius: 5px;
|
|
323
|
+
padding: 5px;
|
|
324
|
+
display: flex;
|
|
325
|
+
align-items: center;
|
|
326
|
+
justify-content: center;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
:host([mode=truefalse]) #add-option {
|
|
330
|
+
display: none;
|
|
331
|
+
}
|
|
332
|
+
`);
|
|
333
|
+
__runInitializers(_init, 1, WebwriterChoice);
|
|
334
|
+
|
|
335
|
+
// src/widgets/webwriter-order.ts
|
|
336
|
+
var _solution_dec, _items_dec2, _itemsSlot_dec, _hideOrderButtons_dec, _layout_dec2, _a2, _WebwriterOrder_decorators, _init2, _itemsSlot, _items2, _solution;
|
|
337
|
+
_WebwriterOrder_decorators = [customElement2("webwriter-order")];
|
|
338
|
+
var WebwriterOrder = class extends (_a2 = LitElementWw2, _layout_dec2 = [property2({ type: String, attribute: true, reflect: true }), option2({
|
|
339
|
+
type: "select",
|
|
340
|
+
options: [
|
|
341
|
+
{ value: "list", label: { "en": "List" } },
|
|
342
|
+
{ value: "tiles", label: { "en": "Tiles" } }
|
|
343
|
+
]
|
|
344
|
+
})], _hideOrderButtons_dec = [property2({ type: Boolean, attribute: true, reflect: true }), option2({ type: Boolean, label: { _: "Hide order buttons" } })], _itemsSlot_dec = [query2("#items-slot")], _items_dec2 = [queryAssignedElements2()], _solution_dec = [property2({ attribute: false })], _a2) {
|
|
345
|
+
constructor() {
|
|
346
|
+
super(...arguments);
|
|
347
|
+
__runInitializers(_init2, 5, this);
|
|
348
|
+
__publicField(this, "observer");
|
|
349
|
+
__publicField(this, "orderSheet", new CSSStyleSheet());
|
|
350
|
+
__publicField(this, "clearDropPreviews", () => {
|
|
351
|
+
this.items.forEach((item) => item.dropPreview = void 0);
|
|
352
|
+
});
|
|
353
|
+
__privateAdd(this, _itemsSlot, __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
|
|
354
|
+
__privateAdd(this, _items2, __runInitializers(_init2, 12, this)), __runInitializers(_init2, 15, this);
|
|
355
|
+
__publicField(this, "handleMove", (e) => {
|
|
356
|
+
const elem = e.target;
|
|
357
|
+
const children = Array.from(this.children);
|
|
358
|
+
const pos = children.indexOf(elem);
|
|
359
|
+
let i;
|
|
360
|
+
if (e.type === "ww-moveup") {
|
|
361
|
+
i = Math.max(0, pos - 1);
|
|
362
|
+
} else if (e.type === "ww-movedown") {
|
|
363
|
+
i = Math.min(children.length, pos + 2);
|
|
364
|
+
} else if (e.type === "ww-moveto") {
|
|
365
|
+
i = e.detail.i;
|
|
366
|
+
}
|
|
367
|
+
this.moveChild(elem, i);
|
|
368
|
+
});
|
|
369
|
+
__privateAdd(this, _solution, []);
|
|
370
|
+
}
|
|
371
|
+
get layout() {
|
|
372
|
+
return this.children?.item(0)?.getAttribute("layout") ?? "list";
|
|
373
|
+
}
|
|
374
|
+
set layout(value) {
|
|
375
|
+
this.querySelectorAll("webwriter-order-item").forEach((el) => el.setAttribute("layout", value));
|
|
376
|
+
this.requestUpdate("layout");
|
|
377
|
+
}
|
|
378
|
+
get hideOrderButtons() {
|
|
379
|
+
return !!this.items[0]?.hideOrderButtons;
|
|
380
|
+
}
|
|
381
|
+
set hideOrderButtons(value) {
|
|
382
|
+
this.items.forEach((item) => item.hideOrderButtons = value);
|
|
383
|
+
}
|
|
384
|
+
connectedCallback() {
|
|
385
|
+
super.connectedCallback();
|
|
386
|
+
this.addEventListener("ww-moveup", this.handleMove);
|
|
387
|
+
this.addEventListener("ww-movedown", this.handleMove);
|
|
388
|
+
this.addEventListener("ww-moveto", this.handleMove);
|
|
389
|
+
this.observer = new MutationObserver(() => {
|
|
390
|
+
this.items.forEach((item) => item.requestUpdate());
|
|
391
|
+
if (this.isContentEditable) {
|
|
392
|
+
this.solution = this.items.map((item) => item.id);
|
|
393
|
+
}
|
|
394
|
+
this.clearDropPreviews();
|
|
395
|
+
});
|
|
396
|
+
this.observer.observe(this, { childList: true });
|
|
397
|
+
}
|
|
398
|
+
serializedCallback() {
|
|
399
|
+
this.shuffleItems();
|
|
400
|
+
}
|
|
401
|
+
disconnectedCallback() {
|
|
402
|
+
super.disconnectedCallback();
|
|
403
|
+
this.observer?.disconnect();
|
|
404
|
+
this.observer = void 0;
|
|
405
|
+
}
|
|
406
|
+
addItem() {
|
|
407
|
+
const orderItem = this.ownerDocument.createElement("webwriter-order-item");
|
|
408
|
+
const p = this.ownerDocument.createElement("p");
|
|
409
|
+
orderItem.appendChild(p);
|
|
410
|
+
orderItem.setAttribute("layout", this.layout);
|
|
411
|
+
this.append(orderItem);
|
|
412
|
+
this.solution = [...__privateGet(this, _solution), orderItem.id];
|
|
413
|
+
this.ownerDocument.getSelection().setBaseAndExtent(p, 0, p, 0);
|
|
414
|
+
}
|
|
415
|
+
shuffleItems() {
|
|
416
|
+
const n = this.items.length;
|
|
417
|
+
const nums = shuffle([...new Array(n).keys()]);
|
|
418
|
+
this.innerHTML = nums.map((i) => this.children.item(i).outerHTML).join("");
|
|
419
|
+
}
|
|
420
|
+
handleKeyDown(e) {
|
|
421
|
+
if (e.key == "ArrowDown") {
|
|
422
|
+
e.stopPropagation();
|
|
423
|
+
e.preventDefault();
|
|
424
|
+
} else if (e.key === "ArrowUp") {
|
|
425
|
+
e.stopPropagation();
|
|
426
|
+
e.preventDefault();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/*
|
|
430
|
+
If contenteditable: Reorder solution -> Triggers orderSheet change
|
|
431
|
+
If not contenteditable: Reorder value -> Triggers orderSheet change
|
|
432
|
+
*/
|
|
433
|
+
moveChild(elem, i) {
|
|
434
|
+
if (i === 0) {
|
|
435
|
+
this.insertAdjacentElement("afterbegin", elem);
|
|
436
|
+
} else if (i < this.items.length) {
|
|
437
|
+
this.items[i].insertAdjacentElement("beforebegin", elem);
|
|
438
|
+
} else {
|
|
439
|
+
this.insertAdjacentElement("beforeend", elem);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
get solution() {
|
|
443
|
+
return __privateGet(this, _solution)?.length ? __privateGet(this, _solution) : void 0;
|
|
444
|
+
}
|
|
445
|
+
set solution(value) {
|
|
446
|
+
__privateSet(this, _solution, value);
|
|
447
|
+
if (value) {
|
|
448
|
+
this.dispatchEvent(new CustomEvent("ww-answer-change", {
|
|
449
|
+
bubbles: true,
|
|
450
|
+
composed: true
|
|
451
|
+
}));
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
reportSolution() {
|
|
455
|
+
this.solution.forEach((id, i) => this.querySelector(`#${id}`).validOrder = i);
|
|
456
|
+
}
|
|
457
|
+
reset() {
|
|
458
|
+
this.solution = void 0;
|
|
459
|
+
this.shuffleItems();
|
|
460
|
+
}
|
|
461
|
+
render() {
|
|
462
|
+
return html2`
|
|
463
|
+
<slot id="items-slot" @webwriter-clear-drop-preview=${this.clearDropPreviews}></slot>
|
|
464
|
+
<sl-button size="small" id="add-option" class="author-only" @click=${() => this.addItem()}>
|
|
465
|
+
<sl-icon src=${plus_default}></sl-icon><span>Add Option</span>
|
|
466
|
+
</sl-button>
|
|
467
|
+
`;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
_init2 = __decoratorStart(_a2);
|
|
471
|
+
_itemsSlot = new WeakMap();
|
|
472
|
+
_items2 = new WeakMap();
|
|
473
|
+
_solution = new WeakMap();
|
|
474
|
+
__decorateElement(_init2, 3, "layout", _layout_dec2, WebwriterOrder);
|
|
475
|
+
__decorateElement(_init2, 3, "hideOrderButtons", _hideOrderButtons_dec, WebwriterOrder);
|
|
476
|
+
__decorateElement(_init2, 4, "itemsSlot", _itemsSlot_dec, WebwriterOrder, _itemsSlot);
|
|
477
|
+
__decorateElement(_init2, 4, "items", _items_dec2, WebwriterOrder, _items2);
|
|
478
|
+
__decorateElement(_init2, 3, "solution", _solution_dec, WebwriterOrder);
|
|
479
|
+
WebwriterOrder = __decorateElement(_init2, 0, "WebwriterOrder", _WebwriterOrder_decorators, WebwriterOrder);
|
|
480
|
+
__publicField(WebwriterOrder, "scopedElements", {
|
|
481
|
+
"sl-button": SlButton2,
|
|
482
|
+
"sl-icon": SlIcon2
|
|
483
|
+
});
|
|
484
|
+
__publicField(WebwriterOrder, "styles", css2`
|
|
485
|
+
:host {
|
|
486
|
+
display: flex !important;
|
|
487
|
+
flex-direction: column;
|
|
488
|
+
align-items: flex-start;
|
|
489
|
+
counter-reset: orderItem;
|
|
490
|
+
gap: 2px;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
:host([layout=tiles]) {
|
|
494
|
+
flex-direction: row;
|
|
495
|
+
flex-wrap: wrap;
|
|
496
|
+
gap: 15px;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
:host(:is([contenteditable=true], [contenteditable=""])) {
|
|
500
|
+
--text-color: var(--sl-color-success-700);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
:host ::slotted(*::part(counter)) {
|
|
504
|
+
counter-increment: orderItem;
|
|
505
|
+
content: counter(orderItem) '. ';
|
|
506
|
+
cursor: move;
|
|
507
|
+
text-align: right;
|
|
508
|
+
padding-right: 0.5em;
|
|
509
|
+
min-width: 1.5em;
|
|
510
|
+
color: var(--text-color, auto);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
sl-button::part(label) {
|
|
514
|
+
padding: 0;
|
|
515
|
+
display: flex;
|
|
516
|
+
flex-direction: row;
|
|
517
|
+
align-items: center;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
sl-button::part(base) {
|
|
521
|
+
border: none;
|
|
522
|
+
background: transparent;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
sl-icon {
|
|
526
|
+
width: 19px;
|
|
527
|
+
height: 19px;
|
|
528
|
+
padding: var(--sl-spacing-x-small);
|
|
529
|
+
padding-left: 0;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
#add-option {
|
|
533
|
+
order: 2147483647;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
#add-option:not(:hover)::part(base) {
|
|
537
|
+
color: darkgray;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
:host([layout=tiles]) #add-option {
|
|
541
|
+
width: 125px;
|
|
542
|
+
height: 125px;
|
|
543
|
+
overflow: hidden;
|
|
544
|
+
border: 2px solid var(--sl-color-gray-300);
|
|
545
|
+
border-radius: 5px;
|
|
546
|
+
padding: 5px;
|
|
547
|
+
display: flex;
|
|
548
|
+
align-items: center;
|
|
549
|
+
justify-content: center;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
:host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
|
|
554
|
+
display: none;
|
|
555
|
+
}
|
|
556
|
+
`);
|
|
557
|
+
__runInitializers(_init2, 1, WebwriterOrder);
|
|
558
|
+
export {
|
|
559
|
+
WebwriterOrder
|
|
560
|
+
};
|