@pie-element/shared-controller-utils 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/index.d.ts CHANGED
@@ -4,6 +4,5 @@
4
4
  * Shared utilities for PIE element controllers, including partial scoring
5
5
  * and choice persistence/shuffling.
6
6
  */
7
- export { lockChoices, getShuffledChoices } from './persistence';
8
- export * as partialScoring from './partial-scoring';
9
- //# sourceMappingURL=index.d.ts.map
7
+ export { lockChoices, getShuffledChoices } from './persistence.js';
8
+ export * as partialScoring from './partial-scoring.js';
package/dist/index.js CHANGED
@@ -1,51 +1,53 @@
1
- function u(r) {
2
- return Array.isArray(r) ? r.filter((e) => e != null) : [];
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.defineProperty, t = (t, n) => {
3
+ let r = {};
4
+ for (var i in t) e(r, i, {
5
+ get: t[i],
6
+ enumerable: !0
7
+ });
8
+ return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ };
10
+ //#endregion
11
+ //#region src/persistence.ts
12
+ function n(e) {
13
+ return Array.isArray(e) ? e.filter((e) => e != null) : [];
3
14
  }
4
- function c(r) {
5
- const e = [...r];
6
- for (let t = e.length - 1; t > 0; t--) {
7
- const n = Math.floor(Math.random() * (t + 1));
8
- [e[t], e[n]] = [e[n], e[t]];
9
- }
10
- return e;
15
+ function r(e) {
16
+ let t = [...e];
17
+ for (let e = t.length - 1; e > 0; e--) {
18
+ let n = Math.floor(Math.random() * (e + 1));
19
+ [t[e], t[n]] = [t[n], t[e]];
20
+ }
21
+ return t;
11
22
  }
12
- function a(r) {
13
- return r == null ? !0 : Array.isArray(r) ? r.length === 0 : typeof r == "object" ? Object.keys(r).length === 0 : !1;
23
+ function i(e) {
24
+ return e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == "object" ? Object.keys(e).length === 0 : !1;
14
25
  }
15
- async function h(r, e, t, n = "value") {
16
- const i = u(e?.data?.shuffledValues ?? e?.shuffledValues ?? []);
17
- if (!e) {
18
- console.warn("Unable to save shuffled choices because there's no session.");
19
- return;
20
- }
21
- if (!a(i))
22
- return u(i.map((f) => r.find((l) => l[n] === f)));
23
- const o = c(r);
24
- if (t && typeof t == "function")
25
- try {
26
- const f = u(o.map((l) => l[n]));
27
- a(f) ? console.error(
28
- `shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(o)}, key: ${n}`
29
- ) : e.id && e.element && await t(e.id, e.element, { shuffledValues: f });
30
- } catch (f) {
31
- console.warn("Unable to save shuffled order for choices"), console.error(f);
32
- }
33
- else
34
- console.warn("Unable to save shuffled choices, shuffle will happen every time.");
35
- return o;
26
+ async function a(e, t, a, o = "value") {
27
+ let s = n(t?.data?.shuffledValues ?? t?.shuffledValues ?? []);
28
+ if (!t) {
29
+ console.warn("Unable to save shuffled choices because there's no session.");
30
+ return;
31
+ }
32
+ if (!i(s)) return n(s.map((t) => e.find((e) => e[o] === t)));
33
+ let c = r(e);
34
+ if (a && typeof a == "function") try {
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}`) : t.id && t.element && await a(t.id, t.element, { shuffledValues: e });
37
+ } catch (e) {
38
+ console.warn("Unable to save shuffled order for choices"), console.error(e);
39
+ }
40
+ else console.warn("Unable to save shuffled choices, shuffle will happen every time.");
41
+ return c;
36
42
  }
37
- function d(r, e, t) {
38
- return !!(r.lockChoiceOrder || t["@pie-element"]?.lockChoiceOrder || (t.role ?? "student") === "instructor");
43
+ function o(e, t, n) {
44
+ return !!(e.lockChoiceOrder || n["@pie-element"]?.lockChoiceOrder || (n.role ?? "student") === "instructor");
39
45
  }
40
- function s(r, e, t) {
41
- return r?.partialScoring === !1 || e?.partialScoring === !1 ? !1 : typeof t == "boolean" ? t : !0;
46
+ //#endregion
47
+ //#region src/partial-scoring.ts
48
+ var s = /* @__PURE__ */ t({ enabled: () => c });
49
+ function c(e, t, n) {
50
+ return e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n == "boolean" ? n : !0;
42
51
  }
43
- const p = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
44
- __proto__: null,
45
- enabled: s
46
- }, Symbol.toStringTag, { value: "Module" }));
47
- export {
48
- h as getShuffledChoices,
49
- d as lockChoices,
50
- p as partialScoring
51
- };
52
+ //#endregion
53
+ export { a as getShuffledChoices, o as lockChoices, s as partialScoring };
@@ -24,4 +24,3 @@ interface Environment {
24
24
  */
25
25
  export declare function enabled(config?: Config, env?: Environment, defaultValue?: boolean): boolean;
26
26
  export {};
27
- //# sourceMappingURL=partial-scoring.d.ts.map
@@ -61,4 +61,3 @@ export declare function getShuffledChoices<T extends Choice>(choices: T[], sessi
61
61
  */
62
62
  export declare function lockChoices(model: Model, _session: Session | undefined, env: Environment): boolean;
63
63
  export {};
64
- //# sourceMappingURL=persistence.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-controller-utils",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-next.1",
4
4
  "description": "Controller utility functions for PIE elements",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,16 +21,25 @@
21
21
  "clean": "rm -rf dist"
22
22
  },
23
23
  "dependencies": {
24
- "@pie-element/shared-types": "workspace:*"
24
+ "@pie-element/shared-types": "0.1.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/bun": "latest",
28
28
  "typescript": "^5.9.3",
29
- "vite": "^7.2.2",
30
- "vitest": "^4.0.17"
29
+ "vite": "^8.0.1",
30
+ "vitest": "^4.1.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "license": "MIT"
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/pie-framework/pie-elements-ng.git",
39
+ "directory": "packages/shared/controller-utils"
40
+ },
41
+ "homepage": "https://github.com/pie-framework/pie-elements-ng#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/pie-framework/pie-elements-ng/issues"
44
+ }
36
45
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"partial-scoring.d.ts","sourceRoot":"","sources":["../src/partial-scoring.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,MAAM;IACd,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,UAAU,WAAW;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAU3F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,OAAO;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE;QACL,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;KAC3B,CAAC;IACF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,UAAU,MAAM;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,KAAK;IACb,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,UAAU,WAAW;IACnB,cAAc,CAAC,EAAE;QACf,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,C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