@opengovsg/confetti 0.0.3 → 0.0.5

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.
@@ -0,0 +1,14 @@
1
+ import { t as Answer, u as BinaryOperatorCondition } from "./types-qVyTr8wu.js";
2
+
3
+ //#region src/core/logic/routing.d.ts
4
+
5
+ declare const evaluateCondition: ({
6
+ answer,
7
+ condition
8
+ }: {
9
+ answer: Answer;
10
+ condition: BinaryOperatorCondition;
11
+ }) => boolean;
12
+ //#endregion
13
+ export { evaluateCondition as unstableInternalConfettiEvaluateCondition };
14
+ //# sourceMappingURL=internals.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { t as evaluateCondition } from "./routing-DjtQKwsR.js";
2
+
3
+ export { evaluateCondition as unstableInternalConfettiEvaluateCondition };
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,204 @@
1
+ import { z } from "zod/v4/mini";
2
+
3
+ //#region ../validators/src/questions/routing.d.ts
4
+
5
+ declare const binaryOperatorConditionSchema: z.ZodMiniObject<{
6
+ type: z.ZodMiniLiteral<"binary-operator">;
7
+ operator: z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"equal">, z.ZodMiniLiteral<"not-equal">, z.ZodMiniLiteral<"greater">, z.ZodMiniLiteral<"greater-or-equal">, z.ZodMiniLiteral<"less">, z.ZodMiniLiteral<"less-or-equal">, z.ZodMiniLiteral<"contains">, z.ZodMiniLiteral<"not-contains">]>;
8
+ value: z.ZodMiniObject<{
9
+ type: z.ZodMiniLiteral<"value">;
10
+ value: z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniNumber<number>]>;
11
+ }, z.core.$strip>;
12
+ target: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
13
+ type: z.ZodMiniLiteral<"next">;
14
+ }, z.core.$strip>, z.ZodMiniObject<{
15
+ type: z.ZodMiniLiteral<"jump">;
16
+ target: z.ZodMiniNumber<number>;
17
+ }, z.core.$strip>, z.ZodMiniObject<{
18
+ type: z.ZodMiniLiteral<"end">;
19
+ }, z.core.$strip>], "type">;
20
+ }, z.core.$strip>;
21
+ type BinaryOperatorCondition = z.infer<typeof binaryOperatorConditionSchema>;
22
+ //#endregion
23
+ //#region ../validators/src/questions/properties.d.ts
24
+ declare const ratingQuestionPropertiesSchema: z.ZodMiniObject<{
25
+ type: z.ZodMiniLiteral<"rating">;
26
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
27
+ scale: z.ZodMiniNumber<number>;
28
+ labels: z.ZodMiniOptional<z.ZodMiniObject<{
29
+ lower: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<string | undefined, string>>>;
30
+ upper: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<string | undefined, string>>>;
31
+ }, z.core.$strip>>;
32
+ display: z.ZodMiniOptional<z.ZodMiniLiteral<"number" | "star" | "emoji" | "tiffany">>;
33
+ }, z.core.$strip>;
34
+ type RatingQuestionProperties = z.infer<typeof ratingQuestionPropertiesSchema>;
35
+ declare const textQuestionPropertiesSchema: z.ZodMiniObject<{
36
+ type: z.ZodMiniLiteral<"open-ended">;
37
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
38
+ max: z.ZodMiniNumber<number>;
39
+ }, z.core.$strip>;
40
+ type TextQuestionProperties = z.infer<typeof textQuestionPropertiesSchema>;
41
+ declare const singleSelectQuestionPropertiesSchema: z.ZodMiniObject<{
42
+ type: z.ZodMiniLiteral<"single-select">;
43
+ options: z.ZodMiniArray<z.ZodMiniObject<{
44
+ value: z.ZodMiniString<string>;
45
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
46
+ }, z.core.$strip>>;
47
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
48
+ editable: z.ZodMiniNullable<z.ZodMiniObject<{
49
+ label: z.ZodMiniString<string>;
50
+ max: z.ZodMiniNumber<number>;
51
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
52
+ }, z.core.$strip>>;
53
+ }, z.core.$strip>;
54
+ type SingleSelectQuestionProperties = z.infer<typeof singleSelectQuestionPropertiesSchema>;
55
+ declare const multiSelectQuestionPropertiesSchema: z.ZodMiniObject<{
56
+ type: z.ZodMiniLiteral<"multi-select">;
57
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
58
+ options: z.ZodMiniArray<z.ZodMiniObject<{
59
+ value: z.ZodMiniString<string>;
60
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
61
+ }, z.core.$strip>>;
62
+ editable: z.ZodMiniNullable<z.ZodMiniObject<{
63
+ label: z.ZodMiniString<string>;
64
+ max: z.ZodMiniNumber<number>;
65
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
66
+ }, z.core.$strip>>;
67
+ max: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
68
+ display: z.ZodMiniOptional<z.ZodMiniLiteral<"checkbox" | "tag">>;
69
+ }, z.core.$strip>;
70
+ type MultiSelectQuestionProperties = z.infer<typeof multiSelectQuestionPropertiesSchema>;
71
+ declare const statementQuestionPropertiesSchema: z.ZodMiniObject<{
72
+ type: z.ZodMiniLiteral<"statement">;
73
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
74
+ buttonUrl: z.ZodMiniOptional<z.ZodMiniString<string>>;
75
+ }, z.core.$strip>;
76
+ type StatementQuestionProperties = z.infer<typeof statementQuestionPropertiesSchema>;
77
+ //#endregion
78
+ //#region ../validators/src/survey.d.ts
79
+ declare const publicGetSurveyOutputSchema: z.ZodMiniObject<{
80
+ title: z.ZodMiniString<string>;
81
+ description: z.ZodMiniNullable<z.ZodMiniString<string>>;
82
+ questions: z.ZodMiniArray<z.ZodMiniObject<{
83
+ id: z.ZodMiniString<string>;
84
+ title: z.ZodMiniString<string>;
85
+ description: z.ZodMiniNullable<z.ZodMiniString<string>>;
86
+ position: z.ZodMiniNumber<number>;
87
+ required: z.ZodMiniBoolean<boolean>;
88
+ properties: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
89
+ type: z.ZodMiniLiteral<"rating">;
90
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
91
+ scale: z.ZodMiniNumber<number>;
92
+ labels: z.ZodMiniOptional<z.ZodMiniObject<{
93
+ lower: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<string | undefined, string>>>;
94
+ upper: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<string | undefined, string>>>;
95
+ }, z.core.$strip>>;
96
+ display: z.ZodMiniOptional<z.ZodMiniLiteral<"number" | "star" | "emoji" | "tiffany">>;
97
+ }, z.core.$strip>, z.ZodMiniObject<{
98
+ type: z.ZodMiniLiteral<"single-select">;
99
+ options: z.ZodMiniArray<z.ZodMiniObject<{
100
+ value: z.ZodMiniString<string>;
101
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
102
+ }, z.core.$strip>>;
103
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
104
+ editable: z.ZodMiniNullable<z.ZodMiniObject<{
105
+ label: z.ZodMiniString<string>;
106
+ max: z.ZodMiniNumber<number>;
107
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
108
+ }, z.core.$strip>>;
109
+ }, z.core.$strip>, z.ZodMiniObject<{
110
+ type: z.ZodMiniLiteral<"open-ended">;
111
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
112
+ max: z.ZodMiniNumber<number>;
113
+ }, z.core.$strip>, z.ZodMiniObject<{
114
+ type: z.ZodMiniLiteral<"multi-select">;
115
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
116
+ options: z.ZodMiniArray<z.ZodMiniObject<{
117
+ value: z.ZodMiniString<string>;
118
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
119
+ }, z.core.$strip>>;
120
+ editable: z.ZodMiniNullable<z.ZodMiniObject<{
121
+ label: z.ZodMiniString<string>;
122
+ max: z.ZodMiniNumber<number>;
123
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
124
+ }, z.core.$strip>>;
125
+ max: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
126
+ display: z.ZodMiniOptional<z.ZodMiniLiteral<"checkbox" | "tag">>;
127
+ }, z.core.$strip>, z.ZodMiniObject<{
128
+ type: z.ZodMiniLiteral<"statement">;
129
+ buttonLabel: z.ZodMiniOptional<z.ZodMiniString<string>>;
130
+ buttonUrl: z.ZodMiniOptional<z.ZodMiniString<string>>;
131
+ }, z.core.$strip>], "type">;
132
+ routingLogic: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
133
+ type: z.ZodMiniLiteral<"always">;
134
+ target: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
135
+ type: z.ZodMiniLiteral<"next">;
136
+ }, z.core.$strip>, z.ZodMiniObject<{
137
+ type: z.ZodMiniLiteral<"jump">;
138
+ target: z.ZodMiniNumber<number>;
139
+ }, z.core.$strip>, z.ZodMiniObject<{
140
+ type: z.ZodMiniLiteral<"end">;
141
+ }, z.core.$strip>], "type">;
142
+ }, z.core.$strip>, z.ZodMiniObject<{
143
+ type: z.ZodMiniLiteral<"switch">;
144
+ cases: z.ZodMiniArray<z.ZodMiniObject<{
145
+ type: z.ZodMiniLiteral<"binary-operator">;
146
+ operator: z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"equal">, z.ZodMiniLiteral<"not-equal">, z.ZodMiniLiteral<"greater">, z.ZodMiniLiteral<"greater-or-equal">, z.ZodMiniLiteral<"less">, z.ZodMiniLiteral<"less-or-equal">, z.ZodMiniLiteral<"contains">, z.ZodMiniLiteral<"not-contains">]>;
147
+ value: z.ZodMiniObject<{
148
+ type: z.ZodMiniLiteral<"value">;
149
+ value: z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniNumber<number>]>;
150
+ }, z.core.$strip>;
151
+ target: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
152
+ type: z.ZodMiniLiteral<"next">;
153
+ }, z.core.$strip>, z.ZodMiniObject<{
154
+ type: z.ZodMiniLiteral<"jump">;
155
+ target: z.ZodMiniNumber<number>;
156
+ }, z.core.$strip>, z.ZodMiniObject<{
157
+ type: z.ZodMiniLiteral<"end">;
158
+ }, z.core.$strip>], "type">;
159
+ }, z.core.$strip>>;
160
+ default: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
161
+ type: z.ZodMiniLiteral<"next">;
162
+ }, z.core.$strip>, z.ZodMiniObject<{
163
+ type: z.ZodMiniLiteral<"jump">;
164
+ target: z.ZodMiniNumber<number>;
165
+ }, z.core.$strip>, z.ZodMiniObject<{
166
+ type: z.ZodMiniLiteral<"end">;
167
+ }, z.core.$strip>], "type">;
168
+ }, z.core.$strip>], "type">;
169
+ }, z.core.$strip>>;
170
+ confirmation: z.ZodMiniObject<{
171
+ title: z.ZodMiniString<string>;
172
+ description: z.ZodMiniString<string>;
173
+ buttonText: z.ZodMiniString<string>;
174
+ }, z.core.$strip>;
175
+ }, z.core.$strip>;
176
+ type PublicGetSurveyOutput = z.infer<typeof publicGetSurveyOutputSchema>;
177
+ //#endregion
178
+ //#region src/core/types.d.ts
179
+ type Question = {
180
+ visible: boolean;
181
+ error?: string;
182
+ } & PublicGetSurveyOutput['questions'][number];
183
+ type Answer = string | number | string[] | undefined;
184
+ interface ConfettiState {
185
+ questions: Question[];
186
+ current: number;
187
+ update: ({
188
+ question,
189
+ answer
190
+ }: {
191
+ question: number;
192
+ answer: Answer;
193
+ }) => {
194
+ next?: number;
195
+ error?: string;
196
+ };
197
+ submit: () => void;
198
+ isCompleted: boolean;
199
+ isSubmitted: boolean;
200
+ errors: Record<Question['id'], string>;
201
+ }
202
+ //#endregion
203
+ 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 };
204
+ //# sourceMappingURL=types-qVyTr8wu.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengovsg/confetti",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "sideEffects": false,
5
5
  "description": "Widgets for Confetti",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -13,6 +13,11 @@
