eat-js-sdk 0.0.25 → 0.0.27
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/eat-prompt-builder.mjs +168 -57
- package/package.json +1 -1
|
@@ -1004,6 +1004,10 @@
|
|
|
1004
1004
|
return await response.json();
|
|
1005
1005
|
};
|
|
1006
1006
|
|
|
1007
|
+
// src/lib/composables/useTypein.ts
|
|
1008
|
+
var useRemoveDiacritics = (data) => data.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/\s+/g, " ");
|
|
1009
|
+
var useRemovePunctuation = (data) => data.replace(/[^\p{L}\p{M}\s\d]/gu, "").replace(/\s+/g, " ");
|
|
1010
|
+
|
|
1007
1011
|
// src/lib/components/prompt/template/PromptBody.svelte
|
|
1008
1012
|
function create_if_block_1(ctx) {
|
|
1009
1013
|
let html_tag;
|
|
@@ -1573,8 +1577,7 @@
|
|
|
1573
1577
|
// src/lib/components/prompt/mcq/PromptMCQ.svelte
|
|
1574
1578
|
function get_each_context(ctx, list, i) {
|
|
1575
1579
|
const child_ctx = ctx.slice();
|
|
1576
|
-
child_ctx[
|
|
1577
|
-
child_ctx[17] = list[i][1];
|
|
1580
|
+
child_ctx[17] = list[i];
|
|
1578
1581
|
child_ctx[19] = i;
|
|
1579
1582
|
return child_ctx;
|
|
1580
1583
|
}
|
|
@@ -1584,7 +1587,7 @@
|
|
|
1584
1587
|
let div0_class_value;
|
|
1585
1588
|
let t2;
|
|
1586
1589
|
let current;
|
|
1587
|
-
let each_value = ensure_array_like(Object.
|
|
1590
|
+
let each_value = ensure_array_like(Object.values(
|
|
1588
1591
|
/*options*/
|
|
1589
1592
|
ctx[7]
|
|
1590
1593
|
));
|
|
@@ -1626,7 +1629,7 @@
|
|
|
1626
1629
|
}
|
|
1627
1630
|
if (dirty & /*selectedOption, Object, options, isFinished, isResultCorrect, handleOptionClick*/
|
|
1628
1631
|
398) {
|
|
1629
|
-
each_value = ensure_array_like(Object.
|
|
1632
|
+
each_value = ensure_array_like(Object.values(
|
|
1630
1633
|
/*options*/
|
|
1631
1634
|
ctx2[7]
|
|
1632
1635
|
));
|
|
@@ -1851,7 +1854,7 @@
|
|
|
1851
1854
|
function click_handler() {
|
|
1852
1855
|
return (
|
|
1853
1856
|
/*click_handler*/
|
|
1854
|
-
ctx[
|
|
1857
|
+
ctx[11](
|
|
1855
1858
|
/*option*/
|
|
1856
1859
|
ctx[17]
|
|
1857
1860
|
)
|
|
@@ -2210,10 +2213,10 @@
|
|
|
2210
2213
|
let { isDataSaving } = $$props;
|
|
2211
2214
|
let { isFinished = false } = $$props;
|
|
2212
2215
|
let { isResultCorrect = false } = $$props;
|
|
2216
|
+
let { isPreviewModeInteractive = false } = $$props;
|
|
2213
2217
|
const { rubric, interaction, metadata, scoringMetadata } = sessionData;
|
|
2214
2218
|
const { prompt, options } = interaction;
|
|
2215
2219
|
let selectedOption = null;
|
|
2216
|
-
let resultFeedbackTitle = null;
|
|
2217
2220
|
let resultFeedback = null;
|
|
2218
2221
|
const dispatch = createEventDispatcher();
|
|
2219
2222
|
if (metadata) {
|
|
@@ -2222,23 +2225,34 @@
|
|
|
2222
2225
|
const { answer_id: answerChoiceId } = currentOption;
|
|
2223
2226
|
selectedOption = answerChoiceId[0];
|
|
2224
2227
|
}
|
|
2228
|
+
const getFeedback = () => {
|
|
2229
|
+
if (!options || !selectedOption)
|
|
2230
|
+
return;
|
|
2231
|
+
const feedbackData = Object.values(options).filter((option) => option.id === selectedOption);
|
|
2232
|
+
$$invalidate(4, resultFeedback = feedbackData[0].feedback || resultFeedback);
|
|
2233
|
+
};
|
|
2225
2234
|
if (isFinished) {
|
|
2226
|
-
|
|
2227
|
-
const feedbackData = Object.values(options).filter((option) => option.id === selectedOption);
|
|
2228
|
-
resultFeedbackTitle = isResultCorrect ? "Well done!" : "Nice try!";
|
|
2229
|
-
resultFeedback = feedbackData[0].feedback || resultFeedback;
|
|
2230
|
-
}
|
|
2235
|
+
getFeedback();
|
|
2231
2236
|
const { answerId, hasAnswer } = scoringMetadata;
|
|
2232
2237
|
selectedOption = answerId && hasAnswer ? answerId : selectedOption;
|
|
2233
2238
|
}
|
|
2234
2239
|
const handleOptionClick = (optionId, option) => {
|
|
2235
|
-
if (isDataSaving || optionId === selectedOption || isFinished)
|
|
2240
|
+
if (isDataSaving || optionId === selectedOption || isFinished && !isPreviewModeInteractive)
|
|
2236
2241
|
return;
|
|
2237
2242
|
$$invalidate(3, selectedOption = optionId);
|
|
2238
2243
|
dispatch("saveOption", {
|
|
2239
2244
|
answer_id: [optionId],
|
|
2240
2245
|
answer_choice: [option]
|
|
2241
2246
|
});
|
|
2247
|
+
if (isPreviewModeInteractive) {
|
|
2248
|
+
setTimeout(
|
|
2249
|
+
() => {
|
|
2250
|
+
$$invalidate(4, resultFeedback = null);
|
|
2251
|
+
getFeedback();
|
|
2252
|
+
},
|
|
2253
|
+
50
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2242
2256
|
};
|
|
2243
2257
|
const click_handler = (option) => handleOptionClick(option.id, option.answer);
|
|
2244
2258
|
$$self.$$set = ($$props2) => {
|
|
@@ -2250,6 +2264,8 @@
|
|
|
2250
2264
|
$$invalidate(1, isFinished = $$props2.isFinished);
|
|
2251
2265
|
if ("isResultCorrect" in $$props2)
|
|
2252
2266
|
$$invalidate(2, isResultCorrect = $$props2.isResultCorrect);
|
|
2267
|
+
if ("isPreviewModeInteractive" in $$props2)
|
|
2268
|
+
$$invalidate(10, isPreviewModeInteractive = $$props2.isPreviewModeInteractive);
|
|
2253
2269
|
};
|
|
2254
2270
|
return [
|
|
2255
2271
|
isDataSaving,
|
|
@@ -2262,6 +2278,7 @@
|
|
|
2262
2278
|
options,
|
|
2263
2279
|
handleOptionClick,
|
|
2264
2280
|
sessionData,
|
|
2281
|
+
isPreviewModeInteractive,
|
|
2265
2282
|
click_handler
|
|
2266
2283
|
];
|
|
2267
2284
|
}
|
|
@@ -2272,7 +2289,8 @@
|
|
|
2272
2289
|
sessionData: 9,
|
|
2273
2290
|
isDataSaving: 0,
|
|
2274
2291
|
isFinished: 1,
|
|
2275
|
-
isResultCorrect: 2
|
|
2292
|
+
isResultCorrect: 2,
|
|
2293
|
+
isPreviewModeInteractive: 10
|
|
2276
2294
|
});
|
|
2277
2295
|
}
|
|
2278
2296
|
get sessionData() {
|
|
@@ -2303,8 +2321,15 @@
|
|
|
2303
2321
|
this.$$set({ isResultCorrect });
|
|
2304
2322
|
flush();
|
|
2305
2323
|
}
|
|
2324
|
+
get isPreviewModeInteractive() {
|
|
2325
|
+
return this.$$.ctx[10];
|
|
2326
|
+
}
|
|
2327
|
+
set isPreviewModeInteractive(isPreviewModeInteractive) {
|
|
2328
|
+
this.$$set({ isPreviewModeInteractive });
|
|
2329
|
+
flush();
|
|
2330
|
+
}
|
|
2306
2331
|
};
|
|
2307
|
-
customElements.define("prompt-mcq", create_custom_element(PromptMCQ, { "sessionData": {}, "isDataSaving": {}, "isFinished": { "type": "Boolean" }, "isResultCorrect": { "type": "Boolean" } }, [], [], true));
|
|
2332
|
+
customElements.define("prompt-mcq", create_custom_element(PromptMCQ, { "sessionData": {}, "isDataSaving": {}, "isFinished": { "type": "Boolean" }, "isResultCorrect": { "type": "Boolean" }, "isPreviewModeInteractive": { "type": "Boolean" } }, [], [], true));
|
|
2308
2333
|
var PromptMCQ_default = PromptMCQ;
|
|
2309
2334
|
|
|
2310
2335
|
// node_modules/autosize/dist/autosize.esm.js
|
|
@@ -2416,8 +2441,8 @@
|
|
|
2416
2441
|
textarea.disabled = /*isDataSaving*/
|
|
2417
2442
|
ctx[0];
|
|
2418
2443
|
attr(textarea, "autocomplete", "off");
|
|
2419
|
-
textarea.readOnly = /*
|
|
2420
|
-
ctx[
|
|
2444
|
+
textarea.readOnly = /*isReadonlyText*/
|
|
2445
|
+
ctx[11];
|
|
2421
2446
|
},
|
|
2422
2447
|
m(target, anchor) {
|
|
2423
2448
|
insert(target, textarea, anchor);
|
|
@@ -2432,38 +2457,38 @@
|
|
|
2432
2457
|
textarea,
|
|
2433
2458
|
"input",
|
|
2434
2459
|
/*textarea_input_handler*/
|
|
2435
|
-
ctx[
|
|
2460
|
+
ctx[22]
|
|
2436
2461
|
),
|
|
2437
2462
|
listen(
|
|
2438
2463
|
textarea,
|
|
2439
2464
|
"mousedown",
|
|
2440
2465
|
/*mousedown_handler*/
|
|
2441
|
-
ctx[
|
|
2466
|
+
ctx[23]
|
|
2442
2467
|
),
|
|
2443
2468
|
listen(
|
|
2444
2469
|
textarea,
|
|
2445
2470
|
"touchstart",
|
|
2446
2471
|
/*touchstart_handler*/
|
|
2447
|
-
ctx[
|
|
2472
|
+
ctx[24],
|
|
2448
2473
|
{ passive: true }
|
|
2449
2474
|
),
|
|
2450
2475
|
listen(
|
|
2451
2476
|
textarea,
|
|
2452
2477
|
"focus",
|
|
2453
2478
|
/*focus_handler*/
|
|
2454
|
-
ctx[
|
|
2479
|
+
ctx[25]
|
|
2455
2480
|
),
|
|
2456
2481
|
listen(
|
|
2457
2482
|
textarea,
|
|
2458
2483
|
"focusout",
|
|
2459
2484
|
/*focusout_handler_1*/
|
|
2460
|
-
ctx[
|
|
2485
|
+
ctx[26]
|
|
2461
2486
|
),
|
|
2462
2487
|
listen(
|
|
2463
2488
|
textarea,
|
|
2464
2489
|
"keydown",
|
|
2465
2490
|
/*keydown_handler_1*/
|
|
2466
|
-
ctx[
|
|
2491
|
+
ctx[27]
|
|
2467
2492
|
),
|
|
2468
2493
|
action_destroyer(autosize_action = svelte_autosize_default.call(null, textarea))
|
|
2469
2494
|
];
|
|
@@ -2502,11 +2527,6 @@
|
|
|
2502
2527
|
textarea.disabled = /*isDataSaving*/
|
|
2503
2528
|
ctx2[0];
|
|
2504
2529
|
}
|
|
2505
|
-
if (dirty[0] & /*isFinished*/
|
|
2506
|
-
2) {
|
|
2507
|
-
textarea.readOnly = /*isFinished*/
|
|
2508
|
-
ctx2[1];
|
|
2509
|
-
}
|
|
2510
2530
|
if (dirty[0] & /*typeinAnswer*/
|
|
2511
2531
|
8) {
|
|
2512
2532
|
set_input_value(
|
|
@@ -2555,8 +2575,8 @@
|
|
|
2555
2575
|
input.disabled = /*isDataSaving*/
|
|
2556
2576
|
ctx[0];
|
|
2557
2577
|
attr(input, "autocomplete", "off");
|
|
2558
|
-
input.readOnly = /*
|
|
2559
|
-
ctx[
|
|
2578
|
+
input.readOnly = /*isReadonlyText*/
|
|
2579
|
+
ctx[11];
|
|
2560
2580
|
},
|
|
2561
2581
|
m(target, anchor) {
|
|
2562
2582
|
insert(target, input, anchor);
|
|
@@ -2571,19 +2591,19 @@
|
|
|
2571
2591
|
input,
|
|
2572
2592
|
"input",
|
|
2573
2593
|
/*input_input_handler*/
|
|
2574
|
-
ctx[
|
|
2594
|
+
ctx[19]
|
|
2575
2595
|
),
|
|
2576
2596
|
listen(
|
|
2577
2597
|
input,
|
|
2578
2598
|
"focusout",
|
|
2579
2599
|
/*focusout_handler*/
|
|
2580
|
-
ctx[
|
|
2600
|
+
ctx[20]
|
|
2581
2601
|
),
|
|
2582
2602
|
listen(
|
|
2583
2603
|
input,
|
|
2584
2604
|
"keydown",
|
|
2585
2605
|
/*keydown_handler*/
|
|
2586
|
-
ctx[
|
|
2606
|
+
ctx[21]
|
|
2587
2607
|
)
|
|
2588
2608
|
];
|
|
2589
2609
|
mounted = true;
|
|
@@ -2621,11 +2641,6 @@
|
|
|
2621
2641
|
input.disabled = /*isDataSaving*/
|
|
2622
2642
|
ctx2[0];
|
|
2623
2643
|
}
|
|
2624
|
-
if (dirty[0] & /*isFinished*/
|
|
2625
|
-
2) {
|
|
2626
|
-
input.readOnly = /*isFinished*/
|
|
2627
|
-
ctx2[1];
|
|
2628
|
-
}
|
|
2629
2644
|
if (dirty[0] & /*typeinAnswer*/
|
|
2630
2645
|
8 && input.value !== /*typeinAnswer*/
|
|
2631
2646
|
ctx2[3]) {
|
|
@@ -2905,7 +2920,7 @@
|
|
|
2905
2920
|
const promptbody_changes = {};
|
|
2906
2921
|
if (dirty[0] & /*textAriaLabel, placeholder, isFinished, isResultCorrect, isDataSaving, typeinAnswer*/
|
|
2907
2922
|
175 | dirty[1] & /*$$scope*/
|
|
2908
|
-
|
|
2923
|
+
32) {
|
|
2909
2924
|
promptbody_changes.$$scope = { dirty, ctx: ctx2 };
|
|
2910
2925
|
}
|
|
2911
2926
|
promptbody.$set(promptbody_changes);
|
|
@@ -2963,6 +2978,7 @@
|
|
|
2963
2978
|
let { isFinished = false } = $$props;
|
|
2964
2979
|
let { isResultCorrect = false } = $$props;
|
|
2965
2980
|
let { isPreviewMode = false } = $$props;
|
|
2981
|
+
let { isPreviewModeInteractive = false } = $$props;
|
|
2966
2982
|
const dispatch = createEventDispatcher();
|
|
2967
2983
|
let typeinAnswer;
|
|
2968
2984
|
let latestAnswer = "";
|
|
@@ -2977,15 +2993,22 @@
|
|
|
2977
2993
|
latestAnswer = typeinAnswer = events.answer[0];
|
|
2978
2994
|
}
|
|
2979
2995
|
let textAriaLabel = !latestAnswer ? "Answer input: Please type your response" : "Your response is";
|
|
2996
|
+
const isReadonlyText = isFinished && !isPreviewModeInteractive;
|
|
2997
|
+
const getFeedback = () => {
|
|
2998
|
+
const { correct: correctFeeback, incorrect: incorrectFeedback } = interaction.feedback;
|
|
2999
|
+
$$invalidate(4, resultFeedback = isResultCorrect ? correctFeeback : incorrectFeedback);
|
|
3000
|
+
};
|
|
3001
|
+
const getResultMessage = () => {
|
|
3002
|
+
$$invalidate(6, resultLabel = isResultCorrect ? "Correct" : "Incorrect");
|
|
3003
|
+
$$invalidate(7, textAriaLabel = `Submitted response is ${resultLabel.toLocaleLowerCase()}`);
|
|
3004
|
+
$$invalidate(5, placeholder = isResultCorrect ? placeholder : "No answer provided");
|
|
3005
|
+
};
|
|
2980
3006
|
if (isFinished) {
|
|
2981
3007
|
const { answer, hasAnswer } = scoringMetadata;
|
|
2982
3008
|
typeinAnswer = answer && hasAnswer ? answer : typeinAnswer;
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
if (!isPreviewMode) {
|
|
2987
|
-
const { correct: correctFeeback, incorrect: incorrectFeedback } = interaction.feedback;
|
|
2988
|
-
resultFeedback = isResultCorrect ? correctFeeback : incorrectFeedback;
|
|
3009
|
+
getResultMessage();
|
|
3010
|
+
if (!isPreviewMode || isPreviewModeInteractive) {
|
|
3011
|
+
getFeedback();
|
|
2989
3012
|
}
|
|
2990
3013
|
}
|
|
2991
3014
|
const saveAnswer = () => {
|
|
@@ -2994,6 +3017,18 @@
|
|
|
2994
3017
|
return;
|
|
2995
3018
|
latestAnswer = typeinAnswer;
|
|
2996
3019
|
dispatch("saveAnswer", { answer: [typeinAnswer || ""] });
|
|
3020
|
+
if (isPreviewModeInteractive) {
|
|
3021
|
+
setTimeout(
|
|
3022
|
+
() => {
|
|
3023
|
+
$$invalidate(6, resultLabel = "");
|
|
3024
|
+
$$invalidate(7, textAriaLabel = "");
|
|
3025
|
+
$$invalidate(5, placeholder = "");
|
|
3026
|
+
getResultMessage();
|
|
3027
|
+
getFeedback();
|
|
3028
|
+
},
|
|
3029
|
+
50
|
|
3030
|
+
);
|
|
3031
|
+
}
|
|
2997
3032
|
};
|
|
2998
3033
|
const saveOnEnter = (event) => {
|
|
2999
3034
|
if (event.key === "Enter") {
|
|
@@ -3028,7 +3063,7 @@
|
|
|
3028
3063
|
const keydown_handler_1 = (event) => saveOnEnter(event);
|
|
3029
3064
|
$$self.$$set = ($$props2) => {
|
|
3030
3065
|
if ("sessionData" in $$props2)
|
|
3031
|
-
$$invalidate(
|
|
3066
|
+
$$invalidate(16, sessionData = $$props2.sessionData);
|
|
3032
3067
|
if ("isDataSaving" in $$props2)
|
|
3033
3068
|
$$invalidate(0, isDataSaving = $$props2.isDataSaving);
|
|
3034
3069
|
if ("isFinished" in $$props2)
|
|
@@ -3036,7 +3071,9 @@
|
|
|
3036
3071
|
if ("isResultCorrect" in $$props2)
|
|
3037
3072
|
$$invalidate(2, isResultCorrect = $$props2.isResultCorrect);
|
|
3038
3073
|
if ("isPreviewMode" in $$props2)
|
|
3039
|
-
$$invalidate(
|
|
3074
|
+
$$invalidate(17, isPreviewMode = $$props2.isPreviewMode);
|
|
3075
|
+
if ("isPreviewModeInteractive" in $$props2)
|
|
3076
|
+
$$invalidate(18, isPreviewModeInteractive = $$props2.isPreviewModeInteractive);
|
|
3040
3077
|
};
|
|
3041
3078
|
return [
|
|
3042
3079
|
isDataSaving,
|
|
@@ -3050,12 +3087,14 @@
|
|
|
3050
3087
|
rubric,
|
|
3051
3088
|
prompt,
|
|
3052
3089
|
typeinType,
|
|
3090
|
+
isReadonlyText,
|
|
3053
3091
|
saveAnswer,
|
|
3054
3092
|
saveOnEnter,
|
|
3055
3093
|
handleFocus,
|
|
3056
3094
|
handleClick,
|
|
3057
3095
|
sessionData,
|
|
3058
3096
|
isPreviewMode,
|
|
3097
|
+
isPreviewModeInteractive,
|
|
3059
3098
|
input_input_handler,
|
|
3060
3099
|
focusout_handler,
|
|
3061
3100
|
keydown_handler,
|
|
@@ -3077,18 +3116,19 @@
|
|
|
3077
3116
|
create_fragment6,
|
|
3078
3117
|
safe_not_equal,
|
|
3079
3118
|
{
|
|
3080
|
-
sessionData:
|
|
3119
|
+
sessionData: 16,
|
|
3081
3120
|
isDataSaving: 0,
|
|
3082
3121
|
isFinished: 1,
|
|
3083
3122
|
isResultCorrect: 2,
|
|
3084
|
-
isPreviewMode:
|
|
3123
|
+
isPreviewMode: 17,
|
|
3124
|
+
isPreviewModeInteractive: 18
|
|
3085
3125
|
},
|
|
3086
3126
|
null,
|
|
3087
3127
|
[-1, -1]
|
|
3088
3128
|
);
|
|
3089
3129
|
}
|
|
3090
3130
|
get sessionData() {
|
|
3091
|
-
return this.$$.ctx[
|
|
3131
|
+
return this.$$.ctx[16];
|
|
3092
3132
|
}
|
|
3093
3133
|
set sessionData(sessionData) {
|
|
3094
3134
|
this.$$set({ sessionData });
|
|
@@ -3116,14 +3156,21 @@
|
|
|
3116
3156
|
flush();
|
|
3117
3157
|
}
|
|
3118
3158
|
get isPreviewMode() {
|
|
3119
|
-
return this.$$.ctx[
|
|
3159
|
+
return this.$$.ctx[17];
|
|
3120
3160
|
}
|
|
3121
3161
|
set isPreviewMode(isPreviewMode) {
|
|
3122
3162
|
this.$$set({ isPreviewMode });
|
|
3123
3163
|
flush();
|
|
3124
3164
|
}
|
|
3165
|
+
get isPreviewModeInteractive() {
|
|
3166
|
+
return this.$$.ctx[18];
|
|
3167
|
+
}
|
|
3168
|
+
set isPreviewModeInteractive(isPreviewModeInteractive) {
|
|
3169
|
+
this.$$set({ isPreviewModeInteractive });
|
|
3170
|
+
flush();
|
|
3171
|
+
}
|
|
3125
3172
|
};
|
|
3126
|
-
customElements.define("prompt-typein", create_custom_element(PromptTypeIn, { "sessionData": {}, "isDataSaving": {}, "isFinished": { "type": "Boolean" }, "isResultCorrect": { "type": "Boolean" }, "isPreviewMode": { "type": "Boolean" } }, [], [], true));
|
|
3173
|
+
customElements.define("prompt-typein", create_custom_element(PromptTypeIn, { "sessionData": {}, "isDataSaving": {}, "isFinished": { "type": "Boolean" }, "isResultCorrect": { "type": "Boolean" }, "isPreviewMode": { "type": "Boolean" }, "isPreviewModeInteractive": { "type": "Boolean" } }, [], [], true));
|
|
3127
3174
|
var PromptTypeIn_default = PromptTypeIn;
|
|
3128
3175
|
|
|
3129
3176
|
// src/lib/components/prompt/skeleton/PromptSkeleton.svelte
|
|
@@ -3398,6 +3445,10 @@
|
|
|
3398
3445
|
),
|
|
3399
3446
|
isPreviewMode: (
|
|
3400
3447
|
/*isPreviewMode*/
|
|
3448
|
+
ctx[7]
|
|
3449
|
+
),
|
|
3450
|
+
isPreviewModeInteractive: (
|
|
3451
|
+
/*isPreviewModeInteractive*/
|
|
3401
3452
|
ctx[6]
|
|
3402
3453
|
)
|
|
3403
3454
|
}
|
|
@@ -3405,7 +3456,7 @@
|
|
|
3405
3456
|
prompttypein.$on(
|
|
3406
3457
|
"saveAnswer",
|
|
3407
3458
|
/*saveEvent*/
|
|
3408
|
-
ctx[
|
|
3459
|
+
ctx[8]
|
|
3409
3460
|
);
|
|
3410
3461
|
return {
|
|
3411
3462
|
c() {
|
|
@@ -3470,13 +3521,17 @@
|
|
|
3470
3521
|
isResultCorrect: (
|
|
3471
3522
|
/*isResultCorrect*/
|
|
3472
3523
|
ctx[5]
|
|
3524
|
+
),
|
|
3525
|
+
isPreviewModeInteractive: (
|
|
3526
|
+
/*isPreviewModeInteractive*/
|
|
3527
|
+
ctx[6]
|
|
3473
3528
|
)
|
|
3474
3529
|
}
|
|
3475
3530
|
});
|
|
3476
3531
|
promptmcq.$on(
|
|
3477
3532
|
"saveOption",
|
|
3478
3533
|
/*saveEvent*/
|
|
3479
|
-
ctx[
|
|
3534
|
+
ctx[8]
|
|
3480
3535
|
);
|
|
3481
3536
|
return {
|
|
3482
3537
|
c() {
|
|
@@ -3595,8 +3650,11 @@
|
|
|
3595
3650
|
}
|
|
3596
3651
|
var bannerLabel = "Invalid session id.";
|
|
3597
3652
|
function instance6($$self, $$props, $$invalidate) {
|
|
3598
|
-
const { "session-id": sessionId, "preview-mode": previewMode, "item-id": itemId } = $$props;
|
|
3599
|
-
const
|
|
3653
|
+
const { "session-id": sessionId, "preview-mode": previewMode, "item-id": itemId, "preview-contentful": previewContentful } = $$props;
|
|
3654
|
+
const previewModeType = ["true", "interactive"];
|
|
3655
|
+
const isPreviewModeInteractive = Boolean(previewMode === "interactive" && itemId);
|
|
3656
|
+
const isPreviewMode = previewModeType.includes(previewMode);
|
|
3657
|
+
const isPreviewContentful = previewContentful === "true" && isPreviewMode;
|
|
3600
3658
|
useSetupAPI();
|
|
3601
3659
|
let sessionData;
|
|
3602
3660
|
let isDataFetching = true;
|
|
@@ -3605,6 +3663,8 @@
|
|
|
3605
3663
|
let isFinished = false;
|
|
3606
3664
|
let isLocked = false;
|
|
3607
3665
|
let isResultCorrect = false;
|
|
3666
|
+
let previewMcqCorrectAnswerId = null;
|
|
3667
|
+
let previewTypeinCorrectAnswers = [];
|
|
3608
3668
|
const skipUserValidationStr = get_store_value(skipUserValidation) ? "?skip_user_validation=true" : "";
|
|
3609
3669
|
const getSessionData = async (sessionId2) => {
|
|
3610
3670
|
try {
|
|
@@ -3621,7 +3681,8 @@
|
|
|
3621
3681
|
};
|
|
3622
3682
|
const getItemData = async (itemId2, metadata) => {
|
|
3623
3683
|
try {
|
|
3624
|
-
|
|
3684
|
+
let includeAnswer = isFinished && isLocked ? "?include=[correct_answer]" : "";
|
|
3685
|
+
includeAnswer = isPreviewContentful ? "?include=[correct_answer,unpublished]&is_contentful_preview=true" : includeAnswer;
|
|
3625
3686
|
const { data } = await useGet(`items/${itemId2}${includeAnswer}`);
|
|
3626
3687
|
$$invalidate(3, interactionType = getInteractionType(data));
|
|
3627
3688
|
$$invalidate(0, sessionData = { ...data, metadata });
|
|
@@ -3675,12 +3736,17 @@
|
|
|
3675
3736
|
};
|
|
3676
3737
|
const setPreviewData = (data) => {
|
|
3677
3738
|
let scoringMetadata;
|
|
3739
|
+
$$invalidate(4, isFinished = !isPreviewModeInteractive);
|
|
3678
3740
|
switch (interactionType) {
|
|
3679
3741
|
case INTERACTION_TYPE_MCQ:
|
|
3680
3742
|
const { options } = data.interaction;
|
|
3681
3743
|
const answerId = Object.values(options).filter((option) => option.correct_choice === true).map((option) => option.id);
|
|
3682
3744
|
scoringMetadata = { hasAnswer: true, answerId: answerId[0] };
|
|
3683
3745
|
$$invalidate(0, sessionData = { ...sessionData, scoringMetadata });
|
|
3746
|
+
if (isPreviewModeInteractive) {
|
|
3747
|
+
previewMcqCorrectAnswerId = answerId[0];
|
|
3748
|
+
}
|
|
3749
|
+
return;
|
|
3684
3750
|
case INTERACTION_TYPE_TYPEIN:
|
|
3685
3751
|
default:
|
|
3686
3752
|
const { correct_answer: correctAnswer, typein_type: typeinType } = data.interaction;
|
|
@@ -3689,9 +3755,50 @@
|
|
|
3689
3755
|
answer: typeinType === TYPEIN_TYPE_SHORT ? correctAnswer[0][0] : correctAnswer[0][0].answer[0]
|
|
3690
3756
|
};
|
|
3691
3757
|
$$invalidate(0, sessionData = { ...sessionData, scoringMetadata });
|
|
3758
|
+
if (isPreviewModeInteractive) {
|
|
3759
|
+
Object.values(correctAnswer).map((data2) => Object.values(data2).map((data3) => {
|
|
3760
|
+
if (typeinType === TYPEIN_TYPE_SHORT) {
|
|
3761
|
+
previewTypeinCorrectAnswers.push(data3);
|
|
3762
|
+
} else {
|
|
3763
|
+
data3.answer.map((answer) => previewTypeinCorrectAnswers.push(answer));
|
|
3764
|
+
}
|
|
3765
|
+
}));
|
|
3766
|
+
}
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
};
|
|
3770
|
+
const updatePreviewData = (data) => {
|
|
3771
|
+
const { scoringMetadata: metadata, interaction } = sessionData;
|
|
3772
|
+
let scoringMetadata;
|
|
3773
|
+
$$invalidate(4, isFinished = true);
|
|
3774
|
+
switch (interactionType) {
|
|
3775
|
+
case INTERACTION_TYPE_MCQ:
|
|
3776
|
+
const { answer_id: answerId } = data;
|
|
3777
|
+
scoringMetadata = { ...metadata, answerId: answerId[0] };
|
|
3778
|
+
$$invalidate(0, sessionData = { ...sessionData, scoringMetadata });
|
|
3779
|
+
$$invalidate(5, isResultCorrect = previewMcqCorrectAnswerId === answerId[0]);
|
|
3780
|
+
return;
|
|
3781
|
+
case INTERACTION_TYPE_TYPEIN:
|
|
3782
|
+
default:
|
|
3783
|
+
const { allow_non_macrons_as_correct_answer: allowNonMacrons, ignore_punctuation: ignorePunctuation } = interaction;
|
|
3784
|
+
const { answer } = data;
|
|
3785
|
+
let typeinAnswer = answer[0];
|
|
3786
|
+
scoringMetadata = { ...metadata, answer: typeinAnswer };
|
|
3787
|
+
$$invalidate(0, sessionData = { ...sessionData, scoringMetadata });
|
|
3788
|
+
if (allowNonMacrons) {
|
|
3789
|
+
typeinAnswer = useRemoveDiacritics(typeinAnswer);
|
|
3790
|
+
}
|
|
3791
|
+
if (ignorePunctuation) {
|
|
3792
|
+
typeinAnswer = useRemovePunctuation(typeinAnswer);
|
|
3793
|
+
}
|
|
3794
|
+
$$invalidate(5, isResultCorrect = previewTypeinCorrectAnswers.includes(typeinAnswer.toLowerCase().trim().replace(/\s+/g, " ")));
|
|
3795
|
+
return;
|
|
3692
3796
|
}
|
|
3693
3797
|
};
|
|
3694
3798
|
const saveEvent = async ({ detail }) => {
|
|
3799
|
+
if (isPreviewModeInteractive && isPreviewMode) {
|
|
3800
|
+
updatePreviewData(detail);
|
|
3801
|
+
}
|
|
3695
3802
|
if (isLocked || isFinished)
|
|
3696
3803
|
return;
|
|
3697
3804
|
try {
|
|
@@ -3703,6 +3810,9 @@
|
|
|
3703
3810
|
$$invalidate(2, isDataSaving = false);
|
|
3704
3811
|
}
|
|
3705
3812
|
};
|
|
3813
|
+
if (!sessionId && !itemId || !sessionId && !isPreviewMode) {
|
|
3814
|
+
isDataFetching = false;
|
|
3815
|
+
}
|
|
3706
3816
|
if (isPreviewMode) {
|
|
3707
3817
|
isFinished = true;
|
|
3708
3818
|
isLocked = true;
|
|
@@ -3713,7 +3823,7 @@
|
|
|
3713
3823
|
getSessionData(sessionId);
|
|
3714
3824
|
}
|
|
3715
3825
|
$$self.$$set = ($$new_props) => {
|
|
3716
|
-
$$invalidate(
|
|
3826
|
+
$$invalidate(26, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)));
|
|
3717
3827
|
};
|
|
3718
3828
|
$$props = exclude_internal_props($$props);
|
|
3719
3829
|
return [
|
|
@@ -3723,6 +3833,7 @@
|
|
|
3723
3833
|
interactionType,
|
|
3724
3834
|
isFinished,
|
|
3725
3835
|
isResultCorrect,
|
|
3836
|
+
isPreviewModeInteractive,
|
|
3726
3837
|
isPreviewMode,
|
|
3727
3838
|
saveEvent
|
|
3728
3839
|
];
|