@constructor-io/constructorio-ui-quizzes 1.19.8 → 1.19.10

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.
@@ -10,6 +10,7 @@ var QuestionTypes;
10
10
  QuestionTypes["MultipleSelect"] = "multiple";
11
11
  QuestionTypes["SingleFilterValue"] = "single_filter_value";
12
12
  QuestionTypes["MultipleFilterValues"] = "multiple_filter_values";
13
+ QuestionTypes["FreeForm"] = "free_form";
13
14
  QuestionTypes["Next"] = "next";
14
15
  QuestionTypes["Skip"] = "skip";
15
16
  QuestionTypes["Back"] = "back";
@@ -15,7 +15,7 @@ function apiReducer(state, action) {
15
15
  case actions_1.QuizAPIActionTypes.SET_IS_ERROR:
16
16
  return Object.assign(Object.assign({}, state), { quizRequestState: constants_1.RequestStates.Error, quizCurrentQuestion: undefined, quizResults: undefined, selectedOptionsWithAttributes: undefined, matchedOptions: undefined });
17
17
  case actions_1.QuizAPIActionTypes.SET_CURRENT_QUESTION: {
18
- const { isOpenQuestion, isCoverQuestion, isSingleQuestion, isMultipleQuestion, isSelectQuestion, isSingleFilterQuestion, isMultipleFilterQuestion, } = (0, utils_1.getQuestionTypes)((_c = (_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.quizCurrentQuestion) === null || _b === void 0 ? void 0 : _b.next_question) === null || _c === void 0 ? void 0 : _c.type);
18
+ const { isOpenQuestion, isCoverQuestion, isSingleQuestion, isMultipleQuestion, isSelectQuestion, isSingleFilterQuestion, isMultipleFilterQuestion, isFreeFormQuestion, } = (0, utils_1.getQuestionTypes)((_c = (_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.quizCurrentQuestion) === null || _b === void 0 ? void 0 : _b.next_question) === null || _c === void 0 ? void 0 : _c.type);
19
19
  const quizFirstQuestion = state.quizFirstQuestion || ((_d = action.payload) === null || _d === void 0 ? void 0 : _d.quizCurrentQuestion);
20
20
  return Object.assign(Object.assign({}, state), { quizRequestState: constants_1.RequestStates.Success, quizCurrentQuestion: Object.assign(Object.assign({}, (_e = action.payload) === null || _e === void 0 ? void 0 : _e.quizCurrentQuestion), { isFirstQuestion: ((_f = quizFirstQuestion === null || quizFirstQuestion === void 0 ? void 0 : quizFirstQuestion.next_question) === null || _f === void 0 ? void 0 : _f.id) ===
21
21
  ((_j = (_h = (_g = action.payload) === null || _g === void 0 ? void 0 : _g.quizCurrentQuestion) === null || _h === void 0 ? void 0 : _h.next_question) === null || _j === void 0 ? void 0 : _j.id), isOpenQuestion,
@@ -24,7 +24,8 @@ function apiReducer(state, action) {
24
24
  isMultipleQuestion,
25
25
  isSelectQuestion,
26
26
  isSingleFilterQuestion,
27
- isMultipleFilterQuestion }), quizFirstQuestion, quizResults: undefined, selectedOptionsWithAttributes: undefined, matchedOptions: undefined });
27
+ isMultipleFilterQuestion,
28
+ isFreeFormQuestion }), quizFirstQuestion, quizResults: undefined, selectedOptionsWithAttributes: undefined, matchedOptions: undefined });
28
29
  }