13
13
  "default": "./build/index.js",
14
14
  "types": "./build/index.d.ts"
15
15
  },
16
+ "./internals": {
17
+ "import": "./build/internals.js",
18
+ "default": "./build/internals.js",
19
+ "types": "./build/internals.d.ts"
20
+ },
16
21
  "./confetti.css": "./build/confetti.css"
17
22
  },
18
23
  "files": [
@@ -32,16 +37,16 @@
32
37
  "react": "^18.2.0 || ^19.0.0"
33
38
  },
34
39
  "devDependencies": {
35
- "@types/react": "^19.2.7",
40
+ "@types/react": "^19.2.9",
36
41
  "esbuild": "^0.27.2",
37
42
  "eslint": "^9.39.2",
38
43
  "prettier": "^3.7.4",
39
44
  "tsdown": "0.19.0",
40
45
  "typescript": "^5.9.3",
46
+ "@confetti/prettier-config": "0.0.0",
41
47
  "@confetti/tsconfig": "0.0.0",
42
- "@confetti/validators": "0.0.0",
43
48
  "@confetti/eslint-config": "0.0.0",
44
- "@confetti/prettier-config": "0.0.0"
49
+ "@confetti/validators": "0.0.0"
45
50
  },
46
51
  "prettier": "@confetti/prettier-config",
47
52
  "scripts": {