@contractspec/example.learning-journey-ui-shared 1.44.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.
Files changed (60) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +48 -0
  2. package/.turbo/turbo-build.log +49 -0
  3. package/CHANGELOG.md +211 -0
  4. package/LICENSE +21 -0
  5. package/README.md +42 -0
  6. package/dist/components/BadgeDisplay.d.ts +12 -0
  7. package/dist/components/BadgeDisplay.d.ts.map +1 -0
  8. package/dist/components/BadgeDisplay.js +45 -0
  9. package/dist/components/BadgeDisplay.js.map +1 -0
  10. package/dist/components/StreakCounter.d.ts +12 -0
  11. package/dist/components/StreakCounter.d.ts.map +1 -0
  12. package/dist/components/StreakCounter.js +46 -0
  13. package/dist/components/StreakCounter.js.map +1 -0
  14. package/dist/components/ViewTabs.d.ts +12 -0
  15. package/dist/components/ViewTabs.d.ts.map +1 -0
  16. package/dist/components/ViewTabs.js +49 -0
  17. package/dist/components/ViewTabs.js.map +1 -0
  18. package/dist/components/XpBar.d.ts +14 -0
  19. package/dist/components/XpBar.d.ts.map +1 -0
  20. package/dist/components/XpBar.js +47 -0
  21. package/dist/components/XpBar.js.map +1 -0
  22. package/dist/components/index.d.ts +5 -0
  23. package/dist/components/index.js +6 -0
  24. package/dist/docs/index.d.ts +1 -0
  25. package/dist/docs/index.js +1 -0
  26. package/dist/docs/learning-journey-ui-shared.docblock.d.ts +1 -0
  27. package/dist/docs/learning-journey-ui-shared.docblock.js +20 -0
  28. package/dist/docs/learning-journey-ui-shared.docblock.js.map +1 -0
  29. package/dist/example.d.ts +33 -0
  30. package/dist/example.d.ts.map +1 -0
  31. package/dist/example.js +35 -0
  32. package/dist/example.js.map +1 -0
  33. package/dist/hooks/index.d.ts +2 -0
  34. package/dist/hooks/index.js +3 -0
  35. package/dist/hooks/useLearningProgress.d.ts +22 -0
  36. package/dist/hooks/useLearningProgress.d.ts.map +1 -0
  37. package/dist/hooks/useLearningProgress.js +74 -0
  38. package/dist/hooks/useLearningProgress.js.map +1 -0
  39. package/dist/index.d.ts +9 -0
  40. package/dist/index.js +11 -0
  41. package/dist/types.d.ts +58 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +0 -0
  44. package/example.ts +1 -0
  45. package/package.json +75 -0
  46. package/src/components/BadgeDisplay.tsx +65 -0
  47. package/src/components/StreakCounter.tsx +49 -0
  48. package/src/components/ViewTabs.tsx +46 -0
  49. package/src/components/XpBar.tsx +54 -0
  50. package/src/components/index.ts +4 -0
  51. package/src/docs/index.ts +1 -0
  52. package/src/docs/learning-journey-ui-shared.docblock.ts +17 -0
  53. package/src/example.ts +23 -0
  54. package/src/hooks/index.ts +1 -0
  55. package/src/hooks/useLearningProgress.ts +101 -0
  56. package/src/index.ts +20 -0
  57. package/src/types.ts +61 -0
  58. package/tsconfig.json +9 -0
  59. package/tsconfig.tsbuildinfo +1 -0
  60. package/tsdown.config.js +17 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XpBar.js","names":[],"sources":["../../src/components/XpBar.tsx"],"sourcesContent":["'use client';\n\nimport { Progress } from '@contractspec/lib.ui-kit-web/ui/progress';\nimport { cn } from '@contractspec/lib.ui-kit-web/ui/utils';\nimport type { XpBarProps } from '../types';\n\nconst sizeStyles = {\n sm: 'h-2',\n md: 'h-3',\n lg: 'h-4',\n};\n\nconst labelSizeStyles = {\n sm: 'text-xs',\n md: 'text-sm',\n lg: 'text-base',\n};\n\nexport function XpBar({\n current,\n max,\n level,\n showLabel = true,\n size = 'md',\n}: XpBarProps) {\n const percentage = max > 0 ? Math.min((current / max) * 100, 100) : 0;\n\n return (\n <div className=\"w-full space-y-1\">\n {showLabel && (\n <div\n className={cn(\n 'flex items-center justify-between',\n labelSizeStyles[size]\n )}\n >\n <span className=\"text-muted-foreground font-medium\">\n {level !== undefined && (\n <span className=\"text-primary mr-1\">Lvl {level}</span>\n )}\n XP\n </span>\n <span className=\"font-semibold\">\n {current.toLocaleString()} / {max.toLocaleString()}\n </span>\n </div>\n )}\n <Progress\n value={percentage}\n className={cn('bg-muted', sizeStyles[size])}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;AAMA,MAAM,aAAa;CACjB,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;AAED,MAAM,kBAAkB;CACtB,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;AAED,SAAgB,MAAM,EACpB,SACA,KACA,OACA,YAAY,MACZ,OAAO,QACM;CACb,MAAM,aAAa,MAAM,IAAI,KAAK,IAAK,UAAU,MAAO,KAAK,IAAI,GAAG;AAEpE,QACE,qBAAC;EAAI,WAAU;aACZ,aACC,qBAAC;GACC,WAAW,GACT,qCACA,gBAAgB,MACjB;cAED,qBAAC;IAAK,WAAU;eACb,UAAU,UACT,qBAAC;KAAK,WAAU;gBAAoB,QAAK;MAAa,EACtD;KAEG,EACP,qBAAC;IAAK,WAAU;;KACb,QAAQ,gBAAgB;KAAC;KAAI,IAAI,gBAAgB;;KAC7C;IACH,EAER,oBAAC;GACC,OAAO;GACP,WAAW,GAAG,YAAY,WAAW,MAAM;IAC3C;GACE"}
@@ -0,0 +1,5 @@
1
+ import { BadgeDisplay } from "./BadgeDisplay.js";
2
+ import { StreakCounter } from "./StreakCounter.js";
3
+ import { ViewTabs } from "./ViewTabs.js";
4
+ import { XpBar } from "./XpBar.js";
5
+ export { BadgeDisplay, StreakCounter, ViewTabs, XpBar };
@@ -0,0 +1,6 @@
1
+ import { XpBar } from "./XpBar.js";
2
+ import { StreakCounter } from "./StreakCounter.js";
3
+ import { BadgeDisplay } from "./BadgeDisplay.js";
4
+ import { ViewTabs } from "./ViewTabs.js";
5
+
6
+ export { BadgeDisplay, StreakCounter, ViewTabs, XpBar };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ import "./learning-journey-ui-shared.docblock.js";
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,20 @@
1
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
2
+
3
+ //#region src/docs/learning-journey-ui-shared.docblock.ts
4
+ registerDocBlocks([{
5
+ id: "docs.examples.learning-journey-ui-shared",
6
+ title: "Learning Journey UI — Shared",
7
+ summary: "Shared UI components and hooks for learning journey mini-apps.",
8
+ kind: "reference",
9
+ visibility: "public",
10
+ route: "/docs/examples/learning-journey-ui-shared",
11
+ tags: [
12
+ "learning",
13
+ "ui",
14
+ "shared"
15
+ ],
16
+ body: `## Includes\n- Hooks: useLearningProgress\n- Components: XpBar, StreakCounter, BadgeDisplay, ViewTabs\n\n## Notes\n- Keep components accessible (labels, focus, contrast).\n- Prefer design-system tokens and components.`
17
+ }]);
18
+
19
+ //#endregion
20
+ //# sourceMappingURL=learning-journey-ui-shared.docblock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning-journey-ui-shared.docblock.js","names":[],"sources":["../../src/docs/learning-journey-ui-shared.docblock.ts"],"sourcesContent":["import type { DocBlock } from '@contractspec/lib.contracts/docs';\nimport { registerDocBlocks } from '@contractspec/lib.contracts/docs';\n\nconst blocks: DocBlock[] = [\n {\n id: 'docs.examples.learning-journey-ui-shared',\n title: 'Learning Journey UI — Shared',\n summary: 'Shared UI components and hooks for learning journey mini-apps.',\n kind: 'reference',\n visibility: 'public',\n route: '/docs/examples/learning-journey-ui-shared',\n tags: ['learning', 'ui', 'shared'],\n body: `## Includes\\n- Hooks: useLearningProgress\\n- Components: XpBar, StreakCounter, BadgeDisplay, ViewTabs\\n\\n## Notes\\n- Keep components accessible (labels, focus, contrast).\\n- Prefer design-system tokens and components.`,\n },\n];\n\nregisterDocBlocks(blocks);\n"],"mappings":";;;AAgBA,kBAb2B,CACzB;CACE,IAAI;CACJ,OAAO;CACP,SAAS;CACT,MAAM;CACN,YAAY;CACZ,OAAO;CACP,MAAM;EAAC;EAAY;EAAM;EAAS;CAClC,MAAM;CACP,CACF,CAEwB"}
@@ -0,0 +1,33 @@
1
+ //#region src/example.d.ts
2
+ declare const example: {
3
+ readonly id: "learning-journey-ui-shared";
4
+ readonly title: "Learning Journey UI — Shared";
5
+ readonly summary: "Shared UI components and hooks for learning journey mini-apps.";
6
+ readonly tags: readonly ["learning", "ui", "shared"];
7
+ readonly kind: "ui";
8
+ readonly visibility: "public";
9
+ readonly docs: {
10
+ readonly rootDocId: "docs.examples.learning-journey-ui-shared";
11
+ };
12
+ readonly entrypoints: {
13
+ readonly packageName: "@contractspec/example.learning-journey-ui-shared";
14
+ readonly docs: "./docs";
15
+ };
16
+ readonly surfaces: {
17
+ readonly templates: true;
18
+ readonly sandbox: {
19
+ readonly enabled: true;
20
+ readonly modes: readonly ["playground", "markdown"];
21
+ };
22
+ readonly studio: {
23
+ readonly enabled: true;
24
+ readonly installable: true;
25
+ };
26
+ readonly mcp: {
27
+ readonly enabled: true;
28
+ };
29
+ };
30
+ };
31
+ //#endregion
32
+ export { example as default };
33
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","names":[],"sources":["../src/example.ts"],"sourcesContent":[],"mappings":";cAAM;EAAA,SAAA,EAoBI,EAAA,4BAAA"}
@@ -0,0 +1,35 @@
1
+ //#region src/example.ts
2
+ const example = {
3
+ id: "learning-journey-ui-shared",
4
+ title: "Learning Journey UI — Shared",
5
+ summary: "Shared UI components and hooks for learning journey mini-apps.",
6
+ tags: [
7
+ "learning",
8
+ "ui",
9
+ "shared"
10
+ ],
11
+ kind: "ui",
12
+ visibility: "public",
13
+ docs: { rootDocId: "docs.examples.learning-journey-ui-shared" },
14
+ entrypoints: {
15
+ packageName: "@contractspec/example.learning-journey-ui-shared",
16
+ docs: "./docs"
17
+ },
18
+ surfaces: {
19
+ templates: true,
20
+ sandbox: {
21
+ enabled: true,
22
+ modes: ["playground", "markdown"]
23
+ },
24
+ studio: {
25
+ enabled: true,
26
+ installable: true
27
+ },
28
+ mcp: { enabled: true }
29
+ }
30
+ };
31
+ var example_default = example;
32
+
33
+ //#endregion
34
+ export { example_default as default };
35
+ //# sourceMappingURL=example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.js","names":[],"sources":["../src/example.ts"],"sourcesContent":["const example = {\n id: 'learning-journey-ui-shared',\n title: 'Learning Journey UI — Shared',\n summary: 'Shared UI components and hooks for learning journey mini-apps.',\n tags: ['learning', 'ui', 'shared'],\n kind: 'ui',\n visibility: 'public',\n docs: {\n rootDocId: 'docs.examples.learning-journey-ui-shared',\n },\n entrypoints: {\n packageName: '@contractspec/example.learning-journey-ui-shared',\n docs: './docs',\n },\n surfaces: {\n templates: true,\n sandbox: { enabled: true, modes: ['playground', 'markdown'] },\n studio: { enabled: true, installable: true },\n mcp: { enabled: true },\n },\n} as const;\n\nexport default example;\n"],"mappings":";AAAA,MAAM,UAAU;CACd,IAAI;CACJ,OAAO;CACP,SAAS;CACT,MAAM;EAAC;EAAY;EAAM;EAAS;CAClC,MAAM;CACN,YAAY;CACZ,MAAM,EACJ,WAAW,4CACZ;CACD,aAAa;EACX,aAAa;EACb,MAAM;EACP;CACD,UAAU;EACR,WAAW;EACX,SAAS;GAAE,SAAS;GAAM,OAAO,CAAC,cAAc,WAAW;GAAE;EAC7D,QAAQ;GAAE,SAAS;GAAM,aAAa;GAAM;EAC5C,KAAK,EAAE,SAAS,MAAM;EACvB;CACF;AAED,sBAAe"}
@@ -0,0 +1,2 @@
1
+ import { useLearningProgress } from "./useLearningProgress.js";
2
+ export { useLearningProgress };
@@ -0,0 +1,3 @@
1
+ import { useLearningProgress } from "./useLearningProgress.js";
2
+
3
+ export { useLearningProgress };
@@ -0,0 +1,22 @@
1
+ import { LearningProgressState } from "../types.js";
2
+ import { LearningJourneyTrackSpec } from "@contractspec/module.learning-journey/track-spec";
3
+
4
+ //#region src/hooks/useLearningProgress.d.ts
5
+ /** Hook for managing learning progress state */
6
+ declare function useLearningProgress(track: LearningJourneyTrackSpec): {
7
+ progress: LearningProgressState;
8
+ stats: {
9
+ totalSteps: number;
10
+ completedSteps: number;
11
+ remainingSteps: number;
12
+ percentComplete: number;
13
+ totalXp: number;
14
+ isComplete: boolean;
15
+ };
16
+ completeStep: (stepId: string) => void;
17
+ resetProgress: () => void;
18
+ incrementStreak: () => void;
19
+ };
20
+ //#endregion
21
+ export { useLearningProgress };
22
+ //# sourceMappingURL=useLearningProgress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLearningProgress.d.ts","names":[],"sources":["../../src/hooks/useLearningProgress.ts"],"sourcesContent":[],"mappings":";;;;;iBAoBgB,mBAAA,QAA2B;EAA3B,QAAA,EAA2B,qBAAR"}
@@ -0,0 +1,74 @@
1
+ 'use client';
2
+
3
+ import { useCallback, useMemo, useState } from "react";
4
+
5
+ //#region src/hooks/useLearningProgress.ts
6
+ /** Default progress state for a new track */
7
+ function createDefaultProgress(trackId) {
8
+ return {
9
+ trackId,
10
+ completedStepIds: [],
11
+ currentStepId: null,
12
+ xpEarned: 0,
13
+ streakDays: 0,
14
+ lastActivityDate: null,
15
+ badges: []
16
+ };
17
+ }
18
+ /** Hook for managing learning progress state */
19
+ function useLearningProgress(track) {
20
+ const [progress, setProgress] = useState(() => createDefaultProgress(track.id));
21
+ const completeStep = useCallback((stepId) => {
22
+ const step = track.steps.find((s) => s.id === stepId);
23
+ if (!step || progress.completedStepIds.includes(stepId)) return;
24
+ setProgress((prev) => {
25
+ const newCompletedIds = [...prev.completedStepIds, stepId];
26
+ const xpReward = step.xpReward ?? 0;
27
+ const nextStep = track.steps.find((s) => !newCompletedIds.includes(s.id));
28
+ const isTrackComplete = newCompletedIds.length === track.steps.length;
29
+ const completionBonus = isTrackComplete ? track.completionRewards?.xpBonus ?? 0 : 0;
30
+ return {
31
+ ...prev,
32
+ completedStepIds: newCompletedIds,
33
+ currentStepId: nextStep?.id ?? null,
34
+ xpEarned: prev.xpEarned + xpReward + completionBonus,
35
+ lastActivityDate: (/* @__PURE__ */ new Date()).toISOString(),
36
+ badges: isTrackComplete && track.completionRewards?.badgeKey ? [...prev.badges, track.completionRewards.badgeKey] : prev.badges
37
+ };
38
+ });
39
+ }, [track, progress.completedStepIds]);
40
+ const resetProgress = useCallback(() => {
41
+ setProgress(createDefaultProgress(track.id));
42
+ }, [track.id]);
43
+ const incrementStreak = useCallback(() => {
44
+ setProgress((prev) => ({
45
+ ...prev,
46
+ streakDays: prev.streakDays + 1,
47
+ lastActivityDate: (/* @__PURE__ */ new Date()).toISOString()
48
+ }));
49
+ }, []);
50
+ return {
51
+ progress,
52
+ stats: useMemo(() => {
53
+ const totalSteps = track.steps.length;
54
+ const completedSteps = progress.completedStepIds.length;
55
+ const percentComplete = totalSteps > 0 ? Math.round(completedSteps / totalSteps * 100) : 0;
56
+ const totalXp = track.totalXp ?? track.steps.reduce((sum, s) => sum + (s.xpReward ?? 0), 0) + (track.completionRewards?.xpBonus ?? 0);
57
+ return {
58
+ totalSteps,
59
+ completedSteps,
60
+ remainingSteps: totalSteps - completedSteps,
61
+ percentComplete,
62
+ totalXp,
63
+ isComplete: completedSteps === totalSteps
64
+ };
65
+ }, [track, progress.completedStepIds]),
66
+ completeStep,
67
+ resetProgress,
68
+ incrementStreak
69
+ };
70
+ }
71
+
72
+ //#endregion
73
+ export { useLearningProgress };
74
+ //# sourceMappingURL=useLearningProgress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLearningProgress.js","names":[],"sources":["../../src/hooks/useLearningProgress.ts"],"sourcesContent":["'use client';\n\nimport { useState, useCallback, useMemo } from 'react';\nimport type { LearningJourneyTrackSpec } from '@contractspec/module.learning-journey/track-spec';\nimport type { LearningProgressState } from '../types';\n\n/** Default progress state for a new track */\nfunction createDefaultProgress(trackId: string): LearningProgressState {\n return {\n trackId,\n completedStepIds: [],\n currentStepId: null,\n xpEarned: 0,\n streakDays: 0,\n lastActivityDate: null,\n badges: [],\n };\n}\n\n/** Hook for managing learning progress state */\nexport function useLearningProgress(track: LearningJourneyTrackSpec) {\n const [progress, setProgress] = useState<LearningProgressState>(() =>\n createDefaultProgress(track.id)\n );\n\n const completeStep = useCallback(\n (stepId: string) => {\n const step = track.steps.find((s) => s.id === stepId);\n if (!step || progress.completedStepIds.includes(stepId)) return;\n\n setProgress((prev) => {\n const newCompletedIds = [...prev.completedStepIds, stepId];\n const xpReward = step.xpReward ?? 0;\n\n // Find next incomplete step\n const nextStep = track.steps.find(\n (s) => !newCompletedIds.includes(s.id)\n );\n\n // Check if track is complete\n const isTrackComplete = newCompletedIds.length === track.steps.length;\n const completionBonus = isTrackComplete\n ? (track.completionRewards?.xpBonus ?? 0)\n : 0;\n\n return {\n ...prev,\n completedStepIds: newCompletedIds,\n currentStepId: nextStep?.id ?? null,\n xpEarned: prev.xpEarned + xpReward + completionBonus,\n lastActivityDate: new Date().toISOString(),\n badges:\n isTrackComplete && track.completionRewards?.badgeKey\n ? [...prev.badges, track.completionRewards.badgeKey]\n : prev.badges,\n };\n });\n },\n [track, progress.completedStepIds]\n );\n\n const resetProgress = useCallback(() => {\n setProgress(createDefaultProgress(track.id));\n }, [track.id]);\n\n const incrementStreak = useCallback(() => {\n setProgress((prev) => ({\n ...prev,\n streakDays: prev.streakDays + 1,\n lastActivityDate: new Date().toISOString(),\n }));\n }, []);\n\n const stats = useMemo(() => {\n const totalSteps = track.steps.length;\n const completedSteps = progress.completedStepIds.length;\n const percentComplete =\n totalSteps > 0 ? Math.round((completedSteps / totalSteps) * 100) : 0;\n const totalXp =\n track.totalXp ??\n track.steps.reduce((sum, s) => sum + (s.xpReward ?? 0), 0) +\n (track.completionRewards?.xpBonus ?? 0);\n\n return {\n totalSteps,\n completedSteps,\n remainingSteps: totalSteps - completedSteps,\n percentComplete,\n totalXp,\n isComplete: completedSteps === totalSteps,\n };\n }, [track, progress.completedStepIds]);\n\n return {\n progress,\n stats,\n completeStep,\n resetProgress,\n incrementStreak,\n };\n}\n"],"mappings":";;;;;;AAOA,SAAS,sBAAsB,SAAwC;AACrE,QAAO;EACL;EACA,kBAAkB,EAAE;EACpB,eAAe;EACf,UAAU;EACV,YAAY;EACZ,kBAAkB;EAClB,QAAQ,EAAE;EACX;;;AAIH,SAAgB,oBAAoB,OAAiC;CACnE,MAAM,CAAC,UAAU,eAAe,eAC9B,sBAAsB,MAAM,GAAG,CAChC;CAED,MAAM,eAAe,aAClB,WAAmB;EAClB,MAAM,OAAO,MAAM,MAAM,MAAM,MAAM,EAAE,OAAO,OAAO;AACrD,MAAI,CAAC,QAAQ,SAAS,iBAAiB,SAAS,OAAO,CAAE;AAEzD,eAAa,SAAS;GACpB,MAAM,kBAAkB,CAAC,GAAG,KAAK,kBAAkB,OAAO;GAC1D,MAAM,WAAW,KAAK,YAAY;GAGlC,MAAM,WAAW,MAAM,MAAM,MAC1B,MAAM,CAAC,gBAAgB,SAAS,EAAE,GAAG,CACvC;GAGD,MAAM,kBAAkB,gBAAgB,WAAW,MAAM,MAAM;GAC/D,MAAM,kBAAkB,kBACnB,MAAM,mBAAmB,WAAW,IACrC;AAEJ,UAAO;IACL,GAAG;IACH,kBAAkB;IAClB,eAAe,UAAU,MAAM;IAC/B,UAAU,KAAK,WAAW,WAAW;IACrC,mCAAkB,IAAI,MAAM,EAAC,aAAa;IAC1C,QACE,mBAAmB,MAAM,mBAAmB,WACxC,CAAC,GAAG,KAAK,QAAQ,MAAM,kBAAkB,SAAS,GAClD,KAAK;IACZ;IACD;IAEJ,CAAC,OAAO,SAAS,iBAAiB,CACnC;CAED,MAAM,gBAAgB,kBAAkB;AACtC,cAAY,sBAAsB,MAAM,GAAG,CAAC;IAC3C,CAAC,MAAM,GAAG,CAAC;CAEd,MAAM,kBAAkB,kBAAkB;AACxC,eAAa,UAAU;GACrB,GAAG;GACH,YAAY,KAAK,aAAa;GAC9B,mCAAkB,IAAI,MAAM,EAAC,aAAa;GAC3C,EAAE;IACF,EAAE,CAAC;AAsBN,QAAO;EACL;EACA,OAtBY,cAAc;GAC1B,MAAM,aAAa,MAAM,MAAM;GAC/B,MAAM,iBAAiB,SAAS,iBAAiB;GACjD,MAAM,kBACJ,aAAa,IAAI,KAAK,MAAO,iBAAiB,aAAc,IAAI,GAAG;GACrE,MAAM,UACJ,MAAM,WACN,MAAM,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,EAAE,IACvD,MAAM,mBAAmB,WAAW;AAEzC,UAAO;IACL;IACA;IACA,gBAAgB,aAAa;IAC7B;IACA;IACA,YAAY,mBAAmB;IAChC;KACA,CAAC,OAAO,SAAS,iBAAiB,CAAC;EAKpC;EACA;EACA;EACD"}
@@ -0,0 +1,9 @@
1
+ import { BadgeDisplayProps, LearningMiniAppProps, LearningProgressState, LearningView, LearningViewProps, StreakCounterProps, ViewTabsProps, XpBarProps } from "./types.js";
2
+ import { BadgeDisplay } from "./components/BadgeDisplay.js";
3
+ import { StreakCounter } from "./components/StreakCounter.js";
4
+ import { ViewTabs } from "./components/ViewTabs.js";
5
+ import { XpBar } from "./components/XpBar.js";
6
+ import "./components/index.js";
7
+ import example from "./example.js";
8
+ import { useLearningProgress } from "./hooks/useLearningProgress.js";
9
+ export { BadgeDisplay, type BadgeDisplayProps, type LearningMiniAppProps, type LearningProgressState, type LearningView, type LearningViewProps, StreakCounter, type StreakCounterProps, ViewTabs, type ViewTabsProps, XpBar, type XpBarProps, example, useLearningProgress };
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import example_default from "./example.js";
2
+ import { useLearningProgress } from "./hooks/useLearningProgress.js";
3
+ import "./hooks/index.js";
4
+ import { XpBar } from "./components/XpBar.js";
5
+ import { StreakCounter } from "./components/StreakCounter.js";
6
+ import { BadgeDisplay } from "./components/BadgeDisplay.js";
7
+ import { ViewTabs } from "./components/ViewTabs.js";
8
+ import "./components/index.js";
9
+ import "./docs/index.js";
10
+
11
+ export { BadgeDisplay, StreakCounter, ViewTabs, XpBar, example_default as example, useLearningProgress };
@@ -0,0 +1,58 @@
1
+ import { LearningJourneyTrackSpec } from "@contractspec/module.learning-journey/track-spec";
2
+
3
+ //#region src/types.d.ts
4
+ /** View types for learning mini-apps */
5
+ type LearningView = 'overview' | 'steps' | 'progress' | 'timeline';
6
+ /** Progress state for a learning track */
7
+ interface LearningProgressState {
8
+ trackId: string;
9
+ completedStepIds: string[];
10
+ currentStepId: string | null;
11
+ xpEarned: number;
12
+ streakDays: number;
13
+ lastActivityDate: string | null;
14
+ badges: string[];
15
+ }
16
+ /** Props for mini-app components */
17
+ interface LearningMiniAppProps {
18
+ track: LearningJourneyTrackSpec;
19
+ progress: LearningProgressState;
20
+ onStepComplete?: (stepId: string) => void;
21
+ onViewChange?: (view: LearningView) => void;
22
+ initialView?: LearningView;
23
+ }
24
+ /** Props for view components */
25
+ interface LearningViewProps {
26
+ track: LearningJourneyTrackSpec;
27
+ progress: LearningProgressState;
28
+ onStepComplete?: (stepId: string) => void;
29
+ }
30
+ /** XP bar props */
31
+ interface XpBarProps {
32
+ current: number;
33
+ max: number;
34
+ level?: number;
35
+ showLabel?: boolean;
36
+ size?: 'sm' | 'md' | 'lg';
37
+ }
38
+ /** Streak counter props */
39
+ interface StreakCounterProps {
40
+ days: number;
41
+ isActive?: boolean;
42
+ size?: 'sm' | 'md' | 'lg';
43
+ }
44
+ /** Badge display props */
45
+ interface BadgeDisplayProps {
46
+ badges: string[];
47
+ maxVisible?: number;
48
+ size?: 'sm' | 'md' | 'lg';
49
+ }
50
+ /** View tabs props */
51
+ interface ViewTabsProps {
52
+ currentView: LearningView;
53
+ onViewChange: (view: LearningView) => void;
54
+ availableViews?: LearningView[];
55
+ }
56
+ //#endregion
57
+ export { BadgeDisplayProps, LearningMiniAppProps, LearningProgressState, LearningView, LearningViewProps, StreakCounterProps, ViewTabsProps, XpBarProps };
58
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;KAGY,YAAA;AAAZ;AAGiB,UAAA,qBAAA,CAAqB;EAWrB,OAAA,EAAA,MAAA;EACR,gBAAA,EAAA,MAAA,EAAA;EACG,aAAA,EAAA,MAAA,GAAA,IAAA;EAEY,QAAA,EAAA,MAAA;EACR,UAAA,EAAA,MAAA;EAAY,gBAAA,EAAA,MAAA,GAAA,IAAA;EAIX,MAAA,EAAA,MAAA,EAAA;AAOjB;AASA;AAOiB,UAhCA,oBAAA,CAgCiB;EAOjB,KAAA,EAtCR,wBAsCqB;EACf,QAAA,EAtCH,qBAsCG;EACQ,cAAA,CAAA,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,GAAA,IAAA;EACJ,YAAA,CAAA,EAAA,CAAA,IAAA,EAtCK,YAsCL,EAAA,GAAA,IAAA;EAAY,WAAA,CAAA,EArCf,YAqCe;;;UAjCd,iBAAA;SACR;YACG;;;;UAKK,UAAA;;;;;;;;UASA,kBAAA;;;;;;UAOA,iBAAA;;;;;;UAOA,aAAA;eACF;uBACQ;mBACJ"}
package/dist/types.js ADDED
File without changes
package/example.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './src/example';
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@contractspec/example.learning-journey-ui-shared",
3
+ "version": "1.44.0",
4
+ "description": "Shared UI components and hooks for learning journey mini-apps.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js",
10
+ "./components": "./dist/components/index.js",
11
+ "./components/BadgeDisplay": "./dist/components/BadgeDisplay.js",
12
+ "./components/StreakCounter": "./dist/components/StreakCounter.js",
13
+ "./components/ViewTabs": "./dist/components/ViewTabs.js",
14
+ "./components/XpBar": "./dist/components/XpBar.js",
15
+ "./docs": "./dist/docs/index.js",
16
+ "./docs/learning-journey-ui-shared.docblock": "./dist/docs/learning-journey-ui-shared.docblock.js",
17
+ "./example": "./dist/example.js",
18
+ "./hooks": "./dist/hooks/index.js",
19
+ "./hooks/useLearningProgress": "./dist/hooks/useLearningProgress.js",
20
+ "./types": "./dist/types.js",
21
+ "./*": "./*"
22
+ },
23
+ "scripts": {
24
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
25
+ "publish:pkg:canary": "bun publish:pkg --tag canary",
26
+ "build": "bun build:types && bun build:bundle",
27
+ "build:bundle": "tsdown",
28
+ "build:types": "tsc --noEmit",
29
+ "dev": "bun build:bundle --watch",
30
+ "clean": "rimraf dist .turbo",
31
+ "lint": "bun lint:fix",
32
+ "lint:fix": "eslint src --fix",
33
+ "lint:check": "eslint src",
34
+ "test": "bun test"
35
+ },
36
+ "dependencies": {
37
+ "@contractspec/lib.schema": "1.44.0",
38
+ "@contractspec/lib.contracts": "1.44.0",
39
+ "@contractspec/module.learning-journey": "1.44.0",
40
+ "@contractspec/lib.design-system": "1.44.0",
41
+ "@contractspec/lib.ui-kit-web": "1.44.0",
42
+ "react": "19.2.3"
43
+ },
44
+ "devDependencies": {
45
+ "@contractspec/tool.tsdown": "1.44.0",
46
+ "@contractspec/tool.typescript": "1.44.0",
47
+ "@types/react": "^19.1.6",
48
+ "tsdown": "^0.18.3",
49
+ "typescript": "^5.9.3"
50
+ },
51
+ "peerDependencies": {
52
+ "react": "^19.2.3"
53
+ },
54
+ "module": "./dist/index.js",
55
+ "publishConfig": {
56
+ "exports": {
57
+ ".": "./dist/index.js",
58
+ "./example": "./dist/example.js",
59
+ "./docs": "./dist/docs/index.js",
60
+ "./hooks": "./dist/hooks/index.js",
61
+ "./components": "./dist/components/index.js",
62
+ "./types": "./dist/types.js",
63
+ "./*": "./*"
64
+ },
65
+ "registry": "https://registry.npmjs.org/",
66
+ "access": "public"
67
+ },
68
+ "license": "MIT",
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "https://github.com/lssm-tech/contractspec.git",
72
+ "directory": "packages/examples/learning-journey-ui-shared"
73
+ },
74
+ "homepage": "https://contractspec.io"
75
+ }
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+
3
+ import { cn } from '@contractspec/lib.ui-kit-web/ui/utils';
4
+ import type { BadgeDisplayProps } from '../types';
5
+
6
+ const BADGE_ICONS: Record<string, string> = {
7
+ studio_first_30m: '🎯',
8
+ platform_tour: '🗺️',
9
+ crm_first_win: '🏆',
10
+ drill_master: '🧠',
11
+ coach_listener: '👂',
12
+ quest_complete: '⭐',
13
+ streak_7: '🔥',
14
+ streak_30: '💎',
15
+ default: '🏅',
16
+ };
17
+
18
+ const sizeStyles = {
19
+ sm: 'h-6 w-6 text-sm',
20
+ md: 'h-8 w-8 text-base',
21
+ lg: 'h-10 w-10 text-lg',
22
+ };
23
+
24
+ export function BadgeDisplay({
25
+ badges,
26
+ maxVisible = 5,
27
+ size = 'md',
28
+ }: BadgeDisplayProps) {
29
+ const visibleBadges = badges.slice(0, maxVisible);
30
+ const hiddenCount = badges.length - maxVisible;
31
+
32
+ if (badges.length === 0) {
33
+ return (
34
+ <div className="text-muted-foreground text-sm">No badges earned yet</div>
35
+ );
36
+ }
37
+
38
+ return (
39
+ <div className="flex items-center gap-1">
40
+ {visibleBadges.map((badge) => (
41
+ <div
42
+ key={badge}
43
+ className={cn(
44
+ 'flex items-center justify-center rounded-full bg-gradient-to-br from-amber-400/20 to-amber-600/20',
45
+ sizeStyles[size]
46
+ )}
47
+ title={badge.replace(/_/g, ' ')}
48
+ >
49
+ {BADGE_ICONS[badge] ?? BADGE_ICONS.default}
50
+ </div>
51
+ ))}
52
+ {hiddenCount > 0 && (
53
+ <div
54
+ className={cn(
55
+ 'text-muted-foreground bg-muted flex items-center justify-center rounded-full',
56
+ sizeStyles[size],
57
+ 'text-xs font-medium'
58
+ )}
59
+ >
60
+ +{hiddenCount}
61
+ </div>
62
+ )}
63
+ </div>
64
+ );
65
+ }
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+
3
+ import { cn } from '@contractspec/lib.ui-kit-web/ui/utils';
4
+ import type { StreakCounterProps } from '../types';
5
+
6
+ const sizeStyles = {
7
+ sm: {
8
+ container: 'gap-1 px-2 py-1',
9
+ icon: 'text-base',
10
+ text: 'text-xs',
11
+ },
12
+ md: {
13
+ container: 'gap-1.5 px-3 py-1.5',
14
+ icon: 'text-lg',
15
+ text: 'text-sm',
16
+ },
17
+ lg: {
18
+ container: 'gap-2 px-4 py-2',
19
+ icon: 'text-xl',
20
+ text: 'text-base',
21
+ },
22
+ };
23
+
24
+ export function StreakCounter({
25
+ days,
26
+ isActive = true,
27
+ size = 'md',
28
+ }: StreakCounterProps) {
29
+ const styles = sizeStyles[size];
30
+
31
+ return (
32
+ <div
33
+ className={cn(
34
+ 'inline-flex items-center rounded-full font-semibold',
35
+ styles.container,
36
+ isActive
37
+ ? 'bg-orange-500/10 text-orange-500'
38
+ : 'bg-muted text-muted-foreground'
39
+ )}
40
+ >
41
+ <span className={styles.icon} role="img" aria-label="streak">
42
+ 🔥
43
+ </span>
44
+ <span className={styles.text}>
45
+ {days} {days === 1 ? 'day' : 'days'}
46
+ </span>
47
+ </div>
48
+ );
49
+ }
@@ -0,0 +1,46 @@
1
+ 'use client';
2
+
3
+ import { Button } from '@contractspec/lib.design-system';
4
+ import type { ViewTabsProps, LearningView } from '../types';
5
+
6
+ const VIEW_LABELS: Record<LearningView, { label: string; icon: string }> = {
7
+ overview: { label: 'Overview', icon: '📊' },
8
+ steps: { label: 'Steps', icon: '📝' },
9
+ progress: { label: 'Progress', icon: '📈' },
10
+ timeline: { label: 'Timeline', icon: '📅' },
11
+ };
12
+
13
+ const DEFAULT_VIEWS: LearningView[] = [
14
+ 'overview',
15
+ 'steps',
16
+ 'progress',
17
+ 'timeline',
18
+ ];
19
+
20
+ export function ViewTabs({
21
+ currentView,
22
+ onViewChange,
23
+ availableViews = DEFAULT_VIEWS,
24
+ }: ViewTabsProps) {
25
+ return (
26
+ <div className="flex flex-wrap gap-2">
27
+ {availableViews.map((view) => {
28
+ const { label, icon } = VIEW_LABELS[view];
29
+ const isActive = currentView === view;
30
+
31
+ return (
32
+ <Button
33
+ key={view}
34
+ variant={isActive ? 'default' : 'outline'}
35
+ size="sm"
36
+ onClick={() => onViewChange(view)}
37
+ className="gap-1.5"
38
+ >
39
+ <span>{icon}</span>
40
+ <span>{label}</span>
41
+ </Button>
42
+ );
43
+ })}
44
+ </div>
45
+ );
46
+ }
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+
3
+ import { Progress } from '@contractspec/lib.ui-kit-web/ui/progress';
4
+ import { cn } from '@contractspec/lib.ui-kit-web/ui/utils';
5
+ import type { XpBarProps } from '../types';
6
+
7
+ const sizeStyles = {
8
+ sm: 'h-2',
9
+ md: 'h-3',
10
+ lg: 'h-4',
11
+ };
12
+
13
+ const labelSizeStyles = {
14
+ sm: 'text-xs',
15
+ md: 'text-sm',
16
+ lg: 'text-base',
17
+ };
18
+
19
+ export function XpBar({
20
+ current,
21
+ max,
22
+ level,
23
+ showLabel = true,
24
+ size = 'md',
25
+ }: XpBarProps) {
26
+ const percentage = max > 0 ? Math.min((current / max) * 100, 100) : 0;
27
+
28
+ return (
29
+ <div className="w-full space-y-1">
30
+ {showLabel && (
31
+ <div
32
+ className={cn(
33
+ 'flex items-center justify-between',
34
+ labelSizeStyles[size]
35
+ )}
36
+ >
37
+ <span className="text-muted-foreground font-medium">
38
+ {level !== undefined && (
39
+ <span className="text-primary mr-1">Lvl {level}</span>
40
+ )}
41
+ XP
42
+ </span>
43
+ <span className="font-semibold">
44
+ {current.toLocaleString()} / {max.toLocaleString()}
45
+ </span>
46
+ </div>
47
+ )}
48
+ <Progress
49
+ value={percentage}
50
+ className={cn('bg-muted', sizeStyles[size])}
51
+ />
52
+ </div>
53
+ );
54
+ }
@@ -0,0 +1,4 @@
1
+ export { XpBar } from './XpBar';
2
+ export { StreakCounter } from './StreakCounter';
3
+ export { BadgeDisplay } from './BadgeDisplay';
4
+ export { ViewTabs } from './ViewTabs';
@@ -0,0 +1 @@
1
+ import './learning-journey-ui-shared.docblock';