@vanillabp/bc-shared 0.0.3
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/README.md +101 -0
- package/dist/chunk-YH4NJHER.js +58 -0
- package/dist/components/Badge.d.ts +12 -0
- package/dist/components/Badge.js +84 -0
- package/dist/components/CircleButton.d.ts +5 -0
- package/dist/components/CircleButton.js +47 -0
- package/dist/components/CopyClipboard.d.ts +21 -0
- package/dist/components/CopyClipboard.js +110 -0
- package/dist/components/DefaultListCell.d.ts +44 -0
- package/dist/components/DefaultListCell.js +179 -0
- package/dist/components/DefaultListHeader.d.ts +22 -0
- package/dist/components/DefaultListHeader.js +110 -0
- package/dist/components/Link.d.ts +10 -0
- package/dist/components/Link.js +34 -0
- package/dist/components/LoadingIndicator.d.ts +4 -0
- package/dist/components/LoadingIndicator.js +48 -0
- package/dist/components/ModalDialog.d.ts +16 -0
- package/dist/components/ModalDialog.js +108 -0
- package/dist/components/SseProvider.d.ts +46 -0
- package/dist/components/SseProvider.js +134 -0
- package/dist/components/Toast.d.ts +22 -0
- package/dist/components/Toast.js +30 -0
- package/dist/components/UserTaskAppLayout.d.ts +9 -0
- package/dist/components/UserTaskAppLayout.js +47 -0
- package/dist/components/WarningListCell.d.ts +6 -0
- package/dist/components/WarningListCell.js +39 -0
- package/dist/components/index.d.ts +20 -0
- package/dist/components/index.js +12 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +4 -0
- package/dist/stories/LoadingIndicator.stories.d.ts +9 -0
- package/dist/stories/LoadingIndicator.stories.js +18 -0
- package/dist/theme/index.d.ts +5 -0
- package/dist/theme/index.js +168 -0
- package/dist/types/BcUserTask.d.ts +12 -0
- package/dist/types/BcUserTask.js +1 -0
- package/dist/types/BcWorkflow.d.ts +11 -0
- package/dist/types/BcWorkflow.js +1 -0
- package/dist/types/ListCell.d.ts +30 -0
- package/dist/types/ListCell.js +15 -0
- package/dist/types/UserTaskForm.d.ts +10 -0
- package/dist/types/UserTaskForm.js +0 -0
- package/dist/types/UserTaskListCell.d.ts +16 -0
- package/dist/types/UserTaskListCell.js +0 -0
- package/dist/types/WorkflowListCell.d.ts +17 -0
- package/dist/types/WorkflowListCell.js +0 -0
- package/dist/types/WorkflowPage.d.ts +11 -0
- package/dist/types/WorkflowPage.js +0 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +8 -0
- package/dist/types/translate.d.ts +3 -0
- package/dist/types/translate.js +0 -0
- package/dist/utils/clickOutside.d.ts +6 -0
- package/dist/utils/clickOutside.js +20 -0
- package/dist/utils/debounce.d.ts +9 -0
- package/dist/utils/debounce.js +27 -0
- package/dist/utils/fetchApi.d.ts +10 -0
- package/dist/utils/fetchApi.js +76 -0
- package/dist/utils/i18n.d.ts +3 -0
- package/dist/utils/i18n.js +5 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/now-hook.d.ts +7 -0
- package/dist/utils/now-hook.js +30 -0
- package/dist/utils/objectUtils.d.ts +5 -0
- package/dist/utils/objectUtils.js +95 -0
- package/dist/utils/responsiveUtils.d.ts +13 -0
- package/dist/utils/responsiveUtils.js +18 -0
- package/dist/utils/timeUtils.d.ts +14 -0
- package/dist/utils/timeUtils.js +107 -0
- package/package.json +76 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import "../chunk-YH4NJHER.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Box, CheckBox, Text, Tip } from "grommet";
|
|
4
|
+
import { Ascend, ContactInfo, Descend, Unsorted } from "grommet-icons";
|
|
5
|
+
const DefaultListHeader = ({
|
|
6
|
+
column,
|
|
7
|
+
currentLanguage,
|
|
8
|
+
sort,
|
|
9
|
+
sortAscending,
|
|
10
|
+
setSort,
|
|
11
|
+
setSortAscending,
|
|
12
|
+
allSelected,
|
|
13
|
+
selectAll
|
|
14
|
+
}) => {
|
|
15
|
+
if (column.path === "id") {
|
|
16
|
+
return /* @__PURE__ */ jsx(
|
|
17
|
+
Box,
|
|
18
|
+
{
|
|
19
|
+
fill: true,
|
|
20
|
+
pad: "xsmall",
|
|
21
|
+
align: "center",
|
|
22
|
+
children: /* @__PURE__ */ jsx(
|
|
23
|
+
CheckBox,
|
|
24
|
+
{
|
|
25
|
+
checked: allSelected,
|
|
26
|
+
onChange: (event) => selectAll(event.currentTarget.checked)
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (column.path === "candidateUsers") {
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
Box,
|
|
35
|
+
{
|
|
36
|
+
pad: "xsmall",
|
|
37
|
+
fill: true,
|
|
38
|
+
align: "center",
|
|
39
|
+
children: /* @__PURE__ */ jsx(
|
|
40
|
+
Tip,
|
|
41
|
+
{
|
|
42
|
+
content: column.title[currentLanguage] || column.title["en"],
|
|
43
|
+
children: /* @__PURE__ */ jsx(ContactInfo, {})
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return /* @__PURE__ */ jsxs(
|
|
50
|
+
Box,
|
|
51
|
+
{
|
|
52
|
+
fill: true,
|
|
53
|
+
direction: "row",
|
|
54
|
+
justify: "between",
|
|
55
|
+
pad: "xsmall",
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ jsx(
|
|
58
|
+
Text,
|
|
59
|
+
{
|
|
60
|
+
truncate: "tip",
|
|
61
|
+
children: column.title[currentLanguage] || column.title["en"]
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
/* @__PURE__ */ jsx(
|
|
65
|
+
Box,
|
|
66
|
+
{
|
|
67
|
+
align: "center",
|
|
68
|
+
direction: "row",
|
|
69
|
+
justify: "end",
|
|
70
|
+
style: { maxHeight: "1.5rem", minWidth: "2rem" },
|
|
71
|
+
children: !column.sortable ? void 0 : !Boolean(sort) ? /* @__PURE__ */ jsx(
|
|
72
|
+
Box,
|
|
73
|
+
{
|
|
74
|
+
overflow: "hidden",
|
|
75
|
+
focusIndicator: false,
|
|
76
|
+
width: "1.6rem",
|
|
77
|
+
onClick: (event) => setSort(column),
|
|
78
|
+
children: /* @__PURE__ */ jsx(
|
|
79
|
+
Unsorted,
|
|
80
|
+
{
|
|
81
|
+
size: "32rem"
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
) : sortAscending ? /* @__PURE__ */ jsx(
|
|
86
|
+
Box,
|
|
87
|
+
{
|
|
88
|
+
focusIndicator: false,
|
|
89
|
+
onClick: (event) => setSortAscending(false),
|
|
90
|
+
pad: { right: "0.5rem" },
|
|
91
|
+
children: /* @__PURE__ */ jsx(Ascend, { size: "16rem" })
|
|
92
|
+
}
|
|
93
|
+
) : /* @__PURE__ */ jsx(
|
|
94
|
+
Box,
|
|
95
|
+
{
|
|
96
|
+
focusIndicator: false,
|
|
97
|
+
onClick: (event) => setSort(void 0),
|
|
98
|
+
pad: { right: "0.5rem" },
|
|
99
|
+
children: /* @__PURE__ */ jsx(Descend, { size: "16rem" })
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
export {
|
|
109
|
+
DefaultListHeader
|
|
110
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TextProps } from 'grommet';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
interface LinkProps extends PropsWithChildren<TextProps> {
|
|
5
|
+
href?: string;
|
|
6
|
+
target?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const Link: ({ ...props }: LinkProps) => JSX.Element;
|
|
9
|
+
|
|
10
|
+
export { Link };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__objRest,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "../chunk-YH4NJHER.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { Text } from "grommet";
|
|
7
|
+
import styled from "styled-components";
|
|
8
|
+
;
|
|
9
|
+
const StyledLink = styled(Text)`
|
|
10
|
+
text-decoration: none;
|
|
11
|
+
color: ${(props) => props.theme.global.colors["accent-3"]};
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
|
|
14
|
+
&:hover {
|
|
15
|
+
text-decoration: underline;
|
|
16
|
+
color: black;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&:visited {
|
|
20
|
+
color: ${(props) => props.theme.global.colors["accent-3"]};
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
const Link = (_a) => {
|
|
24
|
+
var props = __objRest(_a, []);
|
|
25
|
+
return /* @__PURE__ */ jsx(
|
|
26
|
+
StyledLink,
|
|
27
|
+
__spreadValues({
|
|
28
|
+
as: "a"
|
|
29
|
+
}, props)
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
Link
|
|
34
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import "../chunk-YH4NJHER.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Box, Layer, Spinner } from "grommet";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
const NoFocusIndicatorLayer = styled(Layer)`
|
|
6
|
+
a:focus {
|
|
7
|
+
outline: none;
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
const LoadingIndicator = () => /* @__PURE__ */ jsx(
|
|
11
|
+
NoFocusIndicatorLayer,
|
|
12
|
+
{
|
|
13
|
+
plain: true,
|
|
14
|
+
animate: false,
|
|
15
|
+
background: { color: "rgba(0, 0, 0, 0)" },
|
|
16
|
+
responsive: false,
|
|
17
|
+
modal: true,
|
|
18
|
+
children: /* @__PURE__ */ jsx(
|
|
19
|
+
Box,
|
|
20
|
+
{
|
|
21
|
+
round: "medium",
|
|
22
|
+
background: { color: "rgba(0, 0, 0, 0.3)" },
|
|
23
|
+
children: /* @__PURE__ */ jsx(
|
|
24
|
+
Box,
|
|
25
|
+
{
|
|
26
|
+
animation: "rotateRight",
|
|
27
|
+
pad: "medium",
|
|
28
|
+
children: /* @__PURE__ */ jsx(
|
|
29
|
+
Spinner,
|
|
30
|
+
{
|
|
31
|
+
size: "medium",
|
|
32
|
+
border: [
|
|
33
|
+
{ side: "all", color: "rgba(0, 0, 0, 0)", size: "medium" },
|
|
34
|
+
{ side: "right", color: "white", size: "medium" },
|
|
35
|
+
{ side: "top", color: "white", size: "medium" },
|
|
36
|
+
{ side: "left", color: "white", size: "medium" }
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
export {
|
|
47
|
+
LoadingIndicator
|
|
48
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { BoxProps } from 'grommet';
|
|
3
|
+
import { TFunction } from 'i18next';
|
|
4
|
+
|
|
5
|
+
interface ModalProperties extends BoxProps {
|
|
6
|
+
show: boolean;
|
|
7
|
+
header?: string | JSX.Element;
|
|
8
|
+
abort?: () => void;
|
|
9
|
+
action?: () => void;
|
|
10
|
+
t: TFunction;
|
|
11
|
+
actionLabel?: string;
|
|
12
|
+
abortLabel?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const Modal: ({ show, header, abort, abortLabel, action, actionLabel, t, children, ...props }: PropsWithChildren<ModalProperties>) => JSX.Element;
|
|
15
|
+
|
|
16
|
+
export { Modal };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__objRest,
|
|
3
|
+
__spreadProps,
|
|
4
|
+
__spreadValues
|
|
5
|
+
} from "../chunk-YH4NJHER.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Box, Button, Heading, Layer } from "grommet";
|
|
8
|
+
;
|
|
9
|
+
const Modal = (_a) => {
|
|
10
|
+
var _b = _a, {
|
|
11
|
+
show,
|
|
12
|
+
header,
|
|
13
|
+
abort,
|
|
14
|
+
abortLabel = "abort",
|
|
15
|
+
action,
|
|
16
|
+
actionLabel,
|
|
17
|
+
t,
|
|
18
|
+
children
|
|
19
|
+
} = _b, props = __objRest(_b, [
|
|
20
|
+
"show",
|
|
21
|
+
"header",
|
|
22
|
+
"abort",
|
|
23
|
+
"abortLabel",
|
|
24
|
+
"action",
|
|
25
|
+
"actionLabel",
|
|
26
|
+
"t",
|
|
27
|
+
"children"
|
|
28
|
+
]);
|
|
29
|
+
if (!show)
|
|
30
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
Layer,
|
|
33
|
+
{
|
|
34
|
+
full: true,
|
|
35
|
+
animation: "fadeIn",
|
|
36
|
+
background: { color: "dark-1", opacity: true },
|
|
37
|
+
onEsc: abort,
|
|
38
|
+
responsive: true,
|
|
39
|
+
modal: true,
|
|
40
|
+
children: /* @__PURE__ */ jsx(
|
|
41
|
+
Box,
|
|
42
|
+
{
|
|
43
|
+
height: "100%",
|
|
44
|
+
justify: "center",
|
|
45
|
+
direction: "column",
|
|
46
|
+
children: /* @__PURE__ */ jsx(
|
|
47
|
+
Box,
|
|
48
|
+
{
|
|
49
|
+
justify: "center",
|
|
50
|
+
direction: "row",
|
|
51
|
+
pad: "medium",
|
|
52
|
+
children: /* @__PURE__ */ jsx(
|
|
53
|
+
Box,
|
|
54
|
+
__spreadProps(__spreadValues({
|
|
55
|
+
pad: "large",
|
|
56
|
+
background: "white"
|
|
57
|
+
}, props), {
|
|
58
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
59
|
+
header === void 0 ? void 0 : typeof header === "string" ? /* @__PURE__ */ jsx(
|
|
60
|
+
Heading,
|
|
61
|
+
{
|
|
62
|
+
margin: { vertical: "xsmall" },
|
|
63
|
+
level: "2",
|
|
64
|
+
children: t(header)
|
|
65
|
+
}
|
|
66
|
+
) : header,
|
|
67
|
+
children,
|
|
68
|
+
action || abort ? /* @__PURE__ */ jsxs(
|
|
69
|
+
Box,
|
|
70
|
+
{
|
|
71
|
+
direction: "row",
|
|
72
|
+
gap: "small",
|
|
73
|
+
margin: { bottom: "medium" },
|
|
74
|
+
align: "center",
|
|
75
|
+
justify: "around",
|
|
76
|
+
children: [
|
|
77
|
+
action && actionLabel ? /* @__PURE__ */ jsx(
|
|
78
|
+
Button,
|
|
79
|
+
{
|
|
80
|
+
label: t(actionLabel),
|
|
81
|
+
onClick: action,
|
|
82
|
+
primary: true
|
|
83
|
+
}
|
|
84
|
+
) : void 0,
|
|
85
|
+
abort ? /* @__PURE__ */ jsx(
|
|
86
|
+
Button,
|
|
87
|
+
{
|
|
88
|
+
label: t(abortLabel),
|
|
89
|
+
onClick: abort,
|
|
90
|
+
secondary: true
|
|
91
|
+
}
|
|
92
|
+
) : void 0
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
) : /* @__PURE__ */ jsx(Fragment, {})
|
|
96
|
+
] })
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
export {
|
|
107
|
+
Modal
|
|
108
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FetchEventSourceInit } from '@microsoft/fetch-event-source';
|
|
2
|
+
import React, { Context } from 'react';
|
|
3
|
+
|
|
4
|
+
declare type SseURL = string;
|
|
5
|
+
declare type SseConnectionID = string;
|
|
6
|
+
interface EventMessage<T> {
|
|
7
|
+
source: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
event: T;
|
|
10
|
+
}
|
|
11
|
+
interface EventSourceMessage<T> {
|
|
12
|
+
id: string;
|
|
13
|
+
event: string;
|
|
14
|
+
data: T;
|
|
15
|
+
retry?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* If SSE connection is lost (e.g. due to unreliable mobile network)
|
|
19
|
+
* then reconnect is retried every 15 seconds. In case of having
|
|
20
|
+
* a successful REST-call during that period, an SSE potentially
|
|
21
|
+
* caused by this REST-call would be lost. To avoid this situation
|
|
22
|
+
* the wakeup-callback can be used by REST-clients to trigger
|
|
23
|
+
* SSE reconnect immediately instead of waiting to the end of the
|
|
24
|
+
* 15 seconds period. If network is available the SSE connection
|
|
25
|
+
* will be established before doing the REST-call and therefore
|
|
26
|
+
* any potentially triggered SSE can be received and processed.
|
|
27
|
+
*/
|
|
28
|
+
declare type WakeupSseCallback = (() => void) | undefined;
|
|
29
|
+
declare type OnMessageFunction<T> = (ev: EventSourceMessage<T>) => void;
|
|
30
|
+
declare type GuiSseHook = <T>(onMessage: OnMessageFunction<T>, messageName?: string | RegExp) => WakeupSseCallback;
|
|
31
|
+
declare type GetConnectionFunction = (onMessage: OnMessageFunction<any>, messageName?: string | RegExp) => SseConnectionID;
|
|
32
|
+
declare type ReleaseConnectionFunction = (connectionId: SseConnectionID) => void;
|
|
33
|
+
declare type SseContextInterface = {
|
|
34
|
+
wakeupSseCallback: WakeupSseCallback;
|
|
35
|
+
getConnection: GetConnectionFunction;
|
|
36
|
+
releaseConnection: ReleaseConnectionFunction;
|
|
37
|
+
};
|
|
38
|
+
interface SseProviderProps extends Omit<FetchEventSourceInit, 'fetch'> {
|
|
39
|
+
Context: Context<SseContextInterface>;
|
|
40
|
+
buildFetchApi: () => WindowOrWorkerGlobalScope['fetch'];
|
|
41
|
+
url: SseURL;
|
|
42
|
+
}
|
|
43
|
+
declare const SseProvider: ({ url, Context, buildFetchApi, children, ...rest }: React.PropsWithChildren<SseProviderProps>) => JSX.Element;
|
|
44
|
+
declare const useSse: <T>(Context: React.Context<SseContextInterface>, onMessage: OnMessageFunction<T>, messageName?: string | RegExp) => WakeupSseCallback;
|
|
45
|
+
|
|
46
|
+
export { EventMessage, EventSourceMessage, GuiSseHook, OnMessageFunction, SseContextInterface, SseProvider, WakeupSseCallback, useSse };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__objRest,
|
|
3
|
+
__spreadProps,
|
|
4
|
+
__spreadValues
|
|
5
|
+
} from "../chunk-YH4NJHER.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import {
|
|
8
|
+
fetchEventSource
|
|
9
|
+
} from "@microsoft/fetch-event-source";
|
|
10
|
+
import { useContext, useEffect, useRef } from "react";
|
|
11
|
+
;
|
|
12
|
+
const onmessage = (ev, connections) => {
|
|
13
|
+
Object.keys(connections).map((connectionId) => connections[connectionId]).filter((onMessageSignature) => onMessageSignature === void 0 ? false : typeof onMessageSignature.messageName === "string" ? onMessageSignature.messageName === ev.event : onMessageSignature.messageName instanceof RegExp ? onMessageSignature.messageName.test(ev.event) : true).forEach((onMessageSignature) => {
|
|
14
|
+
try {
|
|
15
|
+
onMessageSignature.onMessage(
|
|
16
|
+
__spreadProps(__spreadValues({}, ev), {
|
|
17
|
+
data: parseJSONData(ev.data)
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error("Error on processing event", ev, e);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const parseJSONData = (data) => {
|
|
26
|
+
if (!Boolean(data)) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
return JSON.parse(data);
|
|
30
|
+
};
|
|
31
|
+
const SseProvider = (_a) => {
|
|
32
|
+
var _b = _a, { url, Context: Context2, buildFetchApi, children } = _b, rest = __objRest(_b, ["url", "Context", "buildFetchApi", "children"]);
|
|
33
|
+
const connections = useRef({});
|
|
34
|
+
const abortController = useRef(void 0);
|
|
35
|
+
const closeConnectionTimer = useRef(void 0);
|
|
36
|
+
const retryConnectTimer = useRef(void 0);
|
|
37
|
+
const lastConnectionId = useRef(0);
|
|
38
|
+
const releaseConnection = (connectionId) => {
|
|
39
|
+
delete connections.current[connectionId];
|
|
40
|
+
if (Object.keys(connections.current).length === 0) {
|
|
41
|
+
if (closeConnectionTimer.current !== void 0) {
|
|
42
|
+
window.clearTimeout(closeConnectionTimer.current);
|
|
43
|
+
}
|
|
44
|
+
closeConnectionTimer.current = window.setTimeout(() => {
|
|
45
|
+
var _a2;
|
|
46
|
+
(_a2 = abortController.current) == null ? void 0 : _a2.abort();
|
|
47
|
+
abortController.current = void 0;
|
|
48
|
+
closeConnectionTimer.current = void 0;
|
|
49
|
+
}, 5e3);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const buildEventSource = () => {
|
|
53
|
+
abortController.current = new AbortController();
|
|
54
|
+
fetchEventSource(
|
|
55
|
+
url,
|
|
56
|
+
__spreadValues({
|
|
57
|
+
// since we use locking fetch-api the server has to sent an
|
|
58
|
+
// ping-message immediatelly, to make the client release the lock
|
|
59
|
+
fetch: buildFetchApi(),
|
|
60
|
+
headers: {
|
|
61
|
+
"cache-control": "no-cache"
|
|
62
|
+
},
|
|
63
|
+
signal: abortController.current.signal,
|
|
64
|
+
onmessage: (ev) => onmessage(ev, connections.current),
|
|
65
|
+
openWhenHidden: true,
|
|
66
|
+
onclose: () => {
|
|
67
|
+
throw new Error();
|
|
68
|
+
},
|
|
69
|
+
onerror: (error) => {
|
|
70
|
+
throw new Error("retry", { cause: error });
|
|
71
|
+
}
|
|
72
|
+
}, rest)
|
|
73
|
+
).catch((reason) => {
|
|
74
|
+
if (reason.message === "retry") {
|
|
75
|
+
console.warn("Lost server connection, will rety in 15 seconds", reason.cause);
|
|
76
|
+
retryConnectTimer.current = window.setTimeout(buildEventSource, 15e3);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
console.log("Lost server connection reason and won't retry", reason);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const getConnection = (onMessage, messageName) => {
|
|
83
|
+
if (closeConnectionTimer.current !== void 0) {
|
|
84
|
+
window.clearTimeout(closeConnectionTimer.current);
|
|
85
|
+
closeConnectionTimer.current = void 0;
|
|
86
|
+
}
|
|
87
|
+
if (abortController.current === void 0) {
|
|
88
|
+
buildEventSource();
|
|
89
|
+
}
|
|
90
|
+
const connectionId = lastConnectionId.current.toString();
|
|
91
|
+
++lastConnectionId.current;
|
|
92
|
+
connections.current = __spreadProps(__spreadValues({}, connections.current), {
|
|
93
|
+
[connectionId]: {
|
|
94
|
+
onMessage,
|
|
95
|
+
messageName
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return connectionId;
|
|
99
|
+
};
|
|
100
|
+
const wakeupSseCallback = () => {
|
|
101
|
+
if (retryConnectTimer.current === void 0) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
window.clearTimeout(retryConnectTimer.current);
|
|
105
|
+
retryConnectTimer.current = void 0;
|
|
106
|
+
buildEventSource();
|
|
107
|
+
};
|
|
108
|
+
return /* @__PURE__ */ jsx(
|
|
109
|
+
Context2.Provider,
|
|
110
|
+
{
|
|
111
|
+
value: {
|
|
112
|
+
wakeupSseCallback,
|
|
113
|
+
getConnection,
|
|
114
|
+
releaseConnection
|
|
115
|
+
},
|
|
116
|
+
children
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
const useSse = (Context2, onMessage, messageName) => {
|
|
121
|
+
const sseContext = useContext(Context2);
|
|
122
|
+
useEffect(
|
|
123
|
+
() => {
|
|
124
|
+
const connectionId = sseContext.getConnection(onMessage, messageName);
|
|
125
|
+
return () => sseContext.releaseConnection(connectionId);
|
|
126
|
+
},
|
|
127
|
+
[sseContext, onMessage, messageName]
|
|
128
|
+
);
|
|
129
|
+
return sseContext.wakeupSseCallback;
|
|
130
|
+
};
|
|
131
|
+
export {
|
|
132
|
+
SseProvider,
|
|
133
|
+
useSse
|
|
134
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StatusType } from 'grommet';
|
|
2
|
+
import { Dispatch } from 'react';
|
|
3
|
+
|
|
4
|
+
declare type Toast = {
|
|
5
|
+
namespace: string;
|
|
6
|
+
title: string | undefined | null;
|
|
7
|
+
message: string;
|
|
8
|
+
status?: StatusType;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
};
|
|
11
|
+
declare type ToastAction = {
|
|
12
|
+
type: 'toast';
|
|
13
|
+
toast: Toast | undefined;
|
|
14
|
+
};
|
|
15
|
+
declare type ToastFunction = (toast: Toast) => void;
|
|
16
|
+
interface MessageToastProps {
|
|
17
|
+
dispatch: Dispatch<ToastAction>;
|
|
18
|
+
msg: Toast;
|
|
19
|
+
}
|
|
20
|
+
declare const MessageToast: ({ dispatch, msg }: MessageToastProps) => JSX.Element;
|
|
21
|
+
|
|
22
|
+
export { MessageToast, Toast, ToastAction, ToastFunction };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import "../chunk-YH4NJHER.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Notification } from "grommet";
|
|
4
|
+
import { useCallback, useEffect } from "react";
|
|
5
|
+
import { useTranslation } from "react-i18next";
|
|
6
|
+
;
|
|
7
|
+
const MessageToast = ({ dispatch, msg }) => {
|
|
8
|
+
const { t, i18n } = useTranslation(msg.namespace);
|
|
9
|
+
const close = useCallback(() => dispatch({ type: "toast", toast: void 0 }), [dispatch]);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
let timeout = msg.timeout !== void 0 ? msg.timeout : msg.message.length * 50;
|
|
12
|
+
if (timeout < 3e3)
|
|
13
|
+
timeout = 3e3;
|
|
14
|
+
const timer = window.setTimeout(close, timeout);
|
|
15
|
+
return () => window.clearTimeout(timer);
|
|
16
|
+
}, [msg, close]);
|
|
17
|
+
return /* @__PURE__ */ jsx(
|
|
18
|
+
Notification,
|
|
19
|
+
{
|
|
20
|
+
toast: { autoClose: false },
|
|
21
|
+
title: msg.title ? t(msg.title) : void 0,
|
|
22
|
+
message: t(msg.message),
|
|
23
|
+
status: msg.status ? msg.status : "unknown",
|
|
24
|
+
onClose: close
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
MessageToast
|
|
30
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface FrameProps {
|
|
4
|
+
header?: ReactNode | undefined;
|
|
5
|
+
footer?: ReactNode | undefined;
|
|
6
|
+
}
|
|
7
|
+
declare const UserTaskAppLayout: ({ header, footer, children }: PropsWithChildren<FrameProps>) => JSX.Element;
|
|
8
|
+
|
|
9
|
+
export { UserTaskAppLayout };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import "../chunk-YH4NJHER.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Box } from "grommet";
|
|
4
|
+
;
|
|
5
|
+
const UserTaskAppLayout = ({
|
|
6
|
+
header,
|
|
7
|
+
footer,
|
|
8
|
+
children
|
|
9
|
+
}) => {
|
|
10
|
+
return /* @__PURE__ */ jsxs(
|
|
11
|
+
Box,
|
|
12
|
+
{
|
|
13
|
+
direction: "column",
|
|
14
|
+
fill: true,
|
|
15
|
+
children: [
|
|
16
|
+
/* @__PURE__ */ jsx(
|
|
17
|
+
Box,
|
|
18
|
+
{
|
|
19
|
+
flex: "grow",
|
|
20
|
+
background: "light-4",
|
|
21
|
+
fill: "horizontal",
|
|
22
|
+
children: header
|
|
23
|
+
}
|
|
24
|
+
),
|
|
25
|
+
/* @__PURE__ */ jsx(
|
|
26
|
+
Box,
|
|
27
|
+
{
|
|
28
|
+
fill: true,
|
|
29
|
+
children
|
|
30
|
+
}
|
|
31
|
+
),
|
|
32
|
+
/* @__PURE__ */ jsx(
|
|
33
|
+
Box,
|
|
34
|
+
{
|
|
35
|
+
flex: "grow",
|
|
36
|
+
background: "light-4",
|
|
37
|
+
fill: "horizontal",
|
|
38
|
+
children: footer
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
UserTaskAppLayout
|
|
47
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "../chunk-YH4NJHER.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Box, Text } from "grommet";
|
|
4
|
+
import { Alert, StatusCritical } from "grommet-icons";
|
|
5
|
+
import { useResponsiveScreen } from "../utils/index.js";
|
|
6
|
+
const WarningListCell = ({
|
|
7
|
+
message,
|
|
8
|
+
error = false
|
|
9
|
+
}) => {
|
|
10
|
+
const { isNotPhone } = useResponsiveScreen();
|
|
11
|
+
const Icon = error ? StatusCritical : Alert;
|
|
12
|
+
const color = error ? "status-critical" : "status-warning";
|
|
13
|
+
return /* @__PURE__ */ jsxs(
|
|
14
|
+
Box,
|
|
15
|
+
{
|
|
16
|
+
fill: true,
|
|
17
|
+
align: "center",
|
|
18
|
+
direction: "row",
|
|
19
|
+
background: { color, opacity: "medium" },
|
|
20
|
+
justify: "start",
|
|
21
|
+
pad: "xxsmall",
|
|
22
|
+
gap: "xsmall",
|
|
23
|
+
children: [
|
|
24
|
+
/* @__PURE__ */ jsx(
|
|
25
|
+
Icon,
|
|
26
|
+
{
|
|
27
|
+
color,
|
|
28
|
+
size: "15rem",
|
|
29
|
+
a11yTitle: message
|
|
30
|
+
}
|
|
31
|
+
),
|
|
32
|
+
isNotPhone ? /* @__PURE__ */ jsx(Text, { truncate: "tip", children: message }) : void 0
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
WarningListCell
|
|
39
|
+
};
|