@xinghunm/ai-chat 1.0.2 → 1.1.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/dist/index.d.mts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +586 -215
- package/dist/index.mjs +606 -231
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -47,7 +47,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
47
47
|
|
|
48
48
|
// src/components/ai-chat/index.tsx
|
|
49
49
|
var import_styled17 = __toESM(require("@emotion/styled"));
|
|
50
|
-
var
|
|
50
|
+
var import_compass_ui5 = require("@xinghunm/compass-ui");
|
|
51
51
|
|
|
52
52
|
// src/components/ai-chat-provider/index.tsx
|
|
53
53
|
var import_react2 = require("react");
|
|
@@ -89,7 +89,10 @@ var DEFAULT_AI_CHAT_LABELS = {
|
|
|
89
89
|
questionnaireSubmitting: "Submitting...",
|
|
90
90
|
questionnaireSubmitted: "Selection submitted. Waiting for the plan to continue...",
|
|
91
91
|
questionnaireValidationPrefix: "Please complete:",
|
|
92
|
-
questionnaireSubmitFailed: "Failed to submit. Please try again."
|
|
92
|
+
questionnaireSubmitFailed: "Failed to submit. Please try again.",
|
|
93
|
+
questionnaireMultiSelectHint: "Multiple choice",
|
|
94
|
+
questionnaireOtherOptionLabel: "Other",
|
|
95
|
+
questionnaireOtherPlaceholder: "Other"
|
|
93
96
|
};
|
|
94
97
|
|
|
95
98
|
// src/store/chat-store.ts
|
|
@@ -1534,29 +1537,120 @@ var Value = import_styled3.default.span`
|
|
|
1534
1537
|
// src/components/chat-thread/components/questionnaire-card.tsx
|
|
1535
1538
|
var import_react7 = require("react");
|
|
1536
1539
|
var import_styled4 = __toESM(require("@emotion/styled"));
|
|
1537
|
-
var
|
|
1540
|
+
var import_compass_ui = require("@xinghunm/compass-ui");
|
|
1541
|
+
|
|
1542
|
+
// src/components/chat-thread/components/questionnaire-card-helpers.ts
|
|
1538
1543
|
var OTHER_OPTION_VALUE = "__other__";
|
|
1539
|
-
var
|
|
1540
|
-
submitting: "Submitting...",
|
|
1541
|
-
submitted: "Selection submitted. Waiting for the plan to continue...",
|
|
1542
|
-
validationPrefix: "Please complete:",
|
|
1543
|
-
submitFailed: "Failed to submit. Please try again."
|
|
1544
|
-
};
|
|
1545
|
-
var createInitialAnswers = (questionnaire) => ({
|
|
1546
|
-
...questionnaire.answers ?? {}
|
|
1547
|
-
});
|
|
1544
|
+
var getQuestionnaireQuestion = (questionnaire) => questionnaire.question;
|
|
1548
1545
|
var getMultiSelectAnswerValues = (answer) => Array.isArray(answer) ? answer : [];
|
|
1549
|
-
var
|
|
1546
|
+
var getQuestionOptionValues = (question) => new Set(question.options.map((option) => option.value));
|
|
1547
|
+
var extractSingleSelectOtherDraft = (question, answer) => {
|
|
1548
|
+
if (typeof answer !== "string") {
|
|
1549
|
+
return "";
|
|
1550
|
+
}
|
|
1551
|
+
return getQuestionOptionValues(question).has(answer) ? "" : answer;
|
|
1552
|
+
};
|
|
1553
|
+
var extractMultiSelectOtherDraft = (question, answer) => {
|
|
1554
|
+
if (!Array.isArray(answer)) {
|
|
1555
|
+
return "";
|
|
1556
|
+
}
|
|
1557
|
+
const optionValues = getQuestionOptionValues(question);
|
|
1558
|
+
const customValue = answer.find(
|
|
1559
|
+
(value) => typeof value === "string" && value !== OTHER_OPTION_VALUE && !optionValues.has(value)
|
|
1560
|
+
);
|
|
1561
|
+
return typeof customValue === "string" ? customValue : "";
|
|
1562
|
+
};
|
|
1563
|
+
var createInitialAnswers = (questionnaire) => {
|
|
1564
|
+
const initialAnswers = {};
|
|
1565
|
+
const question = getQuestionnaireQuestion(questionnaire);
|
|
1566
|
+
if (!question) {
|
|
1567
|
+
return initialAnswers;
|
|
1568
|
+
}
|
|
1569
|
+
const answer = questionnaire.answers?.[question.id];
|
|
1570
|
+
switch (question.kind) {
|
|
1571
|
+
case "single_select": {
|
|
1572
|
+
if (typeof answer !== "string") {
|
|
1573
|
+
break;
|
|
1574
|
+
}
|
|
1575
|
+
if (getQuestionOptionValues(question).has(answer)) {
|
|
1576
|
+
initialAnswers[question.id] = answer;
|
|
1577
|
+
break;
|
|
1578
|
+
}
|
|
1579
|
+
if (question.allowOther) {
|
|
1580
|
+
initialAnswers[question.id] = OTHER_OPTION_VALUE;
|
|
1581
|
+
}
|
|
1582
|
+
break;
|
|
1583
|
+
}
|
|
1584
|
+
case "multi_select": {
|
|
1585
|
+
if (!Array.isArray(answer)) {
|
|
1586
|
+
break;
|
|
1587
|
+
}
|
|
1588
|
+
const optionValues = getQuestionOptionValues(question);
|
|
1589
|
+
const selectedValues = [];
|
|
1590
|
+
let hasOtherValue = false;
|
|
1591
|
+
for (const value of answer) {
|
|
1592
|
+
if (typeof value !== "string") {
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
if (optionValues.has(value)) {
|
|
1596
|
+
selectedValues.push(value);
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
if (question.allowOther && !hasOtherValue) {
|
|
1600
|
+
selectedValues.push(OTHER_OPTION_VALUE);
|
|
1601
|
+
hasOtherValue = true;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
initialAnswers[question.id] = selectedValues;
|
|
1605
|
+
break;
|
|
1606
|
+
}
|
|
1607
|
+
default:
|
|
1608
|
+
initialAnswers[question.id] = answer;
|
|
1609
|
+
}
|
|
1610
|
+
return initialAnswers;
|
|
1611
|
+
};
|
|
1612
|
+
var createInitialOtherDrafts = (questionnaire) => {
|
|
1613
|
+
const drafts = {};
|
|
1614
|
+
const question = getQuestionnaireQuestion(questionnaire);
|
|
1615
|
+
if (!question) {
|
|
1616
|
+
return drafts;
|
|
1617
|
+
}
|
|
1618
|
+
const answer = questionnaire.answers?.[question.id];
|
|
1619
|
+
switch (question.kind) {
|
|
1620
|
+
case "single_select":
|
|
1621
|
+
if (question.allowOther) {
|
|
1622
|
+
drafts[question.id] = extractSingleSelectOtherDraft(question, answer);
|
|
1623
|
+
}
|
|
1624
|
+
break;
|
|
1625
|
+
case "multi_select":
|
|
1626
|
+
if (question.allowOther) {
|
|
1627
|
+
drafts[question.id] = extractMultiSelectOtherDraft(question, answer);
|
|
1628
|
+
}
|
|
1629
|
+
break;
|
|
1630
|
+
default:
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
return drafts;
|
|
1634
|
+
};
|
|
1635
|
+
var getMultiSelectDraftState = (question, answer, otherDraft) => {
|
|
1636
|
+
const answerValues = getMultiSelectAnswerValues(answer);
|
|
1637
|
+
return {
|
|
1638
|
+
selectedValues: answerValues,
|
|
1639
|
+
otherValue: otherDraft,
|
|
1640
|
+
hasOtherSelected: question.allowOther === true && answerValues.includes(OTHER_OPTION_VALUE)
|
|
1641
|
+
};
|
|
1642
|
+
};
|
|
1643
|
+
var getSingleSelectDraftState = (question, answer, otherDraft) => {
|
|
1550
1644
|
if (typeof answer !== "string") {
|
|
1551
1645
|
return {
|
|
1552
1646
|
selectedValue: void 0,
|
|
1553
|
-
otherValue:
|
|
1647
|
+
otherValue: otherDraft
|
|
1554
1648
|
};
|
|
1555
1649
|
}
|
|
1556
|
-
const matchesOption = question.options.some((option) => option.value === answer);
|
|
1650
|
+
const matchesOption = answer !== OTHER_OPTION_VALUE && question.options.some((option) => option.value === answer);
|
|
1557
1651
|
return {
|
|
1558
1652
|
selectedValue: matchesOption ? answer : question.allowOther ? OTHER_OPTION_VALUE : void 0,
|
|
1559
|
-
otherValue:
|
|
1653
|
+
otherValue: otherDraft
|
|
1560
1654
|
};
|
|
1561
1655
|
};
|
|
1562
1656
|
var updateAnswerValue = (current, questionId, value) => ({
|
|
@@ -1568,6 +1662,17 @@ var toggleMultiSelectAnswer = (current, questionId, optionValue) => {
|
|
|
1568
1662
|
const nextValues = currentValues.includes(optionValue) ? currentValues.filter((value) => value !== optionValue) : [...currentValues, optionValue];
|
|
1569
1663
|
return updateAnswerValue(current, questionId, nextValues);
|
|
1570
1664
|
};
|
|
1665
|
+
var toggleMultiSelectOtherAnswer = (current, question) => {
|
|
1666
|
+
const currentValues = getMultiSelectAnswerValues(current[question.id]);
|
|
1667
|
+
if (currentValues.includes(OTHER_OPTION_VALUE)) {
|
|
1668
|
+
return updateAnswerValue(
|
|
1669
|
+
current,
|
|
1670
|
+
question.id,
|
|
1671
|
+
currentValues.filter((value) => value !== OTHER_OPTION_VALUE)
|
|
1672
|
+
);
|
|
1673
|
+
}
|
|
1674
|
+
return updateAnswerValue(current, question.id, [...currentValues, OTHER_OPTION_VALUE]);
|
|
1675
|
+
};
|
|
1571
1676
|
var getTextInputValue = (answer) => typeof answer === "string" ? String(answer) : "";
|
|
1572
1677
|
var getNumberInputValue = (answer) => typeof answer === "number" || typeof answer === "string" ? String(answer) : "";
|
|
1573
1678
|
var getOptionChoiceLabel = (index) => {
|
|
@@ -1576,20 +1681,49 @@ var getOptionChoiceLabel = (index) => {
|
|
|
1576
1681
|
}
|
|
1577
1682
|
return String(index + 1);
|
|
1578
1683
|
};
|
|
1579
|
-
var
|
|
1580
|
-
|
|
1684
|
+
var normalizeQuestionAnswer = (question, answer, otherDraft = "") => {
|
|
1685
|
+
if (answer === void 0) {
|
|
1686
|
+
return void 0;
|
|
1687
|
+
}
|
|
1581
1688
|
switch (question.kind) {
|
|
1582
|
-
case "boolean":
|
|
1583
|
-
return typeof answer !== "boolean";
|
|
1584
1689
|
case "multi_select":
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1690
|
+
if (!Array.isArray(answer)) {
|
|
1691
|
+
return void 0;
|
|
1692
|
+
}
|
|
1693
|
+
return (() => {
|
|
1694
|
+
const optionValues = getQuestionOptionValues(question);
|
|
1695
|
+
const normalizedOtherDraft = otherDraft.trim();
|
|
1696
|
+
const normalizedValues = answer.flatMap((value) => {
|
|
1697
|
+
if (typeof value !== "string") {
|
|
1698
|
+
return [];
|
|
1699
|
+
}
|
|
1700
|
+
if (optionValues.has(value)) {
|
|
1701
|
+
return [value];
|
|
1702
|
+
}
|
|
1703
|
+
if (!question.allowOther || value !== OTHER_OPTION_VALUE) {
|
|
1704
|
+
return [];
|
|
1705
|
+
}
|
|
1706
|
+
return normalizedOtherDraft === "" ? [] : [normalizedOtherDraft];
|
|
1707
|
+
});
|
|
1708
|
+
return normalizedValues.length > 0 ? normalizedValues : void 0;
|
|
1709
|
+
})();
|
|
1589
1710
|
case "single_select":
|
|
1590
|
-
|
|
1711
|
+
if (answer === OTHER_OPTION_VALUE) {
|
|
1712
|
+
const normalizedOtherDraft = otherDraft.trim();
|
|
1713
|
+
return normalizedOtherDraft === "" ? void 0 : normalizedOtherDraft;
|
|
1714
|
+
}
|
|
1715
|
+
if (typeof answer !== "string" || answer.trim() === "") {
|
|
1716
|
+
return void 0;
|
|
1717
|
+
}
|
|
1718
|
+
return getQuestionOptionValues(question).has(answer) ? answer : void 0;
|
|
1719
|
+
case "text":
|
|
1720
|
+
return typeof answer === "string" && answer.trim() !== "" ? answer : void 0;
|
|
1721
|
+
case "number":
|
|
1722
|
+
return typeof answer === "number" && !Number.isNaN(answer) ? answer : void 0;
|
|
1723
|
+
case "boolean":
|
|
1724
|
+
return typeof answer === "boolean" ? answer : void 0;
|
|
1591
1725
|
default:
|
|
1592
|
-
return
|
|
1726
|
+
return answer;
|
|
1593
1727
|
}
|
|
1594
1728
|
};
|
|
1595
1729
|
var formatQuestionAnswer = (question, answer) => {
|
|
@@ -1617,80 +1751,221 @@ var formatQuestionAnswer = (question, answer) => {
|
|
|
1617
1751
|
return String(answer);
|
|
1618
1752
|
}
|
|
1619
1753
|
};
|
|
1620
|
-
var
|
|
1754
|
+
var buildQuestionSubmissionDetail = (question, answer) => {
|
|
1621
1755
|
if (answer === void 0) {
|
|
1622
1756
|
return void 0;
|
|
1623
1757
|
}
|
|
1624
1758
|
switch (question.kind) {
|
|
1625
|
-
case "
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
return
|
|
1632
|
-
|
|
1633
|
-
|
|
1759
|
+
case "single_select": {
|
|
1760
|
+
if (typeof answer !== "string") {
|
|
1761
|
+
return void 0;
|
|
1762
|
+
}
|
|
1763
|
+
const optionValues = getQuestionOptionValues(question);
|
|
1764
|
+
const trimmedAnswer = answer.trim();
|
|
1765
|
+
return {
|
|
1766
|
+
questionId: question.id,
|
|
1767
|
+
kind: question.kind,
|
|
1768
|
+
value: answer,
|
|
1769
|
+
selectedOptionValues: optionValues.has(answer) ? [answer] : [],
|
|
1770
|
+
otherValue: optionValues.has(answer) || trimmedAnswer === "" ? void 0 : trimmedAnswer
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
case "multi_select": {
|
|
1774
|
+
if (!Array.isArray(answer)) {
|
|
1775
|
+
return void 0;
|
|
1776
|
+
}
|
|
1777
|
+
const optionValues = getQuestionOptionValues(question);
|
|
1778
|
+
const selectedOptionValues = answer.filter(
|
|
1779
|
+
(value) => typeof value === "string" && optionValues.has(value)
|
|
1780
|
+
);
|
|
1781
|
+
const otherValue = answer.find(
|
|
1782
|
+
(value) => typeof value === "string" && !optionValues.has(value)
|
|
1783
|
+
);
|
|
1784
|
+
return {
|
|
1785
|
+
questionId: question.id,
|
|
1786
|
+
kind: question.kind,
|
|
1787
|
+
value: answer,
|
|
1788
|
+
selectedOptionValues,
|
|
1789
|
+
otherValue: otherValue?.trim() ? otherValue.trim() : void 0
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1634
1792
|
default:
|
|
1635
|
-
return
|
|
1793
|
+
return {
|
|
1794
|
+
questionId: question.id,
|
|
1795
|
+
kind: question.kind,
|
|
1796
|
+
value: answer
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
var getMissingRequiredQuestions = (questionnaire, answers, otherDrafts) => {
|
|
1801
|
+
const question = getQuestionnaireQuestion(questionnaire);
|
|
1802
|
+
if (!question || !question.required) {
|
|
1803
|
+
return [];
|
|
1804
|
+
}
|
|
1805
|
+
return normalizeQuestionAnswer(question, answers[question.id], otherDrafts[question.id]) === void 0 ? [question] : [];
|
|
1806
|
+
};
|
|
1807
|
+
var prepareQuestionnaireSubmission = (questionnaire, answers, otherDrafts) => {
|
|
1808
|
+
const question = getQuestionnaireQuestion(questionnaire);
|
|
1809
|
+
if (!question) {
|
|
1810
|
+
return {
|
|
1811
|
+
normalizedAnswers: {},
|
|
1812
|
+
submissionDetails: void 0,
|
|
1813
|
+
content: questionnaire.title ?? "Questionnaire responses"
|
|
1814
|
+
};
|
|
1636
1815
|
}
|
|
1816
|
+
const value = normalizeQuestionAnswer(question, answers[question.id], otherDrafts[question.id]);
|
|
1817
|
+
const normalizedAnswers = value === void 0 ? {} : { [question.id]: value };
|
|
1818
|
+
const detail = buildQuestionSubmissionDetail(question, normalizedAnswers[question.id]);
|
|
1819
|
+
const submissionDetails = detail === void 0 ? void 0 : { [question.id]: detail };
|
|
1820
|
+
return {
|
|
1821
|
+
normalizedAnswers,
|
|
1822
|
+
submissionDetails,
|
|
1823
|
+
content: [
|
|
1824
|
+
questionnaire.title ?? "Questionnaire responses",
|
|
1825
|
+
...normalizedAnswers[question.id] === void 0 ? [] : [
|
|
1826
|
+
`- ${question.label}: ${formatQuestionAnswer(question, normalizedAnswers[question.id])}`
|
|
1827
|
+
]
|
|
1828
|
+
].join("\n")
|
|
1829
|
+
};
|
|
1830
|
+
};
|
|
1831
|
+
var getQuestionnaireStateKey = (questionnaire) => JSON.stringify([
|
|
1832
|
+
questionnaire.questionnaireId,
|
|
1833
|
+
questionnaire.blockKey,
|
|
1834
|
+
questionnaire.question,
|
|
1835
|
+
questionnaire.status,
|
|
1836
|
+
questionnaire.statusMessage
|
|
1837
|
+
]);
|
|
1838
|
+
|
|
1839
|
+
// src/components/chat-thread/components/questionnaire-card.tsx
|
|
1840
|
+
var import_jsx_runtime5 = require("@emotion/react/jsx-runtime");
|
|
1841
|
+
var DEFAULT_QUESTIONNAIRE_CARD_LABELS = {
|
|
1842
|
+
submitting: "Submitting...",
|
|
1843
|
+
submitted: "Selection submitted. Waiting for the plan to continue...",
|
|
1844
|
+
validationPrefix: "Please complete:",
|
|
1845
|
+
submitFailed: "Failed to submit. Please try again.",
|
|
1846
|
+
multiSelectHint: "Multiple choice",
|
|
1847
|
+
otherOptionLabel: "Other",
|
|
1848
|
+
otherPlaceholder: "Other"
|
|
1849
|
+
};
|
|
1850
|
+
var stopInputClickPropagation = (event) => {
|
|
1851
|
+
event.stopPropagation();
|
|
1637
1852
|
};
|
|
1853
|
+
var stopInputKeyPropagation = (event) => {
|
|
1854
|
+
event.stopPropagation();
|
|
1855
|
+
};
|
|
1856
|
+
var OptionChoice = ({
|
|
1857
|
+
questionId,
|
|
1858
|
+
optionLabel,
|
|
1859
|
+
index,
|
|
1860
|
+
isSelected,
|
|
1861
|
+
isInteractionLocked,
|
|
1862
|
+
onClick,
|
|
1863
|
+
inlineInput,
|
|
1864
|
+
tone = "default"
|
|
1865
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1866
|
+
OptionChoiceItem,
|
|
1867
|
+
{
|
|
1868
|
+
role: "button",
|
|
1869
|
+
tabIndex: isInteractionLocked ? -1 : 0,
|
|
1870
|
+
"aria-pressed": isSelected,
|
|
1871
|
+
"data-selected": isSelected,
|
|
1872
|
+
"data-tone": tone,
|
|
1873
|
+
"data-testid": `question-option-${questionId}-${index}`,
|
|
1874
|
+
onClick: (event) => {
|
|
1875
|
+
if (isInteractionLocked) {
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
if (event.target instanceof HTMLElement && event.target.closest("input")) {
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
onClick();
|
|
1882
|
+
},
|
|
1883
|
+
onKeyDown: (event) => {
|
|
1884
|
+
if (isInteractionLocked) {
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
if (event.key !== "Enter" && event.key !== " ") {
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
event.preventDefault();
|
|
1891
|
+
onClick();
|
|
1892
|
+
},
|
|
1893
|
+
children: [
|
|
1894
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OptionChoiceMarker, { "data-selected": isSelected, children: getOptionChoiceLabel(index) }),
|
|
1895
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(OptionChoiceContent, { children: [
|
|
1896
|
+
inlineInput ? null : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OptionChoiceLabel, { children: optionLabel }),
|
|
1897
|
+
inlineInput
|
|
1898
|
+
] })
|
|
1899
|
+
]
|
|
1900
|
+
}
|
|
1901
|
+
);
|
|
1638
1902
|
var QuestionnaireCardInner = ({
|
|
1639
1903
|
questionnaire,
|
|
1640
1904
|
interactive = false,
|
|
1641
1905
|
onSubmit,
|
|
1642
1906
|
labels
|
|
1643
1907
|
}) => {
|
|
1908
|
+
const questionnaireRef = (0, import_react7.useRef)(questionnaire);
|
|
1909
|
+
const otherInputRefs = (0, import_react7.useRef)({});
|
|
1644
1910
|
const [answers, setAnswers] = (0, import_react7.useState)(
|
|
1645
1911
|
() => createInitialAnswers(questionnaire)
|
|
1646
1912
|
);
|
|
1913
|
+
const [otherDrafts, setOtherDrafts] = (0, import_react7.useState)(
|
|
1914
|
+
() => createInitialOtherDrafts(questionnaire)
|
|
1915
|
+
);
|
|
1647
1916
|
const [errorMessage, setErrorMessage] = (0, import_react7.useState)(null);
|
|
1648
1917
|
const [isSubmitting, setIsSubmitting] = (0, import_react7.useState)(false);
|
|
1649
1918
|
const [isSubmitted, setIsSubmitted] = (0, import_react7.useState)(false);
|
|
1919
|
+
const [pendingFocusQuestionId, setPendingFocusQuestionId] = (0, import_react7.useState)(null);
|
|
1650
1920
|
const resolvedLabels = {
|
|
1651
1921
|
...DEFAULT_QUESTIONNAIRE_CARD_LABELS,
|
|
1652
1922
|
...labels
|
|
1653
1923
|
};
|
|
1654
1924
|
const hasExternalFailureStatus = questionnaire.status === "expired" || questionnaire.status === "failed";
|
|
1925
|
+
const question = getQuestionnaireQuestion(questionnaire);
|
|
1655
1926
|
const visibleErrorMessage = questionnaire.statusMessage ?? errorMessage;
|
|
1656
1927
|
const isInteractionLocked = !interactive || isSubmitting || isSubmitted || hasExternalFailureStatus;
|
|
1928
|
+
questionnaireRef.current = questionnaire;
|
|
1929
|
+
(0, import_react7.useEffect)(() => {
|
|
1930
|
+
setAnswers(createInitialAnswers(questionnaireRef.current));
|
|
1931
|
+
setOtherDrafts(createInitialOtherDrafts(questionnaireRef.current));
|
|
1932
|
+
}, [questionnaire.answers]);
|
|
1933
|
+
(0, import_react7.useEffect)(() => {
|
|
1934
|
+
if (!pendingFocusQuestionId || isInteractionLocked) {
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
const inputElement = otherInputRefs.current[pendingFocusQuestionId];
|
|
1938
|
+
if (!inputElement) {
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
inputElement.focus();
|
|
1942
|
+
setPendingFocusQuestionId(null);
|
|
1943
|
+
}, [isInteractionLocked, pendingFocusQuestionId]);
|
|
1657
1944
|
const handleSubmit = async () => {
|
|
1658
1945
|
if (isSubmitting || isSubmitted) {
|
|
1659
1946
|
return;
|
|
1660
1947
|
}
|
|
1661
|
-
const missingQuestions = questionnaire
|
|
1662
|
-
(question) => question.required && isMissingRequiredAnswer(question, answers)
|
|
1663
|
-
);
|
|
1948
|
+
const missingQuestions = getMissingRequiredQuestions(questionnaire, answers, otherDrafts);
|
|
1664
1949
|
if (missingQuestions.length > 0) {
|
|
1665
1950
|
setErrorMessage(
|
|
1666
|
-
`${resolvedLabels.validationPrefix} ${missingQuestions.map((
|
|
1951
|
+
`${resolvedLabels.validationPrefix} ${missingQuestions.map((question2) => question2.label).join(", ")}`
|
|
1667
1952
|
);
|
|
1668
1953
|
return;
|
|
1669
1954
|
}
|
|
1670
1955
|
setErrorMessage(null);
|
|
1671
1956
|
setIsSubmitting(true);
|
|
1672
|
-
const normalizedAnswers =
|
|
1673
|
-
questionnaire
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
})
|
|
1957
|
+
const { normalizedAnswers, submissionDetails, content } = prepareQuestionnaireSubmission(
|
|
1958
|
+
questionnaire,
|
|
1959
|
+
answers,
|
|
1960
|
+
otherDrafts
|
|
1677
1961
|
);
|
|
1678
|
-
const contentLines = [
|
|
1679
|
-
questionnaire.title ?? "Questionnaire responses",
|
|
1680
|
-
...questionnaire.questions.flatMap((question) => {
|
|
1681
|
-
const value = normalizedAnswers[question.id];
|
|
1682
|
-
if (value === void 0) {
|
|
1683
|
-
return [];
|
|
1684
|
-
}
|
|
1685
|
-
return [`- ${question.label}: ${formatQuestionAnswer(question, value)}`];
|
|
1686
|
-
})
|
|
1687
|
-
];
|
|
1688
1962
|
try {
|
|
1689
1963
|
await onSubmit?.({
|
|
1690
1964
|
questionnaireId: questionnaire.questionnaireId,
|
|
1691
1965
|
...questionnaire.blockKey ? { blockKey: questionnaire.blockKey } : {},
|
|
1692
1966
|
answers: normalizedAnswers,
|
|
1693
|
-
|
|
1967
|
+
details: submissionDetails,
|
|
1968
|
+
content
|
|
1694
1969
|
});
|
|
1695
1970
|
setIsSubmitted(true);
|
|
1696
1971
|
} catch (error) {
|
|
@@ -1699,125 +1974,156 @@ var QuestionnaireCardInner = ({
|
|
|
1699
1974
|
setIsSubmitting(false);
|
|
1700
1975
|
}
|
|
1701
1976
|
};
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1977
|
+
if (!question) {
|
|
1978
|
+
return null;
|
|
1979
|
+
}
|
|
1980
|
+
const renderQuestion = (questionToRender) => {
|
|
1981
|
+
switch (questionToRender.kind) {
|
|
1982
|
+
case "multi_select": {
|
|
1983
|
+
const multiSelectDraft = getMultiSelectDraftState(
|
|
1984
|
+
questionToRender,
|
|
1985
|
+
answers[questionToRender.id],
|
|
1986
|
+
otherDrafts[questionToRender.id] ?? ""
|
|
1987
|
+
);
|
|
1988
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionBody, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(OptionList, { children: [
|
|
1989
|
+
questionToRender.options.map((option, index) => {
|
|
1990
|
+
const isSelected = multiSelectDraft.selectedValues.includes(option.value);
|
|
1991
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1992
|
+
OptionChoice,
|
|
1993
|
+
{
|
|
1994
|
+
questionId: questionToRender.id,
|
|
1995
|
+
optionLabel: option.label,
|
|
1996
|
+
index,
|
|
1997
|
+
isSelected,
|
|
1998
|
+
isInteractionLocked,
|
|
1999
|
+
onClick: () => setAnswers(
|
|
2000
|
+
(current) => toggleMultiSelectAnswer(current, questionToRender.id, option.value)
|
|
2001
|
+
)
|
|
2002
|
+
},
|
|
2003
|
+
option.value
|
|
2004
|
+
);
|
|
2005
|
+
}),
|
|
2006
|
+
questionToRender.allowOther ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2007
|
+
OptionChoice,
|
|
2008
|
+
{
|
|
2009
|
+
questionId: questionToRender.id,
|
|
2010
|
+
optionLabel: resolvedLabels.otherOptionLabel,
|
|
2011
|
+
index: questionToRender.options.length,
|
|
2012
|
+
isSelected: multiSelectDraft.hasOtherSelected,
|
|
2013
|
+
isInteractionLocked,
|
|
2014
|
+
tone: "other",
|
|
2015
|
+
onClick: () => {
|
|
2016
|
+
if (!multiSelectDraft.hasOtherSelected) {
|
|
2017
|
+
setPendingFocusQuestionId(questionToRender.id);
|
|
2018
|
+
}
|
|
2019
|
+
setAnswers((current) => toggleMultiSelectOtherAnswer(current, questionToRender));
|
|
2020
|
+
},
|
|
2021
|
+
inlineInput: multiSelectDraft.hasOtherSelected ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2022
|
+
InlineOtherInput,
|
|
2023
|
+
{
|
|
2024
|
+
ref: (node) => {
|
|
2025
|
+
otherInputRefs.current[questionToRender.id] = node;
|
|
2026
|
+
},
|
|
2027
|
+
"data-testid": `question-input-${questionToRender.id}`,
|
|
2028
|
+
type: "text",
|
|
2029
|
+
value: multiSelectDraft.otherValue,
|
|
2030
|
+
placeholder: resolvedLabels.otherPlaceholder,
|
|
2031
|
+
readOnly: isInteractionLocked,
|
|
2032
|
+
onClick: stopInputClickPropagation,
|
|
2033
|
+
onKeyDown: stopInputKeyPropagation,
|
|
2034
|
+
onChange: (event) => {
|
|
2035
|
+
setOtherDrafts((current) => ({
|
|
2036
|
+
...current,
|
|
2037
|
+
[questionToRender.id]: event.target.value
|
|
2038
|
+
}));
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
) : null
|
|
2042
|
+
},
|
|
2043
|
+
`${questionToRender.id}-other`
|
|
2044
|
+
) : null
|
|
2045
|
+
] }) });
|
|
2046
|
+
}
|
|
1764
2047
|
case "single_select": {
|
|
1765
|
-
const singleSelectDraft = getSingleSelectDraftState(
|
|
2048
|
+
const singleSelectDraft = getSingleSelectDraftState(
|
|
2049
|
+
questionToRender,
|
|
2050
|
+
answers[questionToRender.id],
|
|
2051
|
+
otherDrafts[questionToRender.id] ?? ""
|
|
2052
|
+
);
|
|
1766
2053
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionBody, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(OptionList, { children: [
|
|
1767
|
-
|
|
2054
|
+
questionToRender.options.map((option, index) => {
|
|
1768
2055
|
const isSelected = singleSelectDraft.selectedValue === option.value;
|
|
1769
|
-
return
|
|
1770
|
-
|
|
1771
|
-
optionLabel: option.label,
|
|
1772
|
-
index,
|
|
1773
|
-
isSelected,
|
|
1774
|
-
onClick: () => setAnswers((current) => updateAnswerValue(current, question.id, option.value))
|
|
1775
|
-
});
|
|
1776
|
-
}),
|
|
1777
|
-
question.allowOther ? renderOptionChoice({
|
|
1778
|
-
questionId: question.id,
|
|
1779
|
-
optionLabel: "Other",
|
|
1780
|
-
index: question.options.length,
|
|
1781
|
-
isSelected: singleSelectDraft.selectedValue === OTHER_OPTION_VALUE,
|
|
1782
|
-
tone: "other",
|
|
1783
|
-
onClick: () => setAnswers(
|
|
1784
|
-
(current) => updateAnswerValue(current, question.id, singleSelectDraft.otherValue)
|
|
1785
|
-
),
|
|
1786
|
-
inlineInput: singleSelectDraft.selectedValue === OTHER_OPTION_VALUE ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1787
|
-
InlineOtherInput,
|
|
2056
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2057
|
+
OptionChoice,
|
|
1788
2058
|
{
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
onClick: (
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
2059
|
+
questionId: questionToRender.id,
|
|
2060
|
+
optionLabel: option.label,
|
|
2061
|
+
index,
|
|
2062
|
+
isSelected,
|
|
2063
|
+
isInteractionLocked,
|
|
2064
|
+
onClick: () => setAnswers(
|
|
2065
|
+
(current) => updateAnswerValue(current, questionToRender.id, option.value)
|
|
2066
|
+
)
|
|
2067
|
+
},
|
|
2068
|
+
option.value
|
|
2069
|
+
);
|
|
2070
|
+
}),
|
|
2071
|
+
questionToRender.allowOther ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2072
|
+
OptionChoice,
|
|
2073
|
+
{
|
|
2074
|
+
questionId: questionToRender.id,
|
|
2075
|
+
optionLabel: resolvedLabels.otherOptionLabel,
|
|
2076
|
+
index: questionToRender.options.length,
|
|
2077
|
+
isSelected: singleSelectDraft.selectedValue === OTHER_OPTION_VALUE,
|
|
2078
|
+
isInteractionLocked,
|
|
2079
|
+
tone: "other",
|
|
2080
|
+
onClick: () => {
|
|
2081
|
+
if (singleSelectDraft.selectedValue !== OTHER_OPTION_VALUE) {
|
|
2082
|
+
setPendingFocusQuestionId(questionToRender.id);
|
|
1804
2083
|
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
2084
|
+
setAnswers(
|
|
2085
|
+
(current) => updateAnswerValue(current, questionToRender.id, OTHER_OPTION_VALUE)
|
|
2086
|
+
);
|
|
2087
|
+
},
|
|
2088
|
+
inlineInput: singleSelectDraft.selectedValue === OTHER_OPTION_VALUE ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2089
|
+
InlineOtherInput,
|
|
2090
|
+
{
|
|
2091
|
+
ref: (node) => {
|
|
2092
|
+
otherInputRefs.current[questionToRender.id] = node;
|
|
2093
|
+
},
|
|
2094
|
+
"data-testid": `question-input-${questionToRender.id}`,
|
|
2095
|
+
type: "text",
|
|
2096
|
+
value: singleSelectDraft.otherValue,
|
|
2097
|
+
placeholder: resolvedLabels.otherPlaceholder,
|
|
2098
|
+
readOnly: isInteractionLocked,
|
|
2099
|
+
onClick: stopInputClickPropagation,
|
|
2100
|
+
onKeyDown: stopInputKeyPropagation,
|
|
2101
|
+
onChange: (event) => {
|
|
2102
|
+
setOtherDrafts((current) => ({
|
|
2103
|
+
...current,
|
|
2104
|
+
[questionToRender.id]: event.target.value
|
|
2105
|
+
}));
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
) : null
|
|
2109
|
+
},
|
|
2110
|
+
`${questionToRender.id}-other`
|
|
2111
|
+
) : null
|
|
1808
2112
|
] }) });
|
|
1809
2113
|
}
|
|
1810
2114
|
case "text":
|
|
1811
2115
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionBody, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1812
2116
|
TextInput,
|
|
1813
2117
|
{
|
|
1814
|
-
"data-testid": `question-input-${
|
|
2118
|
+
"data-testid": `question-input-${questionToRender.id}`,
|
|
1815
2119
|
type: "text",
|
|
1816
|
-
value: getTextInputValue(answers[
|
|
1817
|
-
placeholder:
|
|
2120
|
+
value: getTextInputValue(answers[questionToRender.id]),
|
|
2121
|
+
placeholder: questionToRender.placeholder,
|
|
1818
2122
|
readOnly: isInteractionLocked,
|
|
1819
2123
|
onChange: (event) => {
|
|
1820
|
-
setAnswers(
|
|
2124
|
+
setAnswers(
|
|
2125
|
+
(current) => updateAnswerValue(current, questionToRender.id, event.target.value)
|
|
2126
|
+
);
|
|
1821
2127
|
}
|
|
1822
2128
|
}
|
|
1823
2129
|
) });
|
|
@@ -1826,55 +2132,63 @@ var QuestionnaireCardInner = ({
|
|
|
1826
2132
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1827
2133
|
TextInput,
|
|
1828
2134
|
{
|
|
1829
|
-
"data-testid": `question-input-${
|
|
2135
|
+
"data-testid": `question-input-${questionToRender.id}`,
|
|
1830
2136
|
type: "number",
|
|
1831
|
-
value: getNumberInputValue(answers[
|
|
1832
|
-
placeholder:
|
|
2137
|
+
value: getNumberInputValue(answers[questionToRender.id]),
|
|
2138
|
+
placeholder: questionToRender.placeholder,
|
|
1833
2139
|
readOnly: isInteractionLocked,
|
|
1834
2140
|
onChange: (event) => {
|
|
1835
2141
|
setAnswers(
|
|
1836
2142
|
(current) => updateAnswerValue(
|
|
1837
2143
|
current,
|
|
1838
|
-
|
|
2144
|
+
questionToRender.id,
|
|
1839
2145
|
event.target.value === "" ? void 0 : Number(event.target.value)
|
|
1840
2146
|
)
|
|
1841
2147
|
);
|
|
1842
2148
|
}
|
|
1843
2149
|
}
|
|
1844
2150
|
),
|
|
1845
|
-
|
|
2151
|
+
questionToRender.unit ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Unit, { children: questionToRender.unit }) : null
|
|
1846
2152
|
] }) });
|
|
1847
2153
|
case "boolean":
|
|
1848
2154
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionBody, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(OptionList, { children: [
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
2155
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2156
|
+
OptionChoice,
|
|
2157
|
+
{
|
|
2158
|
+
questionId: questionToRender.id,
|
|
2159
|
+
optionLabel: questionToRender.trueLabel ?? "Yes",
|
|
2160
|
+
index: 0,
|
|
2161
|
+
isSelected: answers[questionToRender.id] === true,
|
|
2162
|
+
isInteractionLocked,
|
|
2163
|
+
onClick: () => setAnswers((current) => updateAnswerValue(current, questionToRender.id, true))
|
|
2164
|
+
}
|
|
2165
|
+
),
|
|
2166
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2167
|
+
OptionChoice,
|
|
2168
|
+
{
|
|
2169
|
+
questionId: questionToRender.id,
|
|
2170
|
+
optionLabel: questionToRender.falseLabel ?? "No",
|
|
2171
|
+
index: 1,
|
|
2172
|
+
isSelected: answers[questionToRender.id] === false,
|
|
2173
|
+
isInteractionLocked,
|
|
2174
|
+
onClick: () => setAnswers((current) => updateAnswerValue(current, questionToRender.id, false))
|
|
2175
|
+
}
|
|
2176
|
+
)
|
|
1863
2177
|
] }) });
|
|
1864
2178
|
default:
|
|
1865
2179
|
return null;
|
|
1866
2180
|
}
|
|
1867
2181
|
};
|
|
1868
2182
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Card4, { "data-testid": "questionnaire-card", children: [
|
|
1869
|
-
questionnaire.title ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Title3, { children: questionnaire.title }) : null,
|
|
1870
2183
|
questionnaire.description ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Description, { children: questionnaire.description }) : null,
|
|
1871
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionList, { children:
|
|
2184
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionList, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(QuestionCard, { children: [
|
|
1872
2185
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(QuestionLabel, { children: [
|
|
1873
2186
|
question.label,
|
|
1874
2187
|
question.required ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Required, { children: "*" }) : null
|
|
1875
2188
|
] }),
|
|
2189
|
+
question.kind === "multi_select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionHint, { children: resolvedLabels.multiSelectHint }) : null,
|
|
1876
2190
|
renderQuestion(question)
|
|
1877
|
-
] }, question.id)
|
|
2191
|
+
] }, question.id) }),
|
|
1878
2192
|
visibleErrorMessage ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorMessage, { "data-testid": "questionnaire-error", children: visibleErrorMessage }) : null,
|
|
1879
2193
|
isSubmitted ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SuccessMessage, { "data-testid": "questionnaire-success", children: resolvedLabels.submitted }) : interactive && !hasExternalFailureStatus ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1880
2194
|
SubmitButton,
|
|
@@ -1890,12 +2204,6 @@ var QuestionnaireCardInner = ({
|
|
|
1890
2204
|
) : null
|
|
1891
2205
|
] });
|
|
1892
2206
|
};
|
|
1893
|
-
var getQuestionnaireStateKey = (questionnaire) => JSON.stringify([
|
|
1894
|
-
questionnaire.questionnaireId,
|
|
1895
|
-
questionnaire.questions,
|
|
1896
|
-
questionnaire.status,
|
|
1897
|
-
questionnaire.statusMessage
|
|
1898
|
-
]);
|
|
1899
2207
|
var QuestionnaireCard = (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(QuestionnaireCardInner, { ...props }, getQuestionnaireStateKey(props.questionnaire));
|
|
1900
2208
|
var Card4 = import_styled4.default.section`
|
|
1901
2209
|
display: grid;
|
|
@@ -1905,11 +2213,6 @@ var Card4 = import_styled4.default.section`
|
|
|
1905
2213
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
1906
2214
|
background: rgba(255, 255, 255, 0.03);
|
|
1907
2215
|
`;
|
|
1908
|
-
var Title3 = import_styled4.default.strong`
|
|
1909
|
-
color: rgba(255, 255, 255, 0.94);
|
|
1910
|
-
font-size: 16px;
|
|
1911
|
-
line-height: 1.4;
|
|
1912
|
-
`;
|
|
1913
2216
|
var Description = import_styled4.default.p`
|
|
1914
2217
|
margin: 0;
|
|
1915
2218
|
color: rgba(255, 255, 255, 0.72);
|
|
@@ -1928,13 +2231,18 @@ var QuestionCard = import_styled4.default.div`
|
|
|
1928
2231
|
`;
|
|
1929
2232
|
var QuestionLabel = import_styled4.default.div`
|
|
1930
2233
|
color: rgba(255, 255, 255, 0.9);
|
|
1931
|
-
font-size:
|
|
2234
|
+
font-size: 14px;
|
|
1932
2235
|
font-weight: 600;
|
|
1933
2236
|
`;
|
|
1934
2237
|
var Required = import_styled4.default.span`
|
|
1935
2238
|
margin-left: 4px;
|
|
1936
2239
|
color: rgba(255, 122, 122, 0.9);
|
|
1937
2240
|
`;
|
|
2241
|
+
var QuestionHint = import_styled4.default.div`
|
|
2242
|
+
color: rgba(132, 180, 255, 0.9);
|
|
2243
|
+
font-size: 12px;
|
|
2244
|
+
line-height: 1.4;
|
|
2245
|
+
`;
|
|
1938
2246
|
var QuestionBody = import_styled4.default.div`
|
|
1939
2247
|
display: grid;
|
|
1940
2248
|
gap: 10px;
|
|
@@ -1952,7 +2260,7 @@ var OptionChoiceItem = import_styled4.default.div`
|
|
|
1952
2260
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
1953
2261
|
border-radius: 14px;
|
|
1954
2262
|
background: rgba(255, 255, 255, 0.03);
|
|
1955
|
-
padding: 12px
|
|
2263
|
+
padding: 2px 12px;
|
|
1956
2264
|
color: rgba(255, 255, 255, 0.9);
|
|
1957
2265
|
cursor: pointer;
|
|
1958
2266
|
transition:
|
|
@@ -2003,8 +2311,11 @@ var OptionChoiceMarker = import_styled4.default.span`
|
|
|
2003
2311
|
}
|
|
2004
2312
|
`;
|
|
2005
2313
|
var OptionChoiceContent = import_styled4.default.span`
|
|
2006
|
-
display:
|
|
2007
|
-
|
|
2314
|
+
display: flex;
|
|
2315
|
+
flex-direction: column;
|
|
2316
|
+
justify-content: center;
|
|
2317
|
+
gap: 4px;
|
|
2318
|
+
min-height: 40px;
|
|
2008
2319
|
min-width: 0;
|
|
2009
2320
|
flex: 1;
|
|
2010
2321
|
`;
|
|
@@ -2027,8 +2338,37 @@ var TextInput = import_styled4.default.input`
|
|
|
2027
2338
|
color: rgba(255, 255, 255, 0.34);
|
|
2028
2339
|
}
|
|
2029
2340
|
`;
|
|
2030
|
-
var InlineOtherInput = (0, import_styled4.default)(
|
|
2341
|
+
var InlineOtherInput = (0, import_styled4.default)(import_compass_ui.InputField)`
|
|
2342
|
+
width: 100%;
|
|
2031
2343
|
margin-top: 0;
|
|
2344
|
+
|
|
2345
|
+
.compass-input-field-wrapper {
|
|
2346
|
+
min-height: 30px;
|
|
2347
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
2348
|
+
border-radius: 10px;
|
|
2349
|
+
background: rgba(13, 15, 21, 0.55);
|
|
2350
|
+
box-shadow: none;
|
|
2351
|
+
padding: 2px 9px;
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
.compass-input-field-wrapper:hover {
|
|
2355
|
+
border-color: rgba(126, 160, 255, 0.28);
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
.compass-input-field-wrapper:focus-within {
|
|
2359
|
+
border-color: rgba(126, 160, 255, 0.42);
|
|
2360
|
+
box-shadow: 0 0 0 1px rgba(126, 160, 255, 0.14);
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
.compass-input-field-input {
|
|
2364
|
+
color: rgba(255, 255, 255, 0.92);
|
|
2365
|
+
font-size: 13px;
|
|
2366
|
+
line-height: 1.2;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
.compass-input-field-input::placeholder {
|
|
2370
|
+
color: rgba(255, 255, 255, 0.34);
|
|
2371
|
+
}
|
|
2032
2372
|
`;
|
|
2033
2373
|
var NumberInputRow = import_styled4.default.div`
|
|
2034
2374
|
display: flex;
|
|
@@ -2337,9 +2677,7 @@ var arePlanQuestionsEqual = (previousQuestion, nextQuestion) => {
|
|
|
2337
2677
|
return false;
|
|
2338
2678
|
}
|
|
2339
2679
|
};
|
|
2340
|
-
var areQuestionnairesEqual = (previousQuestionnaire, nextQuestionnaire) => previousQuestionnaire.questionnaireId === nextQuestionnaire.questionnaireId && previousQuestionnaire.title === nextQuestionnaire.title && previousQuestionnaire.description === nextQuestionnaire.description && previousQuestionnaire.submitLabel === nextQuestionnaire.submitLabel && previousQuestionnaire.status === nextQuestionnaire.status && previousQuestionnaire.statusMessage === nextQuestionnaire.statusMessage && previousQuestionnaire.
|
|
2341
|
-
(question, index) => arePlanQuestionsEqual(question, nextQuestionnaire.questions[index])
|
|
2342
|
-
) && areQuestionAnswerMapsEqual(previousQuestionnaire.answers, nextQuestionnaire.answers);
|
|
2680
|
+
var areQuestionnairesEqual = (previousQuestionnaire, nextQuestionnaire) => previousQuestionnaire.questionnaireId === nextQuestionnaire.questionnaireId && previousQuestionnaire.title === nextQuestionnaire.title && previousQuestionnaire.description === nextQuestionnaire.description && previousQuestionnaire.submitLabel === nextQuestionnaire.submitLabel && previousQuestionnaire.status === nextQuestionnaire.status && previousQuestionnaire.statusMessage === nextQuestionnaire.statusMessage && arePlanQuestionsEqual(previousQuestionnaire.question, nextQuestionnaire.question) && areQuestionAnswerMapsEqual(previousQuestionnaire.answers, nextQuestionnaire.answers);
|
|
2343
2681
|
var areMessageBlocksEqual = (previousBlocks, nextBlocks) => {
|
|
2344
2682
|
if (previousBlocks === nextBlocks) {
|
|
2345
2683
|
return true;
|
|
@@ -2493,7 +2831,10 @@ var ChatMessageItemView = ({
|
|
|
2493
2831
|
submitting: labels.questionnaireSubmitting,
|
|
2494
2832
|
submitted: labels.questionnaireSubmitted,
|
|
2495
2833
|
validationPrefix: labels.questionnaireValidationPrefix,
|
|
2496
|
-
submitFailed: labels.questionnaireSubmitFailed
|
|
2834
|
+
submitFailed: labels.questionnaireSubmitFailed,
|
|
2835
|
+
multiSelectHint: labels.questionnaireMultiSelectHint,
|
|
2836
|
+
otherOptionLabel: labels.questionnaireOtherOptionLabel,
|
|
2837
|
+
otherPlaceholder: labels.questionnaireOtherPlaceholder
|
|
2497
2838
|
},
|
|
2498
2839
|
onSubmit: canSubmitQuestionnaire ? (submission) => onQuestionnaireSubmit({
|
|
2499
2840
|
...submission,
|
|
@@ -2752,8 +3093,34 @@ var CollapseToggle = import_styled7.default.button`
|
|
|
2752
3093
|
`;
|
|
2753
3094
|
var Content = import_styled7.default.div`
|
|
2754
3095
|
color: rgba(255, 255, 255, 0.92);
|
|
3096
|
+
font-size: 14px;
|
|
2755
3097
|
line-height: 1.6;
|
|
2756
3098
|
|
|
3099
|
+
h1,
|
|
3100
|
+
h2,
|
|
3101
|
+
h3,
|
|
3102
|
+
h4,
|
|
3103
|
+
h5,
|
|
3104
|
+
h6 {
|
|
3105
|
+
margin: 0;
|
|
3106
|
+
line-height: 2.5;
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
h1 {
|
|
3110
|
+
font-size: 18px;
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
h2 {
|
|
3114
|
+
font-size: 16px;
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
h3,
|
|
3118
|
+
h4,
|
|
3119
|
+
h5,
|
|
3120
|
+
h6 {
|
|
3121
|
+
font-size: 14px;
|
|
3122
|
+
}
|
|
3123
|
+
|
|
2757
3124
|
p {
|
|
2758
3125
|
margin: 0;
|
|
2759
3126
|
}
|
|
@@ -2765,7 +3132,7 @@ var Content = import_styled7.default.div`
|
|
|
2765
3132
|
table {
|
|
2766
3133
|
width: 100%;
|
|
2767
3134
|
border-collapse: collapse;
|
|
2768
|
-
margin: 0;
|
|
3135
|
+
margin: 8px 0 0;
|
|
2769
3136
|
overflow: hidden;
|
|
2770
3137
|
border-radius: 14px;
|
|
2771
3138
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
@@ -2789,6 +3156,10 @@ var Content = import_styled7.default.div`
|
|
|
2789
3156
|
tbody tr:last-of-type td {
|
|
2790
3157
|
border-bottom: none;
|
|
2791
3158
|
}
|
|
3159
|
+
ul,
|
|
3160
|
+
ol {
|
|
3161
|
+
margin: 0 0 8px;
|
|
3162
|
+
}
|
|
2792
3163
|
`;
|
|
2793
3164
|
var ContentStack = import_styled7.default.div`
|
|
2794
3165
|
display: flex;
|
|
@@ -4087,7 +4458,7 @@ var CloseGlyph = import_styled10.default.span`
|
|
|
4087
4458
|
|
|
4088
4459
|
// src/components/chat-composer/components/chat-model-control.tsx
|
|
4089
4460
|
var import_styled11 = __toESM(require("@emotion/styled"));
|
|
4090
|
-
var
|
|
4461
|
+
var import_compass_ui2 = require("@xinghunm/compass-ui");
|
|
4091
4462
|
var import_jsx_runtime12 = require("@emotion/react/jsx-runtime");
|
|
4092
4463
|
var ChatModelControl = ({
|
|
4093
4464
|
selectedModel,
|
|
@@ -4188,7 +4559,7 @@ var ModelReloadButton = import_styled11.default.button`
|
|
|
4188
4559
|
var ReloadIcon = import_styled11.default.svg`
|
|
4189
4560
|
flex-shrink: 0;
|
|
4190
4561
|
`;
|
|
4191
|
-
var ModelSelect = (0, import_styled11.default)(
|
|
4562
|
+
var ModelSelect = (0, import_styled11.default)(import_compass_ui2.Select)`
|
|
4192
4563
|
&& {
|
|
4193
4564
|
width: auto;
|
|
4194
4565
|
min-width: 0;
|
|
@@ -4209,7 +4580,7 @@ var ModelSelect = (0, import_styled11.default)(import_compass_ui.Select)`
|
|
|
4209
4580
|
|
|
4210
4581
|
// src/components/chat-composer/components/chat-mode-control.tsx
|
|
4211
4582
|
var import_styled12 = __toESM(require("@emotion/styled"));
|
|
4212
|
-
var
|
|
4583
|
+
var import_compass_ui3 = require("@xinghunm/compass-ui");
|
|
4213
4584
|
var import_jsx_runtime13 = require("@emotion/react/jsx-runtime");
|
|
4214
4585
|
var ChatModeControl = ({
|
|
4215
4586
|
value,
|
|
@@ -4232,7 +4603,7 @@ var ChatModeControl = ({
|
|
|
4232
4603
|
}
|
|
4233
4604
|
);
|
|
4234
4605
|
};
|
|
4235
|
-
var ModeSelect = (0, import_styled12.default)(
|
|
4606
|
+
var ModeSelect = (0, import_styled12.default)(import_compass_ui3.Select)`
|
|
4236
4607
|
&& {
|
|
4237
4608
|
flex: 0 1 auto;
|
|
4238
4609
|
width: auto;
|
|
@@ -4254,7 +4625,7 @@ var ModeSelect = (0, import_styled12.default)(import_compass_ui2.Select)`
|
|
|
4254
4625
|
|
|
4255
4626
|
// src/components/chat-composer/components/chat-send-actions.tsx
|
|
4256
4627
|
var import_styled13 = __toESM(require("@emotion/styled"));
|
|
4257
|
-
var
|
|
4628
|
+
var import_compass_ui4 = require("@xinghunm/compass-ui");
|
|
4258
4629
|
var import_jsx_runtime14 = require("@emotion/react/jsx-runtime");
|
|
4259
4630
|
var ArrowUpIcon = () => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
4260
4631
|
"svg",
|
|
@@ -4308,7 +4679,7 @@ var ChatSendActions = ({
|
|
|
4308
4679
|
onClick: () => void onSend()
|
|
4309
4680
|
}
|
|
4310
4681
|
) });
|
|
4311
|
-
var PrimaryButton = (0, import_styled13.default)(
|
|
4682
|
+
var PrimaryButton = (0, import_styled13.default)(import_compass_ui4.Button)`
|
|
4312
4683
|
&& {
|
|
4313
4684
|
min-width: 24px;
|
|
4314
4685
|
width: 24px;
|
|
@@ -4334,7 +4705,7 @@ var PrimaryButton = (0, import_styled13.default)(import_compass_ui3.Button)`
|
|
|
4334
4705
|
}
|
|
4335
4706
|
}
|
|
4336
4707
|
`;
|
|
4337
|
-
var StopButton = (0, import_styled13.default)(
|
|
4708
|
+
var StopButton = (0, import_styled13.default)(import_compass_ui4.Button)`
|
|
4338
4709
|
&& {
|
|
4339
4710
|
min-width: 24px;
|
|
4340
4711
|
width: 24px;
|
|
@@ -4907,7 +5278,7 @@ var ChatConversationList = () => {
|
|
|
4907
5278
|
};
|
|
4908
5279
|
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Container3, { children: [
|
|
4909
5280
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Toolbar, { children: [
|
|
4910
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
5281
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Title3, { children: "Sessions" }),
|
|
4911
5282
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CreateButton, { type: "button", "data-testid": "chat-create-session", onClick: handleCreateSession, children: labels.newChat })
|
|
4912
5283
|
] }),
|
|
4913
5284
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(List2, { "data-testid": "chat-session-list", children: sessions.map((session) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
@@ -4936,7 +5307,7 @@ var Toolbar = import_styled16.default.div`
|
|
|
4936
5307
|
flex-direction: column;
|
|
4937
5308
|
gap: 12px;
|
|
4938
5309
|
`;
|
|
4939
|
-
var
|
|
5310
|
+
var Title3 = import_styled16.default.h2`
|
|
4940
5311
|
margin: 0;
|
|
4941
5312
|
font-size: 14px;
|
|
4942
5313
|
color: var(--text-secondary);
|
|
@@ -4961,7 +5332,7 @@ var List2 = import_styled16.default.div`
|
|
|
4961
5332
|
// src/components/ai-chat/index.tsx
|
|
4962
5333
|
var import_jsx_runtime18 = require("@emotion/react/jsx-runtime");
|
|
4963
5334
|
var AiChat = ({ showConversationList = false, ...providerProps }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
4964
|
-
|
|
5335
|
+
import_compass_ui5.ConfigProvider,
|
|
4965
5336
|
{
|
|
4966
5337
|
theme: {
|
|
4967
5338
|
token: {
|