@edpire/sdk 0.5.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.
@@ -0,0 +1,200 @@
1
+ import React from 'react';
2
+ import { RuntimeAnswer, AssessmentContent, AssessmentAnswers, QuestionRuntimeProps } from '@youssefalmia/edpire-runtime';
3
+ export { RuntimeAnswer } from '@youssefalmia/edpire-runtime';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import { RichContent } from '@youssefalmia/edpire-schema/authoring';
6
+
7
+ /**
8
+ * EdpireQuestion — public React component for rendering a single question.
9
+ *
10
+ * Wraps QuestionRuntime from @youssefalmia/edpire-runtime behind a stable
11
+ * public API. Consumers never import the internal runtime package directly.
12
+ *
13
+ * Key conveniences over using QuestionRuntime directly:
14
+ * - `feedback` accepts a plain JSON object (from POST /check) and converts
15
+ * it to the Map<nodeId, ValidationFeedback> that QuestionRuntime expects.
16
+ * - `dir` wraps the question in a container with the correct text direction.
17
+ * - CSS for feedback states is bundled and injected automatically.
18
+ */
19
+
20
+ interface EdpireQuestionProps {
21
+ /**
22
+ * The question's ContentAST — the `content_ast` field from
23
+ * GET /api/v1/assessments/{id} → exercises[n].questions[n].
24
+ */
25
+ content: unknown;
26
+ /**
27
+ * Called on every answer change. Receives the current array of RuntimeAnswers.
28
+ * Collect these and pass them to POST /check or your submit endpoint.
29
+ */
30
+ onAnswersChange?: (answers: RuntimeAnswer[]) => void;
31
+ /**
32
+ * Feedback from POST /api/v1/assessments/{id}/check.
33
+ * Pass the `feedback` field from the response directly — no conversion needed.
34
+ * The component converts the plain object to the Map expected by QuestionRuntime.
35
+ *
36
+ * Set to null/undefined to clear feedback (e.g. when moving to the next question).
37
+ */
38
+ feedback?: Record<string, unknown> | null;
39
+ /**
40
+ * Pre-fill answers — useful for restoring state when navigating back.
41
+ */
42
+ initialAnswers?: RuntimeAnswer[];
43
+ /**
44
+ * CSS class added to the question root div.
45
+ */
46
+ className?: string;
47
+ /**
48
+ * Text direction. Wrap in an rtl container for Arabic content.
49
+ * Defaults to "ltr".
50
+ */
51
+ dir?: "ltr" | "rtl";
52
+ }
53
+ declare const EdpireQuestion: React.NamedExoticComponent<EdpireQuestionProps>;
54
+
55
+ type SpinnerTheme = "default" | "dots" | "pulse" | "bars";
56
+ interface GradingOverlayProps {
57
+ visible: boolean;
58
+ bgColor?: string;
59
+ accentColor?: string;
60
+ text?: string;
61
+ aiText?: string;
62
+ spinnerTheme?: SpinnerTheme;
63
+ animationUrl?: string;
64
+ hasAiNodes?: boolean;
65
+ contained?: boolean;
66
+ }
67
+ type OverlayConfig = Pick<GradingOverlayProps, "bgColor" | "accentColor" | "text" | "spinnerTheme" | "animationUrl">;
68
+
69
+ /**
70
+ * Standalone, dependency-free i18n for the SDK shell.
71
+ *
72
+ * Replaces the web app's `useTranslations("learner.taking")` so the shell can
73
+ * be rendered in any React environment (Vite, CRA, Astro, UMD CDN, mobile
74
+ * WebView). Locale is passed as a prop — there is no React context to set up.
75
+ *
76
+ * Strings mirror `packages/i18n/messages/{en,fr,ar}.json` under `learner.taking.*`.
77
+ * Keep in sync if those copies are edited.
78
+ */
79
+ type ShellLocale = "en" | "fr" | "ar";
80
+
81
+ /**
82
+ * Public types for the polished Assessment Shell.
83
+ *
84
+ * The shell renders the same UI used at edpire.com's hosted player.
85
+ * Consumers using the EdpireAssessment.mount() API get these types
86
+ * indirectly via MountOptions; consumers rendering <AssessmentShell>
87
+ * directly import them from "@edpire/sdk/react".
88
+ */
89
+
90
+ /** Branding payload accepted by AssessmentShell. Mirrors what edpire.com sends. */
91
+ interface TakeBranding {
92
+ /** Org display name — shown as the alt text on the logo. */
93
+ name: string;
94
+ /** Logo URL (any https URL). When absent, the Edpire logo is shown. */
95
+ logoUrl: string | null;
96
+ branding: {
97
+ /** CSS color for the primary action buttons (Submit, View Report, etc.). */
98
+ primaryColor?: string;
99
+ /** CSS color used as the background of the top bar and per-exercise headers. */
100
+ accentColor?: string;
101
+ /** font-family applied to the shell. Pair with `fontUrl` for non-system fonts. */
102
+ fontFamily?: string;
103
+ /** A Google Fonts stylesheet URL; the shell injects a <link> tag at mount. */
104
+ fontUrl?: string;
105
+ /** When false, the "Powered by Edpire" watermark is hidden. Default true. */
106
+ showPoweredBy?: boolean;
107
+ } | null;
108
+ }
109
+ type NodeDetail = {
110
+ type: "choiceSet";
111
+ correctChoiceIds: string[];
112
+ } | {
113
+ type: "matchingSet";
114
+ pairFeedback: Array<{
115
+ leftId: string;
116
+ rightId: string;
117
+ correct: boolean;
118
+ }>;
119
+ correctPairings: Array<{
120
+ leftId: string;
121
+ rightId: string;
122
+ }>;
123
+ };
124
+ interface NodeFeedback {
125
+ nodeId: string;
126
+ status: "correct" | "partial" | "incorrect" | "awaiting_review";
127
+ score: number;
128
+ maxScore: number;
129
+ feedback?: string;
130
+ displayAnswer?: string;
131
+ detail?: NodeDetail;
132
+ teacherFeedback?: RichContent[];
133
+ }
134
+ interface QuestionFeedback {
135
+ questionId: string;
136
+ nodeResults: NodeFeedback[];
137
+ }
138
+ interface ExerciseFeedbackData {
139
+ exerciseId: string;
140
+ questions: QuestionFeedback[];
141
+ }
142
+ interface SubmitResult {
143
+ submissionId: string;
144
+ totalScore: number;
145
+ maxScore: number;
146
+ percentage: number;
147
+ passed: boolean;
148
+ /** If null/undefined, the shell hides the "View Full Report" button. */
149
+ returnUrl?: string | null;
150
+ exerciseFeedback: ExerciseFeedbackData[];
151
+ /** When true, score banners hide the score (still being reviewed). */
152
+ awaitingManualGrading?: boolean;
153
+ }
154
+
155
+ interface AssessmentShellProps {
156
+ assessment: AssessmentContent;
157
+ meta: {
158
+ title: string;
159
+ category: string | null;
160
+ };
161
+ /** Locale for shell strings. Default "en". */
162
+ locale?: ShellLocale;
163
+ branding?: TakeBranding;
164
+ /** Time limit in minutes — shows a countdown chip and auto-submits at 0:00. */
165
+ timeLimitMinutes?: number | null;
166
+ /** ISO timestamp of attempt start — anchors the countdown server-side. */
167
+ startedAt?: string;
168
+ /** Called when the learner submits. Should throw on error. */
169
+ onSubmit: (answers: AssessmentAnswers) => Promise<SubmitResult>;
170
+ /** Called when the learner clicks "View Full Report". Omit to hide the button. */
171
+ onViewReport?: (result: SubmitResult) => void;
172
+ /** Custom label for the post-submit redirect button (overrides default). */
173
+ reportLabel?: string;
174
+ /** Called when the learner clicks the back button (shown only BEFORE submission). */
175
+ onBack?: () => void;
176
+ /** Custom label for the back button (default: localized "Back"). */
177
+ backLabel?: string;
178
+ /** Show a Reset button in the top bar. */
179
+ allowReset?: boolean;
180
+ onReset?: () => void;
181
+ /** Show a close (✕) button in the top bar. */
182
+ onClose?: () => void;
183
+ /** Extra customisation for the grading overlay (branded spinner, etc.). */
184
+ overlayConfig?: OverlayConfig;
185
+ /** Scope grading/time-up overlays to this component instead of the viewport. */
186
+ contained?: boolean;
187
+ /** Media upload handler — required for file-upload and recording modes in
188
+ * OpenResponse questions. */
189
+ mediaHandler?: QuestionRuntimeProps["mediaHandler"];
190
+ /**
191
+ * Logo shown when the org has no `branding.logoUrl`.
192
+ * Defaults to an inline Edpire SVG so the SDK has zero asset dependencies.
193
+ * In edpire.com itself, pass "/edpire_logo_blue.png" to preserve the original
194
+ * Next.js-served asset.
195
+ */
196
+ fallbackLogoUrl?: string;
197
+ }
198
+ declare function AssessmentShell({ assessment, meta, locale, branding, timeLimitMinutes, startedAt, onSubmit, onViewReport, reportLabel, onBack, backLabel, allowReset, onReset, overlayConfig, contained, onClose, mediaHandler, fallbackLogoUrl, }: AssessmentShellProps): react_jsx_runtime.JSX.Element;
199
+
200
+ export { AssessmentShell, type AssessmentShellProps, EdpireQuestion, type EdpireQuestionProps, type ExerciseFeedbackData, type NodeDetail, type NodeFeedback, type OverlayConfig, type QuestionFeedback, type ShellLocale, type SpinnerTheme, type SubmitResult, type TakeBranding };