@constructor-io/constructorio-ui-quizzes 1.17.25 → 1.18.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/constructorio-ui-quizzes-bundled.js +13 -13
- package/lib/cjs/components/CioQuiz/quizApiReducer.js +3 -3
- package/lib/cjs/hooks/usePropsGetters/useSelectInputProps.js +1 -1
- package/lib/cjs/hooks/useQuiz.js +2 -1
- package/lib/cjs/hooks/useQuizState/useQuizApiState.js +9 -2
- package/lib/cjs/stories/Quiz/argTypes.js +14 -0
- package/lib/cjs/utils.js +1 -0
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CioQuiz/quizApiReducer.js +2 -0
- package/lib/mjs/hooks/usePropsGetters/useSelectInputProps.js +1 -1
- package/lib/mjs/hooks/useQuiz.js +1 -0
- package/lib/mjs/hooks/useQuizState/useQuizApiState.js +9 -2
- package/lib/mjs/stories/Quiz/argTypes.js +14 -0
- package/lib/mjs/utils.js +1 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/CioQuiz/quizApiReducer.d.ts +1 -0
- package/lib/types/stories/Quiz/argTypes.d.ts +14 -0
- package/lib/types/types.d.ts +6 -2
- package/lib/types/utils.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +10 -4
|
@@ -8,7 +8,7 @@ exports.initialState = {
|
|
|
8
8
|
quizRequestState: constants_1.RequestStates.Stale,
|
|
9
9
|
};
|
|
10
10
|
function apiReducer(state, action) {
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
12
12
|
switch (action.type) {
|
|
13
13
|
case actions_1.QuizAPIActionTypes.SET_IS_LOADING:
|
|
14
14
|
return Object.assign(Object.assign({}, state), { quizRequestState: constants_1.RequestStates.Loading, quizCurrentQuestion: undefined, quizResults: undefined });
|
|
@@ -36,10 +36,10 @@ function apiReducer(state, action) {
|
|
|
36
36
|
return Object.assign(Object.assign({}, state), { quizRequestState: constants_1.RequestStates.Success, quizResults: (_o = action.payload) === null || _o === void 0 ? void 0 : _o.quizResults, quizCurrentQuestion: undefined, selectedOptionsWithAttributes: (_p = action.payload) === null || _p === void 0 ? void 0 : _p.quizResults.attributes });
|
|
37
37
|
}
|
|
38
38
|
case actions_1.QuizAPIActionTypes.SET_QUIZ_RESULTS_CONFIG: {
|
|
39
|
-
return Object.assign(Object.assign({}, state), {
|
|
39
|
+
return Object.assign(Object.assign({}, state), { metadata: (_q = action.payload) === null || _q === void 0 ? void 0 : _q.quizResultsConfig.metadata, resultsConfig: (_r = action.payload) === null || _r === void 0 ? void 0 : _r.quizResultsConfig.results_config });
|
|
40
40
|
}
|
|
41
41
|
case actions_1.QuizAPIActionTypes.SET_QUIZ_RESULTS_CONFIG_ERROR: {
|
|
42
|
-
return Object.assign(Object.assign({}, state), { resultsConfig: null });
|
|
42
|
+
return Object.assign(Object.assign({}, state), { metadata: null, resultsConfig: null });
|
|
43
43
|
}
|
|
44
44
|
case actions_1.QuizAPIActionTypes.RESET_QUIZ:
|
|
45
45
|
return Object.assign({}, exports.initialState);
|
|
@@ -40,7 +40,7 @@ function useSelectInputProps(quizAnswerChanged, nextQuestion, currentQuestionDat
|
|
|
40
40
|
const prevSelected = {};
|
|
41
41
|
if (Array.isArray(currentAnswer === null || currentAnswer === void 0 ? void 0 : currentAnswer.value)) {
|
|
42
42
|
(_a = currentAnswer === null || currentAnswer === void 0 ? void 0 : currentAnswer.value) === null || _a === void 0 ? void 0 : _a.forEach((answer) => {
|
|
43
|
-
prevSelected[
|
|
43
|
+
prevSelected[answer.id] = true;
|
|
44
44
|
setSelected(prevSelected);
|
|
45
45
|
});
|
|
46
46
|
}
|
package/lib/cjs/hooks/useQuiz.js
CHANGED
|
@@ -8,7 +8,7 @@ const usePrimaryColorStyles_1 = tslib_1.__importDefault(require("./usePrimaryCol
|
|
|
8
8
|
const useQuizEvents_1 = tslib_1.__importDefault(require("./useQuizEvents"));
|
|
9
9
|
const useQuizState_1 = tslib_1.__importDefault(require("./useQuizState"));
|
|
10
10
|
const useQuiz = (quizOptions) => {
|
|
11
|
-
var _a;
|
|
11
|
+
var _a, _b;
|
|
12
12
|
const { apiKey, cioJsClient, primaryColor, resultsPageOptions } = quizOptions;
|
|
13
13
|
// Log console errors for required parameters quizId
|
|
14
14
|
(0, useConsoleErrors_1.default)(quizOptions);
|
|
@@ -36,6 +36,7 @@ const useQuiz = (quizOptions) => {
|
|
|
36
36
|
selectedOptionsWithAttributes: quizApiState.selectedOptionsWithAttributes,
|
|
37
37
|
matchedOptions: quizApiState.matchedOptions,
|
|
38
38
|
resultsConfig: (_a = quizApiState.resultsConfig) !== null && _a !== void 0 ? _a : null,
|
|
39
|
+
metadata: (_b = quizApiState.metadata) !== null && _b !== void 0 ? _b : null,
|
|
39
40
|
},
|
|
40
41
|
quizSessionStorageState,
|
|
41
42
|
}, events: Object.assign({}, quizEvents) }, propGetters), { primaryColorStyles });
|
|
@@ -6,11 +6,12 @@ const actions_1 = require("../../components/CioQuiz/actions");
|
|
|
6
6
|
const quizApiReducer_1 = tslib_1.__importStar(require("../../components/CioQuiz/quizApiReducer"));
|
|
7
7
|
const services_1 = require("../../services");
|
|
8
8
|
const useQueryParams_1 = tslib_1.__importDefault(require("../useQueryParams"));
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
9
10
|
const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults, dispatchLocalState
|
|
10
11
|
// eslint-disable-next-line max-params
|
|
11
12
|
) => {
|
|
12
13
|
const [quizApiState, dispatchApiState] = (0, react_1.useReducer)(quizApiReducer_1.default, quizApiReducer_1.initialState);
|
|
13
|
-
const { quizId, quizVersionId: quizVersionIdProp, resultsPageOptions } = quizOptions;
|
|
14
|
+
const { quizId, quizVersionId: quizVersionIdProp, resultsPageOptions, callbacks } = quizOptions;
|
|
14
15
|
const { queryItems, queryAttributes, isSharedResultsQuery, answers, quizVersionId: quizVersionIdFromParam, } = (0, useQueryParams_1.default)();
|
|
15
16
|
const dispatchQuizResults = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
try {
|
|
@@ -76,8 +77,14 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults,
|
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
79
|
(0, react_1.useEffect)(() => {
|
|
79
|
-
if (typeof quizApiState.resultsConfig === 'undefined')
|
|
80
|
+
if (typeof quizApiState.resultsConfig === 'undefined') {
|
|
80
81
|
dispatchQuizResultsConfig();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const { onQuizResultsConfigLoaded } = callbacks;
|
|
85
|
+
if (onQuizResultsConfigLoaded && (0, utils_1.isFunction)(onQuizResultsConfigLoaded)) {
|
|
86
|
+
onQuizResultsConfigLoaded(quizApiState.resultsConfig, quizApiState.metadata);
|
|
87
|
+
}
|
|
81
88
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
89
|
}, [quizApiState.resultsConfig]);
|
|
83
90
|
(0, react_1.useEffect)(() => {
|
|
@@ -127,6 +127,20 @@ exports.argTypes = {
|
|
|
127
127
|
},
|
|
128
128
|
},
|
|
129
129
|
},
|
|
130
|
+
'callbacks.onQuizResultsConfigLoaded': {
|
|
131
|
+
description: 'Callback function to be called when results config is loaded.',
|
|
132
|
+
control: false,
|
|
133
|
+
table: {
|
|
134
|
+
subcategory: 'callbacks',
|
|
135
|
+
defaultValue: {
|
|
136
|
+
summary: 'null',
|
|
137
|
+
},
|
|
138
|
+
type: {
|
|
139
|
+
summary: '(resultsConfig, metadata) => void',
|
|
140
|
+
detail: '(resultsConfig?: QuizResultsConfig | null, metadata?: object | null) => void',
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
130
144
|
cioJsClient: {
|
|
131
145
|
description: 'Optional custom constructor instance. Either `apiKey` or `cioJsClient` are required',
|
|
132
146
|
},
|
package/lib/cjs/utils.js
CHANGED
|
@@ -42,6 +42,7 @@ exports.functionStrings = {
|
|
|
42
42
|
onQuizNextQuestion: `(question) => console.dir(question)`,
|
|
43
43
|
onQuizSkipQuestion: `(question) => console.dir(question)`,
|
|
44
44
|
onEmailResults: `(data) => console.dir(data)`,
|
|
45
|
+
onQuizResultsConfigLoaded: `(resultsConfig, metadata) => console.dir(resultsConfig, metadata)`,
|
|
45
46
|
cioJsClient: `cioJsClient`,
|
|
46
47
|
};
|
|
47
48
|
const stringifyWithDefaults = (obj) => {
|
package/lib/cjs/version.js
CHANGED
|
@@ -74,12 +74,14 @@ export default function apiReducer(state, action) {
|
|
|
74
74
|
case QuizAPIActionTypes.SET_QUIZ_RESULTS_CONFIG: {
|
|
75
75
|
return {
|
|
76
76
|
...state,
|
|
77
|
+
metadata: action.payload?.quizResultsConfig.metadata,
|
|
77
78
|
resultsConfig: action.payload?.quizResultsConfig.results_config,
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
case QuizAPIActionTypes.SET_QUIZ_RESULTS_CONFIG_ERROR: {
|
|
81
82
|
return {
|
|
82
83
|
...state,
|
|
84
|
+
metadata: null,
|
|
83
85
|
resultsConfig: null,
|
|
84
86
|
};
|
|
85
87
|
}
|
|
@@ -36,7 +36,7 @@ export default function useSelectInputProps(quizAnswerChanged, nextQuestion, cur
|
|
|
36
36
|
const prevSelected = {};
|
|
37
37
|
if (Array.isArray(currentAnswer?.value)) {
|
|
38
38
|
currentAnswer?.value?.forEach((answer) => {
|
|
39
|
-
prevSelected[
|
|
39
|
+
prevSelected[answer.id] = true;
|
|
40
40
|
setSelected(prevSelected);
|
|
41
41
|
});
|
|
42
42
|
}
|
package/lib/mjs/hooks/useQuiz.js
CHANGED
|
@@ -34,6 +34,7 @@ const useQuiz = (quizOptions) => {
|
|
|
34
34
|
selectedOptionsWithAttributes: quizApiState.selectedOptionsWithAttributes,
|
|
35
35
|
matchedOptions: quizApiState.matchedOptions,
|
|
36
36
|
resultsConfig: quizApiState.resultsConfig ?? null,
|
|
37
|
+
metadata: quizApiState.metadata ?? null,
|
|
37
38
|
},
|
|
38
39
|
quizSessionStorageState,
|
|
39
40
|
},
|
|
@@ -3,11 +3,12 @@ import { QuestionTypes, QuizAPIActionTypes, } from '../../components/CioQuiz/act
|
|
|
3
3
|
import apiReducer, { initialState, } from '../../components/CioQuiz/quizApiReducer';
|
|
4
4
|
import { getNextQuestion, getQuizResults, getBrowseResultsForItemIds, getQuizResultsConfig, } from '../../services';
|
|
5
5
|
import useQueryParams from '../useQueryParams';
|
|
6
|
+
import { isFunction } from '../../utils';
|
|
6
7
|
const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults, dispatchLocalState
|
|
7
8
|
// eslint-disable-next-line max-params
|
|
8
9
|
) => {
|
|
9
10
|
const [quizApiState, dispatchApiState] = useReducer(apiReducer, initialState);
|
|
10
|
-
const { quizId, quizVersionId: quizVersionIdProp, resultsPageOptions } = quizOptions;
|
|
11
|
+
const { quizId, quizVersionId: quizVersionIdProp, resultsPageOptions, callbacks } = quizOptions;
|
|
11
12
|
const { queryItems, queryAttributes, isSharedResultsQuery, answers, quizVersionId: quizVersionIdFromParam, } = useQueryParams();
|
|
12
13
|
const dispatchQuizResults = async () => {
|
|
13
14
|
try {
|
|
@@ -84,8 +85,14 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults,
|
|
|
84
85
|
}
|
|
85
86
|
};
|
|
86
87
|
useEffect(() => {
|
|
87
|
-
if (typeof quizApiState.resultsConfig === 'undefined')
|
|
88
|
+
if (typeof quizApiState.resultsConfig === 'undefined') {
|
|
88
89
|
dispatchQuizResultsConfig();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const { onQuizResultsConfigLoaded } = callbacks;
|
|
93
|
+
if (onQuizResultsConfigLoaded && isFunction(onQuizResultsConfigLoaded)) {
|
|
94
|
+
onQuizResultsConfigLoaded(quizApiState.resultsConfig, quizApiState.metadata);
|
|
95
|
+
}
|
|
89
96
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
90
97
|
}, [quizApiState.resultsConfig]);
|
|
91
98
|
useEffect(() => {
|
|
@@ -124,6 +124,20 @@ export const argTypes = {
|
|
|
124
124
|
},
|
|
125
125
|
},
|
|
126
126
|
},
|
|
127
|
+
'callbacks.onQuizResultsConfigLoaded': {
|
|
128
|
+
description: 'Callback function to be called when results config is loaded.',
|
|
129
|
+
control: false,
|
|
130
|
+
table: {
|
|
131
|
+
subcategory: 'callbacks',
|
|
132
|
+
defaultValue: {
|
|
133
|
+
summary: 'null',
|
|
134
|
+
},
|
|
135
|
+
type: {
|
|
136
|
+
summary: '(resultsConfig, metadata) => void',
|
|
137
|
+
detail: '(resultsConfig?: QuizResultsConfig | null, metadata?: object | null) => void',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
127
141
|
cioJsClient: {
|
|
128
142
|
description: 'Optional custom constructor instance. Either `apiKey` or `cioJsClient` are required',
|
|
129
143
|
},
|
package/lib/mjs/utils.js
CHANGED
|
@@ -37,6 +37,7 @@ export const functionStrings = {
|
|
|
37
37
|
onQuizNextQuestion: `(question) => console.dir(question)`,
|
|
38
38
|
onQuizSkipQuestion: `(question) => console.dir(question)`,
|
|
39
39
|
onEmailResults: `(data) => console.dir(data)`,
|
|
40
|
+
onQuizResultsConfigLoaded: `(resultsConfig, metadata) => console.dir(resultsConfig, metadata)`,
|
|
40
41
|
cioJsClient: `cioJsClient`,
|
|
41
42
|
};
|
|
42
43
|
export const stringifyWithDefaults = (obj) => {
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.18.0';
|
|
@@ -9,6 +9,7 @@ export type QuizAPIReducerState = {
|
|
|
9
9
|
selectedOptionsWithAttributes?: string[];
|
|
10
10
|
matchedOptions?: string[];
|
|
11
11
|
resultsConfig?: QuizResultsConfig | null;
|
|
12
|
+
metadata?: object | null;
|
|
12
13
|
};
|
|
13
14
|
export declare const initialState: QuizAPIReducerState;
|
|
14
15
|
export default function apiReducer(state: QuizAPIReducerState, action: ActionQuizAPI): QuizAPIReducerState;
|
|
@@ -123,6 +123,20 @@ export declare const argTypes: {
|
|
|
123
123
|
};
|
|
124
124
|
};
|
|
125
125
|
};
|
|
126
|
+
'callbacks.onQuizResultsConfigLoaded': {
|
|
127
|
+
description: string;
|
|
128
|
+
control: boolean;
|
|
129
|
+
table: {
|
|
130
|
+
subcategory: string;
|
|
131
|
+
defaultValue: {
|
|
132
|
+
summary: string;
|
|
133
|
+
};
|
|
134
|
+
type: {
|
|
135
|
+
summary: string;
|
|
136
|
+
detail: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
};
|
|
126
140
|
cioJsClient: {
|
|
127
141
|
description: string;
|
|
128
142
|
};
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
|
-
import { QuizResultData, NextQuestionResponse, QuizResultsResponse, QuestionOption,
|
|
2
|
+
import { QuizResultData, NextQuestionResponse, QuizResultsResponse, QuestionOption, QuizResultsConfig, QuizzesResultsParameters, QuizzesParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
|
+
import { Question } from '@constructor-io/constructorio-client-javascript/lib/types/quizzes';
|
|
3
4
|
import ConstructorIOClient, { GetBrowseResultsForItemIdsResponse } from '@constructor-io/constructorio-client-javascript';
|
|
4
5
|
import { RequestStates } from './constants';
|
|
5
6
|
import { QuestionTypes } from './components/CioQuiz/actions';
|
|
6
|
-
export type { QuestionOption, QuestionImages,
|
|
7
|
+
export type { QuestionOption, QuestionImages, NextQuestionResponse, QuizResultsResponse, QuizResultsConfigResponse, QuizResultsConfig, BrowseResultData, BrowseRequestType, QuizzesParameters, QuizzesResultsParameters, } from '@constructor-io/constructorio-client-javascript/lib/types/';
|
|
8
|
+
export type { Question } from '@constructor-io/constructorio-client-javascript/lib/types/quizzes';
|
|
7
9
|
export type QuizResultDataPartial = Partial<QuizResultData>;
|
|
8
10
|
export type QuizEmailResults = {
|
|
9
11
|
email: string;
|
|
@@ -33,6 +35,7 @@ export declare namespace QuizResultsEventsProps {
|
|
|
33
35
|
type OnEmailResults = (data: QuizEmailResults) => Promise<void>;
|
|
34
36
|
type OnShareResultsModalOpen = () => void;
|
|
35
37
|
type OnShareResultsModalClose = () => void;
|
|
38
|
+
type OnQuizResultsConfigLoaded = (resultsConfig?: QuizResultsConfig | null, metadata?: object | null) => void;
|
|
36
39
|
}
|
|
37
40
|
export type QuizResultsRequestConfigs = Omit<QuizzesResultsParameters, keyof QuizzesParameters | 'page' | 'resultsPerPage'>;
|
|
38
41
|
export interface ResultsPageOptions {
|
|
@@ -62,6 +65,7 @@ export interface Callbacks {
|
|
|
62
65
|
onEmailResults?: QuizResultsEventsProps.OnEmailResults;
|
|
63
66
|
onShareResultsModalOpen?: QuizResultsEventsProps.OnShareResultsModalOpen;
|
|
64
67
|
onShareResultsModalClose?: QuizResultsEventsProps.OnShareResultsModalClose;
|
|
68
|
+
onQuizResultsConfigLoaded?: QuizResultsEventsProps.OnQuizResultsConfigLoaded;
|
|
65
69
|
}
|
|
66
70
|
export interface IQuizProps {
|
|
67
71
|
apiKey?: string;
|
package/lib/types/utils.d.ts
CHANGED
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.18.0";
|
|
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.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "Constructor.io Quizzes UI library for web applications",
|
|
5
5
|
"author": "Constructor.io Corporation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,11 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
".": {
|
|
27
27
|
"import": "./lib/mjs/index.js",
|
|
28
|
-
"require": "./lib/cjs/index.js"
|
|
28
|
+
"require": "./lib/cjs/index.js",
|
|
29
|
+
"types": "./lib/types/index.d.ts"
|
|
29
30
|
},
|
|
30
31
|
"./cjs": {
|
|
31
32
|
"import": "./lib/cjs/index.js",
|
|
32
|
-
"require": "./lib/cjs/index.js"
|
|
33
|
+
"require": "./lib/cjs/index.js",
|
|
34
|
+
"types": "./lib/types/index.d.ts"
|
|
33
35
|
}
|
|
34
36
|
},
|
|
35
37
|
"files": [
|
|
@@ -59,7 +61,7 @@
|
|
|
59
61
|
"check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause' --excludePackages 'picocolors@1.0.0'"
|
|
60
62
|
},
|
|
61
63
|
"peerDependencies": {
|
|
62
|
-
"@constructor-io/constructorio-client-javascript": "^2.
|
|
64
|
+
"@constructor-io/constructorio-client-javascript": "^2.67.5",
|
|
63
65
|
"react": ">=16.12.0",
|
|
64
66
|
"react-dom": ">=16.12.0",
|
|
65
67
|
"tslib": "^2.4.0"
|
|
@@ -114,5 +116,9 @@
|
|
|
114
116
|
"vite-plugin-css-injected-by-js": "^3.1.0",
|
|
115
117
|
"webpack": "^5.75.0",
|
|
116
118
|
"whatwg-fetch": "^3.6.20"
|
|
119
|
+
},
|
|
120
|
+
"volta": {
|
|
121
|
+
"node": "22.18.0",
|
|
122
|
+
"npm": "10.9.3"
|
|
117
123
|
}
|
|
118
124
|
}
|