@constructor-io/constructorio-ui-quizzes 1.16.3 → 1.17.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 +3 -3
- package/lib/cjs/components/QuizResultsSummary/QuizResultsSummary.js +1 -1
- package/lib/cjs/hooks/usePropsGetters/useCoverQuestionProps.js +2 -1
- package/lib/cjs/hooks/useQueryParams.js +4 -0
- package/lib/cjs/hooks/useShareResultsLink.js +3 -0
- package/lib/cjs/utils.js +10 -2
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/QuizResultsSummary/QuizResultsSummary.js +1 -1
- package/lib/mjs/hooks/usePropsGetters/useCoverQuestionProps.js +2 -1
- package/lib/mjs/hooks/useQueryParams.js +4 -0
- package/lib/mjs/hooks/useShareResultsLink.js +3 -0
- package/lib/mjs/utils.js +10 -2
- package/lib/mjs/version.js +1 -1
- package/lib/types/types.d.ts +2 -0
- package/lib/types/utils.d.ts +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +3 -1
|
@@ -28,7 +28,7 @@ const getSummaryVariables = ({ summary, matchedOptions = [] }) => {
|
|
|
28
28
|
function QuizResultsSummary({ summary, matchedOptions = [], }) {
|
|
29
29
|
const { summaryFirstPart, summaryLastPart, itemsSeparator, lastSeparator, isActiveSummary } = getSummaryVariables({ summary, matchedOptions });
|
|
30
30
|
const matchedOptionsTemplate = (0, utils_1.formatMatchedOptions)(matchedOptions, itemsSeparator, lastSeparator);
|
|
31
|
-
if (!isActiveSummary)
|
|
31
|
+
if (!isActiveSummary || !matchedOptions.length)
|
|
32
32
|
return null;
|
|
33
33
|
return (react_1.default.createElement("p", { className: 'cio-results-explanation' },
|
|
34
34
|
!!(summaryFirstPart === null || summaryFirstPart === void 0 ? void 0 : summaryFirstPart.length) && summaryFirstPart,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
+
const actions_1 = require("../../components/CioQuiz/actions");
|
|
4
5
|
function useCoverQuestionProps(setQuizAnswers, currentQuestionData) {
|
|
5
6
|
(0, react_1.useEffect)(() => {
|
|
6
|
-
if ((currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.type) ===
|
|
7
|
+
if ((currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.type) === actions_1.QuestionTypes.Cover) {
|
|
7
8
|
setQuizAnswers('');
|
|
8
9
|
}
|
|
9
10
|
}, [setQuizAnswers, currentQuestionData]);
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const useQueryParams = () => {
|
|
5
5
|
const getParsedQueryParam = (queryName) => {
|
|
6
|
+
if (typeof window === 'undefined')
|
|
7
|
+
return [];
|
|
6
8
|
const queryParams = new URLSearchParams(window.location.search);
|
|
7
9
|
const queryParam = queryParams.get(queryName);
|
|
8
10
|
if (!queryParam)
|
|
@@ -13,6 +15,8 @@ const useQueryParams = () => {
|
|
|
13
15
|
const queryAttributes = getParsedQueryParam('attributes');
|
|
14
16
|
const isSharedResultsQuery = !!queryItems.length && !!queryAttributes.length;
|
|
15
17
|
const removeSharedResultsQueryParams = (0, react_1.useCallback)(() => {
|
|
18
|
+
if (typeof window === 'undefined')
|
|
19
|
+
return;
|
|
16
20
|
const updatedUrl = new URL(window.location.href);
|
|
17
21
|
updatedUrl.searchParams.delete('items');
|
|
18
22
|
updatedUrl.searchParams.delete('attributes');
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
function useShareResultsLink(quizState) {
|
|
4
4
|
var _a, _b, _c;
|
|
5
|
+
if (typeof window === 'undefined') {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
5
8
|
const urlObj = new URL(window.location.href);
|
|
6
9
|
const existingParams = urlObj.searchParams;
|
|
7
10
|
if (!((_b = (_a = quizState.results) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.results)) {
|
package/lib/cjs/utils.js
CHANGED
|
@@ -8,6 +8,9 @@ const actions_1 = require("./components/CioQuiz/actions");
|
|
|
8
8
|
const renderImages = (images, cssClasses) => {
|
|
9
9
|
const { primary_url: primaryUrl, primary_alt: primaryAlt, secondary_url: secondaryUrl, secondary_alt: secondaryAlt, } = images;
|
|
10
10
|
if (primaryUrl) {
|
|
11
|
+
if (typeof window === 'undefined') {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
11
14
|
const windowWidth = window.innerWidth;
|
|
12
15
|
let src = primaryUrl;
|
|
13
16
|
let alt = primaryAlt || '';
|
|
@@ -88,18 +91,21 @@ function getPreferredColorScheme() {
|
|
|
88
91
|
var _a;
|
|
89
92
|
let colorScheme = 'light';
|
|
90
93
|
// Check if the dark-mode Media-Query matches
|
|
91
|
-
if ((_a = window.matchMedia('(prefers-color-scheme: dark)')) === null || _a === void 0 ? void 0 : _a.matches) {
|
|
94
|
+
if (typeof window !== 'undefined' && ((_a = window.matchMedia('(prefers-color-scheme: dark)')) === null || _a === void 0 ? void 0 : _a.matches)) {
|
|
92
95
|
colorScheme = 'dark';
|
|
93
96
|
}
|
|
94
97
|
return colorScheme;
|
|
95
98
|
}
|
|
96
99
|
exports.getPreferredColorScheme = getPreferredColorScheme;
|
|
97
100
|
function isFunction(fn) {
|
|
98
|
-
return fn && typeof fn === 'function';
|
|
101
|
+
return !!(fn && typeof fn === 'function');
|
|
99
102
|
}
|
|
100
103
|
exports.isFunction = isFunction;
|
|
101
104
|
const getStateFromSessionStorage = (quizStateKey) => {
|
|
102
105
|
var _a;
|
|
106
|
+
if (typeof window === 'undefined') {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
103
109
|
const state = (_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem(quizStateKey);
|
|
104
110
|
if (state) {
|
|
105
111
|
return JSON.parse(state);
|
|
@@ -112,6 +118,7 @@ const resetQuizSessionStorageState = (quizStateKey) => () => {
|
|
|
112
118
|
(_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.removeItem(quizStateKey);
|
|
113
119
|
};
|
|
114
120
|
exports.resetQuizSessionStorageState = resetQuizSessionStorageState;
|
|
121
|
+
/* istanbul ignore next */
|
|
115
122
|
const logger = (action) => {
|
|
116
123
|
var _a;
|
|
117
124
|
try {
|
|
@@ -127,6 +134,7 @@ const logger = (action) => {
|
|
|
127
134
|
}
|
|
128
135
|
};
|
|
129
136
|
exports.logger = logger;
|
|
137
|
+
/* istanbul ignore next */
|
|
130
138
|
// Function to emulate pausing between interactions
|
|
131
139
|
function sleep(ms) {
|
|
132
140
|
// eslint-disable-next-line
|
package/lib/cjs/version.js
CHANGED
|
@@ -25,7 +25,7 @@ const getSummaryVariables = ({ summary, matchedOptions = [] }) => {
|
|
|
25
25
|
export default function QuizResultsSummary({ summary, matchedOptions = [], }) {
|
|
26
26
|
const { summaryFirstPart, summaryLastPart, itemsSeparator, lastSeparator, isActiveSummary } = getSummaryVariables({ summary, matchedOptions });
|
|
27
27
|
const matchedOptionsTemplate = formatMatchedOptions(matchedOptions, itemsSeparator, lastSeparator);
|
|
28
|
-
if (!isActiveSummary)
|
|
28
|
+
if (!isActiveSummary || !matchedOptions.length)
|
|
29
29
|
return null;
|
|
30
30
|
return (React.createElement("p", { className: 'cio-results-explanation' },
|
|
31
31
|
!!summaryFirstPart?.length && summaryFirstPart,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useCallback, useEffect } from 'react';
|
|
2
|
+
import { QuestionTypes } from '../../components/CioQuiz/actions';
|
|
2
3
|
export default function useCoverQuestionProps(setQuizAnswers, currentQuestionData) {
|
|
3
4
|
useEffect(() => {
|
|
4
|
-
if (currentQuestionData?.type ===
|
|
5
|
+
if (currentQuestionData?.type === QuestionTypes.Cover) {
|
|
5
6
|
setQuizAnswers('');
|
|
6
7
|
}
|
|
7
8
|
}, [setQuizAnswers, currentQuestionData]);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
const useQueryParams = () => {
|
|
3
3
|
const getParsedQueryParam = (queryName) => {
|
|
4
|
+
if (typeof window === 'undefined')
|
|
5
|
+
return [];
|
|
4
6
|
const queryParams = new URLSearchParams(window.location.search);
|
|
5
7
|
const queryParam = queryParams.get(queryName);
|
|
6
8
|
if (!queryParam)
|
|
@@ -11,6 +13,8 @@ const useQueryParams = () => {
|
|
|
11
13
|
const queryAttributes = getParsedQueryParam('attributes');
|
|
12
14
|
const isSharedResultsQuery = !!queryItems.length && !!queryAttributes.length;
|
|
13
15
|
const removeSharedResultsQueryParams = useCallback(() => {
|
|
16
|
+
if (typeof window === 'undefined')
|
|
17
|
+
return;
|
|
14
18
|
const updatedUrl = new URL(window.location.href);
|
|
15
19
|
updatedUrl.searchParams.delete('items');
|
|
16
20
|
updatedUrl.searchParams.delete('attributes');
|
package/lib/mjs/utils.js
CHANGED
|
@@ -4,6 +4,9 @@ import { QuestionTypes } from './components/CioQuiz/actions';
|
|
|
4
4
|
export const renderImages = (images, cssClasses) => {
|
|
5
5
|
const { primary_url: primaryUrl, primary_alt: primaryAlt, secondary_url: secondaryUrl, secondary_alt: secondaryAlt, } = images;
|
|
6
6
|
if (primaryUrl) {
|
|
7
|
+
if (typeof window === 'undefined') {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
7
10
|
const windowWidth = window.innerWidth;
|
|
8
11
|
let src = primaryUrl;
|
|
9
12
|
let alt = primaryAlt || '';
|
|
@@ -79,15 +82,18 @@ export const getQuestionTypes = (questionType) => {
|
|
|
79
82
|
export function getPreferredColorScheme() {
|
|
80
83
|
let colorScheme = 'light';
|
|
81
84
|
// Check if the dark-mode Media-Query matches
|
|
82
|
-
if (window.matchMedia('(prefers-color-scheme: dark)')?.matches) {
|
|
85
|
+
if (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)')?.matches) {
|
|
83
86
|
colorScheme = 'dark';
|
|
84
87
|
}
|
|
85
88
|
return colorScheme;
|
|
86
89
|
}
|
|
87
90
|
export function isFunction(fn) {
|
|
88
|
-
return fn && typeof fn === 'function';
|
|
91
|
+
return !!(fn && typeof fn === 'function');
|
|
89
92
|
}
|
|
90
93
|
export const getStateFromSessionStorage = (quizStateKey) => {
|
|
94
|
+
if (typeof window === 'undefined') {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
91
97
|
const state = window?.sessionStorage?.getItem(quizStateKey);
|
|
92
98
|
if (state) {
|
|
93
99
|
return JSON.parse(state);
|
|
@@ -97,6 +103,7 @@ export const getStateFromSessionStorage = (quizStateKey) => {
|
|
|
97
103
|
export const resetQuizSessionStorageState = (quizStateKey) => () => {
|
|
98
104
|
window?.sessionStorage?.removeItem(quizStateKey);
|
|
99
105
|
};
|
|
106
|
+
/* istanbul ignore next */
|
|
100
107
|
export const logger = (action) => {
|
|
101
108
|
try {
|
|
102
109
|
if (typeof process !== 'undefined' && process?.env?.LOGGER) {
|
|
@@ -110,6 +117,7 @@ export const logger = (action) => {
|
|
|
110
117
|
// process variable is not available and logger should not be active
|
|
111
118
|
}
|
|
112
119
|
};
|
|
120
|
+
/* istanbul ignore next */
|
|
113
121
|
// Function to emulate pausing between interactions
|
|
114
122
|
export function sleep(ms) {
|
|
115
123
|
// eslint-disable-next-line
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.17.0';
|
package/lib/types/types.d.ts
CHANGED
|
@@ -155,6 +155,8 @@ export interface PreviousQuestionButtonProps {
|
|
|
155
155
|
type: 'submit' | 'reset' | 'button' | undefined;
|
|
156
156
|
onClick: React.MouseEventHandler<HTMLElement>;
|
|
157
157
|
style?: Record<string, string>;
|
|
158
|
+
role?: string;
|
|
159
|
+
title?: string;
|
|
158
160
|
}
|
|
159
161
|
export interface ResetQuizButtonProps {
|
|
160
162
|
className: string;
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QuestionTypes } from './components/CioQuiz/actions';
|
|
2
2
|
import { QuizLocalReducerState } from './components/CioQuiz/quizLocalReducer';
|
|
3
3
|
import { PrimaryColorStyles, QuestionImages } from './types';
|
|
4
|
-
export declare const renderImages: (images: Partial<QuestionImages>, cssClasses?: string) => JSX.Element | "";
|
|
4
|
+
export declare const renderImages: (images: Partial<QuestionImages>, cssClasses?: string) => JSX.Element | "" | null;
|
|
5
5
|
export declare const functionStrings: {
|
|
6
6
|
onAddToCartClick: string;
|
|
7
7
|
onQuizResultClick: string;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.17.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.17.0",
|
|
4
4
|
"description": "Constructor.io Quizzes UI library for web applications",
|
|
5
5
|
"author": "constructor.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -98,9 +98,11 @@
|
|
|
98
98
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
99
99
|
"eslint-plugin-storybook": "^0.6.15",
|
|
100
100
|
"eslint-plugin-testing-library": "^6.2.0",
|
|
101
|
+
"fishery": "^2.2.2",
|
|
101
102
|
"husky": "^8.0.1",
|
|
102
103
|
"jest": "^29.7.0",
|
|
103
104
|
"jest-environment-jsdom": "^29.7.0",
|
|
105
|
+
"jest-fail-on-console": "^3.2.0",
|
|
104
106
|
"license-checker": "^25.0.1",
|
|
105
107
|
"react": "^18.2.0",
|
|
106
108
|
"react-dom": "^18.2.0",
|