@opengovsg/confetti 0.1.2 → 0.1.4
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/build/confetti.css +67 -0
- package/build/index.d.ts +55 -19
- package/build/index.js +10 -1417
- package/build/internals.d.ts +1 -2
- package/build/internals.js +1 -3
- package/build/routing-ZHrE7mgA.js +1 -0
- package/build/types-BnnL5f51.d.ts +1 -2
- package/package.json +6 -5
- package/build/routing-DjtQKwsR.js +0 -59
package/build/internals.d.ts
CHANGED
|
@@ -10,5 +10,4 @@ declare const evaluateCondition: ({
|
|
|
10
10
|
condition: BinaryOperatorCondition;
|
|
11
11
|
}) => boolean;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { evaluateCondition as unstableInternalConfettiEvaluateCondition };
|
|
14
|
-
//# sourceMappingURL=internals.d.ts.map
|
|
13
|
+
export { evaluateCondition as unstableInternalConfettiEvaluateCondition };
|
package/build/internals.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=({index:e,questions:r,answers:i})=>{if(e===0)return!0;for(let a=0;a<e;a++){let o=r[a],s=o?i[o.id]:void 0;if(!o||!o.visible)continue;let c=o.routingLogic;if(c.type===`always`){if(t({position:a,value:c.target})===e)return!0;continue}if(s==null&&o.required)continue;let l=c.cases,u=s===null?void 0:l.find(e=>n({answer:s,condition:e}));if(!u){if(t({position:a,value:c.default})===e)return!0;continue}if(t({position:a,value:u.target})===e)return!0}return!1},t=({position:e,value:t})=>{switch(t.type){case`next`:return e+1;case`jump`:return t.target;case`end`:return null}},n=({answer:e,condition:t})=>{let n=r(t.value);switch(t.operator){case`equal`:return e===n;case`not-equal`:return e!==n;case`greater`:return typeof e==`number`&&typeof n==`number`&&e>n;case`greater-or-equal`:return typeof e==`number`&&typeof n==`number`&&e>=n;case`less`:return typeof e==`number`&&typeof n==`number`&&e<n;case`less-or-equal`:return typeof e==`number`&&typeof n==`number`&&e<=n;case`contains`:return Array.isArray(e)&&typeof n==`string`&&e.includes(n);case`not-contains`:return Array.isArray(e)&&typeof n==`string`&&!e.includes(n)}},r=e=>e.value;export{e as n,n as t};
|
|
@@ -202,5 +202,4 @@ interface ConfettiState {
|
|
|
202
202
|
errors: Record<Question['id'], string>;
|
|
203
203
|
}
|
|
204
204
|
//#endregion
|
|
205
|
-
export { MultiSelectQuestionProperties as a, StatementQuestionProperties as c, PublicGetSurveyOutput as i, TextQuestionProperties as l, ConfettiState as n, RatingQuestionProperties as o, Question as r, SingleSelectQuestionProperties as s, Answer as t, BinaryOperatorCondition as u };
|
|
206
|
-
//# sourceMappingURL=types-BnnL5f51.d.ts.map
|
|
205
|
+
export { MultiSelectQuestionProperties as a, StatementQuestionProperties as c, PublicGetSurveyOutput as i, TextQuestionProperties as l, ConfettiState as n, RatingQuestionProperties as o, Question as r, SingleSelectQuestionProperties as s, Answer as t, BinaryOperatorCondition as u };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengovsg/confetti",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "Widgets for Confetti",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"repository": "https://github.com/
|
|
9
|
-
"homepage": "https://github.com/
|
|
8
|
+
"repository": "https://github.com/opengovsg/confetti",
|
|
9
|
+
"homepage": "https://github.com/opengovsg/confetti",
|
|
10
10
|
"main": "./build/index.js",
|
|
11
11
|
"types": "./build/index.d.ts",
|
|
12
12
|
"exports": {
|
|
@@ -30,19 +30,20 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"clsx": "^2.1.1",
|
|
32
32
|
"ky": "^1.14.2",
|
|
33
|
-
"react-aria-components": "1.14.0",
|
|
34
33
|
"react-error-boundary": "^6.0.3",
|
|
35
34
|
"usehooks-ts": "^3.1.1",
|
|
36
35
|
"zod": "4.1.12"
|
|
37
36
|
},
|
|
38
37
|
"peerDependencies": {
|
|
39
|
-
"react": "^18.2.0 || ^19.0.0"
|
|
38
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
39
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/react": "^19.2.14",
|
|
43
43
|
"esbuild": "^0.27.2",
|
|
44
44
|
"eslint": "^9.39.2",
|
|
45
45
|
"prettier": "^3.7.4",
|
|
46
|
+
"react-aria-components": "1.14.0",
|
|
46
47
|
"tsdown": "0.19.0",
|
|
47
48
|
"typescript": "^5.9.3",
|
|
48
49
|
"@confetti/eslint-config": "0.0.0",
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
//#region src/core/logic/routing.ts
|
|
2
|
-
const isVisible = ({ index, questions, answers }) => {
|
|
3
|
-
if (index === 0) return true;
|
|
4
|
-
for (let i = 0; i < index; i++) {
|
|
5
|
-
const question = questions[i];
|
|
6
|
-
const answer = question ? answers[question.id] : void 0;
|
|
7
|
-
if (!question || !question.visible) continue;
|
|
8
|
-
const logic = question.routingLogic;
|
|
9
|
-
if (logic.type === "always") if (evaluateTarget({
|
|
10
|
-
position: i,
|
|
11
|
-
value: logic.target
|
|
12
|
-
}) === index) return true;
|
|
13
|
-
else continue;
|
|
14
|
-
if ((answer === void 0 || answer === null) && question.required) continue;
|
|
15
|
-
const cases = logic.cases;
|
|
16
|
-
const match = answer !== null ? cases.find((condition) => evaluateCondition({
|
|
17
|
-
answer,
|
|
18
|
-
condition
|
|
19
|
-
})) : void 0;
|
|
20
|
-
if (!match) if (evaluateTarget({
|
|
21
|
-
position: i,
|
|
22
|
-
value: logic.default
|
|
23
|
-
}) === index) return true;
|
|
24
|
-
else continue;
|
|
25
|
-
if (evaluateTarget({
|
|
26
|
-
position: i,
|
|
27
|
-
value: match.target
|
|
28
|
-
}) === index) return true;
|
|
29
|
-
else continue;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
};
|
|
33
|
-
const evaluateTarget = ({ position, value }) => {
|
|
34
|
-
switch (value.type) {
|
|
35
|
-
case "next": return position + 1;
|
|
36
|
-
case "jump": return value.target;
|
|
37
|
-
case "end": return null;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const evaluateCondition = ({ answer, condition }) => {
|
|
41
|
-
const value = evaluateValue(condition.value);
|
|
42
|
-
switch (condition.operator) {
|
|
43
|
-
case "equal": return answer === value;
|
|
44
|
-
case "not-equal": return answer !== value;
|
|
45
|
-
case "greater": return typeof answer === "number" && typeof value === "number" && answer > value;
|
|
46
|
-
case "greater-or-equal": return typeof answer === "number" && typeof value === "number" && answer >= value;
|
|
47
|
-
case "less": return typeof answer === "number" && typeof value === "number" && answer < value;
|
|
48
|
-
case "less-or-equal": return typeof answer === "number" && typeof value === "number" && answer <= value;
|
|
49
|
-
case "contains": return Array.isArray(answer) && typeof value === "string" && answer.includes(value);
|
|
50
|
-
case "not-contains": return Array.isArray(answer) && typeof value === "string" && !answer.includes(value);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const evaluateValue = (node) => {
|
|
54
|
-
return node.value;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
export { isVisible as n, evaluateCondition as t };
|
|
59
|
-
//# sourceMappingURL=routing-DjtQKwsR.js.map
|