@progress/kendo-react-dateinputs 5.5.0-dev.202206270752 → 5.5.0-dev.202206280851

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.
@@ -132,7 +132,9 @@ var DateInputWithoutContext = /** @class */ (function (_super) {
132
132
  _this.setSelection(_this.selectionByIndex(_this.selection.start));
133
133
  };
134
134
  _this.nativeWheel = function (event) {
135
- event.preventDefault();
135
+ if (document.activeElement === _this.element) {
136
+ event.preventDefault();
137
+ }
136
138
  };
137
139
  _this.wheel = function (event) {
138
140
  if (document.activeElement !== _this.element) {
@@ -228,7 +230,7 @@ var DateInputWithoutContext = /** @class */ (function (_super) {
228
230
  if (this._lastSelectedSymbol && prevState.focused === this.state.focused) {
229
231
  this.setSelection(this.selectionBySymbol(this._lastSelectedSymbol));
230
232
  }
231
- else if (this.selection.start === this.selection.end) {
233
+ else if (this.props.placeholder !== undefined && this.selection.start === this.selection.end) {
232
234
  this.setSelection({ start: 0, end: this.currentFormat.length });
233
235
  }
234
236
  this.setValidity();
@@ -517,6 +519,7 @@ var DateInputWithoutContext = /** @class */ (function (_super) {
517
519
  return { start: start, end: end };
518
520
  };
519
521
  DateInputWithoutContext.prototype.selectionByIndex = function (index) {
522
+ // console.log(42, index);
520
523
  var selection = { start: index, end: index };
521
524
  for (var i = index, j = index - 1; i < this.currentFormat.length || j >= 0; i++, j--) {
522
525
  if (i < this.currentFormat.length && this.currentFormat[i] !== '_') {
@@ -5,7 +5,7 @@ export var packageMetadata = {
5
5
  name: '@progress/kendo-react-dateinputs',
6
6
  productName: 'KendoReact',
7
7
  productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
8
- publishDate: 1656315076,
8
+ publishDate: 1656405121,
9
9
  version: '',
10
10
  licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
11
11
  };
@@ -22,9 +22,10 @@ import { provideIntlService, registerForIntl } from '@progress/kendo-react-intl'
22
22
  import { Virtualization } from '../virtualization/Virtualization';
23
23
  import { TIME_PART } from './models';
24
24
  import { SecondsService, MinutesService, HoursService, DayPeriodService, DOMService } from './services';
25
- import { MAX_TIME, MIDNIGHT_DATE } from '../utils';
25
+ import { debounce, MAX_TIME, MIDNIGHT_DATE } from '../utils';
26
26
  var SCROLL_THRESHOLD = 2; // < 2px threshold
27
27
  var SNAP_THRESHOLD = 0.05; // % of the item height
28
+ var SCROLL_THROTTLE = 100; // ms
28
29
  var SKIP = 0;
29
30
  var getters = (_a = {},
30
31
  _a[Keys.end] = function (data, _) { return data[data.length - 1]; },
@@ -159,7 +160,7 @@ var TimeList = /** @class */ (function (_super) {
159
160
  _this.handleChange(dataItem);
160
161
  }
161
162
  };
162
- _this.handleChange = function (dataItem) {
163
+ _this.handleChange = debounce(function (dataItem) {
163
164
  if (!_this.service) {
164
165
  return;
165
166
  }
@@ -167,14 +168,11 @@ var TimeList = /** @class */ (function (_super) {
167
168
  if (_this.props.value.getTime() === candidate.getTime()) {
168
169
  return;
169
170
  }
170
- _this.setState({
171
- value: candidate
172
- });
173
171
  var onChange = _this.props.onChange;
174
172
  if (onChange) {
175
173
  onChange.call(undefined, candidate);
176
174
  }
177
- };
175
+ }, SCROLL_THROTTLE);
178
176
  _this.dom = new DOMService();
179
177
  return _this;
180
178
  }
@@ -76,3 +76,21 @@ export declare const dateInRange: (candidate: Date, min: Date, max: Date) => Dat
76
76
  * @hidden
77
77
  */
78
78
  export declare const domContainerFactory: (type: string) => (children: string | HTMLElement[], classes?: string, styles?: any) => HTMLElement;
79
+ /**
80
+ * @hidden
81
+ */
82
+ export declare function debounce(func: any, wait: number, options?: any): {
83
+ (...args: any): any;
84
+ cancel: () => void;
85
+ flush: () => any;
86
+ pending: () => boolean;
87
+ };
88
+ /**
89
+ * @hidden
90
+ */
91
+ export declare function throttle(func: any, wait: number): {
92
+ (...args: any): any;
93
+ cancel: () => void;
94
+ flush: () => any;
95
+ pending: () => boolean;
96
+ };
package/dist/es/utils.js CHANGED
@@ -164,3 +164,143 @@ export var domContainerFactory = function (type) { return function (children, cl
164
164
  }
165
165
  return container;
166
166
  }; };
167
+ /**
168
+ * @hidden
169
+ */
170
+ export function debounce(func, wait, options) {
171
+ if (options === void 0) { options = {}; }
172
+ var lastArgs;
173
+ var lastThis;
174
+ var maxWait = options.maxWait;
175
+ var result;
176
+ var timerId;
177
+ var lastCallTime;
178
+ var root = window;
179
+ var lastInvokeTime = 0;
180
+ var leading = false;
181
+ var maxing = false;
182
+ var trailing = true;
183
+ // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.
184
+ var useRAF = (!wait && wait !== 0 && typeof root.requestAnimationFrame === 'function');
185
+ if (typeof func !== 'function') {
186
+ throw new TypeError('Expected a function');
187
+ }
188
+ wait = +wait || 0;
189
+ function invokeFunc(time) {
190
+ var args = lastArgs;
191
+ var thisArg = lastThis;
192
+ lastArgs = lastThis = undefined;
193
+ lastInvokeTime = time;
194
+ result = func.apply(thisArg, args);
195
+ return result;
196
+ }
197
+ function startTimer(pendingFunc, tmr) {
198
+ if (useRAF) {
199
+ root.cancelAnimationFrame(timerId);
200
+ return root.requestAnimationFrame(pendingFunc);
201
+ }
202
+ return setTimeout(pendingFunc, tmr);
203
+ }
204
+ function cancelTimer(id) {
205
+ if (useRAF) {
206
+ return root.cancelAnimationFrame(id);
207
+ }
208
+ clearTimeout(id);
209
+ }
210
+ function leadingEdge(time) {
211
+ // Reset any `maxWait` timer.
212
+ lastInvokeTime = time;
213
+ // Start the timer for the trailing edge.
214
+ timerId = startTimer(timerExpired, wait);
215
+ // Invoke the leading edge.
216
+ return leading ? invokeFunc(time) : result;
217
+ }
218
+ function remainingWait(time) {
219
+ var timeSinceLastCall = time - lastCallTime;
220
+ var timeSinceLastInvoke = time - lastInvokeTime;
221
+ var timeWaiting = wait - timeSinceLastCall;
222
+ return maxing
223
+ ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)
224
+ : timeWaiting;
225
+ }
226
+ function shouldInvoke(time) {
227
+ var timeSinceLastCall = time - lastCallTime;
228
+ var timeSinceLastInvoke = time - lastInvokeTime;
229
+ // Either this is the first call, activity has stopped and we're at the
230
+ // trailing edge, the system time has gone backwards and we're treating
231
+ // it as the trailing edge, or we've hit the `maxWait` limit.
232
+ return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
233
+ (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
234
+ }
235
+ function timerExpired() {
236
+ var time = Date.now();
237
+ if (shouldInvoke(time)) {
238
+ return trailingEdge(time);
239
+ }
240
+ // Restart the timer.
241
+ timerId = startTimer(timerExpired, remainingWait(time));
242
+ }
243
+ function trailingEdge(time) {
244
+ timerId = undefined;
245
+ // Only invoke if we have `lastArgs` which means `func` has been
246
+ // debounced at least once.
247
+ if (trailing && lastArgs) {
248
+ return invokeFunc(time);
249
+ }
250
+ lastArgs = lastThis = undefined;
251
+ return result;
252
+ }
253
+ function cancel() {
254
+ if (timerId !== undefined) {
255
+ cancelTimer(timerId);
256
+ }
257
+ lastInvokeTime = 0;
258
+ lastArgs = lastCallTime = lastThis = timerId = undefined;
259
+ }
260
+ function flush() {
261
+ return timerId === undefined ? result : trailingEdge(Date.now());
262
+ }
263
+ function pending() {
264
+ return timerId !== undefined;
265
+ }
266
+ function debounced() {
267
+ var args = [];
268
+ for (var _i = 0; _i < arguments.length; _i++) {
269
+ args[_i] = arguments[_i];
270
+ }
271
+ var time = Date.now();
272
+ var isInvoking = shouldInvoke(time);
273
+ lastArgs = args;
274
+ /* @ts-ignore */
275
+ lastThis = this;
276
+ lastCallTime = time;
277
+ if (isInvoking) {
278
+ if (timerId === undefined) {
279
+ return leadingEdge(lastCallTime);
280
+ }
281
+ if (maxing) {
282
+ // Handle invocations in a tight loop.
283
+ timerId = startTimer(timerExpired, wait);
284
+ return invokeFunc(lastCallTime);
285
+ }
286
+ }
287
+ if (timerId === undefined) {
288
+ timerId = startTimer(timerExpired, wait);
289
+ }
290
+ return result;
291
+ }
292
+ debounced.cancel = cancel;
293
+ debounced.flush = flush;
294
+ debounced.pending = pending;
295
+ return debounced;
296
+ }
297
+ /**
298
+ * @hidden
299
+ */
300
+ export function throttle(func, wait) {
301
+ return debounce(func, wait, {
302
+ leading: true,
303
+ trailing: true,
304
+ 'maxWait': wait
305
+ });
306
+ }
@@ -135,7 +135,9 @@ var DateInputWithoutContext = /** @class */ (function (_super) {
135
135
  _this.setSelection(_this.selectionByIndex(_this.selection.start));
136
136
  };
137
137
  _this.nativeWheel = function (event) {
138
- event.preventDefault();
138
+ if (document.activeElement === _this.element) {
139
+ event.preventDefault();
140
+ }
139
141
  };
140
142
  _this.wheel = function (event) {
141
143
  if (document.activeElement !== _this.element) {
@@ -231,7 +233,7 @@ var DateInputWithoutContext = /** @class */ (function (_super) {
231
233
  if (this._lastSelectedSymbol && prevState.focused === this.state.focused) {
232
234
  this.setSelection(this.selectionBySymbol(this._lastSelectedSymbol));
233
235
  }
234
- else if (this.selection.start === this.selection.end) {
236
+ else if (this.props.placeholder !== undefined && this.selection.start === this.selection.end) {
235
237
  this.setSelection({ start: 0, end: this.currentFormat.length });
236
238
  }
237
239
  this.setValidity();
@@ -520,6 +522,7 @@ var DateInputWithoutContext = /** @class */ (function (_super) {
520
522
  return { start: start, end: end };
521
523
  };
522
524
  DateInputWithoutContext.prototype.selectionByIndex = function (index) {
525
+ // console.log(42, index);
523
526
  var selection = { start: index, end: index };
524
527
  for (var i = index, j = index - 1; i < this.currentFormat.length || j >= 0; i++, j--) {
525
528
  if (i < this.currentFormat.length && this.currentFormat[i] !== '_') {
@@ -8,7 +8,7 @@ exports.packageMetadata = {
8
8
  name: '@progress/kendo-react-dateinputs',
9
9
  productName: 'KendoReact',
10
10
  productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
11
- publishDate: 1656315076,
11
+ publishDate: 1656405121,
12
12
  version: '',
13
13
  licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
14
14
  };
@@ -28,6 +28,7 @@ var services_1 = require("./services");
28
28
  var utils_1 = require("../utils");
29
29
  var SCROLL_THRESHOLD = 2; // < 2px threshold
30
30
  var SNAP_THRESHOLD = 0.05; // % of the item height
31
+ var SCROLL_THROTTLE = 100; // ms
31
32
  var SKIP = 0;
32
33
  var getters = (_a = {},
33
34
  _a[kendo_react_common_1.Keys.end] = function (data, _) { return data[data.length - 1]; },
@@ -162,7 +163,7 @@ var TimeList = /** @class */ (function (_super) {
162
163
  _this.handleChange(dataItem);
163
164
  }
164
165
  };
165
- _this.handleChange = function (dataItem) {
166
+ _this.handleChange = (0, utils_1.debounce)(function (dataItem) {
166
167
  if (!_this.service) {
167
168
  return;
168
169
  }
@@ -170,14 +171,11 @@ var TimeList = /** @class */ (function (_super) {
170
171
  if (_this.props.value.getTime() === candidate.getTime()) {
171
172
  return;
172
173
  }
173
- _this.setState({
174
- value: candidate
175
- });
176
174
  var onChange = _this.props.onChange;
177
175
  if (onChange) {
178
176
  onChange.call(undefined, candidate);
179
177
  }
180
- };
178
+ }, SCROLL_THROTTLE);
181
179
  _this.dom = new services_1.DOMService();
182
180
  return _this;
183
181
  }
@@ -76,3 +76,21 @@ export declare const dateInRange: (candidate: Date, min: Date, max: Date) => Dat
76
76
  * @hidden
77
77
  */
78
78
  export declare const domContainerFactory: (type: string) => (children: string | HTMLElement[], classes?: string, styles?: any) => HTMLElement;
79
+ /**
80
+ * @hidden
81
+ */
82
+ export declare function debounce(func: any, wait: number, options?: any): {
83
+ (...args: any): any;
84
+ cancel: () => void;
85
+ flush: () => any;
86
+ pending: () => boolean;
87
+ };
88
+ /**
89
+ * @hidden
90
+ */
91
+ export declare function throttle(func: any, wait: number): {
92
+ (...args: any): any;
93
+ cancel: () => void;
94
+ flush: () => any;
95
+ pending: () => boolean;
96
+ };
package/dist/npm/utils.js CHANGED
@@ -9,7 +9,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
9
9
  return to.concat(ar || Array.prototype.slice.call(from));
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.domContainerFactory = exports.dateInRange = exports.shiftWeekNames = exports.intersects = exports.range = exports.isInSelectionRange = exports.isInDateRange = exports.isInRange = exports.getToday = exports.setTime = exports.isValidRange = exports.MAX_TIME = exports.MIN_TIME = exports.MAX_DATE = exports.MIN_DATE = exports.MIDNIGHT_DATE = exports.viewInRange = exports.nullable = exports.isEqualRange = void 0;
12
+ exports.throttle = exports.debounce = exports.domContainerFactory = exports.dateInRange = exports.shiftWeekNames = exports.intersects = exports.range = exports.isInSelectionRange = exports.isInDateRange = exports.isInRange = exports.getToday = exports.setTime = exports.isValidRange = exports.MAX_TIME = exports.MIN_TIME = exports.MAX_DATE = exports.MIN_DATE = exports.MIDNIGHT_DATE = exports.viewInRange = exports.nullable = exports.isEqualRange = void 0;
13
13
  var kendo_date_math_1 = require("@progress/kendo-date-math");
14
14
  var kendo_date_math_2 = require("@progress/kendo-date-math");
15
15
  var SelectionRange_1 = require("./calendar/models/SelectionRange");
@@ -181,3 +181,145 @@ var domContainerFactory = function (type) { return function (children, classes,
181
181
  return container;
182
182
  }; };
183
183
  exports.domContainerFactory = domContainerFactory;
184
+ /**
185
+ * @hidden
186
+ */
187
+ function debounce(func, wait, options) {
188
+ if (options === void 0) { options = {}; }
189
+ var lastArgs;
190
+ var lastThis;
191
+ var maxWait = options.maxWait;
192
+ var result;
193
+ var timerId;
194
+ var lastCallTime;
195
+ var root = window;
196
+ var lastInvokeTime = 0;
197
+ var leading = false;
198
+ var maxing = false;
199
+ var trailing = true;
200
+ // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.
201
+ var useRAF = (!wait && wait !== 0 && typeof root.requestAnimationFrame === 'function');
202
+ if (typeof func !== 'function') {
203
+ throw new TypeError('Expected a function');
204
+ }
205
+ wait = +wait || 0;
206
+ function invokeFunc(time) {
207
+ var args = lastArgs;
208
+ var thisArg = lastThis;
209
+ lastArgs = lastThis = undefined;
210
+ lastInvokeTime = time;
211
+ result = func.apply(thisArg, args);
212
+ return result;
213
+ }
214
+ function startTimer(pendingFunc, tmr) {
215
+ if (useRAF) {
216
+ root.cancelAnimationFrame(timerId);
217
+ return root.requestAnimationFrame(pendingFunc);
218
+ }
219
+ return setTimeout(pendingFunc, tmr);
220
+ }
221
+ function cancelTimer(id) {
222
+ if (useRAF) {
223
+ return root.cancelAnimationFrame(id);
224
+ }
225
+ clearTimeout(id);
226
+ }
227
+ function leadingEdge(time) {
228
+ // Reset any `maxWait` timer.
229
+ lastInvokeTime = time;
230
+ // Start the timer for the trailing edge.
231
+ timerId = startTimer(timerExpired, wait);
232
+ // Invoke the leading edge.
233
+ return leading ? invokeFunc(time) : result;
234
+ }
235
+ function remainingWait(time) {
236
+ var timeSinceLastCall = time - lastCallTime;
237
+ var timeSinceLastInvoke = time - lastInvokeTime;
238
+ var timeWaiting = wait - timeSinceLastCall;
239
+ return maxing
240
+ ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)
241
+ : timeWaiting;
242
+ }
243
+ function shouldInvoke(time) {
244
+ var timeSinceLastCall = time - lastCallTime;
245
+ var timeSinceLastInvoke = time - lastInvokeTime;
246
+ // Either this is the first call, activity has stopped and we're at the
247
+ // trailing edge, the system time has gone backwards and we're treating
248
+ // it as the trailing edge, or we've hit the `maxWait` limit.
249
+ return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
250
+ (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
251
+ }
252
+ function timerExpired() {
253
+ var time = Date.now();
254
+ if (shouldInvoke(time)) {
255
+ return trailingEdge(time);
256
+ }
257
+ // Restart the timer.
258
+ timerId = startTimer(timerExpired, remainingWait(time));
259
+ }
260
+ function trailingEdge(time) {
261
+ timerId = undefined;
262
+ // Only invoke if we have `lastArgs` which means `func` has been
263
+ // debounced at least once.
264
+ if (trailing && lastArgs) {
265
+ return invokeFunc(time);
266
+ }
267
+ lastArgs = lastThis = undefined;
268
+ return result;
269
+ }
270
+ function cancel() {
271
+ if (timerId !== undefined) {
272
+ cancelTimer(timerId);
273
+ }
274
+ lastInvokeTime = 0;
275
+ lastArgs = lastCallTime = lastThis = timerId = undefined;
276
+ }
277
+ function flush() {
278
+ return timerId === undefined ? result : trailingEdge(Date.now());
279
+ }
280
+ function pending() {
281
+ return timerId !== undefined;
282
+ }
283
+ function debounced() {
284
+ var args = [];
285
+ for (var _i = 0; _i < arguments.length; _i++) {
286
+ args[_i] = arguments[_i];
287
+ }
288
+ var time = Date.now();
289
+ var isInvoking = shouldInvoke(time);
290
+ lastArgs = args;
291
+ /* @ts-ignore */
292
+ lastThis = this;
293
+ lastCallTime = time;
294
+ if (isInvoking) {
295
+ if (timerId === undefined) {
296
+ return leadingEdge(lastCallTime);
297
+ }
298
+ if (maxing) {
299
+ // Handle invocations in a tight loop.
300
+ timerId = startTimer(timerExpired, wait);
301
+ return invokeFunc(lastCallTime);
302
+ }
303
+ }
304
+ if (timerId === undefined) {
305
+ timerId = startTimer(timerExpired, wait);
306
+ }
307
+ return result;
308
+ }
309
+ debounced.cancel = cancel;
310
+ debounced.flush = flush;
311
+ debounced.pending = pending;
312
+ return debounced;
313
+ }
314
+ exports.debounce = debounce;
315
+ /**
316
+ * @hidden
317
+ */
318
+ function throttle(func, wait) {
319
+ return debounce(func, wait, {
320
+ leading: true,
321
+ trailing: true,
322
+ 'maxWait': wait
323
+ });
324
+ }
325
+ exports.throttle = throttle;