testforce-engine 0.0.1
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/README.md +3 -0
- package/dist/index.d.mts +183 -0
- package/dist/index.d.ts +183 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +28 -0
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
declare enum TestType {
|
|
4
|
+
QUIZ = "QUIZ",
|
|
5
|
+
TEST = "TEST"
|
|
6
|
+
}
|
|
7
|
+
declare enum TestHeirarchyLevel {
|
|
8
|
+
TEST = "TEST",
|
|
9
|
+
SECTION = "SECTION",
|
|
10
|
+
QUESTION = "QUESTION"
|
|
11
|
+
}
|
|
12
|
+
declare enum QuestionType {
|
|
13
|
+
SINGLE = "SINGLE",
|
|
14
|
+
MULTIPLE = "MULTIPLE",
|
|
15
|
+
INTEGER = "INTEGER"
|
|
16
|
+
}
|
|
17
|
+
declare enum TestStatus {
|
|
18
|
+
START = "Start",
|
|
19
|
+
PAUSED = "Paused",
|
|
20
|
+
REATTEMPT = "Reattempt",
|
|
21
|
+
NOT_STARTED = "NotStarted",
|
|
22
|
+
ENDED = "Ended"
|
|
23
|
+
}
|
|
24
|
+
interface Test {
|
|
25
|
+
name: string;
|
|
26
|
+
type: TestType;
|
|
27
|
+
sections: Section[];
|
|
28
|
+
duration: number;
|
|
29
|
+
sectionsHide: boolean;
|
|
30
|
+
timerLevel: TestHeirarchyLevel;
|
|
31
|
+
_id: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
__v: number;
|
|
35
|
+
isPublished: boolean;
|
|
36
|
+
startDate: Date;
|
|
37
|
+
numberOfQuestions: number;
|
|
38
|
+
isNegativeMarkingEnabled: boolean;
|
|
39
|
+
positiveMarks: number;
|
|
40
|
+
negativeMarks: number;
|
|
41
|
+
marksLevel: TestHeirarchyLevel;
|
|
42
|
+
totalMarks: number;
|
|
43
|
+
totalTime: number;
|
|
44
|
+
channelId: string;
|
|
45
|
+
testMappingId: string;
|
|
46
|
+
status: TestStatus;
|
|
47
|
+
lastVisitedQuestionId: string;
|
|
48
|
+
timeTaken: Record<string, any>;
|
|
49
|
+
}
|
|
50
|
+
interface Section {
|
|
51
|
+
name: string;
|
|
52
|
+
duration: number;
|
|
53
|
+
_id: string;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
updatedAt: string;
|
|
56
|
+
questions: Question[];
|
|
57
|
+
isNegativeMarkingEnabled: boolean;
|
|
58
|
+
positiveMarks: number;
|
|
59
|
+
negativeMarks: number;
|
|
60
|
+
testId: string;
|
|
61
|
+
}
|
|
62
|
+
interface Question {
|
|
63
|
+
_id: string;
|
|
64
|
+
text: string;
|
|
65
|
+
options: Option[];
|
|
66
|
+
type: QuestionType;
|
|
67
|
+
solution: string[];
|
|
68
|
+
sectionId: string;
|
|
69
|
+
testId: string;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
updatedAt: string;
|
|
72
|
+
__v: number;
|
|
73
|
+
solutionDescription?: string;
|
|
74
|
+
displayOrder: number;
|
|
75
|
+
duration: number;
|
|
76
|
+
questionResponse: SolutionDetails$1;
|
|
77
|
+
}
|
|
78
|
+
interface SolutionDetails$1 {
|
|
79
|
+
markedSolution?: string[];
|
|
80
|
+
markedForReview?: boolean;
|
|
81
|
+
timeTaken?: number;
|
|
82
|
+
}
|
|
83
|
+
interface Option {
|
|
84
|
+
text: string;
|
|
85
|
+
_id: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare enum AttemptStatus {
|
|
89
|
+
ATTEMPTED = "ATTEMPTED",
|
|
90
|
+
NOT_ATTEMPTED = "NOT_ATTEMPTED",
|
|
91
|
+
NOT_VISITED = "NOT_VISITED",
|
|
92
|
+
MARKED_FOR_REVIEW = "MARKED_FOR_REVIEW",
|
|
93
|
+
ATTEMPTED_AND_MARKED_FOR_REVIEW = "ATTEMPTED_AND_MARKED_FOR_REVIEW",
|
|
94
|
+
ACITVE_QUESTION = "ACITVE_QUESTION"
|
|
95
|
+
}
|
|
96
|
+
interface UserSettings {
|
|
97
|
+
selectedFilter?: AttemptStatus;
|
|
98
|
+
}
|
|
99
|
+
interface SolutionDetails {
|
|
100
|
+
markedSolution?: string[];
|
|
101
|
+
markedForReview?: boolean;
|
|
102
|
+
timeTaken?: number;
|
|
103
|
+
isSaved?: boolean;
|
|
104
|
+
}
|
|
105
|
+
interface SubmitTest {
|
|
106
|
+
payload: Record<string, any>;
|
|
107
|
+
pause: boolean;
|
|
108
|
+
autoSubmit: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare const TestEngineProvider: ({ test, submitTest, ...props }: {
|
|
112
|
+
test: Test;
|
|
113
|
+
isSolution?: boolean;
|
|
114
|
+
submitTest: React.Dispatch<SubmitTest>;
|
|
115
|
+
} & PropsWithChildren) => React.JSX.Element;
|
|
116
|
+
|
|
117
|
+
declare const useTestEngine: () => {
|
|
118
|
+
currentSection: Section | undefined;
|
|
119
|
+
currentQuestion: Question | undefined;
|
|
120
|
+
handleSubmitTest: (pause?: boolean, autoSubmit?: boolean) => Promise<Record<string, any>>;
|
|
121
|
+
handleUpdateTestDetails: (value: Test) => void;
|
|
122
|
+
handleUpdateQuestionCoordinates: (value: {
|
|
123
|
+
currentQuestionIndex: number;
|
|
124
|
+
currentSectionIndex: number;
|
|
125
|
+
}) => Promise<void>;
|
|
126
|
+
handleUpdateSolutions: (value: Record<string, SolutionDetails>) => void;
|
|
127
|
+
handleUpdateCurrentAnswer: (value: SolutionDetails) => void;
|
|
128
|
+
handleUpdateUserSettings: (value: UserSettings) => void;
|
|
129
|
+
handleResetLocal: () => Promise<void>;
|
|
130
|
+
test: Test | undefined;
|
|
131
|
+
solutions: Record<string, SolutionDetails>;
|
|
132
|
+
currentQuestionIndex: number;
|
|
133
|
+
currentSectionIndex: number;
|
|
134
|
+
currentQuestionAnswer: SolutionDetails | undefined;
|
|
135
|
+
userSettings: UserSettings | undefined;
|
|
136
|
+
isSolution?: boolean;
|
|
137
|
+
submitting?: boolean;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
declare const useTestEngineBody: () => {
|
|
141
|
+
isQuizAnswer: boolean;
|
|
142
|
+
handleClearResponse: () => void;
|
|
143
|
+
handleSelectOption: (optionId: string) => void;
|
|
144
|
+
handleIntegerInputChange: (val: string) => void;
|
|
145
|
+
handleMarkForReview: () => void;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
declare const useTestEngineFooter: () => {
|
|
149
|
+
handleNext: () => void;
|
|
150
|
+
handlePrevious: () => void;
|
|
151
|
+
handleSaveAnswer: () => void;
|
|
152
|
+
handleMarkForReview: () => void;
|
|
153
|
+
isLastQuestion: boolean;
|
|
154
|
+
isFirstQuestion: boolean;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
declare const useTestQuestionStatus: ({ includeAllSections, }?: {
|
|
158
|
+
includeAllSections?: boolean;
|
|
159
|
+
}) => {
|
|
160
|
+
getQuestionStatus: (qi: number, si: number) => AttemptStatus.ATTEMPTED | AttemptStatus.NOT_ATTEMPTED | AttemptStatus.NOT_VISITED | AttemptStatus.MARKED_FOR_REVIEW | AttemptStatus.ATTEMPTED_AND_MARKED_FOR_REVIEW;
|
|
161
|
+
questionStatusMap: Record<AttemptStatus, {
|
|
162
|
+
count: number;
|
|
163
|
+
}>;
|
|
164
|
+
getAnsweredQuestionStatus: (i: number, si: number) => AttemptStatus.ATTEMPTED | AttemptStatus.NOT_ATTEMPTED | AttemptStatus.NOT_VISITED;
|
|
165
|
+
areArraysEqual: (a: string[], b: string[]) => boolean;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
type QuestionStatusType = "correct" | "incorrect" | "skipped";
|
|
169
|
+
declare const useTestSolutionBody: () => {
|
|
170
|
+
correctAnswer: string;
|
|
171
|
+
currentAnswerMarks: string | number;
|
|
172
|
+
currentQuestionStatus: QuestionStatusType;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
declare const useTestTimer: (type: "web" | "app") => {
|
|
176
|
+
timer: number;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
declare const useQuestionStopWatch: (type?: "web" | "app") => {
|
|
180
|
+
questionStopWatch: number;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export { AttemptStatus, type SubmitTest, TestEngineProvider, useQuestionStopWatch, useTestEngine, useTestEngineBody, useTestEngineFooter, useTestQuestionStatus, useTestSolutionBody, useTestTimer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
declare enum TestType {
|
|
4
|
+
QUIZ = "QUIZ",
|
|
5
|
+
TEST = "TEST"
|
|
6
|
+
}
|
|
7
|
+
declare enum TestHeirarchyLevel {
|
|
8
|
+
TEST = "TEST",
|
|
9
|
+
SECTION = "SECTION",
|
|
10
|
+
QUESTION = "QUESTION"
|
|
11
|
+
}
|
|
12
|
+
declare enum QuestionType {
|
|
13
|
+
SINGLE = "SINGLE",
|
|
14
|
+
MULTIPLE = "MULTIPLE",
|
|
15
|
+
INTEGER = "INTEGER"
|
|
16
|
+
}
|
|
17
|
+
declare enum TestStatus {
|
|
18
|
+
START = "Start",
|
|
19
|
+
PAUSED = "Paused",
|
|
20
|
+
REATTEMPT = "Reattempt",
|
|
21
|
+
NOT_STARTED = "NotStarted",
|
|
22
|
+
ENDED = "Ended"
|
|
23
|
+
}
|
|
24
|
+
interface Test {
|
|
25
|
+
name: string;
|
|
26
|
+
type: TestType;
|
|
27
|
+
sections: Section[];
|
|
28
|
+
duration: number;
|
|
29
|
+
sectionsHide: boolean;
|
|
30
|
+
timerLevel: TestHeirarchyLevel;
|
|
31
|
+
_id: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
__v: number;
|
|
35
|
+
isPublished: boolean;
|
|
36
|
+
startDate: Date;
|
|
37
|
+
numberOfQuestions: number;
|
|
38
|
+
isNegativeMarkingEnabled: boolean;
|
|
39
|
+
positiveMarks: number;
|
|
40
|
+
negativeMarks: number;
|
|
41
|
+
marksLevel: TestHeirarchyLevel;
|
|
42
|
+
totalMarks: number;
|
|
43
|
+
totalTime: number;
|
|
44
|
+
channelId: string;
|
|
45
|
+
testMappingId: string;
|
|
46
|
+
status: TestStatus;
|
|
47
|
+
lastVisitedQuestionId: string;
|
|
48
|
+
timeTaken: Record<string, any>;
|
|
49
|
+
}
|
|
50
|
+
interface Section {
|
|
51
|
+
name: string;
|
|
52
|
+
duration: number;
|
|
53
|
+
_id: string;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
updatedAt: string;
|
|
56
|
+
questions: Question[];
|
|
57
|
+
isNegativeMarkingEnabled: boolean;
|
|
58
|
+
positiveMarks: number;
|
|
59
|
+
negativeMarks: number;
|
|
60
|
+
testId: string;
|
|
61
|
+
}
|
|
62
|
+
interface Question {
|
|
63
|
+
_id: string;
|
|
64
|
+
text: string;
|
|
65
|
+
options: Option[];
|
|
66
|
+
type: QuestionType;
|
|
67
|
+
solution: string[];
|
|
68
|
+
sectionId: string;
|
|
69
|
+
testId: string;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
updatedAt: string;
|
|
72
|
+
__v: number;
|
|
73
|
+
solutionDescription?: string;
|
|
74
|
+
displayOrder: number;
|
|
75
|
+
duration: number;
|
|
76
|
+
questionResponse: SolutionDetails$1;
|
|
77
|
+
}
|
|
78
|
+
interface SolutionDetails$1 {
|
|
79
|
+
markedSolution?: string[];
|
|
80
|
+
markedForReview?: boolean;
|
|
81
|
+
timeTaken?: number;
|
|
82
|
+
}
|
|
83
|
+
interface Option {
|
|
84
|
+
text: string;
|
|
85
|
+
_id: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare enum AttemptStatus {
|
|
89
|
+
ATTEMPTED = "ATTEMPTED",
|
|
90
|
+
NOT_ATTEMPTED = "NOT_ATTEMPTED",
|
|
91
|
+
NOT_VISITED = "NOT_VISITED",
|
|
92
|
+
MARKED_FOR_REVIEW = "MARKED_FOR_REVIEW",
|
|
93
|
+
ATTEMPTED_AND_MARKED_FOR_REVIEW = "ATTEMPTED_AND_MARKED_FOR_REVIEW",
|
|
94
|
+
ACITVE_QUESTION = "ACITVE_QUESTION"
|
|
95
|
+
}
|
|
96
|
+
interface UserSettings {
|
|
97
|
+
selectedFilter?: AttemptStatus;
|
|
98
|
+
}
|
|
99
|
+
interface SolutionDetails {
|
|
100
|
+
markedSolution?: string[];
|
|
101
|
+
markedForReview?: boolean;
|
|
102
|
+
timeTaken?: number;
|
|
103
|
+
isSaved?: boolean;
|
|
104
|
+
}
|
|
105
|
+
interface SubmitTest {
|
|
106
|
+
payload: Record<string, any>;
|
|
107
|
+
pause: boolean;
|
|
108
|
+
autoSubmit: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare const TestEngineProvider: ({ test, submitTest, ...props }: {
|
|
112
|
+
test: Test;
|
|
113
|
+
isSolution?: boolean;
|
|
114
|
+
submitTest: React.Dispatch<SubmitTest>;
|
|
115
|
+
} & PropsWithChildren) => React.JSX.Element;
|
|
116
|
+
|
|
117
|
+
declare const useTestEngine: () => {
|
|
118
|
+
currentSection: Section | undefined;
|
|
119
|
+
currentQuestion: Question | undefined;
|
|
120
|
+
handleSubmitTest: (pause?: boolean, autoSubmit?: boolean) => Promise<Record<string, any>>;
|
|
121
|
+
handleUpdateTestDetails: (value: Test) => void;
|
|
122
|
+
handleUpdateQuestionCoordinates: (value: {
|
|
123
|
+
currentQuestionIndex: number;
|
|
124
|
+
currentSectionIndex: number;
|
|
125
|
+
}) => Promise<void>;
|
|
126
|
+
handleUpdateSolutions: (value: Record<string, SolutionDetails>) => void;
|
|
127
|
+
handleUpdateCurrentAnswer: (value: SolutionDetails) => void;
|
|
128
|
+
handleUpdateUserSettings: (value: UserSettings) => void;
|
|
129
|
+
handleResetLocal: () => Promise<void>;
|
|
130
|
+
test: Test | undefined;
|
|
131
|
+
solutions: Record<string, SolutionDetails>;
|
|
132
|
+
currentQuestionIndex: number;
|
|
133
|
+
currentSectionIndex: number;
|
|
134
|
+
currentQuestionAnswer: SolutionDetails | undefined;
|
|
135
|
+
userSettings: UserSettings | undefined;
|
|
136
|
+
isSolution?: boolean;
|
|
137
|
+
submitting?: boolean;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
declare const useTestEngineBody: () => {
|
|
141
|
+
isQuizAnswer: boolean;
|
|
142
|
+
handleClearResponse: () => void;
|
|
143
|
+
handleSelectOption: (optionId: string) => void;
|
|
144
|
+
handleIntegerInputChange: (val: string) => void;
|
|
145
|
+
handleMarkForReview: () => void;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
declare const useTestEngineFooter: () => {
|
|
149
|
+
handleNext: () => void;
|
|
150
|
+
handlePrevious: () => void;
|
|
151
|
+
handleSaveAnswer: () => void;
|
|
152
|
+
handleMarkForReview: () => void;
|
|
153
|
+
isLastQuestion: boolean;
|
|
154
|
+
isFirstQuestion: boolean;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
declare const useTestQuestionStatus: ({ includeAllSections, }?: {
|
|
158
|
+
includeAllSections?: boolean;
|
|
159
|
+
}) => {
|
|
160
|
+
getQuestionStatus: (qi: number, si: number) => AttemptStatus.ATTEMPTED | AttemptStatus.NOT_ATTEMPTED | AttemptStatus.NOT_VISITED | AttemptStatus.MARKED_FOR_REVIEW | AttemptStatus.ATTEMPTED_AND_MARKED_FOR_REVIEW;
|
|
161
|
+
questionStatusMap: Record<AttemptStatus, {
|
|
162
|
+
count: number;
|
|
163
|
+
}>;
|
|
164
|
+
getAnsweredQuestionStatus: (i: number, si: number) => AttemptStatus.ATTEMPTED | AttemptStatus.NOT_ATTEMPTED | AttemptStatus.NOT_VISITED;
|
|
165
|
+
areArraysEqual: (a: string[], b: string[]) => boolean;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
type QuestionStatusType = "correct" | "incorrect" | "skipped";
|
|
169
|
+
declare const useTestSolutionBody: () => {
|
|
170
|
+
correctAnswer: string;
|
|
171
|
+
currentAnswerMarks: string | number;
|
|
172
|
+
currentQuestionStatus: QuestionStatusType;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
declare const useTestTimer: (type: "web" | "app") => {
|
|
176
|
+
timer: number;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
declare const useQuestionStopWatch: (type?: "web" | "app") => {
|
|
180
|
+
questionStopWatch: number;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export { AttemptStatus, type SubmitTest, TestEngineProvider, useQuestionStopWatch, useTestEngine, useTestEngineBody, useTestEngineFooter, useTestQuestionStatus, useTestSolutionBody, useTestTimer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var ne=Object.create;var F=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var ue=(n,e)=>{for(var t in e)F(n,t,{get:e[t],enumerable:!0})},B=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of re(e))!oe.call(n,s)&&s!==t&&F(n,s,{get:()=>e[s],enumerable:!(o=se(e,s))||o.enumerable});return n};var U=(n,e,t)=>(t=n!=null?ne(ie(n)):{},B(e||!n||!n.__esModule?F(t,"default",{value:n,enumerable:!0}):t,n)),ae=n=>B(F({},"__esModule",{value:!0}),n);var Ae={};ue(Ae,{AttemptStatus:()=>w,TestEngineProvider:()=>z,useQuestionStopWatch:()=>te,useTestEngine:()=>D,useTestEngineBody:()=>$,useTestEngineFooter:()=>j,useTestQuestionStatus:()=>Q,useTestSolutionBody:()=>X,useTestTimer:()=>ee});module.exports=ae(Ae);var Z=require("react");var K=U(require("react")),w=(r=>(r.ATTEMPTED="ATTEMPTED",r.NOT_ATTEMPTED="NOT_ATTEMPTED",r.NOT_VISITED="NOT_VISITED",r.MARKED_FOR_REVIEW="MARKED_FOR_REVIEW",r.ATTEMPTED_AND_MARKED_FOR_REVIEW="ATTEMPTED_AND_MARKED_FOR_REVIEW",r.ACITVE_QUESTION="ACITVE_QUESTION",r))(w||{});var W={test:void 0,solutions:{},currentQuestionIndex:0,currentSectionIndex:0,currentQuestionAnswer:{},userSettings:{},isSolution:!1,submitting:!1},P=K.default.createContext([W,()=>{},()=>{}]);P.displayName="TestEngineContext";var J=(n,e)=>{switch(e.type){case"UPDATE_TEST":return{...n,test:e.value};case"UPDATE_SOLUTIONS":return{...n,solutions:e.value};case"UPDATE_CURRENT_ANSWER":return{...n,currentQuestionAnswer:e.value};case"UPDATE_USER_SETTINGS":return{...n,userSettings:e.value};case"UPDATE_TEST_SUBMITTING":return{...n,submitting:e.value};case"UPDATE_QUESTION_COORDINATES":return{...n,currentSectionIndex:e.value.currentSectionIndex,currentQuestionIndex:e.value.currentQuestionIndex}}};var O=U(require("react"));var L=U(require("@react-native-async-storage/async-storage")),ce=()=>!(typeof navigator<"u"&&navigator.product==="ReactNative")&&typeof window<"u"&&window.localStorage?{getItem:e=>localStorage.getItem(e)?JSON.parse(localStorage.getItem(e)):null,setItem:(e,t)=>localStorage.setItem(e,JSON.stringify(t)),removeItem:e=>localStorage.removeItem(e)}:{getItem:async e=>{try{let t=await L.default.getItem(e);return t?JSON.parse(t):null}catch(t){return console.log(t),null}},setItem:async(e,t)=>{try{await L.default.setItem(e,JSON.stringify(t))}catch(o){console.log(o)}},removeItem:async e=>{try{await L.default.removeItem(e)}catch(t){console.log(t)}}},c=ce();var de=({test:n,submitTest:e,...t})=>{let[o,s]=O.default.useState(!1),[u,r]=O.default.useReducer(J,{...W,test:n,isSolution:t.isSolution}),m=async()=>{let l=await c.getItem(`${n?._id}-test-initiated`),T=await c.getItem(`${n._id}-solutions`)||{};r(l?{type:"UPDATE_SOLUTIONS",value:T}:{type:"UPDATE_SOLUTIONS",value:n?.sections?.reduce((i,E)=>(E.questions?.forEach(a=>{a.questionResponse&&(i[a._id]={...a.questionResponse})}),i),{})||{}});let d=await c.getItem(`${n._id}-currentSectionIndex`)||0,I=await c.getItem(`${n._id}-currentQuestionIndex`)||0;r({type:"UPDATE_QUESTION_COORDINATES",value:{currentSectionIndex:d,currentQuestionIndex:I}}),s(!0)};return(0,Z.useEffect)(()=>{m()},[]),o?O.default.createElement(P.Provider,{value:[u,r,e],...t}):O.default.createElement(O.default.Fragment,null)},z=de;var A=U(require("react"));var me=()=>{let n=A.default.useContext(P);if(n===void 0)throw new Error("useTestEngine must be use within TestEngineProvider");let[e,t,o]=n,s=A.default.useMemo(()=>e.test?.sections[e.currentSectionIndex],[e.currentSectionIndex]),u=A.default.useMemo(()=>s?.questions[e.currentQuestionIndex],[e.currentQuestionIndex,s]);A.default.useEffect(()=>{u&&(e.solutions[u._id]?m({...e.solutions[u._id],isSaved:!0}):(e.isSolution||i({...e.solutions,[u._id]:{}}),m({}))),c.setItem(`${e.test?._id}-currentSectionIndex`,e.currentSectionIndex),c.setItem(`${e.test?._id}-currentQuestionIndex`,e.currentQuestionIndex)},[e.currentSectionIndex,e.currentQuestionIndex]);let r=A.default.useCallback(S=>t({type:"UPDATE_TEST",value:S}),[t]),m=A.default.useCallback(S=>t({type:"UPDATE_CURRENT_ANSWER",value:S}),[t]),l=A.default.useCallback(async S=>(await T(),t({type:"UPDATE_QUESTION_COORDINATES",value:S})),[t]),T=async()=>{let S=await c.getItem(`${e?.test?._id}-timers`)||{};e.test?.sections.forEach(v=>{v.questions?.forEach(R=>{S[R._id]&&!e.solutions[R._id]&&(e.solutions[R._id]={}),e.solutions[R._id]&&(e.solutions[R._id].timeTaken=S[R._id])})})},d=A.default.useCallback(S=>t({type:"UPDATE_USER_SETTINGS",value:S}),[t]),I=A.default.useCallback(S=>t({type:"UPDATE_TEST_SUBMITTING",value:S}),[t]);A.default.useEffect(()=>{e.isSolution||c.setItem(`${e.test?._id}-solutions`,e.solutions)},[e.solutions]);let i=A.default.useCallback(S=>t({type:"UPDATE_SOLUTIONS",value:S}),[t]),E=A.default.useCallback(async()=>{if(!await c.getItem(`${e.test?._id}-test-initiated`)&&e.test?.status==="Paused"){let v=await c.getItem(`${e?.test?._id}-timers`)||{},R={};e.test?.sections?.forEach((p,g)=>{p.questions?.forEach((_,y)=>{_._id===e.test?.lastVisitedQuestionId&&l({currentSectionIndex:g,currentQuestionIndex:y}),_.questionResponse&&(R[_._id]=JSON.stringify(_.questionResponse.timeTaken||0))})}),c.setItem(`${e?.test?._id}-timers`,{...v,...R})}e?.isSolution||c.setItem(`${e.test?._id}-test-initiated`,"true")},[]);A.default.useEffect(()=>{E()},[]);let a=async()=>{await c.removeItem(`${e.test?._id}-currentQuestionIndex`),await c.removeItem(`${e.test?._id}-currentSectionIndex`),await c.removeItem(`${e.test?._id}-solutions`),await c.removeItem(`${e.test?._id}-test-initiated`),await c.removeItem(`${e?.test?._id}-timers`)},f=A.default.useCallback(async(S=!1,v=!1)=>{I(!0);let R=await c.getItem(`${e.test?._id}-solutions`)||{},p=await c.getItem(`${e?.test?._id}-timers`)||{},g=[];e.test?.sections.forEach(y=>{y.questions.forEach(M=>{let C={questionId:M._id};R[M._id]&&(C.markedSolution=R[M._id].markedSolution||[],C.timeTaken=parseInt(p[M._id]||0),C.markedForReview=R[M._id].markedForReview||!1,g.push(C))})});let _={submittedBy:v?"autoSubmit":"user",questionResponses:g,testMappingId:e.test?.testMappingId,type:S?"Pause":"Submit",testId:e.test?._id};return S&&(_.lastVisitedQuestionId=u?._id),e.test?.timerLevel==="TEST"&&e.test.type==="TEST"&&S&&p[e?.test?._id]&&(_.timeTaken={[e.test?._id]:p[e?.test?._id]}),g.length||delete _.questionResponses,await a(),I(!1),o({payload:_,pause:S,autoSubmit:v}),_},[u]);return A.default.useMemo(()=>({...e,currentSection:s,currentQuestion:u,handleSubmitTest:f,handleUpdateTestDetails:r,handleUpdateQuestionCoordinates:l,handleUpdateSolutions:i,handleUpdateCurrentAnswer:m,handleUpdateUserSettings:d,handleResetLocal:a}),[e,s,u,f,r,l,i,m,d,a])},D=me;var N=U(require("react"));var Ee=()=>{let{currentQuestion:n,currentQuestionAnswer:e,test:t,solutions:o,isSolution:s,handleUpdateCurrentAnswer:u,handleUpdateSolutions:r}=D(),m=N.default.useMemo(()=>t?.type==="QUIZ"&&!!o[n?._id]?.markedSolution?.length,[t,o,n]),l=(0,N.useCallback)(()=>{u({...e,markedSolution:[],isSaved:!1}),r({...o,[n?._id]:{...e,markedSolution:[]}})},[e,n,o,u,r]),T=(0,N.useCallback)(i=>{if(!(s||m))if(e?.markedSolution?.includes(i)){let E=e.markedSolution.filter(a=>a!==i);return E?.length===0?l():u({...e,markedSolution:E,isSaved:!1})}else{if(n?.type==="SINGLE")return u({...e,markedSolution:[i],isSaved:!1});{let E=e?.markedSolution?.length?e?.markedSolution:[];return u({...e,markedSolution:[...E,i],isSaved:!1})}}},[s,m,n,e,u,l]),d=(0,N.useCallback)(i=>{s||m||(u({...e,markedSolution:i?[i]:[],isSaved:!1}),i||l())},[s,m,u,e,l]),I=(0,N.useCallback)(()=>{u({...e,markedForReview:!e?.markedForReview}),r({...o,[n._id]:{...o[n._id],markedForReview:!e?.markedForReview}})},[u,r,e,o,n]);return{isQuizAnswer:m,handleClearResponse:l,handleSelectOption:T,handleIntegerInputChange:d,handleMarkForReview:I}},$=Ee;var k=require("react");var G=U(require("react"));var Ie=({includeAllSections:n}={})=>{let{currentQuestionIndex:e,solutions:t,currentSectionIndex:o,test:s,isSolution:u}=D(),[r,m]=G.default.useState({MARKED_FOR_REVIEW:{count:0},ATTEMPTED:{count:0},ATTEMPTED_AND_MARKED_FOR_REVIEW:{count:0},NOT_ATTEMPTED:{count:0},NOT_VISITED:{count:0},ACITVE_QUESTION:{count:0}}),l=()=>{let i={...r};Object.values(i).forEach(E=>E.count=0),n?s?.sections?.forEach((E,a)=>{E?.questions?.forEach((f,b)=>{let S=u||s.type==="QUIZ"?I(b,a):T(b,a);i[S].count+=1})}):s?.sections[o]?.questions.forEach((E,a)=>{let f=u||s.type==="QUIZ"?I(a,o):T(a,o);i[f].count+=1}),m(i)};G.default.useEffect(()=>{l()},[e,t,o]);let T=(i,E)=>{let a=s?.sections[E]?.questions[i],f;return t[a?._id]&&t[a?._id].markedSolution?.length&&t[a?._id].markedForReview?f="ATTEMPTED_AND_MARKED_FOR_REVIEW":t[a?._id]&&t[a?._id].markedForReview?f="MARKED_FOR_REVIEW":t[a?._id]&&t[a?._id].markedSolution?.length?f="ATTEMPTED":t[a?._id]?f="NOT_ATTEMPTED":f="NOT_VISITED",f};function d(i,E){let a=i.slice().sort(),f=E.slice().sort();if(a.length!==f.length)return!1;for(let b=0;b<a.length;b++)if(a[b]!==f[b])return!1;return!0}let I=(i,E)=>{let a=s?.sections[E]?.questions[i],f;return t[a?._id]&&t[a?._id].markedSolution?.length?d(t[a?._id].markedSolution,a.solution)?f="ATTEMPTED":f="NOT_ATTEMPTED":f="NOT_VISITED",f};return{getQuestionStatus:T,questionStatusMap:r,getAnsweredQuestionStatus:I,areArraysEqual:d}},Q=Ie;var fe=()=>{let{handleUpdateQuestionCoordinates:n,currentQuestionIndex:e,currentSectionIndex:t,currentSection:o,currentQuestionAnswer:s,handleUpdateSolutions:u,solutions:r,currentQuestion:m,handleUpdateCurrentAnswer:l,test:T,userSettings:d}=D(),{getAnsweredQuestionStatus:I}=Q(),[i,E]=(0,k.useState)([]);(0,k.useEffect)(()=>{if(d?.selectedFilter){let p=o?.questions?.map((g,_)=>{if(d?.selectedFilter===I(_,t))return _})?.filter(g=>g!==void 0);E(p),p?.length&&n({currentSectionIndex:t,currentQuestionIndex:p[0]||0})}else E([])},[d?.selectedFilter,o]);let a=()=>{s?.isSaved||(delete s?.isSaved,u({...r,[m?._id]:{...s}}))},f=()=>{if(d?.selectedFilter){let _=i?.findIndex(y=>y===e);_>=0&&i[_+1]>=0&&n({currentSectionIndex:t,currentQuestionIndex:i[_+1]});return}let p=o?.questions[e+1]?t:T?.sections[t+1]?t+1:t,g=o?.questions[e+1]?e+1:0;n({currentSectionIndex:p,currentQuestionIndex:g})},b=()=>{if(d?.selectedFilter){let _=i?.findIndex(y=>y===e);_>=0&&i[_-1]>=0&&n({currentSectionIndex:t,currentQuestionIndex:i[_-1]});return}let p=o?.questions[e-1]?t:T?.sections[t-1]?t-1:t,g=o?.questions[e-1]?e-1:T.sections[p]?.questions?.length-1;n({currentSectionIndex:p,currentQuestionIndex:g})},S=(0,k.useMemo)(()=>{if(d?.selectedFilter){let p=i?.findIndex(g=>g===e);return!i[p+1]}return!T?.sections[t+1]&&!o?.questions[e+1]},[t,e,i,d?.selectedFilter]),v=(0,k.useMemo)(()=>d?.selectedFilter?i?.findIndex(g=>g===e)<=0:t===0&&e===0,[t,e,i,d?.selectedFilter]);return{handleNext:f,handlePrevious:b,handleSaveAnswer:a,handleMarkForReview:()=>{l({...s,markedForReview:!s?.markedForReview}),u({...r,[m._id]:{...r[m._id],markedForReview:!s?.markedForReview}})},isLastQuestion:S,isFirstQuestion:v}},j=fe;var V=U(require("react"));var H={1:{label:"A"},2:{label:"B"},3:{label:"C"},4:{label:"D"}},_e=()=>{let{currentQuestionIndex:n,test:e,currentSection:t,currentSectionIndex:o,currentQuestion:s}=D(),{getAnsweredQuestionStatus:u}=Q(),r=V.default.useMemo(()=>u(n,o)==="ATTEMPTED"?"correct":u(n,o)==="NOT_ATTEMPTED"?"incorrect":"skipped",[n,o]),m=V.default.useMemo(()=>{switch(r){case"correct":return e?.marksLevel==="TEST"?"+"+e.positiveMarks:"+"+t?.positiveMarks;case"incorrect":return e?.marksLevel==="TEST"?e.isNegativeMarkingEnabled?"-"+e.negativeMarks:0:t?.isNegativeMarkingEnabled?"-"+t?.negativeMarks:0;case"skipped":return 0}},[r,o,n]);return{correctAnswer:V.default.useMemo(()=>{if(!s)return"";if(s.type==="INTEGER")return s.solution[0];if(s.type==="SINGLE"){let T=s.options.findIndex(d=>d._id===s.solution[0]);return H[T+1]?.label||""}return s.type==="MULTIPLE"?s.solution.map(d=>{let I=s.options.findIndex(i=>i._id===d);return H[I+1]?.label||""}).join(", "):""},[s]),currentAnswerMarks:m,currentQuestionStatus:r}},X=_e;var q=U(require("react"));var pe=n=>{let{test:e,handleSubmitTest:t}=D(),o=q.default.useRef(null),[s,u]=q.default.useState(e?.timeTaken?.[e?._id]??e?.duration??0),r=async l=>{let T=await c.getItem(`${e?._id}-timers`);if(l<=0){t(!1,!0);return}T[e._id]=l+"",c.setItem(`${e?._id}-timers`,T),u(l),o.current=setTimeout(()=>{r(l-1)},n==="app"?950:1e3)},m=async()=>{let l=await c.getItem(`${e?._id}-timers`);l||(await c.setItem(`${e?._id}-timers`,{}),l={});let T=parseInt(l?.[e?._id]||e?.timeTaken?.[e?._id]||e?.duration||0);r(T)};return q.default.useEffect(()=>(m(),()=>{o.current&&clearTimeout(o.current)}),[]),{timer:s}},ee=pe;var h=U(require("react"));var ge=n=>{let e=n==="app"?950:1e3,{currentQuestion:t,solutions:o,test:s}=D(),{isQuizAnswer:u}=$(),r=h.default.useRef(null),[m,l]=h.default.useState(0),T=async I=>{if(!t)return;let i=await c.getItem(`${s?._id}-timers`);if((o[t?._id]?.markedSolution||[])?.length===0)i[t?._id]=I+"",c.setItem(`${s?._id}-timers`,i),l(I);else{clearTimeout(r.current);return}r.current=setTimeout(()=>{T(I+1)},e)},d=async()=>{r.current&&(clearTimeout(r.current),r.current=null);let I=await c.getItem(`${s?._id}-timers`);I||(await c.setItem(`${s?._id}-timers`,{}),I={});let i=parseInt(I?.[t?._id]||s?.timeTaken?.[t?._id]||0);l(i),T(i)};return h.default.useEffect(()=>(t?._id&&d(),()=>{r.current&&(clearTimeout(r.current),r.current=null)}),[t]),h.default.useEffect(()=>{r.current===null&&setTimeout(()=>{r.current===null&&d()},e)},[o]),h.default.useEffect(()=>{u&&(clearTimeout(r.current),r.current=null)},[u]),{questionStopWatch:m}},te=ge;0&&(module.exports={AttemptStatus,TestEngineProvider,useQuestionStopWatch,useTestEngine,useTestEngineBody,useTestEngineFooter,useTestQuestionStatus,useTestSolutionBody,useTestTimer});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as Y}from"react";import J from"react";var w=(n=>(n.ATTEMPTED="ATTEMPTED",n.NOT_ATTEMPTED="NOT_ATTEMPTED",n.NOT_VISITED="NOT_VISITED",n.MARKED_FOR_REVIEW="MARKED_FOR_REVIEW",n.ATTEMPTED_AND_MARKED_FOR_REVIEW="ATTEMPTED_AND_MARKED_FOR_REVIEW",n.ACITVE_QUESTION="ACITVE_QUESTION",n))(w||{});var C={test:void 0,solutions:{},currentQuestionIndex:0,currentSectionIndex:0,currentQuestionAnswer:{},userSettings:{},isSolution:!1,submitting:!1},k=J.createContext([C,()=>{},()=>{}]);k.displayName="TestEngineContext";var q=(r,e)=>{switch(e.type){case"UPDATE_TEST":return{...r,test:e.value};case"UPDATE_SOLUTIONS":return{...r,solutions:e.value};case"UPDATE_CURRENT_ANSWER":return{...r,currentQuestionAnswer:e.value};case"UPDATE_USER_SETTINGS":return{...r,userSettings:e.value};case"UPDATE_TEST_SUBMITTING":return{...r,submitting:e.value};case"UPDATE_QUESTION_COORDINATES":return{...r,currentSectionIndex:e.value.currentSectionIndex,currentQuestionIndex:e.value.currentQuestionIndex}}};import O from"react";import F from"@react-native-async-storage/async-storage";var Z=()=>!(typeof navigator<"u"&&navigator.product==="ReactNative")&&typeof window<"u"&&window.localStorage?{getItem:e=>localStorage.getItem(e)?JSON.parse(localStorage.getItem(e)):null,setItem:(e,t)=>localStorage.setItem(e,JSON.stringify(t)),removeItem:e=>localStorage.removeItem(e)}:{getItem:async e=>{try{let t=await F.getItem(e);return t?JSON.parse(t):null}catch(t){return console.log(t),null}},setItem:async(e,t)=>{try{await F.setItem(e,JSON.stringify(t))}catch(o){console.log(o)}},removeItem:async e=>{try{await F.removeItem(e)}catch(t){console.log(t)}}},c=Z();var j=({test:r,submitTest:e,...t})=>{let[o,i]=O.useState(!1),[u,n]=O.useReducer(q,{...C,test:r,isSolution:t.isSolution}),m=async()=>{let l=await c.getItem(`${r?._id}-test-initiated`),T=await c.getItem(`${r._id}-solutions`)||{};n(l?{type:"UPDATE_SOLUTIONS",value:T}:{type:"UPDATE_SOLUTIONS",value:r?.sections?.reduce((s,E)=>(E.questions?.forEach(a=>{a.questionResponse&&(s[a._id]={...a.questionResponse})}),s),{})||{}});let d=await c.getItem(`${r._id}-currentSectionIndex`)||0,I=await c.getItem(`${r._id}-currentQuestionIndex`)||0;n({type:"UPDATE_QUESTION_COORDINATES",value:{currentSectionIndex:d,currentQuestionIndex:I}}),i(!0)};return Y(()=>{m()},[]),o?O.createElement(k.Provider,{value:[u,n,e],...t}):O.createElement(O.Fragment,null)},H=j;import A from"react";var ee=()=>{let r=A.useContext(k);if(r===void 0)throw new Error("useTestEngine must be use within TestEngineProvider");let[e,t,o]=r,i=A.useMemo(()=>e.test?.sections[e.currentSectionIndex],[e.currentSectionIndex]),u=A.useMemo(()=>i?.questions[e.currentQuestionIndex],[e.currentQuestionIndex,i]);A.useEffect(()=>{u&&(e.solutions[u._id]?m({...e.solutions[u._id],isSaved:!0}):(e.isSolution||s({...e.solutions,[u._id]:{}}),m({}))),c.setItem(`${e.test?._id}-currentSectionIndex`,e.currentSectionIndex),c.setItem(`${e.test?._id}-currentQuestionIndex`,e.currentQuestionIndex)},[e.currentSectionIndex,e.currentQuestionIndex]);let n=A.useCallback(S=>t({type:"UPDATE_TEST",value:S}),[t]),m=A.useCallback(S=>t({type:"UPDATE_CURRENT_ANSWER",value:S}),[t]),l=A.useCallback(async S=>(await T(),t({type:"UPDATE_QUESTION_COORDINATES",value:S})),[t]),T=async()=>{let S=await c.getItem(`${e?.test?._id}-timers`)||{};e.test?.sections.forEach(v=>{v.questions?.forEach(R=>{S[R._id]&&!e.solutions[R._id]&&(e.solutions[R._id]={}),e.solutions[R._id]&&(e.solutions[R._id].timeTaken=S[R._id])})})},d=A.useCallback(S=>t({type:"UPDATE_USER_SETTINGS",value:S}),[t]),I=A.useCallback(S=>t({type:"UPDATE_TEST_SUBMITTING",value:S}),[t]);A.useEffect(()=>{e.isSolution||c.setItem(`${e.test?._id}-solutions`,e.solutions)},[e.solutions]);let s=A.useCallback(S=>t({type:"UPDATE_SOLUTIONS",value:S}),[t]),E=A.useCallback(async()=>{if(!await c.getItem(`${e.test?._id}-test-initiated`)&&e.test?.status==="Paused"){let v=await c.getItem(`${e?.test?._id}-timers`)||{},R={};e.test?.sections?.forEach((p,g)=>{p.questions?.forEach((_,y)=>{_._id===e.test?.lastVisitedQuestionId&&l({currentSectionIndex:g,currentQuestionIndex:y}),_.questionResponse&&(R[_._id]=JSON.stringify(_.questionResponse.timeTaken||0))})}),c.setItem(`${e?.test?._id}-timers`,{...v,...R})}e?.isSolution||c.setItem(`${e.test?._id}-test-initiated`,"true")},[]);A.useEffect(()=>{E()},[]);let a=async()=>{await c.removeItem(`${e.test?._id}-currentQuestionIndex`),await c.removeItem(`${e.test?._id}-currentSectionIndex`),await c.removeItem(`${e.test?._id}-solutions`),await c.removeItem(`${e.test?._id}-test-initiated`),await c.removeItem(`${e?.test?._id}-timers`)},f=A.useCallback(async(S=!1,v=!1)=>{I(!0);let R=await c.getItem(`${e.test?._id}-solutions`)||{},p=await c.getItem(`${e?.test?._id}-timers`)||{},g=[];e.test?.sections.forEach(y=>{y.questions.forEach(N=>{let M={questionId:N._id};R[N._id]&&(M.markedSolution=R[N._id].markedSolution||[],M.timeTaken=parseInt(p[N._id]||0),M.markedForReview=R[N._id].markedForReview||!1,g.push(M))})});let _={submittedBy:v?"autoSubmit":"user",questionResponses:g,testMappingId:e.test?.testMappingId,type:S?"Pause":"Submit",testId:e.test?._id};return S&&(_.lastVisitedQuestionId=u?._id),e.test?.timerLevel==="TEST"&&e.test.type==="TEST"&&S&&p[e?.test?._id]&&(_.timeTaken={[e.test?._id]:p[e?.test?._id]}),g.length||delete _.questionResponses,await a(),I(!1),o({payload:_,pause:S,autoSubmit:v}),_},[u]);return A.useMemo(()=>({...e,currentSection:i,currentQuestion:u,handleSubmitTest:f,handleUpdateTestDetails:n,handleUpdateQuestionCoordinates:l,handleUpdateSolutions:s,handleUpdateCurrentAnswer:m,handleUpdateUserSettings:d,handleResetLocal:a}),[e,i,u,f,n,l,s,m,d,a])},D=ee;import ne,{useCallback as P}from"react";var se=()=>{let{currentQuestion:r,currentQuestionAnswer:e,test:t,solutions:o,isSolution:i,handleUpdateCurrentAnswer:u,handleUpdateSolutions:n}=D(),m=ne.useMemo(()=>t?.type==="QUIZ"&&!!o[r?._id]?.markedSolution?.length,[t,o,r]),l=P(()=>{u({...e,markedSolution:[],isSaved:!1}),n({...o,[r?._id]:{...e,markedSolution:[]}})},[e,r,o,u,n]),T=P(s=>{if(!(i||m))if(e?.markedSolution?.includes(s)){let E=e.markedSolution.filter(a=>a!==s);return E?.length===0?l():u({...e,markedSolution:E,isSaved:!1})}else{if(r?.type==="SINGLE")return u({...e,markedSolution:[s],isSaved:!1});{let E=e?.markedSolution?.length?e?.markedSolution:[];return u({...e,markedSolution:[...E,s],isSaved:!1})}}},[i,m,r,e,u,l]),d=P(s=>{i||m||(u({...e,markedSolution:s?[s]:[],isSaved:!1}),s||l())},[i,m,u,e,l]),I=P(()=>{u({...e,markedForReview:!e?.markedForReview}),n({...o,[r._id]:{...o[r._id],markedForReview:!e?.markedForReview}})},[u,n,e,o,r]);return{isQuizAnswer:m,handleClearResponse:l,handleSelectOption:T,handleIntegerInputChange:d,handleMarkForReview:I}},L=se;import{useEffect as ie,useMemo as B,useState as oe}from"react";import G from"react";var re=({includeAllSections:r}={})=>{let{currentQuestionIndex:e,solutions:t,currentSectionIndex:o,test:i,isSolution:u}=D(),[n,m]=G.useState({MARKED_FOR_REVIEW:{count:0},ATTEMPTED:{count:0},ATTEMPTED_AND_MARKED_FOR_REVIEW:{count:0},NOT_ATTEMPTED:{count:0},NOT_VISITED:{count:0},ACITVE_QUESTION:{count:0}}),l=()=>{let s={...n};Object.values(s).forEach(E=>E.count=0),r?i?.sections?.forEach((E,a)=>{E?.questions?.forEach((f,U)=>{let S=u||i.type==="QUIZ"?I(U,a):T(U,a);s[S].count+=1})}):i?.sections[o]?.questions.forEach((E,a)=>{let f=u||i.type==="QUIZ"?I(a,o):T(a,o);s[f].count+=1}),m(s)};G.useEffect(()=>{l()},[e,t,o]);let T=(s,E)=>{let a=i?.sections[E]?.questions[s],f;return t[a?._id]&&t[a?._id].markedSolution?.length&&t[a?._id].markedForReview?f="ATTEMPTED_AND_MARKED_FOR_REVIEW":t[a?._id]&&t[a?._id].markedForReview?f="MARKED_FOR_REVIEW":t[a?._id]&&t[a?._id].markedSolution?.length?f="ATTEMPTED":t[a?._id]?f="NOT_ATTEMPTED":f="NOT_VISITED",f};function d(s,E){let a=s.slice().sort(),f=E.slice().sort();if(a.length!==f.length)return!1;for(let U=0;U<a.length;U++)if(a[U]!==f[U])return!1;return!0}let I=(s,E)=>{let a=i?.sections[E]?.questions[s],f;return t[a?._id]&&t[a?._id].markedSolution?.length?d(t[a?._id].markedSolution,a.solution)?f="ATTEMPTED":f="NOT_ATTEMPTED":f="NOT_VISITED",f};return{getQuestionStatus:T,questionStatusMap:n,getAnsweredQuestionStatus:I,areArraysEqual:d}},Q=re;var ue=()=>{let{handleUpdateQuestionCoordinates:r,currentQuestionIndex:e,currentSectionIndex:t,currentSection:o,currentQuestionAnswer:i,handleUpdateSolutions:u,solutions:n,currentQuestion:m,handleUpdateCurrentAnswer:l,test:T,userSettings:d}=D(),{getAnsweredQuestionStatus:I}=Q(),[s,E]=oe([]);ie(()=>{if(d?.selectedFilter){let p=o?.questions?.map((g,_)=>{if(d?.selectedFilter===I(_,t))return _})?.filter(g=>g!==void 0);E(p),p?.length&&r({currentSectionIndex:t,currentQuestionIndex:p[0]||0})}else E([])},[d?.selectedFilter,o]);let a=()=>{i?.isSaved||(delete i?.isSaved,u({...n,[m?._id]:{...i}}))},f=()=>{if(d?.selectedFilter){let _=s?.findIndex(y=>y===e);_>=0&&s[_+1]>=0&&r({currentSectionIndex:t,currentQuestionIndex:s[_+1]});return}let p=o?.questions[e+1]?t:T?.sections[t+1]?t+1:t,g=o?.questions[e+1]?e+1:0;r({currentSectionIndex:p,currentQuestionIndex:g})},U=()=>{if(d?.selectedFilter){let _=s?.findIndex(y=>y===e);_>=0&&s[_-1]>=0&&r({currentSectionIndex:t,currentQuestionIndex:s[_-1]});return}let p=o?.questions[e-1]?t:T?.sections[t-1]?t-1:t,g=o?.questions[e-1]?e-1:T.sections[p]?.questions?.length-1;r({currentSectionIndex:p,currentQuestionIndex:g})},S=B(()=>{if(d?.selectedFilter){let p=s?.findIndex(g=>g===e);return!s[p+1]}return!T?.sections[t+1]&&!o?.questions[e+1]},[t,e,s,d?.selectedFilter]),v=B(()=>d?.selectedFilter?s?.findIndex(g=>g===e)<=0:t===0&&e===0,[t,e,s,d?.selectedFilter]);return{handleNext:f,handlePrevious:U,handleSaveAnswer:a,handleMarkForReview:()=>{l({...i,markedForReview:!i?.markedForReview}),u({...n,[m._id]:{...n[m._id],markedForReview:!i?.markedForReview}})},isLastQuestion:S,isFirstQuestion:v}},ae=ue;import $ from"react";var K={1:{label:"A"},2:{label:"B"},3:{label:"C"},4:{label:"D"}},ce=()=>{let{currentQuestionIndex:r,test:e,currentSection:t,currentSectionIndex:o,currentQuestion:i}=D(),{getAnsweredQuestionStatus:u}=Q(),n=$.useMemo(()=>u(r,o)==="ATTEMPTED"?"correct":u(r,o)==="NOT_ATTEMPTED"?"incorrect":"skipped",[r,o]),m=$.useMemo(()=>{switch(n){case"correct":return e?.marksLevel==="TEST"?"+"+e.positiveMarks:"+"+t?.positiveMarks;case"incorrect":return e?.marksLevel==="TEST"?e.isNegativeMarkingEnabled?"-"+e.negativeMarks:0:t?.isNegativeMarkingEnabled?"-"+t?.negativeMarks:0;case"skipped":return 0}},[n,o,r]);return{correctAnswer:$.useMemo(()=>{if(!i)return"";if(i.type==="INTEGER")return i.solution[0];if(i.type==="SINGLE"){let T=i.options.findIndex(d=>d._id===i.solution[0]);return K[T+1]?.label||""}return i.type==="MULTIPLE"?i.solution.map(d=>{let I=i.options.findIndex(s=>s._id===d);return K[I+1]?.label||""}).join(", "):""},[i]),currentAnswerMarks:m,currentQuestionStatus:n}},le=ce;import V from"react";var de=r=>{let{test:e,handleSubmitTest:t}=D(),o=V.useRef(null),[i,u]=V.useState(e?.timeTaken?.[e?._id]??e?.duration??0),n=async l=>{let T=await c.getItem(`${e?._id}-timers`);if(l<=0){t(!1,!0);return}T[e._id]=l+"",c.setItem(`${e?._id}-timers`,T),u(l),o.current=setTimeout(()=>{n(l-1)},r==="app"?950:1e3)},m=async()=>{let l=await c.getItem(`${e?._id}-timers`);l||(await c.setItem(`${e?._id}-timers`,{}),l={});let T=parseInt(l?.[e?._id]||e?.timeTaken?.[e?._id]||e?.duration||0);n(T)};return V.useEffect(()=>(m(),()=>{o.current&&clearTimeout(o.current)}),[]),{timer:i}},Te=de;import h from"react";var me=r=>{let e=r==="app"?950:1e3,{currentQuestion:t,solutions:o,test:i}=D(),{isQuizAnswer:u}=L(),n=h.useRef(null),[m,l]=h.useState(0),T=async I=>{if(!t)return;let s=await c.getItem(`${i?._id}-timers`);if((o[t?._id]?.markedSolution||[])?.length===0)s[t?._id]=I+"",c.setItem(`${i?._id}-timers`,s),l(I);else{clearTimeout(n.current);return}n.current=setTimeout(()=>{T(I+1)},e)},d=async()=>{n.current&&(clearTimeout(n.current),n.current=null);let I=await c.getItem(`${i?._id}-timers`);I||(await c.setItem(`${i?._id}-timers`,{}),I={});let s=parseInt(I?.[t?._id]||i?.timeTaken?.[t?._id]||0);l(s),T(s)};return h.useEffect(()=>(t?._id&&d(),()=>{n.current&&(clearTimeout(n.current),n.current=null)}),[t]),h.useEffect(()=>{n.current===null&&setTimeout(()=>{n.current===null&&d()},e)},[o]),h.useEffect(()=>{u&&(clearTimeout(n.current),n.current=null)},[u]),{questionStopWatch:m}},Se=me;export{w as AttemptStatus,H as TestEngineProvider,Se as useQuestionStopWatch,D as useTestEngine,L as useTestEngineBody,ae as useTestEngineFooter,Q as useTestQuestionStatus,le as useTestSolutionBody,Te as useTestTimer};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "testforce-engine",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup",
|
|
10
|
+
"prepare": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@babel/runtime": "^7.26.9",
|
|
17
|
+
"@react-native-async-storage/async-storage": "^2.1.1"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/react": "^19.0.8",
|
|
21
|
+
"tsup": "^8.3.6",
|
|
22
|
+
"typescript": "^5.7.3"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=18",
|
|
26
|
+
"react-native": ">=0.72"
|
|
27
|
+
}
|
|
28
|
+
}
|