@betterinternship/components 1.4.0 → 1.4.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/hooks/useClientProcess.d.ts +17 -18
- package/dist/index.esm.js +344 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +5 -1
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
type ProcessStatus = "pending" | "handled" | "failed";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* * Note to self and devs: we use a callback system to keep the return values of the processes safe.
|
|
8
|
-
* * The job of the callback route is to filter the output of the process.
|
|
9
|
-
*/
|
|
10
|
-
interface UseAsyncProcessOptions {
|
|
2
|
+
export interface ProcessCallbackDto {
|
|
3
|
+
processId: string;
|
|
4
|
+
processName: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ProcessResponse {
|
|
11
7
|
processId: string;
|
|
12
8
|
processName: string;
|
|
13
9
|
processCallbackUrl: string;
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
success: boolean;
|
|
11
|
+
message?: string;
|
|
16
12
|
}
|
|
17
13
|
/**
|
|
18
|
-
*
|
|
14
|
+
* A simpler version, where u just pass the async function that returns process data.
|
|
19
15
|
*
|
|
20
|
-
* @
|
|
21
|
-
* @param UseAsyncProcessOptions
|
|
16
|
+
* @param caller
|
|
22
17
|
* @returns
|
|
23
18
|
*/
|
|
24
|
-
export declare function useClientProcess<T>({
|
|
25
|
-
|
|
19
|
+
export declare function useClientProcess<T, R>({ caller, loadingMessage, successMessage, failureMessage }: {
|
|
20
|
+
caller: (inputs: T) => Promise<ProcessResponse>;
|
|
21
|
+
loadingMessage?: string;
|
|
22
|
+
successMessage?: string;
|
|
23
|
+
failureMessage?: string;
|
|
24
|
+
}): {
|
|
25
|
+
run: (inputs: T) => Promise<void>;
|
|
26
26
|
attempts: number;
|
|
27
|
+
status: ProcessStatus;
|
|
27
28
|
result: unknown;
|
|
28
|
-
error: string | undefined;
|
|
29
|
-
isFetching: boolean;
|
|
30
29
|
};
|
|
31
30
|
export {};
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { useState, useRef } from 'react';
|
|
3
|
+
import React__default, { useState, useEffect, useRef } from 'react';
|
|
4
4
|
import { useQuery } from '@tanstack/react-query';
|
|
5
|
+
import 'react-dom';
|
|
5
6
|
|
|
6
7
|
function styleInject(css, ref) {
|
|
7
8
|
if ( ref === void 0 ) ref = {};
|
|
@@ -3322,6 +3323,301 @@ const Button = React__default.forwardRef(({ className, variant, scheme, size, as
|
|
|
3322
3323
|
});
|
|
3323
3324
|
Button.displayName = "Button";
|
|
3324
3325
|
|
|
3326
|
+
function __insertCSS(code) {
|
|
3327
|
+
if (typeof document == 'undefined') return
|
|
3328
|
+
let head = document.head || document.getElementsByTagName('head')[0];
|
|
3329
|
+
let style = document.createElement('style');
|
|
3330
|
+
style.type = 'text/css';
|
|
3331
|
+
head.appendChild(style)
|
|
3332
|
+
;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code));
|
|
3333
|
+
}
|
|
3334
|
+
Array(12).fill(0);
|
|
3335
|
+
|
|
3336
|
+
let toastsCounter = 1;
|
|
3337
|
+
class Observer {
|
|
3338
|
+
constructor(){
|
|
3339
|
+
// We use arrow functions to maintain the correct `this` reference
|
|
3340
|
+
this.subscribe = (subscriber)=>{
|
|
3341
|
+
this.subscribers.push(subscriber);
|
|
3342
|
+
return ()=>{
|
|
3343
|
+
const index = this.subscribers.indexOf(subscriber);
|
|
3344
|
+
this.subscribers.splice(index, 1);
|
|
3345
|
+
};
|
|
3346
|
+
};
|
|
3347
|
+
this.publish = (data)=>{
|
|
3348
|
+
this.subscribers.forEach((subscriber)=>subscriber(data));
|
|
3349
|
+
};
|
|
3350
|
+
this.addToast = (data)=>{
|
|
3351
|
+
this.publish(data);
|
|
3352
|
+
this.toasts = [
|
|
3353
|
+
...this.toasts,
|
|
3354
|
+
data
|
|
3355
|
+
];
|
|
3356
|
+
};
|
|
3357
|
+
this.create = (data)=>{
|
|
3358
|
+
var _data_id;
|
|
3359
|
+
const { message, ...rest } = data;
|
|
3360
|
+
const id = typeof (data == null ? void 0 : data.id) === 'number' || ((_data_id = data.id) == null ? void 0 : _data_id.length) > 0 ? data.id : toastsCounter++;
|
|
3361
|
+
const alreadyExists = this.toasts.find((toast)=>{
|
|
3362
|
+
return toast.id === id;
|
|
3363
|
+
});
|
|
3364
|
+
const dismissible = data.dismissible === undefined ? true : data.dismissible;
|
|
3365
|
+
if (this.dismissedToasts.has(id)) {
|
|
3366
|
+
this.dismissedToasts.delete(id);
|
|
3367
|
+
}
|
|
3368
|
+
if (alreadyExists) {
|
|
3369
|
+
this.toasts = this.toasts.map((toast)=>{
|
|
3370
|
+
if (toast.id === id) {
|
|
3371
|
+
this.publish({
|
|
3372
|
+
...toast,
|
|
3373
|
+
...data,
|
|
3374
|
+
id,
|
|
3375
|
+
title: message
|
|
3376
|
+
});
|
|
3377
|
+
return {
|
|
3378
|
+
...toast,
|
|
3379
|
+
...data,
|
|
3380
|
+
id,
|
|
3381
|
+
dismissible,
|
|
3382
|
+
title: message
|
|
3383
|
+
};
|
|
3384
|
+
}
|
|
3385
|
+
return toast;
|
|
3386
|
+
});
|
|
3387
|
+
} else {
|
|
3388
|
+
this.addToast({
|
|
3389
|
+
title: message,
|
|
3390
|
+
...rest,
|
|
3391
|
+
dismissible,
|
|
3392
|
+
id
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
return id;
|
|
3396
|
+
};
|
|
3397
|
+
this.dismiss = (id)=>{
|
|
3398
|
+
if (id) {
|
|
3399
|
+
this.dismissedToasts.add(id);
|
|
3400
|
+
requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
|
|
3401
|
+
id,
|
|
3402
|
+
dismiss: true
|
|
3403
|
+
})));
|
|
3404
|
+
} else {
|
|
3405
|
+
this.toasts.forEach((toast)=>{
|
|
3406
|
+
this.subscribers.forEach((subscriber)=>subscriber({
|
|
3407
|
+
id: toast.id,
|
|
3408
|
+
dismiss: true
|
|
3409
|
+
}));
|
|
3410
|
+
});
|
|
3411
|
+
}
|
|
3412
|
+
return id;
|
|
3413
|
+
};
|
|
3414
|
+
this.message = (message, data)=>{
|
|
3415
|
+
return this.create({
|
|
3416
|
+
...data,
|
|
3417
|
+
message
|
|
3418
|
+
});
|
|
3419
|
+
};
|
|
3420
|
+
this.error = (message, data)=>{
|
|
3421
|
+
return this.create({
|
|
3422
|
+
...data,
|
|
3423
|
+
message,
|
|
3424
|
+
type: 'error'
|
|
3425
|
+
});
|
|
3426
|
+
};
|
|
3427
|
+
this.success = (message, data)=>{
|
|
3428
|
+
return this.create({
|
|
3429
|
+
...data,
|
|
3430
|
+
type: 'success',
|
|
3431
|
+
message
|
|
3432
|
+
});
|
|
3433
|
+
};
|
|
3434
|
+
this.info = (message, data)=>{
|
|
3435
|
+
return this.create({
|
|
3436
|
+
...data,
|
|
3437
|
+
type: 'info',
|
|
3438
|
+
message
|
|
3439
|
+
});
|
|
3440
|
+
};
|
|
3441
|
+
this.warning = (message, data)=>{
|
|
3442
|
+
return this.create({
|
|
3443
|
+
...data,
|
|
3444
|
+
type: 'warning',
|
|
3445
|
+
message
|
|
3446
|
+
});
|
|
3447
|
+
};
|
|
3448
|
+
this.loading = (message, data)=>{
|
|
3449
|
+
return this.create({
|
|
3450
|
+
...data,
|
|
3451
|
+
type: 'loading',
|
|
3452
|
+
message
|
|
3453
|
+
});
|
|
3454
|
+
};
|
|
3455
|
+
this.promise = (promise, data)=>{
|
|
3456
|
+
if (!data) {
|
|
3457
|
+
// Nothing to show
|
|
3458
|
+
return;
|
|
3459
|
+
}
|
|
3460
|
+
let id = undefined;
|
|
3461
|
+
if (data.loading !== undefined) {
|
|
3462
|
+
id = this.create({
|
|
3463
|
+
...data,
|
|
3464
|
+
promise,
|
|
3465
|
+
type: 'loading',
|
|
3466
|
+
message: data.loading,
|
|
3467
|
+
description: typeof data.description !== 'function' ? data.description : undefined
|
|
3468
|
+
});
|
|
3469
|
+
}
|
|
3470
|
+
const p = Promise.resolve(promise instanceof Function ? promise() : promise);
|
|
3471
|
+
let shouldDismiss = id !== undefined;
|
|
3472
|
+
let result;
|
|
3473
|
+
const originalPromise = p.then(async (response)=>{
|
|
3474
|
+
result = [
|
|
3475
|
+
'resolve',
|
|
3476
|
+
response
|
|
3477
|
+
];
|
|
3478
|
+
const isReactElementResponse = React__default.isValidElement(response);
|
|
3479
|
+
if (isReactElementResponse) {
|
|
3480
|
+
shouldDismiss = false;
|
|
3481
|
+
this.create({
|
|
3482
|
+
id,
|
|
3483
|
+
type: 'default',
|
|
3484
|
+
message: response
|
|
3485
|
+
});
|
|
3486
|
+
} else if (isHttpResponse(response) && !response.ok) {
|
|
3487
|
+
shouldDismiss = false;
|
|
3488
|
+
const promiseData = typeof data.error === 'function' ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
|
|
3489
|
+
const description = typeof data.description === 'function' ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
|
|
3490
|
+
const isExtendedResult = typeof promiseData === 'object' && !React__default.isValidElement(promiseData);
|
|
3491
|
+
const toastSettings = isExtendedResult ? promiseData : {
|
|
3492
|
+
message: promiseData
|
|
3493
|
+
};
|
|
3494
|
+
this.create({
|
|
3495
|
+
id,
|
|
3496
|
+
type: 'error',
|
|
3497
|
+
description,
|
|
3498
|
+
...toastSettings
|
|
3499
|
+
});
|
|
3500
|
+
} else if (response instanceof Error) {
|
|
3501
|
+
shouldDismiss = false;
|
|
3502
|
+
const promiseData = typeof data.error === 'function' ? await data.error(response) : data.error;
|
|
3503
|
+
const description = typeof data.description === 'function' ? await data.description(response) : data.description;
|
|
3504
|
+
const isExtendedResult = typeof promiseData === 'object' && !React__default.isValidElement(promiseData);
|
|
3505
|
+
const toastSettings = isExtendedResult ? promiseData : {
|
|
3506
|
+
message: promiseData
|
|
3507
|
+
};
|
|
3508
|
+
this.create({
|
|
3509
|
+
id,
|
|
3510
|
+
type: 'error',
|
|
3511
|
+
description,
|
|
3512
|
+
...toastSettings
|
|
3513
|
+
});
|
|
3514
|
+
} else if (data.success !== undefined) {
|
|
3515
|
+
shouldDismiss = false;
|
|
3516
|
+
const promiseData = typeof data.success === 'function' ? await data.success(response) : data.success;
|
|
3517
|
+
const description = typeof data.description === 'function' ? await data.description(response) : data.description;
|
|
3518
|
+
const isExtendedResult = typeof promiseData === 'object' && !React__default.isValidElement(promiseData);
|
|
3519
|
+
const toastSettings = isExtendedResult ? promiseData : {
|
|
3520
|
+
message: promiseData
|
|
3521
|
+
};
|
|
3522
|
+
this.create({
|
|
3523
|
+
id,
|
|
3524
|
+
type: 'success',
|
|
3525
|
+
description,
|
|
3526
|
+
...toastSettings
|
|
3527
|
+
});
|
|
3528
|
+
}
|
|
3529
|
+
}).catch(async (error)=>{
|
|
3530
|
+
result = [
|
|
3531
|
+
'reject',
|
|
3532
|
+
error
|
|
3533
|
+
];
|
|
3534
|
+
if (data.error !== undefined) {
|
|
3535
|
+
shouldDismiss = false;
|
|
3536
|
+
const promiseData = typeof data.error === 'function' ? await data.error(error) : data.error;
|
|
3537
|
+
const description = typeof data.description === 'function' ? await data.description(error) : data.description;
|
|
3538
|
+
const isExtendedResult = typeof promiseData === 'object' && !React__default.isValidElement(promiseData);
|
|
3539
|
+
const toastSettings = isExtendedResult ? promiseData : {
|
|
3540
|
+
message: promiseData
|
|
3541
|
+
};
|
|
3542
|
+
this.create({
|
|
3543
|
+
id,
|
|
3544
|
+
type: 'error',
|
|
3545
|
+
description,
|
|
3546
|
+
...toastSettings
|
|
3547
|
+
});
|
|
3548
|
+
}
|
|
3549
|
+
}).finally(()=>{
|
|
3550
|
+
if (shouldDismiss) {
|
|
3551
|
+
// Toast is still in load state (and will be indefinitely — dismiss it)
|
|
3552
|
+
this.dismiss(id);
|
|
3553
|
+
id = undefined;
|
|
3554
|
+
}
|
|
3555
|
+
data.finally == null ? void 0 : data.finally.call(data);
|
|
3556
|
+
});
|
|
3557
|
+
const unwrap = ()=>new Promise((resolve, reject)=>originalPromise.then(()=>result[0] === 'reject' ? reject(result[1]) : resolve(result[1])).catch(reject));
|
|
3558
|
+
if (typeof id !== 'string' && typeof id !== 'number') {
|
|
3559
|
+
// cannot Object.assign on undefined
|
|
3560
|
+
return {
|
|
3561
|
+
unwrap
|
|
3562
|
+
};
|
|
3563
|
+
} else {
|
|
3564
|
+
return Object.assign(id, {
|
|
3565
|
+
unwrap
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3569
|
+
this.custom = (jsx, data)=>{
|
|
3570
|
+
const id = (data == null ? void 0 : data.id) || toastsCounter++;
|
|
3571
|
+
this.create({
|
|
3572
|
+
jsx: jsx(id),
|
|
3573
|
+
id,
|
|
3574
|
+
...data
|
|
3575
|
+
});
|
|
3576
|
+
return id;
|
|
3577
|
+
};
|
|
3578
|
+
this.getActiveToasts = ()=>{
|
|
3579
|
+
return this.toasts.filter((toast)=>!this.dismissedToasts.has(toast.id));
|
|
3580
|
+
};
|
|
3581
|
+
this.subscribers = [];
|
|
3582
|
+
this.toasts = [];
|
|
3583
|
+
this.dismissedToasts = new Set();
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
const ToastState = new Observer();
|
|
3587
|
+
// bind this to the toast function
|
|
3588
|
+
const toastFunction = (message, data)=>{
|
|
3589
|
+
const id = (data == null ? void 0 : data.id) || toastsCounter++;
|
|
3590
|
+
ToastState.addToast({
|
|
3591
|
+
title: message,
|
|
3592
|
+
...data,
|
|
3593
|
+
id
|
|
3594
|
+
});
|
|
3595
|
+
return id;
|
|
3596
|
+
};
|
|
3597
|
+
const isHttpResponse = (data)=>{
|
|
3598
|
+
return data && typeof data === 'object' && 'ok' in data && typeof data.ok === 'boolean' && 'status' in data && typeof data.status === 'number';
|
|
3599
|
+
};
|
|
3600
|
+
const basicToast = toastFunction;
|
|
3601
|
+
const getHistory = ()=>ToastState.toasts;
|
|
3602
|
+
const getToasts = ()=>ToastState.getActiveToasts();
|
|
3603
|
+
// We use `Object.assign` to maintain the correct types as we would lose them otherwise
|
|
3604
|
+
const toast = Object.assign(basicToast, {
|
|
3605
|
+
success: ToastState.success,
|
|
3606
|
+
info: ToastState.info,
|
|
3607
|
+
warning: ToastState.warning,
|
|
3608
|
+
error: ToastState.error,
|
|
3609
|
+
custom: ToastState.custom,
|
|
3610
|
+
message: ToastState.message,
|
|
3611
|
+
promise: ToastState.promise,
|
|
3612
|
+
dismiss: ToastState.dismiss,
|
|
3613
|
+
loading: ToastState.loading
|
|
3614
|
+
}, {
|
|
3615
|
+
getHistory,
|
|
3616
|
+
getToasts
|
|
3617
|
+
});
|
|
3618
|
+
|
|
3619
|
+
__insertCSS("[data-sonner-toaster][dir=ltr],html[dir=ltr]{--toast-icon-margin-start:-3px;--toast-icon-margin-end:4px;--toast-svg-margin-start:-1px;--toast-svg-margin-end:0px;--toast-button-margin-start:auto;--toast-button-margin-end:0;--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}[data-sonner-toaster][dir=rtl],html[dir=rtl]{--toast-icon-margin-start:4px;--toast-icon-margin-end:-3px;--toast-svg-margin-start:0px;--toast-svg-margin-end:-1px;--toast-button-margin-start:0;--toast-button-margin-end:auto;--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:0;z-index:999999999;transition:transform .4s ease}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-rich-colors=true][data-sonner-toast][data-styled=true] [data-description]{color:inherit}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);background:var(--normal-bg);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast][data-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast][data-expanded=true]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]::before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y,0)) translateX(var(--swipe-amount-x,0));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width:600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg:#000;--normal-bg-hover:hsl(0, 0%, 12%);--normal-border:hsl(0, 0%, 20%);--normal-border-hover:hsl(0, 0%, 25%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size:16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:first-child{animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}");
|
|
3620
|
+
|
|
3325
3621
|
/**
|
|
3326
3622
|
* The orchestrator service to get the process from.
|
|
3327
3623
|
*
|
|
@@ -3357,7 +3653,7 @@ const processCallbackFetcher = (processId, processName, processCallbackUrl) => f
|
|
|
3357
3653
|
* @param UseAsyncProcessOptions
|
|
3358
3654
|
* @returns
|
|
3359
3655
|
*/
|
|
3360
|
-
function
|
|
3656
|
+
function useClientProcessBase({ processId, processName, processCallbackUrl, baseInterval = 1000, maxInterval = 30000, }) {
|
|
3361
3657
|
const [status, setStatus] = useState("pending");
|
|
3362
3658
|
const attemptRef = useRef(0);
|
|
3363
3659
|
const query = useQuery({
|
|
@@ -3385,7 +3681,7 @@ function useClientProcess({ processId, processName, processCallbackUrl, baseInte
|
|
|
3385
3681
|
return null;
|
|
3386
3682
|
},
|
|
3387
3683
|
// Fetching only works if the task hasn't been resolved
|
|
3388
|
-
enabled: !!processId &&
|
|
3684
|
+
enabled: !!processId && !!processName,
|
|
3389
3685
|
// Returns the next interval length to use to wait for fetch
|
|
3390
3686
|
refetchInterval: (query) => {
|
|
3391
3687
|
const data = query.state.data;
|
|
@@ -3404,6 +3700,51 @@ function useClientProcess({ processId, processName, processCallbackUrl, baseInte
|
|
|
3404
3700
|
isFetching: query.isFetching,
|
|
3405
3701
|
};
|
|
3406
3702
|
}
|
|
3703
|
+
/**
|
|
3704
|
+
* A simpler version, where u just pass the async function that returns process data.
|
|
3705
|
+
*
|
|
3706
|
+
* @param caller
|
|
3707
|
+
* @returns
|
|
3708
|
+
*/
|
|
3709
|
+
function useClientProcess({ caller, loadingMessage, successMessage, failureMessage }) {
|
|
3710
|
+
const [response, setResponse] = useState();
|
|
3711
|
+
const clientProcess = useClientProcessBase({
|
|
3712
|
+
processId: response?.processId,
|
|
3713
|
+
processName: response?.processName,
|
|
3714
|
+
processCallbackUrl: response?.processCallbackUrl,
|
|
3715
|
+
});
|
|
3716
|
+
useEffect(() => {
|
|
3717
|
+
if (!response?.processId)
|
|
3718
|
+
return;
|
|
3719
|
+
// Update toast to show current state
|
|
3720
|
+
if (clientProcess.status === 'pending') {
|
|
3721
|
+
toast.loading(loadingMessage ?? "Loading...", {
|
|
3722
|
+
id: response.processId,
|
|
3723
|
+
duration: Infinity,
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
else if (clientProcess.status === 'failed') {
|
|
3727
|
+
toast.error(failureMessage ?? "Something went wrong.", {
|
|
3728
|
+
id: response.processId
|
|
3729
|
+
});
|
|
3730
|
+
}
|
|
3731
|
+
else if (clientProcess.status === 'handled') {
|
|
3732
|
+
toast.success(successMessage ?? "Success!", {
|
|
3733
|
+
id: response.processId
|
|
3734
|
+
});
|
|
3735
|
+
}
|
|
3736
|
+
}, [response, clientProcess]);
|
|
3737
|
+
const wrappedCaller = async (inputs) => {
|
|
3738
|
+
const response = await caller(inputs);
|
|
3739
|
+
setResponse(response);
|
|
3740
|
+
};
|
|
3741
|
+
return {
|
|
3742
|
+
run: wrappedCaller,
|
|
3743
|
+
attempts: clientProcess.attempts,
|
|
3744
|
+
status: clientProcess.status,
|
|
3745
|
+
result: clientProcess.result
|
|
3746
|
+
};
|
|
3747
|
+
}
|
|
3407
3748
|
|
|
3408
3749
|
export { Button, buttonVariants, config, configure, useClientProcess };
|
|
3409
3750
|
//# sourceMappingURL=index.esm.js.map
|