@pie-element/shared-feedback 0.1.0 → 0.1.1-next.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/dist/defaults.d.ts +1 -2
- package/dist/index.d.ts +4 -5
- package/dist/index.js +54 -51
- package/dist/types.d.ts +0 -1
- package/dist/utils.d.ts +1 -2
- package/package.json +12 -10
- package/dist/defaults.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/src/defaults.ts +0 -27
- package/src/index.ts +0 -115
- package/src/types.ts +0 -31
- package/src/utils.ts +0 -12
package/dist/defaults.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Ported from @pie-lib/feedback with TypeScript types and improved structure
|
|
8
8
|
*/
|
|
9
|
-
export * from './types';
|
|
10
|
-
export * from './defaults';
|
|
11
|
-
export * from './utils';
|
|
12
|
-
import type { Correctness, Feedback, FeedbackConfig } from './types';
|
|
9
|
+
export * from './types.js';
|
|
10
|
+
export * from './defaults.js';
|
|
11
|
+
export * from './utils.js';
|
|
12
|
+
import type { Correctness, Feedback, FeedbackConfig } from './types.js';
|
|
13
13
|
/**
|
|
14
14
|
* Get the feedback message for a specific correctness level (async)
|
|
15
15
|
*
|
|
@@ -61,4 +61,3 @@ export declare function getActualFeedbackForCorrectness(correctness: Correctness
|
|
|
61
61
|
* @returns The feedback message or undefined if type is 'none'
|
|
62
62
|
*/
|
|
63
63
|
export declare function getActualFeedback(config: FeedbackConfig, fallback: string): string | undefined;
|
|
64
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
//#region src/defaults.ts
|
|
2
|
+
var e = {
|
|
3
|
+
correct: {
|
|
4
|
+
type: "default",
|
|
5
|
+
default: "Correct",
|
|
6
|
+
custom: "Correct"
|
|
7
|
+
},
|
|
8
|
+
incorrect: {
|
|
9
|
+
type: "default",
|
|
10
|
+
default: "Incorrect",
|
|
11
|
+
custom: "Incorrect"
|
|
12
|
+
},
|
|
13
|
+
partial: {
|
|
14
|
+
type: "default",
|
|
15
|
+
default: "Nearly",
|
|
16
|
+
custom: "Nearly"
|
|
17
|
+
},
|
|
18
|
+
unanswered: {
|
|
19
|
+
type: "default",
|
|
20
|
+
default: "You have not entered a response",
|
|
21
|
+
custom: "You have not entered a response"
|
|
22
|
+
}
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/utils.ts
|
|
26
|
+
function t(e) {
|
|
27
|
+
return e === "partially-correct" ? "partial" : e;
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/index.ts
|
|
31
|
+
function n(n, i = {}) {
|
|
32
|
+
return new Promise((a) => {
|
|
33
|
+
let o = {
|
|
34
|
+
...e,
|
|
35
|
+
...i
|
|
36
|
+
}, s = t(n), c = o[s], l = e[s];
|
|
37
|
+
r(c, l[c.type]).then(a);
|
|
38
|
+
});
|
|
31
39
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
40
|
+
function r(e, t) {
|
|
41
|
+
return new Promise((n) => {
|
|
42
|
+
if (!e || e.type === "none") {
|
|
43
|
+
n(void 0);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
n(e[e.type] || t);
|
|
47
|
+
});
|
|
41
48
|
}
|
|
42
|
-
function i(
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
function i(n, r = {}) {
|
|
50
|
+
let i = {
|
|
51
|
+
...e,
|
|
52
|
+
...r
|
|
53
|
+
}, o = t(n), s = i[o], c = e[o];
|
|
54
|
+
return a(s, c[s.type]);
|
|
45
55
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
return e[e.type] || t;
|
|
56
|
+
function a(e, t) {
|
|
57
|
+
if (!(!e || e.type === "none")) return e[e.type] || t;
|
|
49
58
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
l as getActualFeedback,
|
|
53
|
-
i as getActualFeedbackForCorrectness,
|
|
54
|
-
d as getFeedback,
|
|
55
|
-
f as getFeedbackForCorrectness,
|
|
56
|
-
u as normalizeCorrectness
|
|
57
|
-
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { e as defaultFeedback, a as getActualFeedback, i as getActualFeedbackForCorrectness, r as getFeedback, n as getFeedbackForCorrectness, t as normalizeCorrectness };
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Correctness } from './types';
|
|
1
|
+
import type { Correctness } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Normalize correctness value to standard format
|
|
4
4
|
* Converts 'partially-correct' to 'partial' for consistency
|
|
5
5
|
*/
|
|
6
6
|
export declare function normalizeCorrectness(correctness: string): Correctness;
|
|
7
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/shared-feedback",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-next.1",
|
|
4
4
|
"description": "Feedback utilities for PIE elements",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
"src"
|
|
15
|
+
"dist"
|
|
17
16
|
],
|
|
18
17
|
"scripts": {
|
|
19
18
|
"build": "rm -rf dist tsconfig.tsbuildinfo && vite build && tsc --emitDeclarationOnly",
|
|
@@ -21,14 +20,17 @@
|
|
|
21
20
|
"test": "vitest",
|
|
22
21
|
"clean": "rm -rf dist"
|
|
23
22
|
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"@types/bun": "latest",
|
|
26
|
-
"typescript": "^5.9.3",
|
|
27
|
-
"vite": "^7.2.2",
|
|
28
|
-
"vitest": "^4.0.17"
|
|
29
|
-
},
|
|
30
23
|
"publishConfig": {
|
|
31
24
|
"access": "public"
|
|
32
25
|
},
|
|
33
|
-
"license": "MIT"
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/pie-framework/pie-elements-ng.git",
|
|
30
|
+
"directory": "packages/shared/feedback"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/pie-framework/pie-elements-ng#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/pie-framework/pie-elements-ng/issues"
|
|
35
|
+
}
|
|
34
36
|
}
|
package/dist/defaults.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,QAqB7B,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],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D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,UAAU,EAAE,cAAc,CAAC;CAC5B"}
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,CAKrE"}
|
package/src/defaults.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Feedback } from './types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Default feedback messages for all correctness levels
|
|
5
|
-
*/
|
|
6
|
-
export const defaultFeedback: Feedback = {
|
|
7
|
-
correct: {
|
|
8
|
-
type: 'default',
|
|
9
|
-
default: 'Correct',
|
|
10
|
-
custom: 'Correct',
|
|
11
|
-
},
|
|
12
|
-
incorrect: {
|
|
13
|
-
type: 'default',
|
|
14
|
-
default: 'Incorrect',
|
|
15
|
-
custom: 'Incorrect',
|
|
16
|
-
},
|
|
17
|
-
partial: {
|
|
18
|
-
type: 'default',
|
|
19
|
-
default: 'Nearly',
|
|
20
|
-
custom: 'Nearly',
|
|
21
|
-
},
|
|
22
|
-
unanswered: {
|
|
23
|
-
type: 'default',
|
|
24
|
-
default: 'You have not entered a response',
|
|
25
|
-
custom: 'You have not entered a response',
|
|
26
|
-
},
|
|
27
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pie-element/shared-feedback
|
|
3
|
-
*
|
|
4
|
-
* Feedback utilities for PIE elements
|
|
5
|
-
* Provides utilities for getting feedback messages based on correctness levels
|
|
6
|
-
*
|
|
7
|
-
* Ported from @pie-lib/feedback with TypeScript types and improved structure
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export * from './types';
|
|
11
|
-
export * from './defaults';
|
|
12
|
-
export * from './utils';
|
|
13
|
-
|
|
14
|
-
import type { Correctness, Feedback, FeedbackConfig } from './types';
|
|
15
|
-
import { defaultFeedback } from './defaults';
|
|
16
|
-
import { normalizeCorrectness } from './utils';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get the feedback message for a specific correctness level (async)
|
|
20
|
-
*
|
|
21
|
-
* @param correctness - The correctness level ('correct', 'incorrect', 'partial', 'unanswered')
|
|
22
|
-
* @param feedback - Partial feedback configuration (merged with defaults)
|
|
23
|
-
* @returns Promise resolving to the feedback message or undefined if type is 'none'
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const message = await getFeedbackForCorrectness('correct', {
|
|
28
|
-
* correct: { type: 'custom', default: 'Correct', custom: 'Great job!' }
|
|
29
|
-
* });
|
|
30
|
-
* // Returns: 'Great job!'
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export function getFeedbackForCorrectness(
|
|
34
|
-
correctness: Correctness | 'partially-correct',
|
|
35
|
-
feedback: Partial<Feedback> = {}
|
|
36
|
-
): Promise<string | undefined> {
|
|
37
|
-
return new Promise((resolve) => {
|
|
38
|
-
const merged = { ...defaultFeedback, ...feedback };
|
|
39
|
-
const normalized = normalizeCorrectness(correctness);
|
|
40
|
-
const config = merged[normalized];
|
|
41
|
-
const defaultConfig = defaultFeedback[normalized];
|
|
42
|
-
|
|
43
|
-
getFeedback(config, defaultConfig[config.type as keyof FeedbackConfig] as string).then(resolve);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get the feedback message from a feedback configuration (async)
|
|
49
|
-
*
|
|
50
|
-
* @param config - The feedback configuration
|
|
51
|
-
* @param fallback - Fallback message if config type is not valid
|
|
52
|
-
* @returns Promise resolving to the feedback message or undefined if type is 'none'
|
|
53
|
-
*/
|
|
54
|
-
export function getFeedback(
|
|
55
|
-
config: FeedbackConfig,
|
|
56
|
-
fallback: string
|
|
57
|
-
): Promise<string | undefined> {
|
|
58
|
-
return new Promise((resolve) => {
|
|
59
|
-
if (!config || config.type === 'none') {
|
|
60
|
-
resolve(undefined);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const message = (config[config.type as keyof FeedbackConfig] as string) || fallback;
|
|
65
|
-
resolve(message);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get the feedback message for a specific correctness level (synchronous)
|
|
71
|
-
*
|
|
72
|
-
* This is the recommended function to use for most cases as it's synchronous
|
|
73
|
-
* and more predictable than the Promise-based version.
|
|
74
|
-
*
|
|
75
|
-
* @param correctness - The correctness level ('correct', 'incorrect', 'partial', 'unanswered')
|
|
76
|
-
* @param feedback - Partial feedback configuration (merged with defaults)
|
|
77
|
-
* @returns The feedback message or undefined if type is 'none'
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* const message = getActualFeedbackForCorrectness('correct', {
|
|
82
|
-
* correct: { type: 'custom', default: 'Correct', custom: 'Great job!' }
|
|
83
|
-
* });
|
|
84
|
-
* // Returns: 'Great job!'
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export function getActualFeedbackForCorrectness(
|
|
88
|
-
correctness: Correctness | 'partially-correct',
|
|
89
|
-
feedback: Partial<Feedback> = {}
|
|
90
|
-
): string | undefined {
|
|
91
|
-
const merged = { ...defaultFeedback, ...feedback };
|
|
92
|
-
const normalized = normalizeCorrectness(correctness);
|
|
93
|
-
const config = merged[normalized];
|
|
94
|
-
const defaultConfig = defaultFeedback[normalized];
|
|
95
|
-
|
|
96
|
-
return getActualFeedback(config, defaultConfig[config.type as keyof FeedbackConfig] as string);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Get the feedback message from a feedback configuration (synchronous)
|
|
101
|
-
*
|
|
102
|
-
* @param config - The feedback configuration
|
|
103
|
-
* @param fallback - Fallback message if config type is not valid
|
|
104
|
-
* @returns The feedback message or undefined if type is 'none'
|
|
105
|
-
*/
|
|
106
|
-
export function getActualFeedback(
|
|
107
|
-
config: FeedbackConfig,
|
|
108
|
-
fallback: string
|
|
109
|
-
): string | undefined {
|
|
110
|
-
if (!config || config.type === 'none') {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return (config[config.type as keyof FeedbackConfig] as string) || fallback;
|
|
115
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Feedback type configuration
|
|
3
|
-
*/
|
|
4
|
-
export type FeedbackType = 'default' | 'none' | 'custom';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Correctness levels
|
|
8
|
-
*/
|
|
9
|
-
export type Correctness = 'correct' | 'incorrect' | 'partial' | 'unanswered';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Feedback configuration for a specific correctness level
|
|
13
|
-
*/
|
|
14
|
-
export interface FeedbackConfig {
|
|
15
|
-
/** The type of feedback to show */
|
|
16
|
-
type: FeedbackType;
|
|
17
|
-
/** The default feedback message */
|
|
18
|
-
default: string;
|
|
19
|
-
/** The custom feedback message (if type is 'custom') */
|
|
20
|
-
custom: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Complete feedback configuration for all correctness levels
|
|
25
|
-
*/
|
|
26
|
-
export interface Feedback {
|
|
27
|
-
correct: FeedbackConfig;
|
|
28
|
-
incorrect: FeedbackConfig;
|
|
29
|
-
partial: FeedbackConfig;
|
|
30
|
-
unanswered: FeedbackConfig;
|
|
31
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Correctness } from './types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Normalize correctness value to standard format
|
|
5
|
-
* Converts 'partially-correct' to 'partial' for consistency
|
|
6
|
-
*/
|
|
7
|
-
export function normalizeCorrectness(correctness: string): Correctness {
|
|
8
|
-
if (correctness === 'partially-correct') {
|
|
9
|
-
return 'partial';
|
|
10
|
-
}
|
|
11
|
-
return correctness as Correctness;
|
|
12
|
-
}
|