@genesislcap/foundation-ui 14.246.1 → 14.247.0

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.
Files changed (54) hide show
  1. package/dist/custom-elements.json +2676 -1485
  2. package/dist/dts/base-components.d.ts +11 -0
  3. package/dist/dts/base-components.d.ts.map +1 -1
  4. package/dist/dts/index.d.ts +1 -0
  5. package/dist/dts/index.d.ts.map +1 -1
  6. package/dist/dts/scheduler-cron-builder/daily-recurrence/daily-recurrence.d.ts +342 -0
  7. package/dist/dts/scheduler-cron-builder/daily-recurrence/daily-recurrence.d.ts.map +1 -0
  8. package/dist/dts/scheduler-cron-builder/daily-recurrence/daily-recurrence.styles.d.ts +3 -0
  9. package/dist/dts/scheduler-cron-builder/daily-recurrence/daily-recurrence.styles.d.ts.map +1 -0
  10. package/dist/dts/scheduler-cron-builder/daily-recurrence/daily-recurrence.template.d.ts +4 -0
  11. package/dist/dts/scheduler-cron-builder/daily-recurrence/daily-recurrence.template.d.ts.map +1 -0
  12. package/dist/dts/scheduler-cron-builder/helpers.d.ts +211 -0
  13. package/dist/dts/scheduler-cron-builder/helpers.d.ts.map +1 -0
  14. package/dist/dts/scheduler-cron-builder/index.d.ts +4 -0
  15. package/dist/dts/scheduler-cron-builder/index.d.ts.map +1 -0
  16. package/dist/dts/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.d.ts +400 -0
  17. package/dist/dts/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.d.ts.map +1 -0
  18. package/dist/dts/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.styles.d.ts +3 -0
  19. package/dist/dts/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.styles.d.ts.map +1 -0
  20. package/dist/dts/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.template.d.ts +4 -0
  21. package/dist/dts/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.template.d.ts.map +1 -0
  22. package/dist/dts/scheduler-cron-builder/scheduler-cron-builder.d.ts +124 -0
  23. package/dist/dts/scheduler-cron-builder/scheduler-cron-builder.d.ts.map +1 -0
  24. package/dist/dts/scheduler-cron-builder/scheduler-cron-builder.styles.d.ts +4 -0
  25. package/dist/dts/scheduler-cron-builder/scheduler-cron-builder.styles.d.ts.map +1 -0
  26. package/dist/dts/scheduler-cron-builder/scheduler-cron-builder.template.d.ts +4 -0
  27. package/dist/dts/scheduler-cron-builder/scheduler-cron-builder.template.d.ts.map +1 -0
  28. package/dist/dts/scheduler-cron-builder/types.d.ts +90 -0
  29. package/dist/dts/scheduler-cron-builder/types.d.ts.map +1 -0
  30. package/dist/dts/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.d.ts +346 -0
  31. package/dist/dts/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.d.ts.map +1 -0
  32. package/dist/dts/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.styles.d.ts +3 -0
  33. package/dist/dts/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.styles.d.ts.map +1 -0
  34. package/dist/dts/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.template.d.ts +4 -0
  35. package/dist/dts/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.template.d.ts.map +1 -0
  36. package/dist/dts/utils/base-datasource.d.ts +1 -1
  37. package/dist/esm/base-components.js +2 -0
  38. package/dist/esm/index.js +1 -0
  39. package/dist/esm/scheduler-cron-builder/daily-recurrence/daily-recurrence.js +38 -0
  40. package/dist/esm/scheduler-cron-builder/daily-recurrence/daily-recurrence.styles.js +5 -0
  41. package/dist/esm/scheduler-cron-builder/daily-recurrence/daily-recurrence.template.js +25 -0
  42. package/dist/esm/scheduler-cron-builder/helpers.js +330 -0
  43. package/dist/esm/scheduler-cron-builder/index.js +3 -0
  44. package/dist/esm/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.js +130 -0
  45. package/dist/esm/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.styles.js +25 -0
  46. package/dist/esm/scheduler-cron-builder/monthly-yearly-recurrence/monthly-yearly-recurrence.template.js +92 -0
  47. package/dist/esm/scheduler-cron-builder/scheduler-cron-builder.js +289 -0
  48. package/dist/esm/scheduler-cron-builder/scheduler-cron-builder.styles.js +72 -0
  49. package/dist/esm/scheduler-cron-builder/scheduler-cron-builder.template.js +101 -0
  50. package/dist/esm/scheduler-cron-builder/types.js +67 -0
  51. package/dist/esm/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.js +59 -0
  52. package/dist/esm/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.styles.js +9 -0
  53. package/dist/esm/scheduler-cron-builder/weekly-recurrence/weekly-recurrence.template.js +25 -0
  54. package/package.json +17 -16
