@gravitee/ui-components 3.25.3-typescript-ad6021f → 3.25.3-typescript-bfd8f67

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 (188) hide show
  1. package/package.json +5 -8
  2. package/src/atoms/gv-autocomplete.js +1 -461
  3. package/src/atoms/gv-button.js +1 -410
  4. package/src/atoms/gv-checkbox.js +1 -187
  5. package/src/atoms/gv-date-picker-calendar.js +1 -894
  6. package/src/atoms/gv-date-picker-cell.js +1 -190
  7. package/src/atoms/gv-date-picker.js +1 -671
  8. package/src/atoms/gv-file-upload.js +1 -367
  9. package/src/atoms/gv-icon.js +1 -103
  10. package/src/atoms/gv-image.js +1 -144
  11. package/src/atoms/gv-input-message.js +1 -84
  12. package/src/atoms/gv-input.js +1 -561
  13. package/src/atoms/gv-link.js +1 -210
  14. package/src/atoms/gv-message.js +1 -128
  15. package/src/atoms/gv-metric.js +1 -117
  16. package/src/atoms/gv-relative-time.js +1 -156
  17. package/src/atoms/gv-select-native.js +1 -388
  18. package/src/atoms/gv-select.js +1 -437
  19. package/src/atoms/gv-spinner.js +1 -57
  20. package/src/atoms/gv-state.js +1 -130
  21. package/src/atoms/gv-switch.js +1 -243
  22. package/src/atoms/gv-tag.js +1 -168
  23. package/src/atoms/gv-text.js +1 -168
  24. package/src/charts/gv-chart-bar.js +1 -103
  25. package/src/charts/gv-chart-gauge.js +1 -100
  26. package/src/charts/gv-chart-histogram.js +1 -83
  27. package/src/charts/gv-chart-line.js +1 -224
  28. package/src/charts/gv-chart-map.js +1 -112
  29. package/src/charts/gv-chart-pie.js +1 -91
  30. package/src/index.js +1 -77
  31. package/src/lib/cron-expression.js +1 -205
  32. package/src/lib/date.js +1 -44
  33. package/src/lib/events.js +1 -26
  34. package/src/lib/http-client-schema-form.js +1 -67
  35. package/src/lib/http.js +1 -237
  36. package/src/lib/i18n.js +1 -103
  37. package/src/lib/item.js +1 -118
  38. package/src/lib/properties.js +1 -189
  39. package/src/lib/schema-form.js +1 -44
  40. package/src/lib/studio.js +1 -141
  41. package/src/lib/style.js +1 -41
  42. package/src/lib/text-format.js +1 -69
  43. package/src/lib/theme.js +1 -63
  44. package/src/lib/utils.js +1 -111
  45. package/src/mixins/chart-element.js +1 -165
  46. package/src/mixins/input-element.js +1 -144
  47. package/src/mixins/item-resource.js +1 -120
  48. package/src/mixins/keyboard-element.js +1 -69
  49. package/src/mixins/update-after-browser.js +1 -30
  50. package/src/mixins/with-resize-observer.js +1 -68
  51. package/src/mixins/with-skeleton-attribute.js +1 -112
  52. package/src/molecules/gv-card-full.js +1 -218
  53. package/src/molecules/gv-card-list.js +1 -113
  54. package/src/molecules/gv-card.js +1 -133
  55. package/src/molecules/gv-category-list.js +1 -60
  56. package/src/molecules/gv-category.js +1 -170
  57. package/src/molecules/gv-code.js +1 -359
  58. package/src/molecules/gv-confirm.js +1 -188
  59. package/src/molecules/gv-cron-editor.js +1 -710
  60. package/src/molecules/gv-dropdown-menu.js +1 -116
  61. package/src/molecules/gv-expandable.js +1 -122
  62. package/src/molecules/gv-expression-language.js +1 -270
  63. package/src/molecules/gv-identity-picture.js +1 -148
  64. package/src/molecules/gv-list.js +1 -227
  65. package/src/molecules/gv-metrics.js +1 -162
  66. package/src/molecules/gv-modal.js +1 -213
  67. package/src/molecules/gv-nav.js +1 -196
  68. package/src/molecules/gv-option.js +1 -242
  69. package/src/molecules/gv-plans.js +1 -429
  70. package/src/molecules/gv-popover.js +1 -351
  71. package/src/molecules/gv-promote.js +1 -209
  72. package/src/molecules/gv-rating-list.js +1 -365
  73. package/src/molecules/gv-rating.js +1 -253
  74. package/src/molecules/gv-row-expandable.js +1 -45
  75. package/src/molecules/gv-row.js +1 -210
  76. package/src/molecules/gv-stats.js +1 -121
  77. package/src/molecules/gv-stepper.js +1 -288
  78. package/src/molecules/gv-table.js +1 -685
  79. package/src/molecules/gv-tree.js +1 -250
  80. package/src/organisms/gv-documentation.js +1 -215
  81. package/src/organisms/gv-header.js +1 -288
  82. package/src/organisms/gv-http-client.js +1 -275
  83. package/src/organisms/gv-menu.js +1 -263
  84. package/src/organisms/gv-newsletter-subscription.js +1 -271
  85. package/src/organisms/gv-pagination.js +1 -198
  86. package/src/organisms/gv-properties.js +1 -920
  87. package/src/organisms/gv-resizable-views.js +1 -396
  88. package/src/organisms/gv-resources.js +1 -535
  89. package/src/organisms/gv-schema-form-array.js +1 -250
  90. package/src/organisms/gv-schema-form-control-object.js +1 -154
  91. package/src/organisms/gv-schema-form-control.js +1 -443
  92. package/src/organisms/gv-schema-form.js +1 -751
  93. package/src/organisms/gv-tabs.js +1 -210
  94. package/src/organisms/gv-user-menu.js +1 -314
  95. package/src/organisms/gv-vertical-menu.js +1 -123
  96. package/src/policy-studio/gv-flow-step.js +1 -464
  97. package/src/policy-studio/gv-flow.js +1 -621
  98. package/src/policy-studio/gv-policy-studio-menu.js +1 -750
  99. package/src/policy-studio/gv-policy-studio.js +1 -1842
  100. package/src/styles/empty.js +1 -36
  101. package/src/styles/input.js +1 -263
  102. package/src/styles/link.js +1 -32
  103. package/src/styles/shapes.js +1 -17
  104. package/src/styles/skeleton.js +1 -53
  105. package/src/styles/zoom.js +1 -40
  106. package/src/theme/gv-theme.js +1 -203
  107. package/wc/gv-autocomplete.js +1 -1
  108. package/wc/gv-button.js +1 -1
  109. package/wc/gv-card-full.js +1 -1
  110. package/wc/gv-card-list.js +1 -1
  111. package/wc/gv-card.js +1 -1
  112. package/wc/gv-category-list.js +1 -1
  113. package/wc/gv-category.js +1 -1
  114. package/wc/gv-chart-bar.js +1 -1
  115. package/wc/gv-chart-gauge.js +1 -1
  116. package/wc/gv-chart-histogram.js +1 -1
  117. package/wc/gv-chart-line.js +1 -1
  118. package/wc/gv-chart-map.js +1 -1
  119. package/wc/gv-chart-pie.js +1 -1
  120. package/wc/gv-checkbox.js +1 -1
  121. package/wc/gv-code.js +1 -1
  122. package/wc/gv-confirm.js +1 -1
  123. package/wc/gv-cron-editor.js +1 -1
  124. package/wc/gv-date-picker-calendar.js +1 -1
  125. package/wc/gv-date-picker-cell.js +1 -1
  126. package/wc/gv-date-picker.js +1 -1
  127. package/wc/gv-documentation.js +1 -1
  128. package/wc/gv-dropdown-menu.js +1 -1
  129. package/wc/gv-expandable.js +1 -1
  130. package/wc/gv-expression-language.js +1 -1
  131. package/wc/gv-file-upload.js +1 -1
  132. package/wc/gv-flow-step.js +1 -1
  133. package/wc/gv-flow.js +1 -1
  134. package/wc/gv-header.js +1 -1
  135. package/wc/gv-http-client.js +1 -1
  136. package/wc/gv-icon.js +1 -1
  137. package/wc/gv-identity-picture.js +1 -1
  138. package/wc/gv-image.js +1 -1
  139. package/wc/gv-input-message.js +1 -1
  140. package/wc/gv-input.js +1 -1
  141. package/wc/gv-link.js +1 -1
  142. package/wc/gv-list.js +1 -1
  143. package/wc/gv-menu.js +1 -1
  144. package/wc/gv-message.js +1 -1
  145. package/wc/gv-metric.js +1 -1
  146. package/wc/gv-metrics.js +1 -1
  147. package/wc/gv-modal.js +1 -1
  148. package/wc/gv-nav.js +1 -1
  149. package/wc/gv-newsletter-subscription.js +1 -1
  150. package/wc/gv-option.js +1 -1
  151. package/wc/gv-pagination.js +1 -1
  152. package/wc/gv-plans.js +1 -1
  153. package/wc/gv-policy-studio-menu.js +1 -1
  154. package/wc/gv-policy-studio.js +1 -1
  155. package/wc/gv-popover.js +1 -1
  156. package/wc/gv-promote.js +1 -1
  157. package/wc/gv-properties.js +1 -1
  158. package/wc/gv-rating-list.js +1 -1
  159. package/wc/gv-rating.js +1 -1
  160. package/wc/gv-relative-time.js +1 -1
  161. package/wc/gv-resizable-views.js +1 -1
  162. package/wc/gv-resources.js +1 -1
  163. package/wc/gv-row-expandable.js +1 -1
  164. package/wc/gv-row.js +1 -1
  165. package/wc/gv-schema-form-array.js +1 -1
  166. package/wc/gv-schema-form-control-object.js +1 -1
  167. package/wc/gv-schema-form-control.js +1 -1
  168. package/wc/gv-schema-form.js +1 -1
  169. package/wc/gv-select-native.js +1 -1
  170. package/wc/gv-select.js +1 -1
  171. package/wc/gv-spinner.js +1 -1
  172. package/wc/gv-state.js +1 -1
  173. package/wc/gv-stats.js +1 -1
  174. package/wc/gv-stepper.js +1 -1
  175. package/wc/gv-switch.js +1 -1
  176. package/wc/gv-table.js +1 -1
  177. package/wc/gv-tabs.js +1 -1
  178. package/wc/gv-tag.js +1 -1
  179. package/wc/gv-text.js +1 -1
  180. package/wc/gv-theme.js +1 -1
  181. package/wc/gv-tree.js +1 -1
  182. package/wc/gv-user-menu.js +1 -1
  183. package/wc/gv-vertical-menu.js +1 -1
  184. package/CHANGELOG.md +0 -1292
  185. package/LICENSE.txt +0 -202
  186. package/README.md +0 -195
  187. package/src/.eslintrc.js +0 -19
  188. package/src/theme/definition.json +0 -1762
