@pie-element/shared-controller-utils 0.1.1-next.1 → 0.1.1-next.20261002100925
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 -3
- package/dist/index.js +4 -4
- package/dist/persistence.d.ts +10 -9
- package/package.json +3 -9
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @pie-
|
|
1
|
+
# @pie-element/shared-controller-utils
|
|
2
2
|
|
|
3
3
|
Controller utility functions for PIE elements.
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ This package is part of the PIE workspace and should be installed via workspace
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@pie-
|
|
12
|
+
"@pie-element/shared-controller-utils": "workspace:*"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
```
|
|
@@ -17,7 +17,7 @@ This package is part of the PIE workspace and should be installed via workspace
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import {
|
|
20
|
+
import { getShuffledChoices, lockChoices, partialScoring } from '@pie-element/shared-controller-utils';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Development
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function r(e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
}
|
|
23
23
|
function i(e) {
|
|
24
|
-
return e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == "object"
|
|
24
|
+
return e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == "object" && Object.keys(e).length === 0;
|
|
25
25
|
}
|
|
26
26
|
async function a(e, t, a, o = "value") {
|
|
27
27
|
let s = n(t?.data?.shuffledValues ?? t?.shuffledValues ?? []);
|
|
@@ -33,7 +33,7 @@ async function a(e, t, a, o = "value") {
|
|
|
33
33
|
let c = r(e);
|
|
34
34
|
if (a && typeof a == "function") try {
|
|
35
35
|
let e = n(c.map((e) => e[o]));
|
|
36
|
-
i(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(c)}, key: ${o}`) :
|
|
36
|
+
i(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(c)}, key: ${o}`) : await a(t.id, t.element, { shuffledValues: e });
|
|
37
37
|
} catch (e) {
|
|
38
38
|
console.warn("Unable to save shuffled order for choices"), console.error(e);
|
|
39
39
|
}
|
|
@@ -41,13 +41,13 @@ async function a(e, t, a, o = "value") {
|
|
|
41
41
|
return c;
|
|
42
42
|
}
|
|
43
43
|
function o(e, t, n) {
|
|
44
|
-
return !!(e.lockChoiceOrder || n["@pie-element"]?.lockChoiceOrder
|
|
44
|
+
return !!(e.lockChoiceOrder || n?.["@pie-element"]?.lockChoiceOrder);
|
|
45
45
|
}
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region src/partial-scoring.ts
|
|
48
48
|
var s = /* @__PURE__ */ t({ enabled: () => c });
|
|
49
49
|
function c(e, t, n) {
|
|
50
|
-
return e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n
|
|
50
|
+
return e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n != "boolean" || n;
|
|
51
51
|
}
|
|
52
52
|
//#endregion
|
|
53
53
|
export { a as getShuffledChoices, o as lockChoices, s as partialScoring };
|
package/dist/persistence.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Functions for managing shuffled choice order and session persistence.
|
|
5
5
|
*/
|
|
6
|
+
import type { PieUpdateSession } from '@pie-element/shared-types';
|
|
6
7
|
interface Session {
|
|
7
8
|
id?: string;
|
|
8
9
|
element?: string;
|
|
@@ -23,24 +24,22 @@ interface Environment {
|
|
|
23
24
|
};
|
|
24
25
|
role?: 'student' | 'instructor';
|
|
25
26
|
}
|
|
26
|
-
type UpdateSessionFunction = (sessionId: string, element: string, data: {
|
|
27
|
-
shuffledValues: string[];
|
|
28
|
-
}) => Promise<void>;
|
|
29
27
|
/**
|
|
30
28
|
* Get shuffled choices, either from session storage or by creating a new shuffle.
|
|
31
29
|
*
|
|
32
30
|
* This function:
|
|
33
31
|
* 1. Checks if shuffled values already exist in the session
|
|
34
32
|
* 2. If they exist, returns choices in that order
|
|
35
|
-
* 3. If they don't exist, shuffles the choices and
|
|
33
|
+
* 3. If they don't exist, shuffles the choices and saves the order through `updateSession`
|
|
36
34
|
*
|
|
37
35
|
* @param choices - Array of choice objects to shuffle
|
|
38
|
-
* @param session - Current session object that may contain previous shuffle order
|
|
36
|
+
* @param session - Current session object that may contain previous shuffle order. An element
|
|
37
|
+
* that shuffles each of its parts passes a stand-in built for that part, with no id or element.
|
|
39
38
|
* @param updateSession - Optional function to persist the shuffle order
|
|
40
39
|
* @param choiceKey - Property name to use as the unique identifier (e.g., 'value', 'id')
|
|
41
40
|
* @returns Promise resolving to shuffled choices array
|
|
42
41
|
*/
|
|
43
|
-
export declare function getShuffledChoices<T extends Choice>(choices: T[], session: Session | undefined, updateSession?:
|
|
42
|
+
export declare function getShuffledChoices<T extends Choice>(choices: T[], session: Session | undefined, updateSession?: PieUpdateSession, choiceKey?: string): Promise<T[] | undefined>;
|
|
44
43
|
/**
|
|
45
44
|
* Determine whether choice order should be locked (ordinal) or shuffled.
|
|
46
45
|
*
|
|
@@ -51,13 +50,15 @@ export declare function getShuffledChoices<T extends Choice>(choices: T[], sessi
|
|
|
51
50
|
* Logic:
|
|
52
51
|
* 1. If model.lockChoiceOrder is true, lock order
|
|
53
52
|
* 2. If env['@pie-element'].lockChoiceOrder is true, lock order
|
|
54
|
-
* 3.
|
|
55
|
-
*
|
|
53
|
+
* 3. Otherwise, allow shuffling
|
|
54
|
+
*
|
|
55
|
+
* The role plays no part (PIE-714): an instructor reviewing a session sees the order its
|
|
56
|
+
* student saw.
|
|
56
57
|
*
|
|
57
58
|
* @param model - Model configuration
|
|
58
59
|
* @param session - Current session (unused currently but kept for API compatibility)
|
|
59
60
|
* @param env - Environment configuration
|
|
60
61
|
* @returns Whether to lock choice order
|
|
61
62
|
*/
|
|
62
|
-
export declare function lockChoices(model: Model, _session: Session | undefined, env: Environment): boolean;
|
|
63
|
+
export declare function lockChoices(model: Model, _session: Session | undefined, env: Environment | undefined): boolean;
|
|
63
64
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/shared-controller-utils",
|
|
3
|
-
"version": "0.1.1-next.
|
|
3
|
+
"version": "0.1.1-next.20261002100925",
|
|
4
4
|
"description": "Controller utility functions for PIE elements",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,13 +21,7 @@
|
|
|
21
21
|
"clean": "rm -rf dist"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@pie-element/shared-types": "0.
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@types/bun": "latest",
|
|
28
|
-
"typescript": "^5.9.3",
|
|
29
|
-
"vite": "^8.0.1",
|
|
30
|
-
"vitest": "^4.1.0"
|
|
24
|
+
"@pie-element/shared-types": "0.2.0-next.20261002100925"
|
|
31
25
|
},
|
|
32
26
|
"publishConfig": {
|
|
33
27
|
"access": "public"
|
|
@@ -35,7 +29,7 @@
|
|
|
35
29
|
"license": "MIT",
|
|
36
30
|
"repository": {
|
|
37
31
|
"type": "git",
|
|
38
|
-
"url": "https://github.com/pie-framework/pie-elements-ng.git",
|
|
32
|
+
"url": "git+https://github.com/pie-framework/pie-elements-ng.git",
|
|
39
33
|
"directory": "packages/shared/controller-utils"
|
|
40
34
|
},
|
|
41
35
|
"homepage": "https://github.com/pie-framework/pie-elements-ng#readme",
|