29
30
  case actions_1.QuizAPIActionTypes.SET_QUIZ_RESULTS: {
30
31
  const selectedOptionsWithAttributes = ((_k = action.payload) === null || _k === void 0 ? void 0 : _k.quizResults.quiz_selected_options.filter((option) => option.has_attribute).map((option) => option.value)) || [];
@@ -18,6 +18,9 @@ function handleNextQuestion(state) {
18
18
  case actions_1.QuestionTypes.OpenText:
19
19
  newAnswers.push(['true']);
20
20
  break;
21
+ case actions_1.QuestionTypes.FreeForm:
22
+ newAnswers.push([currentAnswerInput.value]);
23
+ break;
21
24
  case actions_1.QuestionTypes.Cover:
22
25
  newAnswers.push(['seen']);
23
26
  break;
@@ -44,6 +47,7 @@ function quizLocalReducer(state, action) {
44
47
  switch (action.type) {
45
48
  case actions_1.QuestionTypes.OpenText:
46
49
  case actions_1.QuestionTypes.Cover:
50
+ case actions_1.QuestionTypes.FreeForm:
47
51
  case actions_1.QuestionTypes.SingleSelect:
48
52
  case actions_1.QuestionTypes.MultipleSelect:
49
53
  case actions_1.QuestionTypes.SingleFilterValue:
@@ -59,6 +63,7 @@ function quizLocalReducer(state, action) {
59
63
  const currentAnswerInput = Object.values(state.answerInputs)[lastAnswerInputIndex];
60
64
  switch (currentAnswerInput.type) {
61
65
  case actions_1.QuestionTypes.OpenText:
66
+ case actions_1.QuestionTypes.FreeForm:
62
67
  newAnswers.push(['false']);
63
68
  break;
64
69
  case actions_1.QuestionTypes.Cover:
@@ -6,6 +6,10 @@ const QuestionTitle_1 = tslib_1.__importDefault(require("../QuestionTitle/Questi
6
6
  const QuestionDescription_1 = tslib_1.__importDefault(require("../QuestionDescription/QuestionDescription"));
7
7
  const utils_1 = require("../../utils");
8
8
  const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
9
+ /**
10
+ * This component handles both "OpenText" and "FreeForm" question types.
11
+ * Both types share the same UI and behavior for text input.
12
+ */
9
13
  function OpenTextQuestion() {
10
14
  var _a;
11
15
  const { state, getOpenTextInputProps } = (0, react_1.useContext)(context_1.default);
@@ -15,6 +15,7 @@ function QuizQuestions() {
15
15
  if (nextQuestion) {
16
16
  return (react_1.default.createElement(react_1.default.Fragment, null,
17
17
  questionTypes.isOpenQuestion && react_1.default.createElement(OpenTextTypeQuestion_1.default, { key: nextQuestion === null || nextQuestion === void 0 ? void 0 : nextQuestion.id }),
18
+ questionTypes.isFreeFormQuestion && react_1.default.createElement(OpenTextTypeQuestion_1.default, { key: nextQuestion === null || nextQuestion === void 0 ? void 0 : nextQuestion.id }),
18
19
  questionTypes.isCoverQuestion && react_1.default.createElement(CoverTypeQuestion_1.default, { key: nextQuestion === null || nextQuestion === void 0 ? void 0 : nextQuestion.id }),
19
20
  questionTypes.isSelectQuestion && react_1.default.createElement(SelectTypeQuestion_1.default, { key: nextQuestion === null || nextQuestion === void 0 ? void 0 : nextQuestion.id })));
20
21
  }
package/lib/cjs/utils.js CHANGED
@@ -80,6 +80,7 @@ const getQuestionTypes = (questionType) => {
80
80
  const isMultipleQuestion = questionType === actions_1.QuestionTypes.MultipleSelect;
81
81
  const isSingleFilterQuestion = questionType === actions_1.QuestionTypes.SingleFilterValue;
82
82
  const isMultipleFilterQuestion = questionType === actions_1.QuestionTypes.MultipleFilterValues;
83
+ const isFreeFormQuestion = questionType === actions_1.QuestionTypes.FreeForm;
83
84
  const isSelectQuestion = isSingleQuestion || isMultipleQuestion || isSingleFilterQuestion || isMultipleFilterQuestion;
84
85
  return {
85
86
  isOpenQuestion,
@@ -89,6 +90,7 @@ const getQuestionTypes = (questionType) => {
89
90
  isSelectQuestion,
90
91
  isSingleFilterQuestion,
91
92
  isMultipleFilterQuestion,
93
+ isFreeFormQuestion,
92
94
  };
93
95
  };
94
96
  exports.getQuestionTypes = getQuestionTypes;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.19.8';
3
+ exports.default = '1.19.10';
@@ -7,6 +7,7 @@ export var QuestionTypes;
7
7
  QuestionTypes["MultipleSelect"] = "multiple";
8
8
  QuestionTypes["SingleFilterValue"] = "single_filter_value";
9
9
  QuestionTypes["MultipleFilterValues"] = "multiple_filter_values";
10
+ QuestionTypes["FreeForm"] = "free_form";
10
11
  QuestionTypes["Next"] = "next";
11
12
  QuestionTypes["Skip"] = "skip";
12
13
  QuestionTypes["Back"] = "back";
@@ -23,7 +23,7 @@ export default function apiReducer(state, action) {
23
23
  matchedOptions: undefined,
24
24
  };
25
25
  case QuizAPIActionTypes.SET_CURRENT_QUESTION: {
26
- const { isOpenQuestion, isCoverQuestion, isSingleQuestion, isMultipleQuestion, isSelectQuestion, isSingleFilterQuestion, isMultipleFilterQuestion, } = getQuestionTypes(action.payload?.quizCurrentQuestion?.next_question?.type);
26
+ const { isOpenQuestion, isCoverQuestion, isSingleQuestion, isMultipleQuestion, isSelectQuestion, isSingleFilterQuestion, isMultipleFilterQuestion, isFreeFormQuestion, } = getQuestionTypes(action.payload?.quizCurrentQuestion?.next_question?.type);
27
27
  const quizFirstQuestion = state.quizFirstQuestion || action.payload?.quizCurrentQuestion;
28
28
  return {
29
29
  ...state,
@@ -39,6 +39,7 @@ export default function apiReducer(state, action) {
39
39
  isSelectQuestion,
40
40
  isSingleFilterQuestion,
41
41
  isMultipleFilterQuestion,
42
+ isFreeFormQuestion,
42
43
  },
43
44
  quizFirstQuestion,
44
45
  quizResults: undefined,
@@ -14,6 +14,9 @@ function handleNextQuestion(state) {
14
14
  case QuestionTypes.OpenText:
15
15
  newAnswers.push(['true']);
16
16
  break;
17
+ case QuestionTypes.FreeForm:
18
+ newAnswers.push([currentAnswerInput.value]);
19
+ break;
17
20
  case QuestionTypes.Cover:
18
21
  newAnswers.push(['seen']);
19
22
  break;
@@ -50,6 +53,7 @@ export default function quizLocalReducer(state, action) {
50
53
  switch (action.type) {
51
54
  case QuestionTypes.OpenText:
52
55
  case QuestionTypes.Cover:
56
+ case QuestionTypes.FreeForm:
53
57
  case QuestionTypes.SingleSelect:
54
58
  case QuestionTypes.MultipleSelect:
55
59
  case QuestionTypes.SingleFilterValue:
@@ -65,6 +69,7 @@ export default function quizLocalReducer(state, action) {
65
69
  const currentAnswerInput = Object.values(state.answerInputs)[lastAnswerInputIndex];
66
70
  switch (currentAnswerInput.type) {
67
71
  case QuestionTypes.OpenText:
72
+ case QuestionTypes.FreeForm:
68
73
  newAnswers.push(['false']);
69
74
  break;
70
75
  case QuestionTypes.Cover:
@@ -3,6 +3,10 @@ import QuestionTitle from '../QuestionTitle/QuestionTitle';
3
3
  import QuestionDescription from '../QuestionDescription/QuestionDescription';
4
4
  import { renderImages } from '../../utils';
5
5
  import QuizContext from '../CioQuiz/context';
6
+ /**
7
+ * This component handles both "OpenText" and "FreeForm" question types.
8
+ * Both types share the same UI and behavior for text input.
9
+ */
6
10
  function OpenTextQuestion() {
7
11
  const { state, getOpenTextInputProps } = useContext(QuizContext);
8
12
  let question;
@@ -11,6 +11,7 @@ export default function QuizQuestions() {
11
11
  if (nextQuestion) {
12
12
  return (React.createElement(React.Fragment, null,
13
13
  questionTypes.isOpenQuestion && React.createElement(OpenTextQuestion, { key: nextQuestion?.id }),
14
+ questionTypes.isFreeFormQuestion && React.createElement(OpenTextQuestion, { key: nextQuestion?.id }),
14
15
  questionTypes.isCoverQuestion && React.createElement(CoverTypeQuestion, { key: nextQuestion?.id }),
15
16
  questionTypes.isSelectQuestion && React.createElement(SelectTypeQuestion, { key: nextQuestion?.id })));
16
17
  }
package/lib/mjs/utils.js CHANGED
@@ -73,6 +73,7 @@ export const getQuestionTypes = (questionType) => {
73
73
  const isMultipleQuestion = questionType === QuestionTypes.MultipleSelect;
74
74
  const isSingleFilterQuestion = questionType === QuestionTypes.SingleFilterValue;
75
75
  const isMultipleFilterQuestion = questionType === QuestionTypes.MultipleFilterValues;
76
+ const isFreeFormQuestion = questionType === QuestionTypes.FreeForm;
76
77
  const isSelectQuestion = isSingleQuestion || isMultipleQuestion || isSingleFilterQuestion || isMultipleFilterQuestion;
77
78
  return {
78
79
  isOpenQuestion,
@@ -82,6 +83,7 @@ export const getQuestionTypes = (questionType) => {
82
83
  isSelectQuestion,
83
84
  isSingleFilterQuestion,
84
85
  isMultipleFilterQuestion,
86
+ isFreeFormQuestion,
85
87
  };
86
88
  };
87
89
  export function getPreferredColorScheme() {
@@ -1 +1 @@
1
- export default '1.19.8';
1
+ export default '1.19.10';
@@ -7,6 +7,7 @@ export declare enum QuestionTypes {
7
7
  MultipleSelect = "multiple",
8
8
  SingleFilterValue = "single_filter_value",
9
9
  MultipleFilterValues = "multiple_filter_values",
10
+ FreeForm = "free_form",
10
11
  Next = "next",
11
12
  Skip = "skip",
12
13
  Back = "back",
@@ -26,7 +27,7 @@ interface Action<Type, Payload = {}> {
26
27
  type: Type;
27
28
  payload?: Payload;
28
29
  }
29
- export type ActionAnswerInputQuestion = Action<QuestionTypes.OpenText, OpenTextQuestionPayload> | Action<QuestionTypes.SingleSelect, SelectQuestionPayload> | Action<QuestionTypes.MultipleSelect, SelectQuestionPayload> | Action<QuestionTypes.SingleFilterValue, SelectQuestionPayload> | Action<QuestionTypes.MultipleFilterValues, SelectQuestionPayload> | Action<QuestionTypes.Cover, CoverQuestionPayload>;
30
+ export type ActionAnswerInputQuestion = Action<QuestionTypes.OpenText, OpenTextQuestionPayload> | Action<QuestionTypes.SingleSelect, SelectQuestionPayload> | Action<QuestionTypes.MultipleSelect, SelectQuestionPayload> | Action<QuestionTypes.SingleFilterValue, SelectQuestionPayload> | Action<QuestionTypes.MultipleFilterValues, SelectQuestionPayload> | Action<QuestionTypes.FreeForm, OpenTextQuestionPayload> | Action<QuestionTypes.Cover, CoverQuestionPayload>;
30
31
  export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Next, CurrentQuestion> | Action<QuestionTypes.Skip, CurrentQuestion> | Action<QuestionTypes.Back, CurrentQuestion> | Action<QuestionTypes.Reset> | Action<QuestionTypes.Complete> | Action<QuestionTypes.JumpToQuestion, {
31
32
  questionId: number;
32
33
  }> | Action<QuestionTypes.Hydrate, Partial<QuizLocalReducerState>>;
@@ -1,3 +1,7 @@
1
1
  /// <reference types="react" />
2
+ /**
3
+ * This component handles both "OpenText" and "FreeForm" question types.
4
+ * Both types share the same UI and behavior for text input.
5
+ */
2
6
  declare function OpenTextQuestion(): JSX.Element | null;
3
7
  export default OpenTextQuestion;
@@ -115,7 +115,7 @@ export interface QuizSessionStorageState {
115
115
  skipToResults: boolean;
116
116
  hasSessionStorageState: () => boolean;
117
117
  }
118
- export type InputQuestionsTypes = QuestionTypes.OpenText | QuestionTypes.Cover | QuestionTypes.SingleSelect | QuestionTypes.MultipleSelect | QuestionTypes.SingleFilterValue | QuestionTypes.MultipleFilterValues;
118
+ export type InputQuestionsTypes = QuestionTypes.OpenText | QuestionTypes.Cover | QuestionTypes.SingleSelect | QuestionTypes.MultipleSelect | QuestionTypes.SingleFilterValue | QuestionTypes.MultipleFilterValues | QuestionTypes.FreeForm;
119
119
  export type CurrentQuestion = NextQuestionResponse & {
120
120
  isFirstQuestion: boolean;
121
121
  isOpenQuestion: boolean;
@@ -124,6 +124,7 @@ export type CurrentQuestion = NextQuestionResponse & {
124
124
  isMultipleQuestion: boolean;
125
125
  isSingleFilterQuestion: boolean;
126
126
  isMultipleFilterQuestion: boolean;
127
+ isFreeFormQuestion: boolean;
127
128
  isSelectQuestion: boolean;
128
129
  };
129
130
  export declare namespace QuizEventsReturn {
@@ -30,6 +30,7 @@ export declare const getQuestionTypes: (questionType?: `${QuestionTypes}`) => {
30
30
  isSelectQuestion: boolean;
31
31
  isSingleFilterQuestion: boolean;
32
32
  isMultipleFilterQuestion: boolean;
33
+ isFreeFormQuestion: boolean;
33
34
  };
34
35
  export declare function getPreferredColorScheme(): string;
35
36
  export declare function isFunction(fn: any): boolean;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.19.8";
1
+ declare const _default: "1.19.10";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.19.8",
3
+ "version": "1.19.10",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "Constructor.io Corporation",
6
6
  "license": "MIT",
@@ -24,14 +24,14 @@
24
24
  "require": "./dist/constructorio-ui-quizzes-bundled.js"
25
25
  },
26
26
  ".": {
27
+ "types": "./lib/types/index.d.ts",
27
28
  "import": "./lib/mjs/index.js",
28
- "require": "./lib/cjs/index.js",
29
- "types": "./lib/types/index.d.ts"
29
+ "require": "./lib/cjs/index.js"
30
30
  },
31
31
  "./cjs": {
32
32
  "import": "./lib/cjs/index.js",
33
- "require": "./lib/cjs/index.js",
34
- "types": "./lib/types/index.d.ts"
33
+ "types": "./lib/types/index.d.ts",
34
+ "require": "./lib/cjs/index.js"
35
35
  }
36
36
  },
37
37
  "files": [
@@ -61,24 +61,23 @@
61
61
  "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause' --excludePackages 'picocolors@1.0.0'"
62
62
  },
63
63
  "peerDependencies": {
64
- "@constructor-io/constructorio-client-javascript": "^2.68.1",
64
+ "@constructor-io/constructorio-client-javascript": "^2.73.1",
65
65
  "react": ">=16.12.0",
66
66
  "react-dom": ">=16.12.0",
67
67
  "tslib": "^2.4.0"
68
68
  },
69
69
  "devDependencies": {
70
+ "@babel/core": "^7.24.0",
71
+ "@babel/preset-env": "^7.24.0",
72
+ "@babel/preset-react": "^7.23.3",
73
+ "@babel/preset-typescript": "^7.23.3",
70
74
  "@axe-core/react": "^4.7.0",
71
75
  "@cspell/eslint-plugin": "^6.18.1",
72
- "@storybook/addon-a11y": "^7.4.6",
73
- "@storybook/addon-actions": "7.4.6",
74
- "@storybook/addon-docs": "7.4.6",
75
- "@storybook/addon-essentials": "7.4.6",
76
- "@storybook/addon-interactions": "^7.4.6",
77
- "@storybook/addon-links": "7.4.6",
78
- "@storybook/jest": "^0.2.3",
79
- "@storybook/react-webpack5": "7.4.6",
80
- "@storybook/test-runner": "0.16.0",
81
- "@storybook/testing-library": "^0.1.0",
76
+ "@storybook/addon-a11y": "^10.2.10",
77
+ "@storybook/addon-docs": "^10.2.10",
78
+ "@storybook/addon-links": "^10.2.10",
79
+ "@storybook/react-vite": "^10.2.10",
80
+ "@storybook/test-runner": "0.24.2",
82
81
  "@testing-library/jest-dom": "^6.4.2",
83
82
  "@testing-library/react": "^14.2.1",
84
83
  "@types/jest": "^29.5.12",
@@ -87,7 +86,7 @@
87
86
  "@typescript-eslint/eslint-plugin": "^5.47.0",
88
87
  "@typescript-eslint/parser": "^5.47.0",
89
88
  "chromatic": "^6.21.0",
90
- "eslint": "^8.30.0",
89
+ "eslint": "^8.57.1",
91
90
  "eslint-config-airbnb": "^19.0.4",
92
91
  "eslint-config-airbnb-typescript": "^17.0.0",
93
92
  "eslint-config-prettier": "^8.5.0",
@@ -97,7 +96,7 @@
97
96
  "eslint-plugin-prettier": "^4.2.1",
98
97
  "eslint-plugin-react": "^7.31.11",
99
98
  "eslint-plugin-react-hooks": "^4.6.0",
100
- "eslint-plugin-storybook": "^0.6.15",
99
+ "eslint-plugin-storybook": "^10.2.10",
101
100
  "eslint-plugin-testing-library": "^6.2.0",
102
101
  "fishery": "^2.2.2",
103
102
  "husky": "^8.0.1",
@@ -108,12 +107,11 @@
108
107
  "react": "^18.2.0",
109
108
  "react-dom": "^18.2.0",
110
109
  "start-server-and-test": "^2.0.0",
111
- "storybook": "^10.1.11",
110
+ "storybook": "^10.2.10",
112
111
  "ts-jest": "^29.1.2",
113
112
  "typescript": "^4.9.4",
114
113
  "vite": "^7.1.5",
115
114
  "vite-plugin-css-injected-by-js": "^3.1.0",
116
- "webpack": "^5.75.0",
117
115
  "whatwg-fetch": "^3.6.20"
118
116
  },
119
117
  "volta": {