@@ -0,0 +1,330 @@
1
+ import { CRON_LENGTH, DateOrDay, MAX_DAYS, MAX_HOURS, MAX_MINS_SEC, MAX_MONTHS, MAX_WEEK_DAYS, MAX_WEEK_NUMBER, RecurrenceType, WeekType, } from './types';
2
+ export const formatFrequency = (freq) => {
3
+ return Number(freq) > 1 ? `/${freq}` : '';
4
+ };
5
+ /**
6
+ * generates a cron expression for RecurrenceType.DAILY on the basis of provided config
7
+ * @param config {@link DailyConfig}- the config object that contains Daily recurrence details
8
+ * @returns The cron expression string (e.g. `"0 30 10 ? * 2-6"` runs on weekdays from monday-friday at 10:30
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const cron = getCronExpressionForDaily({
13
+ * seconds: "0",
14
+ * hours: "10",
15
+ * minutes: "30",
16
+ * frequency: 2,
17
+ weekType: 'Work week'
18
+ * });
19
+ * console.log(cron); // "0 30 10 ? * 2-6"
20
+ * ```
21
+ * @internal
22
+ */
23
+ export function getCronExpressionForDaily(config, formatFrequencyInput = formatFrequency) {
24
+ const dayOfMonth = config.weekType === WeekType.WORK_WEEK ? '?' : `*${formatFrequencyInput(config.frequency)}`;
25
+ return `${config.seconds} ${config.minutes} ${config.hours} ${dayOfMonth} * ${config.weekType === WeekType.WORK_WEEK ? '2-6' : '?'}`;
26
+ }
27
+ /**
28
+ * generates a cron expression for RecurrenceType.WEEKLY on the basis of provided config
29
+ * @param config {@link WeeklyConfig}- the config object that contains Weekly recurrence details
30
+ * @returns The cron expression string (e.g. `"0 30 10 ? * 1,3"` runs every sunday and tuesday at 10:30
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const cron = getCronExpressionForWeekly({
35
+ * seconds: "0",
36
+ * hours: "10",
37
+ * minutes: "30",
38
+ selectedDays: new Set(['1','3'])
39
+ * });
40
+ * console.log(cron); // "0 30 10 ? * 1,3"
41
+ * ```
42
+ * @internal
43
+ */
44
+ export function getCronExpressionForWeekly(config) {
45
+ const daysOfWeek = [...config.selectedDays].join(',') || '*';
46
+ return `${config.seconds} ${config.minutes} ${config.hours} ? * ${daysOfWeek}`;
47
+ }
48
+ /**
49
+ * generates a cron expression for RecurrenceType.MONTHLY on the basis of provided config
50
+ * @param config {@link MonthlyConfig}- the config object that contains Monthly recurrence details
51
+ * * allows user to specify either Date of the month when dateOrDay is of 'Date' type or
52
+ * Day of week and weekNumber when dateOrDay is of type 'Day of month'
53
+ * @returns The cron expression string (e.g. `"0 30 10 15 *'/4 ?"` runs every 4 months on 15th at 10:30 am)
54
+ *
55
+ * @example with dateOrDay type = 'Date'
56
+ * ```ts
57
+ * const cron = getCronExpressionForMonth({
58
+ * seconds: "0",
59
+ * hours: "10",
60
+ * minutes: "30",
61
+ * frequency: 4,
62
+ * dateOrDay: {
63
+ * type: "Date",
64
+ * dayDate: 15,
65
+ * }
66
+ * });
67
+ * console.log(cron); // "0 30 10 15 *'/4 ?"
68
+ * ```
69
+ * @example with dateOrDay type = 'Day of month'
70
+ * Runs on second friday of every 4th month at 10:30
71
+ * ```ts
72
+ * const cron = getCronExpressionForMonth({
73
+ * seconds: "0",
74
+ * hours: "10",
75
+ * minutes: "30",
76
+ * frequency: 4,
77
+ * dateOrDay: {
78
+ * type: "Day of month",
79
+ * weekNumber: 2,
80
+ * day: '5'
81
+ * }
82
+ * });
83
+ * console.log(cron); // "0 30 10 ? *'/4 5#2"
84
+ * ```
85
+ */
86
+ /** @internal */
87
+ export function getCronExpressionForMonth(config, formatFrequencyInput = formatFrequency) {
88
+ const { dateOrDay, minutes, hours, seconds, frequency: freq } = config;
89
+ const frequency = formatFrequencyInput(freq);
90
+ if (dateOrDay.type === DateOrDay.DATE) {
91
+ return `${seconds} ${minutes} ${hours} ${dateOrDay.dayDate} *${frequency} ?`;
92
+ }
93
+ else if (dateOrDay.weekNumber === '-1') {
94
+ return `${seconds} ${minutes} ${hours} ? *${frequency} ${dateOrDay.day}L`;
95
+ }
96
+ else {
97
+ return `${config.seconds} ${minutes} ${hours} ? *${frequency} ${dateOrDay.day}#${dateOrDay.weekNumber}`;
98
+ }
99
+ }
100
+ /**
101
+ * generates a cron expression for RecurrenceType.YEARLY on the basis of provided config
102
+ * @param config {@link YearlyConfig}- the config object that contains Yearly recurrence details
103
+ * allows user to specify either Date of the month and month when dateOrDay is of 'Date' type or
104
+ * Day of week, weekNumber and month when dateOrDay is of type 'Day of month'
105
+ * @returns The cron expression string (e.g. `"0 30 10 15 3 ?"` runs every year on March 15 at 10:30 am)
106
+ *
107
+ * @example with dateOrDay type = 'Date'
108
+ * ```ts
109
+ * const cron = getCronExpressionForYear({
110
+ * seconds: "0",
111
+ * hours: "10",
112
+ * minutes: "30",
113
+ * frequency: 2,
114
+ * dateOrDay: {
115
+ * type: "Date",
116
+ * month: '3',
117
+ * dayDate: 15,
118
+ * }
119
+ * });
120
+ * console.log(cron); // "0 30 10 15 3 ?"
121
+ * ```
122
+ * @example with dateOrDay type = 'Day of month'
123
+ * Runs on second friday of march, every 2 years
124
+ * ```ts
125
+ * const cron = getCronExpressionForYear({
126
+ * seconds: "0",
127
+ * hours: "10",
128
+ * minutes: "30",
129
+ * frequency: 2,
130
+ * dateOrDay: {
131
+ * type: "Day of month",
132
+ * month: '3',
133
+ * weekNumber: 2,
134
+ * day: '5'
135
+ * }
136
+ * });
137
+ * console.log(cron); // "0 30 10 ? 3 5#2"
138
+ * ```
139
+ * @internal
140
+ */
141
+ export function getCronExpressionForYear(config) {
142
+ const { dateOrDay, minutes, seconds, hours } = config;
143
+ if (dateOrDay.type === DateOrDay.DATE) {
144
+ return `${seconds} ${minutes} ${hours} ${dateOrDay.dayDate} ${dateOrDay.month} ?`;
145
+ }
146
+ else if (dateOrDay.weekNumber === '-1') {
147
+ return `${seconds} ${minutes} ${hours} ? ${dateOrDay.month} ${dateOrDay.day}L`;
148
+ }
149
+ else {
150
+ return `${seconds} ${minutes} ${hours} ? ${dateOrDay.month} ${dateOrDay.day}#${dateOrDay.weekNumber}`;
151
+ }
152
+ }
153
+ /**
154
+ * @internal
155
+ */
156
+ export const isInRange = (val, min, max) => {
157
+ const numVal = Number(val);
158
+ return !isNaN(numVal) && numVal <= max && numVal >= min;
159
+ };
160
+ /**
161
+ * @internal
162
+ */
163
+ export function isValidValue(val, minVal, maxVal, checkSpecial = false, isValueInRange = isInRange) {
164
+ if (val === '*')
165
+ return true;
166
+ // support for ? and L in day of month
167
+ if (checkSpecial && (val === '?' || val === 'L'))
168
+ return true;
169
+ if (checkSpecial && val.endsWith('L')) {
170
+ return isValueInRange(val.slice(0, -1), minVal, maxVal); // Ensure it's a valid weekday number (0-7)
171
+ }
172
+ // support if it's a step value (*/n)
173
+ if (val.startsWith('*/')) {
174
+ return isValueInRange(val.substring(2), 1, maxVal);
175
+ }
176
+ // Support `Day_of_Week#WeekNumber` (e.g., `6#3` means "the third Friday of the month")
177
+ if (checkSpecial && val.includes('#')) {
178
+ const [weekday, weekNumber] = val.split('#');
179
+ return (isValueInRange(weekday, minVal, maxVal) && isValueInRange(weekNumber, 1, MAX_WEEK_NUMBER));
180
+ }
181
+ // Check if it's a single number e.g. 12,13
182
+ if (isValueInRange(val, minVal, maxVal))
183
+ return true;
184
+ // Check if it's a range (e.g., 2-6)
185
+ if (val.includes('-')) {
186
+ const [start, end] = val.split('-');
187
+ return isValueInRange(start, minVal, maxVal) && isValueInRange(end, minVal, maxVal);
188
+ }
189
+ // Check if it's a list (e.g., 1,2,3)
190
+ if (val.includes(',')) {
191
+ return val
192
+ .split(',')
193
+ .every((part) => isValidValue(part, minVal, maxVal, checkSpecial, isValueInRange));
194
+ }
195
+ return false;
196
+ }
197
+ /**
198
+ * used to validate cron expression,
199
+ * checks no of parts should be exactly 6 and verify each part
200
+ * @internal */
201
+ export const isValidCron = (cron, isValid = isValidValue) => {
202
+ const cronParts = cron.trim().split(' ');
203
+ // Ensure it has exactly 6 part
204
+ if (cronParts.length != CRON_LENGTH)
205
+ return false;
206
+ const [second, minute, hour, dayOfMonth, month, dayOfWeek] = cronParts;
207
+ // Validate each part
208
+ return (isValid(second, 0, MAX_MINS_SEC - 1) &&
209
+ isValid(minute, 0, MAX_MINS_SEC - 1) &&
210
+ isValid(hour, 0, MAX_HOURS - 1) &&
211
+ isValid(dayOfMonth, 1, MAX_DAYS, true) && // Allow `L` and `?`
212
+ isValid(month, 1, MAX_MONTHS) &&
213
+ isValid(dayOfWeek, 0, MAX_WEEK_DAYS, true) // Allow `L`, `?`, and `#`
214
+ );
215
+ };
216
+ /**
217
+ * similar to {@link getCronExpressionForDaily}
218
+ * this is used to generate cronConfig object for Daily recurrence from cron string parts passed as params
219
+ * @internal */
220
+ export function buildConfigForDailyRecurrence(dayOfMonth, dayOfWeek) {
221
+ return {
222
+ type: RecurrenceType.DAILY,
223
+ frequency: dayOfMonth.startsWith('*/') ? dayOfMonth.split('*/')[1] : '1',
224
+ weekType: dayOfWeek === '?' ? WeekType.WEEK : WeekType.WORK_WEEK,
225
+ };
226
+ }
227
+ /**
228
+ * similar to {@link getCronExpressionForWeekly}
229
+ * this is used to generate cronConfig object for weekly recurrence from cron string parts passed as params
230
+ * @internal */
231
+ export function buildConfigForWeeklyRecurrence(dayOfWeek) {
232
+ return {
233
+ type: RecurrenceType.WEEKLY,
234
+ selectedDays: dayOfWeek !== '*' ? new Set(dayOfWeek.split(',')) : new Set(),
235
+ };
236
+ }
237
+ /**
238
+ * used to build dateOrDay object for yearly and monthly recurrence
239
+ * @internal */
240
+ export const getDateOrDay = (type, dayOfMonth, mon, dayOfWeek) => {
241
+ let dayOrDate;
242
+ if (dayOfMonth === '?') {
243
+ dayOrDate = {
244
+ type: DateOrDay.DAY_OF_MONTH,
245
+ day: dayOfWeek.split(/[L#]/)[0],
246
+ weekNumber: dayOfWeek.includes('#') ? dayOfWeek.split('#')[1] : '-1',
247
+ };
248
+ }
249
+ else {
250
+ dayOrDate = {
251
+ type: DateOrDay.DATE,
252
+ dayDate: dayOfMonth,
253
+ };
254
+ }
255
+ if (type === RecurrenceType.YEARLY) {
256
+ dayOrDate['month'] = mon;
257
+ }
258
+ return dayOrDate;
259
+ };
260
+ /**
261
+ * similar to {@link getCronExpressionForYearly}
262
+ * this is used to generate cronConfig object for yearly recurrence from cron string parts passed as params
263
+ * @internal */
264
+ export function buildConfigForYearlyRecurrence(dayOfMonth, mon, dayOfWeek, getDateOrDayConfig = getDateOrDay) {
265
+ return {
266
+ type: RecurrenceType.YEARLY,
267
+ frequency: dayOfWeek.split('/').length === 2 ? dayOfWeek.split('/')[1] : '1',
268
+ dateOrDay: getDateOrDayConfig(RecurrenceType.YEARLY, dayOfMonth, mon, dayOfWeek.split('/')[0]),
269
+ };
270
+ }
271
+ /**
272
+ * similar to {@link getCronExpressionForMonth}
273
+ * this is used to generate cronConfig object for monthly recurrence from cron string parts passed as params
274
+ * @internal */
275
+ export function buildConfigForMonthlyRecurrence(dayOfMonth, mon, dayOfWeek, getDateOrDayConfig = getDateOrDay) {
276
+ return {
277
+ type: RecurrenceType.MONTHLY,
278
+ frequency: mon.startsWith('*/') ? mon.split('*/')[1] : '1',
279
+ dateOrDay: getDateOrDayConfig(RecurrenceType.MONTHLY, dayOfMonth, mon, dayOfWeek.split('/')[0]),
280
+ };
281
+ }
282
+ /**
283
+ *
284
+ * @param cron - cron expression representing either Daily, weekly, monthly or yearly recurrence
285
+ * @returns the cron config of a specific recurrence after determining the recurrenceType
286
+ *
287
+ * @example
288
+ * ```ts
289
+ * const config = parseCronExpression('0 30 10 ? * 2-6');
290
+ * console.log(config); // {type: 'Daily', frequency: 2, weekType: 'Work week', time: '10:30'}
291
+ * ```
292
+ * @internal
293
+ */
294
+ export function parseCronExpression(cron, methods) {
295
+ if (!cron)
296
+ return;
297
+ const cronParts = cron.split(' ');
298
+ const [seconds, minutes, hours, dayOfMonth, month, dayOfWeek] = cronParts;
299
+ if (dayOfWeek !== '?' && dayOfMonth !== '?') {
300
+ throw new Error('Support for specifying both a day-of-week AND a day-of-month parameter is not implemented');
301
+ }
302
+ if (dayOfWeek === '2-6' ||
303
+ (dayOfWeek === '?' && (dayOfMonth === '*' || dayOfMonth.startsWith('*')))) {
304
+ return Object.assign({ hours,
305
+ minutes,
306
+ seconds }, methods.buildConfigForDailyRecurrence(dayOfMonth, dayOfWeek));
307
+ }
308
+ else if (/^([1-7](,[1-7])*)$/.test(dayOfWeek) || dayOfWeek === '*') {
309
+ return Object.assign({ hours,
310
+ minutes,
311
+ seconds }, methods.buildConfigForWeeklyRecurrence(dayOfWeek));
312
+ }
313
+ else if (dayOfWeek.includes('L') ||
314
+ dayOfWeek.includes('#') ||
315
+ (/^([1-9]|[12]\d|3[01])$/.test(dayOfMonth) && dayOfWeek === '?')) {
316
+ if (month != '*' && !month.startsWith('*/')) {
317
+ return Object.assign({ hours,
318
+ minutes,
319
+ seconds }, methods.buildConfigForYearlyRecurrence(dayOfMonth, month, dayOfWeek));
320
+ }
321
+ else {
322
+ return Object.assign({ hours,
323
+ minutes,
324
+ seconds }, methods.buildConfigForMonthlyRecurrence(dayOfMonth, month, dayOfWeek));
325
+ }
326
+ }
327
+ else {
328
+ throw new Error('Invalid Cron Expression');
329
+ }
330
+ }
@@ -0,0 +1,3 @@
1
+ export * from './scheduler-cron-builder';
2
+ export * from './scheduler-cron-builder.template';
3
+ export * from './scheduler-cron-builder.styles';
@@ -0,0 +1,130 @@
1
+ import { __decorate } from "tslib";
2
+ import { EventEmitter } from '@genesislcap/foundation-events';
3
+ import { customElement, observable } from '@microsoft/fast-element';
4
+ import { FoundationElement } from '@microsoft/fast-foundation';
5
+ import { CronBuilderEvents, DateOrDay, RecurrenceType, } from '../types';
6
+ import { monthlyYearlyRecurrenceStyles as styles } from './monthly-yearly-recurrence.styles';
7
+ import { monthlyYearlyRecurrenceTemplate as template } from './monthly-yearly-recurrence.template';
8
+ let MonthlyYearlyRecurrence = class MonthlyYearlyRecurrence extends EventEmitter(FoundationElement) {
9
+ constructor() {
10
+ super(...arguments);
11
+ /**
12
+ * This variable is used with `MONTHLY` & `YEARLY` recurrence Type
13
+ * Used to determine if the event should occur either at
14
+ * 1. specific date of the month [1-31].(e.g. 2nd of every month)
15
+ * 2. specific day of the week in the provided week (e.g. 2nd(week number) Tuesday of every month)
16
+ *
17
+ * See {@link DateOrDay}
18
+ * @internal
19
+ */
20
+ this.dayOrDate = DateOrDay.DATE;
21
+ /**
22
+ * This variable is used with both `YEARLY` and `MONTHLY` recurrence Type
23
+ * Used to specify the week number when `day of month` option is selected {@link DateOrDay.DAY_OF_MONTH}
24
+ * allows user to select from 1st,2nd,3rd,4th or last week options
25
+ * @defaultValue `1` for First Week
26
+ * @internal
27
+ */
28
+ this.weekNumber = '1';
29
+ /**
30
+ * This variable is used with both `YEARLY` and `MONTHLY` recurrence Type
31
+ * Used to specify the day of week(Mon-Sunday) when `day of month` option is selected {@link DateOrDay.DAY_OF_MONTH}
32
+ * allows user to select from 1st,2nd,3rd,4th or last week options
33
+ * @defaultValue `1` for Monday
34
+ * @internal
35
+ */
36
+ this.day = '1'; // Monday, Tuesday, etc.
37
+ /**
38
+ * This variable is used with `YEARLY` recurrence Type
39
+ * Used to set the month (1-12) on which the event should occur
40
+ * Should be between 1-12 similar to the no of months(Jan-Dec)
41
+ * @defaultValue `1` for January
42
+ * @internal
43
+ */
44
+ this.selectedMonth = '1';
45
+ }
46
+ configChanged() {
47
+ this.dayOrDate = this.config.dateOrDay.type || DateOrDay.DATE;
48
+ this.setFieldsFromConfig();
49
+ }
50
+ /**
51
+ * used to set fields from the parent config,
52
+ * @internal
53
+ * */
54
+ setFieldsFromConfig() {
55
+ if (this.config.type === RecurrenceType.YEARLY) {
56
+ this.selectedMonth = this.config.dateOrDay.month;
57
+ }
58
+ if (this.config.dateOrDay.type === DateOrDay.DAY_OF_MONTH) {
59
+ this.weekNumber = this.config.dateOrDay.weekNumber || '1';
60
+ this.day = this.config.dateOrDay.day || '1';
61
+ }
62
+ else {
63
+ this.dayDate = this.config.dateOrDay.dayDate || '1';
64
+ }
65
+ }
66
+ /**
67
+ * used to construct dateOrDay type for updating cron expression for monthly or yearly recurrence
68
+ * see {@link MonthlyDateDay} {@link YearlyDateDay} for details
69
+ * @internal
70
+ * */
71
+ getDayOrDateConfig() {
72
+ let dayDateConfig;
73
+ if (this.dayOrDate === DateOrDay.DATE) {
74
+ dayDateConfig = {
75
+ type: DateOrDay.DATE,
76
+ dayDate: this.dayDate || '1',
77
+ };
78
+ }
79
+ else {
80
+ dayDateConfig = {
81
+ type: DateOrDay.DAY_OF_MONTH,
82
+ day: this.day || '1',
83
+ weekNumber: this.weekNumber || '1',
84
+ };
85
+ }
86
+ return dayDateConfig;
87
+ }
88
+ /**
89
+ * emits an event to update cron config and cron expression for monthly or yearly config
90
+ * @internal
91
+ * */
92
+ updateCronConfig() {
93
+ if (this.config.type === RecurrenceType.MONTHLY) {
94
+ this.config = Object.assign(Object.assign({}, this.config), { dateOrDay: this.getDayOrDateConfig() });
95
+ }
96
+ else {
97
+ this.config = Object.assign(Object.assign({}, this.config), { dateOrDay: Object.assign(Object.assign({}, this.getDayOrDateConfig()), { month: this.selectedMonth || '1' }) });
98
+ }
99
+ this.$emit(CronBuilderEvents.updateCronConfig, this.config);
100
+ }
101
+ };
102
+ __decorate([
103
+ observable
104
+ ], MonthlyYearlyRecurrence.prototype, "prefix", void 0);
105
+ __decorate([
106
+ observable
107
+ ], MonthlyYearlyRecurrence.prototype, "config", void 0);
108
+ __decorate([
109
+ observable
110
+ ], MonthlyYearlyRecurrence.prototype, "dayOrDate", void 0);
111
+ __decorate([
112
+ observable
113
+ ], MonthlyYearlyRecurrence.prototype, "dayDate", void 0);
114
+ __decorate([
115
+ observable
116
+ ], MonthlyYearlyRecurrence.prototype, "weekNumber", void 0);
117
+ __decorate([
118
+ observable
119
+ ], MonthlyYearlyRecurrence.prototype, "day", void 0);
120
+ __decorate([
121
+ observable
122
+ ], MonthlyYearlyRecurrence.prototype, "selectedMonth", void 0);
123
+ MonthlyYearlyRecurrence = __decorate([
124
+ customElement({
125
+ name: 'monthly-yearly-recurrence',
126
+ template,
127
+ styles,
128
+ })
129
+ ], MonthlyYearlyRecurrence);
130
+ export { MonthlyYearlyRecurrence };
@@ -0,0 +1,25 @@
1
+ import { css } from '@microsoft/fast-element';
2
+ import { inputControls } from '../scheduler-cron-builder.styles';
3
+ export const monthlyYearlyRecurrenceStyles = css `
4
+ ${inputControls}
5
+ :host {
6
+ display: flex;
7
+ flex-direction: column;
8
+ gap: calc(var(--design-unit) * 4px);
9
+ }
10
+
11
+ .weekdays-row {
12
+ display: flex;
13
+ gap: calc(var(--design-unit) * 3px);
14
+ }
15
+
16
+ .day-of-month-row {
17
+ display: flex;
18
+ gap: calc(var(--design-unit) * 4px);
19
+ width: 100%;
20
+ }
21
+
22
+ .day-date-number-field::part(root) {
23
+ width: 40%;
24
+ }
25
+ `;
@@ -0,0 +1,92 @@
1
+ import { sync, whenElse } from '@genesislcap/foundation-utils';
2
+ import { html, repeat, when } from '@microsoft/fast-element';
3
+ import { DateOrDay, daysOfWeek, months, RecurrenceType, weekNumber } from '../types';
4
+ const dayOrDateTemplate = (prefix) => html `
5
+ <div class="input-container">
6
+ <label class="label">On</label>
7
+ <${prefix}-select
8
+ data-test-id="select-day-or-date"
9
+ :value=${sync((x) => x.dayOrDate)}
10
+ @change="${(x) => x.updateCronConfig()}"
11
+ >
12
+ <${prefix}-option data-test-id="${DateOrDay.DATE}">
13
+ ${DateOrDay.DATE}
14
+ </${prefix}-option>
15
+ <${prefix}-option data-test-id="${DateOrDay.DAY_OF_MONTH}">
16
+ ${DateOrDay.DAY_OF_MONTH}
17
+ </${prefix}-option>
18
+ </${prefix}-select>
19
+ </div>
20
+ `;
21
+ const monthTemplate = (prefix) => html `
22
+ <div class="input-container">
23
+ <label class="label">Month</label>
24
+ <${prefix}-select data-test-id="month-dropdown" :value=${sync((x) => x.selectedMonth)} @change="${(x) => x.updateCronConfig()}" >
25
+ ${repeat(() => months, html `
26
+ <${prefix}-option value="${(x) => x.value}">
27
+ ${(x) => x.label}
28
+ </${prefix}-option>
29
+ `)}
30
+ </${prefix}-select>
31
+ </div>
32
+ `;
33
+ const dateTemplate = (prefix) => html `
34
+ <div class="row">
35
+ ${when((x) => x.config.type === RecurrenceType.YEARLY, html `
36
+ ${monthTemplate(prefix)}
37
+ `)}
38
+ <div class="input-container">
39
+ <label class="label"> ${(x) => (x.config.type === RecurrenceType.MONTHLY ? 'Day date' : 'Day')}</label>
40
+ <${prefix}-select data-test-id="day-date-dropdown" :value=${sync((x) => x.dayDate)} @change="${(x) => x.updateCronConfig()}" >
41
+ ${repeat(() => Array.from({ length: 31 }, (_, i) => i + 1), html `
42
+ <${prefix}-option value="${(x) => x}">
43
+ ${(x) => x}
44
+ </${prefix}-option>
45
+ `)}
46
+ </${prefix}-select>
47
+ </div>
48
+ </div>
49
+
50
+ `;
51
+ const dayOfMonthTemplate = (prefix) => html `
52
+ <div class="day-of-month-row">
53
+ ${when((x) => x.config.type === RecurrenceType.YEARLY, html `
54
+ ${monthTemplate(prefix)}
55
+ `)}
56
+ <div class="input-container">
57
+ <label class="label">Day of Month</label>
58
+ <${prefix}-select
59
+ data-test-id="select-week-number"
60
+ :value=${sync((x) => x.weekNumber)}
61
+ @change="${(x) => x.updateCronConfig()}"
62
+ >
63
+ ${repeat(() => weekNumber, html `
64
+ <${prefix}-option value="${(x) => x.value}">
65
+ ${(x) => x.label}
66
+ </${prefix}-option>
67
+ `)}
68
+ </${prefix}-select>
69
+ </div>
70
+ <div class="input-container">
71
+ <label class="label">Day</label>
72
+ <${prefix}-select
73
+ data-test-id="select-week-day"
74
+ :value=${sync((x) => x.day)}
75
+ @change="${(x) => x.updateCronConfig()}"
76
+ >
77
+ ${repeat(() => daysOfWeek, html `
78
+ <${prefix}-option value="${(x) => x.value}">
79
+ ${(x) => x.label}
80
+ </${prefix}-option>
81
+ `)}
82
+ </${prefix}-select>
83
+ </div>
84
+ </div>
85
+ `;
86
+ export const getPrefixedMonthlyYearlyRecurrence = (prefix) => html `
87
+ ${dayOrDateTemplate(prefix)}
88
+ ${whenElse((x) => x.dayOrDate === DateOrDay.DATE, dateTemplate(prefix), dayOfMonthTemplate(prefix))}
89
+ `;
90
+ export const monthlyYearlyRecurrenceTemplate = html `
91
+ ${(x) => getPrefixedMonthlyYearlyRecurrence(x.prefix)}
92
+ `;