@apia/scheduler-component 5.0.0 → 5.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stage.js","sources":["../../../src/Scheduler/mini/Stage.tsx"],"sourcesContent":["import React from 'react';\r\nimport { Box } from '@apia/theme';\r\n\r\nimport StageButton from './StageButton';\r\nimport { isChild, useMountTransition } from '@apia/util';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { useScheduler } from '..';\r\n\r\ninterface IButtonList {\r\n stageIndex: number;\r\n}\r\n\r\nconst Stage = observer(({ stageIndex }: IButtonList) => {\r\n const controller = useScheduler();\r\n const stage = controller.getState().stageData?.[stageIndex];\r\n const [ref, setRef] = React.useState<HTMLElement | null>(null);\r\n const focusStage = controller.getState().focusStage;\r\n const isMounted = !!stage?.name;\r\n const hasTransitionedIn = useMountTransition(isMounted, 1000);\r\n\r\n const doFocus = React.useCallback(() => {\r\n if (!stage || stage.name === 'daysList') return;\r\n\r\n if (!ref) return;\r\n const firstBtn = ref.querySelector(\r\n '.stage_btn:not(:disabled)',\r\n ) as HTMLElement;\r\n if (firstBtn) {\r\n firstBtn.focus();\r\n }\r\n }, [ref, stage]);\r\n\r\n React.useEffect(() => {\r\n if (focusStage === stage?.name) doFocus();\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, [focusStage]);\r\n\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n React.useLayoutEffect(doFocus, [ref, stage]);\r\n\r\n const handleFocus = React.useCallback(\r\n (sum: number) => {\r\n const focusedElement = document.activeElement;\r\n if (\r\n isChild(focusedElement as HTMLElement, (current) => current === ref) &&\r\n ref\r\n ) {\r\n const buttons = [\r\n ...ref.querySelectorAll<HTMLElement>('.stage_btn:not(:disabled)'),\r\n ];\r\n if (buttons) {\r\n const index = buttons.findIndex(\r\n (current) => current === focusedElement,\r\n );\r\n\r\n if (buttons[index] === focusedElement && buttons[index - sum]) {\r\n buttons[index - sum].focus();\r\n\r\n controller.setState({ focusStage: stage?.name });\r\n }\r\n }\r\n }\r\n },\r\n [controller, ref, stage?.name],\r\n );\r\n\r\n const handleKeyDown = React.useCallback(\r\n (ev: React.KeyboardEvent) => {\r\n if (ev.key.toLowerCase() === 'arrowdown') {\r\n ev.preventDefault();\r\n handleFocus(-1);\r\n }\r\n if (ev.key.toLowerCase() === 'arrowup') {\r\n ev.preventDefault();\r\n handleFocus(+1);\r\n }\r\n },\r\n [handleFocus],\r\n );\r\n\r\n return stage ? (\r\n <Box\r\n data-name={stage?.name}\r\n className={`stage ${hasTransitionedIn && 'in'} ${isMounted && 'visible'}`}\r\n ref={setRef}\r\n onKeyDown={handleKeyDown}\r\n >\r\n {(hasTransitionedIn || isMounted) &&\r\n stage?.buttons?.map((elem) => {\r\n return <StageButton button={elem} key={elem.title} />;\r\n })}\r\n </Box>\r\n ) : null;\r\n});\r\n\r\nexport default Stage;\r\n"],"names":[],"mappings":";;;;;;;;AAYA,MAAM,KAAA,GAAQ,QAAA,CAAS,CAAC,EAAE,YAAW,KAAmB;AACtD,EAAA,MAAM,aAAa,YAAA,EAAa;AAChC,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,QAAA,EAAS,CAAE,YAAY,UAAU,CAAA;AAC1D,EAAA,MAAM,CAAC,GAAA,EAAK,MAAM,CAAA,GAAI,KAAA,CAAM,SAA6B,IAAI,CAAA;AAC7D,EAAA,MAAM,UAAA,GAAa,UAAA,CAAW,QAAA,EAAS,CAAE,UAAA;AACzC,EAAA,MAAM,SAAA,GAAY,CAAC,CAAC,KAAA,EAAO,IAAA;AAC3B,EAAA,MAAM,iBAAA,GAAoB,kBAAA,CAAmB,SAAA,EAAW,GAAI,CAAA;AAE5D,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,WAAA,CAAY,MAAM;AACtC,IAAA,IAAI,CAAC,KAAA,IAAS,KAAA,CAAM,IAAA,KAAS,UAAA;AAAY,MAAA;AAE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MAAM,gBAAgB,KAAA,CAAM,WAAA;AAAA,IAC1B,CAAC,EAAA,KAA4B;AAC3B,MAAA,IAAI,EAAA,CAAG,GAAA,CAAI,WAAA,EAAY,KAAM,WAAA,EAAa;AACxC,QAAA,EAAA,CAAG,cAAA,EAAe;AAClB,QAAA,WAAA,CAAY,EAAE,CAAA;AAAA;AAEhB,MAAA,IAAI,EAAA,CAAG,GAAA,CAAI,WAAA,EAAY,KAAM,SAAA,EAAW;AACtC,QAAA,EAAA,CAAG,cAAA,EAAe;AAClB,QAAA,WAAA,CAAY,CAAE,CAAA;AAAA;AAChB,KACF;AAAA,IACA,CAAC,WAAW;AAAA,GACd;AAEA,EAAA,OAAO,KAAA,mBACL,GAAA;AAAA,IAAC,GAAA;AAAA,IAAA;AAAA,MACC,aAAW,KAAA,EAAO,IAAA;AAAA,MAClB,WAAW,CAAA,MAAA,EAAS,iBAAA,IAAqB,IAAI,CAAA,CAAA,EAAI,aAAa,SAAS,CAAA,CAAA;AAAA,MACvE,GAAA,EAAK,MAAA;AAAA,MACL,SAAA,EAAW,aAAA;AAAA,MAET,gCAAqB,SAAA,KACrB,KAAA,EAAO,OAAA,EAAS,GAAA,CAAI,CAAC,IAAA,KAAS;AAC5B,QAAA,uBAAO,GAAA,CAAC,WAAA,EAAA,EAAY,MAAA,EAAQ,IAAA,EAAA,EAAW,KAAK,KAAO,CAAA;AAAA,OACpD;AAAA;AAAA,GACL,GACE,IAAA;AACN,CAAC;;;;"}
@@ -0,0 +1,43 @@
1
+ import { jsxs } from 'react/jsx-runtime';
2
+ import { toBoolean } from '@apia/util';
3
+ import { SimpleButton } from '@apia/components';
4
+ import { observer } from 'mobx-react-lite';
5
+ import { useScheduler } from '../index.js';
6
+
7
+ const StageButton = observer(
8
+ ({
9
+ button: {
10
+ action,
11
+ isDisabled,
12
+ isSelectedSelector,
13
+ label,
14
+ title,
15
+ value,
16
+ ...props
17
+ }
18
+ }) => {
19
+ const controller = useScheduler();
20
+ const isSelected = isSelectedSelector();
21
+ const showDisponibility = controller.getState().initialProps.showDisponibility;
22
+ const overassign = controller.getState().data?.overassign;
23
+ return /* @__PURE__ */ jsxs(
24
+ SimpleButton,
25
+ {
26
+ variant: "outline",
27
+ className: `${isSelected ? "selected" : ""} ${value !== "" && !Number(value) && Number(value) <= Number(overassign) ? "td_overassign" : ""} ${isDisabled ? "disabled" : ""} stage_btn`,
28
+ onClick: action,
29
+ disabled: isDisabled,
30
+ ...props,
31
+ children: [
32
+ label,
33
+ " ",
34
+ toBoolean(showDisponibility) && value !== "" && `(${Number(value) + Number(overassign) || Number(overassign)})`
35
+ ]
36
+ },
37
+ title
38
+ );
39
+ }
40
+ );
41
+
42
+ export { StageButton as default };
43
+ //# sourceMappingURL=StageButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StageButton.js","sources":["../../../src/Scheduler/mini/StageButton.tsx"],"sourcesContent":["import { toBoolean } from '@apia/util';\r\nimport { SimpleButton } from '@apia/components';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { useScheduler } from '..';\r\nimport { IStageButton } from '@apia/scheduler-controller';\r\n\r\nconst StageButton = observer(\r\n ({\r\n button: {\r\n action,\r\n isDisabled,\r\n isSelectedSelector,\r\n label,\r\n title,\r\n value,\r\n ...props\r\n },\r\n }: {\r\n button: IStageButton;\r\n }) => {\r\n const controller = useScheduler();\r\n const isSelected = isSelectedSelector();\r\n const showDisponibility =\r\n controller.getState().initialProps.showDisponibility;\r\n const overassign = controller.getState().data?.overassign;\r\n\r\n return (\r\n <SimpleButton\r\n variant=\"outline\"\r\n className={`${isSelected ? 'selected' : ''} ${\r\n value !== '' && !Number(value) && Number(value) <= Number(overassign)\r\n ? 'td_overassign'\r\n : ''\r\n } ${isDisabled ? 'disabled' : ''} stage_btn`}\r\n onClick={action}\r\n key={title}\r\n disabled={isDisabled}\r\n {...props}\r\n >\r\n {label}{' '}\r\n {toBoolean(showDisponibility) &&\r\n value !== '' &&\r\n `(${Number(value) + Number(overassign) || Number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PzD;AAAA,KAQP;AAAA;AAGN;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,2 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { Scheduler, ISchedulerDataRetriever, IScheduleInitialProps } from '@apia/scheduler-controller';
3
-
4
- declare const SchedulerComponent: (({ controller, retriever, properties, getController, }: {
5
- controller?: Scheduler;
6
- retriever?: ISchedulerDataRetriever;
7
- properties?: IScheduleInitialProps;
8
- getController?: (ctrl: Scheduler) => void;
9
- }) => react_jsx_runtime.JSX.Element | null) & {
10
- displayName: string;
11
- };
12
-
13
- export { SchedulerComponent };
1
+ export { SchedulerComponent } from './Scheduler/index.js';
14
2
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,556 +1,2 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { Box, getVariant, Heading, Spinner, Label, useBreakpointIndex } from '@apia/theme';
3
- import dayjs from 'dayjs';
4
- import { observer } from 'mobx-react-lite';
5
- import { ApiaUtil, SimpleButton, IconButton, DateInput } from '@apia/components';
6
- import React, { useCallback, createContext, useState, useContext } from 'react';
7
- import { getLabel, arrayOrArray, getDateFormat, toBoolean, useMountTransition, isChild, getSpecificParent, formatMessage } from '@apia/util';
8
- import { Icon } from '@apia/icons';
9
- import { ApiaApi, makeApiaUrl } from '@apia/api';
10
- import { Table } from '@apia/table2-component';
11
- import { Scheduler } from '@apia/scheduler-controller';
12
-
13
- const ReserveDetails = observer(
14
- ({ processes }) => {
15
- let content = /* @__PURE__ */ jsx(Box, { className: "no__appoinments", children: /* @__PURE__ */ jsxs(Box, { as: "span", children: [
16
- getLabel("lblNoAppoinments").text,
17
- " "
18
- ] }) });
19
- if (processes.length > 0)
20
- content = /* @__PURE__ */ jsxs("table", { className: "appoinments__details", children: [
21
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
22
- /* @__PURE__ */ jsx("th", { children: getLabel("lblId").text }),
23
- /* @__PURE__ */ jsx("th", { children: getLabel("flaAtr").text })
24
- ] }) }),
25
- /* @__PURE__ */ jsx("tbody", { children: processes?.map((c) => {
26
- const attributes = arrayOrArray(c.attributes.attribute);
27
- return attributes.map((attr, index) => /* @__PURE__ */ jsxs("tr", { children: [
28
- index === 0 && /* @__PURE__ */ jsx(
29
- "td",
30
- {
31
- className: "appoinments__details_id",
32
- rowSpan: attributes.length,
33
- children: c.id
34
- }
35
- ),
36
- /* @__PURE__ */ jsxs("td", { className: "appoinments__details_attribute", children: [
37
- attr.title,
38
- ": ",
39
- attr.value
40
- ] })
41
- ] }, `${c.id}-${index}`));
42
- }) })
43
- ] });
44
- return /* @__PURE__ */ jsx(Box, { ...getVariant("layout.common.components.scheduler.details"), children: content });
45
- }
46
- );
47
-
48
- const dateFormat = getDateFormat();
49
- const CellRenderer = observer(({ cell }) => {
50
- const controller = useScheduler();
51
- const state = controller.getState();
52
- if (cell.getState("content")) {
53
- return cell.getState("content");
54
- }
55
- const properties = cell.getState("properties");
56
- if (!state)
57
- return;
58
- const isSelected = state.selectedCell === properties.cellId;
59
- const ariaLabel = !properties.isEnabled ? `${dayjs(properties.weekDay, dateFormat).add(Number(properties.dayNumber) - 1, "day").format(dateFormat)},${properties.hour.slice(0, -2) ?? ""}:${properties.hour.slice(2) ?? ""}, ${String("disabled")}
60
- ` : `${dayjs(properties.weekDay, dateFormat).add(Number(properties.dayNumber) - 1, "day").format(dateFormat)},${properties.hour.slice(
61
- 0,
62
- -2
63
- )}:${properties.hour.slice(2)}, ${String(
64
- properties.valuePlusOverassign
65
- )}
66
- `;
67
- const title = !properties.isEnabled ? "" : `${dayjs(properties.weekDay, dateFormat).add(Number(properties.dayNumber) - 1, "day").format(dateFormat)},${properties.hour.slice(
68
- 0,
69
- -2
70
- )}:${properties.hour.slice(2)} ${String(
71
- toBoolean(state.initialProps.showDisponibility) ? `, ${properties.valuePlusOverassign}` : ""
72
- )}
73
- `;
74
- const onSelectDayHandler = useCallback(() => {
75
- if (controller.type === "RescheduleTskScheduler") {
76
- controller.setState({
77
- ...state,
78
- selectedCell: properties.cellId,
79
- selectedDay: {
80
- hour: String(properties.hour),
81
- day: dayjs(properties.weekDay, dateFormat).add(Number(properties.dayNumber) - 1, "day").format(dateFormat),
82
- mondayWeek: String(
83
- dayjs(properties.weekDay, dateFormat).format(dateFormat)
84
- ),
85
- dayNumber: Number(properties.dayNumber),
86
- morningOrAfternoonSelected: Number(properties.hour)
87
- }
88
- });
89
- } else {
90
- ApiaApi.get(
91
- makeApiaUrl({
92
- ajaxUrl: "/apia.design.TaskSchedulerAction.run",
93
- action: "setExecutionSchedulerSelectedDay",
94
- weekDay: properties.weekDay,
95
- hour: properties.hour,
96
- dayNumber: properties.dayNumber
97
- })
98
- ).then((response) => {
99
- if (response?.data?.success) {
100
- controller.setState({
101
- ...state,
102
- selectedCell: properties.cellId,
103
- selectedDay: {
104
- hour: String(properties.hour),
105
- day: dayjs(properties.weekDay, dateFormat).add(Number(properties.dayNumber) - 1, "day").format(dateFormat),
106
- mondayWeek: String(
107
- dayjs(properties.weekDay, dateFormat).format(dateFormat)
108
- ),
109
- dayNumber: Number(properties.dayNumber),
110
- morningOrAfternoonSelected: Number(properties.hour)
111
- }
112
- });
113
- if (properties.currentDayDefinition) {
114
- controller.syncStage(
115
- properties.currentDayDefinition,
116
- Number(properties.hour)
117
- );
118
- }
119
- }
120
- }).catch(() => {
121
- });
122
- }
123
- }, [
124
- controller,
125
- properties.cellId,
126
- properties.currentDayDefinition,
127
- properties.dayNumber,
128
- properties.hour,
129
- properties.weekDay,
130
- state
131
- ]);
132
- return /* @__PURE__ */ jsxs(
133
- Box,
134
- {
135
- className: `scheduler_cell ${properties.isOverassignClassName ? "td_overassign" : ""}`,
136
- children: [
137
- /* @__PURE__ */ jsxs(
138
- SimpleButton,
139
- {
140
- tabIndex: 0,
141
- title,
142
- "aria-label": ariaLabel,
143
- disabled: !properties.isEnabled,
144
- ...getVariant("transparentIcon"),
145
- onClick: onSelectDayHandler,
146
- className: `sched_cell__btn `,
147
- children: [
148
- isSelected && /* @__PURE__ */ jsx(Icon, { title: "", name: "Check" }),
149
- !isSelected && properties.isEnabled && toBoolean(state.initialProps.showDisponibility) && Number(properties.valuePlusOverassign)
150
- ]
151
- }
152
- ),
153
- properties.currentDayDefinition?.type === "laboral" && ApiaUtil.instance.parsers.parseBool(
154
- state.initialProps.showAttributes ?? "false"
155
- ) && /* @__PURE__ */ jsx(
156
- IconButton,
157
- {
158
- size: 24,
159
- icon: "Search",
160
- ...getVariant("transparentIcon"),
161
- className: `schd__info ${!properties.isEnabled ? "schd__info_disabledColor" : ""}`,
162
- onClick: async () => {
163
- const processes = await controller.loadInfo(
164
- properties.dayNumber,
165
- properties.hour
166
- );
167
- ApiaUtil.instance.modals.open({
168
- title: getLabel("lblAppointmentDetails").text,
169
- children: /* @__PURE__ */ jsx(ReserveDetails, { processes }),
170
- variant: "layout.execution.form.fields.scheduler.details"
171
- });
172
- }
173
- }
174
- )
175
- ]
176
- }
177
- );
178
- });
179
- class SchedulerTablePlugin {
180
- getRenderers() {
181
- return {
182
- cell: CellRenderer
183
- };
184
- }
185
- }
186
-
187
- const Navigation = observer(() => {
188
- const controller = useScheduler();
189
- const mondayWeek = controller.getState().data?.mondayWeek;
190
- const {
191
- isDisabled,
192
- isTodayLoading,
193
- isLastWeekLoading,
194
- isDateInputLoading,
195
- isNextWeekLoading,
196
- isDeleteLoading
197
- } = {
198
- isDisabled: controller.getState()?.isLoading !== "NotLoading",
199
- isTodayLoading: controller.getState()?.isLoading === "Today",
200
- isLastWeekLoading: controller.getState()?.isLoading === "LastWeek",
201
- isDateInputLoading: controller.getState()?.isLoading === "DateInput",
202
- isNextWeekLoading: controller.getState()?.isLoading === "NextWeek",
203
- isDeleteLoading: controller.getState()?.isLoading === "DeleteWeek"
204
- };
205
- const onTodayHandler = () => {
206
- controller.setState({ isLoading: "Today" });
207
- controller.makeDaysStage();
208
- controller.loadWeek(dayjs().subtract(1, "day").format(dateFormat));
209
- };
210
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Box, { className: "scheduler__navigator", children: [
211
- /* @__PURE__ */ jsx(
212
- SimpleButton,
213
- {
214
- variant: "outline",
215
- className: "scheduler__navigator_todayBtn",
216
- disabled: isDisabled,
217
- "aria-label": window.LBL_TODAY,
218
- isLoading: isTodayLoading,
219
- onClick: useCallback(onTodayHandler, [controller]),
220
- type: "button",
221
- children: window.LBL_TODAY
222
- }
223
- ),
224
- /* @__PURE__ */ jsx(
225
- SimpleButton,
226
- {
227
- variant: "outline",
228
- className: "scheduler__navigator_lastBtn",
229
- disabled: isDisabled,
230
- title: window.LBL_SCHED_LAST_WEEK_TOOLTIP,
231
- "aria-label": window.LBL_SCHED_LAST_WEEK_TEXT,
232
- isLoading: isLastWeekLoading,
233
- onClick: () => controller.goPreviousWeek(),
234
- type: "button",
235
- children: "<"
236
- }
237
- ),
238
- /* @__PURE__ */ jsx(
239
- DateInput,
240
- {
241
- className: "scheduler__navigator_dateInput",
242
- disabled: isDisabled,
243
- isLoading: isDateInputLoading,
244
- getCustomMask: useCallback(() => {
245
- return "";
246
- }, []),
247
- renderLabel: controller.parsedDateLabel,
248
- onChange: (newDate) => {
249
- if (newDate) {
250
- controller.setState({ isLoading: "DateInput" });
251
- controller.loadWeek(
252
- dayjs(newDate, dateFormat).format(dateFormat)
253
- );
254
- }
255
- },
256
- value: mondayWeek
257
- }
258
- ),
259
- /* @__PURE__ */ jsx(
260
- SimpleButton,
261
- {
262
- variant: "outline",
263
- className: "scheduler__navigator_nextBtn",
264
- disabled: isDisabled,
265
- title: window.LBL_SCHED_NEXT_WEEK_TOOLTIP,
266
- "aria-label": window.LBL_SCHED_NEXT_WEEK_TEXT,
267
- isLoading: isNextWeekLoading,
268
- onClick: () => controller.goNextWeek(),
269
- type: "button",
270
- children: ">"
271
- }
272
- ),
273
- /* @__PURE__ */ jsx(
274
- SimpleButton,
275
- {
276
- variant: "outline-danger",
277
- title: window.LBL_SCHED_RESET_TOOLTIP,
278
- "aria-label": window.LBL_SCHED_RESET_TEXT,
279
- className: "scheduler__navigator_DeleteBtn",
280
- disabled: isDisabled,
281
- isLoading: isDeleteLoading,
282
- onClick: () => controller.deleteDate(),
283
- type: "button",
284
- children: /* @__PURE__ */ jsx(Icon, { name: "Trash", title: window.LBL_SCHED_RESET_TEXT })
285
- }
286
- )
287
- ] }) });
288
- });
289
-
290
- const SchedTable = observer(() => {
291
- const controller = useScheduler();
292
- return /* @__PURE__ */ jsx(
293
- Box,
294
- {
295
- onKeyDownCapture: (ev) => {
296
- if (ev.code === "ArrowRight" && ev.ctrlKey) {
297
- ev.stopPropagation();
298
- controller.goNextWeek();
299
- }
300
- if (ev.code === "ArrowLeft" && ev.ctrlKey) {
301
- ev.stopPropagation();
302
- controller.goPreviousWeek();
303
- }
304
- },
305
- children: /* @__PURE__ */ jsx(Table, { variant: "secondary", controller: controller.tableController })
306
- }
307
- );
308
- });
309
-
310
- const StageButton = observer(
311
- ({
312
- button: {
313
- action,
314
- isDisabled,
315
- isSelectedSelector,
316
- label,
317
- title,
318
- value,
319
- ...props
320
- }
321
- }) => {
322
- const controller = useScheduler();
323
- const isSelected = isSelectedSelector();
324
- const showDisponibility = controller.getState().initialProps.showDisponibility;
325
- const overassign = controller.getState().data?.overassign;
326
- return /* @__PURE__ */ jsxs(
327
- SimpleButton,
328
- {
329
- variant: "outline",
330
- className: `${isSelected ? "selected" : ""} ${value !== "" && !Number(value) && Number(value) <= Number(overassign) ? "td_overassign" : ""} ${isDisabled ? "disabled" : ""} stage_btn`,
331
- onClick: action,
332
- disabled: isDisabled,
333
- ...props,
334
- children: [
335
- label,
336
- " ",
337
- toBoolean(showDisponibility) && value !== "" && `(${Number(value) + Number(overassign) || Number(overassign)})`
338
- ]
339
- },
340
- title
341
- );
342
- }
343
- );
344
-
345
- const Stage = observer(({ stageIndex }) => {
346
- const controller = useScheduler();
347
- const stage = controller.getState().stageData?.[stageIndex];
348
- const [ref, setRef] = React.useState(null);
349
- const focusStage = controller.getState().focusStage;
350
- const isMounted = !!stage?.name;
351
- const hasTransitionedIn = useMountTransition(isMounted, 1e3);
352
- const doFocus = React.useCallback(() => {
353
- if (!stage || stage.name === "daysList")
354
- return;
355
- if (!ref)
356
- return;
357
- const firstBtn = ref.querySelector(
358
- ".stage_btn:not(:disabled)"
359
- );
360
- if (firstBtn) {
361
- firstBtn.focus();
362
- }
363
- }, [ref, stage]);
364
- React.useEffect(() => {
365
- if (focusStage === stage?.name)
366
- doFocus();
367
- }, [focusStage]);
368
- React.useLayoutEffect(doFocus, [ref, stage]);
369
- const handleFocus = React.useCallback(
370
- (sum) => {
371
- const focusedElement = document.activeElement;
372
- if (isChild(focusedElement, (current) => current === ref) && ref) {
373
- const buttons = [
374
- ...ref.querySelectorAll(".stage_btn:not(:disabled)")
375
- ];
376
- if (buttons) {
377
- const index = buttons.findIndex(
378
- (current) => current === focusedElement
379
- );
380
- if (buttons[index] === focusedElement && buttons[index - sum]) {
381
- buttons[index - sum].focus();
382
- controller.setState({ focusStage: stage?.name });
383
- }
384
- }
385
- }
386
- },
387
- [controller, ref, stage?.name]
388
- );
389
- const handleKeyDown = React.useCallback(
390
- (ev) => {
391
- if (ev.key.toLowerCase() === "arrowdown") {
392
- ev.preventDefault();
393
- handleFocus(-1);
394
- }
395
- if (ev.key.toLowerCase() === "arrowup") {
396
- ev.preventDefault();
397
- handleFocus(1);
398
- }
399
- },
400
- [handleFocus]
401
- );
402
- return stage ? /* @__PURE__ */ jsx(
403
- Box,
404
- {
405
- "data-name": stage?.name,
406
- className: `stage ${hasTransitionedIn && "in"} ${isMounted && "visible"}`,
407
- ref: setRef,
408
- onKeyDown: handleKeyDown,
409
- children: (hasTransitionedIn || isMounted) && stage?.buttons?.map((elem) => {
410
- return /* @__PURE__ */ jsx(StageButton, { button: elem }, elem.title);
411
- })
412
- }
413
- ) : null;
414
- });
415
-
416
- const Mini = observer(() => {
417
- const controller = useScheduler();
418
- const data = controller.getState().data;
419
- const stage = controller.getState()?.stageData;
420
- const stagesLength = controller.getState().stageData?.length;
421
- return /* @__PURE__ */ jsxs(
422
- Box,
423
- {
424
- ...getVariant("layout.execution.form.fields.scheduler"),
425
- className: "schedulerMini",
426
- onKeyDown: (ev) => {
427
- if (ev.key.toLowerCase() === "arrowleft") {
428
- const stageName = getSpecificParent(
429
- ev.target,
430
- (current) => current.classList.contains("stage")
431
- )?.dataset.name;
432
- const stageIndex = stage.findIndex(
433
- (current) => current.name === stageName
434
- );
435
- if (stageIndex <= 0)
436
- return;
437
- const nextStage = stage[stageIndex - 1]?.name;
438
- const firstButton = document.querySelector(
439
- `[data-name="${nextStage}"] .selected`
440
- ) || document.querySelector(
441
- `[data-name="${nextStage}"] button:not(:disabled)`
442
- );
443
- if (firstButton)
444
- firstButton.focus();
445
- }
446
- if (ev.key.toLowerCase() === "arrowright") {
447
- const stageName = getSpecificParent(
448
- ev.target,
449
- (current) => current.classList.contains("stage")
450
- )?.dataset.name;
451
- const stageIndex = stage.findIndex(
452
- (current) => current.name === stageName
453
- );
454
- if (stageIndex >= stage.length - 1)
455
- return;
456
- const nextStage = stage[stageIndex + 1]?.name;
457
- const firstButton = document.querySelector(
458
- `[data-name="${nextStage}"] .selected`
459
- ) || document.querySelector(
460
- `[data-name="${nextStage}"] button:not(:disabled)`
461
- );
462
- if (firstButton)
463
- firstButton.focus();
464
- }
465
- },
466
- children: [
467
- data?.weekNotConfigured && /* @__PURE__ */ jsx(Heading, { as: "h1", children: window.LBL_SCHED_WEEK_NOT_CONFIGURED }),
468
- !data?.weekNotConfigured && data?.tskSchDay && /* @__PURE__ */ jsxs(Fragment, { children: [
469
- /* @__PURE__ */ jsx(Stage, { stageIndex: 0 }),
470
- stagesLength >= 2 && /* @__PURE__ */ jsx(
471
- Icon,
472
- {
473
- name: "ArrowDown",
474
- title: "",
475
- className: "schedulerMini_faCaretDown"
476
- }
477
- ),
478
- /* @__PURE__ */ jsx(Stage, { stageIndex: 1 }),
479
- stagesLength >= 3 && /* @__PURE__ */ jsx(
480
- Icon,
481
- {
482
- name: "ArrowDown",
483
- title: "",
484
- className: "schedulerMini_faCaretDown"
485
- }
486
- ),
487
- /* @__PURE__ */ jsx(Stage, { stageIndex: 2 })
488
- ] }),
489
- !data?.weekNotConfigured && !data?.tskSchDay && /* @__PURE__ */ jsx(Box, { className: "box_spinner", title: window.WAIT_A_SECOND, children: /* @__PURE__ */ jsx(Spinner, {}) })
490
- ]
491
- }
492
- );
493
- });
494
-
495
- const SelectedDateInfo = observer(() => {
496
- const controller = useScheduler();
497
- const data = controller.getState().data;
498
- const selectedDay = controller.getState()?.selectedDay;
499
- return /* @__PURE__ */ jsxs(Box, { className: "selectedDateInfo", children: [
500
- selectedDay?.day && selectedDay?.hour && /* @__PURE__ */ jsx(Label, { children: formatMessage(window.LBL_SCHED_SELECTED_DATE, {
501
- TOK1: selectedDay?.day,
502
- TOK2: `${selectedDay.hour.slice(
503
- 0,
504
- -2
505
- )}:${selectedDay.hour.slice(2)}`
506
- }) }),
507
- !selectedDay?.day && !data?.weekNotConfigured && data?.tskSchDay && /* @__PURE__ */ jsx(Label, { sx: { display: "block" }, children: window.LBL_SCHED_DATE_NOT_SELECTED })
508
- ] });
509
- });
510
-
511
- const SchedulerController = createContext(null);
512
- function useScheduler() {
513
- return useContext(SchedulerController);
514
- }
515
- const SchedulerComponent = observer(
516
- ({
517
- controller,
518
- retriever,
519
- properties,
520
- getController
521
- }) => {
522
- if (!controller && !(properties && retriever)) {
523
- console.error(
524
- "Need to create controller or pass retriever and properties"
525
- );
526
- return null;
527
- }
528
- const [actualController] = useState(() => {
529
- const ctrl = controller ?? new Scheduler(properties, retriever);
530
- getController?.(ctrl);
531
- ctrl.tableController.setPlugins((current) => {
532
- if (!current.some((plugin) => plugin instanceof SchedulerTablePlugin)) {
533
- current.push(new SchedulerTablePlugin());
534
- }
535
- return current;
536
- });
537
- return ctrl;
538
- });
539
- const breakPoint = useBreakpointIndex();
540
- return /* @__PURE__ */ jsx(SchedulerController.Provider, { value: actualController, children: /* @__PURE__ */ jsxs(
541
- Box,
542
- {
543
- ...getVariant("layout.common.components.scheduler"),
544
- className: "scheduler",
545
- children: [
546
- /* @__PURE__ */ jsx(Navigation, {}),
547
- /* @__PURE__ */ jsx(SelectedDateInfo, {}),
548
- breakPoint > 4 ? /* @__PURE__ */ jsx(SchedTable, {}) : /* @__PURE__ */ jsx(Mini, {})
549
- ]
550
- }
551
- ) });
552
- }
553
- );
554
-
555
- export { SchedulerComponent };
1
+ export { SchedulerComponent } from './Scheduler/index.js';
556
2
  //# sourceMappingURL=index.js.map