@opengovsg/confetti 0.0.11 → 0.0.12
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/index.d.ts +19 -18
- package/build/index.js +45 -11
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as MultiSelectQuestionProperties, c as StatementQuestionProperties, i as PublicGetSurveyOutput, l as TextQuestionProperties, n as ConfettiState, o as RatingQuestionProperties, r as Question, s as SingleSelectQuestionProperties, t as Answer } from "./types-COft9SvA.js";
|
|
2
2
|
import * as react0 from "react";
|
|
3
3
|
import { HTMLAttributes, PropsWithChildren } from "react";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/core/ConfettiController.d.ts
|
|
7
7
|
interface ConfettiControllerProps {
|
|
@@ -19,7 +19,7 @@ declare const ConfettiController: ({
|
|
|
19
19
|
shouldAutoSubmit,
|
|
20
20
|
onFinished,
|
|
21
21
|
children
|
|
22
|
-
}: ConfettiControllerProps) =>
|
|
22
|
+
}: ConfettiControllerProps) => react_jsx_runtime3.JSX.Element;
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/core/ConfettiProvider.d.ts
|
|
25
25
|
interface ConfettiContextValue {
|
|
@@ -43,17 +43,18 @@ interface ConfettiProviderProps {
|
|
|
43
43
|
apiBaseUrl?: string;
|
|
44
44
|
isSurveyVisible?: boolean | ((_: {
|
|
45
45
|
lastRespondedAt: Date | null;
|
|
46
|
+
lastDismissedAt: Date | null;
|
|
46
47
|
}) => boolean);
|
|
47
48
|
}
|
|
48
49
|
declare const ConfettiProvider: ({
|
|
49
50
|
children,
|
|
50
51
|
surveyId,
|
|
51
52
|
publishableKey,
|
|
52
|
-
respondent,
|
|
53
|
+
respondent: respondentInput,
|
|
53
54
|
metadata,
|
|
54
55
|
isSurveyVisible: isSurveyVisibleInput,
|
|
55
56
|
apiBaseUrl
|
|
56
|
-
}: ConfettiProviderProps) =>
|
|
57
|
+
}: ConfettiProviderProps) => react_jsx_runtime3.JSX.Element | null;
|
|
57
58
|
declare const useConfetti: () => ConfettiContextValue;
|
|
58
59
|
//#endregion
|
|
59
60
|
//#region src/components/Confetti.d.ts
|
|
@@ -63,7 +64,7 @@ declare const Confetti: ({
|
|
|
63
64
|
onFinished,
|
|
64
65
|
shouldAutoSubmit,
|
|
65
66
|
...props
|
|
66
|
-
}: ConfettiProps & Pick<ConfettiControllerProps, "children" | "shouldAutoSubmit">) =>
|
|
67
|
+
}: ConfettiProps & Pick<ConfettiControllerProps, "children" | "shouldAutoSubmit">) => react_jsx_runtime3.JSX.Element;
|
|
67
68
|
//#endregion
|
|
68
69
|
//#region src/components/ThankYouMessage.d.ts
|
|
69
70
|
interface ThankYouMessageProps {
|
|
@@ -80,7 +81,7 @@ declare const ThankYouMessage: ({
|
|
|
80
81
|
title,
|
|
81
82
|
description,
|
|
82
83
|
classNames
|
|
83
|
-
}: ThankYouMessageProps) =>
|
|
84
|
+
}: ThankYouMessageProps) => react_jsx_runtime3.JSX.Element | null;
|
|
84
85
|
//#endregion
|
|
85
86
|
//#region src/components/container/PopoverContainer.d.ts
|
|
86
87
|
interface PopoverContainerProps {
|
|
@@ -102,7 +103,7 @@ declare const PopoverContainer: ({
|
|
|
102
103
|
containerProps,
|
|
103
104
|
onDismiss,
|
|
104
105
|
closeOnFinishMs
|
|
105
|
-
}: PopoverContainerProps) =>
|
|
106
|
+
}: PopoverContainerProps) => react_jsx_runtime3.JSX.Element;
|
|
106
107
|
//#endregion
|
|
107
108
|
//#region src/components/questions/types.d.ts
|
|
108
109
|
type Question$1 = PublicGetSurveyOutput['questions'][number];
|
|
@@ -125,7 +126,7 @@ declare const SurveyQuestionFactory: ({
|
|
|
125
126
|
question,
|
|
126
127
|
onChange,
|
|
127
128
|
error
|
|
128
|
-
}: SurveyQuestionFactoryProps) =>
|
|
129
|
+
}: SurveyQuestionFactoryProps) => react_jsx_runtime3.JSX.Element;
|
|
129
130
|
//#endregion
|
|
130
131
|
//#region src/components/questions/Rating.d.ts
|
|
131
132
|
interface RatingProps extends BaseFieldProps {
|
|
@@ -160,7 +161,7 @@ declare const Rating: ({
|
|
|
160
161
|
id,
|
|
161
162
|
error,
|
|
162
163
|
required
|
|
163
|
-
}: RatingProps) =>
|
|
164
|
+
}: RatingProps) => react_jsx_runtime3.JSX.Element;
|
|
164
165
|
//#endregion
|
|
165
166
|
//#region src/components/questions/FreeText.d.ts
|
|
166
167
|
interface FreeTextProps extends BaseFieldProps {
|
|
@@ -184,7 +185,7 @@ declare const FreeText: ({
|
|
|
184
185
|
classNames,
|
|
185
186
|
required,
|
|
186
187
|
error
|
|
187
|
-
}: FreeTextProps) =>
|
|
188
|
+
}: FreeTextProps) => react_jsx_runtime3.JSX.Element;
|
|
188
189
|
//#endregion
|
|
189
190
|
//#region src/components/questions/SingleChoice.d.ts
|
|
190
191
|
interface SingleChoiceProps extends BaseFieldProps {
|
|
@@ -214,7 +215,7 @@ declare const SingleChoice: ({
|
|
|
214
215
|
id,
|
|
215
216
|
required,
|
|
216
217
|
error
|
|
217
|
-
}: SingleChoiceProps) =>
|
|
218
|
+
}: SingleChoiceProps) => react_jsx_runtime3.JSX.Element;
|
|
218
219
|
//#endregion
|
|
219
220
|
//#region src/components/questions/MultiChoice.d.ts
|
|
220
221
|
interface MultiChoiceProps extends BaseFieldProps {
|
|
@@ -247,7 +248,7 @@ declare const MultiChoice: ({
|
|
|
247
248
|
id,
|
|
248
249
|
required,
|
|
249
250
|
error
|
|
250
|
-
}: MultiChoiceProps) =>
|
|
251
|
+
}: MultiChoiceProps) => react_jsx_runtime3.JSX.Element;
|
|
251
252
|
//#endregion
|
|
252
253
|
//#region src/components/questions/Statement.d.ts
|
|
253
254
|
interface StatementProps extends BaseFieldProps {
|
|
@@ -265,7 +266,7 @@ declare const Statement: ({
|
|
|
265
266
|
title,
|
|
266
267
|
description,
|
|
267
268
|
classNames
|
|
268
|
-
}: StatementProps) =>
|
|
269
|
+
}: StatementProps) => react_jsx_runtime3.JSX.Element;
|
|
269
270
|
//#endregion
|
|
270
271
|
//#region src/components/presentation/Flow.d.ts
|
|
271
272
|
type ChildField = (_: {
|
|
@@ -284,7 +285,7 @@ declare const Flow: ({
|
|
|
284
285
|
children,
|
|
285
286
|
question,
|
|
286
287
|
isLastQuestion
|
|
287
|
-
}: FlowProps) =>
|
|
288
|
+
}: FlowProps) => react_jsx_runtime3.JSX.Element;
|
|
288
289
|
//#endregion
|
|
289
290
|
//#region src/components/presentation/Embed.d.ts
|
|
290
291
|
declare const Embed: ({
|
|
@@ -294,10 +295,10 @@ declare const Embed: ({
|
|
|
294
295
|
}: PropsWithChildren<{
|
|
295
296
|
isCompleted: boolean;
|
|
296
297
|
onSubmit: () => void;
|
|
297
|
-
}>) =>
|
|
298
|
+
}>) => react_jsx_runtime3.JSX.Element;
|
|
298
299
|
//#endregion
|
|
299
300
|
//#region src/templates/EmbeddedConfetti.d.ts
|
|
300
|
-
declare const EmbeddedConfetti: (props: ConfettiProps) =>
|
|
301
|
+
declare const EmbeddedConfetti: (props: ConfettiProps) => react_jsx_runtime3.JSX.Element;
|
|
301
302
|
//#endregion
|
|
302
303
|
//#region src/templates/PopoverConfetti.d.ts
|
|
303
304
|
interface PopoverConfettiProps extends ConfettiProps {
|
|
@@ -317,10 +318,10 @@ declare const PopoverConfetti: ({
|
|
|
317
318
|
onDismiss,
|
|
318
319
|
closeOnFinishMs,
|
|
319
320
|
...props
|
|
320
|
-
}: PopoverConfettiProps) =>
|
|
321
|
+
}: PopoverConfettiProps) => react_jsx_runtime3.JSX.Element;
|
|
321
322
|
//#endregion
|
|
322
323
|
//#region src/templates/StepperConfetti.d.ts
|
|
323
|
-
declare const StepperConfetti: (props: ConfettiProps) =>
|
|
324
|
+
declare const StepperConfetti: (props: ConfettiProps) => react_jsx_runtime3.JSX.Element;
|
|
324
325
|
//#endregion
|
|
325
326
|
//#region src/hooks/useVisibleAfterDelay.d.ts
|
|
326
327
|
interface UseVisibleAfterDelayOptions {
|
package/build/index.js
CHANGED
|
@@ -177,7 +177,12 @@ const publicPutResponseInputSchema = z.object({
|
|
|
177
177
|
])),
|
|
178
178
|
metadata: z.record(z.string().check(z.trim(), z.maxLength(1e3)), z.string().check(z.trim(), z.maxLength(1e3)))
|
|
179
179
|
});
|
|
180
|
-
const publicGetRespondentOutputSchema = z.object({
|
|
180
|
+
const publicGetRespondentOutputSchema = z.object({
|
|
181
|
+
lastRespondedAt: z.nullable(z.union([z.iso.datetime(), z.date()])),
|
|
182
|
+
lastViewedAt: z.nullable(z.union([z.iso.datetime(), z.date()])),
|
|
183
|
+
lastDismissedAt: z.nullable(z.union([z.iso.datetime(), z.date()]))
|
|
184
|
+
});
|
|
185
|
+
const publicPostRespondentEventInputSchema = z.object({ type: z.enum(["view", "dismiss"]) });
|
|
181
186
|
|
|
182
187
|
//#endregion
|
|
183
188
|
//#region src/core/logic/api.ts
|
|
@@ -194,15 +199,18 @@ const client = ky.create({
|
|
|
194
199
|
//#endregion
|
|
195
200
|
//#region src/core/ConfettiProvider.tsx
|
|
196
201
|
const ConfettiContext = createContext(null);
|
|
197
|
-
const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, metadata = {}, isSurveyVisible: isSurveyVisibleInput, apiBaseUrl }) => {
|
|
202
|
+
const ConfettiProvider = ({ children, surveyId, publishableKey, respondent: respondentInput, metadata = {}, isSurveyVisible: isSurveyVisibleInput, apiBaseUrl }) => {
|
|
203
|
+
const hasTrackedViewRef = useRef(false);
|
|
198
204
|
const [survey, setSurvey] = useState();
|
|
199
205
|
const [lastRespondedAt, setLastRespondedAt] = useState();
|
|
206
|
+
const [lastDismissedAt, setLastDismissedAt] = useState();
|
|
200
207
|
const responseId = useMemo(() => crypto.randomUUID(), []);
|
|
201
208
|
const [internalRespondentId, setInternalRespondentId] = useLocalStorage(`cfti:${surveyId}:respondent`, "");
|
|
202
209
|
useEffect(() => {
|
|
203
210
|
if (internalRespondentId) return;
|
|
204
211
|
setInternalRespondentId(crypto.randomUUID());
|
|
205
212
|
}, [internalRespondentId, setInternalRespondentId]);
|
|
213
|
+
const respondent = useMemo(() => respondentInput || internalRespondentId, [respondentInput, internalRespondentId]);
|
|
206
214
|
const client$1 = useMemo(() => {
|
|
207
215
|
const properties = { headers: { "x-cfti-pk": publishableKey } };
|
|
208
216
|
if (apiBaseUrl) properties.prefixUrl = apiBaseUrl;
|
|
@@ -214,14 +222,16 @@ const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, meta
|
|
|
214
222
|
if (!parseResult.success) return;
|
|
215
223
|
setSurvey(parseResult.data);
|
|
216
224
|
});
|
|
217
|
-
if (!respondent
|
|
218
|
-
client$1.get(`v1/cfti/${surveyId}/respondent/${respondent
|
|
225
|
+
if (!respondent) return;
|
|
226
|
+
client$1.get(`v1/cfti/${surveyId}/respondent/${respondent}`).json().then((data) => {
|
|
219
227
|
const parseResult = publicGetRespondentOutputSchema.safeParse(data);
|
|
220
228
|
if (!parseResult.success) {
|
|
221
229
|
setLastRespondedAt(null);
|
|
230
|
+
setLastDismissedAt(null);
|
|
222
231
|
return;
|
|
223
232
|
}
|
|
224
233
|
setLastRespondedAt(parseResult.data.lastRespondedAt ? new Date(parseResult.data.lastRespondedAt) : null);
|
|
234
|
+
setLastDismissedAt(parseResult.data.lastDismissedAt ? new Date(parseResult.data.lastDismissedAt) : null);
|
|
225
235
|
});
|
|
226
236
|
}, [
|
|
227
237
|
apiBaseUrl,
|
|
@@ -232,13 +242,12 @@ const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, meta
|
|
|
232
242
|
]);
|
|
233
243
|
const submit = useCallback(async ({ answers }) => {
|
|
234
244
|
await client$1.put(`v1/cfti/${surveyId}/response/${responseId}`, { json: {
|
|
235
|
-
respondent
|
|
245
|
+
respondent,
|
|
236
246
|
data: answers,
|
|
237
247
|
metadata
|
|
238
248
|
} });
|
|
239
249
|
}, [
|
|
240
250
|
client$1,
|
|
241
|
-
internalRespondentId,
|
|
242
251
|
metadata,
|
|
243
252
|
respondent,
|
|
244
253
|
responseId,
|
|
@@ -246,13 +255,38 @@ const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, meta
|
|
|
246
255
|
]);
|
|
247
256
|
const dismiss = useCallback(() => {
|
|
248
257
|
setSurvey(void 0);
|
|
249
|
-
|
|
250
|
-
|
|
258
|
+
client$1.post(`v1/cfti/${surveyId}/respondent/${respondent}/event`, { json: { type: "dismiss" } }).catch(() => {});
|
|
259
|
+
}, [
|
|
260
|
+
client$1,
|
|
261
|
+
respondent,
|
|
262
|
+
surveyId
|
|
263
|
+
]);
|
|
264
|
+
const isSurveyVisible = useMemo(() => {
|
|
251
265
|
if (isSurveyVisibleInput === void 0) return true;
|
|
252
266
|
if (typeof isSurveyVisibleInput === "boolean") return isSurveyVisibleInput;
|
|
253
|
-
if (lastRespondedAt === void 0) return false;
|
|
254
|
-
return isSurveyVisibleInput({
|
|
255
|
-
|
|
267
|
+
if (lastRespondedAt === void 0 || lastDismissedAt === void 0) return false;
|
|
268
|
+
return isSurveyVisibleInput({
|
|
269
|
+
lastRespondedAt,
|
|
270
|
+
lastDismissedAt
|
|
271
|
+
});
|
|
272
|
+
}, [
|
|
273
|
+
isSurveyVisibleInput,
|
|
274
|
+
lastRespondedAt,
|
|
275
|
+
lastDismissedAt
|
|
276
|
+
]);
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (hasTrackedViewRef.current) return;
|
|
279
|
+
if (isSurveyVisible) {
|
|
280
|
+
hasTrackedViewRef.current = true;
|
|
281
|
+
client$1.post(`v1/cfti/${surveyId}/respondent/${respondent}/event`, { json: { type: "view" } }).catch(() => {});
|
|
282
|
+
}
|
|
283
|
+
}, [
|
|
284
|
+
client$1,
|
|
285
|
+
isSurveyVisible,
|
|
286
|
+
respondent,
|
|
287
|
+
surveyId
|
|
288
|
+
]);
|
|
289
|
+
if (!isSurveyVisible || !survey) return null;
|
|
256
290
|
return /* @__PURE__ */ jsx(ConfettiContext.Provider, {
|
|
257
291
|
value: {
|
|
258
292
|
submit,
|