@@ -1,710 +1 @@
1
- /*
2
- * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import '../atoms/gv-date-picker';
17
- import '../organisms/gv-tabs';
18
- import '../atoms/gv-input';
19
- import '../atoms/gv-tag';
20
- import { css, LitElement, html } from 'lit';
21
- import { skeleton } from '../styles/skeleton';
22
- import { InputElement } from '../mixins/input-element';
23
- import { set } from 'object-path';
24
- import { repeat } from 'lit/directives/repeat';
25
- import { withResizeObserver } from '../mixins/with-resize-observer';
26
- import { isValidCron } from '../lib/cron-expression';
27
- import { dispatchCustomEvent } from '../lib/events';
28
-
29
- /**
30
- * Cron editor component
31
- *
32
- * ## Details
33
- *
34
- * @fires gv-cron-editor:input - input events with the `value` on `detail`
35
- *
36
- * @attr {String} label - cron editor label
37
- * @attr {String} value - cron expression
38
- * @attr {String} mode - the opened mode (if no value is set, the pro mode will be opened)
39
- *
40
- * @attr {Boolean} [clipboard=false]- true if field has clipboard button
41
- * @attr {Boolean} [autofocus=false] - true to put the focus on the input
42
- * @attr {Boolean} [readonly=false] - true if field is readonly mode
43
- */
44
- export class GvCronEditor extends withResizeObserver(InputElement(LitElement)) {
45
- static get properties() {
46
- return {
47
- ...super.properties,
48
- mode: { type: String },
49
- _value: { type: String, attribute: false },
50
- _currentDocumentationId: { type: String, attribute: false },
51
- _small: { type: Boolean },
52
- _truncateTabs: { type: Boolean },
53
- };
54
- }
55
-
56
- constructor() {
57
- super();
58
- this._value = '';
59
- this.readonly = false;
60
- this.autofocus = false;
61
- this.clipboard = false;
62
- this._modes = ['seconds', 'minutes', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'pro'];
63
- this._timeRange = [...Array(60).keys()];
64
- this._days = [
65
- { value: 'MON', label: 'Monday' },
66
- { value: 'TUE', label: 'Tuesday' },
67
- { value: 'WED', label: 'Wednesday' },
68
- { value: 'THU', label: 'Thursday' },
69
- { value: 'FRI', label: 'Friday' },
70
- { value: 'SAT', label: 'Saturday' },
71
- { value: 'SUN', label: 'Sunday' },
72
- ];
73
- this._months = [
74
- 'January',
75
- 'February',
76
- 'March',
77
- 'April',
78
- 'May',
79
- 'June',
80
- 'July',
81
- 'August',
82
- 'September',
83
- 'October',
84
- 'November',
85
- 'December',
86
- ];
87
- this._state = {
88
- seconds: {
89
- seconds: 1,
90
- },
91
- minutes: {
92
- minutes: 1,
93
- seconds: 0,
94
- },
95
- hourly: {
96
- hours: 1,
97
- minutes: 0,
98
- seconds: 0,
99
- },
100
- daily: {
101
- days: 1,
102
- time: 0,
103
- weekdays: false,
104
- },
105
- weekly: {
106
- days: [],
107
- time: 0,
108
- },
109
- monthly: {
110
- day: 1,
111
- month: 1,
112
- time: 0,
113
- },
114
- yearly: {
115
- day: 1,
116
- month: 1,
117
- time: 0,
118
- },
119
- pro: {
120
- value: '',
121
- displayDetails: false,
122
- },
123
- };
124
-
125
- this._docs = [
126
- { id: 'second', label: 'Second' },
127
- { id: 'minute', label: 'Minute' },
128
- { id: 'hour', label: 'Hour' },
129
- { id: 'day-month', label: 'Day (month)' },
130
- { id: 'month', label: 'Month' },
131
- { id: 'day-week', label: 'Day (week)' },
132
- ];
133
-
134
- this._currentDocumentationId = this._docs[0].id;
135
- this._handleChange = this._onChange.bind(this);
136
- this._small = false;
137
- }
138
-
139
- tryToComputeAndInitModeFromValue() {
140
- if (!this.value || this.mode) {
141
- this.mode = this.mode || 'pro';
142
- return;
143
- }
144
- const [seconds, minutes, hours] = this.value.split(' ');
145
-
146
- if (/\d+ \d+ \*\/\d+ \* \* \*/.test(this.value)) {
147
- // Match: `1 42 */15 * * *`
148
- this.mode = 'hourly';
149
- this._state.hourly.hours = Number(hours.replace('*/', ''));
150
- this._state.hourly.minutes = Number(minutes);
151
- this._state.hourly.seconds = Number(seconds);
152
- } else if (/\d+ \*\/\d+ \* \* \* \*/.test(this.value)) {
153
- // Match: `1 */15 * * * *`
154
- this.mode = 'minutes';
155
- this._state.minutes.minutes = Number(minutes.replace('*/', ''));
156
- this._state.minutes.seconds = Number(seconds);
157
- } else if (/\*\/\d+ \* \* \* \* \*/.test(this.value)) {
158
- // Match: `*/15 * * * * *`
159
- this.mode = 'seconds';
160
- this._state.seconds.seconds = Number(seconds.replace('*/', ''));
161
- } else {
162
- this.mode = 'pro';
163
- }
164
- }
165
-
166
- onResize({ width }) {
167
- this._truncateTabs = width < 750;
168
- this._small = width < 449;
169
- }
170
-
171
- set value(value) {
172
- if (isValidCron(value, { seconds: true, alias: true })) {
173
- this._value = value;
174
- if (this._state.pro.value === '') {
175
- this._state.pro.value = value;
176
- }
177
- }
178
- }
179
-
180
- get value() {
181
- if (this.mode === 'pro') {
182
- return this._state.pro.value;
183
- }
184
- return this._value;
185
- }
186
-
187
- async firstUpdated() {
188
- this.tryToComputeAndInitModeFromValue();
189
-
190
- // Give the browser a chance to paint
191
- // eslint-disable-next-line promise/param-names
192
- await new Promise((r) => setTimeout(r, 0));
193
-
194
- this.shadowRoot.querySelectorAll('gv-input, gv-date-picker, gv-checkbox, gv-select').forEach((element) => {
195
- element.addEventListener(`${element.tagName.toLowerCase()}:input`, this._handleChange);
196
- });
197
- }
198
-
199
- _onOpenDocumentation(docId) {
200
- this._currentDocumentationId = docId;
201
- }
202
-
203
- _onChange({ target, detail }) {
204
- if (target.id === 'cron-input' && this.mode !== 'pro') {
205
- this.mode = 'pro';
206
- }
207
- if (target.valid) {
208
- if (target.name == null) {
209
- throw new Error('Field target must have a name to update the state');
210
- }
211
- const tagName = target.tagName.toLowerCase();
212
- let value = detail;
213
- if (tagName === 'gv-date-picker') {
214
- value = new Date(detail);
215
- } else if (target.type === 'number') {
216
- value = Number(detail).valueOf();
217
- }
218
- set(this._state, target.name, value);
219
- this.generate();
220
- if (target.classList.contains('request-update')) {
221
- this.requestUpdate();
222
- }
223
- }
224
- }
225
-
226
- _onChangeTab(event) {
227
- event.preventDefault();
228
- event.stopPropagation();
229
- const {
230
- detail: { to },
231
- } = event;
232
- if (to === 'pro') {
233
- // Needs to be done first otherwise `value` is overridden before using it
234
- this._state.pro.value = this.value;
235
- }
236
- this.mode = to;
237
- this.generate();
238
- if (this.mode === 'pro') {
239
- this.shadowRoot.querySelector('#cron-input').focus();
240
- }
241
- }
242
-
243
- _getTimeExpression(date) {
244
- if (date) {
245
- return `${date.getSeconds()} ${date.getMinutes()} ${date.getHours()}`;
246
- }
247
- return '* * *';
248
- }
249
-
250
- generate() {
251
- let tmpValue = '';
252
- switch (this.mode) {
253
- case 'seconds':
254
- if (this._state.seconds.seconds) {
255
- tmpValue = `*/${this._state.seconds.seconds} * * * * *`;
256
- } else {
257
- tmpValue = `* * * * * *`;
258
- }
259
- break;
260
- case 'minutes':
261
- if (this._state.minutes.minutes) {
262
- tmpValue = `${this._state.minutes.seconds} */${this._state.minutes.minutes} * * * *`;
263
- } else {
264
- tmpValue = `${this._state.minutes.seconds} * * * * *`;
265
- }
266
- break;
267
- case 'hourly':
268
- if (this._state.hourly.hours) {
269
- tmpValue = `${this._state.hourly.seconds} ${this._state.hourly.minutes} */${this._state.hourly.hours} * * *`;
270
- } else {
271
- tmpValue = `${this._state.minutes.seconds} ${this._state.hourly.minutes} * * * *`;
272
- }
273
- break;
274
- case 'daily':
275
- if (this._state.daily.weekdays === false) {
276
- tmpValue = `${this._getTimeExpression(this._state.daily.time)} ${this._state.daily.days} * *`;
277
- } else {
278
- tmpValue = `${this._getTimeExpression(this._state.daily.time)} * * MON-FRI`;
279
- }
280
- break;
281
- case 'weekly':
282
- if (this._state.weekly.days.length === 0) {
283
- tmpValue = `${this._getTimeExpression(this._state.weekly.time)} * * *`;
284
- } else {
285
- tmpValue = `${this._getTimeExpression(this._state.weekly.time)} * * ${this._state.weekly.days.join(',')}`;
286
- }
287
- break;
288
- case 'monthly':
289
- tmpValue = `${this._getTimeExpression(this._state.monthly.time)} ${this._state.monthly.day} ${this._state.monthly.month} *`;
290
- break;
291
- case 'yearly':
292
- tmpValue = `${this._getTimeExpression(this._state.yearly.time)} ${this._state.yearly.day} */${
293
- this._months.indexOf(this._state.yearly.month) + 1
294
- } *`;
295
- break;
296
- case 'pro':
297
- tmpValue = this._state.pro.value;
298
- break;
299
- default:
300
- throw new Error('Invalid cron active tab selection');
301
- }
302
-
303
- this.updateState(tmpValue);
304
- if (this.valid) {
305
- this._value = tmpValue;
306
- this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
307
- dispatchCustomEvent(this, 'input', this.value);
308
- }
309
- }
310
-
311
- updateState(value) {
312
- super.updateState(value);
313
- if (this.valid) {
314
- if (isValidCron(value, { seconds: true, alias: true })) {
315
- this.setValidity();
316
- } else {
317
- this.setValidity(true, 'field is not valid cron expression');
318
- }
319
- }
320
- }
321
-
322
- renderLabel() {
323
- if (this.label) {
324
- return html`<label for=${this.id} title="${this.label}">${this.label}</label>`;
325
- }
326
- return '';
327
- }
328
-
329
- displayProDetails() {
330
- this._state.pro.displayDetails = !this._state.pro.displayDetails;
331
- this.requestUpdate();
332
- }
333
-
334
- renderProDetails() {
335
- if (this._state.pro.displayDetails) {
336
- return html`<div class="tab-content_pro-pane_container">
337
- <div class="tab-content_pro-pane">
338
- <div>Rules for:</div>
339
- <div>
340
- ${repeat(
341
- this._docs,
342
- (doc) => doc.id,
343
- (doc) => {
344
- const isCurrent = doc.id === this._currentDocumentationId;
345
- return html` <gv-tag
346
- @gv-tag:click="${this._onOpenDocumentation.bind(this, doc.id)}"
347
- ?clickable="${!isCurrent}"
348
- ?major="${isCurrent}"
349
- ?minor="${!isCurrent}"
350
- >${doc.label}</gv-tag
351
- >`;
352
- },
353
- )}
354
- </div>
355
- <ul class="help">
356
- <li>
357
- <small>Allowed characters: <code>${this.allowedChar}</code></small>
358
- </li>
359
- <li>
360
- <small>Allowed values: <code>${this.allowedValues}</code></small>
361
- </li>
362
- </ul>
363
- </div>
364
- <div class="tab-content_pro-pane">
365
- <div>Examples:</div>
366
- <ul class="help">
367
- <li>
368
- <small><code>*</code>: for each unit (0, 1, 2, 3...)</small>
369
- </li>
370
- <li>
371
- <small><code>5,8</code>: units 5 and 8</small>
372
- </li>
373
- <li>
374
- <small><code>2-5</code>: units from 2 to 5 (2, 3, 4, 5)</small>
375
- </li>
376
- <li>
377
- <small><code>*/3</code>: every 3 units (0, 3, 6, 9...)</small>
378
- </li>
379
- <li>
380
- <small><code>10-20/3</code>: every 3 units, between the tenth and the twentieth (10, 13, 16, 19)</small>
381
- </li>
382
- </ul>
383
- </div>
384
- </div>`;
385
- }
386
-
387
- return '';
388
- }
389
-
390
- render() {
391
- return html`<div>
392
- ${this.renderLabel()}
393
- <div class="box">
394
- <gv-tabs
395
- .value="${this.mode}"
396
- .options="${this._modes}"
397
- .disabled="${this.disabled}"
398
- ?small="${this._small}"
399
- ?truncate="${this._truncateTabs}"
400
- @gv-tabs:change="${this._onChangeTab.bind(this)}"
401
- >
402
- <div slot="title" class="generated-expression">
403
- <gv-input
404
- name="pro.value"
405
- .autofocus="${this.autofocus}"
406
- .value="${this.value}"
407
- id="cron-input"
408
- placeholder="* */30 * * * * (Every 30 min)"
409
- ></gv-input>
410
- </div>
411
-
412
- <div slot="content" id="seconds" class="tab-content">
413
- <span>Every</span>
414
- <gv-input small type="number" min="1" name="seconds.seconds" .value="${this._state.seconds.seconds}"></gv-input>
415
- <span>second(s)</span>
416
- </div>
417
-
418
- <div slot="content" id="minutes" class="tab-content">
419
- <span>Every</span>
420
- <gv-input small type="number" min="1" name="minutes.minutes" .value="${this._state.minutes.minutes}"></gv-input>
421
- <span>minute(s) on second</span>
422
- <gv-input small type="number" min="0" max="59" name="minutes.seconds" .value="${this._state.minutes.seconds}"></gv-input>
423
- </div>
424
-
425
- <div slot="content" id="hourly" class="tab-content">
426
- <span>Every</span>
427
- <gv-input small type="number" min="1" name="hourly.hours" .value="${this._state.hourly.hours}"></gv-input>
428
- <span>hour(s) on minute</span>
429
- <gv-input small type="number" min="0" max="59" name="hourly.minutes" .value="${this._state.hourly.minutes}"></gv-input>
430
- <span>and second</span>
431
- <gv-input small type="number" min="0" max="59" name="hourly.seconds" .value="${this._state.hourly.seconds}"></gv-input>
432
- </div>
433
-
434
- <div slot="content" id="daily" class="tab-content">
435
- <span>Every</span>
436
- <gv-input
437
- small
438
- type="number"
439
- min="1"
440
- max="31"
441
- name="daily.days"
442
- ?disabled="${this._state.daily.weekdays}"
443
- .value="${this._state.daily.days}"
444
- ></gv-input>
445
- <span class="line">
446
- day(s)
447
- <gv-checkbox
448
- class="request-update"
449
- label="of week"
450
- name="daily.weekdays"
451
- ?checked="${this._state.daily.weekdays}"
452
- ></gv-checkbox>
453
- at</span
454
- >
455
- <gv-date-picker small time strict name="daily.time" .value="${this._state.daily.time}"></gv-date-picker>
456
- </div>
457
-
458
- <div slot="content" id="weekly" class="tab-content tab-content_weekly">
459
- <span>Every</span>
460
- <gv-select small multiple name="weekly.days" .options="${this._days}" .value="${this._state.weekly.days}"></gv-select>
461
- <span>day(s) at</span>
462
- <gv-date-picker small time strict name="weekly.time" .value="${this._state.weekly.time}"></gv-date-picker>
463
- </div>
464
-
465
- <div slot="content" id="monthly" class="tab-content">
466
- <span>On the</span>
467
- <gv-input
468
- small
469
- type="number"
470
- min="1"
471
- max="31"
472
- name="monthly.day"
473
- class="request-update"
474
- .value="${this._state.monthly.day}"
475
- ></gv-input>
476
- <span><sup>${this._getDaySuffix(this._state.monthly.day)}</sup> </span>
477
- <span>day of every</span>
478
- <gv-input small type="number" min="1" max="12" name="monthly.month" .value="${this._state.monthly.month}"></gv-input>
479
- <span>month(s) at</span>
480
- <gv-date-picker small time strict name="monthly.time" .value="${this._state.monthly.time}"></gv-date-picker>
481
- </div>
482
-
483
- <div slot="content" id="yearly" class="tab-content">
484
- <span>Every</span>
485
- <gv-select small name="yearly.month" .options="${this._months}" .value="${this._state.yearly.month}"></gv-select>
486
- <span>on the</span>
487
- <gv-input
488
- small
489
- type="number"
490
- min="1"
491
- max="31"
492
- name="yearly.day"
493
- class="request-update"
494
- .value="${this._state.yearly.day}"
495
- ></gv-input>
496
- <span><sup>${this._getDaySuffix(this._state.yearly.day)}</sup></span>
497
- <span>day</span>
498
- <gv-date-picker small time strict name="yearly.time" .value="${this._state.yearly.time}"></gv-date-picker>
499
- </div>
500
-
501
- <div slot="content" id="pro" class="tab-content tab-content_pro">
502
- <gv-button link small class="tab-content_pro-details_btn" @click="${this.displayProDetails}">
503
- ${this._state.pro.displayDetails
504
- ? 'Hide information about cron rules and examples'
505
- : 'Display information about cron rules and examples'}
506
- </gv-button>
507
- ${this.renderProDetails()}
508
- </div>
509
- </gv-tabs>
510
- </div>
511
- </div>`;
512
- }
513
-
514
- get allowedValues() {
515
- if (this.mode === 'pro') {
516
- switch (this._currentDocumentationId) {
517
- case 'hour':
518
- return '0-23';
519
- case 'day-month':
520
- return '1-31';
521
- case 'month':
522
- return '1-12 or JAN-DEC';
523
- case 'day-week':
524
- return '1-7 or SUN-SAT';
525
- default:
526
- return '0-59';
527
- }
528
- }
529
- return '';
530
- }
531
-
532
- get allowedChar() {
533
- if (this.mode === 'pro') {
534
- return ',-*/';
535
- }
536
- return '';
537
- }
538
-
539
- _getDaySuffix(day = 1) {
540
- if (day) {
541
- if (day.toString().endsWith('1')) {
542
- return 'st';
543
- } else if (day.toString().endsWith('2')) {
544
- return 'nd';
545
- } else if (day.toString().endsWith('3')) {
546
- return 'rd';
547
- }
548
- return 'th';
549
- }
550
- return '';
551
- }
552
-
553
- static get styles() {
554
- return [
555
- skeleton,
556
- // language=CSS
557
- css`
558
- :host {
559
- box-sizing: border-box;
560
- display: block;
561
- margin: 0.2rem;
562
- }
563
-
564
- :host([invalid]) .box {
565
- border-left-color: var(--gv-theme-color-error-dark, #d32f2f);
566
- border-left-width: 3px;
567
- }
568
-
569
- .box {
570
- border: 1px solid var(--gv-theme-neutral-color-dark, #bfbfbf);
571
- border-radius: 4px;
572
- }
573
-
574
- .generated-expression {
575
- display: flex;
576
- align-items: center;
577
- flex: 1;
578
- }
579
-
580
- .generated-expression > span,
581
- .generated-expression > code {
582
- margin: 0.4rem;
583
- }
584
-
585
- .generated-expression gv-input,
586
- .generated-expression code {
587
- --input-small--fz: 16px;
588
- font-size: 16px;
589
- }
590
-
591
- .generated-expression gv-input {
592
- --gv-input--bdc: transparent;
593
- margin: 0;
594
- min-width: 190px;
595
- }
596
-
597
- .tab-content {
598
- display: flex;
599
- align-items: center;
600
- background-color: var(--gv-theme-neutral-color, #f5f5f5);
601
- font-style: italic;
602
- font-size: var(--gv-theme-font-size-s, 12px);
603
- padding: 0.2rem;
604
- }
605
-
606
- .tab-content > * {
607
- margin: 0.2rem;
608
- }
609
-
610
- .tab-content gv-input[type='number'] {
611
- width: 50px;
612
- }
613
-
614
- .tab-content_weekly gv-select {
615
- width: auto;
616
- }
617
-
618
- .tab-content_pro code {
619
- font-size: 14px;
620
- font-weight: bold;
621
- font-style: normal;
622
- }
623
-
624
- .tab-content_pro {
625
- display: flex;
626
- flex-direction: column;
627
- align-items: normal;
628
- --gv-icon--s: 18px;
629
- padding: 0.2rem;
630
- }
631
-
632
- .tab-content_pro-details_btn {
633
- --gv-button--fz: 12px;
634
- }
635
-
636
- .tab-content_pro-pane_container {
637
- display: flex;
638
- flex-direction: row;
639
- }
640
-
641
- .tab-content_pro-pane {
642
- flex: auto;
643
- }
644
-
645
- .tab-content_pro > * {
646
- margin: 0.2rem;
647
- }
648
-
649
- .tab-content_pro small,
650
- .tab-content_pro gv-icon {
651
- margin: 0 0.2rem;
652
- }
653
-
654
- gv-tabs {
655
- --gv-tabs-options--m: auto 0.2rem auto 0;
656
- }
657
-
658
- gv-tabs[small] {
659
- --gv-tabs-options--m: auto 0;
660
- }
661
-
662
- gv-tabs[small] .tab-content {
663
- padding: 0;
664
- }
665
-
666
- .line {
667
- display: flex;
668
- align-items: center;
669
- margin: 0;
670
- }
671
-
672
- .line > * {
673
- margin: 0 0.3rem;
674
- }
675
-
676
- gv-checkbox {
677
- text-decoration: line-through;
678
- font-weight: normal;
679
- }
680
-
681
- gv-checkbox[checked] {
682
- text-decoration: none;
683
- }
684
-
685
- sup {
686
- display: inline-block;
687
- font-size: var(--gv-theme-font-size-s, 12px);
688
- }
689
-
690
- ul {
691
- list-style: none;
692
- margin: 0.5rem 1rem;
693
- padding: 0;
694
- }
695
-
696
- ul.help {
697
- padding-left: 0.2rem;
698
- margin-left: 0.4rem;
699
- border-left: 2px dotted var(--gv-theme-neutral-color-dark, #bfbfbf);
700
- }
701
-
702
- small {
703
- font-size: var(--gv-theme-font-size-s, 12px);
704
- }
705
- `,
706
- ];
707
- }
708
- }
709
-
710
- window.customElements.define('gv-cron-editor', GvCronEditor);
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvCronEditor=void 0,require("../atoms/gv-date-picker"),require("../organisms/gv-tabs"),require("../atoms/gv-input"),require("../atoms/gv-tag");const e=require("lit"),t=require("../styles/skeleton"),s=require("../mixins/input-element"),a=require("object-path"),i=require("lit/directives/repeat"),n=require("../mixins/with-resize-observer"),l=require("../lib/cron-expression"),o=require("../lib/events");class r extends((0,n.withResizeObserver)((0,s.InputElement)(e.LitElement))){static get properties(){return{...super.properties,mode:{type:String},_value:{type:String,attribute:!1},_currentDocumentationId:{type:String,attribute:!1},_small:{type:Boolean},_truncateTabs:{type:Boolean}}}constructor(){super(),this._value="",this.readonly=!1,this.autofocus=!1,this.clipboard=!1,this._modes=["seconds","minutes","hourly","daily","weekly","monthly","yearly","pro"],this._timeRange=[...Array(60).keys()],this._days=[{value:"MON",label:"Monday"},{value:"TUE",label:"Tuesday"},{value:"WED",label:"Wednesday"},{value:"THU",label:"Thursday"},{value:"FRI",label:"Friday"},{value:"SAT",label:"Saturday"},{value:"SUN",label:"Sunday"}],this._months=["January","February","March","April","May","June","July","August","September","October","November","December"],this._state={seconds:{seconds:1},minutes:{minutes:1,seconds:0},hourly:{hours:1,minutes:0,seconds:0},daily:{days:1,time:0,weekdays:!1},weekly:{days:[],time:0},monthly:{day:1,month:1,time:0},yearly:{day:1,month:1,time:0},pro:{value:"",displayDetails:!1}},this._docs=[{id:"second",label:"Second"},{id:"minute",label:"Minute"},{id:"hour",label:"Hour"},{id:"day-month",label:"Day (month)"},{id:"month",label:"Month"},{id:"day-week",label:"Day (week)"}],this._currentDocumentationId=this._docs[0].id,this._handleChange=this._onChange.bind(this),this._small=!1}tryToComputeAndInitModeFromValue(){if(!this.value||this.mode)return void(this.mode=this.mode||"pro");const[e,t,s]=this.value.split(" ");/\d+ \d+ \*\/\d+ \* \* \*/.test(this.value)?(this.mode="hourly",this._state.hourly.hours=Number(s.replace("*/","")),this._state.hourly.minutes=Number(t),this._state.hourly.seconds=Number(e)):/\d+ \*\/\d+ \* \* \* \*/.test(this.value)?(this.mode="minutes",this._state.minutes.minutes=Number(t.replace("*/","")),this._state.minutes.seconds=Number(e)):/\*\/\d+ \* \* \* \* \*/.test(this.value)?(this.mode="seconds",this._state.seconds.seconds=Number(e.replace("*/",""))):this.mode="pro"}onResize({width:e}){this._truncateTabs=e<750,this._small=e<449}set value(e){(0,l.isValidCron)(e,{seconds:!0,alias:!0})&&(this._value=e,""===this._state.pro.value&&(this._state.pro.value=e))}get value(){return"pro"===this.mode?this._state.pro.value:this._value}async firstUpdated(){this.tryToComputeAndInitModeFromValue(),await new Promise((e=>setTimeout(e,0))),this.shadowRoot.querySelectorAll("gv-input, gv-date-picker, gv-checkbox, gv-select").forEach((e=>{e.addEventListener(`${e.tagName.toLowerCase()}:input`,this._handleChange)}))}_onOpenDocumentation(e){this._currentDocumentationId=e}_onChange({target:e,detail:t}){if("cron-input"===e.id&&"pro"!==this.mode&&(this.mode="pro"),e.valid){if(null==e.name)throw new Error("Field target must have a name to update the state");let s=t;"gv-date-picker"===e.tagName.toLowerCase()?s=new Date(t):"number"===e.type&&(s=Number(t).valueOf()),(0,a.set)(this._state,e.name,s),this.generate(),e.classList.contains("request-update")&&this.requestUpdate()}}_onChangeTab(e){e.preventDefault(),e.stopPropagation();const{detail:{to:t}}=e;"pro"===t&&(this._state.pro.value=this.value),this.mode=t,this.generate(),"pro"===this.mode&&this.shadowRoot.querySelector("#cron-input").focus()}_getTimeExpression(e){return e?`${e.getSeconds()} ${e.getMinutes()} ${e.getHours()}`:"* * *"}generate(){let e="";switch(this.mode){case"seconds":e=this._state.seconds.seconds?`*/${this._state.seconds.seconds} * * * * *`:"* * * * * *";break;case"minutes":e=this._state.minutes.minutes?`${this._state.minutes.seconds} */${this._state.minutes.minutes} * * * *`:`${this._state.minutes.seconds} * * * * *`;break;case"hourly":e=this._state.hourly.hours?`${this._state.hourly.seconds} ${this._state.hourly.minutes} */${this._state.hourly.hours} * * *`:`${this._state.minutes.seconds} ${this._state.hourly.minutes} * * * *`;break;case"daily":e=!1===this._state.daily.weekdays?`${this._getTimeExpression(this._state.daily.time)} ${this._state.daily.days} * *`:`${this._getTimeExpression(this._state.daily.time)} * * MON-FRI`;break;case"weekly":e=0===this._state.weekly.days.length?`${this._getTimeExpression(this._state.weekly.time)} * * *`:`${this._getTimeExpression(this._state.weekly.time)} * * ${this._state.weekly.days.join(",")}`;break;case"monthly":e=`${this._getTimeExpression(this._state.monthly.time)} ${this._state.monthly.day} ${this._state.monthly.month} *`;break;case"yearly":e=`${this._getTimeExpression(this._state.yearly.time)} ${this._state.yearly.day} */${this._months.indexOf(this._state.yearly.month)+1} *`;break;case"pro":e=this._state.pro.value;break;default:throw new Error("Invalid cron active tab selection")}this.updateState(e),this.valid&&(this._value=e,this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0})),(0,o.dispatchCustomEvent)(this,"input",this.value))}updateState(e){super.updateState(e),this.valid&&((0,l.isValidCron)(e,{seconds:!0,alias:!0})?this.setValidity():this.setValidity(!0,"field is not valid cron expression"))}renderLabel(){return this.label?e.html`<label for="${this.id}" title="${this.label}">${this.label}</label>`:""}displayProDetails(){this._state.pro.displayDetails=!this._state.pro.displayDetails,this.requestUpdate()}renderProDetails(){return this._state.pro.displayDetails?e.html`<div class="tab-content_pro-pane_container"><div class="tab-content_pro-pane"><div>Rules for:</div><div>${(0,i.repeat)(this._docs,(e=>e.id),(t=>{const s=t.id===this._currentDocumentationId;return e.html`<gv-tag @gv-tag:click="${this._onOpenDocumentation.bind(this,t.id)}" ?clickable="${!s}" ?major="${s}" ?minor="${!s}">${t.label}</gv-tag>`}))}</div><ul class="help"><li><small>Allowed characters: <code>${this.allowedChar}</code></small></li><li><small>Allowed values: <code>${this.allowedValues}</code></small></li></ul></div><div class="tab-content_pro-pane"><div>Examples:</div><ul class="help"><li><small><code>*</code>: for each unit (0, 1, 2, 3...)</small></li><li><small><code>5,8</code>: units 5 and 8</small></li><li><small><code>2-5</code>: units from 2 to 5 (2, 3, 4, 5)</small></li><li><small><code>*/3</code>: every 3 units (0, 3, 6, 9...)</small></li><li><small><code>10-20/3</code>: every 3 units, between the tenth and the twentieth (10, 13, 16, 19)</small></li></ul></div></div>`:""}render(){return e.html`<div>${this.renderLabel()}<div class="box"><gv-tabs .value="${this.mode}" .options="${this._modes}" .disabled="${this.disabled}" ?small="${this._small}" ?truncate="${this._truncateTabs}" @gv-tabs:change="${this._onChangeTab.bind(this)}"><div slot="title" class="generated-expression"><gv-input name="pro.value" .autofocus="${this.autofocus}" .value="${this.value}" id="cron-input" placeholder="* */30 * * * * (Every 30 min)"></gv-input></div><div slot="content" id="seconds" class="tab-content"><span>Every</span><gv-input small type="number" min="1" name="seconds.seconds" .value="${this._state.seconds.seconds}"></gv-input><span>second(s)</span></div><div slot="content" id="minutes" class="tab-content"><span>Every</span><gv-input small type="number" min="1" name="minutes.minutes" .value="${this._state.minutes.minutes}"></gv-input><span>minute(s) on second</span><gv-input small type="number" min="0" max="59" name="minutes.seconds" .value="${this._state.minutes.seconds}"></gv-input></div><div slot="content" id="hourly" class="tab-content"><span>Every</span><gv-input small type="number" min="1" name="hourly.hours" .value="${this._state.hourly.hours}"></gv-input><span>hour(s) on minute</span><gv-input small type="number" min="0" max="59" name="hourly.minutes" .value="${this._state.hourly.minutes}"></gv-input><span>and second</span><gv-input small type="number" min="0" max="59" name="hourly.seconds" .value="${this._state.hourly.seconds}"></gv-input></div><div slot="content" id="daily" class="tab-content"><span>Every</span><gv-input small type="number" min="1" max="31" name="daily.days" ?disabled="${this._state.daily.weekdays}" .value="${this._state.daily.days}"></gv-input><span class="line">day(s)<gv-checkbox class="request-update" label="of week" name="daily.weekdays" ?checked="${this._state.daily.weekdays}"></gv-checkbox>at</span><gv-date-picker small time strict name="daily.time" .value="${this._state.daily.time}"></gv-date-picker></div><div slot="content" id="weekly" class="tab-content tab-content_weekly"><span>Every</span><gv-select small multiple="multiple" name="weekly.days" .options="${this._days}" .value="${this._state.weekly.days}"></gv-select><span>day(s) at</span><gv-date-picker small time strict name="weekly.time" .value="${this._state.weekly.time}"></gv-date-picker></div><div slot="content" id="monthly" class="tab-content"><span>On the</span><gv-input small type="number" min="1" max="31" name="monthly.day" class="request-update" .value="${this._state.monthly.day}"></gv-input><span><sup>${this._getDaySuffix(this._state.monthly.day)}</sup> </span><span>day of every</span><gv-input small type="number" min="1" max="12" name="monthly.month" .value="${this._state.monthly.month}"></gv-input><span>month(s) at</span><gv-date-picker small time strict name="monthly.time" .value="${this._state.monthly.time}"></gv-date-picker></div><div slot="content" id="yearly" class="tab-content"><span>Every</span><gv-select small name="yearly.month" .options="${this._months}" .value="${this._state.yearly.month}"></gv-select><span>on the</span><gv-input small type="number" min="1" max="31" name="yearly.day" class="request-update" .value="${this._state.yearly.day}"></gv-input><span><sup>${this._getDaySuffix(this._state.yearly.day)}</sup></span> <span>day</span><gv-date-picker small time strict name="yearly.time" .value="${this._state.yearly.time}"></gv-date-picker></div><div slot="content" id="pro" class="tab-content tab-content_pro"><gv-button link small class="tab-content_pro-details_btn" @click="${this.displayProDetails}">${this._state.pro.displayDetails?"Hide information about cron rules and examples":"Display information about cron rules and examples"}</gv-button>${this.renderProDetails()}</div></gv-tabs></div></div>`}get allowedValues(){if("pro"===this.mode)switch(this._currentDocumentationId){case"hour":return"0-23";case"day-month":return"1-31";case"month":return"1-12 or JAN-DEC";case"day-week":return"1-7 or SUN-SAT";default:return"0-59"}return""}get allowedChar(){return"pro"===this.mode?",-*/":""}_getDaySuffix(e=1){return e?e.toString().endsWith("1")?"st":e.toString().endsWith("2")?"nd":e.toString().endsWith("3")?"rd":"th":""}static get styles(){return[t.skeleton,e.css`:host{box-sizing:border-box;display:block;margin:.2rem}:host([invalid]) .box{border-left-color:var(--gv-theme-color-error-dark,#d32f2f);border-left-width:3px}.box{border:1px solid var(--gv-theme-neutral-color-dark,#bfbfbf);border-radius:4px}.generated-expression{display:flex;align-items:center;flex:1}.generated-expression>code,.generated-expression>span{margin:.4rem}.generated-expression code,.generated-expression gv-input{--input-small--fz:16px;font-size:16px}.generated-expression gv-input{--gv-input--bdc:transparent;margin:0;min-width:190px}.tab-content{display:flex;align-items:center;background-color:var(--gv-theme-neutral-color,#f5f5f5);font-style:italic;font-size:var(--gv-theme-font-size-s,12px);padding:.2rem}.tab-content>*{margin:.2rem}.tab-content gv-input[type=number]{width:50px}.tab-content_weekly gv-select{width:auto}.tab-content_pro code{font-size:14px;font-weight:700;font-style:normal}.tab-content_pro{display:flex;flex-direction:column;align-items:normal;--gv-icon--s:18px;padding:.2rem}.tab-content_pro-details_btn{--gv-button--fz:12px}.tab-content_pro-pane_container{display:flex;flex-direction:row}.tab-content_pro-pane{flex:auto}.tab-content_pro>*{margin:.2rem}.tab-content_pro gv-icon,.tab-content_pro small{margin:0 .2rem}gv-tabs{--gv-tabs-options--m:auto 0.2rem auto 0}gv-tabs[small]{--gv-tabs-options--m:auto 0}gv-tabs[small] .tab-content{padding:0}.line{display:flex;align-items:center;margin:0}.line>*{margin:0 .3rem}gv-checkbox{text-decoration:line-through;font-weight:400}gv-checkbox[checked]{text-decoration:none}sup{display:inline-block;font-size:var(--gv-theme-font-size-s,12px)}ul{list-style:none;margin:.5rem 1rem;padding:0}ul.help{padding-left:.2rem;margin-left:.4rem;border-left:2px dotted var(--gv-theme-neutral-color-dark,#bfbfbf)}small{font-size:var(--gv-theme-font-size-s,12px)}`]}}exports.GvCronEditor=r,window.customElements.define("gv-cron-editor",r);