@harshshahcg/survey-render 1.2.0 → 1.3.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/components/SurveyRenderer.d.ts +12 -5
- package/dist/converters/detectFormat.d.ts +20 -0
- package/dist/converters/fmbToPlcOutput.d.ts +13 -0
- package/dist/converters/index.d.ts +9 -0
- package/dist/converters/plcToFmbInput.d.ts +11 -0
- package/dist/converters/types.d.ts +57 -0
- package/dist/index.d.ts +3 -1
- package/dist/surveyRender.js +2046 -1902
- package/dist/surveyRender.js.map +1 -1
- package/dist/surveyRender.umd.cjs +22 -22
- package/dist/surveyRender.umd.cjs.map +1 -1
- package/dist/types/survey.types.d.ts +2 -0
- package/dist/utils/questionStatus.d.ts +5 -0
- package/package.json +6 -3
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { SurveyConfig, SurveySubmitPayload } from "../types/survey.types";
|
|
2
|
+
import type { PLCSurveyConfig } from "../converters/types";
|
|
2
3
|
import type { SurveyProgressBarConfig } from "./SurveyContainer";
|
|
4
|
+
/** Survey input: FMB (internal format) or PLC (converted to FMB at runtime). */
|
|
5
|
+
export type SurveyInputData = SurveyConfig | PLCSurveyConfig;
|
|
6
|
+
/** Payload passed to onSubmit/onSave: FMB or PLC depending on input data type. */
|
|
7
|
+
export type SurveySubmitPayloadUnion = SurveySubmitPayload | import("../converters/types").PLCSubmitPayload;
|
|
3
8
|
export interface SurveyRendererProps {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
/** Survey config in FMB or PLC format. PLC is auto-converted to FMB internally. */
|
|
10
|
+
data: SurveyInputData;
|
|
11
|
+
/** Called with submit payload in same format as input (FMB or PLC). */
|
|
12
|
+
onSubmit: (payload: SurveySubmitPayloadUnion) => void;
|
|
13
|
+
/** Called with draft payload in same format as input (FMB or PLC). */
|
|
14
|
+
onSave?: (payload: SurveySubmitPayloadUnion) => void;
|
|
7
15
|
onExit?: () => void;
|
|
8
16
|
isSubmitting?: boolean;
|
|
9
17
|
className?: string;
|
|
@@ -15,7 +23,6 @@ export interface SurveyRendererProps {
|
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
25
|
* Main entry component. Renders a full survey from JSON config.
|
|
18
|
-
* Supports
|
|
19
|
-
* Wrap your app root (or survey container) with data-theme for styling.
|
|
26
|
+
* Supports FMB and PLC formats; PLC is converted to FMB internally. Output format matches input.
|
|
20
27
|
*/
|
|
21
28
|
export declare function SurveyRenderer({ data, onSubmit, onSave, onExit, isSubmitting, className, showHeader, theme, progressBar, }: SurveyRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect survey format from input data.
|
|
3
|
+
* Uses type field when present; otherwise infers from structure.
|
|
4
|
+
*/
|
|
5
|
+
import type { SurveyConfig } from "../types/survey.types";
|
|
6
|
+
import type { PLCSurveyConfig, SurveyType } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Detects whether the survey data is PLC or FMB format.
|
|
9
|
+
* @param data - Survey input (must have type and questionList)
|
|
10
|
+
* @returns "PLC" | "FMB"
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectSurveyFormat(data: unknown): SurveyType;
|
|
13
|
+
/**
|
|
14
|
+
* Type guard: data is valid PLC survey config (after format detection).
|
|
15
|
+
*/
|
|
16
|
+
export declare function isPLCData(data: unknown): data is PLCSurveyConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Type guard: data is FMB survey config.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isFMBData(data: unknown): data is SurveyConfig;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert FMB submit payload back to PLC format.
|
|
3
|
+
* Used when the survey was initialized with PLC data so output matches input format.
|
|
4
|
+
* Each response item includes question text, correct_answer, selected_answer (option letters), and correct_answer_option.
|
|
5
|
+
*/
|
|
6
|
+
import type { SurveySubmitPayload } from "../types/survey.types";
|
|
7
|
+
import type { PLCSurveyConfig, PLCSubmitPayload } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Convert FMB submit payload to PLC format.
|
|
10
|
+
* @param fmbPayload - Payload in FMB format (from formatResponses / submit)
|
|
11
|
+
* @param originalPlcSurvey - The PLC config that was converted to FMB at init
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertFMBToPLC(fmbPayload: SurveySubmitPayload, originalPlcSurvey: PLCSurveyConfig): PLCSubmitPayload;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format utilities: detect format, convert PLC ↔ FMB.
|
|
3
|
+
* Library always works internally with FMB; conversion is at boundary.
|
|
4
|
+
*/
|
|
5
|
+
export { detectSurveyFormat, isPLCData, isFMBData, } from "./detectFormat";
|
|
6
|
+
export { convertPLCToFMB } from "./plcToFmbInput";
|
|
7
|
+
export { convertFMBToPLC } from "./fmbToPlcOutput";
|
|
8
|
+
export type { SurveyType, BaseSurveyInput, PLCQuestion, PLCSurveyConfig, PLCResponseItem, PLCSubmitPayload, SurveySubmitPayloadUnion, } from "./types";
|
|
9
|
+
export { isPLCSurvey, isFMBSurvey } from "./types";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert PLC survey config to FMB (SurveyConfig).
|
|
3
|
+
* Library always works internally with FMB.
|
|
4
|
+
*/
|
|
5
|
+
import type { SurveyConfig } from "../types/survey.types";
|
|
6
|
+
import type { PLCSurveyConfig } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Convert PLC survey config to FMB SurveyConfig.
|
|
9
|
+
* Use the result for all internal rendering and state.
|
|
10
|
+
*/
|
|
11
|
+
export declare function convertPLCToFMB(plcData: PLCSurveyConfig): SurveyConfig;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for survey format detection and conversion.
|
|
3
|
+
* Library always works internally with FMB; PLC is converted at input and output.
|
|
4
|
+
*/
|
|
5
|
+
import type { SurveyConfig, SurveySubmitPayload } from "../types/survey.types";
|
|
6
|
+
export type SurveyType = "FMB" | "PLC";
|
|
7
|
+
export interface BaseSurveyInput {
|
|
8
|
+
type: SurveyType;
|
|
9
|
+
surveyId: string;
|
|
10
|
+
surveyCode?: string;
|
|
11
|
+
surveyName?: string;
|
|
12
|
+
medium: string;
|
|
13
|
+
config?: Record<string, unknown>;
|
|
14
|
+
questionList: unknown[];
|
|
15
|
+
}
|
|
16
|
+
/** PLC question structure (input format). */
|
|
17
|
+
export interface PLCQuestion {
|
|
18
|
+
image: string;
|
|
19
|
+
question: string;
|
|
20
|
+
question_type: "scq" | "mcq";
|
|
21
|
+
options: string[];
|
|
22
|
+
correct_answer: string[];
|
|
23
|
+
correct_answer_option: string[];
|
|
24
|
+
question_number: number;
|
|
25
|
+
isMandatory: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** PLC survey config (input format). */
|
|
28
|
+
export interface PLCSurveyConfig extends BaseSurveyInput {
|
|
29
|
+
type: "PLC";
|
|
30
|
+
questionList: PLCQuestion[];
|
|
31
|
+
}
|
|
32
|
+
/** Type guard: input has type field "PLC". */
|
|
33
|
+
export declare function isPLCSurvey(data: BaseSurveyInput): data is PLCSurveyConfig;
|
|
34
|
+
/** Type guard: input has type field "FMB". */
|
|
35
|
+
export declare function isFMBSurvey(data: BaseSurveyInput | {
|
|
36
|
+
type?: string;
|
|
37
|
+
}): data is SurveyConfig;
|
|
38
|
+
/** PLC response item: full question and answer info for each question. */
|
|
39
|
+
export interface PLCResponseItem {
|
|
40
|
+
question_number: number;
|
|
41
|
+
question: string;
|
|
42
|
+
correct_answer: string[];
|
|
43
|
+
selected_answer: string[];
|
|
44
|
+
correct_answer_option: string[];
|
|
45
|
+
}
|
|
46
|
+
/** Payload returned on submit/save when input was PLC. */
|
|
47
|
+
export interface PLCSubmitPayload {
|
|
48
|
+
type: "PLC";
|
|
49
|
+
surveyId: string;
|
|
50
|
+
surveyCode?: string;
|
|
51
|
+
surveyName?: string;
|
|
52
|
+
medium: string;
|
|
53
|
+
config?: Record<string, unknown>;
|
|
54
|
+
responses: PLCResponseItem[];
|
|
55
|
+
}
|
|
56
|
+
/** Union: submit/save callback receives FMB or PLC payload depending on input format. */
|
|
57
|
+
export type SurveySubmitPayloadUnion = SurveySubmitPayload | PLCSubmitPayload;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,10 +28,12 @@ export { validateResponses, canSubmit, } from "./utils/validation";
|
|
|
28
28
|
export type { ValidationErrorItem } from "./utils/validation";
|
|
29
29
|
export { formatResponses } from "./utils/responseFormatter";
|
|
30
30
|
export type { InternalResponses } from "./utils/responseFormatter";
|
|
31
|
-
export { getQuestionStatusMap } from "./utils/questionStatus";
|
|
31
|
+
export { getQuestionStatusMap, getQuestionStatus } from "./utils/questionStatus";
|
|
32
32
|
export type { QuestionStatus } from "./utils/questionStatus";
|
|
33
33
|
export { validateFile, validateFileType, validateFileSize, fileToFileObject, isValueFileObject, getEffectiveMediaConfig, MEDIA_ALLOWED_TYPES, MEDIA_MAX_SIZE_MB, } from "./utils/fileUtils";
|
|
34
34
|
export type { FileValidationResult, EffectiveMediaConfig } from "./utils/fileUtils";
|
|
35
35
|
export { DEFAULT_MEDIA_ALLOWED_TYPES, DEFAULT_MEDIA_MAX_SIZE_MB, } from "./helpers/constants";
|
|
36
36
|
export { getStatusClass, getStatusColor, getStatusIconClass } from "./utils/themeStatusStyles";
|
|
37
37
|
export { calculateWeightedProgress, type ProgressMetrics, } from "./utils/progressCalculation";
|
|
38
|
+
export { detectSurveyFormat, isPLCData, isFMBData, convertPLCToFMB, convertFMBToPLC, isPLCSurvey, isFMBSurvey, } from "./converters";
|
|
39
|
+
export type { SurveyType, PLCQuestion, PLCSurveyConfig, PLCResponseItem, PLCSubmitPayload, SurveySubmitPayloadUnion, } from "./converters";
|