eat-js-sdk 2.2.5 → 2.2.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.
- package/dist/interaction-builder.mjs +50 -40
- package/package.json +1 -1
|
@@ -10240,15 +10240,14 @@ create_custom_element(
|
|
|
10240
10240
|
);
|
|
10241
10241
|
var root_1$d = /* @__PURE__ */ from_html(`<p class="p2 text-red-400 mb-3">Student's answer</p>`);
|
|
10242
10242
|
var root_3$9 = /* @__PURE__ */ from_html(`<span class="w-8 h-8 absolute right-2 top-2.5 flex items-center justify-center" aria-hidden="true"><!></span>`);
|
|
10243
|
-
var root_2$7 = /* @__PURE__ */ from_html(`<div class="relative"><textarea id="answerText" data-testid="input-long-txa" autocomplete="off" rows="3"></textarea> <!></div>`);
|
|
10243
|
+
var root_2$7 = /* @__PURE__ */ from_html(`<div class="relative"><textarea id="answerText" data-testid="input-long-txa" placeholder="Type your answer here" autocomplete="off" rows="3"></textarea> <!></div>`);
|
|
10244
10244
|
var root_5$3 = /* @__PURE__ */ from_html(`<span class="w-8 h-8 absolute right-2 top-2.5 flex items-center justify-center" aria-hidden="true"><!></span>`);
|
|
10245
|
-
var root_4$1 = /* @__PURE__ */ from_html(`<div class="relative"><input data-testid="input-short-txb" autocomplete="off"/> <!></div>`);
|
|
10245
|
+
var root_4$1 = /* @__PURE__ */ from_html(`<div class="relative"><input data-testid="input-short-txb" autocomplete="off" placeholder="Type your answer here"/> <!></div>`);
|
|
10246
10246
|
var root$b = /* @__PURE__ */ from_html(`<div class="relative"><!> <!></div>`);
|
|
10247
10247
|
function TypeInTextField($$anchor, $$props) {
|
|
10248
10248
|
push($$props, true);
|
|
10249
10249
|
let value = prop($$props, "value", 15), variant = prop($$props, "variant", 7), readonly = prop($$props, "readonly", 7, false), disabled = prop($$props, "disabled", 7, false), showStatus = prop($$props, "showStatus", 7, false), isCorrect = prop($$props, "isCorrect", 7, null), isSkipped = prop($$props, "isSkipped", 7, false), onBlur = prop($$props, "onBlur", 7);
|
|
10250
10250
|
let ariaLabel = /* @__PURE__ */ user_derived(() => showStatus() && isCorrect() !== null ? `Submitted response is ${isCorrect() ? "correct" : "incorrect"}` : !value() ? "Answer input: Please type your response" : "Your response is");
|
|
10251
|
-
let typeinPlaceholder = /* @__PURE__ */ user_derived(() => isSkipped() ? "No answer provided" : "Type your answer here");
|
|
10252
10251
|
const focusHandlers = useTextInputFocus();
|
|
10253
10252
|
const handleFocus = (e2) => {
|
|
10254
10253
|
focusHandlers.handleFocus(e2);
|
|
@@ -10334,7 +10333,7 @@ function TypeInTextField($$anchor, $$props) {
|
|
|
10334
10333
|
append($$anchor2, p);
|
|
10335
10334
|
};
|
|
10336
10335
|
if_block(node, ($$render) => {
|
|
10337
|
-
if (showStatus() && isCorrect() === false
|
|
10336
|
+
if (showStatus() && !isSkipped() && isCorrect() === false) $$render(consequent);
|
|
10338
10337
|
});
|
|
10339
10338
|
}
|
|
10340
10339
|
var node_1 = sibling(node, 2);
|
|
@@ -10352,8 +10351,8 @@ function TypeInTextField($$anchor, $$props) {
|
|
|
10352
10351
|
var span = root_3$9();
|
|
10353
10352
|
var node_3 = child(span);
|
|
10354
10353
|
{
|
|
10355
|
-
let $0 = /* @__PURE__ */ user_derived(() =>
|
|
10356
|
-
let $1 = /* @__PURE__ */ user_derived(() =>
|
|
10354
|
+
let $0 = /* @__PURE__ */ user_derived(() => Boolean(isCorrect()));
|
|
10355
|
+
let $1 = /* @__PURE__ */ user_derived(() => Boolean(isCorrect()) ? "text-green-700" : "text-red-850");
|
|
10357
10356
|
ResultIcon(node_3, {
|
|
10358
10357
|
get isCorrect() {
|
|
10359
10358
|
return get$1($0);
|
|
@@ -10367,7 +10366,7 @@ function TypeInTextField($$anchor, $$props) {
|
|
|
10367
10366
|
append($$anchor3, span);
|
|
10368
10367
|
};
|
|
10369
10368
|
if_block(node_2, ($$render) => {
|
|
10370
|
-
if (showStatus() && value() && value().trim() && isCorrect() !== null
|
|
10369
|
+
if (showStatus() && value() && value().trim() && isCorrect() !== null) $$render(consequent_1);
|
|
10371
10370
|
});
|
|
10372
10371
|
}
|
|
10373
10372
|
reset(div_1);
|
|
@@ -10376,14 +10375,13 @@ function TypeInTextField($$anchor, $$props) {
|
|
|
10376
10375
|
set_class(textarea, 1, `input-long-txa typein-textbox h-32 resize-none
|
|
10377
10376
|
${$0 ?? ""}
|
|
10378
10377
|
${showStatus() && !isSkipped() && isCorrect() === true ? "border-2 border-green-700 bg-green-400" : ""}
|
|
10379
|
-
${showStatus() && isCorrect() === false
|
|
10378
|
+
${showStatus() && !isSkipped() && isCorrect() === false ? "border-2 border-red-850" : ""}`);
|
|
10380
10379
|
set_attribute(textarea, "aria-label", get$1(ariaLabel));
|
|
10381
10380
|
textarea.readOnly = readonly();
|
|
10382
10381
|
textarea.disabled = disabled();
|
|
10383
|
-
set_attribute(textarea, "placeholder", get$1(typeinPlaceholder));
|
|
10384
10382
|
},
|
|
10385
10383
|
[
|
|
10386
|
-
() => showStatus() && value() && value().trim() && isCorrect() !== null
|
|
10384
|
+
() => showStatus() && value() && value().trim() && isCorrect() !== null ? "pr-10" : ""
|
|
10387
10385
|
]
|
|
10388
10386
|
);
|
|
10389
10387
|
event("focus", textarea, handleFocus);
|
|
@@ -10404,8 +10402,8 @@ function TypeInTextField($$anchor, $$props) {
|
|
|
10404
10402
|
var span_1 = root_5$3();
|
|
10405
10403
|
var node_5 = child(span_1);
|
|
10406
10404
|
{
|
|
10407
|
-
let $0 = /* @__PURE__ */ user_derived(() =>
|
|
10408
|
-
let $1 = /* @__PURE__ */ user_derived(() =>
|
|
10405
|
+
let $0 = /* @__PURE__ */ user_derived(() => Boolean(isCorrect()));
|
|
10406
|
+
let $1 = /* @__PURE__ */ user_derived(() => Boolean(isCorrect()) ? "text-green-700" : "text-red-850");
|
|
10409
10407
|
ResultIcon(node_5, {
|
|
10410
10408
|
get isCorrect() {
|
|
10411
10409
|
return get$1($0);
|
|
@@ -10419,16 +10417,15 @@ function TypeInTextField($$anchor, $$props) {
|
|
|
10419
10417
|
append($$anchor3, span_1);
|
|
10420
10418
|
};
|
|
10421
10419
|
if_block(node_4, ($$render) => {
|
|
10422
|
-
if (showStatus() && value() && value().trim() && isCorrect() !== null
|
|
10420
|
+
if (showStatus() && value() && value().trim() && isCorrect() !== null) $$render(consequent_3);
|
|
10423
10421
|
});
|
|
10424
10422
|
}
|
|
10425
10423
|
reset(div_2);
|
|
10426
10424
|
template_effect(() => {
|
|
10427
|
-
set_class(input, 1, `input-short-txb typein-textbox typein-input ${showStatus() && !isSkipped() && isCorrect() === true ? "border-2 border-green-700 bg-green-400" : ""} ${showStatus() && isCorrect() === false
|
|
10425
|
+
set_class(input, 1, `input-short-txb typein-textbox typein-input ${showStatus() && !isSkipped() && isCorrect() === true ? "border-2 border-green-700 bg-green-400" : ""} ${showStatus() && !isSkipped() && isCorrect() === false ? "border-2 border-red-850" : ""}`);
|
|
10428
10426
|
set_attribute(input, "aria-label", get$1(ariaLabel));
|
|
10429
10427
|
input.readOnly = readonly();
|
|
10430
10428
|
input.disabled = disabled();
|
|
10431
|
-
set_attribute(input, "placeholder", get$1(typeinPlaceholder));
|
|
10432
10429
|
});
|
|
10433
10430
|
event("focus", input, handleFocus);
|
|
10434
10431
|
event("blur", input, handleBlur);
|
|
@@ -11026,7 +11023,7 @@ function TypeInFeedback($$anchor, $$props) {
|
|
|
11026
11023
|
}
|
|
11027
11024
|
return false;
|
|
11028
11025
|
})());
|
|
11029
|
-
const showHasMultipleAnswers = /* @__PURE__ */ user_derived(() => get$1(hasMultipleAnswers) && config().variant
|
|
11026
|
+
const showHasMultipleAnswers = /* @__PURE__ */ user_derived(() => feedbackState().showStatusLine && get$1(hasMultipleAnswers) && (config().variant === "short" || config().variant === "long"));
|
|
11030
11027
|
const showFeedbackAlert = /* @__PURE__ */ user_derived(() => feedbackState().isFeedbackShown && !feedbackState().isSkipped && config().variant === "inline" && !!feedbackState().resultFeedback?.trim());
|
|
11031
11028
|
const showInlineComparisonTable = /* @__PURE__ */ user_derived(() => feedbackState().showComparisonTable && config().variant === "inline");
|
|
11032
11029
|
const feedbackIconType = /* @__PURE__ */ user_derived(() => isInteractiveMode2() && config().variant === "inline" ? "info" : "result");
|
|
@@ -19100,27 +19097,38 @@ registerInteraction("dropdown", createDropdownInteraction, DropdownComponent);
|
|
|
19100
19097
|
const decodeNbsp = (text) => text.replace(/&nbsp;/g, " ").replace(/ /g, " ");
|
|
19101
19098
|
const stripTags = (s) => s.replace(/<[^>]+>/g, "");
|
|
19102
19099
|
const hasHtmlTags = (s) => /<[^>]/.test(s);
|
|
19100
|
+
const getTagName = (tag) => tag.replace(/^<\/?([^\s>]+).*$/, "$1").toLowerCase();
|
|
19103
19101
|
const extractHtmlWords = (htmlText) => {
|
|
19104
|
-
const re = /(<\/[^>]+>)|(<[^>]+>)|(
|
|
19105
|
-
const
|
|
19106
|
-
let openPending = "";
|
|
19102
|
+
const re = /(<\/[^>]+>)|(<[^>]+>)|([^\s<>]+)/g;
|
|
19103
|
+
const tokens = [];
|
|
19107
19104
|
let m;
|
|
19108
19105
|
while ((m = re.exec(htmlText)) !== null) {
|
|
19109
|
-
if (m[
|
|
19110
|
-
|
|
19111
|
-
|
|
19112
|
-
|
|
19113
|
-
|
|
19114
|
-
|
|
19115
|
-
|
|
19116
|
-
|
|
19106
|
+
if (m[1]) tokens.push({ type: "close", value: m[1] });
|
|
19107
|
+
else if (m[2]) tokens.push({ type: "open", value: m[2] });
|
|
19108
|
+
else tokens.push({ type: "word", value: m[3] });
|
|
19109
|
+
}
|
|
19110
|
+
const words = [];
|
|
19111
|
+
const openStack = [];
|
|
19112
|
+
for (const tok of tokens) {
|
|
19113
|
+
if (tok.type === "open") {
|
|
19114
|
+
openStack.push(tok.value);
|
|
19115
|
+
} else if (tok.type === "close") {
|
|
19116
|
+
const closingName = getTagName(tok.value);
|
|
19117
|
+
for (let i = openStack.length - 1; i >= 0; i--) {
|
|
19118
|
+
if (getTagName(openStack[i]) === closingName) {
|
|
19119
|
+
openStack.splice(i, 1);
|
|
19120
|
+
break;
|
|
19121
|
+
}
|
|
19117
19122
|
}
|
|
19123
|
+
} else {
|
|
19124
|
+
words.push({ value: tok.value, openStack: [...openStack] });
|
|
19118
19125
|
}
|
|
19119
19126
|
}
|
|
19120
|
-
|
|
19121
|
-
|
|
19122
|
-
|
|
19123
|
-
|
|
19127
|
+
return words.map(({ value, openStack: openStack2 }) => {
|
|
19128
|
+
const open = openStack2.join("");
|
|
19129
|
+
const close = [...openStack2].reverse().map((t2) => `</${getTagName(t2)}>`).join("");
|
|
19130
|
+
return open + value + close;
|
|
19131
|
+
});
|
|
19124
19132
|
};
|
|
19125
19133
|
const splitParagraphs = (rawText) => rawText.split(/<\/p>/i).map((p) => p.replace(/^<p>/i, "").trim()).filter(Boolean);
|
|
19126
19134
|
const parseSentences = (rawText, correctAnswers = []) => {
|
|
@@ -19169,13 +19177,10 @@ const parseWords = (rawText, correctAnswers = []) => {
|
|
|
19169
19177
|
const decoded = para.replace(/<eat-contentful>/g, "<eat-contentful>").replace(/<\/eat-contentful>/g, "</eat-contentful>");
|
|
19170
19178
|
tokenRegex.lastIndex = 0;
|
|
19171
19179
|
let match;
|
|
19172
|
-
let pendingOpenTags = "";
|
|
19173
|
-
const trailingOpenTagsRe = /((?:<(?!\/?eat-)[^>]+>)+\s*)$/;
|
|
19174
19180
|
while ((match = tokenRegex.exec(decoded)) !== null) {
|
|
19175
19181
|
if (match[2] !== void 0) {
|
|
19176
|
-
const outerOpen =
|
|
19182
|
+
const outerOpen = match[1] ?? "";
|
|
19177
19183
|
const outerClose = match[3] ?? "";
|
|
19178
|
-
pendingOpenTags = "";
|
|
19179
19184
|
const rawContent = match[2].trim();
|
|
19180
19185
|
const displayText = decodeNbsp(rawContent);
|
|
19181
19186
|
if (displayText) {
|
|
@@ -19191,10 +19196,7 @@ const parseWords = (rawText, correctAnswers = []) => {
|
|
|
19191
19196
|
}
|
|
19192
19197
|
} else if (match[4] !== void 0) {
|
|
19193
19198
|
const rawChunk = match[4];
|
|
19194
|
-
const
|
|
19195
|
-
pendingOpenTags = trailingTagMatch ? trailingTagMatch[1].trimEnd() : "";
|
|
19196
|
-
const chunk = trailingTagMatch ? rawChunk.slice(0, -trailingTagMatch[1].length) : rawChunk;
|
|
19197
|
-
const words = hasHtmlTags(chunk) ? extractHtmlWords(chunk) : chunk.split(/\s+/).filter(Boolean);
|
|
19199
|
+
const words = hasHtmlTags(rawChunk) ? extractHtmlWords(rawChunk) : rawChunk.split(/\s+/).filter(Boolean);
|
|
19198
19200
|
for (const word of words) {
|
|
19199
19201
|
const visibleWord = hasHtmlTags(word) ? stripTags(word) : word;
|
|
19200
19202
|
if (purePunctRe.test(visibleWord)) {
|
|
@@ -19209,7 +19211,15 @@ const parseWords = (rawText, correctAnswers = []) => {
|
|
|
19209
19211
|
} else {
|
|
19210
19212
|
while (correctAnswerIdSet.has(`${globalIndex}`)) globalIndex++;
|
|
19211
19213
|
if (hasHtmlTags(word)) {
|
|
19212
|
-
|
|
19214
|
+
const innerVisible = stripTags(word);
|
|
19215
|
+
const punctMatch = innerVisible.match(trailingPunctRe);
|
|
19216
|
+
if (punctMatch) {
|
|
19217
|
+
const punc = punctMatch[1];
|
|
19218
|
+
const rebuilt = word.replace(new RegExp(punc.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "(</)"), "$1");
|
|
19219
|
+
segments.push({ id: `${globalIndex}`, text: decodeNbsp(rebuilt), trailingPunctuation: punc });
|
|
19220
|
+
} else {
|
|
19221
|
+
segments.push({ id: `${globalIndex}`, text: decodeNbsp(word) });
|
|
19222
|
+
}
|
|
19213
19223
|
} else {
|
|
19214
19224
|
const punctMatch = word.match(trailingPunctRe);
|
|
19215
19225
|
const text = decodeNbsp(punctMatch ? word.slice(0, -punctMatch[1].length) : word);
|