eat-js-sdk 2.0.41 → 2.0.42
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 +44 -19
- package/package.json +1 -1
|
@@ -9860,11 +9860,6 @@ function shouldSaveTextAnswer(currentAnswer, latestAnswer, isDataSaving) {
|
|
|
9860
9860
|
const hasChanged = currentAnswer !== latestAnswer;
|
|
9861
9861
|
return !isDataSaving && hasChanged;
|
|
9862
9862
|
}
|
|
9863
|
-
function shouldSaveInlineAnswers(currentAnswers, latestAnswersStr, isDataSaving) {
|
|
9864
|
-
const currentAnswersStr = JSON.stringify(currentAnswers);
|
|
9865
|
-
const hasChanged = currentAnswersStr !== latestAnswersStr;
|
|
9866
|
-
return !isDataSaving && hasChanged;
|
|
9867
|
-
}
|
|
9868
9863
|
var root_1$e = /* @__PURE__ */ from_html(`<label class="absolute left-0 top-0 bottom-0" aria-hidden="true"><span class="absolute inset-0 bg-black opacity-5 rounded-l-lg w-8.5 h-10.5 top-1"></span> <span class="absolute font-semibold text-base leading-[19px] text-charcoal px-3 inline-block pt-[15px]"> </span></label>`);
|
|
9869
9864
|
var root_2$8 = /* @__PURE__ */ from_html(`<span class="w-6 h-6 absolute right-4 top-3.5 flex items-center justify-center" aria-hidden="true"><!></span>`);
|
|
9870
9865
|
var root$b = /* @__PURE__ */ from_html(`<span><!> <input placeholder="Type your answer here" autocomplete="off"/> <!></span>`);
|
|
@@ -11042,10 +11037,6 @@ function TypeInComponent($$anchor, $$props) {
|
|
|
11042
11037
|
set(isUpdatingFromBlur, false);
|
|
11043
11038
|
return;
|
|
11044
11039
|
}
|
|
11045
|
-
if (!shouldSaveInlineAnswers(get$1(interactionState).data.inlineInputs, get$1(latestSavedAnswer), isDataSaving())) {
|
|
11046
|
-
set(isUpdatingFromBlur, false);
|
|
11047
|
-
return;
|
|
11048
|
-
}
|
|
11049
11040
|
set(latestSavedAnswer, currentAnswersStr, true);
|
|
11050
11041
|
if (get$1(isInteractiveMode2)) {
|
|
11051
11042
|
const allFilled = (() => {
|
|
@@ -11318,6 +11309,11 @@ const createTypeInInteraction = (config, sessionData) => {
|
|
|
11318
11309
|
const variant = config.variant;
|
|
11319
11310
|
const isPreviewMode2 = () => config.mode === MODES.PREVIEW;
|
|
11320
11311
|
const isNormalMode = () => !config.mode || config.mode === MODES.SESSION;
|
|
11312
|
+
const getExpectedBlanksCount = () => {
|
|
11313
|
+
if (variant !== "inline") return 1;
|
|
11314
|
+
const blankCount = (config.inlinePrompt?.match(/<eat-contentful>/g) || []).length;
|
|
11315
|
+
return blankCount;
|
|
11316
|
+
};
|
|
11321
11317
|
const punctuationRegex = /[\p{P}\p{S}]/gu;
|
|
11322
11318
|
const normalizeAnswer = (raw) => {
|
|
11323
11319
|
if (raw == null) return "";
|
|
@@ -11434,10 +11430,15 @@ const createTypeInInteraction = (config, sessionData) => {
|
|
|
11434
11430
|
component: null,
|
|
11435
11431
|
createInitialState: () => {
|
|
11436
11432
|
const previewAnswers = isPreviewMode2() && sessionData?.scoringMetadata?.answer ? sessionData.scoringMetadata.answer : [];
|
|
11433
|
+
let initialInlineInputs = [];
|
|
11434
|
+
if (variant === "inline") {
|
|
11435
|
+
const expectedBlanks = getExpectedBlanksCount();
|
|
11436
|
+
initialInlineInputs = previewAnswers.length > 0 ? previewAnswers : Array(expectedBlanks).fill("");
|
|
11437
|
+
}
|
|
11437
11438
|
return {
|
|
11438
11439
|
data: {
|
|
11439
11440
|
userInput: variant === "inline" ? "" : previewAnswers[0] || "",
|
|
11440
|
-
inlineInputs:
|
|
11441
|
+
inlineInputs: initialInlineInputs,
|
|
11441
11442
|
interactiveTriggeredResult: false,
|
|
11442
11443
|
showFeedback: false,
|
|
11443
11444
|
attempts: 0,
|
|
@@ -11451,7 +11452,8 @@ const createTypeInInteraction = (config, sessionData) => {
|
|
|
11451
11452
|
isCompleted: (state2) => {
|
|
11452
11453
|
if (config.isFinished !== void 0) return config.isFinished;
|
|
11453
11454
|
if (variant === "inline") {
|
|
11454
|
-
|
|
11455
|
+
const expectedBlanks = getExpectedBlanksCount();
|
|
11456
|
+
return state2.data.inlineInputs.length === expectedBlanks && state2.data.inlineInputs.every((a) => a && a.trim().length > 0);
|
|
11455
11457
|
}
|
|
11456
11458
|
return Boolean(state2.data.userInput && state2.data.userInput.trim().length > 0);
|
|
11457
11459
|
},
|
|
@@ -11470,10 +11472,20 @@ const createTypeInInteraction = (config, sessionData) => {
|
|
|
11470
11472
|
const last = events[events.length - 1];
|
|
11471
11473
|
const rawAnswer = last.answer_id ?? last.answer;
|
|
11472
11474
|
const answers = Array.isArray(rawAnswer) ? rawAnswer : [rawAnswer];
|
|
11475
|
+
let inlineInputs = [];
|
|
11476
|
+
if (variant === "inline") {
|
|
11477
|
+
const expectedBlanks = getExpectedBlanksCount();
|
|
11478
|
+
inlineInputs = Array(expectedBlanks).fill("");
|
|
11479
|
+
answers.forEach((ans, idx) => {
|
|
11480
|
+
if (idx < expectedBlanks) {
|
|
11481
|
+
inlineInputs[idx] = ans || "";
|
|
11482
|
+
}
|
|
11483
|
+
});
|
|
11484
|
+
}
|
|
11473
11485
|
return {
|
|
11474
11486
|
data: {
|
|
11475
11487
|
userInput: variant === "inline" ? "" : answers[0] || "",
|
|
11476
|
-
inlineInputs
|
|
11488
|
+
inlineInputs,
|
|
11477
11489
|
interactiveTriggeredResult: false,
|
|
11478
11490
|
showFeedback: Boolean(config.isFinished),
|
|
11479
11491
|
attempts: events.length,
|
|
@@ -11484,10 +11496,15 @@ const createTypeInInteraction = (config, sessionData) => {
|
|
|
11484
11496
|
lastModified: last.timestamp || interactionUtils.createTimestamp()
|
|
11485
11497
|
};
|
|
11486
11498
|
}
|
|
11499
|
+
let initialInlineInputs = [];
|
|
11500
|
+
if (variant === "inline") {
|
|
11501
|
+
const expectedBlanks = getExpectedBlanksCount();
|
|
11502
|
+
initialInlineInputs = Array(expectedBlanks).fill("");
|
|
11503
|
+
}
|
|
11487
11504
|
return {
|
|
11488
11505
|
data: {
|
|
11489
11506
|
userInput: "",
|
|
11490
|
-
inlineInputs:
|
|
11507
|
+
inlineInputs: initialInlineInputs,
|
|
11491
11508
|
interactiveTriggeredResult: false,
|
|
11492
11509
|
showFeedback: false,
|
|
11493
11510
|
attempts: 0,
|
|
@@ -11505,8 +11522,12 @@ const createTypeInInteraction = (config, sessionData) => {
|
|
|
11505
11522
|
});
|
|
11506
11523
|
},
|
|
11507
11524
|
updateInlineInput: (state2, index2, value) => {
|
|
11508
|
-
const
|
|
11509
|
-
clone
|
|
11525
|
+
const expectedLength = getExpectedBlanksCount();
|
|
11526
|
+
let clone = [...state2.data.inlineInputs];
|
|
11527
|
+
if (clone.length < expectedLength) {
|
|
11528
|
+
clone = Array(expectedLength).fill("").map((_, i) => clone[i] || "");
|
|
11529
|
+
}
|
|
11530
|
+
clone[index2] = value ?? "";
|
|
11510
11531
|
return interactionUtils.updateState(state2, {
|
|
11511
11532
|
inlineInputs: clone,
|
|
11512
11533
|
lastModified: interactionUtils.createTimestamp()
|
|
@@ -11520,10 +11541,14 @@ const createTypeInInteraction = (config, sessionData) => {
|
|
|
11520
11541
|
feedback: generateTypeInFeedback(result, answers)
|
|
11521
11542
|
};
|
|
11522
11543
|
},
|
|
11523
|
-
serialize: (state2) =>
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11544
|
+
serialize: (state2) => {
|
|
11545
|
+
if (variant === "inline") {
|
|
11546
|
+
const expectedLength = getExpectedBlanksCount();
|
|
11547
|
+
const result = Array(expectedLength).fill("").map((_, i) => state2.data.inlineInputs[i] ?? "");
|
|
11548
|
+
return { answer: result, timestamp: state2.lastModified };
|
|
11549
|
+
}
|
|
11550
|
+
return { answer: [state2.data.userInput], timestamp: state2.lastModified };
|
|
11551
|
+
},
|
|
11527
11552
|
deserialize: (answer) => ({
|
|
11528
11553
|
data: {
|
|
11529
11554
|
userInput: variant === "inline" ? "" : answer.answer[0] || "",
|